ftrace: Make function trace pid filtering a bit more exact
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Fri, 20 Mar 2020 03:40:40 +0000 (23:40 -0400)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Fri, 27 Mar 2020 20:39:02 +0000 (16:39 -0400)
commit717e3f5ebc823e5ecfdd15155b0fd81af9fc58d6
tree4a6dee32b382d562589d9e87de05f58f06db2ebf
parent6a13a0d7b4d1171ef9b80ad69abc37e1daa941b3
ftrace: Make function trace pid filtering a bit more exact

The set_ftrace_pid file is used to filter function tracing to only trace
tasks that are listed in that file. Instead of testing the pids listed in
that file (it's a bitmask) at each function trace event, the logic is done
via a sched_switch hook. A flag is set when the next task to run is in the
list of pids in the set_ftrace_pid file. But the sched_switch hook is not at
the exact location of when the task switches, and the flag gets set before
the task to be traced actually runs. This leaves a residue of traced
functions that do not belong to the pid that should be filtered on.

By changing the logic slightly, where instead of having  a boolean flag to
test, record the pid that should be traced, with special values for not to
trace and always trace. Then at each function call, a check will be made to
see if the function should be ignored, or if the current pid matches the
function that should be traced, and only trace if it matches (or if it has
the special value to always trace).

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/ftrace.c
kernel/trace/trace.h