lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1273483623.15998.57.camel@minggr.sh.intel.com>
Date:	Mon, 10 May 2010 17:27:03 +0800
From:	Lin Ming <ming.m.lin@...el.com>
To:	Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...e.hu>
Cc:	Frederic Weisbecker <fweisbec@...il.com>,
	"eranian@...il.com" <eranian@...il.com>,
	"Gary.Mohr@...l.com" <Gary.Mohr@...l.com>,
	Corey Ashford <cjashfor@...ux.vnet.ibm.com>,
	"arjan@...ux.intel.com" <arjan@...ux.intel.com>,
	"Zhang, Yanmin" <yanmin_zhang@...ux.intel.com>,
	Paul Mackerras <paulus@...ba.org>,
	"David S. Miller" <davem@...emloft.net>,
	Russell King <rmk+kernel@....linux.org.uk>,
	Paul Mundt <lethal@...ux-sh.org>,
	lkml <linux-kernel@...r.kernel.org>
Subject: [RFC][PATCH 3/9] perf: export registerred pmus via sysfs

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@...el.com>
---
 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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ