Skip to content

Commit 7bb3fe2

Browse files
committed
tools/power/turbostat: Obey allowed CPUs during startup
Set turbostat CPU affinity to make sure turbostat is running on one of the allowed CPUs. Set base_cpu to the first allowed CPU so that some platform information is dumped using one of the allowed CPUs. Signed-off-by: Zhang Rui <[email protected]>
1 parent 4ede6d1 commit 7bb3fe2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tools/power/x86/turbostat/turbostat.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -5731,6 +5731,10 @@ void topology_probe()
57315731
}
57325732
}
57335733

5734+
if (!CPU_COUNT_S(cpu_allowed_setsize, cpu_allowed_set))
5735+
err(-ENODEV, "No valid cpus found");
5736+
sched_setaffinity(0, cpu_allowed_setsize, cpu_allowed_set);
5737+
57345738
/*
57355739
* Allocate and initialize cpu_affinity_set
57365740
*/
@@ -5941,12 +5945,17 @@ void setup_all_buffers(void)
59415945

59425946
void set_base_cpu(void)
59435947
{
5944-
base_cpu = sched_getcpu();
5945-
if (base_cpu < 0)
5946-
err(-ENODEV, "No valid cpus found");
5948+
int i;
59475949

5948-
if (debug > 1)
5949-
fprintf(outf, "base_cpu = %d\n", base_cpu);
5950+
for (i = 0; i < topo.max_cpu_num + 1; ++i) {
5951+
if (cpu_is_not_allowed(i))
5952+
continue;
5953+
base_cpu = i;
5954+
if (debug > 1)
5955+
fprintf(outf, "base_cpu = %d\n", base_cpu);
5956+
return;
5957+
}
5958+
err(-ENODEV, "No valid cpus found");
59505959
}
59515960

59525961
void turbostat_init()
@@ -5976,8 +5985,6 @@ int fork_it(char **argv)
59765985
first_counter_read = 0;
59775986
if (status)
59785987
exit(status);
5979-
/* clear affinity side-effect of get_counters() */
5980-
sched_setaffinity(0, cpu_present_setsize, cpu_present_set);
59815988
gettimeofday(&tv_even, (struct timezone *)NULL);
59825989

59835990
child_pid = fork();

0 commit comments

Comments
 (0)