Skip to content

Commit 2c52f94

Browse files
committed
tools/power turbostat: Fix --cpu-set 0 regression on HT systems
"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: a2b4d0f ("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>
1 parent ce012c9 commit 2c52f94

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,11 +2427,17 @@ char *sys_lpi_file_debugfs = "/sys/kernel/debug/pmc_core/slp_s0_residency_usec";
24272427

24282428
int cpu_is_not_present(int cpu)
24292429
{
2430+
if (cpu < 0)
2431+
return 1;
2432+
24302433
return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
24312434
}
24322435

24332436
int cpu_is_not_allowed(int cpu)
24342437
{
2438+
if (cpu < 0)
2439+
return 1;
2440+
24352441
return !CPU_ISSET_S(cpu, cpu_allowed_setsize, cpu_allowed_set);
24362442
}
24372443

@@ -2473,9 +2479,12 @@ int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pk
24732479
int i;
24742480

24752481
for (i = MAX_HT_ID; i > 0; --i) { /* ht_id 0 is self */
2476-
if (cpus[cpu].ht_sibling_cpu_id[i] <= 0)
2482+
int sibling_cpu_id = cpus[cpu].ht_sibling_cpu_id[i];
2483+
2484+
if (cpu_is_not_allowed(sibling_cpu_id))
24772485
continue;
2478-
t = &thread_base[cpus[cpu].ht_sibling_cpu_id[i]];
2486+
2487+
t = &thread_base[sibling_cpu_id];
24792488

24802489
retval |= func(t, c, p);
24812490
}
@@ -6252,10 +6261,13 @@ int for_all_cpus_2(int (func) (struct thread_data *, struct core_data *,
62526261
int i;
62536262

62546263
for (i = MAX_HT_ID; i > 0; --i) { /* ht_id 0 is self */
6255-
if (cpus[cpu].ht_sibling_cpu_id[i] <= 0)
6264+
int sibling_cpu_id = cpus[cpu].ht_sibling_cpu_id[i];
6265+
6266+
if (cpu_is_not_allowed(sibling_cpu_id))
62566267
continue;
6257-
t = &thread_base[cpus[cpu].ht_sibling_cpu_id[i]];
6258-
t2 = &thread_base2[cpus[cpu].ht_sibling_cpu_id[i]];
6268+
6269+
t = &thread_base[sibling_cpu_id];
6270+
t2 = &thread_base2[sibling_cpu_id];
62596271

62606272
retval |= func(t, c, p, t2, c2, p2);
62616273
}

0 commit comments

Comments
 (0)