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_eval_map {
29 const char *system;
30 const char *eval_string;
31 unsigned long eval_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 int syscall_regfunc(void);
85extern void syscall_unregfunc(void);
86#endif
87
88#define PARAMS(args...) args
89
90#define TRACE_DEFINE_ENUM(x)
91#define TRACE_DEFINE_SIZEOF(x)
92
93#endif
94
95
96
97
98
99
100
101
102
103#ifndef DECLARE_TRACE
104
105#define TP_PROTO(args...) args
106#define TP_ARGS(args...) args
107#define TP_CONDITION(args...) args
108
109
110
111
112
113
114
115
116#if defined(CONFIG_TRACEPOINTS) && !defined(NOTRACE)
117#define TRACEPOINTS_ENABLED
118#endif
119
120#ifdef TRACEPOINTS_ENABLED
121
122
123
124
125
126
127
128
129
130
131
132#define __DO_TRACE(tp, proto, args, cond, rcucheck) \
133 do { \
134 struct tracepoint_func *it_func_ptr; \
135 void *it_func; \
136 void *__data; \
137 \
138 if (!(cond)) \
139 return; \
140 if (rcucheck) \
141 rcu_irq_enter_irqson(); \
142 rcu_read_lock_sched_notrace(); \
143 it_func_ptr = rcu_dereference_sched((tp)->funcs); \
144 if (it_func_ptr) { \
145 do { \
146 it_func = (it_func_ptr)->func; \
147 __data = (it_func_ptr)->data; \
148 ((void(*)(proto))(it_func))(args); \
149 } while ((++it_func_ptr)->func); \
150 } \
151 rcu_read_unlock_sched_notrace(); \
152 if (rcucheck) \
153 rcu_irq_exit_irqson(); \
154 } while (0)
155
156#ifndef MODULE
157#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args) \
158 static inline void trace_##name##_rcuidle(proto) \
159 { \
160 if (static_key_false(&__tracepoint_##name.key)) \
161 __DO_TRACE(&__tracepoint_##name, \
162 TP_PROTO(data_proto), \
163 TP_ARGS(data_args), \
164 TP_CONDITION(cond), 1); \
165 }
166#else
167#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args)
168#endif
169
170
171
172
173
174
175
176
177
178
179
180
181
182#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
183 extern struct tracepoint __tracepoint_##name; \
184 static inline void trace_##name(proto) \
185 { \
186 if (static_key_false(&__tracepoint_##name.key)) \
187 __DO_TRACE(&__tracepoint_##name, \
188 TP_PROTO(data_proto), \
189 TP_ARGS(data_args), \
190 TP_CONDITION(cond), 0); \
191 if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
192 rcu_read_lock_sched_notrace(); \
193 rcu_dereference_sched(__tracepoint_##name.funcs);\
194 rcu_read_unlock_sched_notrace(); \
195 } \
196 } \
197 __DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args), \
198 PARAMS(cond), PARAMS(data_proto), PARAMS(data_args)) \
199 static inline int \
200 register_trace_##name(void (*probe)(data_proto), void *data) \
201 { \
202 return tracepoint_probe_register(&__tracepoint_##name, \
203 (void *)probe, data); \
204 } \
205 static inline int \
206 register_trace_prio_##name(void (*probe)(data_proto), void *data,\
207 int prio) \
208 { \
209 return tracepoint_probe_register_prio(&__tracepoint_##name, \
210 (void *)probe, data, prio); \
211 } \
212 static inline int \
213 unregister_trace_##name(void (*probe)(data_proto), void *data) \
214 { \
215 return tracepoint_probe_unregister(&__tracepoint_##name,\
216 (void *)probe, data); \
217 } \
218 static inline void \
219 check_trace_callback_type_##name(void (*cb)(data_proto)) \
220 { \
221 } \
222 static inline bool \
223 trace_##name##_enabled(void) \
224 { \
225 return static_key_false(&__tracepoint_##name.key); \
226 }
227
228
229
230
231
232
233#define DEFINE_TRACE_FN(name, reg, unreg) \
234 static const char __tpstrtab_##name[] \
235 __attribute__((section("__tracepoints_strings"))) = #name; \
236 struct tracepoint __tracepoint_##name \
237 __attribute__((section("__tracepoints"))) = \
238 { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
239 static struct tracepoint * const __tracepoint_ptr_##name __used \
240 __attribute__((section("__tracepoints_ptrs"))) = \
241 &__tracepoint_##name;
242
243#define DEFINE_TRACE(name) \
244 DEFINE_TRACE_FN(name, NULL, NULL);
245
246#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
247 EXPORT_SYMBOL_GPL(__tracepoint_##name)
248#define EXPORT_TRACEPOINT_SYMBOL(name) \
249 EXPORT_SYMBOL(__tracepoint_##name)
250
251#else
252#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
253 static inline void trace_##name(proto) \
254 { } \
255 static inline void trace_##name##_rcuidle(proto) \
256 { } \
257 static inline int \
258 register_trace_##name(void (*probe)(data_proto), \
259 void *data) \
260 { \
261 return -ENOSYS; \
262 } \
263 static inline int \
264 unregister_trace_##name(void (*probe)(data_proto), \
265 void *data) \
266 { \
267 return -ENOSYS; \
268 } \
269 static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
270 { \
271 } \
272 static inline bool \
273 trace_##name##_enabled(void) \
274 { \
275 return false; \
276 }
277
278#define DEFINE_TRACE_FN(name, reg, unreg)
279#define DEFINE_TRACE(name)
280#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
281#define EXPORT_TRACEPOINT_SYMBOL(name)
282
283#endif
284
285#ifdef CONFIG_TRACING
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
313#define tracepoint_string(str) \
314 ({ \
315 static const char *___tp_str __tracepoint_string = str; \
316 ___tp_str; \
317 })
318#define __tracepoint_string __attribute__((section("__tracepoint_str")))
319#else
320
321
322
323
324
325# define tracepoint_string(str) str
326# define __tracepoint_string
327#endif
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343#define DECLARE_TRACE_NOARGS(name) \
344 __DECLARE_TRACE(name, void, , \
345 cpu_online(raw_smp_processor_id()), \
346 void *__data, __data)
347
348#define DECLARE_TRACE(name, proto, args) \
349 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
350 cpu_online(raw_smp_processor_id()), \
351 PARAMS(void *__data, proto), \
352 PARAMS(__data, args))
353
354#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
355 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
356 cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
357 PARAMS(void *__data, proto), \
358 PARAMS(__data, args))
359
360#define TRACE_EVENT_FLAGS(event, flag)
361
362#define TRACE_EVENT_PERF_PERM(event, expr...)
363
364#endif
365
366#ifndef TRACE_EVENT
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
472#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
473#define DEFINE_EVENT(template, name, proto, args) \
474 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
475#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
476 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
477#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
478 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
479#define DEFINE_EVENT_CONDITION(template, name, proto, \
480 args, cond) \
481 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
482 PARAMS(args), PARAMS(cond))
483
484#define TRACE_EVENT(name, proto, args, struct, assign, print) \
485 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
486#define TRACE_EVENT_FN(name, proto, args, struct, \
487 assign, print, reg, unreg) \
488 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
489#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
490 assign, print, reg, unreg) \
491 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
492 PARAMS(args), PARAMS(cond))
493#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
494 struct, assign, print) \
495 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
496 PARAMS(args), PARAMS(cond))
497
498#define TRACE_EVENT_FLAGS(event, flag)
499
500#define TRACE_EVENT_PERF_PERM(event, expr...)
501
502#endif
503