Skip to content

Commit 71cfd1d

Browse files
committed
tools/power/turbostat: Introduce cpu_allowed_set
Turbostat supports "-c" parameter which limits output to system summary plus the specified cpu-set. But some code still uses cpu_present_set to read and dump the counters. Introduce cpu_allowed_set for code that should obey the specified cpu-set. No functional change. Signed-off-by: Zhang Rui <[email protected]>
1 parent 6b74a30 commit 71cfd1d

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

tools/power/x86/turbostat/turbostat.c

+28-3
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ int backwards_count;
904904
char *progname;
905905

906906
#define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */
907-
cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset;
908-
size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size;
907+
cpu_set_t *cpu_present_set, *cpu_allowed_set, *cpu_affinity_set, *cpu_subset;
908+
size_t cpu_present_setsize, cpu_allowed_setsize, cpu_affinity_setsize, cpu_subset_size;
909909
#define MAX_ADDED_COUNTERS 8
910910
#define MAX_ADDED_THREAD_COUNTERS 24
911911
#define BITMASK_SIZE 32
@@ -1157,6 +1157,11 @@ int cpu_is_not_present(int cpu)
11571157
return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
11581158
}
11591159

1160+
int cpu_is_not_allowed(int cpu)
1161+
{
1162+
return !CPU_ISSET_S(cpu, cpu_allowed_setsize, cpu_allowed_set);
1163+
}
1164+
11601165
/*
11611166
* run func(thread, core, package) in topology order
11621167
* skip non-present cpus
@@ -3396,6 +3401,10 @@ void free_all_buffers(void)
33963401
cpu_present_set = NULL;
33973402
cpu_present_setsize = 0;
33983403

3404+
CPU_FREE(cpu_allowed_set);
3405+
cpu_allowed_set = NULL;
3406+
cpu_allowed_setsize = 0;
3407+
33993408
CPU_FREE(cpu_affinity_set);
34003409
cpu_affinity_set = NULL;
34013410
cpu_affinity_setsize = 0;
@@ -5697,13 +5706,29 @@ void topology_probe()
56975706
CPU_ZERO_S(cpu_present_setsize, cpu_present_set);
56985707
for_all_proc_cpus(mark_cpu_present);
56995708

5709+
/*
5710+
* Allocate and initialize cpu_allowed_set
5711+
*/
5712+
cpu_allowed_set = CPU_ALLOC((topo.max_cpu_num + 1));
5713+
if (cpu_allowed_set == NULL)
5714+
err(3, "CPU_ALLOC");
5715+
cpu_allowed_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
5716+
CPU_ZERO_S(cpu_allowed_setsize, cpu_allowed_set);
5717+
57005718
/*
57015719
* Validate that all cpus in cpu_subset are also in cpu_present_set
57025720
*/
57035721
for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) {
5704-
if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset))
5722+
if (!cpu_subset) {
5723+
if (CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set))
5724+
CPU_SET_S(i, cpu_allowed_setsize, cpu_allowed_set);
5725+
continue;
5726+
}
5727+
if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) {
57055728
if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set))
57065729
err(1, "cpu%d not present", i);
5730+
CPU_SET_S(i, cpu_allowed_setsize, cpu_allowed_set);
5731+
}
57075732
}
57085733

57095734
/*

0 commit comments

Comments
 (0)