From: Jiri Olsa <jolsa@redhat.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Greg KH <greg@kroah.com>,
acme@redhat.com, mingo@elte.hu, paulus@samba.org,
cjashfor@linux.vnet.ibm.com, linux-kernel@vger.kernel.org
Subject: Re: [RFCv3 0/9] perf tool: parser generator for events parsing
Date: Wed, 25 Jan 2012 15:37:11 +0100 [thread overview]
Message-ID: <20120125143711.GD2582@m.brq.redhat.com> (raw)
In-Reply-To: <1327488573.2614.59.camel@laptop>
On Wed, Jan 25, 2012 at 11:49:33AM +0100, Peter Zijlstra wrote:
> On Tue, 2012-01-24 at 16:53 -0800, Greg KH wrote:
>
> > Well, what's to keep someone from exploding one of those files to go
> > over the buffer size without knowing it?
>
> The content is known at compile time, we could put checks in. But yeah
> 4k isn't that much text..
>
> > Even after reading the above link, I can't really understand what this
> > is being used for. As it's sysfs files, why aren't Documentation/ABI/
> > files also being created with the patch explaining it all?
>
> Ah, yeah, documentation, wasn't that written in C :-)
>
> But fair enough... Anyway, the purpose is to describe the magic bits
> that go into perf_event_attr::config[012] for a particular pmu.
>
> Basically they're the 'hardware' bitmasks we want to export, so that
> userspace can deal with sane name/value pairs.
>
> > Again, if at all possible, sysfs should be one value per file. Please
> > NEVER create a sysfs file that requires a parser to determine what is
> > going on in it. It should be a simple 'read the value' type thing.
>
> The whole purpose was to drive a parser :-) Anyway, is:
> "config:0-7,32-35" acceptable for a single file?
>
> This means, the 'config' member of struct perf_event_attr bits 0-7,32-35
> form a bitfield whose name is then given by the filename that has this
> content.
>
> > So yes, multiple sysfs files do make sense, the resource load should be
> > almost non-existant for new ones.
>
> Surely all these attribute objects take more space than a few lines of
> text, but ok, I guess multiple files it is.
>
please check attached patch, would something like this be ok?
jirka
---
.../testing/sysfs-bus-event_source-devices-format | 14 ++++++++++++
include/linux/perf_event.h | 22 ++++++++++++++++++++
kernel/events/core.c | 22 ++++++++++++++++++++
3 files changed, 58 insertions(+), 0 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-bus-event_source-devices-format
diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-format b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
new file mode 100644
index 0000000..5a15221
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
@@ -0,0 +1,14 @@
+Where: /sys/bus/event_source/devices/<dev>/format
+Date: January 2012
+Kernel Version: 3.3
+Contact: Jiri Olsa <jolsa@redhat.com>
+Description:
+ Attribute group for 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.
+
+ Example: 'config1:1,6-10,44'
+ Defines contents of attribute that occupies bits 1,6-10,44 of
+ perf_event_attr::config1.
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 0b91db2..e2bf1c7 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -516,6 +516,7 @@ struct perf_guest_info_callbacks {
#include <linux/irq_work.h>
#include <linux/jump_label.h>
#include <linux/atomic.h>
+#include <linux/sysfs.h>
#include <asm/local.h>
#define PERF_MAX_STACK_DEPTH 255
@@ -626,6 +627,12 @@ struct pmu {
int task_ctx_nr;
/*
+ * True if the pmu defines its own set of format attributes within
+ * attr_groups. If false, default format attributes are used.
+ */
+ bool format_defined;
+
+ /*
* Fully disable/enable this PMU, can be used to protect from the PMI
* as well as for lazy/batch writing of the MSRs.
*/
@@ -1215,5 +1222,20 @@ do { \
register_cpu_notifier(&fn##_nb); \
} while (0)
+
+#define PMU_FORMAT_ATTR(_name, _format) \
+static ssize_t \
+pmu_format_attr_##_name##_show(struct device *dev, \
+ struct device_attribute *attr, \
+ char *page) \
+{ \
+ BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
+ return sprintf(page, _format "\n"); \
+} \
+ \
+static struct device_attribute format_attr_##_name = \
+ __ATTR(_name, 0444, \
+ pmu_format_attr_##_name##_show, NULL)
+
#endif /* __KERNEL__ */
#endif /* _LINUX_PERF_EVENT_H */
diff --git a/kernel/events/core.c b/kernel/events/core.c
index de859fb..8d2d6f3 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5503,6 +5503,22 @@ static struct bus_type pmu_bus = {
.dev_attrs = pmu_dev_attrs,
};
+/* Default format attributes. */
+PMU_FORMAT_ATTR(config, "config:0-63");
+PMU_FORMAT_ATTR(config1, "config1:0-63");
+PMU_FORMAT_ATTR(config2, "config2:0-63");
+
+static struct attribute *format_attrs[] = {
+ &format_attr_config.attr,
+ &format_attr_config1.attr,
+ &format_attr_config2.attr,
+};
+
+static struct attribute_group format_attr_group = {
+ .name = "format",
+ .attrs = format_attrs,
+};
+
static void pmu_dev_release(struct device *dev)
{
kfree(dev);
@@ -5529,6 +5545,12 @@ static int pmu_dev_alloc(struct pmu *pmu)
if (ret)
goto free_dev;
+ if (!pmu->format_defined) {
+ ret = sysfs_create_group(&pmu->dev->kobj, &format_attr_group);
+ if (ret)
+ goto free_dev;
+ }
+
out:
return ret;
--
1.7.1
next prev parent reply other threads:[~2012-01-25 14:37 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-15 15:30 [RFC 0/3] perf tool: Add new event group management Jiri Olsa
2011-12-15 15:30 ` [PATCH 1/3] perf, tool: Add parser generator for events parsing Jiri Olsa
2011-12-16 14:02 ` Peter Zijlstra
2011-12-16 14:03 ` Peter Zijlstra
2011-12-20 10:31 ` Jiri Olsa
2011-12-20 10:47 ` Peter Zijlstra
2011-12-20 11:30 ` Peter Zijlstra
2011-12-20 11:39 ` Peter Zijlstra
2011-12-21 16:16 ` new syntax for perf event Jiri Olsa
2012-01-05 9:17 ` Jiri Olsa
2012-01-05 14:10 ` Peter Zijlstra
2012-01-09 15:28 ` Jiri Olsa
2012-01-09 15:43 ` Peter Zijlstra
2012-01-16 12:31 ` [RFCv3 0/9] perf tool: parser generator for events parsing Jiri Olsa
2012-01-16 12:31 ` [PATCH 1/9] perf, tool: Make perf_evlist__splice_list_tail global Jiri Olsa
2012-01-16 12:31 ` [PATCH 2/9] perf, tool: Remove unused functions from debugfs object Jiri Olsa
2012-01-16 12:31 ` [PATCH 3/9] perf, tool: Add sysfs mountpoint interface Jiri Olsa
2012-01-16 12:31 ` [PATCH 4/9] perf, tool: Add bitmap_or function into bitmap object Jiri Olsa
2012-01-16 12:31 ` [PATCH 5/9] perf: Add sysfs format attribute for pmu device Jiri Olsa
2012-01-23 15:13 ` Eric W. Biederman
2012-01-23 15:33 ` Jiri Olsa
2012-01-24 15:22 ` Peter Zijlstra
2012-01-24 19:40 ` Eric W. Biederman
2012-01-25 8:54 ` Jiri Olsa
2012-01-26 16:26 ` Peter Zijlstra
2012-01-27 12:32 ` Jiri Olsa
2012-01-16 12:31 ` [PATCH 6/9] perf, tool: Add parser generator for events parsing Jiri Olsa
2012-01-24 16:02 ` Peter Zijlstra
2012-01-25 8:42 ` Jiri Olsa
2012-01-16 12:31 ` [PATCH 7/9] perf, tool: Add config options support for event parsing Jiri Olsa
2012-01-16 12:31 ` [PATCH 8/9] perf, tool: Add perf pmu object to access pmu format definition Jiri Olsa
2012-01-16 12:31 ` [PATCH 9/9] perf, tool: Add support to specify pmu style event Jiri Olsa
2012-01-24 15:22 ` [RFCv3 0/9] perf tool: parser generator for events parsing Peter Zijlstra
2012-01-24 16:26 ` Peter Zijlstra
2012-01-25 0:53 ` Greg KH
2012-01-25 10:49 ` Peter Zijlstra
2012-01-25 14:37 ` Jiri Olsa [this message]
2012-01-26 16:23 ` Peter Zijlstra
2012-01-26 16:27 ` Greg KH
2012-01-25 17:01 ` Greg KH
2012-01-27 14:34 ` [PATCHv4 " Jiri Olsa
2012-01-27 14:34 ` [PATCH 1/9] perf, tool: Make perf_evlist__splice_list_tail global Jiri Olsa
2012-02-07 19:31 ` [tip:perf/core] perf evlist: Make splice_list_tail method public tip-bot for Jiri Olsa
2012-01-27 14:34 ` [PATCH 2/9] perf, tool: Remove unused functions from debugfs object Jiri Olsa
2012-02-17 9:51 ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-01-27 14:34 ` [PATCH 3/9] perf, tool: Add sysfs mountpoint interface Jiri Olsa
2012-02-17 9:52 ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-01-27 14:34 ` [PATCH 4/9] perf, tool: Add bitmap_or function into bitmap object Jiri Olsa
2012-02-17 9:53 ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-01-27 14:34 ` [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device Jiri Olsa
2012-01-27 21:08 ` Corey Ashford
2012-01-27 21:19 ` Peter Zijlstra
2012-02-01 0:47 ` Corey Ashford
2012-01-30 9:52 ` Jiri Olsa
2012-02-01 1:25 ` Corey Ashford
2012-02-01 13:13 ` Jiri Olsa
2012-02-01 14:18 ` Peter Zijlstra
2012-02-01 14:31 ` Jiri Olsa
2012-02-01 14:40 ` Peter Zijlstra
2012-02-01 13:36 ` Peter Zijlstra
2012-02-02 0:33 ` Corey Ashford
2012-01-27 14:34 ` [PATCH 6/9] perf, tool: Add parser generator for events parsing Jiri Olsa
2012-01-27 14:34 ` [PATCH 7/9] perf, tool: Add config options support for event parsing Jiri Olsa
2012-01-27 14:34 ` [PATCH 8/9] perf, tool: Add perf pmu object to access pmu format definition Jiri Olsa
2012-01-27 14:34 ` [PATCH 9/9] perf, tool: Add support to specify pmu style event Jiri Olsa
2012-02-13 13:13 ` [PATCHv4 0/9] perf tool: parser generator for events parsing Jiri Olsa
2012-02-14 16:28 ` Peter Zijlstra
2012-02-14 16:43 ` Peter Zijlstra
2012-02-14 20:20 ` Peter Zijlstra
2012-02-14 20:57 ` Peter Zijlstra
2012-02-14 21:03 ` Peter Zijlstra
2012-02-15 9:24 ` Jiri Olsa
2012-02-15 11:18 ` Peter Zijlstra
2012-02-15 13:32 ` Jiri Olsa
2012-02-15 13:39 ` Peter Zijlstra
2012-02-15 9:04 ` Jiri Olsa
2012-02-15 11:03 ` Peter Zijlstra
2011-12-22 19:32 ` [PATCH 1/3] perf, tool: Add " Vince Weaver
2011-12-19 14:37 ` Jiri Olsa
2011-12-20 10:29 ` [PATCHv2 0/2] perf tool: " Jiri Olsa
2011-12-20 10:29 ` [PATCHv2 1/2] perf, tool: Add " Jiri Olsa
2011-12-20 10:29 ` [PATCHv2 2/2] perf, tool: Add more automated tests for event parsing Jiri Olsa
2011-12-20 17:37 ` [PATCH 1/3] perf, tool: Add parser generator for events parsing Arnaldo Carvalho de Melo
2011-12-21 9:55 ` Jiri Olsa
2011-12-15 15:30 ` [PATCH 2/3] perf, tool: Add new event group management Jiri Olsa
2011-12-20 17:47 ` Arnaldo Carvalho de Melo
2011-12-20 21:20 ` Peter Zijlstra
2011-12-21 11:54 ` Arnaldo Carvalho de Melo
2011-12-15 15:30 ` [PATCH 3/3] perf, tool: Add more automated tests for event parsing Jiri Olsa
2011-12-20 17:38 ` Arnaldo Carvalho de Melo
2011-12-21 8:47 ` [tip:perf/core] perf test: " tip-bot for Jiri Olsa
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=20120125143711.GD2582@m.brq.redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome