aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/trace
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2014-05-06 09:26:30 -0400
committerSteven Rostedt <rostedt@goodmis.org>2014-05-07 12:10:51 -0400
commit7c65bbc7dcface00b295bbd18bce82fe1db3d633 (patch)
tree4e5cd0710e3c533831eb673f8feeb46a911a9f09 /Documentation/trace
parentbdffd893a0e9c431304142d12d9a0a21d365c502 (diff)
tracing: Add trace_<tracepoint>_enabled() function
There are some code paths in the kernel that need to do some preparations before it calls a tracepoint. As that code is worthless overhead when the tracepoint is not enabled, it would be prudent to have that code only run when the tracepoint is active. To accomplish this, all tracepoints now get a static inline function called "trace_<tracepoint-name>_enabled()" which returns true when the tracepoint is enabled and false otherwise. As an added bonus, that function uses the static_key of the tracepoint such that no branch is needed. if (trace_mytracepoint_enabled()) { arg = process_tp_arg(); trace_mytracepoint(arg); } Will keep the "process_tp_arg()" (which may be expensive to run) from being executed when the tracepoint isn't enabled. It's best to encapsulate the tracepoint itself in the if statement just to keep races. For example, if you had: if (trace_mytracepoint_enabled()) arg = process_tp_arg(); trace_mytracepoint(arg); There's a chance that the tracepoint could be enabled just after the if statement, and arg will be undefined when calling the tracepoint. Link: http://lkml.kernel.org/r/20140506094407.507b6435@gandalf.local.home Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'Documentation/trace')
-rw-r--r--Documentation/trace/tracepoints.txt24
1 files changed, 24 insertions, 0 deletions
diff --git a/Documentation/trace/tracepoints.txt b/Documentation/trace/tracepoints.txt
index 6b018b53177a..a3efac621c5a 100644
--- a/Documentation/trace/tracepoints.txt
+++ b/Documentation/trace/tracepoints.txt
@@ -115,6 +115,30 @@ If the tracepoint has to be used in kernel modules, an
115EXPORT_TRACEPOINT_SYMBOL_GPL() or EXPORT_TRACEPOINT_SYMBOL() can be 115EXPORT_TRACEPOINT_SYMBOL_GPL() or EXPORT_TRACEPOINT_SYMBOL() can be
116used to export the defined tracepoints. 116used to export the defined tracepoints.
117 117
118If you need to do a bit of work for a tracepoint parameter, and
119that work is only used for the tracepoint, that work can be encapsulated
120within an if statement with the following:
121
122 if (trace_foo_bar_enabled()) {
123 int i;
124 int tot = 0;
125
126 for (i = 0; i < count; i++)
127 tot += calculate_nuggets();
128
129 trace_foo_bar(tot);
130 }
131
132All trace_<tracepoint>() calls have a matching trace_<tracepoint>_enabled()
133function defined that returns true if the tracepoint is enabled and
134false otherwise. The trace_<tracepoint>() should always be within the
135block of the if (trace_<tracepoint>_enabled()) to prevent races between
136the tracepoint being enabled and the check being seen.
137
138The advantage of using the trace_<tracepoint>_enabled() is that it uses
139the static_key of the tracepoint to allow the if statement to be implemented
140with jump labels and avoid conditional branches.
141
118Note: The convenience macro TRACE_EVENT provides an alternative way to 142Note: The convenience macro TRACE_EVENT provides an alternative way to
119 define tracepoints. Check http://lwn.net/Articles/379903, 143 define tracepoints. Check http://lwn.net/Articles/379903,
120 http://lwn.net/Articles/381064 and http://lwn.net/Articles/383362 144 http://lwn.net/Articles/381064 and http://lwn.net/Articles/383362