linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Andi Kleen <ak@linux.intel.com>, David Ahern <dsahern@gmail.com>
Subject: [PATCH 1/9] perf x86: Add precise sysfs cpu pmu attribute
Date: Sat, 26 Jan 2013 18:27:47 +0100	[thread overview]
Message-ID: <1359221275-24254-2-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1359221275-24254-1-git-send-email-jolsa@redhat.com>

Adding sysfs 'precise' attribute for cpu device
(/sys/devices/cpu/precise) to show the maximum
value for perf event precise attribute.

This will be initially used for automated precise
event perf test and could be helpful otherwise.

TODO Arnaldo suggested to use this as a guide for
default adding of precise attribute for HW events.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
---
 arch/x86/kernel/cpu/perf_event.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 6774c17..190995e 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -377,19 +377,26 @@ static inline int precise_br_compat(struct perf_event *event)
 	return m == b;
 }
 
-int x86_pmu_hw_config(struct perf_event *event)
+static int x86_get_precise(void)
 {
-	if (event->attr.precise_ip) {
-		int precise = 0;
+	int precise = 0;
 
-		/* Support for constant skid */
-		if (x86_pmu.pebs_active && !x86_pmu.pebs_broken) {
+	/* Support for constant skid */
+	if (x86_pmu.pebs_active && !x86_pmu.pebs_broken) {
+		precise++;
+
+		/* Support for IP fixup */
+		if (x86_pmu.lbr_nr)
 			precise++;
+	}
 
-			/* Support for IP fixup */
-			if (x86_pmu.lbr_nr)
-				precise++;
-		}
+	return precise;
+}
+
+int x86_pmu_hw_config(struct perf_event *event)
+{
+	if (event->attr.precise_ip) {
+		int precise = x86_get_precise();
 
 		if (event->attr.precise_ip > precise)
 			return -EOPNOTSUPP;
@@ -1700,6 +1707,13 @@ static int x86_pmu_event_init(struct perf_event *event)
 	return err;
 }
 
+static ssize_t get_attr_precise(struct device *cdev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	return snprintf(buf, 10, "%d\n", x86_get_precise());
+}
+
 static int x86_pmu_event_idx(struct perf_event *event)
 {
 	int idx = event->hw.idx;
@@ -1752,9 +1766,11 @@ static ssize_t set_attr_rdpmc(struct device *cdev,
 }
 
 static DEVICE_ATTR(rdpmc, S_IRUSR | S_IWUSR, get_attr_rdpmc, set_attr_rdpmc);
+static DEVICE_ATTR(precise, S_IRUGO, get_attr_precise, NULL);
 
 static struct attribute *x86_pmu_attrs[] = {
 	&dev_attr_rdpmc.attr,
+	&dev_attr_precise.attr,
 	NULL,
 };
 
-- 
1.7.11.7


  reply	other threads:[~2013-01-26 17:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-26 17:27 [PATCH 0/9] perf: Adding better precise_ip field handling Jiri Olsa
2013-01-26 17:27 ` Jiri Olsa [this message]
2013-01-26 17:27 ` [PATCH 2/9] perf tools: Add precise object to interface sysfs precise Jiri Olsa
2013-01-26 17:27 ` [PATCH 3/9] perf tests: Add precise event automated test Jiri Olsa
2013-01-26 17:27 ` [PATCH 4/9] perf tools: Add a precise event qualifier Jiri Olsa
2013-01-26 17:27 ` [PATCH 5/9] perf tools: Read maximal precise value for 'precise' term Jiri Olsa
2013-01-26 17:27 ` [PATCH 6/9] perf tools: Favor 'p' modifier before 'precise' term properly Jiri Olsa
2013-01-26 17:27 ` [PATCH 7/9] perf tests: Add automated precise term test Jiri Olsa
2013-01-26 17:27 ` [PATCH 8/9] perf: Document the ABI for 'precise' sysfs attribute Jiri Olsa
2013-01-26 17:27 ` [PATCH 9/9] perf: Document the ABI for 'rdpmc' " Jiri Olsa
2013-01-26 18:53 ` [PATCH 0/9] perf: Adding better precise_ip field handling Jiri Olsa
2013-01-27 12:41 ` Ingo Molnar
2013-01-27 12:57   ` Jiri Olsa
2013-01-27 13:02     ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2013-05-09 13:32 Jiri Olsa
2013-05-09 13:32 ` [PATCH 1/9] perf x86: Add precise sysfs cpu pmu attribute 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=1359221275-24254-2-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=dsahern@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --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).