[PATCH 4/5] perf: add 'keep tracking' flag to PERF_EVENT_IOC_DISABLE
From: Adrian Hunter
Date: Fri Jun 28 2013 - 09:17:31 EST
Make it possible to disable an event but continue to receive
"tracking" events i.e. continue to receive mmap, comm, task events.
The flag is updated by both PERF_EVENT_IOC_DISABLE and
PERF_EVENT_IOC_ENABLE. The flag is cleared by prctl
PR_TASK_PERF_EVENTS_DISABLE.
Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
---
include/linux/perf_event.h | 1 +
include/uapi/linux/perf_event.h | 1 +
kernel/events/core.c | 21 +++++++++++++++++++--
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 50b3efd..789eeeb 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -436,6 +436,7 @@ struct perf_event {
struct perf_cgroup *cgrp; /* cgroup event is attach to */
int cgrp_defer_enabled;
#endif
+ int keep_tracking;
#endif /* CONFIG_PERF_EVENTS */
};
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 663be3f..7b4ecfb 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -324,6 +324,7 @@ struct perf_event_attr {
enum perf_event_ioc_flags {
PERF_IOC_FLAG_GROUP = 1U << 0,
+ PERF_IOC_KEEP_TRACKING = 1U << 1,
};
/*
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1db3af9..0c1fbe9 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3495,6 +3495,16 @@ static inline int perf_fget_light(int fd, struct fd *p)
return 0;
}
+static void perf_event_keep_tracking(struct perf_event *event, u32 flags)
+{
+ int keep_tracking = !!(flags & PERF_IOC_KEEP_TRACKING);
+
+ if (flags & PERF_IOC_FLAG_GROUP)
+ event->group_leader->keep_tracking = keep_tracking;
+ else
+ event->keep_tracking = keep_tracking;
+}
+
static int perf_event_set_output(struct perf_event *event,
struct perf_event *output_event);
static int perf_event_set_filter(struct perf_event *event, void __user *arg);
@@ -3510,6 +3520,7 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
func = perf_event_enable;
break;
case PERF_EVENT_IOC_DISABLE:
+ perf_event_keep_tracking(event, flags);
func = perf_event_disable;
break;
case PERF_EVENT_IOC_RESET:
@@ -3552,6 +3563,9 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
else
perf_event_for_each_child(event, func);
+ if (cmd == PERF_EVENT_IOC_ENABLE)
+ perf_event_keep_tracking(event, flags);
+
return 0;
}
@@ -3572,8 +3586,10 @@ int perf_event_task_disable(void)
struct perf_event *event;
mutex_lock(¤t->perf_event_mutex);
- list_for_each_entry(event, ¤t->perf_event_list, owner_entry)
+ list_for_each_entry(event, ¤t->perf_event_list, owner_entry) {
perf_event_for_each_child(event, perf_event_disable);
+ event->keep_tracking = 0;
+ }
mutex_unlock(¤t->perf_event_mutex);
return 0;
@@ -4670,7 +4686,8 @@ perf_event_aux_ctx(struct perf_event_context *ctx,
struct perf_event *event;
list_for_each_entry_rcu(event, &ctx->event_list, event_entry) {
- if (event->state < PERF_EVENT_STATE_INACTIVE)
+ if (event->state < PERF_EVENT_STATE_INACTIVE &&
+ !event->keep_tracking)
continue;
if (!event_filter_match(event))
continue;
--
1.7.11.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/