All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] perf: allow building PMU driver as module
@ 2014-03-18  8:56 Yan, Zheng
  2014-03-18  8:56 ` [PATCH 2/4] hrtimer: export __hrtimer_start_range_ns Yan, Zheng
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Yan, Zheng @ 2014-03-18  8:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: a.p.zijlstra, mingo, acme, eranian, andi, Yan, Zheng

This patch adds support for building PMU driver as module. It exports
function perf_pmu_{register,unregister} and adds reference tracking
for PMU driver module. When PMU driver is built as module, each active
event of the PMU holds a reference to the driver module.

Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
---
 include/linux/perf_event.h |  1 +
 kernel/events/core.c       | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index e56b07f..4f0710e 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -172,6 +172,7 @@ struct perf_event;
 struct pmu {
 	struct list_head		entry;
 
+	struct module			*module;
 	struct device			*dev;
 	const struct attribute_group	**attr_groups;
 	const char			*name;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 661951a..1616b7d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -39,6 +39,7 @@
 #include <linux/hw_breakpoint.h>
 #include <linux/mm_types.h>
 #include <linux/cgroup.h>
+#include <linux/module.h>
 
 #include "internal.h"
 
@@ -3244,6 +3245,9 @@ static void __free_event(struct perf_event *event)
 	if (event->ctx)
 		put_ctx(event->ctx);
 
+	if (event->pmu)
+		module_put(event->pmu->module);
+
 	call_rcu(&event->rcu_head, free_event_rcu);
 }
 static void free_event(struct perf_event *event)
@@ -6566,6 +6570,7 @@ free_pdc:
 	free_percpu(pmu->pmu_disable_count);
 	goto unlock;
 }
+EXPORT_SYMBOL_GPL(perf_pmu_register);
 
 void perf_pmu_unregister(struct pmu *pmu)
 {
@@ -6587,6 +6592,7 @@ void perf_pmu_unregister(struct pmu *pmu)
 	put_device(pmu->dev);
 	free_pmu_context(pmu);
 }
+EXPORT_SYMBOL_GPL(perf_pmu_unregister);
 
 struct pmu *perf_init_event(struct perf_event *event)
 {
@@ -6600,6 +6606,10 @@ struct pmu *perf_init_event(struct perf_event *event)
 	pmu = idr_find(&pmu_idr, event->attr.type);
 	rcu_read_unlock();
 	if (pmu) {
+		if (!try_module_get(pmu->module)) {
+			pmu = ERR_PTR(-ENODEV);
+			goto unlock;
+		}
 		event->pmu = pmu;
 		ret = pmu->event_init(event);
 		if (ret)
@@ -6608,6 +6618,10 @@ struct pmu *perf_init_event(struct perf_event *event)
 	}
 
 	list_for_each_entry_rcu(pmu, &pmus, entry) {
+		if (!try_module_get(pmu->module)) {
+			pmu = ERR_PTR(-ENODEV);
+			goto unlock;
+		}
 		event->pmu = pmu;
 		ret = pmu->event_init(event);
 		if (!ret)
@@ -6786,6 +6800,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 err_pmu:
 	if (event->destroy)
 		event->destroy(event);
+	module_put(pmu->module);
 err_ns:
 	if (event->ns)
 		put_pid_ns(event->ns);
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-04-18 13:22 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-18  8:56 [PATCH 1/4] perf: allow building PMU driver as module Yan, Zheng
2014-03-18  8:56 ` [PATCH 2/4] hrtimer: export __hrtimer_start_range_ns Yan, Zheng
2014-03-19  8:47   ` Peter Zijlstra
2014-03-19  9:53     ` Thomas Gleixner
2014-03-19  9:58       ` Peter Zijlstra
2014-04-18 13:08   ` [tip:perf/core] hrtimer: Export __hrtimer_start_range_ns() tip-bot for Yan, Zheng
2014-03-18  8:56 ` [PATCH 3/4] perf/x86: export perf_assign_events Yan, Zheng
2014-04-18 13:08   ` [tip:perf/core] perf/x86: Export perf_assign_events() tip-bot for Yan, Zheng
2014-03-18  8:56 ` [PATCH 4/4] perf/x86/uncore: modularize Intel uncore driver Yan, Zheng
2014-03-19  8:49   ` Peter Zijlstra
2014-03-19 11:32     ` Ingo Molnar
2014-03-19 11:42       ` Peter Zijlstra
2014-03-19 11:53         ` Ingo Molnar
2014-03-19 12:44           ` Peter Zijlstra
2014-03-19 12:55             ` Ingo Molnar
2014-03-20 15:01   ` Vince Weaver
2014-03-20 15:50     ` Andi Kleen
2014-04-18 13:08 ` [tip:perf/core] perf: Allow building PMU drivers as modules tip-bot for Yan, Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.