tracing: updates
Steven Rostedt
maintainerIngo,
Please pull the latest tip/tracing/core tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/core
Jeff Mahoney (1):
tracing: Fix ftrace_event_call alignment for use with gcc 4.5
Li Zefan (1):
tracing: Remove CONFIG_TRACE_POWER from kernel config
Steven Rostedt (1):
ftrace: Remove memory barriers from NMI code when not needed
Wenji Huang (4):
tracing: Fix typo in prof_sysexit_enable()
tracing: Fix typo of info text in trace_kprobe.c
tracing: Remove unnecessary variable in print_graph_return
tracing: Simplify memory recycle of trace_define_field
----
arch/x86/kernel/ftrace.c | 26 ++++++++++++++++++++++++++ include/linux/syscalls.h | 6 ++++-- include/trace/ftrace.h | 3 ++- kernel/trace/Kconfig | 9 --------- kernel/trace/trace.h | 3 ++- kernel/trace/trace_events.c | 4 +--- kernel/trace/trace_functions_graph.c | 1 - kernel/trace/trace_kprobe.c | 4 ++-- kernel/trace/trace_syscalls.c | 2 +- 9 files changed, 38 insertions(+), 20 deletions(-)
Steven Rostedt
maintainerPATCH 1/7 ftrace: Remove memory barriers from NMI code when not needed
From: Steven Rostedt <[email protected]>
The code in stop_machine that modifies the kernel text has a bit of logic to handle the case of NMIs. stop_machine does not prevent NMIs from executing, and if an NMI were to trigger on another CPU as the modifying CPU is changing the NMI text, a GPF could result.
To prevent the GPF, the NMI calls ftrace_nmi_enter() which may modify the code first, then any other NMIs will just change the text to the same content which will do no harm. The code that stop_machine called must wait for NMIs to finish while it changes each location in the kernel. That code may also change the text to what the NMI changed it to. The key is that the text will never change content while another CPU is executing it.
To make the above work, the call to ftrace_nmi_enter() must also do a smp_mb() as well as atomic_inc(). But for applications like perf that require a high number of NMIs for profiling, this can have a dramatic effect on the system. Not only is it doing a full memory barrier on both nmi_enter() as well as nmi_exit() it is also modifying a global variable with an atomic operation. This kills performance on large SMP machines.
Since the memory barriers are only needed when ftrace is in the process of modifying the text (which is seldom), this patch adds a "modifying_code" variable that gets set before stop machine is executed and cleared afterwards.
The NMIs will check this variable and store it in a per CPU "save_modifying_code" variable that it will use to check if it needs to do the memory barriers and atomic dec on NMI exit.
--- arch/x86/kernel/ftrace.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
arch/x86/kernel/ftrace.c +26 -0
@@ -30,14 +30,32 @@#ifdef CONFIG_DYNAMIC_FTRACE +/* +* modifying_code is set to notify NMIs that they need to use +* memory barriers when entering or exiting. But we don't want +* to burden NMIs with unnecessary memory barriers when code +* modification is not being done (which is most of the time). +* +* A mutex is already held when ftrace_arch_code_modify_prepare +* and post_process are called. No locks need to be taken here. +* +* Stop machine will make sure currently running NMIs are done +* and new NMIs will see the updated variable before we need +* to worry about NMIs doing memory barriers. +*/ +static int modifying_code__read_mostly ; +static DEFINE_PER_CPU(int, save_modifying_code); +int ftrace_arch_code_modify_prepare (void ) {set_kernel_text_rw (); + modifying_code =1 ;return 0 ; }int ftrace_arch_code_modify_post_process (void ) { + modifying_code =0 ;set_kernel_text_ro ();return 0 ; }
@@ -149,6 +167,11 @@ static void ftrace_mod_code(void)void ftrace_nmi_enter (void ) { +__get_cpu_var (save_modifying_code) = modifying_code; + +if (!__get_cpu_var (save_modifying_code)) +return ; +if (atomic_inc_return (&nmi_running) &MOD_CODE_WRITE_FLAG ) {smp_rmb ();ftrace_mod_code ();
@@ -160,6 +183,9 @@ void ftrace_nmi_enter(void)void ftrace_nmi_exit (void ) { +if (!__get_cpu_var (save_modifying_code)) +return ; +/* Finish all executions before clearing nmi_running */ smp_mb ();atomic_dec (&nmi_running);
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 2/7 tracing: Fix ftrace_event_call alignment for use with gcc 4.5
In reply to Steven RostedtFrom: Jeff Mahoney <[email protected]>
GCC 4.5 introduces behavior that forces the alignment of structures to
use the largest possible value. The default value is 32 bytes, so if some structures are defined with a 4-byte alignment and others aren't declared with an alignment constraint at all - it will align at 32-bytes.
For things like the ftrace events, this results in a non-standard array. When initializing the ftrace subsystem, we traverse the _ftrace_events section and call the initialization callback for each event. When the structures are misaligned, we could be treating another part of the structure (or the zeroed out space between them) as a function pointer.
This patch forces the alignment for all the ftrace_event_call structures to 4 bytes.
Without this patch, the kernel fails to boot very early when built with gcc 4.5.
It's trivial to check the alignment of the members of the array, so it might be worthwhile to add something to the build system to do that automatically. Unfortunately, that only covers this case. I've asked one of the gcc developers about adding a warning when this condition is seen.
LKML-Reference: <[email protected]>
--- include/linux/syscalls.h | 6 ++++-- include/trace/ftrace.h | 3 ++- kernel/trace/trace.h | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)
include/linux/syscalls.h +4 -2
@@ -132,7 +132,8 @@ struct perf_event_attr;#define SYSCALL_TRACE_ENTER_EVENT (sname) \ static const struct syscall_metadata __syscall_meta_##sname; \ - static struct ftrace_event_call event_enter_##sname; \ + static struct ftrace_event_call \ + __attribute__((__aligned__(4))) event_enter_##sname; \ static struct trace_event enter_syscall_print_##sname = { \ .trace = print_syscall_enter, \ }; \
@@ -153,7 +154,8 @@ struct perf_event_attr;#define SYSCALL_TRACE_EXIT_EVENT (sname) \ static const struct syscall_metadata __syscall_meta_##sname; \ - static struct ftrace_event_call event_exit_##sname; \ + static struct ftrace_event_call \ + __attribute__((__aligned__(4))) event_exit_##sname; \ static struct trace_event exit_syscall_print_##sname = { \ .trace = print_syscall_exit, \ }; \
include/trace/ftrace.h +2 -1
@@ -65,7 +65,8 @@ };#undef DEFINE_EVENT#define DEFINE_EVENT (template, name, proto, args) \ - static struct ftrace_event_call event_##name + static struct ftrace_event_call \ + __attribute__((__aligned__(4))) event_##name#undef DEFINE_EVENT_PRINT#define DEFINE_EVENT_PRINT (template, name, proto, args, print) \
kernel/trace/trace.h +2 -1
@@ -792,7 +792,8 @@ extern const char *__stop___trace_bprintk_fmt[];#undef FTRACE_ENTRY#define FTRACE_ENTRY (call, struct_name, id, tstruct, print) \ - extern struct ftrace_event_call event_##call; + extern struct ftrace_event_call \ + __attribute__((__aligned__(4))) event_##call;#undef FTRACE_ENTRY_DUP#define FTRACE_ENTRY_DUP (call, struct_name, id, tstruct, print) \ FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 3/7 tracing: Remove CONFIG_TRACE_POWER from kernel config
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
The power tracer has been converted to power trace events.
LKML-Reference: <[email protected]>
--- kernel/trace/Kconfig | 9 --------- 1 files changed, 0 insertions(+), 9 deletions(-)
kernel/trace/Kconfig +0 -9
@@ -330,15 +330,6 @@ config BRANCH_TRACER Say N if unsure. -config POWER_TRACER - bool "Trace power consumption behavior" - depends on X86 - select GENERIC_TRACER - help - This tracer helps developers to analyze and optimize the kernel's - power management decisions, specifically the C-state and P-state - behavior. - config KSYM_TRACER bool "Trace read and write access on kernel memory locations" depends on HAVE_HW_BREAKPOINT
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 4/7 tracing: Fix typo in prof_sysexit_enable()
In reply to Steven RostedtFrom: Wenji Huang <[email protected]>
LKML-Reference: <[email protected]>
--- kernel/trace/trace_syscalls.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_syscalls.c +1 -1
@@ -603,7 +603,7 @@ int prof_sysexit_enable(struct ftrace_event_call *call) ret =register_trace_sys_exit (prof_syscall_exit);if (ret) {pr_info ("event trace: Could not activate" -"syscall entry trace point" ); +"syscall exit trace point" ); }else {set_bit (num, enabled_prof_exit_syscalls); sys_prof_refcount_exit++;
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 5/7 tracing: Fix typo of info text in trace_kprobe.c
In reply to Steven RostedtFrom: Wenji Huang <[email protected]>
LKML-Reference: <[email protected]>
--- kernel/trace/trace_kprobe.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_kprobe.c +2 -2
@@ -651,12 +651,12 @@ static int create_trace_probe(int argc, char **argv) event =strchr (group,'/' ) +1 ; event[-1 ] ='\0' ;if (strlen (group) ==0 ) { -pr_info ("Group name is not specifiled\n" ); +pr_info ("Group name is not specified\n" );return -EINVAL ; } }if (strlen (event) ==0 ) { -pr_info ("Event name is not specifiled\n" ); +pr_info ("Event name is not specified\n" );return -EINVAL ; } }
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 6/7 tracing: Remove unnecessary variable in print_graph_return
In reply to Steven RostedtFrom: Wenji Huang <[email protected]>
The "cpu" variable is declared at the start of the function and also within a branch, with the exact same initialization.
Remove the local variable of the same name in the branch.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_functions_graph.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
kernel/trace/trace_functions_graph.c +0 -1
@@ -855,7 +855,6 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,int i;if (data) { -int cpu = iter->cpu;int *depth = &(per_cpu_ptr (data->cpu_data, cpu)->depth);/*
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 7/7 tracing: Simplify memory recycle of trace_define_field
In reply to Steven RostedtFrom: Wenji Huang <[email protected]>
Discard freeing field->type since it is not necessary.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
kernel/trace/trace_events.c +1 -3
@@ -60,10 +60,8 @@ int trace_define_field(struct ftrace_event_call *call, const char *type,return 0 ; err: -if (field) { +if (field)kfree (field->name); -kfree (field->type); - }kfree (field);return -ENOMEM ;
Signature · 1 line
1.6.5
Quoted 24 lines · Steven Rostedt
Ingo,
Please pull the latest tip/tracing/core tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/coreJeff Mahoney (1):
tracing: Fixftrace_event_callalignment for use with gcc 4.5Li Zefan (1):
tracing: RemoveCONFIG_TRACE_POWERfrom kernel configSteven Rostedt (1):
ftrace: Remove memory barriers from NMI code when not neededWenji Huang (4):
tracing: Fix typo inprof_sysexit_enable()
tracing: Fix typo of info text intrace_kprobe.c
tracing: Remove unnecessary variable inprint_graph_return
tracing: Simplify memory recycle oftrace_define_field----
Quoted 10 lines
arch/x86/kernel/ftrace.c | 26 ++++++++++++++++++++++++++ include/linux/syscalls.h | 6 ++++-- include/trace/ftrace.h | 3 ++- kernel/trace/Kconfig | 9 --------- kernel/trace/trace.h | 3 ++- kernel/trace/trace_events.c | 4 +--- kernel/trace/trace_functions_graph.c | 1 - kernel/trace/trace_kprobe.c | 4 ++-- kernel/trace/trace_syscalls.c | 2 +- 9 files changed, 38 insertions(+), 20 deletions(-)
Pulled, thanks a lot Steve!
Ingo