summaryrefslogtreecommitdiffstats
path: root/tools/power
diff options
context:
space:
mode:
authorPrarit Bhargava <prarit@redhat.com>2020-06-29 15:26:57 -0400
committerLen Brown <len.brown@intel.com>2020-09-03 13:57:47 -0400
commit8201a0285789fade1c5b031914577e2b27a64f05 (patch)
treeeb4994c870de72b430d38961b4aac0bb0e6bee17 /tools/power
parent9972d5d84d76982606806b2ce887f70c2f8ba60a (diff)
downloadlinux-8201a0285789fade1c5b031914577e2b27a64f05.tar.bz2
tools/power turbostat: Use sched_getcpu() instead of hardcoded cpu 0
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>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/x86/turbostat/turbostat.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 66c468262020..151a70f2311b 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -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);