Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <jtanenba@redhat.com>
Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Jacob Tanenbaum and committed by
Rafael J. Wysocki
562e5f1a ce512b84

+88 -147
+88 -147
tools/power/cpupower/utils/cpufreq-info.c
··· 245 245 return 0; 246 246 } 247 247 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 - 379 248 /* --freq / -f */ 380 249 381 250 static int get_freq_kernel(unsigned int cpu, unsigned int human) 382 251 { 383 252 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")); 385 256 return -EINVAL; 257 + } 386 258 if (human) { 387 259 print_speed(freq); 388 - printf("\n"); 389 260 } else 390 - printf("%lu\n", freq); 261 + printf("%lu", freq); 262 + printf(_(" (asserted by call to kernel)\n")); 391 263 return 0; 392 264 } 393 265 ··· 269 397 static int get_freq_hardware(unsigned int cpu, unsigned int human) 270 398 { 271 399 unsigned long freq = cpufreq_get_freq_hardware(cpu); 272 - if (!freq) 400 + printf(_(" current CPU frequency: ")); 401 + if (!freq) { 402 + printf("Unable to call hardware\n"); 273 403 return -EINVAL; 404 + } 274 405 if (human) { 275 406 print_speed(freq); 276 - printf("\n"); 277 407 } else 278 - printf("%lu\n", freq); 408 + printf("%lu", freq); 409 + printf(_(" (asserted by call to hardware)\n")); 279 410 return 0; 280 411 } 281 412 ··· 287 412 static int get_hardware_limits(unsigned int cpu) 288 413 { 289 414 unsigned long min, max; 290 - if (cpufreq_get_hardware_limits(cpu, &min, &max)) 415 + 416 + printf(_(" hardware limits: ")); 417 + if (cpufreq_get_hardware_limits(cpu, &min, &max)) { 418 + printf(_("Not Available\n")); 291 419 return -EINVAL; 292 - printf("%lu %lu\n", min, max); 420 + } 421 + 422 + print_speed(min); 423 + printf(" - "); 424 + print_speed(max); 425 + printf("\n"); 293 426 return 0; 294 427 } 295 428 ··· 306 423 static int get_driver(unsigned int cpu) 307 424 { 308 425 char *driver = cpufreq_get_driver(cpu); 309 - if (!driver) 426 + if (!driver) { 427 + printf(_(" no or unknown cpufreq driver is active on this CPU\n")); 310 428 return -EINVAL; 311 - printf("%s\n", driver); 429 + } 430 + printf(" driver: %s\n", driver); 312 431 cpufreq_put_driver(driver); 313 432 return 0; 314 433 } ··· 320 435 static int get_policy(unsigned int cpu) 321 436 { 322 437 struct cpufreq_policy *policy = cpufreq_get_policy(cpu); 323 - if (!policy) 438 + if (!policy) { 439 + printf(_(" Unable to determine current policy\n")); 324 440 return -EINVAL; 325 - printf("%lu %lu %s\n", policy->min, policy->max, policy->governor); 441 + } 442 + printf(_(" current policy: frequency should be within ")); 443 + print_speed(policy->min); 444 + printf(_(" and ")); 445 + print_speed(policy->max); 446 + 447 + printf(".\n "); 448 + printf(_("The governor \"%s\" may decide which speed to use\n" 449 + " within this range.\n"), 450 + policy->governor); 326 451 cpufreq_put_policy(policy); 327 452 return 0; 328 453 } ··· 343 448 { 344 449 struct cpufreq_available_governors *governors = 345 450 cpufreq_get_available_governors(cpu); 346 - if (!governors) 451 + 452 + printf(_(" available cpufreq governors: ")); 453 + if (!governors) { 454 + printf(_("Not Available\n")); 347 455 return -EINVAL; 456 + } 348 457 349 458 while (governors->next) { 350 459 printf("%s ", governors->governor); ··· 365 466 static int get_affected_cpus(unsigned int cpu) 366 467 { 367 468 struct cpufreq_affected_cpus *cpus = cpufreq_get_affected_cpus(cpu); 368 - if (!cpus) 469 + 470 + printf(_(" CPUs which need to have their frequency coordinated by software: ")); 471 + if (!cpus) { 472 + printf(_("Not Available\n")); 369 473 return -EINVAL; 474 + } 370 475 371 476 while (cpus->next) { 372 477 printf("%d ", cpus->cpu); ··· 386 483 static int get_related_cpus(unsigned int cpu) 387 484 { 388 485 struct cpufreq_affected_cpus *cpus = cpufreq_get_related_cpus(cpu); 389 - if (!cpus) 486 + 487 + printf(_(" CPUs which run at the same hardware frequency: ")); 488 + if (!cpus) { 489 + printf(_("Not Available\n")); 390 490 return -EINVAL; 491 + } 391 492 392 493 while (cpus->next) { 393 494 printf("%d ", cpus->cpu); ··· 432 525 static int get_latency(unsigned int cpu, unsigned int human) 433 526 { 434 527 unsigned long latency = cpufreq_get_transition_latency(cpu); 435 - if (!latency) 528 + 529 + printf(_(" maximum transition latency: ")); 530 + if (!latency) { 531 + printf(_(" Cannot determine latency.\n")); 436 532 return -EINVAL; 533 + } 437 534 438 535 if (human) { 439 536 print_duration(latency); ··· 445 534 } else 446 535 printf("%lu\n", latency); 447 536 return 0; 537 + } 538 + 539 + static void debug_output_one(unsigned int cpu) 540 + { 541 + struct cpufreq_available_frequencies *freqs; 542 + 543 + get_driver(cpu); 544 + get_related_cpus(cpu); 545 + get_affected_cpus(cpu); 546 + get_latency(cpu, 1); 547 + get_hardware_limits(cpu); 548 + 549 + freqs = cpufreq_get_available_frequencies(cpu); 550 + if (freqs) { 551 + printf(_(" available frequency steps: ")); 552 + while (freqs->next) { 553 + print_speed(freqs->frequency); 554 + printf(", "); 555 + freqs = freqs->next; 556 + } 557 + print_speed(freqs->frequency); 558 + printf("\n"); 559 + cpufreq_put_available_frequencies(freqs); 560 + } 561 + 562 + get_available_governors(cpu); 563 + get_policy(cpu); 564 + if (get_freq_hardware(cpu, 1) < 0) 565 + get_freq_kernel(cpu, 1); 566 + get_boost_mode(cpu); 448 567 } 449 568 450 569 static struct option info_opts[] = {