[RFC][PATCH 3/9] perf: export registerred pmus via sysfs
From: Lin Ming
Date: Mon May 10 2010 - 05:27:56 EST
Export pmus via sysfs /sys/devices/system/cpu/pmus/0...N
The file name is the pmu id, ie, /sys/devices/system/cpu/pmus/N
represents pmu id N.
So perf tool can use it to initialize perf_event_attr.
Signed-off-by: Lin Ming <ming.m.lin@xxxxxxxxx>
---
kernel/perf_event.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index f19d40e..003b632 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -5744,6 +5744,52 @@ static int __init perf_event_sysfs_init(void)
}
device_initcall(perf_event_sysfs_init);
+#define PMU_ID_LEN 5
+static int __init perf_pmu_sysfs_init(void)
+{
+ struct kobject *pmu_kobj;
+ struct pmu *pmu;
+ struct bin_attribute *bin_attr;
+ char *pmu_id;
+ int err;
+ int i = 0;
+
+ pmu_kobj = kobject_create_and_add("pmus", &cpu_sysdev_class.kset.kobj);
+ if (!pmu_kobj) {
+ printk(KERN_WARNING "%s: kset create error\n", __func__);
+ return -ENOMEM;
+ }
+
+ list_for_each_entry(pmu, &pmus, entry) {
+ bin_attr = kzalloc(sizeof(*bin_attr), GFP_KERNEL);
+ pmu_id = kzalloc(PMU_ID_LEN, GFP_KERNEL);
+
+ if (!bin_attr || !pmu_id) {
+ if (bin_attr)
+ kfree(bin_attr);
+ if (pmu_id)
+ kfree(pmu_id);
+ return -ENOMEM;
+ }
+
+ sysfs_attr_init(&bin_attr.attr);
+ sprintf(pmu_id, "%d\n", i++);
+ bin_attr->size = 0;
+ bin_attr->attr.name = pmu_id;
+ bin_attr->attr.mode = 0444;
+
+ err = sysfs_create_bin_file(pmu_kobj, bin_attr);
+ if (err) {
+ kfree(bin_attr);
+ kfree(pmu_id);
+ return -ENOMEM;
+ }
+ }
+
+ return 0;
+}
+device_initcall(perf_pmu_sysfs_init);
+
void perf_event_register_pmu(struct pmu *pmu)
{
pmu->id = pmu_id_curr++;
--
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/