[PATCH v2 3/3] perf tool: simplify checking active smt

From: Konstantin Khlebnikov
Date: Wed Apr 29 2020 - 12:23:48 EST


SMT now could be disabled via "/sys/devices/system/cpu/smt/control".
Status shown in "/sys/devices/system/cpu/smt/active" simply as "0" / "1".

If this knob isn't here then fallback to checking topology as before.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx>
---
tools/perf/util/smt.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/tools/perf/util/smt.c b/tools/perf/util/smt.c
index dc37b5abd1c3..c398528d1006 100644
--- a/tools/perf/util/smt.c
+++ b/tools/perf/util/smt.c
@@ -19,6 +19,9 @@ int smt_on(void)
if (cached)
return cached_result;

+ if (sysfs__read_int("devices/system/cpu/smt/active", &active) > 0)
+ goto done;
+
ncpu = sysconf(_SC_NPROCESSORS_CONF);
for (cpu = 0; cpu < ncpu; cpu++) {
char fn[256];
@@ -37,6 +40,7 @@ int smt_on(void)
active = str && (strchr(str, ',') != NULL || strchr(str, '-') != NULL);
free(str);

+done:
if (!cached) {
cached_result = active;
cached = true;