27 unsigned int cpunr = 0;
29 fp = fopen(
"/proc/stat",
"r");
31 printf(
_(
"Couldn't count the number of CPUs (%s: %s), assuming 1\n"),
"/proc/stat",
strerror(
errno));
43 if (
sscanf(value,
"cpu%d ", &cpunr) != 1)
55 static void proc_cpufreq_output(
void)
59 unsigned int min_pctg = 0;
60 unsigned int max_pctg = 0;
63 printf(
_(
" minimum CPU frequency - maximum CPU frequency - governor\n"));
66 for (cpu = 0; cpu <
nr_cpus; cpu++) {
74 min_pctg = (policy->
min * 100) / max;
75 max_pctg = (policy->
max * 100) / max;
77 printf(
"CPU%3d %9lu kHz (%3d %%) - %9lu kHz (%3d %%) - %s\n",
78 cpu , policy->
min, max ? min_pctg : 0, policy->
max,
79 max ? max_pctg : 0, policy->
governor);
85 static void print_speed(
unsigned long speed)
89 if (speed > 1000000) {
93 printf(
"%u.%02u GHz", ((
unsigned int) speed/1000000),
94 ((
unsigned int) (speed%1000000)/10000));
95 }
else if (speed > 100000) {
99 printf(
"%u MHz", ((
unsigned int) speed / 1000));
100 }
else if (speed > 1000) {
104 printf(
"%u.%01u MHz", ((
unsigned int) speed/1000),
105 ((
unsigned int) (speed%1000)/100));
112 static void print_duration(
unsigned long duration)
116 if (duration > 1000000) {
117 tmp = duration % 10000;
120 printf(
"%u.%02u ms", ((
unsigned int) duration/1000000),
121 ((
unsigned int) (duration%1000000)/10000));
122 }
else if (duration > 100000) {
123 tmp = duration % 1000;
126 printf(
"%u us", ((
unsigned int) duration / 1000));
127 }
else if (duration > 1000) {
128 tmp = duration % 100;
131 printf(
"%u.%01u us", ((
unsigned int) duration/1000),
132 ((
unsigned int) (duration%1000)/100));
134 printf(
"%lu ns", duration);
141 static int get_boost_mode(
unsigned int cpu)
151 ret = cpufreq_has_boost_support(cpu, &support, &active, &b_states);
153 printf(
_(
"Error while evaluating Boost Capabilities"
154 " on CPU %d -- are you root?\n"), cpu);
163 printf(
_(
" boost state support:\n"));
165 printf(
_(
" Supported: %s\n"), support ?
_(
"yes") :
_(
"no"));
166 printf(
_(
" Active: %s\n"), active ?
_(
"yes") :
_(
"no"));
171 pstates, &pstate_no);
175 printf(
_(
" Boost States: %d\n"), b_states);
176 printf(
_(
" Total States: %d\n"), pstate_no);
177 for (i = 0; i < pstate_no; i++) {
179 printf(
_(
" Pstate-Pb%d: %luMHz (boost state)"
180 "\n"), i, pstates[i]);
182 printf(
_(
" Pstate-P%d: %luMHz\n"),
183 i - b_states, pstates[i]);
187 unsigned long long intel_turbo_ratio = 0;
195 intel_turbo_ratio = msr_intel_get_turbo_ratio(cpu);
196 dprint (
" Ratio: 0x%llx - bclk: %f\n",
197 intel_turbo_ratio, bclk);
199 ratio = (intel_turbo_ratio >> 24) & 0xFF;
201 printf(
_(
" %.0f MHz max turbo 4 active cores\n"),
204 ratio = (intel_turbo_ratio >> 16) & 0xFF;
206 printf(
_(
" %.0f MHz max turbo 3 active cores\n"),
209 ratio = (intel_turbo_ratio >> 8) & 0xFF;
211 printf(
_(
" %.0f MHz max turbo 2 active cores\n"),
214 ratio = (intel_turbo_ratio >> 0) & 0xFF;
216 printf(
_(
" %.0f MHz max turbo 1 active cores\n"),
222 static void debug_output_one(
unsigned int cpu)
227 unsigned long min,
max, freq_kernel, freq_hardware;
228 unsigned long total_trans,
latency;
229 unsigned long long total_time;
242 printf(
_(
" no or unknown cpufreq driver is active on this CPU\n"));
244 printf(
_(
" driver: %s\n"), driver);
250 printf(
_(
" CPUs which run at the same hardware frequency: "));
261 printf(
_(
" CPUs which need to have their frequency coordinated by software: "));
272 printf(
_(
" maximum transition latency: "));
273 print_duration(latency);
278 printf(
_(
" hardware limits: "));
287 printf(
_(
" available frequency steps: "));
288 while (freqs->
next) {
300 printf(
_(
" available cpufreq governors: "));
301 while (governors->
next) {
303 governors = governors->
next;
311 printf(
_(
" current policy: frequency should be within "));
312 print_speed(policy->
min);
314 print_speed(policy->
max);
317 printf(
_(
"The governor \"%s\" may"
318 " decide which speed to use\n within this range.\n"),
323 if (freq_kernel || freq_hardware) {
324 printf(
_(
" current CPU frequency is "));
326 print_speed(freq_hardware);
327 printf(
_(
" (asserted by call to hardware)"));
329 print_speed(freq_kernel);
345 printf(
" (%lu)\n", total_trans);
355 static int get_freq_kernel(
unsigned int cpu,
unsigned int human)
371 static int get_freq_hardware(
unsigned int cpu,
unsigned int human)
386 static int get_hardware_limits(
unsigned int cpu)
391 printf(
"%lu %lu\n", min, max);
397 static int get_driver(
unsigned int cpu)
409 static int get_policy(
unsigned int cpu)
421 static int get_available_governors(
unsigned int cpu)
428 while (governors->
next) {
430 governors = governors->
next;
440 static int get_affected_cpus(
unsigned int cpu)
457 static int get_related_cpus(
unsigned int cpu)
474 static int get_freq_stats(
unsigned int cpu,
unsigned int human)
477 unsigned long long total_time;
493 printf(
" (%lu)\n", total_trans);
499 static int get_latency(
unsigned int cpu,
unsigned int human)
506 print_duration(latency);
513 static struct option info_opts[] = {
514 { .name =
"debug", .has_arg = no_argument, .flag =
NULL, .val =
'e'},
515 { .name =
"boost", .has_arg = no_argument, .flag =
NULL, .val =
'b'},
516 { .name =
"freq", .has_arg = no_argument, .flag =
NULL, .val =
'f'},
517 { .name =
"hwfreq", .has_arg = no_argument, .flag =
NULL, .val =
'w'},
518 { .name =
"hwlimits", .has_arg = no_argument, .flag =
NULL, .val =
'l'},
519 { .name =
"driver", .has_arg = no_argument, .flag =
NULL, .val =
'd'},
520 { .name =
"policy", .has_arg = no_argument, .flag =
NULL, .val =
'p'},
521 { .name =
"governors", .has_arg = no_argument, .flag =
NULL, .val =
'g'},
522 { .name =
"related-cpus", .has_arg = no_argument, .flag =
NULL, .val =
'r'},
523 { .name =
"affected-cpus",.has_arg = no_argument, .flag =
NULL, .val =
'a'},
524 { .name =
"stats", .has_arg = no_argument, .flag =
NULL, .val =
's'},
525 { .name =
"latency", .has_arg = no_argument, .flag =
NULL, .val =
'y'},
526 { .name =
"proc", .has_arg = no_argument, .flag =
NULL, .val =
'o'},
527 { .name =
"human", .has_arg = no_argument, .flag =
NULL, .val =
'm'},
534 extern int optind, opterr, optopt;
536 unsigned int cpu = 0;
537 unsigned int human = 0;
538 int output_param = 0;
541 ret = getopt_long(argc, argv,
"oefwldpgrasmyb", info_opts,
NULL);
579 fprintf(stderr,
"invalid or unknown argument\n");
584 switch (output_param) {
587 printf(
_(
"The argument passed to this tool can't be "
588 "combined with passing a --cpu argument\n"));
602 switch (output_param) {
604 printf(
_(
"You can't specify more than one --cpu parameter and/or\n"
605 "more than one output-specific argument\n"));
608 printf(
_(
"invalid or unknown argument\n"));
611 proc_cpufreq_output();
621 printf(
_(
"couldn't analyze CPU %d as it doesn't seem to be present\n"), cpu);
624 printf(
_(
"analyzing CPU %d:\n"), cpu);
626 switch (output_param) {
631 debug_output_one(cpu);
634 ret = get_affected_cpus(cpu);
637 ret = get_related_cpus(cpu);
640 ret = get_available_governors(cpu);
643 ret = get_policy(cpu);
646 ret = get_driver(cpu);
649 ret = get_hardware_limits(cpu);
652 ret = get_freq_hardware(cpu, human);
655 ret = get_freq_kernel(cpu, human);
658 ret = get_freq_stats(cpu, human);
661 ret = get_latency(cpu, human);