cpupower: Provide online and offline CPU information
PATCH v2 1/1 cpupower: Provide online and offline CPU information
When a user tries to modify cpuidle or cpufreq properties on offline CPUs, the tool returns success (exit status 0) but also does not provide any warning message regarding offline cpus that may have been specified but left unchanged. In case of all or a few CPUs being offline, it can be difficult to keep track of which CPUs didn't get the new frequency or idle state set. Silent failures are difficult to keep track of when there are a huge number of CPUs on which the action is performed.
This patch adds helper functions to find both online and offline CPUs and print them out accordingly.
We use these helper functions in cpuidle-set and cpufreq-set to print an additional message if the user attempts to modify offline cpus.
--- tools/power/cpupower/utils/cpufreq-set.c | 3 + tools/power/cpupower/utils/cpuidle-set.c | 4 ++ tools/power/cpupower/utils/cpupower.c | 8 +++ tools/power/cpupower/utils/helpers/helpers.h | 12 ++++ tools/power/cpupower/utils/helpers/misc.c | 66 +++++++++++++++++++- 5 files changed, 92 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/cpufreq-set.c +3 -0
@@ -311,6 +311,7 @@ int cmd_freq_set(int argc, char **argv) } } +get_cpustate ();/* loop over CPUs */ for (cpu = bitmask_first(cpus_chosen);
@@ -328,5 +329,7 @@ int cmd_freq_set(int argc, char **argv) } } +print_offline_cpus (); +return 0 ; }
tools/power/cpupower/utils/cpuidle-set.c +4 -0
@@ -95,6 +95,8 @@ int cmd_idle_set(int argc, char **argv)exit (EXIT_FAILURE ); } +get_cpustate (); +/* Default is: set all CPUs */ if (bitmask_isallclear (cpus_chosen))bitmask_setall (cpus_chosen);
@@ -181,5 +183,7 @@ int cmd_idle_set(int argc, char **argv)break ; } } + +print_offline_cpus ();return EXIT_SUCCESS ; }
tools/power/cpupower/utils/cpupower.c +8 -0
@@ -34,6 +34,8 @@ int run_as_root;int base_cpu;/* Affected cpus chosen by -c/--cpu param */ struct bitmask *cpus_chosen; +struct bitmask *online_cpus; +struct bitmask *offline_cpus;#ifdef DEBUG int be_verbose;
@@ -178,6 +180,8 @@ int main(int argc, const char *argv[])char pathname[32 ]; cpus_chosen =bitmask_alloc (sysconf (_SC_NPROCESSORS_CONF)); + online_cpus =bitmask_alloc (sysconf (_SC_NPROCESSORS_CONF)); + offline_cpus =bitmask_alloc (sysconf (_SC_NPROCESSORS_CONF)); argc--; argv +=1 ;
@@ -230,6 +234,10 @@ int main(int argc, const char *argv[]) ret = p->main (argc, argv);if (cpus_chosen)bitmask_free (cpus_chosen); +if (online_cpus) +bitmask_free (online_cpus); +if (offline_cpus) +bitmask_free (offline_cpus);return ret; }print_help ();
tools/power/cpupower/utils/helpers/helpers.h +12 -0
@@ -94,6 +94,8 @@ struct cpupower_cpu_info {*/ extern int get_cpu_info (struct cpupower_cpu_info *cpu_info);extern struct cpupower_cpu_info cpupower_cpu_info; + +/* cpuid and cpuinfo helpers **************************/ /* X86 ONLY ****************************************/
@@ -171,4 +173,14 @@ static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };static inline unsigned int cpuid_edx (unsigned int op) {return 0 ; };#endif /* defined(__i386__) || defined(__x86_64__) */ +/* +* CPU State related functions +*/ +extern struct bitmask *online_cpus; +extern struct bitmask *offline_cpus; + +void get_cpustate (void ); +void get_cpustate (void ); +void get_cpustate (void ); +#endif /* __CPUPOWERUTILS_HELPERS__ */
tools/power/cpupower/utils/helpers/misc.c +65 -1
76 lines not on this page · raw message
Signature · 1 line
2.24.3 (Apple Git-128)
Shuah Khan
maintainerQuoted 16 lines · Brahadambal Srinivasan
When a user tries to modify cpuidle or cpufreq properties on offline CPUs, the tool returns success (exit status 0) but also does not provide any warning message regarding offline cpus that may have been specified but left unchanged. In case of all or a few CPUs being offline, it can be difficult to keep track of which CPUs didn't get the new frequency or idle state set. Silent failures are difficult to keep track of when there are a huge number of CPUs on which the action is performed.
This patch adds helper functions to find both online and offline CPUs and print them out accordingly.
We use these helper functions in cpuidle-set and cpufreq-set to print an additional message if the user attempts to modify offline cpus.
Reported-by Pavithra R. Prakash <[email protected]>Signed-off-by Brahadambal Srinivasan <[email protected]>
Quoted 8 lines
--- tools/power/cpupower/utils/cpufreq-set.c | 3 + tools/power/cpupower/utils/cpuidle-set.c | 4 ++ tools/power/cpupower/utils/cpupower.c | 8 +++ tools/power/cpupower/utils/helpers/helpers.h | 12 ++++ tools/power/cpupower/utils/helpers/misc.c | 66 +++++++++++++++++++- 5 files changed, 92 insertions(+), 1 deletion(-)
Please elaborate the changes made since v1.
I am seeing compile warnings. Please fix and send v3.
utils/cpufreq-set.c: In function ‘cmd_freq_set’:utils/cpufreq-set.c:332:2: warning: implicit declaration of function ‘print_offline_cpus’ [-Wimplicit-function-declaration]
332 | print_offline_cpus();
| ^~~~~~~~~~~~~~~~~~
CC utils/cpupower-set.o
CC utils/cpupower-info.o
CC utils/cpuidle-info.o
CC utils/cpuidle-set.outils/cpuidle-set.c: In function ‘cmd_idle_set’:utils/cpuidle-set.c:187:2: warning: implicit declaration of function ‘print_offline_cpus’ [-Wimplicit-function-declaration]
187 | print_offline_cpus();
thanks,
-- Shuah