From: Stephane Eranian <eranian@google.com>
To: linux-kernel@vger.kernel.org
Cc: acme@redhat.com, peterz@infradead.org, mingo@elte.hu,
ak@linux.intel.com, kan.liang@intel.com, jolsa@redhat.com,
Stephane Eranian <eranian@gmail.com>
Subject: [PATCH v2 1/5] perf/core: add PERF_RECORD_SAMPLE_SKID_IP record type
Date: Thu, 2 Nov 2017 11:15:55 -0700 [thread overview]
Message-ID: <1509646559-919-2-git-send-email-eranian@google.com> (raw)
In-Reply-To: <1509646559-919-1-git-send-email-eranian@google.com>
From: Stephane Eranian <eranian@gmail.com>
This patchs adds a new sample record type. The goal
is to record the interrupted instruction pointer (IP)
as seen by the kernel and reflected in the machine state (pt_regs).
On some architectures, it is possible to avoid the IP skid using
hardware support. For instance, on Intel x86, the use of PEBS helps
eliminate the skid on Haswell and later processors.
Without this patch, on Haswell processors, if you set:
- attr.precise = 0, then you get the skid IP
- attr.precise > 0, then you get the PEBS ip corrected for skid
The IP normally comes when the event has PERF_RECORD_SAMPLE_IP set.
However, there are certain measuremewnts where you need to have BOTH
the corrected IP and the skid IP. For instance, when studying branches,
the skid IP usually points to the target of the branch while the corrected
IP point to the branch instruction itself. Today, it is not possible to retrieve
both at the same time. This patch makes this possible by specifying
PERF_SAMPLE_IP|PERF_SAMPLE_SKID_IP.
Signed-off-by: Stephane Eranian <eranian@google.com>
---
include/linux/perf_event.h | 2 ++
include/uapi/linux/perf_event.h | 4 +++-
kernel/events/core.c | 14 ++++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 874b71a70058..772530501025 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -917,6 +917,7 @@ struct perf_sample_data {
u64 stack_user_size;
u64 phys_addr;
+ u64 skid_ip;
} ____cacheline_aligned;
/* default value for data source */
@@ -937,6 +938,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
data->weight = 0;
data->data_src.val = PERF_MEM_NA;
data->txn = 0;
+ data->skid_ip = 0; /* mark as uinitialized */
}
extern void perf_output_sample(struct perf_output_handle *handle,
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 140ae638cfd6..93e1970e9421 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -140,8 +140,9 @@ enum perf_event_sample_format {
PERF_SAMPLE_TRANSACTION = 1U << 17,
PERF_SAMPLE_REGS_INTR = 1U << 18,
PERF_SAMPLE_PHYS_ADDR = 1U << 19,
+ PERF_SAMPLE_SKID_IP = 1U << 20,
- PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */
+ PERF_SAMPLE_MAX = 1U << 21, /* non-ABI */
};
/*
@@ -816,6 +817,7 @@ enum perf_event_type {
* { u64 abi; # enum perf_sample_regs_abi
* u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR
* { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR
+ * { u64 skid_ip; } && PERF_SAMPLE_SKID_IP
* };
*/
PERF_RECORD_SAMPLE = 9,
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0649a84204e6..40f2839c8b94 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1565,6 +1565,9 @@ static void __perf_event_header_size(struct perf_event *event, u64 sample_type)
if (sample_type & PERF_SAMPLE_PHYS_ADDR)
size += sizeof(data->phys_addr);
+ if (sample_type & PERF_SAMPLE_SKID_IP)
+ size += sizeof(data->skid_ip);
+
event->header_size = size;
}
@@ -5934,6 +5937,9 @@ void perf_output_sample(struct perf_output_handle *handle,
if (sample_type & PERF_SAMPLE_PHYS_ADDR)
perf_output_put(handle, data->phys_addr);
+ if (sample_type & PERF_SAMPLE_SKID_IP)
+ perf_output_put(handle, data->skid_ip);
+
if (!event->attr.watermark) {
int wakeup_events = event->attr.wakeup_events;
@@ -5999,6 +6005,14 @@ void perf_prepare_sample(struct perf_event_header *header,
if (sample_type & PERF_SAMPLE_IP)
data->ip = perf_instruction_pointer(regs);
+ /*
+ * if skid_ip has not been set by arch specific code, then
+ * we initialize it to IP as interrupt-based sampling has
+ * skid
+ */
+ if (!data->skid_ip && sample_type & PERF_SAMPLE_SKID_IP)
+ data->skid_ip = perf_instruction_pointer(regs);
+
if (sample_type & PERF_SAMPLE_CALLCHAIN) {
int size = 1;
--
2.7.4
next prev parent reply other threads:[~2017-11-02 18:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-02 18:15 [PATCH v2 0/5] perf: add support for capturing skid IP Stephane Eranian
2017-11-02 18:15 ` Stephane Eranian [this message]
2017-11-02 18:59 ` [PATCH v2 1/5] perf/core: add PERF_RECORD_SAMPLE_SKID_IP record type Peter Zijlstra
2017-11-02 19:46 ` Stephane Eranian
2017-11-02 18:15 ` [PATCH v2 2/5] perf/x86: add PERF_SAMPLE_SKID_IP support for X86 PEBS Stephane Eranian
2017-11-03 15:05 ` Jiri Olsa
2017-11-02 18:15 ` [PATCH v2 3/5] perf/tools: add support for PERF_SAMPLE_SKID_IP Stephane Eranian
2017-11-02 18:15 ` [PATCH v2 4/5] perf/record: add support for sampling skid ip Stephane Eranian
2017-11-06 21:25 ` Andi Kleen
2017-11-02 18:15 ` [PATCH v2 5/5] perf/script: add support for " Stephane Eranian
2017-11-03 15:03 ` 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=1509646559-919-2-git-send-email-eranian@google.com \
--to=eranian@google.com \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=eranian@gmail.com \
--cc=jolsa@redhat.com \
--cc=kan.liang@intel.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).