From: He Kuang <hekuang@huawei.com>
To: <ast@plumgrid.com>, <rostedt@goodmis.org>,
<masami.hiramatsu.pt@hitachi.com>, <mingo@redhat.com>,
<acme@redhat.com>, <a.p.zijlstra@chello.nl>, <jolsa@kernel.org>,
<namhyung@kernel.org>
Cc: <wangnan0@huawei.com>, <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH 2/5] perf/trace: Add perf extra percpu trace buffer
Date: Wed, 1 Jul 2015 02:57:32 +0000 [thread overview]
Message-ID: <1435719455-91155-3-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1435719455-91155-1-git-send-email-hekuang@huawei.com>
Introduce another trace buffer besides perf_trace_buffer, so other
utilities like bpf can generate and fill perf event data to it
extraly and the data can be collected to the original buffer
afterwards. The life cycle of this extra buffer is the same as the
original one.
Signed-off-by: He Kuang <hekuang@huawei.com>
---
include/linux/ftrace_event.h | 5 ++++-
kernel/trace/trace_event_perf.c | 46 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index f9ecf63..b6cf5a3 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -411,7 +411,8 @@ struct ftrace_event_file {
} \
early_initcall(trace_init_perf_perm_##name);
-#define PERF_MAX_TRACE_SIZE 2048
+#define PERF_MAX_TRACE_SIZE 2048
+#define PERF_MAX_EXTRA_TRACE_SIZE 128
#define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
@@ -614,6 +615,8 @@ extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
extern void ftrace_profile_free_filter(struct perf_event *event);
extern void *perf_trace_buf_prepare(int size, unsigned short type,
struct pt_regs **regs, int *rctxp);
+extern void *perf_extra_trace_buf_prepare(int size, int rctx);
+extern void *get_perf_extra_trace_buf(int rctx);
static inline void
perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 6fa484d..603b3da 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -10,6 +10,7 @@
#include "trace.h"
static char __percpu *perf_trace_buf[PERF_NR_CONTEXTS];
+static char __percpu *perf_extra_trace_buf[PERF_NR_CONTEXTS];
/*
* Force it to be aligned to unsigned long to avoid misaligned accesses
@@ -18,6 +19,10 @@ static char __percpu *perf_trace_buf[PERF_NR_CONTEXTS];
typedef typeof(unsigned long [PERF_MAX_TRACE_SIZE / sizeof(unsigned long)])
perf_trace_t;
+typedef
+typeof(unsigned long [PERF_MAX_EXTRA_TRACE_SIZE / sizeof(unsigned long)])
+ perf_extra_trace_t;
+
/* Count the events in use (per event id, not per instance) */
static int total_ref_count;
@@ -113,6 +118,13 @@ static int perf_trace_event_reg(struct ftrace_event_call *tp_event,
goto fail;
perf_trace_buf[i] = buf;
+
+ buf = (char __percpu *)
+ alloc_percpu(perf_extra_trace_t);
+ if (!buf)
+ goto fail;
+
+ perf_extra_trace_buf[i] = buf;
}
}
@@ -130,6 +142,9 @@ fail:
for (i = 0; i < PERF_NR_CONTEXTS; i++) {
free_percpu(perf_trace_buf[i]);
perf_trace_buf[i] = NULL;
+
+ free_percpu(perf_extra_trace_buf[i]);
+ perf_extra_trace_buf[i] = NULL;
}
}
@@ -164,6 +179,9 @@ static void perf_trace_event_unreg(struct perf_event *p_event)
for (i = 0; i < PERF_NR_CONTEXTS; i++) {
free_percpu(perf_trace_buf[i]);
perf_trace_buf[i] = NULL;
+
+ free_percpu(perf_extra_trace_buf[i]);
+ perf_extra_trace_buf[i] = NULL;
}
}
out:
@@ -260,6 +278,34 @@ void perf_trace_del(struct perf_event *p_event, int flags)
tp_event->class->reg(tp_event, TRACE_REG_PERF_DEL, p_event);
}
+void *perf_extra_trace_buf_prepare(int size, int rctx)
+{
+ char *raw_data;
+
+ BUILD_BUG_ON(PERF_MAX_EXTRA_TRACE_SIZE % sizeof(unsigned long));
+
+ if (WARN_ONCE(size > PERF_MAX_EXTRA_TRACE_SIZE,
+ "perf extra buffer not large enough"))
+ return NULL;
+
+ raw_data = this_cpu_ptr(perf_extra_trace_buf[rctx]);
+
+ /* The first 4 bytes is raw_data size and it is used as a valid flag */
+ *(u32 *)raw_data = size;
+ raw_data += sizeof(u32);
+
+ return raw_data;
+}
+EXPORT_SYMBOL_GPL(perf_extra_trace_buf_prepare);
+NOKPROBE_SYMBOL(perf_extra_trace_buf_prepare);
+
+void *get_perf_extra_trace_buf(int rctx)
+{
+ return this_cpu_ptr(perf_extra_trace_buf[rctx]);
+}
+EXPORT_SYMBOL_GPL(get_perf_extra_trace_buf);
+NOKPROBE_SYMBOL(get_perf_extra_trace_buf);
+
void *perf_trace_buf_prepare(int size, unsigned short type,
struct pt_regs **regs, int *rctxp)
{
--
1.8.5.2
next prev parent reply other threads:[~2015-07-01 2:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-01 2:57 [RFC PATCH 0/5] Make eBPF programs output data to perf event He Kuang
2015-07-01 2:57 ` [RFC PATCH 1/5] bpf: Put perf_events check ahead of bpf prog He Kuang
2015-07-02 3:50 ` Alexei Starovoitov
2015-07-02 5:52 ` Wangnan (F)
2015-07-02 18:02 ` Alexei Starovoitov
2015-07-01 2:57 ` He Kuang [this message]
2015-07-01 2:57 ` [RFC PATCH 3/5] tracing/kprobe: Separate inc recursion count out of perf_trace_buf_prepare He Kuang
2015-07-01 2:57 ` [RFC PATCH 4/5] bpf: Introduce function for outputing sample data to perf event He Kuang
2015-07-01 2:57 ` [RFC PATCH 5/5] tracing/kprobe: Combine extra trace buf into perf trace buf He Kuang
2015-07-01 5:44 ` [RFC PATCH 0/5] Make eBPF programs output data to perf event Peter Zijlstra
2015-07-01 6:21 ` Wangnan (F)
2015-07-01 11:58 ` Peter Zijlstra
2015-07-02 2:48 ` Alexei Starovoitov
2015-07-02 3:38 ` He Kuang
2015-07-02 3:52 ` Alexei Starovoitov
2015-07-02 9:24 ` Wangnan (F)
2015-07-02 18:37 ` Alexei Starovoitov
2015-07-02 9:31 ` Peter Zijlstra
2015-07-02 13:50 ` [RFC PATCH v2 0/4] " He Kuang
2015-07-02 13:50 ` [RFC PATCH v2 1/4] bpf: Put perf_events check ahead of bpf prog He Kuang
2015-07-02 18:41 ` Alexei Starovoitov
2015-07-02 13:50 ` [RFC PATCH v2 2/4] tracing/kprobe: Separate inc recursion count out of perf_trace_buf_prepare He Kuang
2015-07-02 13:50 ` [RFC PATCH v2 3/4] bpf: Introduce function for outputing data to perf event He Kuang
2015-07-02 13:50 ` [RFC PATCH v2 4/4] tracing/kprobe: Combine bpf output and perf event output He Kuang
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=1435719455-91155-3-git-send-email-hekuang@huawei.com \
--to=hekuang@huawei.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=ast@plumgrid.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=wangnan0@huawei.com \
/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®