mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: He Kuang <hekuang@huawei.com>
To: <rostedt@goodmis.org>, <ast@plumgrid.com>,
	<masami.hiramatsu.pt@hitachi.com>, <acme@kernel.org>,
	<a.p.zijlstra@chello.nl>, <mingo@redhat.com>,
	<namhyung@kernel.org>, <jolsa@kernel.org>
Cc: <wangnan0@huawei.com>, <linux-kernel@vger.kernel.org>,
	<hekuang@huawei.com>
Subject: [RFC PATCH v2 4/4] tracing/kprobe: Combine bpf output and perf event output
Date: Thu, 2 Jul 2015 13:50:43 +0000	[thread overview]
Message-ID: <1435845043-107196-5-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1435845043-107196-1-git-send-email-hekuang@huawei.com>

Check and collect temporary trace buffer in the stage of preparing
perf trace buffer. If there're data to be collected, set invalid flag,
extend the trace buffer size and move the data to proper offset, so
the combined data will be compatible to the orignal format and can be
processed by perf-script.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 kernel/trace/trace_kprobe.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 16ad88e..274735b 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1140,6 +1140,8 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
 	struct hlist_head *head;
 	int size, __size, dsize;
 	int rctx;
+	u32 buf_tail_size;
+	char *buf_tail;
 
 	head = this_cpu_ptr(call->perf_events);
 	if (hlist_empty(head))
@@ -1152,15 +1154,29 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
 	if (prog && !trace_call_bpf(prog, regs))
 		goto out;
 
+	/* Check trace buf */
+	buf_tail = get_perf_trace_buf(rctx) +
+		PERF_MAX_TRACE_SIZE - sizeof(u32);
+	buf_tail_size = *(u32 *)buf_tail;
+
+	/* Clear size to invalid buf */
+	*(u32 *)buf_tail = 0;
+
+	if (buf_tail_size != 0)
+		buf_tail -= buf_tail_size;
+
 	dsize = __get_data_size(&tk->tp, regs);
 	__size = sizeof(*entry) + tk->tp.size + dsize;
-	size = ALIGN(__size + sizeof(u32), sizeof(u64));
+	size = ALIGN(__size + buf_tail_size + sizeof(u32), sizeof(u64));
 	size -= sizeof(u32);
 
 	entry = perf_trace_buf_prepare_rctx(size, call->event.type, NULL, rctx);
 	if (!entry)
 		goto out;
 
+	/* Move temporary buf to proper offset */
+	memmove((char *)entry + __size, buf_tail, buf_tail_size);
+
 	entry->ip = (unsigned long)tk->rp.kp.addr;
 	memset(&entry[1], 0, dsize);
 	store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize);
@@ -1183,6 +1199,8 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
 	struct hlist_head *head;
 	int size, __size, dsize;
 	int rctx;
+	u32 buf_tail_size;
+	char *buf_tail;
 
 	head = this_cpu_ptr(call->perf_events);
 	if (hlist_empty(head))
@@ -1195,15 +1213,29 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
 	if (prog && !trace_call_bpf(prog, regs))
 		goto out;
 
+	/* Check trace buf */
+	buf_tail = get_perf_trace_buf(rctx) +
+		PERF_MAX_TRACE_SIZE - sizeof(u32);
+	buf_tail_size = *(u32 *)buf_tail;
+
+	/* Clear size to invalid buf */
+	*(u32 *)buf_tail = 0;
+
+	if (buf_tail_size != 0)
+		buf_tail -= buf_tail_size;
+
 	dsize = __get_data_size(&tk->tp, regs);
 	__size = sizeof(*entry) + tk->tp.size + dsize;
-	size = ALIGN(__size + sizeof(u32), sizeof(u64));
+	size = ALIGN(__size + buf_tail_size + sizeof(u32), sizeof(u64));
 	size -= sizeof(u32);
 
 	entry = perf_trace_buf_prepare_rctx(size, call->event.type, NULL, rctx);
 	if (!entry)
 		goto out;
 
+	/* Move temporary buf to proper offset */
+	memmove((char *)entry + __size, buf_tail, buf_tail_size);
+
 	entry->func = (unsigned long)tk->rp.kp.addr;
 	entry->ret_ip = (unsigned long)ri->ret_addr;
 	store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize);
-- 
1.8.5.2


      parent reply	other threads:[~2015-07-02 13:51 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 ` [RFC PATCH 2/5] perf/trace: Add perf extra percpu trace buffer He Kuang
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       ` He Kuang [this message]

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=1435845043-107196-5-git-send-email-hekuang@huawei.com \
    --to=hekuang@huawei.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --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®