cpupower-monitor fix error legs and remove hard-codes
Shuah Khan
maintainercover cpupower-monitor fix error legs and remove hard-codes
Two patch series fixes cpupower-monitor error legs to free cpu topology and replaces hard-coded topology depth values with defines.
Shuah Khan (2):
pm: cpupower: Fix cmd_monitor() error legs to free cpu_topology
pm: cpupower: remove hard-coded topology depth values
.../utils/idle_monitor/cpupower-monitor.c | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-)
Signature · 1 line
2.45.2
Shuah Khan
maintainerPATCH 1/2 pm: cpupower: Fix cmd_monitor() error legs to free cpu_topology
cmd_monitor() calls get_cpu_topology() to allocate memory for cpu topology and fails to release in error legs.
Fix it to call cpu_topology_release() from error legs.
--- tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++ 1 file changed, 2 insertions(+)
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +2 -0
@@ -427,11 +427,13 @@ int cmd_monitor(int argc, char **argv)if (avail_monitors ==0 ) {printf (_ ("No HW Cstate monitors found\n" )); +cpu_topology_release (cpu_top);return 1 ; }if (mode == list) {list_monitors (); +cpu_topology_release (cpu_top);exit (EXIT_SUCCESS ); }
Signature · 1 line
2.45.2
Shuah Khan
maintainerPATCH 2/2 pm: cpupower: remove hard-coded topology depth values
In reply to Shuah KhanRemove hard-coded topology depth values and replace them with defines to improve code readability and maintainability in cpupower-monitor code.
--- .../utils/idle_monitor/cpupower-monitor.c | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-)
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +29 -11
@@ -92,7 +92,11 @@ int fill_string_with_spaces(char *s, int n)return 0 ; } -#define MAX_COL_WIDTH 6 +#define MAX_COL_WIDTH 6 +#define TOPOLOGY_DEPTH_PKG 3 +#define TOPOLOGY_DEPTH_CORE 2 +#define TOPOLOGY_DEPTH_CPU 1 +void print_header (int topology_depth) {int unsigned mon;
@@ -114,12 +118,19 @@ void print_header(int topology_depth) }printf ("\n" ); -if (topology_depth >2 ) +switch (topology_depth) { +case TOPOLOGY_DEPTH_PKG :printf (" PKG|" ); -if (topology_depth >1 ) +break ; +case TOPOLOGY_DEPTH_CORE :printf ("CORE|" ); -if (topology_depth >0 ) +break ; +case TOPOLOGY_DEPTH_CPU :printf (" CPU|" ); +break ; +default : +return ; + }for (mon =0 ; mon < avail_monitors; mon++) {if (mon !=0 )
@@ -153,12 +164,19 @@ void print_results(int topology_depth, int cpu) cpu_top.core_info[cpu].pkg == -1)return ; -if (topology_depth >2 ) +switch (topology_depth) { +case TOPOLOGY_DEPTH_PKG :printf ("%4d|" , cpu_top.core_info[cpu].pkg); -if (topology_depth >1 ) +break ; +case TOPOLOGY_DEPTH_CORE :printf ("%4d|" , cpu_top.core_info[cpu].core); -if (topology_depth >0 ) +break ; +case TOPOLOGY_DEPTH_CPU :printf ("%4d|" , cpu_top.core_info[cpu].cpu); +break ; +default : +return ; + }for (mon =0 ; mon < avail_monitors; mon++) {if (mon !=0 )
@@ -454,15 +472,15 @@ int cmd_monitor(int argc, char **argv)/* ToDo: Topology parsing needs fixing first to do this more generically */ if (cpu_top.pkgs >1 ) -print_header (3 ); +print_header (TOPOLOGY_DEPTH_PKG );else -print_header (1 ); +print_header (TOPOLOGY_DEPTH_CPU );for (cpu =0 ; cpu < cpu_count; cpu++) {if (cpu_top.pkgs >1 ) -print_results (3 , cpu); +print_results (TOPOLOGY_DEPTH_PKG , cpu);else -print_results (1 , cpu); +print_results (TOPOLOGY_DEPTH_CPU , cpu); }for (num =0 ; num < avail_monitors; num++) {
Signature · 1 line
2.45.2