Hi,

My previous argument was flawed. Here goes another try.

Rather than parse /proc/cpuinfo, use the same information cpufreq-info has 
about the cpu's. It currently gets that information from /proc/stat, so it 
makes since not to parse different files to harvest the same information.

print_cpus_index.patch adds an option to cpufreq-info to print the index of 
each cpu in system. This option can be used by a variety of scripts, 
including cpufrequtils.init, to enumerate a list of cpu indices to perform 
actions on.

02_449307-parse-cpufreq-info-for-cpus.patch is the patch against 
cpufrequtils.init to use the new option.

Thanks, Kel.
diff -Nrup cpufrequtils-002/man/cpufreq-info.1 cpufrequtils-002.n/man/cpufreq-info.1
--- cpufrequtils-002/man/cpufreq-info.1	2006-06-01 18:54:41.000000000 +1000
+++ cpufrequtils-002.n/man/cpufreq-info.1	2007-12-05 10:43:09.000000000 +1000
@@ -40,6 +40,9 @@ Determines which CPUs can only switch fr
 .TP  
 \fB\-o\fR \fB\-\-proc\fR
 Prints out information like provided by the /proc/cpufreq interface in 2.4. and early 2.6. kernels.
+.TP
+\fB\-i\fR \fB\-\-cpus-index\fR
+Prints an index number for each CPU on the system.
 .TP  
 \fB\-m\fR \fB\-\-human\fR
 human\-readable output for the \-f and \-w parameters.
diff -Nrup cpufrequtils-002/utils/info.c cpufrequtils-002.n/utils/info.c
--- cpufrequtils-002/utils/info.c	2006-06-01 18:54:41.000000000 +1000
+++ cpufrequtils-002.n/utils/info.c	2007-12-05 13:06:10.000000000 +1000
@@ -55,6 +55,14 @@ static unsigned int count_cpus(void)
 	return (ret+1);
 }
 
+static void print_cpus_index(void)
+{
+	unsigned int cpu, nr_cpus;
+
+	nr_cpus = count_cpus();
+	for (cpu=0; cpu < nr_cpus; cpu++)
+		printf("%d\n", cpu);
+}
 
 static void proc_cpufreq_output(void)
 {
@@ -359,6 +367,7 @@ static struct option info_opts[] = {
 	{ .name="affected-cpus",.has_arg=no_argument,		.flag=NULL,	.val='a'},
 	{ .name="proc",		.has_arg=no_argument,		.flag=NULL,	.val='o'},
 	{ .name="human",	.has_arg=no_argument,		.flag=NULL,	.val='m'},
+	{ .name="cpus-index",	.has_arg=no_argument,		.flag=NULL,	.val='i'},
 	{ .name="help",		.has_arg=no_argument,		.flag=NULL,	.val='h'},
 };
 
@@ -375,7 +384,7 @@ int main(int argc, char **argv) {
 	textdomain (PACKAGE);
 
 	do {
-		ret = getopt_long(argc, argv, "c:hoefwldpgam", info_opts, NULL);
+		ret = getopt_long(argc, argv, "c:hoefwldpgami", info_opts, NULL);
 		switch (ret) {
 		case '?':
 			output_param = '?';
@@ -396,6 +405,7 @@ int main(int argc, char **argv) {
 		case 'l':
 		case 'w':
 		case 'f':
+		case 'i':
 		case 'e':
 			if (output_param) { 
 				output_param = -1; 
@@ -458,6 +468,9 @@ int main(int argc, char **argv) {
 		print_header();
 		print_help();
 		break;
+	case 'i':
+		print_cpus_index();
+		break;
 	case 'o':
 		proc_cpufreq_output();
 		break;
diff -Nrup cpufrequtils-002/debian/cpufrequtils.init cpufrequtils-002.parse-cpufreqinfo/debian/cpufrequtils.init
--- cpufrequtils-002/debian/cpufrequtils.init	2007-11-25 00:08:27.000000000 +1000
+++ cpufrequtils-002.parse-cpufreqinfo/debian/cpufrequtils.init	2007-12-05 13:14:53.000000000 +1000
@@ -52,7 +52,7 @@ check_governor_avail() {
 	return 1;
 }
 
-[ -x $CPUFREQ_SET ] || exit 0
+[ -x $CPUFREQ_SET ] && [ -x $CPUFREQ_INFO ]|| exit 0
 
 if [ -f /etc/default/cpufrequtils ] ; then
 	. /etc/default/cpufrequtils
@@ -73,7 +73,7 @@ if [ -n "$GOVERNOR" ] ; then
 	CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --governor $GOVERNOR"
 fi
 
-CPUS=$(sed -ne 's/^processor[[:space:]]*: \([0-9]\+\)$/\1/p' /proc/cpuinfo)
+CPUS=$($CPUFREQ_INFO --cpus-index)
 RETVAL=0
 case "$1" in
 	start|force-reload|restart|reload)

Reply via email to