Skip to content

Commit ce512b8

Browse files
watologo1rafaeljw
authored andcommitted
cpupower: Do not analyse offlined cpus
Use sysfs_is_cpu_online(cpu) instead of cpufreq_cpu_exists(cpu) to detect offlined cpus. Re-arrange printfs slightly to have a consistent output even if you have multiple CPUs as output and even if offlined cores are in between. Signed-off-by: Thomas Renninger <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e51207f commit ce512b8

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

tools/power/cpupower/utils/cpufreq-info.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <getopt.h>
1515

1616
#include "cpufreq.h"
17+
#include "helpers/sysfs.h"
1718
#include "helpers/helpers.h"
1819
#include "helpers/bitmask.h"
1920

@@ -647,11 +648,14 @@ int cmd_freq_info(int argc, char **argv)
647648

648649
if (!bitmask_isbitset(cpus_chosen, cpu))
649650
continue;
650-
if (cpufreq_cpu_exists(cpu)) {
651-
printf(_("couldn't analyze CPU %d as it doesn't seem to be present\n"), cpu);
651+
652+
printf(_("analyzing CPU %d:\n"), cpu);
653+
654+
if (sysfs_is_cpu_online(cpu) != 1) {
655+
printf(_(" *is offline\n"));
656+
printf("\n");
652657
continue;
653658
}
654-
printf(_("analyzing CPU %d:\n"), cpu);
655659

656660
switch (output_param) {
657661
case 'b':
@@ -693,6 +697,7 @@ int cmd_freq_info(int argc, char **argv)
693697
}
694698
if (ret)
695699
return ret;
700+
printf("\n");
696701
}
697702
return ret;
698703
}

tools/power/cpupower/utils/cpuidle-info.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <stdlib.h>
1313
#include <string.h>
1414
#include <getopt.h>
15-
#include <cpufreq.h>
1615

1716
#include "helpers/helpers.h"
1817
#include "helpers/sysfs.h"
@@ -25,8 +24,6 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose)
2524
unsigned int idlestates, idlestate;
2625
char *tmp;
2726

28-
printf(_ ("Analyzing CPU %d:\n"), cpu);
29-
3027
idlestates = sysfs_get_idlestate_count(cpu);
3128
if (idlestates == 0) {
3229
printf(_("CPU %u: No idle states\n"), cpu);
@@ -71,7 +68,6 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose)
7168
printf(_("Duration: %llu\n"),
7269
sysfs_get_idlestate_time(cpu, idlestate));
7370
}
74-
printf("\n");
7571
}
7672

7773
static void cpuidle_general_output(void)
@@ -189,10 +185,17 @@ int cmd_idle_info(int argc, char **argv)
189185
for (cpu = bitmask_first(cpus_chosen);
190186
cpu <= bitmask_last(cpus_chosen); cpu++) {
191187

192-
if (!bitmask_isbitset(cpus_chosen, cpu) ||
193-
cpufreq_cpu_exists(cpu))
188+
if (!bitmask_isbitset(cpus_chosen, cpu))
194189
continue;
195190

191+
printf(_("analyzing CPU %d:\n"), cpu);
192+
193+
if (sysfs_is_cpu_online(cpu) != 1) {
194+
printf(_(" *is offline\n"));
195+
printf("\n");
196+
continue;
197+
}
198+
196199
switch (output_param) {
197200

198201
case 'o':
@@ -203,6 +206,7 @@ int cmd_idle_info(int argc, char **argv)
203206
cpuidle_cpu_output(cpu, verbose);
204207
break;
205208
}
209+
printf("\n");
206210
}
207211
return EXIT_SUCCESS;
208212
}

tools/power/cpupower/utils/cpupower-info.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <string.h>
1313
#include <getopt.h>
1414

15-
#include <cpufreq.h>
1615
#include "helpers/helpers.h"
1716
#include "helpers/sysfs.h"
1817

@@ -83,12 +82,16 @@ int cmd_info(int argc, char **argv)
8382
for (cpu = bitmask_first(cpus_chosen);
8483
cpu <= bitmask_last(cpus_chosen); cpu++) {
8584

86-
if (!bitmask_isbitset(cpus_chosen, cpu) ||
87-
cpufreq_cpu_exists(cpu))
85+
if (!bitmask_isbitset(cpus_chosen, cpu))
8886
continue;
8987

9088
printf(_("analyzing CPU %d:\n"), cpu);
9189

90+
if (sysfs_is_cpu_online(cpu) != 1){
91+
printf(_(" *is offline\n"));
92+
continue;
93+
}
94+
9295
if (params.perf_bias) {
9396
ret = msr_intel_get_perf_bias(cpu);
9497
if (ret < 0) {

tools/power/cpupower/utils/cpupower-set.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <string.h>
1313
#include <getopt.h>
1414

15-
#include <cpufreq.h>
1615
#include "helpers/helpers.h"
1716
#include "helpers/sysfs.h"
1817
#include "helpers/bitmask.h"
@@ -78,10 +77,15 @@ int cmd_set(int argc, char **argv)
7877
for (cpu = bitmask_first(cpus_chosen);
7978
cpu <= bitmask_last(cpus_chosen); cpu++) {
8079

81-
if (!bitmask_isbitset(cpus_chosen, cpu) ||
82-
cpufreq_cpu_exists(cpu))
80+
if (!bitmask_isbitset(cpus_chosen, cpu))
8381
continue;
8482

83+
if (sysfs_is_cpu_online(cpu) != 1){
84+
fprintf(stderr, _("Cannot set values on CPU %d:"), cpu);
85+
fprintf(stderr, _(" *is offline\n"));
86+
continue;
87+
}
88+
8589
if (params.perf_bias) {
8690
ret = msr_intel_set_perf_bias(cpu, perf_bias);
8791
if (ret) {

0 commit comments

Comments
 (0)