From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org,
Frederic Weisbecker <fweisbec@gmail.com>,
Mike Galbraith <efault@gmx.de>, Paul Mackerras <paulus@samba.org>,
Stephane Eranian <eranian@google.com>,
Andi Kleen <ak@linux.intel.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Matt Fleming <matt.fleming@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [PATCH v1 08/11] x86: perf: intel_pt: Add sampling functionality
Date: Thu, 6 Feb 2014 12:50:31 +0200 [thread overview]
Message-ID: <1391683834-29868-9-git-send-email-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <1391683834-29868-1-git-send-email-alexander.shishkin@linux.intel.com>
Intel Processor Trace (PT) data can be used in perf event samples to annotate
other perf events. This patch implements itrace sampling related hooks that
configure and output sampling data to perf stream. Users will need to include
PERF_SAMPLE_ITRACE flag in the attr.sample_type mask and specify PT's PMU type
in attr.itrace_sample_type field.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
arch/x86/kernel/cpu/perf_event_intel_pt.c | 115 ++++++++++++++++++++++++++++++
1 file changed, 115 insertions(+)
diff --git a/arch/x86/kernel/cpu/perf_event_intel_pt.c b/arch/x86/kernel/cpu/perf_event_intel_pt.c
index b6b1a84..af1482d 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_pt.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_pt.c
@@ -946,17 +946,130 @@ static void pt_event_read(struct perf_event *event)
{
}
+typedef unsigned int (*pt_copyfn)(void *data, const void *src,
+ unsigned int len);
+
+/**
+ * pt_buffer_output - copy part of pt buffer to perf stream
+ * @buf: buffer to copy from
+ * @from: initial offset
+ * @to: final offset
+ * @copyfn: function that copies data out (like perf_output_copy())
+ * @data: data to be passed on to the copy function (like perf_output_handle)
+ */
+static int pt_buffer_output(struct pt_buffer *buf, unsigned long from,
+ unsigned long to, pt_copyfn copyfn, void *data)
+{
+ unsigned long tocopy;
+ unsigned int len = 0, remainder;
+ void *page;
+
+ do {
+ tocopy = PAGE_SIZE - offset_in_page(from);
+ if (to > from)
+ tocopy = min(tocopy, to - from);
+ if (!tocopy)
+ break;
+
+ page = pt_buffer_get_page(buf, from >> PAGE_SHIFT);
+ if (WARN_ONCE(!page, "no data page for %lx offset\n", from))
+ break;
+
+ page += offset_in_page(from);
+
+ remainder = copyfn(data, page, tocopy);
+ if (remainder)
+ return -EFAULT;
+
+ len += tocopy;
+ from += tocopy;
+ if (from == buf->size)
+ from = 0;
+ } while (to != from);
+ return len;
+}
+
static int pt_event_init(struct perf_event *event)
{
if (event->attr.type != pt_pmu.itrace.pmu.type)
return -ENOENT;
+ /* can't be both */
+ if (event->attr.sample_type & PERF_SAMPLE_ITRACE)
+ return -ENOENT;
+
if (!pt_event_valid(event))
return -EINVAL;
return 0;
}
+static unsigned long pt_trace_sampler_trace(struct perf_event *event,
+ struct perf_sample_data *data)
+{
+ struct pt_buffer *buf;
+
+ pt_event_stop(event, 0);
+
+ buf = itrace_event_get_priv(event);
+ if (!buf) {
+ data->trace.size = 0;
+ goto out;
+ }
+
+ pt_read_offset(buf);
+ pt_update_head(buf);
+
+ data->trace.to = local64_read(&buf->head);
+
+ if (data->trace.to < event->attr.itrace_sample_size)
+ data->trace.from = buf->size + data->trace.to -
+ event->attr.itrace_sample_size;
+ else
+ data->trace.from = data->trace.to -
+ event->attr.itrace_sample_size;
+ data->trace.size = ALIGN(event->attr.itrace_sample_size, sizeof(u64));
+
+ itrace_event_put(event);
+
+out:
+ if (!data->trace.size)
+ pt_event_start(event, 0);
+
+ return data->trace.size;
+}
+
+static void pt_trace_sampler_output(struct perf_event *event,
+ struct perf_output_handle *handle,
+ struct perf_sample_data *data)
+{
+ unsigned long padding;
+ struct pt_buffer *buf;
+ int ret;
+
+ buf = itrace_event_get_priv(event);
+ if (!buf)
+ return;
+
+ ret = pt_buffer_output(buf, data->trace.from, data->trace.to,
+ (pt_copyfn)perf_output_copy, handle);
+ itrace_event_put(event);
+ if (ret < 0) {
+ pr_warn("%s: failed to copy trace data\n", __func__);
+ goto out;
+ }
+
+ padding = data->trace.size - ret;
+ if (padding) {
+ u64 u = 0;
+
+ perf_output_copy(handle, &u, padding);
+ }
+
+out:
+ pt_event_start(event, 0);
+}
+
static __init int pt_init(void)
{
int ret, cpu;
@@ -982,6 +1095,8 @@ static __init int pt_init(void)
pt_pmu.itrace.pmu.read = pt_event_read;
pt_pmu.itrace.alloc_buffer = pt_buffer_itrace_alloc;
pt_pmu.itrace.free_buffer = pt_buffer_itrace_free;
+ pt_pmu.itrace.sample_trace = pt_trace_sampler_trace;
+ pt_pmu.itrace.sample_output = pt_trace_sampler_output;
pt_pmu.itrace.name = "intel_pt";
ret = itrace_pmu_register(&pt_pmu.itrace);
--
1.8.5.2
next prev parent reply other threads:[~2014-02-06 10:51 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-06 10:50 [PATCH v1 00/11] perf: Add support for Intel Processor Trace Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 01/11] x86: Add Intel Processor Trace (INTEL_PT) cpu feature detection Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 02/11] perf: Abstract ring_buffer backing store operations Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 03/11] perf: Allow for multiple ring buffers per event Alexander Shishkin
2014-02-17 14:33 ` Peter Zijlstra
2014-02-18 2:36 ` Andi Kleen
2014-03-14 10:38 ` Peter Zijlstra
2014-03-14 14:10 ` Andi Kleen
2014-03-18 14:06 ` Alexander Shishkin
2014-02-19 22:02 ` Dave Hansen
2014-03-10 9:59 ` Alexander Shishkin
2014-03-10 17:24 ` Andi Kleen
2014-03-14 10:44 ` Peter Zijlstra
2014-03-14 14:13 ` Andi Kleen
2014-03-14 10:41 ` Peter Zijlstra
2014-05-07 15:26 ` Peter Zijlstra
2014-05-07 19:25 ` Ingo Molnar
2014-05-07 21:08 ` Andi Kleen
2014-05-07 21:22 ` Peter Zijlstra
2014-05-08 3:26 ` Alexander Shishkin
2014-05-08 4:05 ` Alexander Shishkin
2014-05-08 9:08 ` Alexander Shishkin
2014-05-08 12:34 ` Alexander Shishkin
2014-05-08 12:41 ` Peter Zijlstra
2014-05-08 12:46 ` Alexander Shishkin
2014-05-08 14:16 ` Peter Zijlstra
2014-02-06 10:50 ` [PATCH v1 04/11] itrace: Infrastructure for instruction flow tracing units Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 05/11] itrace: Add functionality to include traces in perf event samples Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 06/11] itrace: Add functionality to include traces in process core dumps Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 07/11] x86: perf: intel_pt: Intel PT PMU driver Alexander Shishkin
2014-02-06 20:29 ` Andi Kleen
2014-02-17 14:44 ` Peter Zijlstra
2014-02-17 16:07 ` Andi Kleen
2014-02-17 14:46 ` Peter Zijlstra
2014-02-18 12:42 ` Alexander Shishkin
2014-02-06 10:50 ` Alexander Shishkin [this message]
2014-02-06 10:50 ` [PATCH v1 09/11] x86: perf: intel_pt: Add core dump functionality Alexander Shishkin
2014-02-06 20:36 ` Andi Kleen
2014-02-07 9:03 ` Alexander Shishkin
2014-02-06 23:59 ` Andi Kleen
2014-02-07 9:09 ` Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 10/11] x86: perf: intel_bts: Add BTS PMU driver Alexander Shishkin
2014-02-06 10:50 ` [PATCH v1 11/11] x86: perf: intel_bts: Add core dump related functionality Alexander Shishkin
2014-02-06 23:57 ` Andi Kleen
2014-02-07 9:02 ` Alexander Shishkin
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=1391683834-29868-9-git-send-email-alexander.shishkin@linux.intel.com \
--to=alexander.shishkin@linux.intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matt.fleming@intel.com \
--cc=mingo@redhat.com \
--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
all inboxes | Powered by JetHome®