[RFC PATCH 1/7] perf, core: Add all PMUs to pmu_idr
From: Yan, Zheng
Date: Wed May 28 2014 - 02:19:45 EST
Currently, the build-in PMUs are not added to pmu_idr. This makes
a inconvenience for finding PMU by type.
Signed-off-by: Yan, Zheng <zheng.z.yan@xxxxxxxxx>
---
kernel/events/core.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index ed50b09..bafc416 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6496,14 +6496,15 @@ int perf_pmu_register(struct pmu *pmu, const char *name, int type)
goto skip_type;
pmu->name = name;
- if (type < 0) {
- type = idr_alloc(&pmu_idr, pmu, PERF_TYPE_MAX, 0, GFP_KERNEL);
- if (type < 0) {
- ret = type;
- goto free_pdc;
- }
+ ret = idr_alloc(&pmu_idr, pmu, type >= 0 ? type : PERF_TYPE_MAX,
+ 0, GFP_KERNEL);
+ if (ret < 0)
+ goto free_pdc;
+ pmu->type = ret;
+ if (WARN_ON_ONCE(type >= 0 && pmu->type != type)) {
+ ret = -EINVAL;
+ goto free_idr;
}
- pmu->type = type;
if (pmu_bus_running) {
ret = pmu_dev_alloc(pmu);
@@ -6575,8 +6576,7 @@ free_dev:
put_device(pmu->dev);
free_idr:
- if (pmu->type >= PERF_TYPE_MAX)
- idr_remove(&pmu_idr, pmu->type);
+ idr_remove(&pmu_idr, pmu->type);
free_pdc:
free_percpu(pmu->pmu_disable_count);
@@ -6598,8 +6598,7 @@ void perf_pmu_unregister(struct pmu *pmu)
synchronize_rcu();
free_percpu(pmu->pmu_disable_count);
- if (pmu->type >= PERF_TYPE_MAX)
- idr_remove(&pmu_idr, pmu->type);
+ idr_remove(&pmu_idr, pmu->type);
device_del(pmu->dev);
put_device(pmu->dev);
free_pmu_context(pmu);
--
1.9.0
--
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/