tracing: Use the perf recursion protection from trace event
Subsystems (3)
PATCH 1/4 tracing: Use the perf recursion protection from trace event
When we commit a trace to perf, we first check if we are recursing in the same buffer so that we don't mess-up the buffer with a recursing trace. But later on, we do the same check from perf to avoid commit recursion. The recursion check is desired early before we touch the buffer but we want to do this check only once.
Then export the recursion protection from perf and use it from the trace events before submitting a trace.
--- include/linux/ftrace_event.h | 9 +---- include/linux/perf_event.h | 4 ++ include/trace/ftrace.h | 23 ++++++------ kernel/perf_event.c | 68 +++++++++++++++++++++++------------ kernel/trace/trace_event_profile.c | 14 ++++--- kernel/trace/trace_kprobe.c | 48 +++++++++---------------- kernel/trace/trace_syscalls.c | 47 +++++++++---------------- 7 files changed, 106 insertions(+), 107 deletions(-)
include/linux/ftrace_event.h +2 -7
@@ -137,13 +137,8 @@ struct ftrace_event_call {#define FTRACE_MAX_PROFILE_SIZE 2048 -struct perf_trace_buf { -char buf[FTRACE_MAX_PROFILE_SIZE ]; -int recursion; -}; - -extern struct perf_trace_buf *perf_trace_buf; -extern struct perf_trace_buf *perf_trace_buf_nmi; +extern char *perf_trace_buf; +extern char *perf_trace_buf_nmi;#define MAX_FILTER_PRED 32#define MAX_FILTER_STR_VAL 256/* Should handle KSYM_SYMBOL_LEN */
include/linux/perf_event.h +4 -0
@@ -874,6 +874,8 @@ extern int perf_output_begin(struct perf_output_handle *handle,extern void perf_output_end (struct perf_output_handle *handle);extern void perf_output_copy (struct perf_output_handle *handle,const void *buf,unsigned int len); +extern int perf_swevent_get_recursion_context (int **recursion); +extern void perf_swevent_put_recursion_context (int *recursion);#else static inline void perf_event_task_sched_in (struct task_struct *task,int cpu) { }
@@ -902,6 +904,8 @@ static inline void perf_event_mmap(struct vm_area_struct *vma) { }static inline void perf_event_comm (struct task_struct *tsk) { }static inline void perf_event_fork (struct task_struct *tsk) { }static inline void perf_event_init (void ) { } +static int perf_swevent_get_recursion_context (int **recursion) {return -1 ; } +static void perf_swevent_put_recursion_context (int *recursion) { }#endif
include/trace/ftrace.h +12 -11
@@ -724,16 +724,19 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ static void ftrace_profile_##call(proto) \ { \ struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ + extern int perf_swevent_get_recursion_context(int **recursion); \ + extern void perf_swevent_put_recursion_context(int *recursion); \ struct ftrace_event_call *event_call = &event_##call; \ extern void perf_tp_event(int, u64, u64, void *, int); \ struct ftrace_raw_##call *entry; \ - struct perf_trace_buf *trace_buf; \ u64 __addr = 0, __count = 1; \ unsigned long irq_flags; \ struct trace_entry *ent; \ int __entry_size; \ int __data_size; \ + char *trace_buf; \ char *raw_data; \ + int *recursion; \ int __cpu; \ int pc; \ \
@@ -749,6 +752,10 @@ static void ftrace_profile_##call(proto) \return ; \ \local_irq_save (irq_flags); \ + \ +if (perf_swevent_get_recursion_context (&recursion)) \ + goto end_recursion; \ + \ __cpu =smp_processor_id (); \ \if (in_nmi ()) \
@@ -759,13 +766,7 @@ static void ftrace_profile_##call(proto) \if (!trace_buf) \ goto end; \ \ - trace_buf =per_cpu_ptr (trace_buf, __cpu); \ -if (trace_buf->recursion++) \ - goto end_recursion; \ - \ -barrier (); \ - \ - raw_data = trace_buf->buf; \ + raw_data =per_cpu_ptr (trace_buf, __cpu); \ \ *(u64 *)(&raw_data[__entry_size -sizeof (u64)]) =0ULL ; \ entry = (struct ftrace_raw_##call *)raw_data; \
@@ -780,9 +781,9 @@ static void ftrace_profile_##call(proto) \perf_tp_event (event_call->id, __addr, __count, entry, \ __entry_size); \ \ -end_recursion: \ - trace_buf->recursion--; \ -end: \ +end: \ +perf_swevent_put_recursion_context (recursion); \ +end_recursion: \local_irq_restore (irq_flags); \ \ }
kernel/perf_event.c +45 -23
98 lines not on this page · raw message
kernel/trace/trace_event_profile.c +8 -6
@@ -9,31 +9,33 @@#include "trace.h" -struct perf_trace_buf *perf_trace_buf; +char *perf_trace_buf;EXPORT_SYMBOL_GPL (perf_trace_buf); -struct perf_trace_buf *perf_trace_buf_nmi; +char *perf_trace_buf_nmi;EXPORT_SYMBOL_GPL (perf_trace_buf_nmi); +typedef typeof (char [FTRACE_MAX_PROFILE_SIZE ])perf_trace_t ; +/* Count the events in use (per event id, not per instance) */ static int total_profile_count;static int ftrace_profile_enable_event (struct ftrace_event_call *event) { -struct perf_trace_buf *buf; +char *buf;int ret = -ENOMEM ;if (atomic_inc_return (&event->profile_count))return 0 ;if (!total_profile_count) { - buf = alloc_percpu(struct perf_trace_buf); + buf = (char *)alloc_percpu (perf_trace_t);if (!buf) goto fail_buf;rcu_assign_pointer (perf_trace_buf, buf); - buf = alloc_percpu(struct perf_trace_buf); + buf = (char *)alloc_percpu (perf_trace_t);if (!buf) goto fail_buf_nmi;
@@ -79,7 +81,7 @@ int ftrace_profile_enable(int event_id)static void ftrace_profile_disable_event (struct ftrace_event_call *event) { -struct perf_trace_buf *buf, *nmi_buf; +char *buf, *nmi_buf;if (!atomic_add_negative (-1 , &event->profile_count))return ;
kernel/trace/trace_kprobe.c +18 -30
105 lines not on this page · raw message
kernel/trace/trace_syscalls.c +17 -30
103 lines not on this page · raw message
Signature · 1 line
1.6.2.3
PATCH 2/4 tracing: Forget about the nmi buffer from syscall events
We are never in an nmi context when we commit a syscall trace to perf. So just forget about the nmi buffer there.
--- kernel/trace/trace_syscalls.c | 10 ++-------- 1 files changed, 2 insertions(+), 8 deletions(-)
kernel/trace/trace_syscalls.c +2 -8
@@ -511,10 +511,7 @@ static void prof_syscall_enter(struct pt_regs *regs, long id) cpu =smp_processor_id (); -if (in_nmi ()) - trace_buf =rcu_dereference (perf_trace_buf_nmi); -else - trace_buf =rcu_dereference (perf_trace_buf); + trace_buf =rcu_dereference (perf_trace_buf);if (!trace_buf) goto end;
@@ -617,10 +614,7 @@ static void prof_syscall_exit(struct pt_regs *regs, long ret) cpu =smp_processor_id (); -if (in_nmi ()) - trace_buf =rcu_dereference (perf_trace_buf_nmi); -else - trace_buf =rcu_dereference (perf_trace_buf); + trace_buf =rcu_dereference (perf_trace_buf);if (!trace_buf) goto end;
Signature · 1 line
1.6.2.3
[tip:perf/core] tracing: Forget about the NMI buffer for syscall events
Commit-ID: 28889bf9e2db29747d58cd47a92d727f927c3aee Gitweb: http://git.kernel.org/tip/28889bf9e2db29747d58cd47a92d727f927c3aee Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 22 Nov 2009 05:21:33 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 22 Nov 2009 09:03:42 +0100
tracing: Forget about the NMI buffer for syscall events
We are never in an NMI context when we commit a syscall trace to perf. So just forget about the nmi buffer there.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_syscalls.c | 10 ++-------- 1 files changed, 2 insertions(+), 8 deletions(-)
kernel/trace/trace_syscalls.c +2 -8
@@ -511,10 +511,7 @@ static void prof_syscall_enter(struct pt_regs *regs, long id) cpu =smp_processor_id (); -if (in_nmi ()) - trace_buf =rcu_dereference (perf_trace_buf_nmi); -else - trace_buf =rcu_dereference (perf_trace_buf); + trace_buf =rcu_dereference (perf_trace_buf);if (!trace_buf) goto end;
@@ -617,10 +614,7 @@ static void prof_syscall_exit(struct pt_regs *regs, long ret) cpu =smp_processor_id (); -if (in_nmi ()) - trace_buf =rcu_dereference (perf_trace_buf_nmi); -else - trace_buf =rcu_dereference (perf_trace_buf); + trace_buf =rcu_dereference (perf_trace_buf);if (!trace_buf) goto end;
PATCH 3/4 hw-breakpoints: Remove x86 specific headers from core file
In reply to Frederic WeisbeckerRemove asm/processor.h and asm/debugreg.h as these headers are not used anymore in the hw-breakpoints core file.
--- kernel/hw_breakpoint.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
kernel/hw_breakpoint.c +0 -6
@@ -40,12 +40,6 @@#include <linux/hw_breakpoint.h> -#include <asm/processor.h> - -#ifdef CONFIG_X86 -#include <asm/debugreg.h> -#endif -/* * Constraints data */
Signature · 1 line
1.6.2.3
[tip:perf/core] hw-breakpoints: Remove x86 specific headers from core file
Commit-ID: b3a75542d329ce4e1c66b293cefeb4429a2af043 Gitweb: http://git.kernel.org/tip/b3a75542d329ce4e1c66b293cefeb4429a2af043 Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 22 Nov 2009 05:21:34 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 22 Nov 2009 09:03:43 +0100
hw-breakpoints: Remove x86 specific headers from core file
Remove asm/processor.h and asm/debugreg.h as these headers are not used anymore in the hw-breakpoints core file.
LKML-Reference: <[email protected]>
--- kernel/hw_breakpoint.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
kernel/hw_breakpoint.c +0 -6
@@ -40,12 +40,6 @@#include <linux/hw_breakpoint.h> -#include <asm/processor.h> - -#ifdef CONFIG_X86 -#include <asm/debugreg.h> -#endif -/* * Constraints data */
PATCH 4/4 hw-breakpoints: Separate the kernel part from breakpoint headers
In reply to Frederic WeisbeckerSo that we can include this header from userspace tools, like perf tools, to get the breakpoint types and len definitions.
--- include/linux/hw_breakpoint.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/hw_breakpoint.h +2 -0
@@ -16,6 +16,7 @@ enum { HW_BREAKPOINT_X = 4, }; +#ifdef __KERNEL__#ifdef CONFIG_HAVE_HW_BREAKPOINT static inline unsigned long hw_breakpoint_addr (struct perf_event *bp)
@@ -133,5 +134,6 @@ static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) }#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* __KERNEL__ */ #endif /* _LINUX_HW_BREAKPOINT_H */
Signature · 1 line
1.6.2.3
[tip:perf/core] hw-breakpoints: Separate the kernel part from breakpoint headers
Commit-ID: 5093ebad5f2348076fdc3dac7d2358b1ad7f85f7 Gitweb: http://git.kernel.org/tip/5093ebad5f2348076fdc3dac7d2358b1ad7f85f7 Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 22 Nov 2009 05:21:35 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 22 Nov 2009 09:03:43 +0100
hw-breakpoints: Separate the kernel part from breakpoint headers
So that we can include this header from userspace tools, like perf tools, to get the breakpoint types and len definitions.
LKML-Reference: <[email protected]>
--- include/linux/hw_breakpoint.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/hw_breakpoint.h +2 -0
@@ -16,6 +16,7 @@ enum { HW_BREAKPOINT_X = 4, }; +#ifdef __KERNEL__#ifdef CONFIG_HAVE_HW_BREAKPOINT static inline unsigned long hw_breakpoint_addr (struct perf_event *bp)
@@ -133,5 +134,6 @@ static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) }#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* __KERNEL__ */ #endif /* _LINUX_HW_BREAKPOINT_H */
PATCH v2 1/4 tracing: Use the perf recursion protection from trace event
In reply to Frederic WeisbeckerWhen we commit a trace to perf, we first check if we are recursing in the same buffer so that we don't mess-up the buffer with a recursing trace. But later on, we do the same check from perf to avoid commit recursion. The recursion check is desired early before we touch the buffer but we want to do this check only once.
Then export the recursion protection from perf and use it from the trace events before submitting a trace.
v2: Put appropriate Reported-by tag
--- include/linux/ftrace_event.h | 9 +---- include/linux/perf_event.h | 4 ++ include/trace/ftrace.h | 23 ++++++------ kernel/perf_event.c | 68 +++++++++++++++++++++++------------ kernel/trace/trace_event_profile.c | 14 ++++--- kernel/trace/trace_kprobe.c | 48 +++++++++---------------- kernel/trace/trace_syscalls.c | 47 +++++++++---------------- 7 files changed, 106 insertions(+), 107 deletions(-)
include/linux/ftrace_event.h +2 -7
@@ -137,13 +137,8 @@ struct ftrace_event_call {#define FTRACE_MAX_PROFILE_SIZE 2048 -struct perf_trace_buf { -char buf[FTRACE_MAX_PROFILE_SIZE ]; -int recursion; -}; - -extern struct perf_trace_buf *perf_trace_buf; -extern struct perf_trace_buf *perf_trace_buf_nmi; +extern char *perf_trace_buf; +extern char *perf_trace_buf_nmi;#define MAX_FILTER_PRED 32#define MAX_FILTER_STR_VAL 256/* Should handle KSYM_SYMBOL_LEN */
include/linux/perf_event.h +4 -0
@@ -874,6 +874,8 @@ extern int perf_output_begin(struct perf_output_handle *handle,extern void perf_output_end (struct perf_output_handle *handle);extern void perf_output_copy (struct perf_output_handle *handle,const void *buf,unsigned int len); +extern int perf_swevent_get_recursion_context (int **recursion); +extern void perf_swevent_put_recursion_context (int *recursion);#else static inline void perf_event_task_sched_in (struct task_struct *task,int cpu) { }
@@ -902,6 +904,8 @@ static inline void perf_event_mmap(struct vm_area_struct *vma) { }static inline void perf_event_comm (struct task_struct *tsk) { }static inline void perf_event_fork (struct task_struct *tsk) { }static inline void perf_event_init (void ) { } +static int perf_swevent_get_recursion_context (int **recursion) {return -1 ; } +static void perf_swevent_put_recursion_context (int *recursion) { }#endif
include/trace/ftrace.h +12 -11
@@ -724,16 +724,19 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ static void ftrace_profile_##call(proto) \ { \ struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ + extern int perf_swevent_get_recursion_context(int **recursion); \ + extern void perf_swevent_put_recursion_context(int *recursion); \ struct ftrace_event_call *event_call = &event_##call; \ extern void perf_tp_event(int, u64, u64, void *, int); \ struct ftrace_raw_##call *entry; \ - struct perf_trace_buf *trace_buf; \ u64 __addr = 0, __count = 1; \ unsigned long irq_flags; \ struct trace_entry *ent; \ int __entry_size; \ int __data_size; \ + char *trace_buf; \ char *raw_data; \ + int *recursion; \ int __cpu; \ int pc; \ \
@@ -749,6 +752,10 @@ static void ftrace_profile_##call(proto) \return ; \ \local_irq_save (irq_flags); \ + \ +if (perf_swevent_get_recursion_context (&recursion)) \ + goto end_recursion; \ + \ __cpu =smp_processor_id (); \ \if (in_nmi ()) \
@@ -759,13 +766,7 @@ static void ftrace_profile_##call(proto) \if (!trace_buf) \ goto end; \ \ - trace_buf =per_cpu_ptr (trace_buf, __cpu); \ -if (trace_buf->recursion++) \ - goto end_recursion; \ - \ -barrier (); \ - \ - raw_data = trace_buf->buf; \ + raw_data =per_cpu_ptr (trace_buf, __cpu); \ \ *(u64 *)(&raw_data[__entry_size -sizeof (u64)]) =0ULL ; \ entry = (struct ftrace_raw_##call *)raw_data; \
@@ -780,9 +781,9 @@ static void ftrace_profile_##call(proto) \perf_tp_event (event_call->id, __addr, __count, entry, \ __entry_size); \ \ -end_recursion: \ - trace_buf->recursion--; \ -end: \ +end: \ +perf_swevent_put_recursion_context (recursion); \ +end_recursion: \local_irq_restore (irq_flags); \ \ }
kernel/perf_event.c +45 -23
98 lines not on this page · raw message
kernel/trace/trace_event_profile.c +8 -6
@@ -9,31 +9,33 @@#include "trace.h" -struct perf_trace_buf *perf_trace_buf; +char *perf_trace_buf;EXPORT_SYMBOL_GPL (perf_trace_buf); -struct perf_trace_buf *perf_trace_buf_nmi; +char *perf_trace_buf_nmi;EXPORT_SYMBOL_GPL (perf_trace_buf_nmi); +typedef typeof (char [FTRACE_MAX_PROFILE_SIZE ])perf_trace_t ; +/* Count the events in use (per event id, not per instance) */ static int total_profile_count;static int ftrace_profile_enable_event (struct ftrace_event_call *event) { -struct perf_trace_buf *buf; +char *buf;int ret = -ENOMEM ;if (atomic_inc_return (&event->profile_count))return 0 ;if (!total_profile_count) { - buf = alloc_percpu(struct perf_trace_buf); + buf = (char *)alloc_percpu (perf_trace_t);if (!buf) goto fail_buf;rcu_assign_pointer (perf_trace_buf, buf); - buf = alloc_percpu(struct perf_trace_buf); + buf = (char *)alloc_percpu (perf_trace_t);if (!buf) goto fail_buf_nmi;
@@ -79,7 +81,7 @@ int ftrace_profile_enable(int event_id)static void ftrace_profile_disable_event (struct ftrace_event_call *event) { -struct perf_trace_buf *buf, *nmi_buf; +char *buf, *nmi_buf;if (!atomic_add_negative (-1 , &event->profile_count))return ;
kernel/trace/trace_kprobe.c +18 -30
105 lines not on this page · raw message
kernel/trace/trace_syscalls.c +17 -30
103 lines not on this page · raw message
Signature · 1 line
1.6.2.3
Commit-ID: ce71b9df8893ec954e56c5979df6da274f20f65e Gitweb: http://git.kernel.org/tip/ce71b9df8893ec954e56c5979df6da274f20f65e Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 22 Nov 2009 05:26:55 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 22 Nov 2009 09:03:42 +0100
tracing: Use the perf recursion protection from trace event
When we commit a trace to perf, we first check if we are recursing in the same buffer so that we don't mess-up the buffer with a recursing trace. But later on, we do the same check from perf to avoid commit recursion. The recursion check is desired early before we touch the buffer but we want to do this check only once.
Then export the recursion protection from perf and use it from the trace events before submitting a trace.
v2: Put appropriate Reported-by tag
LKML-Reference: <[email protected]>
--- include/linux/ftrace_event.h | 9 +---- include/linux/perf_event.h | 4 ++ include/trace/ftrace.h | 23 ++++++------ kernel/perf_event.c | 68 +++++++++++++++++++++++------------ kernel/trace/trace_event_profile.c | 14 ++++--- kernel/trace/trace_kprobe.c | 48 +++++++++---------------- kernel/trace/trace_syscalls.c | 47 +++++++++---------------- 7 files changed, 106 insertions(+), 107 deletions(-)
include/linux/ftrace_event.h +2 -7
@@ -137,13 +137,8 @@ struct ftrace_event_call {#define FTRACE_MAX_PROFILE_SIZE 2048 -struct perf_trace_buf { -char buf[FTRACE_MAX_PROFILE_SIZE ]; -int recursion; -}; - -extern struct perf_trace_buf *perf_trace_buf; -extern struct perf_trace_buf *perf_trace_buf_nmi; +extern char *perf_trace_buf; +extern char *perf_trace_buf_nmi;#define MAX_FILTER_PRED 32#define MAX_FILTER_STR_VAL 256/* Should handle KSYM_SYMBOL_LEN */
include/linux/perf_event.h +4 -0
@@ -874,6 +874,8 @@ extern int perf_output_begin(struct perf_output_handle *handle,extern void perf_output_end (struct perf_output_handle *handle);extern void perf_output_copy (struct perf_output_handle *handle,const void *buf,unsigned int len); +extern int perf_swevent_get_recursion_context (int **recursion); +extern void perf_swevent_put_recursion_context (int *recursion);#else static inline void perf_event_task_sched_in (struct task_struct *task,int cpu) { }
@@ -902,6 +904,8 @@ static inline void perf_event_mmap(struct vm_area_struct *vma) { }static inline void perf_event_comm (struct task_struct *tsk) { }static inline void perf_event_fork (struct task_struct *tsk) { }static inline void perf_event_init (void ) { } +static int perf_swevent_get_recursion_context (int **recursion) {return -1 ; } +static void perf_swevent_put_recursion_context (int *recursion) { }#endif
include/trace/ftrace.h +12 -11
@@ -724,16 +724,19 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ static void ftrace_profile_##call(proto) \ { \ struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ + extern int perf_swevent_get_recursion_context(int **recursion); \ + extern void perf_swevent_put_recursion_context(int *recursion); \ struct ftrace_event_call *event_call = &event_##call; \ extern void perf_tp_event(int, u64, u64, void *, int); \ struct ftrace_raw_##call *entry; \ - struct perf_trace_buf *trace_buf; \ u64 __addr = 0, __count = 1; \ unsigned long irq_flags; \ struct trace_entry *ent; \ int __entry_size; \ int __data_size; \ + char *trace_buf; \ char *raw_data; \ + int *recursion; \ int __cpu; \ int pc; \ \
@@ -749,6 +752,10 @@ static void ftrace_profile_##call(proto) \return ; \ \local_irq_save (irq_flags); \ + \ +if (perf_swevent_get_recursion_context (&recursion)) \ + goto end_recursion; \ + \ __cpu =smp_processor_id (); \ \if (in_nmi ()) \
@@ -759,13 +766,7 @@ static void ftrace_profile_##call(proto) \if (!trace_buf) \ goto end; \ \ - trace_buf =per_cpu_ptr (trace_buf, __cpu); \ -if (trace_buf->recursion++) \ - goto end_recursion; \ - \ -barrier (); \ - \ - raw_data = trace_buf->buf; \ + raw_data =per_cpu_ptr (trace_buf, __cpu); \ \ *(u64 *)(&raw_data[__entry_size -sizeof (u64)]) =0ULL ; \ entry = (struct ftrace_raw_##call *)raw_data; \
@@ -780,9 +781,9 @@ static void ftrace_profile_##call(proto) \perf_tp_event (event_call->id, __addr, __count, entry, \ __entry_size); \ \ -end_recursion: \ - trace_buf->recursion--; \ -end: \ +end: \ +perf_swevent_put_recursion_context (recursion); \ +end_recursion: \local_irq_restore (irq_flags); \ \ }
kernel/perf_event.c +45 -23
98 lines not on this page · raw message
kernel/trace/trace_event_profile.c +8 -6
@@ -9,31 +9,33 @@#include "trace.h" -struct perf_trace_buf *perf_trace_buf; +char *perf_trace_buf;EXPORT_SYMBOL_GPL (perf_trace_buf); -struct perf_trace_buf *perf_trace_buf_nmi; +char *perf_trace_buf_nmi;EXPORT_SYMBOL_GPL (perf_trace_buf_nmi); +typedef typeof (char [FTRACE_MAX_PROFILE_SIZE ])perf_trace_t ; +/* Count the events in use (per event id, not per instance) */ static int total_profile_count;static int ftrace_profile_enable_event (struct ftrace_event_call *event) { -struct perf_trace_buf *buf; +char *buf;int ret = -ENOMEM ;if (atomic_inc_return (&event->profile_count))return 0 ;if (!total_profile_count) { - buf = alloc_percpu(struct perf_trace_buf); + buf = (char *)alloc_percpu (perf_trace_t);if (!buf) goto fail_buf;rcu_assign_pointer (perf_trace_buf, buf); - buf = alloc_percpu(struct perf_trace_buf); + buf = (char *)alloc_percpu (perf_trace_t);if (!buf) goto fail_buf_nmi;
@@ -79,7 +81,7 @@ int ftrace_profile_enable(int event_id)static void ftrace_profile_disable_event (struct ftrace_event_call *event) { -struct perf_trace_buf *buf, *nmi_buf; +char *buf, *nmi_buf;if (!atomic_add_negative (-1 , &event->profile_count))return ;
kernel/trace/trace_kprobe.c +18 -30
105 lines not on this page · raw message
kernel/trace/trace_syscalls.c +17 -30
103 lines not on this page · raw message
[tip:perf/core] perf_events: Fix modular build
In reply to Frederic WeisbeckerCommit-ID: 645e8cc0c9f01f07f384fd522b782e5e6ae9de18 Gitweb: http://git.kernel.org/tip/645e8cc0c9f01f07f384fd522b782e5e6ae9de18 Author: Ingo Molnar <[email protected]> AuthorDate: Sun, 22 Nov 2009 12:20:19 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 22 Nov 2009 12:21:33 +0100
perf_events: Fix modular build
Fix:
ERROR: "perf_swevent_put_recursion_context" [fs/ext4/ext4.ko] undefined!
ERROR: "perf_swevent_get_recursion_context" [fs/ext4/ext4.ko] undefined!
Cc: Frederic Weisbecker <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Jason Baron <[email protected]>
LKML-Reference: <[email protected]>
--- kernel/perf_event.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
kernel/perf_event.c +2 -0
@@ -3903,11 +3903,13 @@ int perf_swevent_get_recursion_context(int **recursion)return 0 ; } +EXPORT_SYMBOL_GPL (perf_swevent_get_recursion_context);void perf_swevent_put_recursion_context (int *recursion) { (*recursion)--; } +EXPORT_SYMBOL_GPL (perf_swevent_put_recursion_context); static void __do_perf_sw_event(enum perf_type_id type, u32 event_id, u64 nr, int nmi,
Peter Zijlstra
maintainerQuoted 28 lines · Frederic Weisbecker
kernel/perf_event.c +13
-4@@ -3880,34 +3880,42 @@ static void perf_swevent_ctx_event(struct perf_event_context *ctx, } } -static int *perf_swevent_recursion_context (struct perf_cpu_context *cpuctx) +/* +* Must be called with preemption disabled +*/ +int perf_swevent_get_recursion_context (int **recursion) { +struct perf_cpu_context *cpuctx = &__get_cpu_var (perf_cpu_context); +if (in_nmi ()) -return &cpuctx->recursion[3 ]; + *recursion = &cpuctx->recursion[3 ]; +else if (in_irq ()) + *recursion = &cpuctx->recursion[2 ]; +else if (in_softirq ()) + *recursion = &cpuctx->recursion[1 ]; +else + *recursion = &cpuctx->recursion[0 ]; -if (in_irq ()) -return &cpuctx->recursion[2 ];
kernel/perf_event.c static void perf_swevent_ctx_event(struct perf_event_context *ctx, · line 3905
Quoted 10 lines
kernel/perf_event.c +4
-3+if (**recursion) +return -1 ; -if (in_softirq ()) -return &cpuctx->recursion[1 ]; + (**recursion)++; -return &cpuctx->recursion[0 ]; +return 0 ; }
You lost the barrier();
Quoted 4 lines
kernel/perf_event.c +0
-4-static void do_perf_sw_event (enum perf_type_id type,u32 event_id, -u64 nr,int nmi, -struct perf_sample_data *data, -struct pt_regs *regs)
kernel/perf_event.c static void perf_swevent_ctx_event(struct perf_event_context *ctx, · line 3910
Quoted 10 lines
kernel/perf_event.c +3
-6+void perf_swevent_put_recursion_context (int *recursion) { -struct perf_cpu_context *cpuctx = &get_cpu_var (perf_cpu_context); -int *recursion =perf_swevent_recursion_context (cpuctx); -struct perf_event_context *ctx; - -if (*recursion) - goto out; + (*recursion)--; +}
And here as well.
Furthermore, its much cleaner if you simply use get_cpu_var(perf_cpu_context) in get_recursion_context, and put_cpu_var() in put_recursion_context.
That way you put the preempt_disable where it belongs, instead of:
Quoted 9 lines
kernel/perf_event.c +9
-0+static void do_perf_sw_event (enum perf_type_id type,u32 event_id, +u64 nr,int nmi, +struct perf_sample_data *data, +struct pt_regs *regs) +{ +int *recursion; + +preempt_disable (); +
kernel/perf_event.c static void do_perf_sw_event(enum perf_type_id type, u32 event_id, · line 3950
Quoted 10 lines
kernel/perf_event.c +6
-1+if (perf_swevent_get_recursion_context (&recursion)) + goto out; + +__do_perf_sw_event (type, event_id, nr, nmi, data, regs); +perf_swevent_put_recursion_context (recursion); out: -put_cpu_var (perf_cpu_context); +preempt_enable (); }
mucking about like here, also it cleans up the code in that you don't have to drag that recursion variable around like so.
Quoted 42 lines · Peter Zijlstra
Quoted 28 lines · Frederic Weisbecker
kernel/perf_event.c +13
-4@@ -3880,34 +3880,42 @@ static void perf_swevent_ctx_event(struct perf_event_context *ctx, } } -static int *perf_swevent_recursion_context (struct perf_cpu_context *cpuctx) +/* +* Must be called with preemption disabled +*/ +int perf_swevent_get_recursion_context (int **recursion) { +struct perf_cpu_context *cpuctx = &__get_cpu_var (perf_cpu_context); +if (in_nmi ()) -return &cpuctx->recursion[3 ]; + *recursion = &cpuctx->recursion[3 ]; +else if (in_irq ()) + *recursion = &cpuctx->recursion[2 ]; +else if (in_softirq ()) + *recursion = &cpuctx->recursion[1 ]; +else + *recursion = &cpuctx->recursion[0 ]; -if (in_irq ()) -return &cpuctx->recursion[2 ];kernel/perf_event.c static void perf_swevent_ctx_event(struct perf_event_context *ctx, · line 3905
Quoted 10 lines
kernel/perf_event.c +4
-3+if (**recursion) +return -1 ; -if (in_softirq ()) -return &cpuctx->recursion[1 ]; + (**recursion)++; -return &cpuctx->recursion[0 ]; +return 0 ; }You lost the
barrier();
Quoted 16 lines
Quoted 4 lines
kernel/perf_event.c +0
-4-static void do_perf_sw_event (enum perf_type_id type,u32 event_id, -u64 nr,int nmi, -struct perf_sample_data *data, -struct pt_regs *regs)kernel/perf_event.c static void perf_swevent_ctx_event(struct perf_event_context *ctx, · line 3910
Quoted 10 lines
kernel/perf_event.c +3
-6+void perf_swevent_put_recursion_context (int *recursion) { -struct perf_cpu_context *cpuctx = &get_cpu_var (perf_cpu_context); -int *recursion =perf_swevent_recursion_context (cpuctx); -struct perf_event_context *ctx; - -if (*recursion) - goto out; + (*recursion)--; +}And here as well.
Global functions are in essence a barrier() to GCC but yeah.
Ingo
Peter Zijlstra
maintainerQuoted 13 lines · Ingo Molnar
Quoted 4 lines
Quoted 4 lines
kernel/perf_event.c +1
-2+void perf_swevent_put_recursion_context (int *recursion) { -struct perf_cpu_context *cpuctx = &get_cpu_var (perf_cpu_context); -int *recursion =perf_swevent_recursion_context (cpuctx);Quoted 8 lines
kernel/perf_event.c static void perf_swevent_ctx_event(struct perf_event_context *ctx, · line 3910
Quoted 6 lines
kernel/perf_event.c +2
-4-struct perf_event_context *ctx; - -if (*recursion) - goto out; + (*recursion)--; +}And here as well.
Quoted 1 line
Global functions are in essence a
barrier()to GCC but yeah.
Can't rely on that, because if the thing decides to inline this function it looses that barrier semantic.
And it being such a small function with a few callsites in the same translation unit, there's a fair chance it will actually inline.
Quoted 36 lines · Peter Zijlstra
Quoted 35 lines · Frederic Weisbecker
kernel/perf_event.c +16
-6@@ -3880,34 +3880,42 @@ static void perf_swevent_ctx_event(struct perf_event_context *ctx, } } -static int *perf_swevent_recursion_context (struct perf_cpu_context *cpuctx) +/* +* Must be called with preemption disabled +*/ +int perf_swevent_get_recursion_context (int **recursion) { +struct perf_cpu_context *cpuctx = &__get_cpu_var (perf_cpu_context); +if (in_nmi ()) -return &cpuctx->recursion[3 ]; + *recursion = &cpuctx->recursion[3 ]; +else if (in_irq ()) + *recursion = &cpuctx->recursion[2 ]; +else if (in_softirq ()) + *recursion = &cpuctx->recursion[1 ]; +else + *recursion = &cpuctx->recursion[0 ]; -if (in_irq ()) -return &cpuctx->recursion[2 ]; +if (**recursion) +return -1 ; -if (in_softirq ()) -return &cpuctx->recursion[1 ]; + (**recursion)++;
Quoted 5 lines
kernel/perf_event.c static void perf_swevent_ctx_event(struct perf_event_context *ctx, · line 3905
Quoted 3 lines
kernel/perf_event.c +1
-1-return &cpuctx->recursion[0 ]; +return 0 ; }You lost the
barrier();
I thought that putting that into a function would already do the trick but that is notwithstanding the fact it could be inlined as you said in another message.
Ok, I'll add them back.
Quoted 37 lines
Quoted 4 lines
kernel/perf_event.c +0
-4-static void do_perf_sw_event (enum perf_type_id type,u32 event_id, -u64 nr,int nmi, -struct perf_sample_data *data, -struct pt_regs *regs)kernel/perf_event.c static void perf_swevent_ctx_event(struct perf_event_context *ctx, · line 3910
Quoted 10 lines
kernel/perf_event.c +3
-6+void perf_swevent_put_recursion_context (int *recursion) { -struct perf_cpu_context *cpuctx = &get_cpu_var (perf_cpu_context); -int *recursion =perf_swevent_recursion_context (cpuctx); -struct perf_event_context *ctx; - -if (*recursion) - goto out; + (*recursion)--; +}And here as well.
Furthermore, its much cleaner if you simply use
get_cpu_var(perf_cpu_context)inget_recursion_context, andput_cpu_var()input_recursion_context.That way you put the
preempt_disablewhere it belongs, instead of:Quoted 14 lines
kernel/perf_event.c +13
-0+static void do_perf_sw_event (enum perf_type_id type,u32 event_id, +u64 nr,int nmi, +struct perf_sample_data *data, +struct pt_regs *regs) +{ +int *recursion; + +preempt_disable (); + +if (perf_swevent_get_recursion_context (&recursion)) + goto out; + +__do_perf_sw_event (type, event_id, nr, nmi, data, regs);
Quoted 9 lines
kernel/perf_event.c static void do_perf_sw_event(enum perf_type_id type, u32 event_id, · line 3950
Quoted 5 lines
kernel/perf_event.c +2
-1+perf_swevent_put_recursion_context (recursion); out: -put_cpu_var (perf_cpu_context); +preempt_enable (); }mucking about like here, also it cleans up the code in that you don't have to drag that recursion variable around like so.
That's cleaner but adds an unnecessary overhead in the trace event path. We already disable the interrupts there. That's why I preferred to let the caller decide.
Peter Zijlstra
maintainerQuoted 3 lines · Frederic Weisbecker
That's cleaner but adds an unnecessary overhead in the trace event path. We already disable the interrupts there. That's why I preferred to let the caller decide.
The trace path is already far from optimal, so I'd rather penalize that than the regular swcounter path.