ftrace: support for SOFT_DISABLE to syscall events caused huge slowdown of ftrace startup test
Hi,
I tested my ftrace-related patches and enabled also the startup test:
CONFIG_FTRACE_SELFTEST=y
CONFIG_FTRACE_STARTUP_TEST=y
On today's kernel/git/tip/tip.git, the boot "freezed" for 1 minute when doing "Testing event system syscalls".
A bisect pointed finger to the commit d562aff93bfb530b099 (tracing: Add support for SOFT_DISABLE to syscall events).
It seems that the culprit are the "synchronize_sched" calls added to "unreg_event_syscall_enter" and "unreg_event_syscall_exit" functions. They are called 2312 times during the boot here and are responsible for the delay.
I wonder if it might cause slowdown also at runtime.
I am going to look deeper into the code and eventually come up with a solution. But it might take some time. I am still newbie in the kernel development. Any hints or tips are welcome ;-)
Best Regards,
Petr
Steven Rostedt
maintainerQuoted 18 lines · On Tue, 03 Dec 2013 18:16:09 +0100 Petr Mladek <[email protected]> wrote:
Hi,
I tested my ftrace-related patches and enabled also the startup test:
CONFIG_FTRACE_SELFTEST=y
CONFIG_FTRACE_STARTUP_TEST=yOn today's
kernel/git/tip/tip.git, the boot "freezed" for 1 minute when doing "Testing event system syscalls".A bisect pointed finger to the commit
d562aff93bfb530b099(tracing: Add support forSOFT_DISABLEto syscall events).It seems that the culprit are the "
synchronize_sched" calls added to "unreg_event_syscall_enter" and "unreg_event_syscall_exit" functions. They are called 2312 times during the boot here and are responsible for the delay.
Quoted 6 lines
I wonder if it might cause slowdown also at runtime.
I am going to look deeper into the code and eventually come up with a solution. But it might take some time. I am still newbie in the kernel development. Any hints or tips are welcome ;-)
Yeah, the synchronize_sched() at all disabling of syscall events seems rather extreme. Perhaps this is good enough.
Dose this work for you?
Tom, do you see anything wrong with this. I'm assuming that the synchronize_sched() within the event unregistering, was there for deleting of trace instances. By placing the synchronize_sched() only within the deletion code, this should be good enough.
-- Steve
kernel/trace/trace_events.c +3 -0
@@ -2314,6 +2314,9 @@ int event_trace_del_tracer(struct trace_array *tr)/* Disable any running events */ __ftrace_set_clr_event_nolock (tr,NULL ,NULL ,NULL ,0 ); +/* Access to events are within rcu_read_lock_sched() */ +synchronize_sched (); +down_write (&trace_event_sem);__trace_remove_event_dirs (tr);debugfs_remove_recursive (tr->event_dir);
kernel/trace/trace_syscalls.c +0 -10
@@ -431,11 +431,6 @@ static void unreg_event_syscall_enter(struct ftrace_event_file *file,if (!tr->sys_refcount_enter)unregister_trace_sys_enter (ftrace_syscall_enter, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); } static int reg_event_syscall_exit(struct ftrace_event_file *file,
@@ -474,11 +469,6 @@ static void unreg_event_syscall_exit(struct ftrace_event_file *file,if (!tr->sys_refcount_exit)unregister_trace_sys_exit (ftrace_syscall_exit, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); }static int __init init_syscall_trace (struct ftrace_event_call *call)
Quoted 28 lines · Steven Rostedt
Quoted 18 lines · On Tue, 03 Dec 2013 18:16:09 +0100 Petr Mladek <[email protected]> wrote:
Hi,
I tested my ftrace-related patches and enabled also the startup test:
CONFIG_FTRACE_SELFTEST=y
CONFIG_FTRACE_STARTUP_TEST=yOn today's
kernel/git/tip/tip.git, the boot "freezed" for 1 minute when doing "Testing event system syscalls".A bisect pointed finger to the commit
d562aff93bfb530b099(tracing: Add support forSOFT_DISABLEto syscall events).It seems that the culprit are the "
synchronize_sched" calls added to "unreg_event_syscall_enter" and "unreg_event_syscall_exit" functions. They are called 2312 times during the boot here and are responsible for the delay.Quoted 6 lines
I wonder if it might cause slowdown also at runtime.
I am going to look deeper into the code and eventually come up with a solution. But it might take some time. I am still newbie in the kernel development. Any hints or tips are welcome ;-)
Quoted 5 lines
Yeah, the
synchronize_sched()at all disabling of syscall events seems rather extreme. Perhaps this is good enough.Dose this work for you?
I'm also seeing a very long (~ 1 min or so) startup with CONFIG_FTRACE_STARTUP_TEST, but that seems to be the case with or without your patch, or even with the SOFT_DISABLE syscall patch reverted.
I haven't done a comparison between any of these cases, just noting that unless it's expected for the ftrace startup test to take a full minute or so, there might be a problem somewhere else as well. Or I may be not testing correctly - if it was bisected to the SOFT_DISABLE commit, I'm guessing there's a more pronounced difference than what I'm seeing here...
Tom
Quoted 51 lines
Tom, do you see anything wrong with this. I'm assuming that the
synchronize_sched()within the event unregistering, was there for deleting of trace instances. By placing thesynchronize_sched()only within the deletion code, this should be good enough.-- Steve
Signed-off-by Steven Rostedt <[email protected]>kernel/trace/trace_events.c +3
-0@@ -2314,6 +2314,9 @@ int event_trace_del_tracer(struct trace_array *tr)/* Disable any running events */ __ftrace_set_clr_event_nolock (tr,NULL ,NULL ,NULL ,0 ); +/* Access to events are within rcu_read_lock_sched() */ +synchronize_sched (); +down_write (&trace_event_sem);__trace_remove_event_dirs (tr);debugfs_remove_recursive (tr->event_dir);kernel/trace/trace_syscalls.c +0
-10@@ -431,11 +431,6 @@ static void unreg_event_syscall_enter(struct ftrace_event_file *file,if (!tr->sys_refcount_enter)unregister_trace_sys_enter (ftrace_syscall_enter, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); } static int reg_event_syscall_exit(struct ftrace_event_file *file,@@ -474,11 +469,6 @@ static void unreg_event_syscall_exit(struct ftrace_event_file *file,if (!tr->sys_refcount_exit)unregister_trace_sys_exit (ftrace_syscall_exit, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); }static int __init init_syscall_trace (struct ftrace_event_call *call)
Tom Zanussi
Acked-byQuoted 40 lines · Tom Zanussi
Quoted 28 lines · Steven Rostedt
Quoted 18 lines · On Tue, 03 Dec 2013 18:16:09 +0100 Petr Mladek <[email protected]> wrote:
Hi,
I tested my ftrace-related patches and enabled also the startup test:
CONFIG_FTRACE_SELFTEST=y
CONFIG_FTRACE_STARTUP_TEST=yOn today's
kernel/git/tip/tip.git, the boot "freezed" for 1 minute when doing "Testing event system syscalls".A bisect pointed finger to the commit
d562aff93bfb530b099(tracing: Add support forSOFT_DISABLEto syscall events).It seems that the culprit are the "
synchronize_sched" calls added to "unreg_event_syscall_enter" and "unreg_event_syscall_exit" functions. They are called 2312 times during the boot here and are responsible for the delay.Quoted 6 lines
I wonder if it might cause slowdown also at runtime.
I am going to look deeper into the code and eventually come up with a solution. But it might take some time. I am still newbie in the kernel development. Any hints or tips are welcome ;-)
Quoted 5 lines
Yeah, the
synchronize_sched()at all disabling of syscall events seems rather extreme. Perhaps this is good enough.Dose this work for you?
I'm also seeing a very long (~ 1 min or so) startup with
CONFIG_FTRACE_STARTUP_TEST, but that seems to be the case with or without your patch, or even with theSOFT_DISABLEsyscall patch reverted.
Quoted 7 lines
I haven't done a comparison between any of these cases, just noting that unless it's expected for the ftrace startup test to take a full minute or so, there might be a problem somewhere else as well. Or I may be not testing correctly - if it was bisected to the
SOFT_DISABLEcommit, I'm guessing there's a more pronounced difference than what I'm seeing here...
OK, so the ftrace startup test does apparently take a long time in the normal case, about 1 min on my machine, but that goes to 3 minutes with the SOFT_DISABLE and the selftest output shows the time is in the syscall tests.
Your patch brings that down to 1 minute again, so it does fix the problem here, and moving the synchronize_sched() out to the tracer deletion code instead makes more sense - I didn't realize it was so expensive; the other case where an event handler could go away would be in kprobes, but that's covered too via disable_trace_probe().
Quoted 54 lines
Tom
Quoted 51 lines
Tom, do you see anything wrong with this. I'm assuming that the
synchronize_sched()within the event unregistering, was there for deleting of trace instances. By placing thesynchronize_sched()only within the deletion code, this should be good enough.-- Steve
Signed-off-by Steven Rostedt <[email protected]>kernel/trace/trace_events.c +3
-0@@ -2314,6 +2314,9 @@ int event_trace_del_tracer(struct trace_array *tr)/* Disable any running events */ __ftrace_set_clr_event_nolock (tr,NULL ,NULL ,NULL ,0 ); +/* Access to events are within rcu_read_lock_sched() */ +synchronize_sched (); +down_write (&trace_event_sem);__trace_remove_event_dirs (tr);debugfs_remove_recursive (tr->event_dir);kernel/trace/trace_syscalls.c +0
-10@@ -431,11 +431,6 @@ static void unreg_event_syscall_enter(struct ftrace_event_file *file,if (!tr->sys_refcount_enter)unregister_trace_sys_enter (ftrace_syscall_enter, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); } static int reg_event_syscall_exit(struct ftrace_event_file *file,@@ -474,11 +469,6 @@ static void unreg_event_syscall_exit(struct ftrace_event_file *file,if (!tr->sys_refcount_exit)unregister_trace_sys_exit (ftrace_syscall_exit, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); }static int __init init_syscall_trace (struct ftrace_event_call *call)
Petr Mladek
Acked-bySteven Rostedt píše v Út 03. 12. 2013 v 12:41 -0500:
Quoted 28 lines
Quoted 18 lines · On Tue, 03 Dec 2013 18:16:09 +0100 Petr Mladek <[email protected]> wrote:
Hi,
I tested my ftrace-related patches and enabled also the startup test:
CONFIG_FTRACE_SELFTEST=y
CONFIG_FTRACE_STARTUP_TEST=yOn today's
kernel/git/tip/tip.git, the boot "freezed" for 1 minute when doing "Testing event system syscalls".A bisect pointed finger to the commit
d562aff93bfb530b099(tracing: Add support forSOFT_DISABLEto syscall events).It seems that the culprit are the "
synchronize_sched" calls added to "unreg_event_syscall_enter" and "unreg_event_syscall_exit" functions. They are called 2312 times during the boot here and are responsible for the delay.Quoted 6 lines
I wonder if it might cause slowdown also at runtime.
I am going to look deeper into the code and eventually come up with a solution. But it might take some time. I am still newbie in the kernel development. Any hints or tips are welcome ;-)
Quoted 4 lines
Yeah, the
synchronize_sched()at all disabling of syscall events seems rather extreme. Perhaps this is good enough.Dose this work for you?
I could confirm that it removes the delay and looks fine to me.
Quoted 51 lines
Tom, do you see anything wrong with this. I'm assuming that the
synchronize_sched()within the event unregistering, was there for deleting of trace instances. By placing thesynchronize_sched()only within the deletion code, this should be good enough.-- Steve
Signed-off-by Steven Rostedt <[email protected]>kernel/trace/trace_events.c +3
-0@@ -2314,6 +2314,9 @@ int event_trace_del_tracer(struct trace_array *tr)/* Disable any running events */ __ftrace_set_clr_event_nolock (tr,NULL ,NULL ,NULL ,0 ); +/* Access to events are within rcu_read_lock_sched() */ +synchronize_sched (); +down_write (&trace_event_sem);__trace_remove_event_dirs (tr);debugfs_remove_recursive (tr->event_dir);kernel/trace/trace_syscalls.c +0
-10@@ -431,11 +431,6 @@ static void unreg_event_syscall_enter(struct ftrace_event_file *file,if (!tr->sys_refcount_enter)unregister_trace_sys_enter (ftrace_syscall_enter, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); } static int reg_event_syscall_exit(struct ftrace_event_file *file,@@ -474,11 +469,6 @@ static void unreg_event_syscall_exit(struct ftrace_event_file *file,if (!tr->sys_refcount_exit)unregister_trace_sys_exit (ftrace_syscall_exit, tr);mutex_unlock (&syscall_trace_lock); -/* -* Callers expect the event to be completely disabled on -* return, so wait for current handlers to finish. -*/ -synchronize_sched (); }static int __init init_syscall_trace (struct ftrace_event_call *call)