Skip to content

Commit

Permalink
tools/power turbostat: Use sched_getcpu() instead of hardcoded cpu 0
Browse files Browse the repository at this point in the history
Disabling cpu 0 results in an error

turbostat: /sys/devices/system/cpu/cpu0/topology/thread_siblings: open failed: No such file or directory

Use sched_getcpu() instead of a hardcoded cpu 0 to get the max cpu number.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Len Brown <len.brown@intel.com>
  • Loading branch information
Prarit Bhargava authored and Len Brown committed Sep 3, 2020
1 parent 9972d5d commit 8201a02
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/power/x86/turbostat/turbostat.c
Original file line number Diff line number Diff line change
@@ -2865,12 +2865,19 @@ void re_initialize(void)
void set_max_cpu_num(void)
{
FILE *filep;
int base_cpu;
unsigned long dummy;
char pathname[64];

base_cpu = sched_getcpu();
if (base_cpu < 0)
err(1, "cannot find calling cpu ID");
sprintf(pathname,
"/sys/devices/system/cpu/cpu%d/topology/thread_siblings",
base_cpu);

filep = fopen_or_die(pathname, "r");
topo.max_cpu_num = 0;
filep = fopen_or_die(
"/sys/devices/system/cpu/cpu0/topology/thread_siblings",
"r");
while (fscanf(filep, "%lx,", &dummy) == 1)
topo.max_cpu_num += BITMASK_SIZE;
fclose(filep);

0 comments on commit 8201a02

Please sign in to comment.