mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lin Ming <ming.m.lin@intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@elte.hu>, Andi Kleen <andi@firstfloor.org>,
	Stephane Eranian <eranian@google.com>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 4/4] perf tool: Get PMU type id from sysfs
Date: Thu, 30 Jun 2011 08:09:56 +0000	[thread overview]
Message-ID: <1309421396-17438-5-git-send-email-ming.m.lin@intel.com> (raw)
In-Reply-To: <1309421396-17438-1-git-send-email-ming.m.lin@intel.com>

PMU type id can be allocated dynamically, for example

$ perf stat -e uncore:r0101 ls

$ cat /sys/bus/event_source/devices/uncore/type 
6

Uncore pmu type is read from sysfs and set into attr->type.

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
---
 tools/perf/util/parse-events.c |   55 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 41982c3..6cbbeda 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -684,7 +684,7 @@ parse_symbolic_event(const char **strp, struct perf_event_attr *attr)
 }
 
 static enum event_result
-parse_raw_event(const char **strp, struct perf_event_attr *attr)
+parse_raw_config(const char **strp, struct perf_event_attr *attr)
 {
 	const char *str = *strp;
 	u64 config;
@@ -695,7 +695,6 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr)
 	n = hex2u64(str + 1, &config);
 	if (n > 0) {
 		*strp = str + n + 1;
-		attr->type = PERF_TYPE_RAW;
 		attr->config = config;
 		return EVT_HANDLED;
 	}
@@ -703,6 +702,54 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr)
 }
 
 static enum event_result
+parse_raw_event(const char **strp, struct perf_event_attr *attr)
+{
+	if (parse_raw_config(strp, attr) != EVT_HANDLED)
+		return EVT_FAILED;
+
+	attr->type = PERF_TYPE_RAW;
+	return EVT_HANDLED;
+}
+
+#define EVENT_SOURCE_DIR "/sys/bus/event_source/devices"
+
+static enum event_result
+parse_sysfs_event(const char **strp, struct perf_event_attr *attr)
+{
+	char *pmu_name;
+	char evt_path[MAXPATHLEN];
+	char type_buf[4];
+	u64 type;
+	int fd;
+
+	pmu_name = strchr(*strp, ':');
+	if (!pmu_name)
+		return EVT_FAILED;
+
+	pmu_name = strndup(*strp, pmu_name - *strp);
+
+	snprintf(evt_path, MAXPATHLEN, "%s/%s/type", EVENT_SOURCE_DIR,
+		 pmu_name);
+
+	fd = open(evt_path, O_RDONLY);
+	if (fd < 0)
+		return EVT_FAILED;
+
+	if (read(fd, type_buf, sizeof(type_buf)) < 0) {
+		close(fd);
+		return EVT_FAILED;
+	}
+
+	close(fd);
+	type = atoll(type_buf);
+	attr->type = type;
+	*strp += strlen(pmu_name) + 1; /* + 1 for the ':' */
+	free(pmu_name);
+
+	return parse_raw_config(strp, attr);
+}
+
+static enum event_result
 parse_numeric_event(const char **strp, struct perf_event_attr *attr)
 {
 	const char *str = *strp;
@@ -783,6 +830,10 @@ parse_event_symbols(const struct option *opt, const char **str,
 {
 	enum event_result ret;
 
+	ret = parse_sysfs_event(str, attr);
+	if (ret != EVT_FAILED)
+		goto modifier;
+
 	ret = parse_tracepoint_event(opt, str, attr);
 	if (ret != EVT_FAILED)
 		goto modifier;
-- 
1.7.5.1


  parent reply	other threads:[~2011-06-30  8:04 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-30  8:09 [PATCH 0/4] perf: Intel uncore pmu counting support Lin Ming
2011-06-30  8:09 ` [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu Lin Ming
2011-06-30 14:08   ` Peter Zijlstra
2011-07-01  6:05     ` Lin Ming
2011-06-30 16:58   ` Andi Kleen
2011-07-04  6:39     ` Lin Ming
2011-07-04  8:38       ` Peter Zijlstra
2011-07-04 21:57       ` Andi Kleen
2011-07-05 11:22         ` Peter Zijlstra
2011-07-05 12:48           ` Lin Ming
2011-07-05 12:56             ` Peter Zijlstra
2011-07-05 13:13               ` Lin Ming
2011-07-05 16:01           ` Andi Kleen
2011-07-06  9:35             ` Ingo Molnar
2011-06-30  8:09 ` [PATCH 2/4] perf, x86: Add Intel SandyBridge " Lin Ming
2011-06-30 22:09   ` Peter Zijlstra
2011-06-30  8:09 ` [PATCH 3/4] perf: Remove perf_event_attr::type check Lin Ming
2011-07-21 19:31   ` [tip:perf/core] " tip-bot for Lin Ming
2011-06-30  8:09 ` Lin Ming [this message]
2011-06-30 12:10 ` [PATCH 0/4] perf: Intel uncore pmu counting support Stephane Eranian
2011-06-30 14:10   ` Peter Zijlstra
2011-06-30 16:27   ` Stephane Eranian
2011-07-01  3:17     ` Lin Ming
2011-07-01 10:49       ` Stephane Eranian
2011-07-01 12:23         ` Stephane Eranian
2011-07-01 12:28           ` Stephane Eranian
2011-07-04  6:03         ` Lin Ming
2011-07-01  5:49   ` Lin Ming
2011-07-01 11:08 ` Ingo Molnar

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=1309421396-17438-5-git-send-email-ming.m.lin@intel.com \
    --to=ming.m.lin@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=andi@firstfloor.org \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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

Powered by JetHome