All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Ingo Molnar <mingo@elte.hu>, Lin Ming <ming.m.lin@intel.com>,
	Stephane Eranian <eranian@google.com>,
	"robert.richter" <robert.richter@amd.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	fweisbec <fweisbec@gmail.com>, paulus <paulus@samba.org>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	Kay Sievers <kay.sievers@vrfy.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Kyle Moffett <kyle@moffetthome.net>
Cc: linux-kernel@vger.kernel.org, Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [RFC][PATCH 8/8] perf: Sysfs events
Date: Wed, 17 Nov 2010 23:17:38 +0100	[thread overview]
Message-ID: <20101117222056.369896257@chello.nl> (raw)
In-Reply-To: 20101117221730.002627458@chello.nl

[-- Attachment #1: perf-sysfs-events.patch --]
[-- Type: text/plain, Size: 4531 bytes --]

Simple example of a static event enumeration,.. need to come up with
something more dynamic for things like trace-events which can come
and go during the life-time of a struct pmu.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 arch/x86/kernel/cpu/perf_event.c |   51 ++++++++++++++++++++++++++++++++++++
 include/linux/perf_event.h       |    1 
 kernel/perf_event.c              |   55 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+)

Index: linux-2.6/include/linux/perf_event.h
===================================================================
--- linux-2.6.orig/include/linux/perf_event.h
+++ linux-2.6/include/linux/perf_event.h
@@ -578,6 +578,7 @@ struct perf_event;
 struct pmu {
 	struct list_head		entry;
 
+	const struct attribute_group	**groups;
 	struct device			*dev;
 	char				*name;
 	int				type;
Index: linux-2.6/kernel/perf_event.c
===================================================================
--- linux-2.6.orig/kernel/perf_event.c
+++ linux-2.6/kernel/perf_event.c
@@ -4700,7 +4700,61 @@ static int perf_swevent_init(struct perf
 	return 0;
 }
 
+static struct attribute *swevent_attrs[PERF_COUNT_SW_MAX+1];
+
+static ssize_t swevent_attr_show(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	int i;
+
+	for (i = 0; swevent_attrs[i]; i++) {
+		if ((struct attribute *)attr == swevent_attrs[i])
+			break;
+	}
+
+	return snprintf(buf, PAGE_SIZE-1, "%d\n", i);
+}
+
+#define SWEVENT_ATTR(name)	\
+	static DEVICE_ATTR(name, S_IRUGO, swevent_attr_show, NULL)
+
+SWEVENT_ATTR(cpu_clock);
+SWEVENT_ATTR(task_clock);
+SWEVENT_ATTR(page_faults);
+SWEVENT_ATTR(context_switches);
+SWEVENT_ATTR(cpu_migrations);
+SWEVENT_ATTR(page_faults_min);
+SWEVENT_ATTR(page_faults_maj);
+SWEVENT_ATTR(alignment_faults);
+SWEVENT_ATTR(emulation_faults);
+
+static struct attribute *swevent_attrs[] = {
+	&dev_attr_cpu_clock.attr,
+	&dev_attr_task_clock.attr,
+	&dev_attr_page_faults.attr,
+	&dev_attr_context_switches.attr,
+	&dev_attr_cpu_migrations.attr,
+	&dev_attr_page_faults_min.attr,
+	&dev_attr_page_faults_maj.attr,
+	&dev_attr_alignment_faults.attr,
+	&dev_attr_emulation_faults.attr,
+	NULL,
+};
+
+static struct attribute_group swevent_group = {
+	.name	= "events",
+	.attrs	= swevent_attrs,
+};
+
+static const struct attribute_group *swevent_groups[] = {
+	&swevent_group,
+	NULL
+};
+
 static struct pmu perf_swevent = {
+	.groups		= swevent_groups,
+
 	.task_ctx_nr	= perf_sw_context,
 
 	.event_init	= perf_swevent_init,
@@ -5172,6 +5226,7 @@ static int pmu_dev_alloc(struct pmu *pmu
 	dev_set_drvdata(pmu->dev, pmu);
 	pmu->dev->bus = &pmu_bus;
 	pmu->dev->release = pmu_dev_release;
+	pmu->dev->groups = pmu->groups;
 	ret = device_add(pmu->dev);
 	if (ret)
 		goto free_dev;
Index: linux-2.6/arch/x86/kernel/cpu/perf_event.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/perf_event.c
+++ linux-2.6/arch/x86/kernel/cpu/perf_event.c
@@ -25,6 +25,7 @@
 #include <linux/highmem.h>
 #include <linux/cpu.h>
 #include <linux/bitops.h>
+#include <linux/device.h>
 
 #include <asm/apic.h>
 #include <asm/stacktrace.h>
@@ -1607,7 +1608,57 @@ int x86_pmu_event_init(struct perf_event
 	return err;
 }
 
+static struct attribute *hwevent_attrs[PERF_COUNT_HW_MAX+1];
+
+static ssize_t hwevent_attr_show(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	int i;
+
+	for (i = 0; hwevent_attrs[i]; i++) {
+		if ((struct attribute *)attr == hwevent_attrs[i])
+			break;
+	}
+
+	return snprintf(buf, PAGE_SIZE-1, "0x%Lx\n", x86_pmu.event_map(i));
+}
+
+#define HWEVENT_ATTR(name)	\
+	static DEVICE_ATTR(name, S_IRUGO, hwevent_attr_show, NULL)
+
+HWEVENT_ATTR(cpu_cycles);
+HWEVENT_ATTR(instructions);
+HWEVENT_ATTR(cache_references);
+HWEVENT_ATTR(cache_misses);
+HWEVENT_ATTR(branch_instructions);
+HWEVENT_ATTR(branch_misses);
+HWEVENT_ATTR(bus_cycles);
+
+static struct attribute *hwevent_attrs[] = {
+	&dev_attr_cpu_cycles.attr,
+	&dev_attr_instructions.attr,
+	&dev_attr_cache_references.attr,
+	&dev_attr_cache_misses.attr,
+	&dev_attr_branch_instructions.attr,
+	&dev_attr_branch_misses.attr,
+	&dev_attr_bus_cycles.attr,
+	NULL,
+};
+
+static struct attribute_group hwevent_group = {
+	.name	= "events",
+	.attrs	= hwevent_attrs,
+};
+
+static const struct attribute_group *hwevent_groups[] = {
+	&hwevent_group,
+	NULL
+};
+
 static struct pmu pmu = {
+	.groups		= hwevent_groups,
+
 	.pmu_enable	= x86_pmu_enable,
 	.pmu_disable	= x86_pmu_disable,
 



      parent reply	other threads:[~2010-11-17 22:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-17 22:17 [RFC][PATCH 0/8] perf sysfs bits Peter Zijlstra
2010-11-17 22:17 ` [RFC][PATCH 1/8] perf, x86: Fixup Kconfig deps Peter Zijlstra
2010-11-26 15:01   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-11-17 22:17 ` [RFC][PATCH 2/8] perf, arch: Use early_initcall() for all arch pmu implementations Peter Zijlstra
2010-11-25 10:25   ` Peter Zijlstra
2010-11-25 14:47     ` Peter Zijlstra
2010-11-25 16:22       ` Will Deacon
2010-11-25 16:34         ` Peter Zijlstra
2010-11-25 17:55     ` Peter Zijlstra
2010-11-26  7:13       ` Paul Mundt
2010-11-26  9:41       ` Will Deacon
2010-11-26 15:05       ` [tip:perf/core] perf, arch: Cleanup perf-pmu init vs lockup-detector tip-bot for Peter Zijlstra
2010-11-17 22:17 ` [RFC][PATCH 3/8] perf: Move perf_event_init() into main.c Peter Zijlstra
2010-12-16 12:32   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-11-17 22:17 ` [RFC][PATCH 4/8] perf: Use early_initcall() for tracepoint and breakpoint init Peter Zijlstra
2010-11-17 22:17 ` [RFC][PATCH 5/8] init: Initialized IRD earlier Peter Zijlstra
2010-12-16 12:32   ` [tip:perf/core] init: Initialized IDR earlier tip-bot for Peter Zijlstra
2010-11-17 22:17 ` [RFC][PATCH 6/8] perf: Dynamic pmu types Peter Zijlstra
2010-12-16 12:32   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-11-17 22:17 ` [RFC][PATCH 7/8] perf: Sysfs enumeration Peter Zijlstra
2010-12-16 12:33   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-11-17 22:17 ` Peter Zijlstra [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101117222056.369896257@chello.nl \
    --to=a.p.zijlstra@chello.nl \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=gregkh@suse.de \
    --cc=hpa@zytor.com \
    --cc=kay.sievers@vrfy.org \
    --cc=kyle@moffetthome.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.m.lin@intel.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=robert.richter@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.