tracing/fgraph: Adjust fgraph depth before calling trace return callback
While debugging the virtual cputime with the function graph tracer
with a max_depth of 1 (most common use of the max_depth so far),
I found that I was missing kernel execution because of a race condition.
The code for the return side of the function has a slight race:
ftrace_pop_return_trace(&trace, &ret, frame_pointer);
trace.rettime = trace_clock_local();
ftrace_graph_return(&trace);
barrier();
current->curr_ret_stack--;
The ftrace_pop_return_trace() initializes the trace structure for
the callback. The ftrace_graph_return() uses the trace structure
for its own use as that structure is on the stack and is local
to this function. Then the curr_ret_stack is decremented which
is what the trace.depth is set to.
If an interrupt comes in after the ftrace_graph_return() but
before the curr_ret_stack, then the called function will get
a depth of 2. If max_depth is set to 1 this function will be
ignored.
The problem is that the trace has already been called, and the
timestamp for that trace will not reflect the time the function
was about to re-enter userspace. Calls to the interrupt will not
be traced because the max_depth has prevented this.
To solve this issue, the ftrace_graph_return() can safely be
moved after the current->curr_ret_stack has been updated.
This way the timestamp for the return callback will reflect
the actual time.
If an interrupt comes in after the curr_ret_stack update and
ftrace_graph_return(), it will be traced. It may look a little
confusing to see it within the other function, but at least
it will not be lost.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by:
Steven Rostedt <rostedt@goodmis.org>
Loading
-
mentioned in commit 8114865f
-
mentioned in commit 07f7175b
-
mentioned in commit 01e0ab2c
-
mentioned in commit f1f5b14a
-
mentioned in commit 556763e5
-
mentioned in commit d48ebb24
-
mentioned in commit a87532c7
-
mentioned in commit 8712b27c
-
mentioned in commit bc715ee4
-
mentioned in commit e949b6db
-
mentioned in commit fe60522e
-
mentioned in commit 18588e14
-
mentioned in commit 9c4bf5e0
-
mentioned in commit d125f3f8
-
mentioned in commit 552701dd
-
mentioned in commit b1b35f2e
-
mentioned in commit 7c6ea35e
Please register or sign in to comment