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

pm: cpupower: remove hard-coded topology depth values

Remove hard-coded topology depth values and replace them with
defines to improve code readability and maintainability in
cpupower-monitor code.

Link: https://lore.kernel.org/r/20250305225342.19447-3-skhan@linuxfoundation.org
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

+29 -11
+29 -11
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
··· 92 92 return 0; 93 93 } 94 94 95 - #define MAX_COL_WIDTH 6 95 + #define MAX_COL_WIDTH 6 96 + #define TOPOLOGY_DEPTH_PKG 3 97 + #define TOPOLOGY_DEPTH_CORE 2 98 + #define TOPOLOGY_DEPTH_CPU 1 99 + 96 100 void print_header(int topology_depth) 97 101 { 98 102 int unsigned mon; ··· 118 114 } 119 115 printf("\n"); 120 116 121 - if (topology_depth > 2) 117 + switch (topology_depth) { 118 + case TOPOLOGY_DEPTH_PKG: 122 119 printf(" PKG|"); 123 - if (topology_depth > 1) 120 + break; 121 + case TOPOLOGY_DEPTH_CORE: 124 122 printf("CORE|"); 125 - if (topology_depth > 0) 123 + break; 124 + case TOPOLOGY_DEPTH_CPU: 126 125 printf(" CPU|"); 126 + break; 127 + default: 128 + return; 129 + } 127 130 128 131 for (mon = 0; mon < avail_monitors; mon++) { 129 132 if (mon != 0) ··· 164 153 cpu_top.core_info[cpu].pkg == -1) 165 154 return; 166 155 167 - if (topology_depth > 2) 156 + switch (topology_depth) { 157 + case TOPOLOGY_DEPTH_PKG: 168 158 printf("%4d|", cpu_top.core_info[cpu].pkg); 169 - if (topology_depth > 1) 159 + break; 160 + case TOPOLOGY_DEPTH_CORE: 170 161 printf("%4d|", cpu_top.core_info[cpu].core); 171 - if (topology_depth > 0) 162 + break; 163 + case TOPOLOGY_DEPTH_CPU: 172 164 printf("%4d|", cpu_top.core_info[cpu].cpu); 165 + break; 166 + default: 167 + return; 168 + } 173 169 174 170 for (mon = 0; mon < avail_monitors; mon++) { 175 171 if (mon != 0) ··· 472 454 /* ToDo: Topology parsing needs fixing first to do 473 455 this more generically */ 474 456 if (cpu_top.pkgs > 1) 475 - print_header(3); 457 + print_header(TOPOLOGY_DEPTH_PKG); 476 458 else 477 - print_header(1); 459 + print_header(TOPOLOGY_DEPTH_CPU); 478 460 479 461 for (cpu = 0; cpu < cpu_count; cpu++) { 480 462 if (cpu_top.pkgs > 1) 481 - print_results(3, cpu); 463 + print_results(TOPOLOGY_DEPTH_PKG, cpu); 482 464 else 483 - print_results(1, cpu); 465 + print_results(TOPOLOGY_DEPTH_CPU, cpu); 484 466 } 485 467 486 468 for (num = 0; num < avail_monitors; num++) {