diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2014-05-06 09:26:30 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2014-05-07 12:10:51 -0400 |
commit | 7c65bbc7dcface00b295bbd18bce82fe1db3d633 (patch) | |
tree | 4e5cd0710e3c533831eb673f8feeb46a911a9f09 /include | |
parent | bdffd893a0e9c431304142d12d9a0a21d365c502 (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 'include')
-rw-r--r-- | include/linux/tracepoint.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 9d30ee469c2a..2e2a5f7717e5 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h | |||
@@ -185,6 +185,11 @@ extern void syscall_unregfunc(void); | |||
185 | static inline void \ | 185 | static inline void \ |
186 | check_trace_callback_type_##name(void (*cb)(data_proto)) \ | 186 | check_trace_callback_type_##name(void (*cb)(data_proto)) \ |
187 | { \ | 187 | { \ |
188 | } \ | ||
189 | static inline bool \ | ||
190 | trace_##name##_enabled(void) \ | ||
191 | { \ | ||
192 | return static_key_false(&__tracepoint_##name.key); \ | ||
188 | } | 193 | } |
189 | 194 | ||
190 | /* | 195 | /* |
@@ -230,6 +235,11 @@ extern void syscall_unregfunc(void); | |||
230 | } \ | 235 | } \ |
231 | static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \ | 236 | static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \ |
232 | { \ | 237 | { \ |
238 | } \ | ||
239 | static inline bool \ | ||
240 | trace_##name##_enabled(void) \ | ||
241 | { \ | ||
242 | return false; \ | ||
233 | } | 243 | } |
234 | 244 | ||
235 | #define DEFINE_TRACE_FN(name, reg, unreg) | 245 | #define DEFINE_TRACE_FN(name, reg, unreg) |