• Steven Rostedt (Red Hat)'s avatar
    tracing: Skip more functions when doing stack tracing of events · 70b3d6c5
    Steven Rostedt (Red Hat) authored
    [ Upstream commit be54f69c ]
    
     # echo 1 > options/stacktrace
     # echo 1 > events/sched/sched_switch/enable
     # cat trace
              <idle>-0     [002] d..2  1982.525169: <stack trace>
     => save_stack_trace
     => __ftrace_trace_stack
     => trace_buffer_unlock_commit_regs
     => event_trigger_unlock_commit
     => trace_event_buffer_commit
     => trace_event_raw_event_sched_switch
     => __schedule
     => schedule
     => schedule_preempt_disabled
     => cpu_startup_entry
     => start_secondary
    
    The above shows that we are seeing 6 functions before ever making it to the
    caller of the sched_switch event.
    
     # echo stacktrace > events/sched/sched_switch/trigger
     # cat trace
              <idle>-0     [002] d..3  2146.335208: <stack trace>
     => trace_event_buffer_commit
     => trace_event_raw_event_sched_switch
     => __schedule
     => schedule
     => schedule_preempt_disabled
     => cpu_startup_entry
     => start_secondary
    
    The stacktrace trigger isn't as bad, because it adds its own skip to the
    stacktracing, but still has two events extra.
    
    One issue is that if the stacktrace passes its own "regs" then there should
    be no addition to the skip, as the regs will not include the functions being
    called. This was an issue that was fixed by commit 7717c6be ("tracing:
    Fix stacktrace skip depth in trace_buffer_unlock_commit_regs()" as adding
    the skip number for kprobes made the probes not have any stack at all.
    
    But since this is only an issue when regs is being used, a skip should be
    added if regs is NULL. Now we have:
    
     # echo 1 > options/stacktrace
     # echo 1 > events/sched/sched_switch/enable
     # cat trace
              <idle>-0     [000] d..2  1297.676333: <stack trace>
     => __schedule
     => schedule
     => schedule_preempt_disabled
     => cpu_startup_entry
     => rest_init
     => start_kernel
     => x86_64_start_reservations
     => x86_64_start_kernel
    
     # echo stacktrace > events/sched/sched_switch/trigger
     # cat trace
              <idle>-0     [002] d..3  1370.759745: <stack trace>
     => __schedule
     => schedule
     => schedule_preempt_disabled
     => cpu_startup_entry
     => start_secondary
    
    And kprobes are not touched.
    Reported-by: 's avatarPeter Zijlstra <peterz@infradead.org>
    Signed-off-by: 's avatarSteven Rostedt <rostedt@goodmis.org>
    Signed-off-by: 's avatarSasha Levin <sashal@kernel.org>
    70b3d6c5
Name
Last commit
Last update
Documentation Loading commit data...
arch Loading commit data...
block Loading commit data...
certs Loading commit data...
crypto Loading commit data...
drivers Loading commit data...
firmware Loading commit data...
fs Loading commit data...
include Loading commit data...
init Loading commit data...
ipc Loading commit data...
kernel Loading commit data...
lib Loading commit data...
mm Loading commit data...
net Loading commit data...
samples Loading commit data...
scripts Loading commit data...
security Loading commit data...
sound Loading commit data...
tools Loading commit data...
usr Loading commit data...
virt Loading commit data...
.get_maintainer.ignore Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
COPYING Loading commit data...
CREDITS Loading commit data...
Kbuild Loading commit data...
Kconfig Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README Loading commit data...
REPORTING-BUGS Loading commit data...