cpupower: Provide online and offline CPU information
PATCH v3 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.
In v1 of this patch, I had sent tried to address this with repetitive code in both cpufreq-set and cpuidle-set. V2 incorporated the review comments and added helper functions to find both online and offline CPUs and print them out accordingly. Correcting compile issues in v3.
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 print_online_cpus (void ); +void print_offline_cpus (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.27.0
Shuah Khan
maintainerQuoted 8 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 fllowing text shouldn't be part of the change log. This type of version to version change text is added between the --- and start of diff.
Quoted 10 lines
In v1 of this patch, I had sent tried to address this with repetitive code in both cpufreq-set and cpuidle-set. V2 incorporated the review comments and added helper functions to find both online and offline CPUs and print them out accordingly. Correcting compile issues in v3.
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(-)
Add revision changes here.
tools/power/cpupower/utils/cpufreq-set.c
Quoted 4 lines
tools/power/cpupower/utils/cpufreq-set.c +0
-0
thanks,
-- Shuah