mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: acme@redhat.com, a.p.zijlstra@chello.nl, mingo@elte.hu,
	paulus@samba.org, cjashfor@linux.vnet.ibm.com,
	fweisbec@gmail.com
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
	andi@firstfloor.org, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCH 3/8] perf: Add PERF_EVENT_IOC_ID ioctl to return event ID
Date: Wed,  4 Apr 2012 23:16:11 +0200	[thread overview]
Message-ID: <1333574176-11388-4-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1333574176-11388-1-git-send-email-jolsa@redhat.com>

The only way to get the event ID is by reading the event fd,
followed by parsing the ID value out of the returned data.

While this is ok for current read format used by perf tool,
it is not ok when we use PERF_FORMAT_GROUP format.

With this format the data are returned for the whole group
and there's no way to find out what ID belongs to our fd
(if we are not group leader event).

Adding a simple ioctl that returns event primary ID for given fd.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 include/linux/perf_event.h |    1 +
 kernel/events/core.c       |    9 +++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index ddbb6a9..3173ae2 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -284,6 +284,7 @@ struct perf_event_attr {
 #define PERF_EVENT_IOC_PERIOD		_IOW('$', 4, __u64)
 #define PERF_EVENT_IOC_SET_OUTPUT	_IO ('$', 5)
 #define PERF_EVENT_IOC_SET_FILTER	_IOW('$', 6, char *)
+#define PERF_EVENT_IOC_ID		_IOR('$', 7, u64 *)
 
 enum perf_event_ioc_flags {
 	PERF_IOC_FLAG_GROUP		= 1U << 0,
diff --git a/kernel/events/core.c b/kernel/events/core.c
index a6a9ec4..3ef2a5f 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3266,6 +3266,15 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	case PERF_EVENT_IOC_PERIOD:
 		return perf_event_period(event, (u64 __user *)arg);
 
+	case PERF_EVENT_IOC_ID:
+	{
+		u64 id = primary_event_id(event);
+
+		if (copy_to_user((void __user *)arg, &id, sizeof(id)))
+			return -EFAULT;
+		return 0;
+	}
+
 	case PERF_EVENT_IOC_SET_OUTPUT:
 	{
 		struct perf_event *output_event = NULL;
-- 
1.7.7.6


  parent reply	other threads:[~2012-04-04 21:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-04 21:16 [RFCv2 0/8] perf tool: Add new event group management Jiri Olsa
2012-04-04 21:16 ` [PATCH 1/8] perf, tool: Add support to parse event group syntax Jiri Olsa
2012-04-04 21:16 ` [PATCH 2/8] perf, tool: Enable grouping logic for parsed events Jiri Olsa
2012-04-04 21:16 ` Jiri Olsa [this message]
2012-04-04 21:16 ` [PATCH 4/8] perf, tool: Use PERF_EVENT_IOC_ID perf ioctl to read event id Jiri Olsa
2012-04-04 21:16 ` [PATCH 5/8] perf, tool: Separate 'mem:' event scanner bits Jiri Olsa
2012-04-11 13:28   ` Robert Richter
2012-04-11 14:33     ` Jiri Olsa
2012-04-13 17:02       ` Robert Richter
2012-04-04 21:16 ` [PATCH 6/8] perf, tool: Add modifier support to group event syntax Jiri Olsa
2012-04-04 21:16 ` [PATCH 7/8] perf, tool: Add support for parsing PERF_SAMPLE_READ Jiri Olsa
2012-04-04 21:16 ` [PATCH 8/8] perf, tool: Enable sampling on specified event group leader Jiri Olsa
2012-04-04 21:21 ` [RFCv2 0/8] perf tool: Add new event group management Jiri Olsa
2012-04-15 15:16 ` Peter Zijlstra
2012-04-16 12:16   ` Jiri Olsa
2012-04-16 14:23     ` Peter Zijlstra
2012-04-16 15:26     ` Peter Zijlstra
2012-04-16 15:37       ` Jiri Olsa
2012-04-17  2:16         ` Namhyung Kim
2012-04-17  9:09       ` Namhyung Kim
2012-04-17  9:33         ` Jiri Olsa
2012-05-25 22:36 ` Andi Kleen
2012-05-26 12:38   ` Jiri Olsa
2012-05-26 19:23     ` Andi Kleen
2012-05-27  7:56     ` Ulrich Drepper
2012-05-27 15:08       ` Andi Kleen
2012-05-28 19:21       ` Jiri Olsa
2012-05-29  8:39       ` Peter Zijlstra

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=1333574176-11388-4-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    /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®