Skip to content

Commit b6398bc

Browse files
dedekindlenb
authored andcommitted
tools/power turbostat: Fix --show/--hide for individual cpuidle counters
Problem: individual swidle counter names (C1, C1+, C1-, etc.) cannot be selected via --show/--hide due to two bugs in probe_cpuidle_counts(): 1. The function returns immediately when BIC_cpuidle is not enabled, without checking deferred_add_index. 2. The deferred name check runs against name_buf before the trailing newline is stripped, so is_deferred_add("C1\n") never matches "C1". Fix: 1. Relax the early return to pass through when deferred names are queued. 2. Strip the trailing newline from name_buf before performing deferred name checks. 3. Check each suffixed variant (C1+, C1, C1-) individually so that e.g. "--show C1+" enables only the requested metric. In addition, introduce a helper function to avoid repeating the condition (readability cleanup). Fixes: ec4acd3 ("tools/power turbostat: disable "cpuidle" invocation counters, by default") Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 23cb4f5 commit b6398bc

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11285,6 +11285,14 @@ void probe_cpuidle_residency(void)
1128511285
}
1128611286
}
1128711287

11288+
static bool cpuidle_counter_wanted(char *name)
11289+
{
11290+
if (is_deferred_skip(name))
11291+
return false;
11292+
11293+
return DO_BIC(BIC_cpuidle) || is_deferred_add(name);
11294+
}
11295+
1128811296
void probe_cpuidle_counts(void)
1128911297
{
1129011298
char path[64];
@@ -11294,7 +11302,7 @@ void probe_cpuidle_counts(void)
1129411302
int min_state = 1024, max_state = 0;
1129511303
char *sp;
1129611304

11297-
if (!DO_BIC(BIC_cpuidle))
11305+
if (!DO_BIC(BIC_cpuidle) && !deferred_add_index)
1129811306
return;
1129911307

1130011308
for (state = 10; state >= 0; --state) {
@@ -11309,12 +11317,6 @@ void probe_cpuidle_counts(void)
1130911317

1131011318
remove_underbar(name_buf);
1131111319

11312-
if (!DO_BIC(BIC_cpuidle) && !is_deferred_add(name_buf))
11313-
continue;
11314-
11315-
if (is_deferred_skip(name_buf))
11316-
continue;
11317-
1131811320
/* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */
1131911321
sp = strchr(name_buf, '-');
1132011322
if (!sp)
@@ -11329,16 +11331,19 @@ void probe_cpuidle_counts(void)
1132911331
* Add 'C1+' for C1, and so on. The 'below' sysfs file always contains 0 for
1133011332
* the last state, so do not add it.
1133111333
*/
11332-
1133311334
*sp = '+';
1133411335
*(sp + 1) = '\0';
11335-
sprintf(path, "cpuidle/state%d/below", state);
11336-
add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
11336+
if (cpuidle_counter_wanted(name_buf)) {
11337+
sprintf(path, "cpuidle/state%d/below", state);
11338+
add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
11339+
}
1133711340
}
1133811341

1133911342
*sp = '\0';
11340-
sprintf(path, "cpuidle/state%d/usage", state);
11341-
add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
11343+
if (cpuidle_counter_wanted(name_buf)) {
11344+
sprintf(path, "cpuidle/state%d/usage", state);
11345+
add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
11346+
}
1134211347

1134311348
/*
1134411349
* The 'above' sysfs file always contains 0 for the shallowest state (smallest
@@ -11347,8 +11352,10 @@ void probe_cpuidle_counts(void)
1134711352
if (state != min_state) {
1134811353
*sp = '-';
1134911354
*(sp + 1) = '\0';
11350-
sprintf(path, "cpuidle/state%d/above", state);
11351-
add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
11355+
if (cpuidle_counter_wanted(name_buf)) {
11356+
sprintf(path, "cpuidle/state%d/above", state);
11357+
add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
11358+
}
1135211359
}
1135311360
}
1135411361
}

0 commit comments

Comments
 (0)