aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-10-10 08:53:11 -0400
committerIngo Molnar <mingo@kernel.org>2012-10-24 04:41:23 -0400
commita47473939db20e3961b200eb00acf5fcf084d755 (patch)
treeb588160c049ce2dd2755a44094d6cc1f9b5d9068
parentef8c029fa793423439e67ef0416b220d3fa3321a (diff)
perf/x86: Make hardware event translations available in sysfs
Add support to display hardware events translations available through the sysfs. Add 'events' group attribute under the sysfs x86 PMU record with attribute/file for each hardware event. This patch adds only backbone for PMUs to display config under 'events' directory. The specific PMU support itself will come in next patches, however this is how the sysfs group will look like: # ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend The file - hw event ID mapping is: file hw event ID --------------------------------------------------------------- cpu-cycles PERF_COUNT_HW_CPU_CYCLES instructions PERF_COUNT_HW_INSTRUCTIONS cache-references PERF_COUNT_HW_CACHE_REFERENCES cache-misses PERF_COUNT_HW_CACHE_MISSES branch-instructions PERF_COUNT_HW_BRANCH_INSTRUCTIONS branch-misses PERF_COUNT_HW_BRANCH_MISSES bus-cycles PERF_COUNT_HW_BUS_CYCLES stalled-cycles-frontend PERF_COUNT_HW_STALLED_CYCLES_FRONTEND stalled-cycles-backend PERF_COUNT_HW_STALLED_CYCLES_BACKEND ref-cycles PERF_COUNT_HW_REF_CPU_CYCLES Each file in the 'events' directory contains the term translation for the symbolic hw event for the currently running cpu model. # cat /sys/devices/cpu/events/stalled-cycles-backend event=0xb1,umask=0x01,inv,cmask=0x01 Suggested-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Cc: Paul Mackerras <paulus@samba.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Stephane Eranian <eranian@google.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1349873598-12583-2-git-send-email-jolsa@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/kernel/cpu/perf_event.c60
-rw-r--r--arch/x86/kernel/cpu/perf_event.h2
2 files changed, 62 insertions, 0 deletions
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 4a3374e61a93..9fa4c45ecad9 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1316,6 +1316,62 @@ static struct attribute_group x86_pmu_format_group = {
1316 .attrs = NULL, 1316 .attrs = NULL,
1317}; 1317};
1318 1318
1319struct perf_pmu_events_attr {
1320 struct device_attribute attr;
1321 u64 id;
1322};
1323
1324ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,
1325 char *page)
1326{
1327 struct perf_pmu_events_attr *pmu_attr = \
1328 container_of(attr, struct perf_pmu_events_attr, attr);
1329
1330 u64 config = x86_pmu.event_map(pmu_attr->id);
1331 return x86_pmu.events_sysfs_show(page, config);
1332}
1333
1334#define EVENT_VAR(_id) event_attr_##_id
1335#define EVENT_PTR(_id) &event_attr_##_id.attr.attr
1336
1337#define EVENT_ATTR(_name, _id) \
1338static struct perf_pmu_events_attr EVENT_VAR(_id) = { \
1339 .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \
1340 .id = PERF_COUNT_HW_##_id, \
1341};
1342
1343EVENT_ATTR(cpu-cycles, CPU_CYCLES );
1344EVENT_ATTR(instructions, INSTRUCTIONS );
1345EVENT_ATTR(cache-references, CACHE_REFERENCES );
1346EVENT_ATTR(cache-misses, CACHE_MISSES );
1347EVENT_ATTR(branch-instructions, BRANCH_INSTRUCTIONS );
1348EVENT_ATTR(branch-misses, BRANCH_MISSES );
1349EVENT_ATTR(bus-cycles, BUS_CYCLES );
1350EVENT_ATTR(stalled-cycles-frontend, STALLED_CYCLES_FRONTEND );
1351EVENT_ATTR(stalled-cycles-backend, STALLED_CYCLES_BACKEND );
1352EVENT_ATTR(ref-cycles, REF_CPU_CYCLES );
1353
1354static struct attribute *empty_attrs;
1355
1356struct attribute *events_attr[] = {
1357 EVENT_PTR(CPU_CYCLES),
1358 EVENT_PTR(INSTRUCTIONS),
1359 EVENT_PTR(CACHE_REFERENCES),
1360 EVENT_PTR(CACHE_MISSES),
1361 EVENT_PTR(BRANCH_INSTRUCTIONS),
1362 EVENT_PTR(BRANCH_MISSES),
1363 EVENT_PTR(BUS_CYCLES),
1364 EVENT_PTR(STALLED_CYCLES_FRONTEND),
1365 EVENT_PTR(STALLED_CYCLES_BACKEND),
1366 EVENT_PTR(REF_CPU_CYCLES),
1367 NULL,
1368};
1369
1370static struct attribute_group x86_pmu_events_group = {
1371 .name = "events",
1372 .attrs = events_attr,
1373};
1374
1319static int __init init_hw_perf_events(void) 1375static int __init init_hw_perf_events(void)
1320{ 1376{
1321 struct x86_pmu_quirk *quirk; 1377 struct x86_pmu_quirk *quirk;
@@ -1362,6 +1418,9 @@ static int __init init_hw_perf_events(void)
1362 x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */ 1418 x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */
1363 x86_pmu_format_group.attrs = x86_pmu.format_attrs; 1419 x86_pmu_format_group.attrs = x86_pmu.format_attrs;
1364 1420
1421 if (!x86_pmu.events_sysfs_show)
1422 x86_pmu_events_group.attrs = &empty_attrs;
1423
1365 pr_info("... version: %d\n", x86_pmu.version); 1424 pr_info("... version: %d\n", x86_pmu.version);
1366 pr_info("... bit width: %d\n", x86_pmu.cntval_bits); 1425 pr_info("... bit width: %d\n", x86_pmu.cntval_bits);
1367 pr_info("... generic registers: %d\n", x86_pmu.num_counters); 1426 pr_info("... generic registers: %d\n", x86_pmu.num_counters);
@@ -1651,6 +1710,7 @@ static struct attribute_group x86_pmu_attr_group = {
1651static const struct attribute_group *x86_pmu_attr_groups[] = { 1710static const struct attribute_group *x86_pmu_attr_groups[] = {
1652 &x86_pmu_attr_group, 1711 &x86_pmu_attr_group,
1653 &x86_pmu_format_group, 1712 &x86_pmu_format_group,
1713 &x86_pmu_events_group,
1654 NULL, 1714 NULL,
1655}; 1715};
1656 1716
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h
index 271d25700297..6f75b6a7f37c 100644
--- a/arch/x86/kernel/cpu/perf_event.h
+++ b/arch/x86/kernel/cpu/perf_event.h
@@ -354,6 +354,8 @@ struct x86_pmu {
354 int attr_rdpmc; 354 int attr_rdpmc;
355 struct attribute **format_attrs; 355 struct attribute **format_attrs;
356 356
357 ssize_t (*events_sysfs_show)(char *page, u64 config);
358
357 /* 359 /*
358 * CPU Hotplug hooks 360 * CPU Hotplug hooks
359 */ 361 */