diff options
author | Zhou Chengming <zhouchengming1@huawei.com> | 2017-08-25 09:49:37 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2017-08-29 07:29:29 -0400 |
commit | 75e8387685f6c65feb195a4556110b58f852b848 (patch) | |
tree | 1c8f8318f1fe76197a2a0d2fcfc53992b1855b30 | |
parent | f12f42acdbb577a12eecfcebbbec41c81505c4dc (diff) |
perf/ftrace: Fix double traces of perf on ftrace:function
When running perf on the ftrace:function tracepoint, there is a bug
which can be reproduced by:
perf record -e ftrace:function -a sleep 20 &
perf record -e ftrace:function ls
perf script
ls 10304 [005] 171.853235: ftrace:function:
perf_output_begin
ls 10304 [005] 171.853237: ftrace:function:
perf_output_begin
ls 10304 [005] 171.853239: ftrace:function:
task_tgid_nr_ns
ls 10304 [005] 171.853240: ftrace:function:
task_tgid_nr_ns
ls 10304 [005] 171.853242: ftrace:function:
__task_pid_nr_ns
ls 10304 [005] 171.853244: ftrace:function:
__task_pid_nr_ns
We can see that all the function traces are doubled.
The problem is caused by the inconsistency of the register
function perf_ftrace_event_register() with the probe function
perf_ftrace_function_call(). The former registers one probe
for every perf_event. And the latter handles all perf_events
on the current cpu. So when two perf_events on the current cpu,
the traces of them will be doubled.
So this patch adds an extra parameter "event" for perf_tp_event,
only send sample data to this event when it's not NULL.
Signed-off-by: Zhou Chengming <zhouchengming1@huawei.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: acme@kernel.org
Cc: alexander.shishkin@linux.intel.com
Cc: huawei.libin@huawei.com
Link: http://lkml.kernel.org/r/1503668977-12526-1-git-send-email-zhouchengming1@huawei.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | include/linux/perf_event.h | 2 | ||||
-rw-r--r-- | include/linux/trace_events.h | 4 | ||||
-rw-r--r-- | kernel/events/core.c | 13 | ||||
-rw-r--r-- | kernel/trace/trace_event_perf.c | 4 | ||||
-rw-r--r-- | kernel/trace/trace_kprobe.c | 4 | ||||
-rw-r--r-- | kernel/trace/trace_syscalls.c | 4 | ||||
-rw-r--r-- | kernel/trace/trace_uprobe.c | 2 |
7 files changed, 20 insertions, 13 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index b14095bcf4bb..c00cd4b02f32 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -1201,7 +1201,7 @@ extern void perf_event_init(void); | |||
1201 | extern void perf_tp_event(u16 event_type, u64 count, void *record, | 1201 | extern void perf_tp_event(u16 event_type, u64 count, void *record, |
1202 | int entry_size, struct pt_regs *regs, | 1202 | int entry_size, struct pt_regs *regs, |
1203 | struct hlist_head *head, int rctx, | 1203 | struct hlist_head *head, int rctx, |
1204 | struct task_struct *task); | 1204 | struct task_struct *task, struct perf_event *event); |
1205 | extern void perf_bp_event(struct perf_event *event, void *data); | 1205 | extern void perf_bp_event(struct perf_event *event, void *data); |
1206 | 1206 | ||
1207 | #ifndef perf_misc_flags | 1207 | #ifndef perf_misc_flags |
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 536c80ff7ad9..5012b524283d 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h | |||
@@ -508,9 +508,9 @@ void perf_trace_run_bpf_submit(void *raw_data, int size, int rctx, | |||
508 | static inline void | 508 | static inline void |
509 | perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type, | 509 | perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type, |
510 | u64 count, struct pt_regs *regs, void *head, | 510 | u64 count, struct pt_regs *regs, void *head, |
511 | struct task_struct *task) | 511 | struct task_struct *task, struct perf_event *event) |
512 | { | 512 | { |
513 | perf_tp_event(type, count, raw_data, size, regs, head, rctx, task); | 513 | perf_tp_event(type, count, raw_data, size, regs, head, rctx, task, event); |
514 | } | 514 | } |
515 | #endif | 515 | #endif |
516 | 516 | ||
diff --git a/kernel/events/core.c b/kernel/events/core.c index ce131d25622a..03ac9c8b02fb 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -7906,16 +7906,15 @@ void perf_trace_run_bpf_submit(void *raw_data, int size, int rctx, | |||
7906 | } | 7906 | } |
7907 | } | 7907 | } |
7908 | perf_tp_event(call->event.type, count, raw_data, size, regs, head, | 7908 | perf_tp_event(call->event.type, count, raw_data, size, regs, head, |
7909 | rctx, task); | 7909 | rctx, task, NULL); |
7910 | } | 7910 | } |
7911 | EXPORT_SYMBOL_GPL(perf_trace_run_bpf_submit); | 7911 | EXPORT_SYMBOL_GPL(perf_trace_run_bpf_submit); |
7912 | 7912 | ||
7913 | void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size, | 7913 | void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size, |
7914 | struct pt_regs *regs, struct hlist_head *head, int rctx, | 7914 | struct pt_regs *regs, struct hlist_head *head, int rctx, |
7915 | struct task_struct *task) | 7915 | struct task_struct *task, struct perf_event *event) |
7916 | { | 7916 | { |
7917 | struct perf_sample_data data; | 7917 | struct perf_sample_data data; |
7918 | struct perf_event *event; | ||
7919 | 7918 | ||
7920 | struct perf_raw_record raw = { | 7919 | struct perf_raw_record raw = { |
7921 | .frag = { | 7920 | .frag = { |
@@ -7929,9 +7928,15 @@ void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size, | |||
7929 | 7928 | ||
7930 | perf_trace_buf_update(record, event_type); | 7929 | perf_trace_buf_update(record, event_type); |
7931 | 7930 | ||
7932 | hlist_for_each_entry_rcu(event, head, hlist_entry) { | 7931 | /* Use the given event instead of the hlist */ |
7932 | if (event) { | ||
7933 | if (perf_tp_event_match(event, &data, regs)) | 7933 | if (perf_tp_event_match(event, &data, regs)) |
7934 | perf_swevent_event(event, count, &data, regs); | 7934 | perf_swevent_event(event, count, &data, regs); |
7935 | } else { | ||
7936 | hlist_for_each_entry_rcu(event, head, hlist_entry) { | ||
7937 | if (perf_tp_event_match(event, &data, regs)) | ||
7938 | perf_swevent_event(event, count, &data, regs); | ||
7939 | } | ||
7935 | } | 7940 | } |
7936 | 7941 | ||
7937 | /* | 7942 | /* |
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 562fa69df5d3..13ba2d3f6a91 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c | |||
@@ -306,6 +306,7 @@ static void | |||
306 | perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip, | 306 | perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip, |
307 | struct ftrace_ops *ops, struct pt_regs *pt_regs) | 307 | struct ftrace_ops *ops, struct pt_regs *pt_regs) |
308 | { | 308 | { |
309 | struct perf_event *event; | ||
309 | struct ftrace_entry *entry; | 310 | struct ftrace_entry *entry; |
310 | struct hlist_head *head; | 311 | struct hlist_head *head; |
311 | struct pt_regs regs; | 312 | struct pt_regs regs; |
@@ -329,8 +330,9 @@ perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip, | |||
329 | 330 | ||
330 | entry->ip = ip; | 331 | entry->ip = ip; |
331 | entry->parent_ip = parent_ip; | 332 | entry->parent_ip = parent_ip; |
333 | event = container_of(ops, struct perf_event, ftrace_ops); | ||
332 | perf_trace_buf_submit(entry, ENTRY_SIZE, rctx, TRACE_FN, | 334 | perf_trace_buf_submit(entry, ENTRY_SIZE, rctx, TRACE_FN, |
333 | 1, ®s, head, NULL); | 335 | 1, ®s, head, NULL, event); |
334 | 336 | ||
335 | #undef ENTRY_SIZE | 337 | #undef ENTRY_SIZE |
336 | } | 338 | } |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index c9b5aa10fbf9..8a907e12b6b9 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -1200,7 +1200,7 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs) | |||
1200 | memset(&entry[1], 0, dsize); | 1200 | memset(&entry[1], 0, dsize); |
1201 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); | 1201 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); |
1202 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, | 1202 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, |
1203 | head, NULL); | 1203 | head, NULL, NULL); |
1204 | } | 1204 | } |
1205 | NOKPROBE_SYMBOL(kprobe_perf_func); | 1205 | NOKPROBE_SYMBOL(kprobe_perf_func); |
1206 | 1206 | ||
@@ -1236,7 +1236,7 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, | |||
1236 | entry->ret_ip = (unsigned long)ri->ret_addr; | 1236 | entry->ret_ip = (unsigned long)ri->ret_addr; |
1237 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); | 1237 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); |
1238 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, | 1238 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, |
1239 | head, NULL); | 1239 | head, NULL, NULL); |
1240 | } | 1240 | } |
1241 | NOKPROBE_SYMBOL(kretprobe_perf_func); | 1241 | NOKPROBE_SYMBOL(kretprobe_perf_func); |
1242 | #endif /* CONFIG_PERF_EVENTS */ | 1242 | #endif /* CONFIG_PERF_EVENTS */ |
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 5e10395da88e..74d9a86eccc0 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c | |||
@@ -596,7 +596,7 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) | |||
596 | (unsigned long *)&rec->args); | 596 | (unsigned long *)&rec->args); |
597 | perf_trace_buf_submit(rec, size, rctx, | 597 | perf_trace_buf_submit(rec, size, rctx, |
598 | sys_data->enter_event->event.type, 1, regs, | 598 | sys_data->enter_event->event.type, 1, regs, |
599 | head, NULL); | 599 | head, NULL, NULL); |
600 | } | 600 | } |
601 | 601 | ||
602 | static int perf_sysenter_enable(struct trace_event_call *call) | 602 | static int perf_sysenter_enable(struct trace_event_call *call) |
@@ -667,7 +667,7 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) | |||
667 | rec->nr = syscall_nr; | 667 | rec->nr = syscall_nr; |
668 | rec->ret = syscall_get_return_value(current, regs); | 668 | rec->ret = syscall_get_return_value(current, regs); |
669 | perf_trace_buf_submit(rec, size, rctx, sys_data->exit_event->event.type, | 669 | perf_trace_buf_submit(rec, size, rctx, sys_data->exit_event->event.type, |
670 | 1, regs, head, NULL); | 670 | 1, regs, head, NULL, NULL); |
671 | } | 671 | } |
672 | 672 | ||
673 | static int perf_sysexit_enable(struct trace_event_call *call) | 673 | static int perf_sysexit_enable(struct trace_event_call *call) |
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index a7581fec9681..4525e0271a53 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c | |||
@@ -1156,7 +1156,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu, | |||
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, | 1158 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, |
1159 | head, NULL); | 1159 | head, NULL, NULL); |
1160 | out: | 1160 | out: |
1161 | preempt_enable(); | 1161 | preempt_enable(); |
1162 | } | 1162 | } |