]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tools/power turbostat: Process HT siblings in CPU order
authorLen Brown <len.brown@intel.com>
Wed, 22 Apr 2026 15:13:00 +0000 (11:13 -0400)
committerLen Brown <len.brown@intel.com>
Wed, 22 Apr 2026 15:31:57 +0000 (11:31 -0400)
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>
tools/power/x86/turbostat/turbostat.c

index f8e9aa8c9e541bb7dca453711527414e4f9ad0ba..d46878c63a80f278462fdfed193be107f128da70 100644 (file)
@@ -6219,55 +6219,6 @@ static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size)
        return 0;
 }
 
-int set_thread_siblings(struct cpu_topology *thiscpu)
-{
-       char path[80], character;
-       FILE *filep;
-       unsigned long map;
-       int so, shift, sib_core;
-       int cpu = thiscpu->cpu_id;
-       int offset = topo.max_cpu_num + 1;
-       size_t size;
-       int ht_id = 0;
-
-       thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1));
-       if (thiscpu->ht_id < 0)
-               thiscpu->ht_id = 0;     /* first CPU in core */
-       if (!thiscpu->put_ids)
-               return -1;
-
-       size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
-       CPU_ZERO_S(size, thiscpu->put_ids);
-
-       sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu);
-       filep = fopen(path, "r");
-
-       if (!filep) {
-               warnx("%s: open failed", path);
-               return -1;
-       }
-       do {
-               offset -= BITMASK_SIZE;
-               if (fscanf(filep, "%lx%c", &map, &character) != 2)
-                       err(1, "%s: failed to parse file", path);
-               for (shift = 0; shift < BITMASK_SIZE; shift++) {
-                       if ((map >> shift) & 0x1) {
-                               so = shift + offset;
-                               sib_core = get_core_id(so);
-                               if (sib_core == thiscpu->core_id) {
-                                       CPU_SET_S(so, size, thiscpu->put_ids);
-                                       cpus[so].ht_id = ht_id;
-                                       cpus[cpu].ht_sibling_cpu_id[ht_id] = so;
-                                       ht_id += 1;
-                               }
-                       }
-               }
-       } while (character == ',');
-       fclose(filep);
-
-       return CPU_COUNT_S(size, thiscpu->put_ids);
-}
-
 /*
  * run func(thread, core, package) in topology order
  * skip non-present cpus
@@ -9539,6 +9490,37 @@ int dir_filter(const struct dirent *dirp)
                return 0;
 }
 
+int set_thread_siblings(struct cpu_topology *thiscpu)
+{
+       char path[80];
+       int cpu = thiscpu->cpu_id;
+       size_t size;
+       int ht_id = 0;
+       int i;
+
+       thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1));
+       if (thiscpu->ht_id < 0)
+               thiscpu->ht_id = 0;     /* first CPU in core */
+       if (!thiscpu->put_ids)
+               return -1;
+
+       size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
+       CPU_ZERO_S(size, thiscpu->put_ids);
+
+       sprintf(path, "/sys/devices/system/cpu/cpu%d/topology", cpu);
+
+       initialize_cpu_set_from_sysfs(thiscpu->put_ids, path, "thread_siblings_list");
+
+       for (i = 0; i <= topo.max_cpu_num; ++i)
+               if (CPU_ISSET_S(i, size, thiscpu->put_ids)) {
+                       cpus[i].ht_id = ht_id;
+                       cpus[cpu].ht_sibling_cpu_id[ht_id] = i;
+                       ht_id += 1;
+               }
+
+       return (ht_id - 1);
+}
+
 void topology_probe(bool startup)
 {
        int i;