Skip to content

Commit 0014f65

Browse files
committed
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/[email protected] Signed-off-by: Shuah Khan <[email protected]>
1 parent d52d2b3 commit 0014f65

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ int fill_string_with_spaces(char *s, int n)
9292
return 0;
9393
}
9494

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+
96100
void print_header(int topology_depth)
97101
{
98102
int unsigned mon;
@@ -114,12 +118,19 @@ void print_header(int topology_depth)
114118
}
115119
printf("\n");
116120

117-
if (topology_depth > 2)
121+
switch (topology_depth) {
122+
case TOPOLOGY_DEPTH_PKG:
118123
printf(" PKG|");
119-
if (topology_depth > 1)
124+
break;
125+
case TOPOLOGY_DEPTH_CORE:
120126
printf("CORE|");
121-
if (topology_depth > 0)
127+
break;
128+
case TOPOLOGY_DEPTH_CPU:
122129
printf(" CPU|");
130+
break;
131+
default:
132+
return;
133+
}
123134

124135
for (mon = 0; mon < avail_monitors; mon++) {
125136
if (mon != 0)
@@ -153,12 +164,19 @@ void print_results(int topology_depth, int cpu)
153164
cpu_top.core_info[cpu].pkg == -1)
154165
return;
155166

156-
if (topology_depth > 2)
167+
switch (topology_depth) {
168+
case TOPOLOGY_DEPTH_PKG:
157169
printf("%4d|", cpu_top.core_info[cpu].pkg);
158-
if (topology_depth > 1)
170+
break;
171+
case TOPOLOGY_DEPTH_CORE:
159172
printf("%4d|", cpu_top.core_info[cpu].core);
160-
if (topology_depth > 0)
173+
break;
174+
case TOPOLOGY_DEPTH_CPU:
161175
printf("%4d|", cpu_top.core_info[cpu].cpu);
176+
break;
177+
default:
178+
return;
179+
}
162180

163181
for (mon = 0; mon < avail_monitors; mon++) {
164182
if (mon != 0)
@@ -454,15 +472,15 @@ int cmd_monitor(int argc, char **argv)
454472
/* ToDo: Topology parsing needs fixing first to do
455473
this more generically */
456474
if (cpu_top.pkgs > 1)
457-
print_header(3);
475+
print_header(TOPOLOGY_DEPTH_PKG);
458476
else
459-
print_header(1);
477+
print_header(TOPOLOGY_DEPTH_CPU);
460478

461479
for (cpu = 0; cpu < cpu_count; cpu++) {
462480
if (cpu_top.pkgs > 1)
463-
print_results(3, cpu);
481+
print_results(TOPOLOGY_DEPTH_PKG, cpu);
464482
else
465-
print_results(1, cpu);
483+
print_results(TOPOLOGY_DEPTH_CPU, cpu);
466484
}
467485

468486
for (num = 0; num < avail_monitors; num++) {

0 commit comments

Comments
 (0)