Skip to content

Commit 58839fd

Browse files
committed
tools/power turbostat: Process HT siblings in CPU order
On large systems with HT sibling cpu#'s more than 32 apart, HT siblings were processed and displayed in reverse order. This was due to how set_thread_siblings() parsed the sibling-bit-mask. Update set_thread_siblings to instead parse the sibling-list, like other cpu lists, and to thus order HT siblings by ascending CPU number, no matter the size of the system. Signed-off-by: Len Brown <len.brown@intel.com>
1 parent aea40f1 commit 58839fd

1 file changed

Lines changed: 31 additions & 49 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6219,55 +6219,6 @@ static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size)
62196219
return 0;
62206220
}
62216221

6222-
int set_thread_siblings(struct cpu_topology *thiscpu)
6223-
{
6224-
char path[80], character;
6225-
FILE *filep;
6226-
unsigned long map;
6227-
int so, shift, sib_core;
6228-
int cpu = thiscpu->cpu_id;
6229-
int offset = topo.max_cpu_num + 1;
6230-
size_t size;
6231-
int ht_id = 0;
6232-
6233-
thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1));
6234-
if (thiscpu->ht_id < 0)
6235-
thiscpu->ht_id = 0; /* first CPU in core */
6236-
if (!thiscpu->put_ids)
6237-
return -1;
6238-
6239-
size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
6240-
CPU_ZERO_S(size, thiscpu->put_ids);
6241-
6242-
sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu);
6243-
filep = fopen(path, "r");
6244-
6245-
if (!filep) {
6246-
warnx("%s: open failed", path);
6247-
return -1;
6248-
}
6249-
do {
6250-
offset -= BITMASK_SIZE;
6251-
if (fscanf(filep, "%lx%c", &map, &character) != 2)
6252-
err(1, "%s: failed to parse file", path);
6253-
for (shift = 0; shift < BITMASK_SIZE; shift++) {
6254-
if ((map >> shift) & 0x1) {
6255-
so = shift + offset;
6256-
sib_core = get_core_id(so);
6257-
if (sib_core == thiscpu->core_id) {
6258-
CPU_SET_S(so, size, thiscpu->put_ids);
6259-
cpus[so].ht_id = ht_id;
6260-
cpus[cpu].ht_sibling_cpu_id[ht_id] = so;
6261-
ht_id += 1;
6262-
}
6263-
}
6264-
}
6265-
} while (character == ',');
6266-
fclose(filep);
6267-
6268-
return CPU_COUNT_S(size, thiscpu->put_ids);
6269-
}
6270-
62716222
/*
62726223
* run func(thread, core, package) in topology order
62736224
* skip non-present cpus
@@ -9539,6 +9490,37 @@ int dir_filter(const struct dirent *dirp)
95399490
return 0;
95409491
}
95419492

9493+
int set_thread_siblings(struct cpu_topology *thiscpu)
9494+
{
9495+
char path[80];
9496+
int cpu = thiscpu->cpu_id;
9497+
size_t size;
9498+
int ht_id = 0;
9499+
int i;
9500+
9501+
thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1));
9502+
if (thiscpu->ht_id < 0)
9503+
thiscpu->ht_id = 0; /* first CPU in core */
9504+
if (!thiscpu->put_ids)
9505+
return -1;
9506+
9507+
size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
9508+
CPU_ZERO_S(size, thiscpu->put_ids);
9509+
9510+
sprintf(path, "/sys/devices/system/cpu/cpu%d/topology", cpu);
9511+
9512+
initialize_cpu_set_from_sysfs(thiscpu->put_ids, path, "thread_siblings_list");
9513+
9514+
for (i = 0; i <= topo.max_cpu_num; ++i)
9515+
if (CPU_ISSET_S(i, size, thiscpu->put_ids)) {
9516+
cpus[i].ht_id = ht_id;
9517+
cpus[cpu].ht_sibling_cpu_id[ht_id] = i;
9518+
ht_id += 1;
9519+
}
9520+
9521+
return (ht_id - 1);
9522+
}
9523+
95429524
void topology_probe(bool startup)
95439525
{
95449526
int i;

0 commit comments

Comments
 (0)