diff options
author | Oleg Nesterov <oleg@redhat.com> | 2013-06-20 13:38:06 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2013-07-01 20:34:23 -0400 |
commit | 288e984e622336bab8bc3dfdf2f190816362d9a1 (patch) | |
tree | f760ff7bfe1278767f1dd2e2a95d91768ab5ecee /kernel/trace/trace_kprobe.c | |
parent | 6e94a780374ed31b280f939d4757e8d7858dff16 (diff) |
tracing/kprobes: Avoid perf_trace_buf_*() if ->perf_events is empty
perf_trace_buf_prepare() + perf_trace_buf_submit() make no sense
if this task/CPU has no active counters. Change kprobe_perf_func()
and kretprobe_perf_func() to check call->perf_events beforehand
and return if this list is empty.
For example, "perf record -e some_probe -p1". Only /sbin/init will
report, all other threads which hit the same probe will do
perf_trace_buf_prepare/perf_trace_buf_submit just to realize that
nobody wants perf_swevent_event().
Link: http://lkml.kernel.org/r/20130620173806.GA13151@redhat.com
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/trace_kprobe.c')
-rw-r--r-- | kernel/trace/trace_kprobe.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index f2374172ba7b..c35bebe53ffe 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -1156,6 +1156,10 @@ kprobe_perf_func(struct trace_probe *tp, struct pt_regs *regs) | |||
1156 | int size, __size, dsize; | 1156 | int size, __size, dsize; |
1157 | int rctx; | 1157 | int rctx; |
1158 | 1158 | ||
1159 | head = this_cpu_ptr(call->perf_events); | ||
1160 | if (hlist_empty(head)) | ||
1161 | return; | ||
1162 | |||
1159 | dsize = __get_data_size(tp, regs); | 1163 | dsize = __get_data_size(tp, regs); |
1160 | __size = sizeof(*entry) + tp->size + dsize; | 1164 | __size = sizeof(*entry) + tp->size + dsize; |
1161 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); | 1165 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
@@ -1171,8 +1175,6 @@ kprobe_perf_func(struct trace_probe *tp, struct pt_regs *regs) | |||
1171 | entry->ip = (unsigned long)tp->rp.kp.addr; | 1175 | entry->ip = (unsigned long)tp->rp.kp.addr; |
1172 | memset(&entry[1], 0, dsize); | 1176 | memset(&entry[1], 0, dsize); |
1173 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); | 1177 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); |
1174 | |||
1175 | head = this_cpu_ptr(call->perf_events); | ||
1176 | perf_trace_buf_submit(entry, size, rctx, | 1178 | perf_trace_buf_submit(entry, size, rctx, |
1177 | entry->ip, 1, regs, head, NULL); | 1179 | entry->ip, 1, regs, head, NULL); |
1178 | } | 1180 | } |
@@ -1188,6 +1190,10 @@ kretprobe_perf_func(struct trace_probe *tp, struct kretprobe_instance *ri, | |||
1188 | int size, __size, dsize; | 1190 | int size, __size, dsize; |
1189 | int rctx; | 1191 | int rctx; |
1190 | 1192 | ||
1193 | head = this_cpu_ptr(call->perf_events); | ||
1194 | if (hlist_empty(head)) | ||
1195 | return; | ||
1196 | |||
1191 | dsize = __get_data_size(tp, regs); | 1197 | dsize = __get_data_size(tp, regs); |
1192 | __size = sizeof(*entry) + tp->size + dsize; | 1198 | __size = sizeof(*entry) + tp->size + dsize; |
1193 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); | 1199 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
@@ -1203,8 +1209,6 @@ kretprobe_perf_func(struct trace_probe *tp, struct kretprobe_instance *ri, | |||
1203 | entry->func = (unsigned long)tp->rp.kp.addr; | 1209 | entry->func = (unsigned long)tp->rp.kp.addr; |
1204 | entry->ret_ip = (unsigned long)ri->ret_addr; | 1210 | entry->ret_ip = (unsigned long)ri->ret_addr; |
1205 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); | 1211 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); |
1206 | |||
1207 | head = this_cpu_ptr(call->perf_events); | ||
1208 | perf_trace_buf_submit(entry, size, rctx, | 1212 | perf_trace_buf_submit(entry, size, rctx, |
1209 | entry->ret_ip, 1, regs, head, NULL); | 1213 | entry->ret_ip, 1, regs, head, NULL); |
1210 | } | 1214 | } |