From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org
Cc: acme@redhat.com, x86@vger.kernel.org, eranian@google.com,
jolsa@redhat.com, a.p.zijlstra@chello.nl,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 27/31] perf, x86: Report the arch perfmon events in sysfs
Date: Tue, 2 Oct 2012 16:48:47 -0700 [thread overview]
Message-ID: <1349221731-15665-28-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1349221731-15665-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
Report all the supported arch perfmon events as event aliases in
/sys/devices/cpu/...
This is needed to use the TSX intx,intx_cp attributes with
symbolic events, at least for these basic events.
Currently cpu/instructions/ doesn't work because instructions
is also a generic event. It works for all events which are not
the same as generic events though.
Probably needs to be fixed in the perf events parser.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
arch/x86/kernel/cpu/perf_event.c | 7 ++++
arch/x86/kernel/cpu/perf_event.h | 1 +
arch/x86/kernel/cpu/perf_event_intel.c | 56 ++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index b0f4edd..a5a5bef 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1309,6 +1309,11 @@ static struct attribute_group x86_pmu_format_group = {
.attrs = NULL,
};
+static struct attribute_group x86_pmu_events_group = {
+ .name = "events",
+ .attrs = NULL,
+};
+
static int __init init_hw_perf_events(void)
{
struct x86_pmu_quirk *quirk;
@@ -1354,6 +1359,7 @@ static int __init init_hw_perf_events(void)
x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */
x86_pmu_format_group.attrs = x86_pmu.format_attrs;
+ x86_pmu_events_group.attrs = x86_pmu.events_attrs;
pr_info("... version: %d\n", x86_pmu.version);
pr_info("... bit width: %d\n", x86_pmu.cntval_bits);
@@ -1646,6 +1652,7 @@ static struct attribute_group x86_pmu_attr_group = {
static const struct attribute_group *x86_pmu_attr_groups[] = {
&x86_pmu_attr_group,
&x86_pmu_format_group,
+ &x86_pmu_events_group,
NULL,
};
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h
index 002ecc9..9b71b34 100644
--- a/arch/x86/kernel/cpu/perf_event.h
+++ b/arch/x86/kernel/cpu/perf_event.h
@@ -358,6 +358,7 @@ struct x86_pmu {
*/
int attr_rdpmc;
struct attribute **format_attrs;
+ struct attribute **events_attrs;
/*
* CPU Hotplug hooks
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 8b8bb61..4639aad 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -34,6 +34,18 @@ static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly =
[PERF_COUNT_HW_REF_CPU_CYCLES] = 0x0300, /* pseudo-encoding */
};
+static const char *intel_perfmon_names[PERF_COUNT_HW_MAX] __read_mostly =
+{
+ [PERF_COUNT_HW_CPU_CYCLES] = "cycles",
+ [PERF_COUNT_HW_INSTRUCTIONS] = "instructions",
+ [PERF_COUNT_HW_CACHE_REFERENCES] = "cache-references",
+ [PERF_COUNT_HW_CACHE_MISSES] = "cache-misses",
+ [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "branches",
+ [PERF_COUNT_HW_BRANCH_MISSES] = "branch-misses",
+ [PERF_COUNT_HW_BUS_CYCLES] = "bus-cycles",
+ [PERF_COUNT_HW_REF_CPU_CYCLES] = "ref-cycles"
+};
+
static struct event_constraint intel_core_event_constraints[] __read_mostly =
{
INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */
@@ -1987,6 +1999,48 @@ static __init void intel_nehalem_quirk(void)
}
}
+static struct attribute *intel_arch_events[PERF_COUNT_HW_MAX + 1] __read_mostly;
+
+struct event_attribute {
+ struct device_attribute attr;
+ u64 config;
+};
+
+static struct event_attribute intel_arch_event_attr[PERF_COUNT_HW_MAX];
+
+static ssize_t show_event(struct device *dev,
+ struct device_attribute *attr,
+ char *page)
+{
+ struct event_attribute *e = container_of(attr, struct event_attribute, attr);
+
+ return sprintf(page, "event=%#llx,umask=%#llx",
+ e->config & 0xff,
+ (e->config >> 8) & 0xff);
+}
+
+static __init void intel_gen_arch_events(void)
+{
+ int j, i;
+
+ j = 0;
+ for_each_clear_bit(i, x86_pmu.events_mask, ARRAY_SIZE(intel_arch_events_map)) {
+ struct event_attribute *e = intel_arch_event_attr + j;
+ struct device_attribute *d = &e->attr;
+ struct attribute *a = &d->attr;
+ int id = intel_arch_events_map[i].id;
+
+ e->config = intel_perfmon_event_map[id];
+ intel_arch_events[j] = a;
+ a->name = intel_perfmon_names[id];
+ a->mode = 0444;
+ d->show = show_event;
+ j++;
+ }
+ intel_arch_events[j] = NULL;
+ x86_pmu.events_attrs = intel_arch_events;
+}
+
__init int intel_pmu_init(void)
{
union cpuid10_edx edx;
@@ -2030,6 +2084,8 @@ __init int intel_pmu_init(void)
x86_pmu.max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, x86_pmu.num_counters);
+ intel_gen_arch_events();
+
/*
* Quirk: v2 perfmon does not report fixed-purpose events, so
* assume at least 3 events:
--
1.7.7.6
next prev parent reply other threads:[~2012-10-02 23:51 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-02 23:48 perf PMU support for Haswell v2 Andi Kleen
2012-10-02 23:48 ` [PATCH 01/31] perf, x86: Add PEBSv2 record support Andi Kleen
2012-10-02 23:48 ` [PATCH 02/31] perf, x86: Basic Haswell PMU support v2 Andi Kleen
2012-10-02 23:48 ` [PATCH 03/31] perf, x86: Basic Haswell PEBS support Andi Kleen
2012-10-02 23:48 ` [PATCH 04/31] perf, x86: Support the TSX intx/intx_cp qualifiers Andi Kleen
2012-10-02 23:48 ` [PATCH 05/31] perf, x86: Report PEBS event in a raw format Andi Kleen
2012-10-02 23:48 ` [PATCH 06/31] perf, kvm: Support the intx/intx_cp modifiers in KVM arch perfmon emulation Andi Kleen
2012-10-03 10:27 ` Avi Kivity
2012-10-03 12:11 ` Andi Kleen
2012-10-03 12:54 ` Avi Kivity
2012-10-04 9:10 ` [06/31] " Gleb Natapov
2012-10-02 23:48 ` [PATCH 07/31] perf, x86: Support PERF_SAMPLE_ADDR on Haswell Andi Kleen
2012-10-02 23:48 ` [PATCH 08/31] perf, x86: Support Haswell v4 LBR format Andi Kleen
2012-10-02 23:48 ` [PATCH 09/31] perf, x86: Disable LBR recording for unknown LBR_FMT Andi Kleen
2012-10-02 23:48 ` [PATCH 10/31] perf, x86: Support LBR filtering by INTX/NOTX/ABORT Andi Kleen
2012-10-02 23:48 ` [PATCH 11/31] perf, tools: Add abort,notx,intx branch filter options to perf report -j Andi Kleen
2012-10-02 23:48 ` [PATCH 12/31] perf, tools: Support sorting by intx, abort branch flags Andi Kleen
2012-10-02 23:48 ` [PATCH 13/31] perf, x86: Support full width counting on Haswell Andi Kleen
2012-10-02 23:48 ` [PATCH 14/31] perf, x86: Avoid checkpointed counters causing excessive TSX aborts Andi Kleen
2012-10-02 23:48 ` [PATCH 15/31] perf, core: Add a concept of a weightened sample Andi Kleen
2012-10-02 23:48 ` [PATCH 16/31] perf, x86: Support weight samples for PEBS Andi Kleen
2012-10-02 23:48 ` [PATCH 17/31] perf, tools: Add support for weight Andi Kleen
2012-10-02 23:48 ` [PATCH 18/31] perf, tools: Handle XBEGIN like a jump Andi Kleen
2012-10-02 23:48 ` [PATCH 19/31] perf, x86: Support for printing PMU state on spurious PMIs v2 Andi Kleen
2012-10-02 23:48 ` [PATCH 20/31] perf, core: Add generic transaction flags Andi Kleen
2012-10-02 23:48 ` [PATCH 21/31] perf, x86: Add Haswell specific transaction flag reporting Andi Kleen
2012-10-02 23:48 ` [PATCH 22/31] perf, tools: Add support for record transaction flags Andi Kleen
2012-10-02 23:48 ` [PATCH 23/31] perf, tools: Point --sort documentation to --help Andi Kleen
2012-10-02 23:48 ` [PATCH 24/31] perf, tools: Add browser support for transaction flags Andi Kleen
2012-10-02 23:48 ` [PATCH 25/31] perf, tools: Move parse_events error printing to parse_events_options Andi Kleen
2012-10-02 23:48 ` [PATCH 26/31] perf, tools: Support events with - in the name Andi Kleen
2012-10-02 23:48 ` Andi Kleen [this message]
2012-10-02 23:48 ` [PATCH 28/31] tools, perf: Add a precise event qualifier Andi Kleen
2012-10-02 23:48 ` [PATCH 29/31] perf, x86: Add Haswell TSX event aliases Andi Kleen
2012-10-02 23:48 ` [PATCH 30/31] perf, tools: Add perf stat --transaction Andi Kleen
2012-10-02 23:48 ` [PATCH 31/31] perf, x86: Add a Haswell precise instructions event Andi Kleen
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=1349221731-15665-28-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@vger.kernel.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
all inboxes | Powered by JetHome®