]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tools/power turbostat: Fix --cpu-set 0 regression on HT systems
authorLen Brown <len.brown@intel.com>
Thu, 16 Apr 2026 20:17:31 +0000 (16:17 -0400)
committerLen Brown <len.brown@intel.com>
Wed, 22 Apr 2026 15:31:57 +0000 (11:31 -0400)
"turbostat --cpu-set 0" appears to hang if cpu0 has an HT sibling.

This is because the initialization code recognizes that it does not
have to open perf files for the HT sibling, but the HT support
in the collection code sees the HT sibling and tries to read
from an uninitialized file descriptor, 0 (standard input).

Access HT siblings only when they are in the allowed set.

Fixes: a2b4d0f8bf07 ("tools/power turbostat: Favor cpu# over core#")
Signed-off-by: Len Brown <len.brown@intel.com>
Reported-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
tools/power/x86/turbostat/turbostat.c

index d6b4fd17c5f37df0ed771af75578fa268887d92d..7f61f07ceb31477f447fb04ab606385f5cd3eb0e 100644 (file)
@@ -2427,11 +2427,17 @@ char *sys_lpi_file_debugfs = "/sys/kernel/debug/pmc_core/slp_s0_residency_usec";
 
 int cpu_is_not_present(int cpu)
 {
+       if (cpu < 0)
+               return 1;
+
        return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
 }
 
 int cpu_is_not_allowed(int cpu)
 {
+       if (cpu < 0)
+               return 1;
+
        return !CPU_ISSET_S(cpu, cpu_allowed_setsize, cpu_allowed_set);
 }
 
@@ -2473,9 +2479,12 @@ int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pk
                int i;
 
                for (i = MAX_HT_ID; i > 0; --i) {       /* ht_id 0 is self */
-                       if (cpus[cpu].ht_sibling_cpu_id[i] <= 0)
+                       int sibling_cpu_id = cpus[cpu].ht_sibling_cpu_id[i];
+
+                       if (cpu_is_not_allowed(sibling_cpu_id))
                                continue;
-                       t = &thread_base[cpus[cpu].ht_sibling_cpu_id[i]];
+
+                       t = &thread_base[sibling_cpu_id];
 
                        retval |= func(t, c, p);
                }
@@ -6252,10 +6261,13 @@ int for_all_cpus_2(int (func) (struct thread_data *, struct core_data *,
                int i;
 
                for (i = MAX_HT_ID; i > 0; --i) {       /* ht_id 0 is self */
-                       if (cpus[cpu].ht_sibling_cpu_id[i] <= 0)
+                       int sibling_cpu_id = cpus[cpu].ht_sibling_cpu_id[i];
+
+                       if (cpu_is_not_allowed(sibling_cpu_id))
                                continue;
-                       t = &thread_base[cpus[cpu].ht_sibling_cpu_id[i]];
-                       t2 = &thread_base2[cpus[cpu].ht_sibling_cpu_id[i]];
+
+                       t = &thread_base[sibling_cpu_id];
+                       t2 = &thread_base2[sibling_cpu_id];
 
                        retval |= func(t, c, p, t2, c2, p2);
                }