From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Dmitry Monakhov <dmtrmonakhov@yandex-team.ru>
Subject: [PATCH] perf tool: fix detection of active SMT
Date: Wed, 29 Apr 2020 13:00:39 +0300 [thread overview]
Message-ID: <158815443969.303706.11130341357699244442.stgit@buzz> (raw)
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 fallback to checking topology but fix couple bugs:
Check access("devices/system/cpu/cpu%d/topology/core_cpus", F_OK) fails,
unless current directory is "/sys". Simply try read this file first.
Cpu bitmap is split into 32 bit words. For system with more than 32 cores
threads are always in different words thus first word never has two bits:
cpu0: "0000,00000100,00000001", cpu 79: "8000,00000080,00000000".
Instead of parsing bitmap read "core_cpus_list" or "thread_siblings_list"
and simply check presence of ',' or '-' in it.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Fixes: de5077c4e38f ("perf tools: Add utility function to detect SMT status")
Fixes: 0ccdb8407a46 ("perf tools: Apply new CPU topology sysfs attributes")
---
tools/perf/util/smt.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/tools/perf/util/smt.c b/tools/perf/util/smt.c
index 3b791ef2cd50..c398528d1006 100644
--- a/tools/perf/util/smt.c
+++ b/tools/perf/util/smt.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
#include <linux/bitops.h>
#include "api/fs/fs.h"
#include "smt.h"
@@ -9,39 +10,39 @@ int smt_on(void)
{
static bool cached;
static int cached_result;
+ int active;
int cpu;
int ncpu;
+ char *str = NULL;
+ size_t strlen;
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++) {
- unsigned long long siblings;
- char *str;
- size_t strlen;
char fn[256];
- snprintf(fn, sizeof fn,
- "devices/system/cpu/cpu%d/topology/core_cpus", cpu);
- if (access(fn, F_OK) == -1) {
- snprintf(fn, sizeof fn,
- "devices/system/cpu/cpu%d/topology/thread_siblings",
- cpu);
- }
- if (sysfs__read_str(fn, &str, &strlen) < 0)
- continue;
- /* Entry is hex, but does not have 0x, so need custom parser */
- siblings = strtoull(str, NULL, 16);
- free(str);
- if (hweight64(siblings) > 1) {
- cached_result = 1;
- cached = true;
+ snprintf(fn, sizeof(fn), "devices/system/cpu/cpu%d/topology/%s",
+ cpu, "core_cpus_list");
+ if (sysfs__read_str(fn, &str, &strlen) > 0)
+ break;
+
+ snprintf(fn, sizeof(fn), "devices/system/cpu/cpu%d/topology/%s",
+ cpu, "thread_siblings_list");
+ if (sysfs__read_str(fn, &str, &strlen) > 0)
break;
- }
}
+
+ active = str && (strchr(str, ',') != NULL || strchr(str, '-') != NULL);
+ free(str);
+
+done:
if (!cached) {
- cached_result = 0;
+ cached_result = active;
cached = true;
}
return cached_result;
next reply other threads:[~2020-04-29 10:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 10:00 Konstantin Khlebnikov [this message]
2020-04-29 13:03 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=158815443969.303706.11130341357699244442.stgit@buzz \
--to=khlebnikov@yandex-team.ru \
--cc=acme@kernel.org \
--cc=dmtrmonakhov@yandex-team.ru \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®