Skip to contentSkip to conversation

perf: Add PERF_EVENT_IOC_ID ioctl to return event ID

tip:perf/core tip-bot for Jiri Olsa 1 participant 1 message Aug 12, 2013 perf events

lore
Share & tools
lore

tip-bot for Jiri Olsa

author merge bot
#0 lore raw
Commit-ID:  cf4957f17f2a89984915ea808876d9c82225b862
Gitweb:     http://git.kernel.org/tip/cf4957f17f2a89984915ea808876d9c82225b862
Author:     Jiri Olsa <[email protected]>
AuthorDate: Wed, 24 Oct 2012 13:37:58 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 7 Aug 2013 17:35:19 -0300

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.

---
 include/uapi/linux/perf_event.h | 1 +
 kernel/events/core.c            | 9 +++++++++
 2 files changed, 10 insertions(+)
include/uapi/linux/perf_event.h +1 -0
index efef1d3..62c25a2 100644
@@ -321,6 +321,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,
kernel/events/core.c +9 -0
index 916cf1f..5200b60 100644
@@ -3568,6 +3568,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:
 	{
 		int ret;