All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>
Subject: [PATCH 03/11] perf tool: Use PERF_EVENT_IOC_ID perf ioctl to read event id
Date: Sat, 20 Oct 2012 16:33:11 +0200	[thread overview]
Message-ID: <1350743599-4805-4-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1350743599-4805-1-git-send-email-jolsa@redhat.com>

Changing the way we retrieve the event ID. Instead of parsing out
the ID out of the read data, using the PERF_EVENT_IOC_ID ioctl.

Keeping the old way in place to support kernels without
PERF_EVENT_IOC_ID ioctl support.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/evlist.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 561bdfb..ef13aab 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -290,19 +290,33 @@ static int perf_evlist__id_add_fd(struct perf_evlist *evlist,
 				  struct perf_evsel *evsel,
 				  int cpu, int thread, int fd)
 {
-	u64 read_data[4] = { 0, };
-	int id_idx = 1; /* The first entry is the counter value */
+	u64 id;
+	int ret;
 
-	if (!(evsel->attr.read_format & PERF_FORMAT_ID) ||
-	    read(fd, &read_data, sizeof(read_data)) == -1)
-		return -1;
+	ret = ioctl(fd, PERF_EVENT_IOC_ID, &id);
+	if (!ret)
+		goto add;
+
+	/* Legacy way to get event id.. All hail to old kernels! */
+	if (errno == ENOTTY) {
+		u64 read_data[4] = { 0, };
+		int id_idx = 1; /* The first entry is the counter value */
+
+		if (!(evsel->attr.read_format & PERF_FORMAT_ID) ||
+		    read(fd, &read_data, sizeof(read_data)) == -1)
+			return -1;
 
-	if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
-		++id_idx;
-	if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
-		++id_idx;
+		if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
+			++id_idx;
+		if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
+			++id_idx;
+
+		id = read_data[id_idx];
+	} else if (errno)
+		return -1;
 
-	perf_evlist__id_add(evlist, evsel, cpu, thread, read_data[id_idx]);
+ add:
+	perf_evlist__id_add(evlist, evsel, cpu, thread, id);
 	return 0;
 }
 
-- 
1.7.11.4


  parent reply	other threads:[~2012-10-20 14:33 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-20 14:33 [PATCH 00/11] perf tool: Add PERF_SAMPLE_READ sample read support Jiri Olsa
2012-10-20 14:33 ` [PATCH 01/11] perf: Add PERF_EVENT_IOC_ID ioctl to return event ID Jiri Olsa
2012-10-20 14:33 ` [PATCH 02/11] perf: Do not get values from disabled counters in group format read Jiri Olsa
2012-10-23 16:13   ` Peter Zijlstra
2012-10-23 16:50     ` Jiri Olsa
2012-10-24 12:01       ` Peter Zijlstra
2012-10-24 12:14         ` Jiri Olsa
2012-10-24 12:32           ` Peter Zijlstra
2012-10-24 16:03           ` Jiri Olsa
2012-10-20 14:33 ` Jiri Olsa [this message]
2012-10-22  7:57   ` [PATCH 03/11] perf tool: Use PERF_EVENT_IOC_ID perf ioctl to read event id Namhyung Kim
2012-10-22  8:40     ` Jiri Olsa
2012-10-20 14:33 ` [PATCH 04/11] perf tool: Add support for parsing PERF_SAMPLE_READ sample type Jiri Olsa
2012-10-22  8:56   ` Namhyung Kim
2012-10-20 14:33 ` [PATCH 05/11] perf tool: Fix event ID retrieval for group format read case Jiri Olsa
2012-10-20 14:33 ` [PATCH 06/11] perf tool: Add perf_evlist__id2sid function to get event ID related data Jiri Olsa
2012-10-20 14:33 ` [PATCH 07/11] perf tool: Add PERF_SAMPLE_READ sample related processing Jiri Olsa
2012-10-20 14:33 ` [PATCH 08/11] perf tool: Add 'S' event/group modifier to read sample value Jiri Olsa
2012-10-20 14:33 ` [PATCH 09/11] perf test: Add parse events tests for leader sampling Jiri Olsa
2012-10-22  8:58   ` Namhyung Kim
2012-10-22  9:12     ` Jiri Olsa
2012-10-20 14:33 ` [PATCH 10/11] perf tool: Display period values for all group members Jiri Olsa
2012-10-20 14:33 ` [PATCH 11/11] perf record: Fix mmap error output condition Jiri Olsa
2012-10-30 12:11   ` [tip:perf/core] " tip-bot for Jiri Olsa
2012-10-21 16:38 ` [PATCH 00/11] perf tool: Add PERF_SAMPLE_READ sample read support Ingo Molnar
2012-10-22  8:09   ` Jiri Olsa
2012-10-22  8:51     ` Namhyung Kim
2012-10-22  9:15       ` Jiri Olsa
2012-10-22  7:32 ` Namhyung Kim
2012-10-22  7:53   ` Jiri Olsa
2012-10-22  8:53     ` Namhyung Kim
2012-10-22  9:06       ` Jiri Olsa
2012-10-26  1:29 ` Namhyung Kim
2012-10-26  9:14   ` Peter Zijlstra
2012-10-26 10:23     ` Jiri Olsa
2012-10-26 15:39       ` Namhyung Kim
2012-10-26 16:14         ` David Ahern
2012-10-26 16:25           ` Namhyung Kim
2012-10-26 16:47             ` David Ahern
2012-10-26 17:00         ` 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=1350743599-4805-4-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.