Commit cf4957f17f2a89984915ea808876d9c82225b862

Authored by Jiri Olsa
Committed by Arnaldo Carvalho de Melo
1 parent 93786a5f6a

perf: Add PERF_EVENT_IOC_ID ioctl to return event ID

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>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-v1bn5cto707jn0bon34afqr1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Showing 2 changed files with 10 additions and 0 deletions Side-by-side Diff

include/uapi/linux/perf_event.h
... ... @@ -321,6 +321,7 @@
321 321 #define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64)
322 322 #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
323 323 #define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
  324 +#define PERF_EVENT_IOC_ID _IOR('$', 7, u64 *)
324 325  
325 326 enum perf_event_ioc_flags {
326 327 PERF_IOC_FLAG_GROUP = 1U << 0,
kernel/events/core.c
... ... @@ -3568,6 +3568,15 @@
3568 3568 case PERF_EVENT_IOC_PERIOD:
3569 3569 return perf_event_period(event, (u64 __user *)arg);
3570 3570  
  3571 + case PERF_EVENT_IOC_ID:
  3572 + {
  3573 + u64 id = primary_event_id(event);
  3574 +
  3575 + if (copy_to_user((void __user *)arg, &id, sizeof(id)))
  3576 + return -EFAULT;
  3577 + return 0;
  3578 + }
  3579 +
3571 3580 case PERF_EVENT_IOC_SET_OUTPUT:
3572 3581 {
3573 3582 int ret;