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/errno.h>
18#include <linux/types.h>
19#include <linux/rcupdate.h>
20#include <linux/static_key.h>
21
22struct module;
23struct tracepoint;
24struct notifier_block;
25
26struct tracepoint_func {
27 void *func;
28 void *data;
29};
30
31struct tracepoint {
32 const char *name;
33 struct static_key key;
34 void (*regfunc)(void);
35 void (*unregfunc)(void);
36 struct tracepoint_func __rcu *funcs;
37};
38
39struct trace_enum_map {
40 const char *system;
41 const char *enum_string;
42 unsigned long enum_value;
43};
44
45extern int
46tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
47extern int
48tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
49extern void
50for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
51 void *priv);
52
53#ifdef CONFIG_MODULES
54struct tp_module {
55 struct list_head list;
56 struct module *mod;
57};
58
59bool trace_module_has_bad_taint(struct module *mod);
60extern int register_tracepoint_module_notifier(struct notifier_block *nb);
61extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
62#else
63static inline bool trace_module_has_bad_taint(struct module *mod)
64{
65 return false;
66}
67static inline
68int register_tracepoint_module_notifier(struct notifier_block *nb)
69{
70 return 0;
71}
72static inline
73int unregister_tracepoint_module_notifier(struct notifier_block *nb)
74{
75 return 0;
76}
77#endif
78
79
80
81
82
83
84static inline void tracepoint_synchronize_unregister(void)
85{
86 synchronize_sched();
87}
88
89#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
90extern void syscall_regfunc(void);
91extern void syscall_unregfunc(void);
92#endif
93
94#define PARAMS(args...) args
95
96#define TRACE_DEFINE_ENUM(x)
97
98#endif
99
100
101
102
103
104
105
106
107
108#ifndef DECLARE_TRACE
109
110#define TP_PROTO(args...) args
111#define TP_ARGS(args...) args
112#define TP_CONDITION(args...) args
113
114#ifdef CONFIG_TRACEPOINTS
115
116
117
118
119
120
121
122
123
124
125
126#define __DO_TRACE(tp, proto, args, cond, prercu, postrcu) \
127 do { \
128 struct tracepoint_func *it_func_ptr; \
129 void *it_func; \
130 void *__data; \
131 \
132 if (!(cond)) \
133 return; \
134 prercu; \
135 rcu_read_lock_sched_notrace(); \
136 it_func_ptr = rcu_dereference_sched((tp)->funcs); \
137 if (it_func_ptr) { \
138 do { \
139 it_func = (it_func_ptr)->func; \
140 __data = (it_func_ptr)->data; \
141 ((void(*)(proto))(it_func))(args); \
142 } while ((++it_func_ptr)->func); \
143 } \
144 rcu_read_unlock_sched_notrace(); \
145 postrcu; \
146 } while (0)
147
148#ifndef MODULE
149#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args) \
150 static inline void trace_##name##_rcuidle(proto) \
151 { \
152 if (static_key_false(&__tracepoint_##name.key)) \
153 __DO_TRACE(&__tracepoint_##name, \
154 TP_PROTO(data_proto), \
155 TP_ARGS(data_args), \
156 TP_CONDITION(cond), \
157 rcu_irq_enter(), \
158 rcu_irq_exit()); \
159 }
160#else
161#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args)
162#endif
163
164
165
166
167
168
169
170
171
172
173
174
175#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
176 extern struct tracepoint __tracepoint_##name; \
177 static inline void trace_##name(proto) \
178 { \
179 if (static_key_false(&__tracepoint_##name.key)) \
180 __DO_TRACE(&__tracepoint_##name, \
181 TP_PROTO(data_proto), \
182 TP_ARGS(data_args), \
183 TP_CONDITION(cond),,); \
184 if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
185 rcu_read_lock_sched_notrace(); \
186 rcu_dereference_sched(__tracepoint_##name.funcs);\
187 rcu_read_unlock_sched_notrace(); \
188 } \
189 } \
190 __DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args), \
191 PARAMS(cond), PARAMS(data_proto), PARAMS(data_args)) \
192 static inline int \
193 register_trace_##name(void (*probe)(data_proto), void *data) \
194 { \
195 return tracepoint_probe_register(&__tracepoint_##name, \
196 (void *)probe, data); \
197 } \
198 static inline int \
199 unregister_trace_##name(void (*probe)(data_proto), void *data) \
200 { \
201 return tracepoint_probe_unregister(&__tracepoint_##name,\
202 (void *)probe, data); \
203 } \
204 static inline void \
205 check_trace_callback_type_##name(void (*cb)(data_proto)) \
206 { \
207 } \
208 static inline bool \
209 trace_##name##_enabled(void) \
210 { \
211 return static_key_false(&__tracepoint_##name.key); \
212 }
213
214
215
216
217
218
219#define DEFINE_TRACE_FN(name, reg, unreg) \
220 static const char __tpstrtab_##name[] \
221 __attribute__((section("__tracepoints_strings"))) = #name; \
222 struct tracepoint __tracepoint_##name \
223 __attribute__((section("__tracepoints"))) = \
224 { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
225 static struct tracepoint * const __tracepoint_ptr_##name __used \
226 __attribute__((section("__tracepoints_ptrs"))) = \
227 &__tracepoint_##name;
228
229#define DEFINE_TRACE(name) \
230 DEFINE_TRACE_FN(name, NULL, NULL);
231
232#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
233 EXPORT_SYMBOL_GPL(__tracepoint_##name)
234#define EXPORT_TRACEPOINT_SYMBOL(name) \
235 EXPORT_SYMBOL(__tracepoint_##name)
236
237#else
238#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
239 static inline void trace_##name(proto) \
240 { } \
241 static inline void trace_##name##_rcuidle(proto) \
242 { } \
243 static inline int \
244 register_trace_##name(void (*probe)(data_proto), \
245 void *data) \
246 { \
247 return -ENOSYS; \
248 } \
249 static inline int \
250 unregister_trace_##name(void (*probe)(data_proto), \
251 void *data) \
252 { \
253 return -ENOSYS; \
254 } \
255 static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
256 { \
257 } \
258 static inline bool \
259 trace_##name##_enabled(void) \
260 { \
261 return false; \
262 }
263
264#define DEFINE_TRACE_FN(name, reg, unreg)
265#define DEFINE_TRACE(name)
266#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
267#define EXPORT_TRACEPOINT_SYMBOL(name)
268
269#endif
270
271#ifdef CONFIG_TRACING
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299#define tracepoint_string(str) \
300 ({ \
301 static const char *___tp_str __tracepoint_string = str; \
302 ___tp_str; \
303 })
304#define __tracepoint_string __attribute__((section("__tracepoint_str")))
305#else
306
307
308
309
310
311# define tracepoint_string(str) str
312# define __tracepoint_string
313#endif
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329#define DECLARE_TRACE_NOARGS(name) \
330 __DECLARE_TRACE(name, void, , 1, void *__data, __data)
331
332#define DECLARE_TRACE(name, proto, args) \
333 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), 1, \
334 PARAMS(void *__data, proto), \
335 PARAMS(__data, args))
336
337#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
338 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
339 PARAMS(void *__data, proto), \
340 PARAMS(__data, args))
341
342#define TRACE_EVENT_FLAGS(event, flag)
343
344#define TRACE_EVENT_PERF_PERM(event, expr...)
345
346#endif
347
348#ifndef TRACE_EVENT
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
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#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
455#define DEFINE_EVENT(template, name, proto, args) \
456 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
457#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
458 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
459#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
460 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
461#define DEFINE_EVENT_CONDITION(template, name, proto, \
462 args, cond) \
463 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
464 PARAMS(args), PARAMS(cond))
465
466#define TRACE_EVENT(name, proto, args, struct, assign, print) \
467 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
468#define TRACE_EVENT_FN(name, proto, args, struct, \
469 assign, print, reg, unreg) \
470 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
471#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
472 struct, assign, print) \
473 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
474 PARAMS(args), PARAMS(cond))
475
476#define TRACE_EVENT_FLAGS(event, flag)
477
478#define TRACE_EVENT_PERF_PERM(event, expr...)
479
480#endif
481