linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: acme@redhat.com, a.p.zijlstra@chello.nl, mingo@elte.hu,
	paulus@samba.org, cjashfor@linux.vnet.ibm.com,
	fweisbec@gmail.com, eranian@google.com
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCH 04/10] perf, x86: Making hardware events translations available in sysfs
Date: Wed,  4 Jul 2012 00:00:42 +0200	[thread overview]
Message-ID: <1341352848-11833-5-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1341352848-11833-1-git-send-email-jolsa@redhat.com>

Making hardware events translations available through the sysfs.
Adding 'events' group attribute under the sysfs x86 PMU record
with attribute/file for each hardware event:

  # ls  /sys/devices/cpu/events/
  branch_instructions
  branch_misses
  bus_cycles
  cache_misses
  cache_references
  cycles
  instructions
  ref_cycles
  stalled_cycles_backend
  stalled_cycles_frontend

The file - hw event ID mappings is:

  file                      hw event ID
  ---------------------------------------------------------------
  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 'events' directory contains term translation for the
symbolic hw event for the currently running cpu model.

  # cat /sys/devices/cpu/events/instructions
  config=0xc0

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 arch/x86/kernel/cpu/perf_event.c |   44 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 41db515..e7aab56 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1666,9 +1666,53 @@ static struct attribute_group x86_pmu_attr_group = {
 	.attrs = x86_pmu_attrs,
 };
 
+#define PMU_EVENTS_ATTR_CONFIG(_name, _id)				\
+static ssize_t								\
+_name##_show(struct device *dev,					\
+			   struct device_attribute *attr,		\
+			   char *page)					\
+{									\
+	u64 val = x86_pmu.event_map(_id);				\
+	BUILD_BUG_ON(_id >= PERF_COUNT_HW_MAX);				\
+	return sprintf(page, "config=0x%llx\n", val);			\
+}									\
+									\
+static struct device_attribute event_attr_##_name = __ATTR_RO(_name)
+
+PMU_EVENTS_ATTR_CONFIG(cycles, PERF_COUNT_HW_CPU_CYCLES);
+PMU_EVENTS_ATTR_CONFIG(instructions, PERF_COUNT_HW_INSTRUCTIONS);
+PMU_EVENTS_ATTR_CONFIG(cache_references, PERF_COUNT_HW_CACHE_REFERENCES);
+PMU_EVENTS_ATTR_CONFIG(cache_misses, PERF_COUNT_HW_CACHE_MISSES);
+PMU_EVENTS_ATTR_CONFIG(branch_instructions, PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
+PMU_EVENTS_ATTR_CONFIG(branch_misses, PERF_COUNT_HW_BRANCH_MISSES);
+PMU_EVENTS_ATTR_CONFIG(bus_cycles, PERF_COUNT_HW_BUS_CYCLES);
+PMU_EVENTS_ATTR_CONFIG(stalled_cycles_frontend, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND);
+PMU_EVENTS_ATTR_CONFIG(stalled_cycles_backend, PERF_COUNT_HW_STALLED_CYCLES_BACKEND);
+PMU_EVENTS_ATTR_CONFIG(ref_cycles, PERF_COUNT_HW_REF_CPU_CYCLES);
+
+static struct attribute *events_attr[] = {
+	&event_attr_cycles.attr,
+	&event_attr_instructions.attr,
+	&event_attr_cache_references.attr,
+	&event_attr_cache_misses.attr,
+	&event_attr_branch_instructions.attr,
+	&event_attr_branch_misses.attr,
+	&event_attr_bus_cycles.attr,
+	&event_attr_stalled_cycles_frontend.attr,
+	&event_attr_stalled_cycles_backend.attr,
+	&event_attr_ref_cycles.attr,
+	NULL,
+};
+
+static struct attribute_group x86_pmu_events_group = {
+	.name = "events",
+	.attrs = events_attr,
+};
+
 static const struct attribute_group *x86_pmu_attr_groups[] = {
 	&x86_pmu_attr_group,
 	&x86_pmu_format_group,
+	&x86_pmu_events_group,
 	NULL,
 };
 
-- 
1.7.10.4


  parent reply	other threads:[~2012-07-03 22:01 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-03 22:00 [RFCv2 0/10] perf, tool: Allow to use hw events in PMU syntax Jiri Olsa
2012-07-03 22:00 ` [PATCH 01/10] perf, tool: Add empty rule for new line in event syntax parsing Jiri Olsa
2012-07-06 11:23   ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-07-03 22:00 ` [PATCH 02/10] perf, tool: Fix pmu object initialization Jiri Olsa
2012-07-04 10:30   ` Peter Zijlstra
2012-07-04 11:40     ` Jiri Olsa
2012-07-04 11:50       ` Peter Zijlstra
2012-07-05 14:28   ` Arnaldo Carvalho de Melo
2012-07-03 22:00 ` [PATCH 03/10] perf, tool: Properly free format data Jiri Olsa
2012-07-03 22:00 ` Jiri Olsa [this message]
2012-07-04 10:22   ` [PATCH 04/10] perf, x86: Making hardware events translations available in sysfs Peter Zijlstra
2012-07-04 10:38     ` Peter Zijlstra
2012-07-04 12:01       ` Jiri Olsa
2012-07-04 12:14         ` Peter Zijlstra
2012-07-04 16:35           ` Arnaldo Carvalho de Melo
2012-07-04 10:22   ` Peter Zijlstra
2012-07-04 10:24   ` Peter Zijlstra
2012-07-04 10:28     ` Peter Zijlstra
2012-07-04 12:00       ` Jiri Olsa
2012-07-03 22:00 ` [PATCH 05/10] perf, tool: Split out PE_VALUE_SYM parsing token to SW and HW tokens Jiri Olsa
2012-07-06 11:24   ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-07-03 22:00 ` [PATCH 06/10] perf, tool: Split event symbols arrays to hw and sw parts Jiri Olsa
2012-07-06 11:25   ` [tip:perf/core] perf tools: " tip-bot for Jiri Olsa
2012-07-03 22:00 ` [PATCH 07/10] perf, tool: Add support to specify hw event as pmu event term Jiri Olsa
2012-07-04 10:39   ` Peter Zijlstra
2012-07-04 12:00     ` Jiri Olsa
2012-07-04 12:13       ` Peter Zijlstra
2012-07-06  1:08         ` Stephane Eranian
2012-07-09 13:03           ` Peter Zijlstra
2012-07-03 22:00 ` [PATCH 08/10] perf, tool: Add sysfs read file interface Jiri Olsa
2012-07-04 10:40   ` Peter Zijlstra
2012-07-03 22:00 ` [PATCH 09/10] perf, test: Use ARRAY_SIZE in parse events tests Jiri Olsa
2012-07-06 11:22   ` [tip:perf/core] perf " tip-bot for Jiri Olsa
2012-07-03 22:00 ` [PATCH 10/10] perf, test: Add automated tests for pmu sysfs translated events 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=1341352848-11833-5-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.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;
as well as URLs for NNTP newsgroup(s).