tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints
[deliverable/linux.git] / include / linux / tracepoint.h
CommitLineData
97e1c18e
MD
1#ifndef _LINUX_TRACEPOINT_H
2#define _LINUX_TRACEPOINT_H
3
4/*
5 * Kernel Tracepoint API.
6 *
8cd09a59 7 * See Documentation/trace/tracepoints.txt.
97e1c18e 8 *
de7b2973 9 * Copyright (C) 2008-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
97e1c18e
MD
10 *
11 * Heavily inspired from the Linux Kernel Markers.
12 *
13 * This file is released under the GPLv2.
14 * See the file COPYING for more details.
15 */
16
b70e4f05 17#include <linux/errno.h>
97e1c18e
MD
18#include <linux/types.h>
19#include <linux/rcupdate.h>
c5905afb 20#include <linux/static_key.h>
97e1c18e
MD
21
22struct module;
23struct tracepoint;
de7b2973 24struct notifier_block;
97e1c18e 25
38516ab5
SR
26struct tracepoint_func {
27 void *func;
28 void *data;
29};
30
97e1c18e
MD
31struct tracepoint {
32 const char *name; /* Tracepoint name */
c5905afb 33 struct static_key key;
97419875
JS
34 void (*regfunc)(void);
35 void (*unregfunc)(void);
bd1c8b22 36 struct tracepoint_func __rcu *funcs;
65498646 37};
97e1c18e 38
38516ab5 39extern int
de7b2973
MD
40tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
41extern int
42tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
43extern void
44for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
45 void *priv);
2e26ca71 46
b75ef8b4
MD
47#ifdef CONFIG_MODULES
48struct tp_module {
49 struct list_head list;
50 unsigned int num_tracepoints;
51 struct tracepoint * const *tracepoints_ptrs;
52};
de7b2973 53
45ab2813 54bool trace_module_has_bad_taint(struct module *mod);
de7b2973
MD
55extern int register_tracepoint_module_notifier(struct notifier_block *nb);
56extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
45ab2813
SRRH
57#else
58static inline bool trace_module_has_bad_taint(struct module *mod)
59{
60 return false;
61}
de7b2973
MD
62static inline
63int register_tracepoint_module_notifier(struct notifier_block *nb)
64{
65 return 0;
66}
67static inline
68int unregister_tracepoint_module_notifier(struct notifier_block *nb)
69{
70 return 0;
71}
b75ef8b4
MD
72#endif /* CONFIG_MODULES */
73
2e26ca71
SR
74/*
75 * tracepoint_synchronize_unregister must be called between the last tracepoint
76 * probe unregistration and the end of module exit to make sure there is no
77 * caller executing a probe when it is freed.
78 */
79static inline void tracepoint_synchronize_unregister(void)
80{
81 synchronize_sched();
82}
83
84#define PARAMS(args...) args
85
2e26ca71
SR
86#endif /* _LINUX_TRACEPOINT_H */
87
88/*
89 * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include
90 * file ifdef protection.
91 * This is due to the way trace events work. If a file includes two
92 * trace event headers under one "CREATE_TRACE_POINTS" the first include
93 * will override the TRACE_EVENT and break the second include.
94 */
95
ea20d929
SR
96#ifndef DECLARE_TRACE
97
2939b046 98#define TP_PROTO(args...) args
8cd09a59 99#define TP_ARGS(args...) args
287050d3 100#define TP_CONDITION(args...) args
97e1c18e
MD
101
102#ifdef CONFIG_TRACEPOINTS
103
104/*
105 * it_func[0] is never NULL because there is at least one element in the array
106 * when the array itself is non NULL.
38516ab5
SR
107 *
108 * Note, the proto and args passed in includes "__data" as the first parameter.
109 * The reason for this is to handle the "void" prototype. If a tracepoint
110 * has a "void" prototype, then it is invalid to declare a function
111 * as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
112 * "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
97e1c18e 113 */
2fbb90db 114#define __DO_TRACE(tp, proto, args, cond, prercu, postrcu) \
97e1c18e 115 do { \
38516ab5
SR
116 struct tracepoint_func *it_func_ptr; \
117 void *it_func; \
118 void *__data; \
97e1c18e 119 \
287050d3
SR
120 if (!(cond)) \
121 return; \
2fbb90db 122 prercu; \
da7b3eab 123 rcu_read_lock_sched_notrace(); \
38516ab5
SR
124 it_func_ptr = rcu_dereference_sched((tp)->funcs); \
125 if (it_func_ptr) { \
97e1c18e 126 do { \
38516ab5
SR
127 it_func = (it_func_ptr)->func; \
128 __data = (it_func_ptr)->data; \
129 ((void(*)(proto))(it_func))(args); \
130 } while ((++it_func_ptr)->func); \
97e1c18e 131 } \
da7b3eab 132 rcu_read_unlock_sched_notrace(); \
2fbb90db 133 postrcu; \
97e1c18e
MD
134 } while (0)
135
7ece55a4
JT
136#ifndef MODULE
137#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args) \
138 static inline void trace_##name##_rcuidle(proto) \
139 { \
140 if (static_key_false(&__tracepoint_##name.key)) \
141 __DO_TRACE(&__tracepoint_##name, \
142 TP_PROTO(data_proto), \
143 TP_ARGS(data_args), \
144 TP_CONDITION(cond), \
d6284099
PM
145 rcu_irq_enter(), \
146 rcu_irq_exit()); \
7ece55a4
JT
147 }
148#else
149#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args)
150#endif
151
97e1c18e
MD
152/*
153 * Make sure the alignment of the structure in the __tracepoints section will
154 * not add unwanted padding between the beginning of the section and the
155 * structure. Force alignment to the same alignment as the section start.
156 */
2fbb90db 157#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
7e066fb8 158 extern struct tracepoint __tracepoint_##name; \
97e1c18e
MD
159 static inline void trace_##name(proto) \
160 { \
c5905afb 161 if (static_key_false(&__tracepoint_##name.key)) \
97e1c18e 162 __DO_TRACE(&__tracepoint_##name, \
38516ab5 163 TP_PROTO(data_proto), \
287050d3 164 TP_ARGS(data_args), \
2fbb90db
SR
165 TP_CONDITION(cond),,); \
166 } \
7ece55a4
JT
167 __DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args), \
168 PARAMS(cond), PARAMS(data_proto), PARAMS(data_args)) \
38516ab5
SR
169 static inline int \
170 register_trace_##name(void (*probe)(data_proto), void *data) \
97e1c18e 171 { \
de7b2973
MD
172 return tracepoint_probe_register(&__tracepoint_##name, \
173 (void *)probe, data); \
97e1c18e 174 } \
38516ab5
SR
175 static inline int \
176 unregister_trace_##name(void (*probe)(data_proto), void *data) \
97e1c18e 177 { \
de7b2973
MD
178 return tracepoint_probe_unregister(&__tracepoint_##name,\
179 (void *)probe, data); \
53da59aa 180 } \
38516ab5
SR
181 static inline void \
182 check_trace_callback_type_##name(void (*cb)(data_proto)) \
53da59aa 183 { \
97e1c18e
MD
184 }
185
65498646
MD
186/*
187 * We have no guarantee that gcc and the linker won't up-align the tracepoint
188 * structures, so we create an array of pointers that will be used for iteration
189 * on the tracepoints.
190 */
d430d3d7
JB
191#define DEFINE_TRACE_FN(name, reg, unreg) \
192 static const char __tpstrtab_##name[] \
193 __attribute__((section("__tracepoints_strings"))) = #name; \
194 struct tracepoint __tracepoint_##name \
195 __attribute__((section("__tracepoints"))) = \
c5905afb 196 { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
d430d3d7
JB
197 static struct tracepoint * const __tracepoint_ptr_##name __used \
198 __attribute__((section("__tracepoints_ptrs"))) = \
65498646 199 &__tracepoint_##name;
97419875
JS
200
201#define DEFINE_TRACE(name) \
202 DEFINE_TRACE_FN(name, NULL, NULL);
7e066fb8
MD
203
204#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
205 EXPORT_SYMBOL_GPL(__tracepoint_##name)
206#define EXPORT_TRACEPOINT_SYMBOL(name) \
207 EXPORT_SYMBOL(__tracepoint_##name)
208
97e1c18e 209#else /* !CONFIG_TRACEPOINTS */
2fbb90db 210#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
97e1c18e
MD
211 static inline void trace_##name(proto) \
212 { } \
2fbb90db
SR
213 static inline void trace_##name##_rcuidle(proto) \
214 { } \
38516ab5
SR
215 static inline int \
216 register_trace_##name(void (*probe)(data_proto), \
217 void *data) \
97e1c18e
MD
218 { \
219 return -ENOSYS; \
220 } \
38516ab5
SR
221 static inline int \
222 unregister_trace_##name(void (*probe)(data_proto), \
223 void *data) \
c420970e
MD
224 { \
225 return -ENOSYS; \
53da59aa 226 } \
38516ab5 227 static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
53da59aa 228 { \
c420970e 229 }
97e1c18e 230
97419875 231#define DEFINE_TRACE_FN(name, reg, unreg)
7e066fb8
MD
232#define DEFINE_TRACE(name)
233#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
234#define EXPORT_TRACEPOINT_SYMBOL(name)
235
97e1c18e 236#endif /* CONFIG_TRACEPOINTS */
38516ab5
SR
237
238/*
239 * The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
240 * (void). "void" is a special value in a function prototype and can
241 * not be combined with other arguments. Since the DECLARE_TRACE()
242 * macro adds a data element at the beginning of the prototype,
243 * we need a way to differentiate "(void *data, proto)" from
244 * "(void *data, void)". The second prototype is invalid.
245 *
246 * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
247 * and "void *__data" as the callback prototype.
248 *
249 * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
250 * "void *__data, proto" as the callback prototype.
251 */
252#define DECLARE_TRACE_NOARGS(name) \
287050d3 253 __DECLARE_TRACE(name, void, , 1, void *__data, __data)
38516ab5
SR
254
255#define DECLARE_TRACE(name, proto, args) \
287050d3 256 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), 1, \
38516ab5
SR
257 PARAMS(void *__data, proto), \
258 PARAMS(__data, args))
259
287050d3
SR
260#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
261 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
262 PARAMS(void *__data, proto), \
263 PARAMS(__data, args))
264
1ed0c597
FW
265#define TRACE_EVENT_FLAGS(event, flag)
266
d5b5f391
PZ
267#define TRACE_EVENT_PERF_PERM(event, expr...)
268
ea20d929 269#endif /* DECLARE_TRACE */
97e1c18e 270
ea20d929 271#ifndef TRACE_EVENT
823f9124
SR
272/*
273 * For use with the TRACE_EVENT macro:
274 *
275 * We define a tracepoint, its arguments, its printk format
2621bca8 276 * and its 'fast binary record' layout.
823f9124
SR
277 *
278 * Firstly, name your tracepoint via TRACE_EVENT(name : the
279 * 'subsystem_event' notation is fine.
280 *
281 * Think about this whole construct as the
282 * 'trace_sched_switch() function' from now on.
283 *
284 *
285 * TRACE_EVENT(sched_switch,
286 *
287 * *
288 * * A function has a regular function arguments
289 * * prototype, declare it via TP_PROTO():
290 * *
291 *
ef18012b
SR
292 * TP_PROTO(struct rq *rq, struct task_struct *prev,
293 * struct task_struct *next),
823f9124
SR
294 *
295 * *
296 * * Define the call signature of the 'function'.
297 * * (Design sidenote: we use this instead of a
298 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
299 * *
300 *
ef18012b 301 * TP_ARGS(rq, prev, next),
823f9124
SR
302 *
303 * *
304 * * Fast binary tracing: define the trace record via
305 * * TP_STRUCT__entry(). You can think about it like a
306 * * regular C structure local variable definition.
307 * *
308 * * This is how the trace record is structured and will
309 * * be saved into the ring buffer. These are the fields
310 * * that will be exposed to user-space in
156f5a78 311 * * /sys/kernel/debug/tracing/events/<*>/format.
823f9124
SR
312 * *
313 * * The declared 'local variable' is called '__entry'
314 * *
315 * * __field(pid_t, prev_prid) is equivalent to a standard declariton:
316 * *
317 * * pid_t prev_pid;
318 * *
319 * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
320 * *
321 * * char prev_comm[TASK_COMM_LEN];
322 * *
323 *
324 * TP_STRUCT__entry(
325 * __array( char, prev_comm, TASK_COMM_LEN )
326 * __field( pid_t, prev_pid )
327 * __field( int, prev_prio )
328 * __array( char, next_comm, TASK_COMM_LEN )
329 * __field( pid_t, next_pid )
330 * __field( int, next_prio )
331 * ),
332 *
333 * *
334 * * Assign the entry into the trace record, by embedding
335 * * a full C statement block into TP_fast_assign(). You
336 * * can refer to the trace record as '__entry' -
337 * * otherwise you can put arbitrary C code in here.
338 * *
339 * * Note: this C code will execute every time a trace event
340 * * happens, on an active tracepoint.
341 * *
342 *
ef18012b
SR
343 * TP_fast_assign(
344 * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
345 * __entry->prev_pid = prev->pid;
346 * __entry->prev_prio = prev->prio;
823f9124
SR
347 * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
348 * __entry->next_pid = next->pid;
ef18012b 349 * __entry->next_prio = next->prio;
ec6e7c3a 350 * ),
823f9124
SR
351 *
352 * *
353 * * Formatted output of a trace record via TP_printk().
354 * * This is how the tracepoint will appear under ftrace
355 * * plugins that make use of this tracepoint.
356 * *
357 * * (raw-binary tracing wont actually perform this step.)
358 * *
359 *
360 * TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
361 * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
362 * __entry->next_comm, __entry->next_pid, __entry->next_prio),
363 *
364 * );
365 *
366 * This macro construct is thus used for the regular printk format
367 * tracing setup, it is used to construct a function pointer based
368 * tracepoint callback (this is used by programmatic plugins and
369 * can also by used by generic instrumentation like SystemTap), and
370 * it is also used to expose a structured trace record in
156f5a78 371 * /sys/kernel/debug/tracing/events/.
97419875
JS
372 *
373 * A set of (un)registration functions can be passed to the variant
374 * TRACE_EVENT_FN to perform any (un)registration work.
823f9124
SR
375 */
376
091ad365 377#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
ff038f5c
SR
378#define DEFINE_EVENT(template, name, proto, args) \
379 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
f5abaa1b
SR
380#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
381 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
e5bc9721
SR
382#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
383 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
287050d3
SR
384#define DEFINE_EVENT_CONDITION(template, name, proto, \
385 args, cond) \
386 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
387 PARAMS(args), PARAMS(cond))
ff038f5c 388
30a8fecc 389#define TRACE_EVENT(name, proto, args, struct, assign, print) \
da4d0302 390 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
97419875
JS
391#define TRACE_EVENT_FN(name, proto, args, struct, \
392 assign, print, reg, unreg) \
393 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
287050d3
SR
394#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
395 struct, assign, print) \
396 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
397 PARAMS(args), PARAMS(cond))
7cb2e3ee 398
1ed0c597
FW
399#define TRACE_EVENT_FLAGS(event, flag)
400
d5b5f391
PZ
401#define TRACE_EVENT_PERF_PERM(event, expr...)
402
7cb2e3ee 403#endif /* ifdef TRACE_EVENT (see note above) */
This page took 0.706006 seconds and 5 git commands to generate.