Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1176002

[RFC PATCH v2 4/4] tracing/kprobe: Combine bpf output and perf event output

From He Kuang <hekuang@huawei.com>
Newsgroups linux.kernel
Subject [RFC PATCH v2 4/4] tracing/kprobe: Combine bpf output and perf event output
Date 2015-07-02 16:00 +0200
Message-ID <pHNbZ-3p1-31@gated-at.bofh.it> (permalink)
References <pHjGV-1xX-13@gated-at.bofh.it> <pHNbY-3p1-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[RFC PATCH v2 0/4] Make eBPF programs output data to perf event He Kuang <hekuang@huawei.com> - 2015-07-02 16:00 +0200
  [RFC PATCH v2 1/4] bpf: Put perf_events check ahead of bpf prog He Kuang <hekuang@huawei.com> - 2015-07-02 16:00 +0200
  [RFC PATCH v2 3/4] bpf: Introduce function for outputing data to perf event He Kuang <hekuang@huawei.com> - 2015-07-02 16:00 +0200
  [RFC PATCH v2 2/4] tracing/kprobe: Separate inc recursion count out of perf_trace_buf_prepare He Kuang <hekuang@huawei.com> - 2015-07-02 16:00 +0200
  [RFC PATCH v2 4/4] tracing/kprobe: Combine bpf output and perf event output He Kuang <hekuang@huawei.com> - 2015-07-02 16:00 +0200

csiph-web