Skip to content

Commit 562e5f1

Browse files
JacobTanenbaumrafaeljw
authored andcommitted
cpupower: rework the "cpupower frequency-info" command
this patch makes two changes to the way that "cpupower frequancy-info" operates 1. make it so that querying individual values always returns a message to the user currently cpupower frequency info doesn't return anything to the user when querying an individual value cannot be returned [root@amd-dinar-09 cpupower]# cpupower -c 4 frequency-info -d analyzing CPU 4: [root@amd-dinar-09 cpupower]# I added messages so that each query prints a message to the terminal [root@amd-dinar-09 cpupower]# ./cpupower -c 4 frequency-info -d analyzing CPU 4: no or unknown cpufreq driver is active on this CPU [root@amd-dinar-09 cpupower]# (this is just one example) 2. change debug_output_one() to use the functions already provided by cpufreq-info.c to query individual values of interest. Signed-off-by: Jacob Tanenbaum <[email protected]> Signed-off-by: Thomas Renninger <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ce512b8 commit 562e5f1

File tree

1 file changed

+88
-147
lines changed

1 file changed

+88
-147
lines changed

tools/power/cpupower/utils/cpufreq-info.c

Lines changed: 88 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -245,149 +245,21 @@ static int get_boost_mode(unsigned int cpu)
245245
return 0;
246246
}
247247

248-
static void debug_output_one(unsigned int cpu)
249-
{
250-
char *driver;
251-
struct cpufreq_affected_cpus *cpus;
252-
struct cpufreq_available_frequencies *freqs;
253-
unsigned long min, max, freq_kernel, freq_hardware;
254-
unsigned long total_trans, latency;
255-
unsigned long long total_time;
256-
struct cpufreq_policy *policy;
257-
struct cpufreq_available_governors *governors;
258-
struct cpufreq_stats *stats;
259-
260-
if (cpufreq_cpu_exists(cpu))
261-
return;
262-
263-
freq_kernel = cpufreq_get_freq_kernel(cpu);
264-
freq_hardware = cpufreq_get_freq_hardware(cpu);
265-
266-
driver = cpufreq_get_driver(cpu);
267-
if (!driver) {
268-
printf(_(" no or unknown cpufreq driver is active on this CPU\n"));
269-
} else {
270-
printf(_(" driver: %s\n"), driver);
271-
cpufreq_put_driver(driver);
272-
}
273-
274-
cpus = cpufreq_get_related_cpus(cpu);
275-
if (cpus) {
276-
printf(_(" CPUs which run at the same hardware frequency: "));
277-
while (cpus->next) {
278-
printf("%d ", cpus->cpu);
279-
cpus = cpus->next;
280-
}
281-
printf("%d\n", cpus->cpu);
282-
cpufreq_put_related_cpus(cpus);
283-
}
284-
285-
cpus = cpufreq_get_affected_cpus(cpu);
286-
if (cpus) {
287-
printf(_(" CPUs which need to have their frequency coordinated by software: "));
288-
while (cpus->next) {
289-
printf("%d ", cpus->cpu);
290-
cpus = cpus->next;
291-
}
292-
printf("%d\n", cpus->cpu);
293-
cpufreq_put_affected_cpus(cpus);
294-
}
295-
296-
latency = cpufreq_get_transition_latency(cpu);
297-
if (latency) {
298-
printf(_(" maximum transition latency: "));
299-
print_duration(latency);
300-
printf(".\n");
301-
}
302-
303-
if (!(cpufreq_get_hardware_limits(cpu, &min, &max))) {
304-
printf(_(" hardware limits: "));
305-
print_speed(min);
306-
printf(" - ");
307-
print_speed(max);
308-
printf("\n");
309-
}
310-
311-
freqs = cpufreq_get_available_frequencies(cpu);
312-
if (freqs) {
313-
printf(_(" available frequency steps: "));
314-
while (freqs->next) {
315-
print_speed(freqs->frequency);
316-
printf(", ");
317-
freqs = freqs->next;
318-
}
319-
print_speed(freqs->frequency);
320-
printf("\n");
321-
cpufreq_put_available_frequencies(freqs);
322-
}
323-
324-
governors = cpufreq_get_available_governors(cpu);
325-
if (governors) {
326-
printf(_(" available cpufreq governors: "));
327-
while (governors->next) {
328-
printf("%s, ", governors->governor);
329-
governors = governors->next;
330-
}
331-
printf("%s\n", governors->governor);
332-
cpufreq_put_available_governors(governors);
333-
}
334-
335-
policy = cpufreq_get_policy(cpu);
336-
if (policy) {
337-
printf(_(" current policy: frequency should be within "));
338-
print_speed(policy->min);
339-
printf(_(" and "));
340-
print_speed(policy->max);
341-
342-
printf(".\n ");
343-
printf(_("The governor \"%s\" may"
344-
" decide which speed to use\n within this range.\n"),
345-
policy->governor);
346-
cpufreq_put_policy(policy);
347-
}
348-
349-
if (freq_kernel || freq_hardware) {
350-
printf(_(" current CPU frequency is "));
351-
if (freq_hardware) {
352-
print_speed(freq_hardware);
353-
printf(_(" (asserted by call to hardware)"));
354-
} else
355-
print_speed(freq_kernel);
356-
printf(".\n");
357-
}
358-
stats = cpufreq_get_stats(cpu, &total_time);
359-
if (stats) {
360-
printf(_(" cpufreq stats: "));
361-
while (stats) {
362-
print_speed(stats->frequency);
363-
printf(":%.2f%%", (100.0 * stats->time_in_state) / total_time);
364-
stats = stats->next;
365-
if (stats)
366-
printf(", ");
367-
}
368-
cpufreq_put_stats(stats);
369-
total_trans = cpufreq_get_transitions(cpu);
370-
if (total_trans)
371-
printf(" (%lu)\n", total_trans);
372-
else
373-
printf("\n");
374-
}
375-
get_boost_mode(cpu);
376-
377-
}
378-
379248
/* --freq / -f */
380249

381250
static int get_freq_kernel(unsigned int cpu, unsigned int human)
382251
{
383252
unsigned long freq = cpufreq_get_freq_kernel(cpu);
384-
if (!freq)
253+
printf(_(" current CPU frequency: "));
254+
if (!freq) {
255+
printf(_(" Unable to call to kernel\n"));
385256
return -EINVAL;
257+
}
386258
if (human) {
387259
print_speed(freq);
388-
printf("\n");
389260
} else
390-
printf("%lu\n", freq);
261+
printf("%lu", freq);
262+
printf(_(" (asserted by call to kernel)\n"));
391263
return 0;
392264
}
393265

@@ -397,13 +269,16 @@ static int get_freq_kernel(unsigned int cpu, unsigned int human)
397269
static int get_freq_hardware(unsigned int cpu, unsigned int human)
398270
{
399271
unsigned long freq = cpufreq_get_freq_hardware(cpu);
400-
if (!freq)
272+
printf(_(" current CPU frequency: "));
273+
if (!freq) {
274+
printf("Unable to call hardware\n");
401275
return -EINVAL;
276+
}
402277
if (human) {
403278
print_speed(freq);
404-
printf("\n");
405279
} else
406-
printf("%lu\n", freq);
280+
printf("%lu", freq);
281+
printf(_(" (asserted by call to hardware)\n"));
407282
return 0;
408283
}
409284

@@ -412,9 +287,17 @@ static int get_freq_hardware(unsigned int cpu, unsigned int human)
412287
static int get_hardware_limits(unsigned int cpu)
413288
{
414289
unsigned long min, max;
415-
if (cpufreq_get_hardware_limits(cpu, &min, &max))
290+
291+
printf(_(" hardware limits: "));
292+
if (cpufreq_get_hardware_limits(cpu, &min, &max)) {
293+
printf(_("Not Available\n"));
416294
return -EINVAL;
417-
printf("%lu %lu\n", min, max);
295+
}
296+
297+
print_speed(min);
298+
printf(" - ");
299+
print_speed(max);
300+
printf("\n");
418301
return 0;
419302
}
420303

@@ -423,9 +306,11 @@ static int get_hardware_limits(unsigned int cpu)
423306
static int get_driver(unsigned int cpu)
424307
{
425308
char *driver = cpufreq_get_driver(cpu);
426-
if (!driver)
309+
if (!driver) {
310+
printf(_(" no or unknown cpufreq driver is active on this CPU\n"));
427311
return -EINVAL;
428-
printf("%s\n", driver);
312+
}
313+
printf(" driver: %s\n", driver);
429314
cpufreq_put_driver(driver);
430315
return 0;
431316
}
@@ -435,9 +320,19 @@ static int get_driver(unsigned int cpu)
435320
static int get_policy(unsigned int cpu)
436321
{
437322
struct cpufreq_policy *policy = cpufreq_get_policy(cpu);
438-
if (!policy)
323+
if (!policy) {
324+
printf(_(" Unable to determine current policy\n"));
439325
return -EINVAL;
440-
printf("%lu %lu %s\n", policy->min, policy->max, policy->governor);
326+
}
327+
printf(_(" current policy: frequency should be within "));
328+
print_speed(policy->min);
329+
printf(_(" and "));
330+
print_speed(policy->max);
331+
332+
printf(".\n ");
333+
printf(_("The governor \"%s\" may decide which speed to use\n"
334+
" within this range.\n"),
335+
policy->governor);
441336
cpufreq_put_policy(policy);
442337
return 0;
443338
}
@@ -448,8 +343,12 @@ static int get_available_governors(unsigned int cpu)
448343
{
449344
struct cpufreq_available_governors *governors =
450345
cpufreq_get_available_governors(cpu);
451-
if (!governors)
346+
347+
printf(_(" available cpufreq governors: "));
348+
if (!governors) {
349+
printf(_("Not Available\n"));
452350
return -EINVAL;
351+
}
453352

454353
while (governors->next) {
455354
printf("%s ", governors->governor);
@@ -466,8 +365,12 @@ static int get_available_governors(unsigned int cpu)
466365
static int get_affected_cpus(unsigned int cpu)
467366
{
468367
struct cpufreq_affected_cpus *cpus = cpufreq_get_affected_cpus(cpu);
469-
if (!cpus)
368+
369+
printf(_(" CPUs which need to have their frequency coordinated by software: "));
370+
if (!cpus) {
371+
printf(_("Not Available\n"));
470372
return -EINVAL;
373+
}
471374

472375
while (cpus->next) {
473376
printf("%d ", cpus->cpu);
@@ -483,8 +386,12 @@ static int get_affected_cpus(unsigned int cpu)
483386
static int get_related_cpus(unsigned int cpu)
484387
{
485388
struct cpufreq_affected_cpus *cpus = cpufreq_get_related_cpus(cpu);
486-
if (!cpus)
389+
390+
printf(_(" CPUs which run at the same hardware frequency: "));
391+
if (!cpus) {
392+
printf(_("Not Available\n"));
487393
return -EINVAL;
394+
}
488395

489396
while (cpus->next) {
490397
printf("%d ", cpus->cpu);
@@ -525,8 +432,12 @@ static int get_freq_stats(unsigned int cpu, unsigned int human)
525432
static int get_latency(unsigned int cpu, unsigned int human)
526433
{
527434
unsigned long latency = cpufreq_get_transition_latency(cpu);
528-
if (!latency)
435+
436+
printf(_(" maximum transition latency: "));
437+
if (!latency) {
438+
printf(_(" Cannot determine latency.\n"));
529439
return -EINVAL;
440+
}
530441

531442
if (human) {
532443
print_duration(latency);
@@ -536,6 +447,36 @@ static int get_latency(unsigned int cpu, unsigned int human)
536447
return 0;
537448
}
538449

450+
static void debug_output_one(unsigned int cpu)
451+
{
452+
struct cpufreq_available_frequencies *freqs;
453+
454+
get_driver(cpu);
455+
get_related_cpus(cpu);
456+
get_affected_cpus(cpu);
457+
get_latency(cpu, 1);
458+
get_hardware_limits(cpu);
459+
460+
freqs = cpufreq_get_available_frequencies(cpu);
461+
if (freqs) {
462+
printf(_(" available frequency steps: "));
463+
while (freqs->next) {
464+
print_speed(freqs->frequency);
465+
printf(", ");
466+
freqs = freqs->next;
467+
}
468+
print_speed(freqs->frequency);
469+
printf("\n");
470+
cpufreq_put_available_frequencies(freqs);
471+
}
472+
473+
get_available_governors(cpu);
474+
get_policy(cpu);
475+
if (get_freq_hardware(cpu, 1) < 0)
476+
get_freq_kernel(cpu, 1);
477+
get_boost_mode(cpu);
478+
}
479+
539480
static struct option info_opts[] = {
540481
{"debug", no_argument, NULL, 'e'},
541482
{"boost", no_argument, NULL, 'b'},

0 commit comments

Comments
 (0)