Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1175995 > unrolled thread
| Started by | He Kuang <hekuang@huawei.com> |
|---|---|
| First post | 2015-07-02 16:00 +0200 |
| Last post | 2015-07-02 16:00 +0200 |
| Articles | 5 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[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
| From | He Kuang <hekuang@huawei.com> |
|---|---|
| Date | 2015-07-02 16:00 +0200 |
| Subject | [RFC PATCH v2 0/4] Make eBPF programs output data to perf event |
| Message-ID | <pHNbY-3p1-3@gated-at.bofh.it> |
Hi,
Accordint to the discussion on patchset v1, it seems an extra
perf_trace_buf is reduntant, this patch removes the additional buffer
and stores bpf output into a temporary region at the ending of the
original perf_trace_buf. The temporary region will be moved back to
the proper offset of perf_trace_buf at the stage of
perf_trace_prepare_buf.
v1-v2:
- Remove additional perf_trace_buf. Use the end of perf_trace_buf as
a temporary region to store bpf data.
- Rename bpf_output_sample to bpf_output_data.
- New bpf API added to the end of the function list.
Thank you.
He Kuang (4):
bpf: Put perf_events check ahead of bpf prog
tracing/kprobe: Separate inc recursion count out of
perf_trace_buf_prepare
bpf: Introduce function for outputing data to perf event
tracing/kprobe: Combine bpf output and perf event output
include/linux/ftrace_event.h | 4 +++
include/linux/perf_event.h | 2 ++
include/uapi/linux/bpf.h | 3 ++
kernel/events/core.c | 6 ++++
kernel/events/internal.h | 17 ++++++----
kernel/trace/bpf_trace.c | 29 +++++++++++++++++
kernel/trace/trace_event_perf.c | 56 +++++++++++++++++++++++++++++---
kernel/trace/trace_kprobe.c | 72 ++++++++++++++++++++++++++++++++++-------
samples/bpf/bpf_helpers.h | 2 ++
9 files changed, 167 insertions(+), 24 deletions(-)
--
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/
[toc] | [next] | [standalone]
| From | He Kuang <hekuang@huawei.com> |
|---|---|
| Date | 2015-07-02 16:00 +0200 |
| Subject | [RFC PATCH v2 1/4] bpf: Put perf_events check ahead of bpf prog |
| Message-ID | <pHNbY-3p1-15@gated-at.bofh.it> |
| In reply to | #1175995 |
When we add a kprobe point and record events by perf, the execution path
of all threads on each cpu will enter this point, but perf may only
record events on a particular thread or cpu at this kprobe point, a
check on call->perf_events list filters out the threads which perf is
not recording.
Currently, bpf_prog will be entered at the beginning of
kprobe_perf_func() before the above check, which makes bpf_prog be
executed in every threads including determined not to be recorded
threads. A simple test can demonstrate this:
'bpf_prog_on_write.o' contains a bpf prog which outputs to trace buffer
when it is entered. Run a background thread 'another-dd' and 'dd'
simultaneously, but only record 'dd' thread by perf. The result shows
all threads trigger bpf_prog.
$ another-dd if=/dev/zero of=test1 bs=4k count=1000000
$ perf record -v --event bpf_prog_on_write.o -- dd if=/dev/zero of=test2 bs=4k count=3
$ cat /sys/kernel/debug/tracing/trace
another-dd-1007 [000] d... 120.225835: : generic_perform_write: tgid=1007, pid=1007
another-dd-1007 [000] d... 120.227123: : generic_perform_write: tgid=1007, pid=1007
[repeat many times...]
another-dd-1007 [000] d... 120.412395: : generic_perform_write: tgid=1007, pid=1007
another-dd-1007 [000] d... 120.412524: : generic_perform_write: tgid=1007, pid=1007
dd-1009 [000] d... 120.413080: : generic_perform_write: tgid=1009, pid=1009
dd-1009 [000] d... 120.414846: : generic_perform_write: tgid=1009, pid=1009
dd-1009 [000] d... 120.415013: : generic_perform_write: tgid=1009, pid=1009
another-dd-1007 [000] d... 120.416128: : generic_perform_write: tgid=1007, pid=1007
another-dd-1007 [000] d... 120.416295: : generic_perform_write: tgid=1007, pid=1007
This patch moves the check on perf_events list ahead and skip running
bpf_prog on threads perf not care.
After this patch:
$ another-dd if=/dev/zero of=test1 bs=4k count=1000000
$ perf record -v --event bpf_prog_on_write.o -- dd if=/dev/zero of=test2 bs=4k count=3
$ cat /sys/kernel/debug/tracing/trace
dd-994 [000] d... 46.386754: : generic_perform_write: tgid=994, pid=994
dd-994 [000] d... 46.389167: : generic_perform_write: tgid=994, pid=994
dd-994 [000] d... 46.389551: : generic_perform_write: tgid=994, pid=994
Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
kernel/trace/trace_kprobe.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index d0ce590..5600df8 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1141,13 +1141,13 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
int size, __size, dsize;
int rctx;
- if (prog && !trace_call_bpf(prog, regs))
- return;
-
head = this_cpu_ptr(call->perf_events);
if (hlist_empty(head))
return;
+ if (prog && !trace_call_bpf(prog, regs))
+ return;
+
dsize = __get_data_size(&tk->tp, regs);
__size = sizeof(*entry) + tk->tp.size + dsize;
size = ALIGN(__size + sizeof(u32), sizeof(u64));
@@ -1176,13 +1176,13 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
int size, __size, dsize;
int rctx;
- if (prog && !trace_call_bpf(prog, regs))
- return;
-
head = this_cpu_ptr(call->perf_events);
if (hlist_empty(head))
return;
+ if (prog && !trace_call_bpf(prog, regs))
+ return;
+
dsize = __get_data_size(&tk->tp, regs);
__size = sizeof(*entry) + tk->tp.size + dsize;
size = ALIGN(__size + sizeof(u32), sizeof(u64));
--
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/
[toc] | [prev] | [next] | [standalone]
| From | He Kuang <hekuang@huawei.com> |
|---|---|
| Date | 2015-07-02 16:00 +0200 |
| Subject | [RFC PATCH v2 3/4] bpf: Introduce function for outputing data to perf event |
| Message-ID | <pHNbZ-3p1-17@gated-at.bofh.it> |
| In reply to | #1175995 |
Add function to receive data from eBPF programs and fill that into
perf trace buffer of the current context. In previous patch we make
sure that the recursion counter protecting perf trace buffer is
checked when bpf_prog is executed, so here we can safely fill the
trace buffer. The data is temporarily stored at the end of
perf_trace_buf, the last 4 bytes of the buffer is used as a valid flag
and contains tempory buffer length.
In order to get the corresponding trace buffer of the context, new
function perf_swevent_current_context_type() is added, this function
only gets the current context type but does not increase the recursion
count.
Signed-off-by: He Kuang <hekuang@huawei.com>
---
include/linux/ftrace_event.h | 2 ++
include/linux/perf_event.h | 2 ++
include/uapi/linux/bpf.h | 3 +++
kernel/events/core.c | 6 ++++++
kernel/events/internal.h | 17 ++++++++++-------
kernel/trace/bpf_trace.c | 29 +++++++++++++++++++++++++++++
kernel/trace/trace_event_perf.c | 29 +++++++++++++++++++++++++++++
samples/bpf/bpf_helpers.h | 2 ++
8 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index d54f11d..1c1f3ad 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -616,6 +616,8 @@ extern void *perf_trace_buf_prepare(int size, unsigned short type,
struct pt_regs **regs, int *rctxp);
extern void *perf_trace_buf_prepare_rctx(int size, unsigned short type,
struct pt_regs **regs, int rctx);
+extern void *perf_trace_buf_prepare_rctx_tail(int size, int rctx);
+extern void *get_perf_trace_buf(int rctx);
static inline void
perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index a204d52..984c89c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -939,6 +939,7 @@ extern unsigned int perf_output_copy(struct perf_output_handle *handle,
const void *buf, unsigned int len);
extern unsigned int perf_output_skip(struct perf_output_handle *handle,
unsigned int len);
+extern int perf_swevent_current_context_type(void);
extern int perf_swevent_get_recursion_context(void);
extern void perf_swevent_put_recursion_context(int rctx);
extern u64 perf_swevent_set_period(struct perf_event *event);
@@ -995,6 +996,7 @@ static inline void perf_event_exec(void) { }
static inline void perf_event_comm(struct task_struct *tsk, bool exec) { }
static inline void perf_event_fork(struct task_struct *tsk) { }
static inline void perf_event_init(void) { }
+static inline int perf_swevent_current_context_type(void); { return -1; }
static inline int perf_swevent_get_recursion_context(void) { return -1; }
static inline void perf_swevent_put_recursion_context(int rctx) { }
static inline u64 perf_swevent_set_period(struct perf_event *event) { return 0; }
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index a9ebdf5..13d3e46 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -210,6 +210,9 @@ enum bpf_func_id {
* Return: 0 on success
*/
BPF_FUNC_l4_csum_replace,
+
+ /* int bpf_output_data(void *src, int size) */
+ BPF_FUNC_output_data,
__BPF_FUNC_MAX_ID,
};
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 9e0773d..0224d5b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6376,6 +6376,12 @@ end:
DEFINE_PER_CPU(struct pt_regs, __perf_regs[4]);
+int perf_swevent_current_context_type(void)
+{
+ return current_context_type();
+}
+EXPORT_SYMBOL_GPL(perf_swevent_current_context_type);
+
int perf_swevent_get_recursion_context(void)
{
struct swevent_htable *swhash = this_cpu_ptr(&swevent_htable);
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index 2deb24c..5cabce5 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -175,18 +175,21 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs);
extern int get_callchain_buffers(void);
extern void put_callchain_buffers(void);
-static inline int get_recursion_context(int *recursion)
+static inline int current_context_type(void)
{
- int rctx;
-
if (in_nmi())
- rctx = 3;
+ return 3;
else if (in_irq())
- rctx = 2;
+ return 2;
else if (in_softirq())
- rctx = 1;
+ return 1;
else
- rctx = 0;
+ return 0;
+}
+
+static inline int get_recursion_context(int *recursion)
+{
+ int rctx = current_context_type();
if (recursion[rctx])
return -1;
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2d56ce5..9159b5e 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -79,6 +79,33 @@ static const struct bpf_func_proto bpf_probe_read_proto = {
.arg3_type = ARG_ANYTHING,
};
+static u64 bpf_output_data(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
+{
+ void *src = (void *) (long) r1;
+ int size = (int) r2;
+ void *buf;
+ int rctx = perf_swevent_current_context_type();
+
+ if (rctx < 0)
+ return -EINVAL;
+
+ buf = perf_trace_buf_prepare_rctx_tail(size, rctx);
+ if (!buf)
+ return -ENOMEM;
+
+ memcpy(buf, src, size);
+
+ return 0;
+}
+
+static const struct bpf_func_proto bpf_output_data_proto = {
+ .func = bpf_output_data,
+ .gpl_only = true,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_STACK,
+ .arg2_type = ARG_CONST_STACK_SIZE,
+};
+
static u64 bpf_ktime_get_ns(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
{
/* NMI safe access to clock monotonic */
@@ -170,6 +197,8 @@ static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func
return &bpf_map_delete_elem_proto;
case BPF_FUNC_probe_read:
return &bpf_probe_read_proto;
+ case BPF_FUNC_output_data:
+ return &bpf_output_data_proto;
case BPF_FUNC_ktime_get_ns:
return &bpf_ktime_get_ns_proto;
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 344b601..2eeb59b 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -260,6 +260,35 @@ 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_trace_buf_prepare_rctx_tail(int size, int rctx)
+{
+ char *raw_data;
+
+ BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long));
+
+ if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
+ "perf buffer not large enough"))
+ return NULL;
+
+ raw_data = this_cpu_ptr(perf_trace_buf[rctx]);
+ raw_data += (PERF_MAX_TRACE_SIZE - sizeof(u32));
+
+ /* The lat 4 bytes is raw_data size and it is used as a valid flag */
+ *(u32 *)raw_data = size;
+ raw_data -= size;
+
+ return raw_data;
+}
+EXPORT_SYMBOL_GPL(perf_trace_buf_prepare_rctx_tail);
+NOKPROBE_SYMBOL(perf_trace_buf_prepare_rctx_tail);
+
+void *get_perf_trace_buf(int rctx)
+{
+ return this_cpu_ptr(perf_trace_buf[rctx]);
+}
+EXPORT_SYMBOL_GPL(get_perf_trace_buf);
+NOKPROBE_SYMBOL(get_perf_trace_buf);
+
static void *__perf_trace_buf_prepare(int size, unsigned short type,
struct pt_regs **regs, int *rctxp,
bool update_rctx)
diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h
index f960b5f..44bfbeb 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/samples/bpf/bpf_helpers.h
@@ -17,6 +17,8 @@ static int (*bpf_map_delete_elem)(void *map, void *key) =
(void *) BPF_FUNC_map_delete_elem;
static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =
(void *) BPF_FUNC_probe_read;
+static int (*bpf_output_data)(void *src, int size) =
+ (void *) BPF_FUNC_output_data;
static unsigned long long (*bpf_ktime_get_ns)(void) =
(void *) BPF_FUNC_ktime_get_ns;
static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
--
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/
[toc] | [prev] | [next] | [standalone]
| From | He Kuang <hekuang@huawei.com> |
|---|---|
| Date | 2015-07-02 16:00 +0200 |
| Subject | [RFC PATCH v2 2/4] tracing/kprobe: Separate inc recursion count out of perf_trace_buf_prepare |
| Message-ID | <pHNbZ-3p1-21@gated-at.bofh.it> |
| In reply to | #1175995 |
Inside perf_trace_buf_prepare(), a recursion count is increased, the
count was first introduced by commit 444a2a3bcd6d ("tracing,
perf_events: Protect the buffer from recursion in perf") to protect
the percpu data buffer from being overwritten.
For future patch to enable eBPF saving data into perf trace buffer and
prevent data buffer being filled recursively, the recursion count is
increased outside before entering trace_call_bpf() and decreased in
case of error. In this condition, we use the new function
perf_trace_buf_prepare_rctx() for not increasing the recursion count a
second time.
Signed-off-by: He Kuang <hekuang@huawei.com>
---
include/linux/ftrace_event.h | 2 ++
kernel/trace/trace_event_perf.c | 27 ++++++++++++++++++++++-----
kernel/trace/trace_kprobe.c | 28 ++++++++++++++++++++++------
3 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index f9ecf63..d54f11d 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -614,6 +614,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_trace_buf_prepare_rctx(int size, unsigned short type,
+ struct pt_regs **regs, 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..344b601 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -260,8 +260,9 @@ 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_trace_buf_prepare(int size, unsigned short type,
- struct pt_regs **regs, int *rctxp)
+static void *__perf_trace_buf_prepare(int size, unsigned short type,
+ struct pt_regs **regs, int *rctxp,
+ bool update_rctx)
{
struct trace_entry *entry;
unsigned long flags;
@@ -276,9 +277,11 @@ void *perf_trace_buf_prepare(int size, unsigned short type,
pc = preempt_count();
- *rctxp = perf_swevent_get_recursion_context();
- if (*rctxp < 0)
- return NULL;
+ if (update_rctx) {
+ *rctxp = perf_swevent_get_recursion_context();
+ if (*rctxp < 0)
+ return NULL;
+ }
if (regs)
*regs = this_cpu_ptr(&__perf_regs[*rctxp]);
@@ -294,9 +297,23 @@ void *perf_trace_buf_prepare(int size, unsigned short type,
return raw_data;
}
+
+void *perf_trace_buf_prepare(int size, unsigned short type,
+ struct pt_regs **regs, int *rctxp)
+{
+ return __perf_trace_buf_prepare(size, type, regs, rctxp, true);
+}
EXPORT_SYMBOL_GPL(perf_trace_buf_prepare);
NOKPROBE_SYMBOL(perf_trace_buf_prepare);
+void *perf_trace_buf_prepare_rctx(int size, unsigned short type,
+ struct pt_regs **regs, int rctx)
+{
+ return __perf_trace_buf_prepare(size, type, regs, &rctx, false);
+}
+EXPORT_SYMBOL_GPL(perf_trace_buf_prepare_rctx);
+NOKPROBE_SYMBOL(perf_trace_buf_prepare_rctx);
+
#ifdef CONFIG_FUNCTION_TRACER
static void
perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip,
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 5600df8..16ad88e 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1145,22 +1145,30 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
if (hlist_empty(head))
return;
- if (prog && !trace_call_bpf(prog, regs))
+ rctx = perf_swevent_get_recursion_context();
+ if (rctx < 0)
return;
+ if (prog && !trace_call_bpf(prog, regs))
+ goto out;
+
dsize = __get_data_size(&tk->tp, regs);
__size = sizeof(*entry) + tk->tp.size + dsize;
size = ALIGN(__size + sizeof(u32), sizeof(u64));
size -= sizeof(u32);
- entry = perf_trace_buf_prepare(size, call->event.type, NULL, &rctx);
+ entry = perf_trace_buf_prepare_rctx(size, call->event.type, NULL, rctx);
if (!entry)
- return;
+ goto out;
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);
perf_trace_buf_submit(entry, size, rctx, 0, 1, regs, head, NULL);
+
+ return;
+out:
+ perf_swevent_put_recursion_context(rctx);
}
NOKPROBE_SYMBOL(kprobe_perf_func);
@@ -1180,22 +1188,30 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
if (hlist_empty(head))
return;
- if (prog && !trace_call_bpf(prog, regs))
+ rctx = perf_swevent_get_recursion_context();
+ if (rctx < 0)
return;
+ if (prog && !trace_call_bpf(prog, regs))
+ goto out;
+
dsize = __get_data_size(&tk->tp, regs);
__size = sizeof(*entry) + tk->tp.size + dsize;
size = ALIGN(__size + sizeof(u32), sizeof(u64));
size -= sizeof(u32);
- entry = perf_trace_buf_prepare(size, call->event.type, NULL, &rctx);
+ entry = perf_trace_buf_prepare_rctx(size, call->event.type, NULL, rctx);
if (!entry)
- return;
+ goto out;
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);
perf_trace_buf_submit(entry, size, rctx, 0, 1, regs, head, NULL);
+
+ return;
+out:
+ perf_swevent_put_recursion_context(rctx);
}
NOKPROBE_SYMBOL(kretprobe_perf_func);
#endif /* CONFIG_PERF_EVENTS */
--
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/
[toc] | [prev] | [next] | [standalone]
| From | He Kuang <hekuang@huawei.com> |
|---|---|
| Date | 2015-07-02 16:00 +0200 |
| Subject | [RFC PATCH v2 4/4] tracing/kprobe: Combine bpf output and perf event output |
| Message-ID | <pHNbZ-3p1-31@gated-at.bofh.it> |
| In reply to | #1175995 |
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/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web