1#ifndef _LINUX_TRACEPOINT_H
2#define _LINUX_TRACEPOINT_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/smp.h>
18#include <linux/errno.h>
19#include <linux/types.h>
20#include <linux/cpumask.h>
21#include <linux/rcupdate.h>
22#include <linux/tracepoint-defs.h>
23
24struct module;
25struct tracepoint;
26struct notifier_block;
27
28struct trace_enum_map {
29 const char *system;
30 const char *enum_string;
31 unsigned long enum_value;
32};
33
34#define TRACEPOINT_DEFAULT_PRIO 10
35
36extern int
37tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
38extern int
39tracepoint_probe_register_prio(struct tracepoint *tp, void *probe, void *data,
40 int prio);
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);
46
47#ifdef CONFIG_MODULES
48struct tp_module {
49 struct list_head list;
50 struct module *mod;
51};
52
53bool trace_module_has_bad_taint(struct module *mod);
54extern int register_tracepoint_module_notifier(struct notifier_block *nb);
55extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
56#else
57static inline bool trace_module_has_bad_taint(struct module *mod)
58{
59 return false;
60}
61static inline
62int register_tracepoint_module_notifier(struct notifier_block *nb)
63{
64 return 0;
65}
66static inline
67int unregister_tracepoint_module_notifier(struct notifier_block *nb)
68{
69 return 0;
70}
71#endif
72
73
74
75
76
77
78static inline void tracepoint_synchronize_unregister(void)
79{
80 synchronize_sched();
81}
82
83#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
84extern void syscall_regfunc(void);
85extern void syscall_unregfunc(void);
86#endif
87
88#define PARAMS(args...) args
89
90#define TRACE_DEFINE_ENUM(x)
91
92#endif
93
94
95
96
97
98
99
100
101
102#ifndef DECLARE_TRACE
103
104#define TP_PROTO(args...) args
105#define TP_ARGS(args...) args
106#define TP_CONDITION(args...) args
107
108
109
110
111
112
113
114
115#if defined(CONFIG_TRACEPOINTS) && !defined(NOTRACE)
116#define TRACEPOINTS_ENABLED
117#endif
118
119#ifdef TRACEPOINTS_ENABLED
120
121
122
123
124
125
126
127
128
129
130
131#define __DO_TRACE(tp, proto, args, cond, prercu, postrcu) \
132 do { \
133 struct tracepoint_func *it_func_ptr; \
134 void *it_func; \
135 void *__data; \
136 \
137 if (!(cond)) \
138 return; \
139 prercu; \
140 rcu_read_lock_sched_notrace(); \
141 it_func_ptr = rcu_dereference_sched((tp)->funcs); \
142 if (it_func_ptr) { \
143 do { \
144 it_func = (it_func_ptr)->func; \
145 __data = (it_func_ptr)->data; \
146 ((void(*)(proto))(it_func))(args); \
147 } while ((++it_func_ptr)->func); \
148 } \
149 rcu_read_unlock_sched_notrace(); \
150 postrcu; \
151 } while (0)
152
153#ifndef MODULE
154#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args) \
155 static inline void trace_##name##_rcuidle(proto) \
156 { \
157 if (static_key_false(&__tracepoint_##name.key)) \
158 __DO_TRACE(&__tracepoint_##name, \
159 TP_PROTO(data_proto), \
160 TP_ARGS(data_args), \
161 TP_CONDITION(cond), \
162 rcu_irq_enter_irqson(), \
163 rcu_irq_exit_irqson()); \
164 }
165#else
166#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args)
167#endif
168
169
170
171
172
173
174
175
176
177
178
179
180
181#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
182 extern struct tracepoint __tracepoint_##name; \
183 static inline void trace_##name(proto) \
184 { \
185 if (static_key_false(&__tracepoint_##name.key)) \
186 __DO_TRACE(&__tracepoint_##name, \
187 TP_PROTO(data_proto), \
188 TP_ARGS(data_args), \
189 TP_CONDITION(cond),,); \
190 if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
191 rcu_read_lock_sched_notrace(); \
192 rcu_dereference_sched(__tracepoint_##name.funcs);\
193 rcu_read_unlock_sched_notrace(); \
194 } \
195 } \
196 __DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args), \
197 PARAMS(cond), PARAMS(data_proto), PARAMS(data_args)) \
198 static inline int \
199 register_trace_##name(void (*probe)(data_proto), void *data) \
200 { \
201 return tracepoint_probe_register(&__tracepoint_##name, \
202 (void *)probe, data); \
203 } \
204 static inline int \
205 register_trace_prio_##name(void (*probe)(data_proto), void *data,\
206 int prio) \
207 { \
208 return tracepoint_probe_register_prio(&__tracepoint_##name, \
209 (void *)probe, data, prio); \
210 } \
211 static inline int \
212 unregister_trace_##name(void (*probe)(data_proto), void *data) \
213 { \
214 return tracepoint_probe_unregister(&__tracepoint_##name,\
215 (void *)probe, data); \
216 } \
217 static inline void \
218 check_trace_callback_type_##name(void (*cb)(data_proto)) \
219 { \
220 } \
221 static inline bool \
222 trace_##name##_enabled(void) \
223 { \
224 return static_key_false(&__tracepoint_##name.key); \
225 }
226
227
228
229
230
231
232#define DEFINE_TRACE_FN(name, reg, unreg) \
233 static const char __tpstrtab_##name[] \
234 __attribute__((section("__tracepoints_strings"))) = #name; \
235 struct tracepoint __tracepoint_##name \
236 __attribute__((section("__tracepoints"))) = \
237 { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
238 static struct tracepoint * const __tracepoint_ptr_##name __used \
239 __attribute__((section("__tracepoints_ptrs"))) = \
240 &__tracepoint_##name;
241
242#define DEFINE_TRACE(name) \
243 DEFINE_TRACE_FN(name, NULL, NULL);
244
245#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
246 EXPORT_SYMBOL_GPL(__tracepoint_##name)
247#define EXPORT_TRACEPOINT_SYMBOL(name) \
248 EXPORT_SYMBOL(__tracepoint_##name)
249
250#else
251#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
252 static inline void trace_##name(proto) \
253 { } \
254 static inline void trace_##name##_rcuidle(proto) \
255 { } \
256 static inline int \
257 register_trace_##name(void (*probe)(data_proto), \
258 void *data) \
259 { \
260 return -ENOSYS; \
261 } \
262 static inline int \
263 unregister_trace_##name(void (*probe)(data_proto), \
264 void *data) \
265 { \
266 return -ENOSYS; \
267 } \
268 static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
269 { \
270 } \
271 static inline bool \
272 trace_##name##_enabled(void) \
273 { \
274 return false; \
275 }
276
277#define DEFINE_TRACE_FN(name, reg, unreg)
278#define DEFINE_TRACE(name)
279#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
280#define EXPORT_TRACEPOINT_SYMBOL(name)
281
282#endif
283
284#ifdef CONFIG_TRACING
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312#define tracepoint_string(str) \
313 ({ \
314 static const char *___tp_str __tracepoint_string = str; \
315 ___tp_str; \
316 })
317#define __tracepoint_string __attribute__((section("__tracepoint_str")))
318#else
319
320
321
322
323
324# define tracepoint_string(str) str
325# define __tracepoint_string
326#endif
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342#define DECLARE_TRACE_NOARGS(name) \
343 __DECLARE_TRACE(name, void, , \
344 cpu_online(raw_smp_processor_id()), \
345 void *__data, __data)
346
347#define DECLARE_TRACE(name, proto, args) \
348 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
349 cpu_online(raw_smp_processor_id()), \
350 PARAMS(void *__data, proto), \
351 PARAMS(__data, args))
352
353#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
354 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
355 cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
356 PARAMS(void *__data, proto), \
357 PARAMS(__data, args))
358
359#define TRACE_EVENT_FLAGS(event, flag)
360
361#define TRACE_EVENT_PERF_PERM(event, expr...)
362
363#endif
364
365#ifndef TRACE_EVENT
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
472#define DEFINE_EVENT(template, name, proto, args) \
473 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
474#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
475 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
476#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
477 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
478#define DEFINE_EVENT_CONDITION(template, name, proto, \
479 args, cond) \
480 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
481 PARAMS(args), PARAMS(cond))
482
483#define TRACE_EVENT(name, proto, args, struct, assign, print) \
484 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
485#define TRACE_EVENT_FN(name, proto, args, struct, \
486 assign, print, reg, unreg) \
487 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
488#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
489 assign, print, reg, unreg) \
490 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
491 PARAMS(args), PARAMS(cond))
492#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
493 struct, assign, print) \
494 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
495 PARAMS(args), PARAMS(cond))
496
497#define TRACE_EVENT_FLAGS(event, flag)
498
499#define TRACE_EVENT_PERF_PERM(event, expr...)
500
501#endif
502