Skip to content

Commit

Permalink
tools/power turbostat: set max_num_cpus equal to the cpumask length
Browse files Browse the repository at this point in the history
Future fixes will use sysfs files that contain cpumask output.  The code
needs to know the length of the cpumask in order to determine which cpus
are set in a cpumask.  Currently topo.max_cpu_num is the maximum cpu
number.  It can be increased the the maximum value of cpus represented in
cpumasks.

Set max_num_cpus to the length of a cpumask.

Signed-off-by: Prarit Bhargava <[email protected]>
Signed-off-by: Len Brown <[email protected]>
  • Loading branch information
prarit authored and lenb committed Jun 2, 2018
1 parent 023fe0a commit 843c579
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tools/power/x86/turbostat/turbostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2496,17 +2496,28 @@ void re_initialize(void)
printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus);
}

void set_max_cpu_num(void)
{
FILE *filep;
unsigned long dummy;

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 += 32;
fclose(filep);
topo.max_cpu_num--; /* 0 based */
}

/*
* count_cpus()
* remember the last one seen, it will be the max
*/
int count_cpus(int cpu)
{
if (topo.max_cpu_num < cpu)
topo.max_cpu_num = cpu;

topo.num_cpus += 1;
topo.num_cpus++;
return 0;
}
int mark_cpu_present(int cpu)
Expand Down Expand Up @@ -4564,8 +4575,8 @@ void topology_probe()
} *cpus;

/* Initialize num_cpus, max_cpu_num */
set_max_cpu_num();
topo.num_cpus = 0;
topo.max_cpu_num = 0;
for_all_proc_cpus(count_cpus);
if (!summary_only && topo.num_cpus > 1)
BIC_PRESENT(BIC_CPU);
Expand Down

0 comments on commit 843c579

Please sign in to comment.