linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Richter <robert.richter@amd.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Robert Richter <robert.richter@amd.com>
Subject: [PATCH 05/12] perf/x86-ibs: Take instruction pointer from ibs sample
Date: Mon, 2 Apr 2012 20:19:11 +0200	[thread overview]
Message-ID: <1333390758-10893-6-git-send-email-robert.richter@amd.com> (raw)
In-Reply-To: <1333390758-10893-1-git-send-email-robert.richter@amd.com>

Each IBS sample contains a linear address of the instruction that
caused the sample to trigger. This address is more precise than the
rip that was taken from the interrupt handler's stack. Update the rip
with that address. We use this in the next patch to implement
precise-event sampling on AMD systems using IBS.

Signed-off-by: Robert Richter <robert.richter@amd.com>
---
 arch/x86/include/asm/perf_event.h        |    6 ++-
 arch/x86/kernel/cpu/perf_event_amd_ibs.c |   48 +++++++++++++++++++----------
 2 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
index 9cf6696..651172d 100644
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -157,6 +157,7 @@ struct x86_pmu_capability {
 #define IBS_CAPS_OPCNT			(1U<<4)
 #define IBS_CAPS_BRNTRGT		(1U<<5)
 #define IBS_CAPS_OPCNTEXT		(1U<<6)
+#define IBS_CAPS_RIPINVALIDCHK		(1U<<7)
 
 #define IBS_CAPS_DEFAULT		(IBS_CAPS_AVAIL		\
 					 | IBS_CAPS_FETCHSAM	\
@@ -169,14 +170,14 @@ struct x86_pmu_capability {
 #define IBSCTL_LVT_OFFSET_VALID		(1ULL<<8)
 #define IBSCTL_LVT_OFFSET_MASK		0x0F
 
-/* IbsFetchCtl bits/masks */
+/* ibs fetch bits/masks */
 #define IBS_FETCH_RAND_EN	(1ULL<<57)
 #define IBS_FETCH_VAL		(1ULL<<49)
 #define IBS_FETCH_ENABLE	(1ULL<<48)
 #define IBS_FETCH_CNT		0xFFFF0000ULL
 #define IBS_FETCH_MAX_CNT	0x0000FFFFULL
 
-/* IbsOpCtl bits */
+/* ibs op bits/masks */
 /* lower 4 bits of the current count are ignored: */
 #define IBS_OP_CUR_CNT		(0xFFFF0ULL<<32)
 #define IBS_OP_CNT_CTL		(1ULL<<19)
@@ -184,6 +185,7 @@ struct x86_pmu_capability {
 #define IBS_OP_ENABLE		(1ULL<<17)
 #define IBS_OP_MAX_CNT		0x0000FFFFULL
 #define IBS_OP_MAX_CNT_EXT	0x007FFFFFULL	/* not a register bit mask */
+#define IBS_RIP_INVALID		(1ULL<<38)
 
 extern u32 get_ibs_caps(void);
 
diff --git a/arch/x86/kernel/cpu/perf_event_amd_ibs.c b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
index eec3ea2..0321b64 100644
--- a/arch/x86/kernel/cpu/perf_event_amd_ibs.c
+++ b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
@@ -9,6 +9,7 @@
 #include <linux/perf_event.h>
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/ptrace.h>
 
 #include <asm/apic.h>
 
@@ -382,7 +383,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
 	struct perf_raw_record raw;
 	struct pt_regs regs;
 	struct perf_ibs_data ibs_data;
-	int offset, size, overflow, reenable;
+	int offset, size, check_rip, offset_max, throttle = 0;
 	unsigned int msr;
 	u64 *buf, config;
 
@@ -413,28 +414,41 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
 
 	perf_ibs_event_update(perf_ibs, event, config);
 	perf_sample_data_init(&data, 0, hwc->last_period);
+	if (!perf_ibs_set_period(perf_ibs, hwc, &config))
+		goto out;	/* no sw counter overflow */
+
+	ibs_data.caps = ibs_caps;
+	size = 1;
+	offset = 1;
+	check_rip = (perf_ibs == &perf_ibs_op && (ibs_caps & IBS_CAPS_RIPINVALIDCHK));
+	if (event->attr.sample_type & PERF_SAMPLE_RAW)
+		offset_max = perf_ibs->offset_max;
+	else if (check_rip)
+		offset_max = 2;
+	else
+		offset_max = 1;
+	do {
+		rdmsrl(msr + offset, *buf++);
+		size++;
+		offset = find_next_bit(perf_ibs->offset_mask,
+				       perf_ibs->offset_max,
+				       offset + 1);
+	} while (offset < offset_max);
+	ibs_data.size = sizeof(u64) * size;
+
+	regs = *iregs;
+	if (!check_rip || !(ibs_data.regs[2] & IBS_RIP_INVALID))
+		instruction_pointer_set(&regs, ibs_data.regs[1]);
 
 	if (event->attr.sample_type & PERF_SAMPLE_RAW) {
-		ibs_data.caps = ibs_caps;
-		size = 1;
-		offset = 1;
-		do {
-		    rdmsrl(msr + offset, *buf++);
-		    size++;
-		    offset = find_next_bit(perf_ibs->offset_mask,
-					   perf_ibs->offset_max,
-					   offset + 1);
-		} while (offset < perf_ibs->offset_max);
-		raw.size = sizeof(u32) + sizeof(u64) * size;
+		raw.size = sizeof(u32) + ibs_data.size;
 		raw.data = ibs_data.data;
 		data.raw = &raw;
 	}
 
-	regs = *iregs; /* XXX: update ip from ibs sample */
-
-	overflow = perf_ibs_set_period(perf_ibs, hwc, &config);
-	reenable = !(overflow && perf_event_overflow(event, &data, &regs));
-	config = (config >> 4) | (reenable ? perf_ibs->enable_mask : 0);
+	throttle = perf_event_overflow(event, &data, &regs);
+out:
+	config = (config >> 4) | (throttle ? 0 : perf_ibs->enable_mask);
 	perf_ibs_enable_event(hwc, config);
 
 	perf_event_update_userpage(event);
-- 
1.7.8.4



  parent reply	other threads:[~2012-04-02 18:21 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-02 18:19 [PATCH 00/12] perf/x86-ibs: Precise event sampling with IBS for AMD CPUs Robert Richter
2012-04-02 18:19 ` [PATCH 01/12] perf/x86-ibs: Fix update of period Robert Richter
2012-05-09 14:29   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 02/12] perf: Pass last sampling period to perf_sample_data_init() Robert Richter
2012-05-09 14:30   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 03/12] perf/x86-ibs: Enable ibs op micro-ops counting mode Robert Richter
2012-05-09 14:31   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 04/12] perf/x86-ibs: Fix frequency profiling Robert Richter
2012-05-09 14:32   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` Robert Richter [this message]
2012-05-09 14:33   ` [tip:perf/core] perf/x86-ibs: Take instruction pointer from ibs sample tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 06/12] perf/x86-ibs: Precise event sampling with IBS for AMD CPUs Robert Richter
2012-04-14 10:21   ` Peter Zijlstra
2012-04-23  9:56     ` Robert Richter
2012-04-27 12:34       ` Robert Richter
2012-04-27 12:39         ` Stephane Eranian
2012-04-27 12:54           ` Robert Richter
2012-04-27 13:10             ` Stephane Eranian
2012-04-27 15:18               ` Robert Richter
2012-04-27 15:30                 ` Peter Zijlstra
2012-04-27 15:57                   ` Stephane Eranian
2012-04-27 15:30             ` Peter Zijlstra
2012-04-27 16:09               ` Robert Richter
2012-04-27 16:21                 ` Peter Zijlstra
2012-04-27 16:23                   ` Stephane Eranian
2012-04-14 10:22   ` Peter Zijlstra
2012-04-23  8:41     ` Robert Richter
2012-04-23 10:36       ` Peter Zijlstra
2012-04-14 10:24   ` Peter Zijlstra
2012-04-23 10:08     ` Robert Richter
2012-05-02 10:33   ` [PATCH v2] " Robert Richter
2012-05-02 11:14     ` Peter Zijlstra
2012-05-04 17:53       ` Peter Zijlstra
2012-05-09 14:34     ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 07/12] perf/x86-ibs: Rename some variables Robert Richter
2012-05-09 14:34   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 08/12] perf/x86-ibs: Trigger overflow if remaining period is too small Robert Richter
2012-05-09 14:35   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 09/12] perf/x86-ibs: Extend hw period that triggers overflow Robert Richter
2012-05-09 14:36   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 10/12] perf/x86-ibs: Implement workaround for IBS erratum #420 Robert Richter
2012-05-09 14:37   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 11/12] perf/x86-ibs: Catch spurious interrupts after stopping ibs Robert Richter
2012-05-09 14:38   ` [tip:perf/core] perf/x86-ibs: Catch spurious interrupts after stopping IBS tip-bot for Robert Richter
2012-04-02 18:19 ` [PATCH 12/12] perf/x86-ibs: Fix usage of IBS op current count Robert Richter
2012-05-09 14:39   ` [tip:perf/core] " tip-bot for Robert Richter
2012-04-02 19:11 ` [PATCH 00/12] perf/x86-ibs: Precise event sampling with IBS for AMD CPUs Ingo Molnar
2012-04-03 10:48   ` Robert Richter

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=1333390758-10893-6-git-send-email-robert.richter@amd.com \
    --to=robert.richter@amd.com \
    --cc=acme@redhat.com \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.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).