All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Richter <rric@kernel.org>
To: Borislav Petkov <bp@alien8.de>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@infradead.org>,
	Jiri Olsa <jolsa@redhat.com>,
	linux-kernel@vger.kernel.org,
	Robert Richter <robert.richter@linaro.org>,
	Robert Richter <rric@kernel.org>
Subject: [PATCH v2 13/14] perf, persistent: Exposing persistent events using sysfs
Date: Tue, 11 Jun 2013 18:42:39 +0200	[thread overview]
Message-ID: <1370968960-22527-14-git-send-email-rric@kernel.org> (raw)
In-Reply-To: <1370968960-22527-1-git-send-email-rric@kernel.org>

From: Robert Richter <robert.richter@linaro.org>

Expose persistent events in the system to userland using sysfs. Perf
tools are able to read existing pmu events from sysfs. Now we use a
persistent pmu as an event container containing all registered
persistent events of the system. This patch adds dynamically
registration of persistent events to sysfs. E.g. something like this:

 /sys/bus/event_source/devices/persistent/events/mce_record:persistent,config=106
 /sys/bus/event_source/devices/persistent/format/persistent:attr5:23

Perf tools need to support the attr<num> syntax that is added in a
separate patch set. With it we are able to run perf tool commands to
read persistent events, e.g.:

 # perf record -e persistent/mce_record/ sleep 10
 # perf top -e persistent/mce_record/

[ Document attr<index> syntax in sysfs ABI ]
Reported-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Robert Richter <robert.richter@linaro.org>
Signed-off-by: Robert Richter <rric@kernel.org>
---
 .../testing/sysfs-bus-event_source-devices-format  | 43 ++++++++++++-----
 kernel/events/persistent.c                         | 55 +++++++++++++++++++++-
 2 files changed, 86 insertions(+), 12 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-format b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
index 77f47ff..47b7353 100644
--- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
@@ -1,13 +1,14 @@
-Where:		/sys/bus/event_source/devices/<dev>/format
+Where:		/sys/bus/event_source/devices/<pmu>/format/<name>
 Date:		January 2012
-Kernel Version: 3.3
+Kernel Version:	3.3
+		3.12	(added attr<index>:<bits>)
 Contact:	Jiri Olsa <jolsa@redhat.com>
-Description:
-		Attribute group to describe the magic bits that go into
-		perf_event_attr::config[012] for a particular pmu.
-		Each attribute of this group defines the 'hardware' bitmask
-		we want to export, so that userspace can deal with sane
-		name/value pairs.
+
+Description:	Define formats for bit ranges in perf_event_attr
+
+		Attribute group to describe the magic bits that go
+		into struct perf_event_attr for a particular pmu. Bit
+		range may be any bit mask of an u64 (bits 0 to 63).
 
 		Userspace must be prepared for the possibility that attributes
 		define overlapping bit ranges. For example:
@@ -15,6 +16,26 @@ Description:
 			attr2 = 'config:0-7'
 			attr3 = 'config:12-35'
 
-		Example: 'config1:1,6-10,44'
-		Defines contents of attribute that occupies bits 1,6-10,44 of
-		perf_event_attr::config1.
+		Syntax			Description
+
+		config[012]*:<bits>	Each attribute of this group
+					defines the 'hardware' bitmask
+					we want to export, so that
+					userspace can deal with sane
+					name/value pairs.
+
+		attr<index>:<bits>	Set any field of the event
+					attribute. The index is a
+					decimal number that specifies
+					the u64 value to be set within
+					struct perf_event_attr.
+
+		Examples:
+
+		'config1:1,6-10,44'	Defines contents of attribute
+					that occupies bits 1,6-10,44
+					of perf_event_attr::config1.
+
+		'attr5:23'		Define the persistent event
+					flag (bit 23 of the attribute
+					flags)
diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c
index 96201c1..8be7c05 100644
--- a/kernel/events/persistent.c
+++ b/kernel/events/persistent.c
@@ -17,8 +17,10 @@ struct pers_event_desc {
 struct pers_event {
 	char				*name;
 	struct perf_event_attr		attr;
+	struct perf_pmu_events_attr	sysfs;
 };
 
+static struct pmu persistent_pmu;
 static DEFINE_PER_CPU(struct list_head, pers_events);
 static DEFINE_PER_CPU(struct mutex, pers_events_lock);
 
@@ -137,6 +139,8 @@ unwind:
 	return PTR_ERR(event);
 }
 
+static int pers_event_sysfs_register(struct pers_event *event);
+
 int perf_add_persistent_event_by_id(char* name, int id)
 {
 	struct pers_event	*event;
@@ -150,6 +154,8 @@ int perf_add_persistent_event_by_id(char* name, int id)
 	if (!event->name)
 		goto fail;
 
+	event->sysfs.id		= id;
+
 	attr = &event->attr;
 	attr->sample_period	= 1;
 	attr->wakeup_events	= 1;
@@ -163,6 +169,8 @@ int perf_add_persistent_event_by_id(char* name, int id)
 	if (ret)
 		goto fail;
 
+	pers_event_sysfs_register(event);
+
 	return 0;
 fail:
 	kfree(event->name);
@@ -207,12 +215,57 @@ static struct attribute_group persistent_format_group = {
 	.attrs = persistent_format_attrs,
 };
 
+#define MAX_EVENTS 16
+
+static struct attribute *persistent_events_attr[MAX_EVENTS + 1] = { };
+
+static struct attribute_group persistent_events_group = {
+	.name = "events",
+	.attrs = persistent_events_attr,
+};
+
 static const struct attribute_group *persistent_attr_groups[] = {
 	&persistent_format_group,
+	NULL, /* placeholder: &persistent_events_group */
 	NULL,
 };
+#define EVENTS_GROUP	(persistent_attr_groups[1])
 
-static struct pmu persistent_pmu;
+static ssize_t pers_event_sysfs_show(struct device *dev,
+				struct device_attribute *__attr, char *page)
+{
+	struct perf_pmu_events_attr *attr =
+		container_of(__attr, struct perf_pmu_events_attr, attr);
+	return sprintf(page, "persistent,config=%lld",
+		(unsigned long long)attr->id);
+}
+
+static int pers_event_sysfs_register(struct pers_event *event)
+{
+	struct device_attribute *attr = &event->sysfs.attr;
+	int idx;
+
+	*attr = (struct device_attribute)__ATTR(, 0444, pers_event_sysfs_show,
+						NULL);
+	attr->attr.name = event->name;
+
+	/* add sysfs attr to events: */
+	for (idx = 0; idx < MAX_EVENTS; idx++) {
+		if (!cmpxchg(persistent_events_attr + idx, NULL, &attr->attr))
+			break;
+	}
+
+	if (idx >= MAX_EVENTS)
+		return -ENOSPC;
+	if (!idx)
+		EVENTS_GROUP = &persistent_events_group;
+	if (!persistent_pmu.dev)
+		return 0;	/* sysfs not yet initialized */
+	if (idx)
+		return sysfs_update_group(&persistent_pmu.dev->kobj,
+					EVENTS_GROUP);
+	return sysfs_create_group(&persistent_pmu.dev->kobj, EVENTS_GROUP);
+}
 
 static int persistent_pmu_init(struct perf_event *event)
 {
-- 
1.8.1.1


  parent reply	other threads:[~2013-06-11 16:43 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-11 16:42 [PATCH v2 00/14] perf, persistent: Kernel updates for perf tool integration Robert Richter
2013-06-11 16:42 ` [PATCH v2 01/14] perf, ring_buffer: Use same prefix Robert Richter
2013-06-11 16:42 ` [PATCH v2 02/14] perf: Add persistent events Robert Richter
2013-06-24  9:28   ` Peter Zijlstra
2013-06-24 19:24     ` Borislav Petkov
2013-06-25  8:46       ` Robert Richter
2013-06-11 16:42 ` [PATCH v2 03/14] perf: Add persistent event facilities Robert Richter
2013-06-14  2:15   ` Namhyung Kim
2013-06-14  7:20     ` Robert Richter
2013-06-24  9:32   ` Peter Zijlstra
2013-06-25  8:47     ` Robert Richter
2013-06-24  9:44   ` Peter Zijlstra
2013-06-25  8:41     ` Robert Richter
2013-06-24  9:48   ` Peter Zijlstra
2013-06-24 19:26     ` Borislav Petkov
2013-06-25  7:44       ` Peter Zijlstra
2013-06-25  9:24         ` Robert Richter
2013-06-25  9:37           ` Borislav Petkov
2013-06-25 10:51             ` Robert Richter
2013-06-25 15:29               ` Borislav Petkov
2013-06-25 16:14                 ` Robert Richter
2013-06-11 16:42 ` [PATCH v2 04/14] MCE: Enable persistent event Robert Richter
2013-06-11 16:42 ` [PATCH v2 05/14] perf, persistent: Rework struct pers_event_desc Robert Richter
2013-06-11 16:42 ` [PATCH v2 06/14] perf, persistent: Remove rb_put() Robert Richter
2013-06-11 16:42 ` [PATCH v2 07/14] perf, persistent: Introduce get_persistent_event() Robert Richter
2013-06-11 16:42 ` [PATCH v2 08/14] perf, persistent: Reworking perf_get_persistent_event_fd() Robert Richter
2013-06-11 16:42 ` [PATCH v2 09/14] perf, persistent: Protect event lists with mutex Robert Richter
2013-06-11 16:42 ` [PATCH v2 10/14] perf, persistent: Avoid adding identical events Robert Richter
2013-06-11 16:42 ` [PATCH v2 11/14] perf, persistent: Implementing a persistent pmu Robert Richter
2013-06-11 16:42 ` [PATCH v2 12/14] perf, persistent: Name each persistent event Robert Richter
2013-06-11 16:42 ` Robert Richter [this message]
2013-06-14  2:36   ` [PATCH v2 13/14] perf, persistent: Exposing persistent events using sysfs Namhyung Kim
2013-06-14  8:57     ` Robert Richter
2013-06-11 16:42 ` [PATCH v2 14/14] perf, persistent: Allow multiple users for an event Robert Richter
2013-06-24 10:08 ` [PATCH v2 00/14] perf, persistent: Kernel updates for perf tool integration Peter Zijlstra
2013-06-25 10:46   ` Robert Richter
2013-06-24 10:22 ` Peter Zijlstra
2013-06-25 16:56   ` Robert Richter
2013-06-24 10:24 ` Peter Zijlstra
2013-06-24 15:25 ` Peter Zijlstra
2013-06-24 19:45   ` Ingo Molnar
2013-06-25 17:57     ` Robert Richter
2013-06-25 19:16       ` Borislav Petkov
2013-06-26  8:12         ` Robert Richter
2013-06-26  8:24           ` Borislav Petkov
2013-06-26  9:46             ` Ingo Molnar
2013-06-26  9:56               ` Borislav Petkov
2013-06-26 10:11             ` Robert Richter
2013-06-26 11:45               ` Ingo Molnar
2013-06-26 12:25                 ` Ingo Molnar
2013-06-26 12:44                 ` Robert Richter
2013-06-27  5:46                   ` Namhyung Kim
2013-06-27  8:35                     ` Borislav Petkov
2013-06-27  8:50                       ` Ingo Molnar

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=1370968960-22527-14-git-send-email-rric@kernel.org \
    --to=rric@kernel.org \
    --cc=acme@infradead.org \
    --cc=bp@alien8.de \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=robert.richter@linaro.org \
    /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.