lkml.org 
[lkml]   [2015]   [Jun]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 5/5] tracing/kprobe: Combine extra trace buf into perf trace buf
Date
Collect extra trace buffer data in the stage of preparing perf trace
buffer. If extra perf trace buffer is valid, set invalid flag, extend
the trace buffer size and append the data of extra buffer to perf
trace buffer, 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 | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 16ad88e..88642ee 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 extra_buf_size;
+ char *extra_buf;

head = this_cpu_ptr(call->perf_events);
if (hlist_empty(head))
@@ -1152,15 +1154,28 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
if (prog && !trace_call_bpf(prog, regs))
goto out;

+ /* Check extra trace buf */
+ extra_buf = get_perf_extra_trace_buf(rctx);
+ extra_buf_size = *(u32 *)extra_buf;
+
+ /* Clear size to invalid buf */
+ *(u32 *)extra_buf = 0;
+
+ if (extra_buf_size != 0)
+ extra_buf += sizeof(u32);
+
dsize = __get_data_size(&tk->tp, regs);
__size = sizeof(*entry) + tk->tp.size + dsize;
- size = ALIGN(__size + sizeof(u32), sizeof(u64));
+ size = ALIGN(__size + extra_buf_size + sizeof(u32), sizeof(u64));
size -= sizeof(u32);

entry = perf_trace_buf_prepare_rctx(size, call->event.type, NULL, rctx);
if (!entry)
goto out;

+ /* Combine extra trace buf to perf trace buf */
+ memcpy((char *)entry + __size, extra_buf, extra_buf_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 +1198,8 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
struct hlist_head *head;
int size, __size, dsize;
int rctx;
+ u32 extra_buf_size;
+ char *extra_buf;

head = this_cpu_ptr(call->perf_events);
if (hlist_empty(head))
@@ -1195,15 +1212,28 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
if (prog && !trace_call_bpf(prog, regs))
goto out;

+ /* Check extra trace buf */
+ extra_buf = get_perf_extra_trace_buf(rctx);
+ extra_buf_size = *(u32 *)extra_buf;
+
+ /* Clear size to invalid buf */
+ *(u32 *)extra_buf = 0;
+
+ if (extra_buf_size != 0)
+ extra_buf += sizeof(u32);
+
dsize = __get_data_size(&tk->tp, regs);
__size = sizeof(*entry) + tk->tp.size + dsize;
- size = ALIGN(__size + sizeof(u32), sizeof(u64));
+ size = ALIGN(__size + extra_buf_size + sizeof(u32), sizeof(u64));
size -= sizeof(u32);

entry = perf_trace_buf_prepare_rctx(size, call->event.type, NULL, rctx);
if (!entry)
goto out;

+ /* Combine extra trace buf to perf trace buf */
+ memcpy((char *)entry + __size, extra_buf, extra_buf_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


\
 
 \ /
  Last update: 2015-07-01 05:21    [W:0.137 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site