[PATCH v3 20/46] perf/core: add pmu::event_terminate
From: David Carrillo-Cisneros
Date: Sat Oct 29 2016 - 20:47:27 EST
The new pmu::event_terminate allows a PMU to access an event's cgroup
before the event is torn down.
Used in CMT to dettach the cgroup from a monr before perf clears
event->cgrp.
Signed-off-by: David Carrillo-Cisneros <davidcc@xxxxxxxxxx>
---
include/linux/perf_event.h | 6 ++++++
kernel/events/core.c | 4 ++++
2 files changed, 10 insertions(+)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 406119b..14dff7a 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -298,6 +298,12 @@ struct pmu {
int (*event_init) (struct perf_event *event);
/*
+ * Terminate the event for this PMU. Optional complement for a
+ * successful event_init. Called before the event fields are tear down.
+ */
+ void (*event_terminate) (struct perf_event *event);
+
+ /*
* Notification that the event was mapped or unmapped. Called
* in the context of the mapping task.
*/
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0de3ca5..464f46d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4005,6 +4005,8 @@ static void _free_event(struct perf_event *event)
ring_buffer_attach(event, NULL);
mutex_unlock(&event->mmap_mutex);
}
+ if (event->pmu->event_terminate)
+ event->pmu->event_terminate(event);
if (is_cgroup_event(event))
perf_detach_cgroup(event);
@@ -9226,6 +9228,8 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
exclusive_event_destroy(event);
err_pmu:
+ if (event->pmu->event_terminate)
+ event->pmu->event_terminate(event);
if (event->destroy)
event->destroy(event);
module_put(pmu->module);
--
2.8.0.rc3.226.g39d4020