aboutsummaryrefslogtreecommitdiffstats
path: root/tools/power/cpupower/utils
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2011-04-19 14:33:50 -0400
committerDominik Brodowski <linux@dominikbrodowski.net>2011-07-29 12:35:39 -0400
commita1ce5ba2b7d08ab6347dc254f86f70e91c5f1a44 (patch)
tree22d59faf4df1547bb9547935c7f63c3ef6a6b387 /tools/power/cpupower/utils
parent2cd005cac6d586b8ca324814a9c58ed0c08ffe40 (diff)
cpupowerutils: utils - ConfigStyle bugfixes
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'tools/power/cpupower/utils')
-rw-r--r--tools/power/cpupower/utils/cpufreq-info.c123
-rw-r--r--tools/power/cpupower/utils/cpufreq-set.c25
-rw-r--r--tools/power/cpupower/utils/cpuidle-info.c27
-rw-r--r--tools/power/cpupower/utils/cpupower-info.c17
-rw-r--r--tools/power/cpupower/utils/cpupower-set.c16
-rw-r--r--tools/power/cpupower/utils/cpupower.c22
6 files changed, 122 insertions, 108 deletions
diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c
index eaa8be06edfa..8628644188cf 100644
--- a/tools/power/cpupower/utils/cpufreq-info.c
+++ b/tools/power/cpupower/utils/cpufreq-info.c
@@ -27,7 +27,7 @@ static unsigned int count_cpus(void)
27 unsigned int cpunr = 0; 27 unsigned int cpunr = 0;
28 28
29 fp = fopen("/proc/stat", "r"); 29 fp = fopen("/proc/stat", "r");
30 if(!fp) { 30 if (!fp) {
31 printf(_("Couldn't count the number of CPUs (%s: %s), assuming 1\n"), "/proc/stat", strerror(errno)); 31 printf(_("Couldn't count the number of CPUs (%s: %s), assuming 1\n"), "/proc/stat", strerror(errno));
32 return 1; 32 return 1;
33 } 33 }
@@ -48,7 +48,7 @@ static unsigned int count_cpus(void)
48 fclose(fp); 48 fclose(fp);
49 49
50 /* cpu count starts from 0, on error return 1 (UP) */ 50 /* cpu count starts from 0, on error return 1 (UP) */
51 return (ret+1); 51 return ret + 1;
52} 52}
53 53
54 54
@@ -63,7 +63,7 @@ static void proc_cpufreq_output(void)
63 printf(_(" minimum CPU frequency - maximum CPU frequency - governor\n")); 63 printf(_(" minimum CPU frequency - maximum CPU frequency - governor\n"));
64 64
65 nr_cpus = count_cpus(); 65 nr_cpus = count_cpus();
66 for (cpu=0; cpu < nr_cpus; cpu++) { 66 for (cpu = 0; cpu < nr_cpus; cpu++) {
67 policy = cpufreq_get_policy(cpu); 67 policy = cpufreq_get_policy(cpu);
68 if (!policy) 68 if (!policy)
69 continue; 69 continue;
@@ -75,7 +75,8 @@ static void proc_cpufreq_output(void)
75 max_pctg = (policy->max * 100) / max; 75 max_pctg = (policy->max * 100) / max;
76 } 76 }
77 printf("CPU%3d %9lu kHz (%3d %%) - %9lu kHz (%3d %%) - %s\n", 77 printf("CPU%3d %9lu kHz (%3d %%) - %9lu kHz (%3d %%) - %s\n",
78 cpu , policy->min, max ? min_pctg : 0, policy->max, max ? max_pctg : 0, policy->governor); 78 cpu , policy->min, max ? min_pctg : 0, policy->max,
79 max ? max_pctg : 0, policy->governor);
79 80
80 cpufreq_put_policy(policy); 81 cpufreq_put_policy(policy);
81 } 82 }
@@ -89,21 +90,21 @@ static void print_speed(unsigned long speed)
89 tmp = speed % 10000; 90 tmp = speed % 10000;
90 if (tmp >= 5000) 91 if (tmp >= 5000)
91 speed += 10000; 92 speed += 10000;
92 printf ("%u.%02u GHz", ((unsigned int) speed/1000000), 93 printf("%u.%02u GHz", ((unsigned int) speed/1000000),
93 ((unsigned int) (speed%1000000)/10000)); 94 ((unsigned int) (speed%1000000)/10000));
94 } else if (speed > 100000) { 95 } else if (speed > 100000) {
95 tmp = speed % 1000; 96 tmp = speed % 1000;
96 if (tmp >= 500) 97 if (tmp >= 500)
97 speed += 1000; 98 speed += 1000;
98 printf ("%u MHz", ((unsigned int) speed / 1000)); 99 printf("%u MHz", ((unsigned int) speed / 1000));
99 } else if (speed > 1000) { 100 } else if (speed > 1000) {
100 tmp = speed % 100; 101 tmp = speed % 100;
101 if (tmp >= 50) 102 if (tmp >= 50)
102 speed += 100; 103 speed += 100;
103 printf ("%u.%01u MHz", ((unsigned int) speed/1000), 104 printf("%u.%01u MHz", ((unsigned int) speed/1000),
104 ((unsigned int) (speed%1000)/100)); 105 ((unsigned int) (speed%1000)/100));
105 } else 106 } else
106 printf ("%lu kHz", speed); 107 printf("%lu kHz", speed);
107 108
108 return; 109 return;
109} 110}
@@ -116,28 +117,29 @@ static void print_duration(unsigned long duration)
116 tmp = duration % 10000; 117 tmp = duration % 10000;
117 if (tmp >= 5000) 118 if (tmp >= 5000)
118 duration += 10000; 119 duration += 10000;
119 printf ("%u.%02u ms", ((unsigned int) duration/1000000), 120 printf("%u.%02u ms", ((unsigned int) duration/1000000),
120 ((unsigned int) (duration%1000000)/10000)); 121 ((unsigned int) (duration%1000000)/10000));
121 } else if (duration > 100000) { 122 } else if (duration > 100000) {
122 tmp = duration % 1000; 123 tmp = duration % 1000;
123 if (tmp >= 500) 124 if (tmp >= 500)
124 duration += 1000; 125 duration += 1000;
125 printf ("%u us", ((unsigned int) duration / 1000)); 126 printf("%u us", ((unsigned int) duration / 1000));
126 } else if (duration > 1000) { 127 } else if (duration > 1000) {
127 tmp = duration % 100; 128 tmp = duration % 100;
128 if (tmp >= 50) 129 if (tmp >= 50)
129 duration += 100; 130 duration += 100;
130 printf ("%u.%01u us", ((unsigned int) duration/1000), 131 printf("%u.%01u us", ((unsigned int) duration/1000),
131 ((unsigned int) (duration%1000)/100)); 132 ((unsigned int) (duration%1000)/100));
132 } else 133 } else
133 printf ("%lu ns", duration); 134 printf("%lu ns", duration);
134 135
135 return; 136 return;
136} 137}
137 138
138/* --boost / -b */ 139/* --boost / -b */
139 140
140static int get_boost_mode(unsigned int cpu) { 141static int get_boost_mode(unsigned int cpu)
142{
141 int support, active, b_states = 0, ret, pstate_no, i; 143 int support, active, b_states = 0, ret, pstate_no, i;
142 /* ToDo: Make this more global */ 144 /* ToDo: Make this more global */
143 unsigned long pstates[MAX_HW_PSTATES] = {0,}; 145 unsigned long pstates[MAX_HW_PSTATES] = {0,};
@@ -158,13 +160,13 @@ static int get_boost_mode(unsigned int cpu) {
158 && (cpuid_edx(0x80000007) & (1 << 7))) 160 && (cpuid_edx(0x80000007) & (1 << 7)))
159 */ 161 */
160 162
161 printf(_(" boost state support: \n")); 163 printf(_(" boost state support:\n"));
162 164
163 printf(_(" Supported: %s\n"), support ? _("yes") : _("no")); 165 printf(_(" Supported: %s\n"), support ? _("yes") : _("no"));
164 printf(_(" Active: %s\n"), active ? _("yes") : _("no")); 166 printf(_(" Active: %s\n"), active ? _("yes") : _("no"));
165 167
166 /* ToDo: Only works for AMD for now... */ 168 /* ToDo: Only works for AMD for now... */
167 169
168 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD && 170 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD &&
169 cpupower_cpu_info.family >= 0x10) { 171 cpupower_cpu_info.family >= 0x10) {
170 ret = decode_pstates(cpu, cpupower_cpu_info.family, b_states, 172 ret = decode_pstates(cpu, cpupower_cpu_info.family, b_states,
@@ -196,12 +198,11 @@ static void debug_output_one(unsigned int cpu)
196 unsigned long total_trans, latency; 198 unsigned long total_trans, latency;
197 unsigned long long total_time; 199 unsigned long long total_time;
198 struct cpufreq_policy *policy; 200 struct cpufreq_policy *policy;
199 struct cpufreq_available_governors * governors; 201 struct cpufreq_available_governors *governors;
200 struct cpufreq_stats *stats; 202 struct cpufreq_stats *stats;
201 203
202 if (cpufreq_cpu_exists(cpu)) { 204 if (cpufreq_cpu_exists(cpu))
203 return; 205 return;
204 }
205 206
206 freq_kernel = cpufreq_get_freq_kernel(cpu); 207 freq_kernel = cpufreq_get_freq_kernel(cpu);
207 freq_hardware = cpufreq_get_freq_hardware(cpu); 208 freq_hardware = cpufreq_get_freq_hardware(cpu);
@@ -294,8 +295,7 @@ static void debug_output_one(unsigned int cpu)
294 if (freq_hardware) { 295 if (freq_hardware) {
295 print_speed(freq_hardware); 296 print_speed(freq_hardware);
296 printf(_(" (asserted by call to hardware)")); 297 printf(_(" (asserted by call to hardware)"));
297 } 298 } else
298 else
299 print_speed(freq_kernel); 299 print_speed(freq_kernel);
300 printf(".\n"); 300 printf(".\n");
301 } 301 }
@@ -322,7 +322,8 @@ static void debug_output_one(unsigned int cpu)
322 322
323/* --freq / -f */ 323/* --freq / -f */
324 324
325static int get_freq_kernel(unsigned int cpu, unsigned int human) { 325static int get_freq_kernel(unsigned int cpu, unsigned int human)
326{
326 unsigned long freq = cpufreq_get_freq_kernel(cpu); 327 unsigned long freq = cpufreq_get_freq_kernel(cpu);
327 if (!freq) 328 if (!freq)
328 return -EINVAL; 329 return -EINVAL;
@@ -337,7 +338,8 @@ static int get_freq_kernel(unsigned int cpu, unsigned int human) {
337 338
338/* --hwfreq / -w */ 339/* --hwfreq / -w */
339 340
340static int get_freq_hardware(unsigned int cpu, unsigned int human) { 341static int get_freq_hardware(unsigned int cpu, unsigned int human)
342{
341 unsigned long freq = cpufreq_get_freq_hardware(cpu); 343 unsigned long freq = cpufreq_get_freq_hardware(cpu);
342 if (!freq) 344 if (!freq)
343 return -EINVAL; 345 return -EINVAL;
@@ -351,7 +353,8 @@ static int get_freq_hardware(unsigned int cpu, unsigned int human) {
351 353
352/* --hwlimits / -l */ 354/* --hwlimits / -l */
353 355
354static int get_hardware_limits(unsigned int cpu) { 356static int get_hardware_limits(unsigned int cpu)
357{
355 unsigned long min, max; 358 unsigned long min, max;
356 if (cpufreq_get_hardware_limits(cpu, &min, &max)) 359 if (cpufreq_get_hardware_limits(cpu, &min, &max))
357 return -EINVAL; 360 return -EINVAL;
@@ -361,7 +364,8 @@ static int get_hardware_limits(unsigned int cpu) {
361 364
362/* --driver / -d */ 365/* --driver / -d */
363 366
364static int get_driver(unsigned int cpu) { 367static int get_driver(unsigned int cpu)
368{
365 char *driver = cpufreq_get_driver(cpu); 369 char *driver = cpufreq_get_driver(cpu);
366 if (!driver) 370 if (!driver)
367 return -EINVAL; 371 return -EINVAL;
@@ -372,7 +376,8 @@ static int get_driver(unsigned int cpu) {
372 376
373/* --policy / -p */ 377/* --policy / -p */
374 378
375static int get_policy(unsigned int cpu) { 379static int get_policy(unsigned int cpu)
380{
376 struct cpufreq_policy *policy = cpufreq_get_policy(cpu); 381 struct cpufreq_policy *policy = cpufreq_get_policy(cpu);
377 if (!policy) 382 if (!policy)
378 return -EINVAL; 383 return -EINVAL;
@@ -383,8 +388,10 @@ static int get_policy(unsigned int cpu) {
383 388
384/* --governors / -g */ 389/* --governors / -g */
385 390
386static int get_available_governors(unsigned int cpu) { 391static int get_available_governors(unsigned int cpu)
387 struct cpufreq_available_governors *governors = cpufreq_get_available_governors(cpu); 392{
393 struct cpufreq_available_governors *governors =
394 cpufreq_get_available_governors(cpu);
388 if (!governors) 395 if (!governors)
389 return -EINVAL; 396 return -EINVAL;
390 397
@@ -400,7 +407,8 @@ static int get_available_governors(unsigned int cpu) {
400 407
401/* --affected-cpus / -a */ 408/* --affected-cpus / -a */
402 409
403static int get_affected_cpus(unsigned int cpu) { 410static int get_affected_cpus(unsigned int cpu)
411{
404 struct cpufreq_affected_cpus *cpus = cpufreq_get_affected_cpus(cpu); 412 struct cpufreq_affected_cpus *cpus = cpufreq_get_affected_cpus(cpu);
405 if (!cpus) 413 if (!cpus)
406 return -EINVAL; 414 return -EINVAL;
@@ -416,7 +424,8 @@ static int get_affected_cpus(unsigned int cpu) {
416 424
417/* --related-cpus / -r */ 425/* --related-cpus / -r */
418 426
419static int get_related_cpus(unsigned int cpu) { 427static int get_related_cpus(unsigned int cpu)
428{
420 struct cpufreq_affected_cpus *cpus = cpufreq_get_related_cpus(cpu); 429 struct cpufreq_affected_cpus *cpus = cpufreq_get_related_cpus(cpu);
421 if (!cpus) 430 if (!cpus)
422 return -EINVAL; 431 return -EINVAL;
@@ -432,17 +441,19 @@ static int get_related_cpus(unsigned int cpu) {
432 441
433/* --stats / -s */ 442/* --stats / -s */
434 443
435static int get_freq_stats(unsigned int cpu, unsigned int human) { 444static int get_freq_stats(unsigned int cpu, unsigned int human)
445{
436 unsigned long total_trans = cpufreq_get_transitions(cpu); 446 unsigned long total_trans = cpufreq_get_transitions(cpu);
437 unsigned long long total_time; 447 unsigned long long total_time;
438 struct cpufreq_stats *stats = cpufreq_get_stats(cpu, &total_time); 448 struct cpufreq_stats *stats = cpufreq_get_stats(cpu, &total_time);
439 while (stats) { 449 while (stats) {
440 if (human) { 450 if (human) {
441 print_speed(stats->frequency); 451 print_speed(stats->frequency);
442 printf(":%.2f%%", (100.0 * stats->time_in_state) / total_time); 452 printf(":%.2f%%",
443 } 453 (100.0 * stats->time_in_state) / total_time);
444 else 454 } else
445 printf("%lu:%llu", stats->frequency, stats->time_in_state); 455 printf("%lu:%llu",
456 stats->frequency, stats->time_in_state);
446 stats = stats->next; 457 stats = stats->next;
447 if (stats) 458 if (stats)
448 printf(", "); 459 printf(", ");
@@ -455,7 +466,8 @@ static int get_freq_stats(unsigned int cpu, unsigned int human) {
455 466
456/* --latency / -y */ 467/* --latency / -y */
457 468
458static int get_latency(unsigned int cpu, unsigned int human) { 469static int get_latency(unsigned int cpu, unsigned int human)
470{
459 unsigned long latency = cpufreq_get_transition_latency(cpu); 471 unsigned long latency = cpufreq_get_transition_latency(cpu);
460 if (!latency) 472 if (!latency)
461 return -EINVAL; 473 return -EINVAL;
@@ -468,7 +480,8 @@ static int get_latency(unsigned int cpu, unsigned int human) {
468 return 0; 480 return 0;
469} 481}
470 482
471void freq_info_help(void) { 483void freq_info_help(void)
484{
472 printf(_("Usage: cpupower freqinfo [options]\n")); 485 printf(_("Usage: cpupower freqinfo [options]\n"));
473 printf(_("Options:\n")); 486 printf(_("Options:\n"));
474 printf(_(" -e, --debug Prints out debug information [default]\n")); 487 printf(_(" -e, --debug Prints out debug information [default]\n"));
@@ -494,26 +507,26 @@ void freq_info_help(void) {
494 printf("\n"); 507 printf("\n");
495 printf(_("If no argument is given, full output about\n" 508 printf(_("If no argument is given, full output about\n"
496 "cpufreq is printed which is useful e.g. for reporting bugs.\n\n")); 509 "cpufreq is printed which is useful e.g. for reporting bugs.\n\n"));
497 printf(_("By default info of CPU 0 is shown which can be overridden \n" 510 printf(_("By default info of CPU 0 is shown which can be overridden\n"
498 "with the cpupower --cpu main command option.\n")); 511 "with the cpupower --cpu main command option.\n"));
499} 512}
500 513
501static struct option info_opts[] = { 514static struct option info_opts[] = {
502 { .name="debug", .has_arg=no_argument, .flag=NULL, .val='e'}, 515 { .name = "debug", .has_arg = no_argument, .flag = NULL, .val = 'e'},
503 { .name="boost", .has_arg=no_argument, .flag=NULL, .val='b'}, 516 { .name = "boost", .has_arg = no_argument, .flag = NULL, .val = 'b'},
504 { .name="freq", .has_arg=no_argument, .flag=NULL, .val='f'}, 517 { .name = "freq", .has_arg = no_argument, .flag = NULL, .val = 'f'},
505 { .name="hwfreq", .has_arg=no_argument, .flag=NULL, .val='w'}, 518 { .name = "hwfreq", .has_arg = no_argument, .flag = NULL, .val = 'w'},
506 { .name="hwlimits", .has_arg=no_argument, .flag=NULL, .val='l'}, 519 { .name = "hwlimits", .has_arg = no_argument, .flag = NULL, .val = 'l'},
507 { .name="driver", .has_arg=no_argument, .flag=NULL, .val='d'}, 520 { .name = "driver", .has_arg = no_argument, .flag = NULL, .val = 'd'},
508 { .name="policy", .has_arg=no_argument, .flag=NULL, .val='p'}, 521 { .name = "policy", .has_arg = no_argument, .flag = NULL, .val = 'p'},
509 { .name="governors", .has_arg=no_argument, .flag=NULL, .val='g'}, 522 { .name = "governors", .has_arg = no_argument, .flag = NULL, .val = 'g'},
510 { .name="related-cpus", .has_arg=no_argument, .flag=NULL, .val='r'}, 523 { .name = "related-cpus", .has_arg = no_argument, .flag = NULL, .val = 'r'},
511 { .name="affected-cpus",.has_arg=no_argument, .flag=NULL, .val='a'}, 524 { .name = "affected-cpus",.has_arg = no_argument, .flag = NULL, .val = 'a'},
512 { .name="stats", .has_arg=no_argument, .flag=NULL, .val='s'}, 525 { .name = "stats", .has_arg = no_argument, .flag = NULL, .val = 's'},
513 { .name="latency", .has_arg=no_argument, .flag=NULL, .val='y'}, 526 { .name = "latency", .has_arg = no_argument, .flag = NULL, .val = 'y'},
514 { .name="proc", .has_arg=no_argument, .flag=NULL, .val='o'}, 527 { .name = "proc", .has_arg = no_argument, .flag = NULL, .val = 'o'},
515 { .name="human", .has_arg=no_argument, .flag=NULL, .val='m'}, 528 { .name = "human", .has_arg = no_argument, .flag = NULL, .val = 'm'},
516 { .name="help", .has_arg=no_argument, .flag=NULL, .val='h'}, 529 { .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
517 { }, 530 { },
518}; 531};
519 532
@@ -572,7 +585,7 @@ int cmd_freq_info(int argc, char **argv)
572 fprintf(stderr, "invalid or unknown argument\n"); 585 fprintf(stderr, "invalid or unknown argument\n");
573 return EXIT_FAILURE; 586 return EXIT_FAILURE;
574 } 587 }
575 } while(cont); 588 } while (cont);
576 589
577 switch (output_param) { 590 switch (output_param) {
578 case 'o': 591 case 'o':
@@ -591,7 +604,7 @@ int cmd_freq_info(int argc, char **argv)
591 /* Default is: show output of CPU 0 only */ 604 /* Default is: show output of CPU 0 only */
592 if (bitmask_isallclear(cpus_chosen)) 605 if (bitmask_isallclear(cpus_chosen))
593 bitmask_setbit(cpus_chosen, 0); 606 bitmask_setbit(cpus_chosen, 0);
594 607
595 switch (output_param) { 608 switch (output_param) {
596 case -1: 609 case -1:
597 printf(_("You can't specify more than one --cpu parameter and/or\n" 610 printf(_("You can't specify more than one --cpu parameter and/or\n"
@@ -659,7 +672,7 @@ int cmd_freq_info(int argc, char **argv)
659 break; 672 break;
660 } 673 }
661 if (ret) 674 if (ret)
662 return (ret); 675 return ret;
663 } 676 }
664 return ret; 677 return ret;
665} 678}
diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c
index d415b6b52a09..5f783622bf31 100644
--- a/tools/power/cpupower/utils/cpufreq-set.c
+++ b/tools/power/cpupower/utils/cpufreq-set.c
@@ -43,12 +43,12 @@ void freq_set_help(void)
43} 43}
44 44
45static struct option set_opts[] = { 45static struct option set_opts[] = {
46 { .name="min", .has_arg=required_argument, .flag=NULL, .val='d'}, 46 { .name = "min", .has_arg = required_argument, .flag = NULL, .val = 'd'},
47 { .name="max", .has_arg=required_argument, .flag=NULL, .val='u'}, 47 { .name = "max", .has_arg = required_argument, .flag = NULL, .val = 'u'},
48 { .name="governor", .has_arg=required_argument, .flag=NULL, .val='g'}, 48 { .name = "governor", .has_arg = required_argument, .flag = NULL, .val = 'g'},
49 { .name="freq", .has_arg=required_argument, .flag=NULL, .val='f'}, 49 { .name = "freq", .has_arg = required_argument, .flag = NULL, .val = 'f'},
50 { .name="help", .has_arg=no_argument, .flag=NULL, .val='h'}, 50 { .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
51 { .name="related", .has_arg=no_argument, .flag=NULL, .val='r'}, 51 { .name = "related", .has_arg = no_argument, .flag = NULL, .val='r'},
52 { }, 52 { },
53}; 53};
54 54
@@ -64,7 +64,7 @@ static void print_error(void)
64}; 64};
65 65
66struct freq_units { 66struct freq_units {
67 char* str_unit; 67 char *str_unit;
68 int power_of_ten; 68 int power_of_ten;
69}; 69};
70 70
@@ -204,7 +204,8 @@ static int do_one_cpu(unsigned int cpu, struct cpufreq_policy *new_pol,
204 else if (new_pol->max) 204 else if (new_pol->max)
205 return cpufreq_modify_policy_max(cpu, new_pol->max); 205 return cpufreq_modify_policy_max(cpu, new_pol->max);
206 else if (new_pol->governor) 206 else if (new_pol->governor)
207 return cpufreq_modify_policy_governor(cpu, new_pol->governor); 207 return cpufreq_modify_policy_governor(cpu,
208 new_pol->governor);
208 209
209 default: 210 default:
210 /* slow path */ 211 /* slow path */
@@ -282,15 +283,15 @@ int cmd_freq_set(int argc, char **argv)
282 if ((strlen(optarg) < 3) || (strlen(optarg) > 18)) { 283 if ((strlen(optarg) < 3) || (strlen(optarg) > 18)) {
283 print_unknown_arg(); 284 print_unknown_arg();
284 return -EINVAL; 285 return -EINVAL;
285 } 286 }
286 if ((sscanf(optarg, "%s", gov)) != 1) { 287 if ((sscanf(optarg, "%s", gov)) != 1) {
287 print_unknown_arg(); 288 print_unknown_arg();
288 return -EINVAL; 289 return -EINVAL;
289 } 290 }
290 new_pol.governor = gov; 291 new_pol.governor = gov;
291 break; 292 break;
292 } 293 }
293 } while(cont); 294 } while (cont);
294 295
295 /* parameter checking */ 296 /* parameter checking */
296 if (double_parm) { 297 if (double_parm) {
@@ -339,7 +340,7 @@ int cmd_freq_set(int argc, char **argv)
339 /* loop over CPUs */ 340 /* loop over CPUs */
340 for (cpu = bitmask_first(cpus_chosen); 341 for (cpu = bitmask_first(cpus_chosen);
341 cpu <= bitmask_last(cpus_chosen); cpu++) { 342 cpu <= bitmask_last(cpus_chosen); cpu++) {
342 343
343 if (!bitmask_isbitset(cpus_chosen, cpu) || 344 if (!bitmask_isbitset(cpus_chosen, cpu) ||
344 cpufreq_cpu_exists(cpu)) 345 cpufreq_cpu_exists(cpu))
345 continue; 346 continue;
diff --git a/tools/power/cpupower/utils/cpuidle-info.c b/tools/power/cpupower/utils/cpuidle-info.c
index 635468224e74..70da3574f1e9 100644
--- a/tools/power/cpupower/utils/cpuidle-info.c
+++ b/tools/power/cpupower/utils/cpuidle-info.c
@@ -31,8 +31,7 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose)
31 if (idlestates == 0) { 31 if (idlestates == 0) {
32 printf(_("CPU %u: No idle states\n"), cpu); 32 printf(_("CPU %u: No idle states\n"), cpu);
33 return; 33 return;
34 } 34 } else if (idlestates <= 0) {
35 else if (idlestates <= 0) {
36 printf(_("CPU %u: Can't read idle state info\n"), cpu); 35 printf(_("CPU %u: Can't read idle state info\n"), cpu);
37 return; 36 return;
38 } 37 }
@@ -92,7 +91,7 @@ static void cpuidle_general_output(void)
92 } 91 }
93 92
94 printf(_("CPUidle driver: %s\n"), tmp); 93 printf(_("CPUidle driver: %s\n"), tmp);
95 free (tmp); 94 free(tmp);
96 95
97 tmp = sysfs_get_cpuidle_governor(); 96 tmp = sysfs_get_cpuidle_governor();
98 if (!tmp) { 97 if (!tmp) {
@@ -101,7 +100,7 @@ static void cpuidle_general_output(void)
101 } 100 }
102 101
103 printf(_("CPUidle governor: %s\n"), tmp); 102 printf(_("CPUidle governor: %s\n"), tmp);
104 free (tmp); 103 free(tmp);
105} 104}
106 105
107static void proc_cpuidle_cpu_output(unsigned int cpu) 106static void proc_cpuidle_cpu_output(unsigned int cpu)
@@ -117,8 +116,7 @@ static void proc_cpuidle_cpu_output(unsigned int cpu)
117 * printf(_("CPU %u: No C-states available\n"), cpu); 116 * printf(_("CPU %u: No C-states available\n"), cpu);
118 * return; 117 * return;
119 */ 118 */
120 } 119 } else if (cstates <= 0) {
121 else if (cstates <= 0) {
122 printf(_("CPU %u: Can't read C-state info\n"), cpu); 120 printf(_("CPU %u: Can't read C-state info\n"), cpu);
123 return; 121 return;
124 } 122 }
@@ -143,7 +141,8 @@ static void proc_cpuidle_cpu_output(unsigned int cpu)
143 141
144/* --freq / -f */ 142/* --freq / -f */
145 143
146void idle_info_help(void) { 144void idle_info_help(void)
145{
147 printf(_ ("Usage: cpupower idleinfo [options]\n")); 146 printf(_ ("Usage: cpupower idleinfo [options]\n"));
148 printf(_ ("Options:\n")); 147 printf(_ ("Options:\n"));
149 printf(_ (" -s, --silent Only show general C-state information\n")); 148 printf(_ (" -s, --silent Only show general C-state information\n"));
@@ -155,9 +154,9 @@ void idle_info_help(void) {
155} 154}
156 155
157static struct option info_opts[] = { 156static struct option info_opts[] = {
158 { .name="silent", .has_arg=no_argument, .flag=NULL, .val='s'}, 157 { .name = "silent", .has_arg = no_argument, .flag = NULL, .val = 's'},
159 { .name="proc", .has_arg=no_argument, .flag=NULL, .val='o'}, 158 { .name = "proc", .has_arg = no_argument, .flag = NULL, .val = 'o'},
160 { .name="help", .has_arg=no_argument, .flag=NULL, .val='h'}, 159 { .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
161 { }, 160 { },
162}; 161};
163 162
@@ -202,7 +201,7 @@ int cmd_idle_info(int argc, char **argv)
202 output_param = ret; 201 output_param = ret;
203 break; 202 break;
204 } 203 }
205 } while(cont); 204 } while (cont);
206 205
207 switch (output_param) { 206 switch (output_param) {
208 case -1: 207 case -1:
@@ -219,10 +218,10 @@ int cmd_idle_info(int argc, char **argv)
219 /* Default is: show output of CPU 0 only */ 218 /* Default is: show output of CPU 0 only */
220 if (bitmask_isallclear(cpus_chosen)) 219 if (bitmask_isallclear(cpus_chosen))
221 bitmask_setbit(cpus_chosen, 0); 220 bitmask_setbit(cpus_chosen, 0);
222 221
223 if (output_param == 0) 222 if (output_param == 0)
224 cpuidle_general_output(); 223 cpuidle_general_output();
225 224
226 for (cpu = bitmask_first(cpus_chosen); 225 for (cpu = bitmask_first(cpus_chosen);
227 cpu <= bitmask_last(cpus_chosen); cpu++) { 226 cpu <= bitmask_last(cpus_chosen); cpu++) {
228 227
@@ -241,5 +240,5 @@ int cmd_idle_info(int argc, char **argv)
241 break; 240 break;
242 } 241 }
243 } 242 }
244 return (EXIT_SUCCESS); 243 return EXIT_SUCCESS;
245} 244}
diff --git a/tools/power/cpupower/utils/cpupower-info.c b/tools/power/cpupower/utils/cpupower-info.c
index 7add04ccbad4..85253cb7600e 100644
--- a/tools/power/cpupower/utils/cpupower-info.c
+++ b/tools/power/cpupower/utils/cpupower-info.c
@@ -30,10 +30,10 @@ void info_help(void)
30} 30}
31 31
32static struct option set_opts[] = { 32static struct option set_opts[] = {
33 { .name="perf-bias", .has_arg=optional_argument, .flag=NULL, .val='b'}, 33 { .name = "perf-bias", .has_arg = optional_argument, .flag = NULL, .val = 'b'},
34 { .name="sched-mc", .has_arg=optional_argument, .flag=NULL, .val='m'}, 34 { .name = "sched-mc", .has_arg = optional_argument, .flag = NULL, .val = 'm'},
35 { .name="sched-smt", .has_arg=optional_argument, .flag=NULL, .val='s'}, 35 { .name = "sched-smt", .has_arg = optional_argument, .flag = NULL, .val = 's'},
36 { .name="help", .has_arg=no_argument, .flag=NULL, .val='h'}, 36 { .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
37 { }, 37 { },
38}; 38};
39 39
@@ -57,12 +57,11 @@ int cmd_info(int argc, char **argv)
57 int perf_bias:1; 57 int perf_bias:1;
58 }; 58 };
59 int params; 59 int params;
60
61 } params = {}; 60 } params = {};
62 int ret = 0; 61 int ret = 0;
63 62
64 setlocale(LC_ALL, ""); 63 setlocale(LC_ALL, "");
65 textdomain (PACKAGE); 64 textdomain(PACKAGE);
66 65
67 /* parameter parsing */ 66 /* parameter parsing */
68 while ((ret = getopt_long(argc, argv, "msbh", set_opts, NULL)) != -1) { 67 while ((ret = getopt_long(argc, argv, "msbh", set_opts, NULL)) != -1) {
@@ -105,7 +104,7 @@ int cmd_info(int argc, char **argv)
105 printf(_("not supported\n")); 104 printf(_("not supported\n"));
106 else 105 else
107 printf("%d\n", ret); 106 printf("%d\n", ret);
108 } 107 }
109 if (params.sched_smt) { 108 if (params.sched_smt) {
110 ret = sysfs_get_sched("smt"); 109 ret = sysfs_get_sched("smt");
111 printf(_("System's thread sibling scheduler setting: ")); 110 printf(_("System's thread sibling scheduler setting: "));
@@ -123,7 +122,7 @@ int cmd_info(int argc, char **argv)
123 if (params.perf_bias) { 122 if (params.perf_bias) {
124 if (!run_as_root) { 123 if (!run_as_root) {
125 params.perf_bias = 0; 124 params.perf_bias = 0;
126 printf (_("Intel's performance bias setting needs root privileges\n")); 125 printf(_("Intel's performance bias setting needs root privileges\n"));
127 } else if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS)) { 126 } else if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS)) {
128 printf(_("System does not support Intel's performance" 127 printf(_("System does not support Intel's performance"
129 " bias setting\n")); 128 " bias setting\n"));
@@ -134,7 +133,7 @@ int cmd_info(int argc, char **argv)
134 /* loop over CPUs */ 133 /* loop over CPUs */
135 for (cpu = bitmask_first(cpus_chosen); 134 for (cpu = bitmask_first(cpus_chosen);
136 cpu <= bitmask_last(cpus_chosen); cpu++) { 135 cpu <= bitmask_last(cpus_chosen); cpu++) {
137 136
138 if (!bitmask_isbitset(cpus_chosen, cpu) || 137 if (!bitmask_isbitset(cpus_chosen, cpu) ||
139 cpufreq_cpu_exists(cpu)) 138 cpufreq_cpu_exists(cpu))
140 continue; 139 continue;
diff --git a/tools/power/cpupower/utils/cpupower-set.c b/tools/power/cpupower/utils/cpupower-set.c
index 3f807bc7a567..bc1b391e46f0 100644
--- a/tools/power/cpupower/utils/cpupower-set.c
+++ b/tools/power/cpupower/utils/cpupower-set.c
@@ -30,10 +30,10 @@ void set_help(void)
30} 30}
31 31
32static struct option set_opts[] = { 32static struct option set_opts[] = {
33 { .name="perf-bias", .has_arg=optional_argument, .flag=NULL, .val='b'}, 33 { .name = "perf-bias", .has_arg = optional_argument, .flag = NULL, .val = 'b'},
34 { .name="sched-mc", .has_arg=optional_argument, .flag=NULL, .val='m'}, 34 { .name = "sched-mc", .has_arg = optional_argument, .flag = NULL, .val = 'm'},
35 { .name="sched-smt", .has_arg=optional_argument, .flag=NULL, .val='s'}, 35 { .name = "sched-smt", .has_arg = optional_argument, .flag = NULL, .val = 's'},
36 { .name="help", .has_arg=no_argument, .flag=NULL, .val='h'}, 36 { .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'},
37 { }, 37 { },
38}; 38};
39 39
@@ -57,17 +57,17 @@ int cmd_set(int argc, char **argv)
57 int perf_bias:1; 57 int perf_bias:1;
58 }; 58 };
59 int params; 59 int params;
60
61 } params; 60 } params;
62 int sched_mc = 0, sched_smt = 0, perf_bias = 0; 61 int sched_mc = 0, sched_smt = 0, perf_bias = 0;
63 int ret = 0; 62 int ret = 0;
64 63
65 setlocale(LC_ALL, ""); 64 setlocale(LC_ALL, "");
66 textdomain (PACKAGE); 65 textdomain(PACKAGE);
67 66
68 params.params = 0; 67 params.params = 0;
69 /* parameter parsing */ 68 /* parameter parsing */
70 while ((ret = getopt_long(argc, argv, "m:s:b:h", set_opts, NULL)) != -1) { 69 while ((ret = getopt_long(argc, argv, "m:s:b:h",
70 set_opts, NULL)) != -1) {
71 switch (ret) { 71 switch (ret) {
72 case 'h': 72 case 'h':
73 set_help(); 73 set_help();
@@ -135,7 +135,7 @@ int cmd_set(int argc, char **argv)
135 /* loop over CPUs */ 135 /* loop over CPUs */
136 for (cpu = bitmask_first(cpus_chosen); 136 for (cpu = bitmask_first(cpus_chosen);
137 cpu <= bitmask_last(cpus_chosen); cpu++) { 137 cpu <= bitmask_last(cpus_chosen); cpu++) {
138 138
139 if (!bitmask_isbitset(cpus_chosen, cpu) || 139 if (!bitmask_isbitset(cpus_chosen, cpu) ||
140 cpufreq_cpu_exists(cpu)) 140 cpufreq_cpu_exists(cpu))
141 continue; 141 continue;
diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c
index b048e5595359..5844ae0f786f 100644
--- a/tools/power/cpupower/utils/cpupower.c
+++ b/tools/power/cpupower/utils/cpupower.c
@@ -50,8 +50,8 @@ static struct cmd_struct commands[] = {
50 { "set", cmd_set, set_help, 1 }, 50 { "set", cmd_set, set_help, 1 },
51 { "info", cmd_info, info_help, 0 }, 51 { "info", cmd_info, info_help, 0 },
52 { "monitor", cmd_monitor, monitor_help, 0 }, 52 { "monitor", cmd_monitor, monitor_help, 0 },
53 { "help", cmd_help, print_help, 0 }, 53 { "help", cmd_help, print_help, 0 },
54 // { "bench", cmd_bench, NULL, 1 }, 54 /* { "bench", cmd_bench, NULL, 1 }, */
55}; 55};
56 56
57int cmd_help(int argc, const char **argv) 57int cmd_help(int argc, const char **argv)
@@ -95,8 +95,9 @@ static void print_help(void)
95 printf(_("\nUse cpupower help subcommand for getting help for above subcommands.\n")); 95 printf(_("\nUse cpupower help subcommand for getting help for above subcommands.\n"));
96} 96}
97 97
98static void print_version(void) { 98static void print_version(void)
99 printf(PACKAGE " " VERSION "\n"); 99{
100 printf(PACKAGE " " VERSION "\n");
100 printf(_("Report errors and bugs to %s, please.\n"), PACKAGE_BUGREPORT); 101 printf(_("Report errors and bugs to %s, please.\n"), PACKAGE_BUGREPORT);
101} 102}
102 103
@@ -109,10 +110,10 @@ static void handle_options(int *argc, const char ***argv)
109 110
110 for (x = 0; x < *argc && ((*argv)[x])[0] == '-'; x++) { 111 for (x = 0; x < *argc && ((*argv)[x])[0] == '-'; x++) {
111 const char *param = (*argv)[x]; 112 const char *param = (*argv)[x];
112 if (!strcmp(param, "-h") || !strcmp(param, "--help")){ 113 if (!strcmp(param, "-h") || !strcmp(param, "--help")) {
113 print_help(); 114 print_help();
114 exit(EXIT_SUCCESS); 115 exit(EXIT_SUCCESS);
115 } else if (!strcmp(param, "-c") || !strcmp(param, "--cpu")){ 116 } else if (!strcmp(param, "-c") || !strcmp(param, "--cpu")) {
116 if (*argc < 2) { 117 if (*argc < 2) {
117 print_help(); 118 print_help();
118 exit(EXIT_FAILURE); 119 exit(EXIT_FAILURE);
@@ -132,13 +133,14 @@ static void handle_options(int *argc, const char ***argv)
132 /* Cut out param: cpupower -c 1 info -> cpupower info */ 133 /* Cut out param: cpupower -c 1 info -> cpupower info */
133 new_argc += 2; 134 new_argc += 2;
134 continue; 135 continue;
135 } else if (!strcmp(param, "-v") || !strcmp(param, "--version")){ 136 } else if (!strcmp(param, "-v") ||
137 !strcmp(param, "--version")) {
136 print_version(); 138 print_version();
137 exit(EXIT_SUCCESS); 139 exit(EXIT_SUCCESS);
138#ifdef DEBUG 140#ifdef DEBUG
139 } else if (!strcmp(param, "-d") || !strcmp(param, "--debug")){ 141 } else if (!strcmp(param, "-d") || !strcmp(param, "--debug")) {
140 be_verbose = 1; 142 be_verbose = 1;
141 new_argc ++; 143 new_argc++;
142 continue; 144 continue;
143#endif 145#endif
144 } else { 146 } else {
@@ -171,7 +173,7 @@ int main(int argc, const char *argv[])
171 } 173 }
172 174
173 setlocale(LC_ALL, ""); 175 setlocale(LC_ALL, "");
174 textdomain (PACKAGE); 176 textdomain(PACKAGE);
175 177
176 /* Turn "perf cmd --help" into "perf help cmd" */ 178 /* Turn "perf cmd --help" into "perf help cmd" */
177 if (argc > 1 && !strcmp(argv[1], "--help")) { 179 if (argc > 1 && !strcmp(argv[1], "--help")) {