linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 04/15] perf tools: Add utility function to detect SMT status
Date: Wed, 23 Aug 2017 16:36:03 -0300	[thread overview]
Message-ID: <20170823193614.20394-5-acme@kernel.org> (raw)
In-Reply-To: <20170823193614.20394-1-acme@kernel.org>

From: Andi Kleen <ak@linux.intel.com>

Add an smt_on() function to return if SMT is enabled or disabled.  Used
in the next patch.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170811232634.30465-7-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/Build |  1 +
 tools/perf/util/smt.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/smt.h |  6 ++++++
 3 files changed, 51 insertions(+)
 create mode 100644 tools/perf/util/smt.c
 create mode 100644 tools/perf/util/smt.h

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8d49a989f193..94518c1bf8b6 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -22,6 +22,7 @@ libperf-y += rbtree.o
 libperf-y += libstring.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
+libperf-y += smt.o
 libperf-y += quote.o
 libperf-y += strbuf.o
 libperf-y += string.o
diff --git a/tools/perf/util/smt.c b/tools/perf/util/smt.c
new file mode 100644
index 000000000000..453f6f6f29f3
--- /dev/null
+++ b/tools/perf/util/smt.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <linux/bitops.h>
+#include "api/fs/fs.h"
+#include "smt.h"
+
+int smt_on(void)
+{
+	static bool cached;
+	static int cached_result;
+	int cpu;
+	int ncpu;
+
+	if (cached)
+		return cached_result;
+
+	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/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;
+			break;
+		}
+	}
+	if (!cached) {
+		cached_result = 0;
+		cached = true;
+	}
+	return cached_result;
+}
diff --git a/tools/perf/util/smt.h b/tools/perf/util/smt.h
new file mode 100644
index 000000000000..b8414b7bcbc8
--- /dev/null
+++ b/tools/perf/util/smt.h
@@ -0,0 +1,6 @@
+#ifndef SMT_H
+#define SMT_H 1
+
+int smt_on(void);
+
+#endif
-- 
2.13.5

  parent reply	other threads:[~2017-08-23 19:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 19:35 [GIT PULL 00/15] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 01/15] perf xyarray: Save max_x, max_y Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 02/15] perf evsel: Fix buffer overflow while freeing events Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 03/15] perf bpf: Tighten detection of BPF events Arnaldo Carvalho de Melo
2017-08-23 19:36 ` Arnaldo Carvalho de Melo [this message]
2017-08-23 19:36 ` [PATCH 05/15] perf tools: Expression parser enhancements for metrics Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 06/15] perf tools: Increase maximum number of events in expressions Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 07/15] perf tools: Dedup events in expression parsing Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 08/15] perf vendor events: Add core event list for Skylake Server Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 09/15] perf vendor events: Add Skylake server uncore event list Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 10/15] perf tools: Add support for printing new mem_info encodings Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 11/15] perf test: Add test cases for new data source encoding Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 12/15] perf tools: Really install manpages via 'make install-man' Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 13/15] perf: Fix documentation for sysctls perf_event_paranoid and perf_event_mlock_kb Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 14/15] perf tools: Fix static linking with libdw from elfutils Arnaldo Carvalho de Melo
2017-08-23 19:36 ` [PATCH 15/15] perf tools: Fix static linking with libunwind 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=20170823193614.20394-5-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.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;
as well as URLs for NNTP newsgroup(s).