xref: /linux/include/linux/tracepoint.h (revision fab183d632628381b466a41479489541ac0e29a0)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _LINUX_TRACEPOINT_H
3 #define _LINUX_TRACEPOINT_H
4 
5 /*
6  * Kernel Tracepoint API.
7  *
8  * See Documentation/trace/tracepoints.rst.
9  *
10  * Copyright (C) 2008-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11  *
12  * Heavily inspired from the Linux Kernel Markers.
13  */
14 
15 #include <linux/smp.h>
16 #include <linux/srcu.h>
17 #include <linux/errno.h>
18 #include <linux/types.h>
19 #include <linux/rcupdate.h>
20 #include <linux/rcupdate_trace.h>
21 #include <linux/tracepoint-defs.h>
22 #include <linux/static_call.h>
23 #include <linux/cfi.h>
24 
25 struct module;
26 struct tracepoint;
27 struct notifier_block;
28 
29 struct trace_eval_map {
30 	const char		*system;
31 	const char		*eval_string;
32 	unsigned long		eval_value;
33 };
34 
35 #define TRACEPOINT_DEFAULT_PRIO	10
36 
37 extern int
38 tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
39 extern int
40 tracepoint_probe_register_prio(struct tracepoint *tp, void *probe, void *data,
41 			       int prio);
42 extern int
43 tracepoint_probe_register_prio_may_exist(struct tracepoint *tp, void *probe, void *data,
44 					 int prio);
45 extern int
46 tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
47 static inline int
tracepoint_probe_register_may_exist(struct tracepoint * tp,void * probe,void * data)48 tracepoint_probe_register_may_exist(struct tracepoint *tp, void *probe,
49 				    void *data)
50 {
51 	return tracepoint_probe_register_prio_may_exist(tp, probe, data,
52 							TRACEPOINT_DEFAULT_PRIO);
53 }
54 extern void
55 for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
56 		void *priv);
57 
58 #ifdef CONFIG_MODULES
59 struct tp_module {
60 	struct list_head list;
61 	struct module *mod;
62 };
63 
64 bool trace_module_has_bad_taint(struct module *mod);
65 extern int register_tracepoint_module_notifier(struct notifier_block *nb);
66 extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
67 void for_each_module_tracepoint(void (*fct)(struct tracepoint *,
68 					struct module *, void *),
69 				void *priv);
70 void for_each_tracepoint_in_module(struct module *,
71 				   void (*fct)(struct tracepoint *,
72 					struct module *, void *),
73 				   void *priv);
74 #else
trace_module_has_bad_taint(struct module * mod)75 static inline bool trace_module_has_bad_taint(struct module *mod)
76 {
77 	return false;
78 }
79 static inline
register_tracepoint_module_notifier(struct notifier_block * nb)80 int register_tracepoint_module_notifier(struct notifier_block *nb)
81 {
82 	return 0;
83 }
84 static inline
unregister_tracepoint_module_notifier(struct notifier_block * nb)85 int unregister_tracepoint_module_notifier(struct notifier_block *nb)
86 {
87 	return 0;
88 }
89 static inline
for_each_module_tracepoint(void (* fct)(struct tracepoint *,struct module *,void *),void * priv)90 void for_each_module_tracepoint(void (*fct)(struct tracepoint *,
91 					struct module *, void *),
92 				void *priv)
93 {
94 }
95 static inline
for_each_tracepoint_in_module(struct module * mod,void (* fct)(struct tracepoint *,struct module *,void *),void * priv)96 void for_each_tracepoint_in_module(struct module *mod,
97 				   void (*fct)(struct tracepoint *,
98 					struct module *, void *),
99 				   void *priv)
100 {
101 }
102 #endif /* CONFIG_MODULES */
103 
104 /*
105  * tracepoint_synchronize_unregister must be called between the last tracepoint
106  * probe unregistration and the end of module exit to make sure there is no
107  * caller executing a probe when it is freed.
108  *
109  * An alternative is to use the following for batch reclaim associated
110  * with a given tracepoint:
111  *
112  * - tracepoint_is_faultable() == false: call_srcu()
113  * - tracepoint_is_faultable() == true:  call_rcu_tasks_trace()
114  */
115 #ifdef CONFIG_TRACEPOINTS
116 extern struct srcu_struct tracepoint_srcu;
tracepoint_synchronize_unregister(void)117 static inline void tracepoint_synchronize_unregister(void)
118 {
119 	synchronize_rcu_tasks_trace();
120 	synchronize_srcu(&tracepoint_srcu);
121 }
tracepoint_is_faultable(struct tracepoint * tp)122 static inline bool tracepoint_is_faultable(struct tracepoint *tp)
123 {
124 	return tp->ext && tp->ext->faultable;
125 }
126 /*
127  * Run RCU callback with the appropriate grace period wait for non-faultable
128  * tracepoints, e.g., those used in atomic context.
129  */
call_tracepoint_unregister_atomic(struct rcu_head * rcu,rcu_callback_t func)130 static inline void call_tracepoint_unregister_atomic(struct rcu_head *rcu, rcu_callback_t func)
131 {
132 	call_srcu(&tracepoint_srcu, rcu, func);
133 }
134 /*
135  * Run RCU callback with the appropriate grace period wait for faultable
136  * tracepoints, e.g., those used in syscall context.
137  */
call_tracepoint_unregister_syscall(struct rcu_head * rcu,rcu_callback_t func)138 static inline void call_tracepoint_unregister_syscall(struct rcu_head *rcu, rcu_callback_t func)
139 {
140 	call_rcu_tasks_trace(rcu, func);
141 }
142 #else
tracepoint_synchronize_unregister(void)143 static inline void tracepoint_synchronize_unregister(void)
144 { }
tracepoint_is_faultable(struct tracepoint * tp)145 static inline bool tracepoint_is_faultable(struct tracepoint *tp)
146 {
147 	return false;
148 }
call_tracepoint_unregister_atomic(struct rcu_head * rcu,rcu_callback_t func)149 static inline void call_tracepoint_unregister_atomic(struct rcu_head *rcu, rcu_callback_t func)
150 {  }
call_tracepoint_unregister_syscall(struct rcu_head * rcu,rcu_callback_t func)151 static inline void call_tracepoint_unregister_syscall(struct rcu_head *rcu, rcu_callback_t func)
152 {  }
153 #endif
154 
155 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
156 extern int syscall_regfunc(void);
157 extern void syscall_unregfunc(void);
158 #endif /* CONFIG_HAVE_SYSCALL_TRACEPOINTS */
159 
160 #ifndef PARAMS
161 #define PARAMS(args...) args
162 #endif
163 
164 #define TRACE_DEFINE_ENUM(x)
165 #define TRACE_DEFINE_SIZEOF(x)
166 
167 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
tracepoint_ptr_deref(tracepoint_ptr_t * p)168 static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
169 {
170 	return offset_to_ptr(p);
171 }
172 
173 #define __TRACEPOINT_ENTRY(name)					\
174 	asm("	.section \"__tracepoints_ptrs\", \"a\"		\n"	\
175 	    "	.balign 4					\n"	\
176 	    "	.long 	__tracepoint_" #name " - .		\n"	\
177 	    "	.previous					\n")
178 #else
tracepoint_ptr_deref(tracepoint_ptr_t * p)179 static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
180 {
181 	return *p;
182 }
183 
184 #define __TRACEPOINT_ENTRY(name)					 \
185 	static tracepoint_ptr_t __tracepoint_ptr_##name __used		 \
186 	__section("__tracepoints_ptrs") = &__tracepoint_##name
187 #endif
188 
189 #endif /* _LINUX_TRACEPOINT_H */
190 
191 /*
192  * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include
193  *  file ifdef protection.
194  *  This is due to the way trace events work. If a file includes two
195  *  trace event headers under one "CREATE_TRACE_POINTS" the first include
196  *  will override the TRACE_EVENT and break the second include.
197  */
198 
199 #ifndef DECLARE_TRACE
200 
201 #define TP_PROTO(args...)	args
202 #define TP_ARGS(args...)	args
203 #define TP_CONDITION(args...)	args
204 
205 /*
206  * Individual subsystem may have a separate configuration to
207  * enable their tracepoints. By default, this file will create
208  * the tracepoints if CONFIG_TRACEPOINTS is defined. If a subsystem
209  * wants to be able to disable its tracepoints from being created
210  * it can define NOTRACE before including the tracepoint headers.
211  */
212 #if defined(CONFIG_TRACEPOINTS) && !defined(NOTRACE)
213 #define TRACEPOINTS_ENABLED
214 #endif
215 
216 #ifdef TRACEPOINTS_ENABLED
217 
218 #ifdef CONFIG_HAVE_STATIC_CALL
219 #define __DO_TRACE_CALL(name, args)					\
220 	do {								\
221 		struct tracepoint_func *it_func_ptr;			\
222 		void *__data;						\
223 		it_func_ptr =						\
224 			rcu_dereference_raw((&__tracepoint_##name)->funcs); \
225 		if (it_func_ptr) {					\
226 			__data = (it_func_ptr)->data;			\
227 			static_call(tp_func_##name)(__data, args);	\
228 		}							\
229 	} while (0)
230 #else
231 #define __DO_TRACE_CALL(name, args)	__traceiter_##name(NULL, args)
232 #endif /* CONFIG_HAVE_STATIC_CALL */
233 
234 /*
235  * Declare an exported function that Rust code can call to trigger this
236  * tracepoint. This function does not include the static branch; that is done
237  * in Rust to avoid a function call when the tracepoint is disabled.
238  */
239 #define DEFINE_RUST_DO_TRACE(name, proto, args)
240 #define __DEFINE_RUST_DO_TRACE(name, proto, args)			\
241 	notrace void rust_do_trace_##name(proto)			\
242 	{								\
243 		__do_trace_##name(args);				\
244 	}
245 
246 /*
247  * When a tracepoint is used, it's name is added to the __tracepoint_check
248  * section. This section is only used at build time to make sure all
249  * defined tracepoints are used. It is discarded after the build.
250  */
251 # define TRACEPOINT_CHECK(name)						\
252 	static const char __used __section("__tracepoint_check")	\
253 	__trace_check_##name[] = #name;
254 
255 /*
256  * Make sure the alignment of the structure in the __tracepoints section will
257  * not add unwanted padding between the beginning of the section and the
258  * structure. Force alignment to the same alignment as the section start.
259  *
260  * When lockdep is enabled, we make sure to always test if RCU is
261  * "watching" regardless if the tracepoint is enabled or not. Tracepoints
262  * require RCU to be active, and it should always warn at the tracepoint
263  * site if it is not watching, as it will need to be active when the
264  * tracepoint is enabled.
265  */
266 #define __DECLARE_TRACE_COMMON(name, proto, args, data_proto)		\
267 	extern int __traceiter_##name(data_proto);			\
268 	DECLARE_STATIC_CALL(tp_func_##name, __traceiter_##name);	\
269 	extern struct tracepoint __tracepoint_##name;			\
270 	extern void rust_do_trace_##name(proto);			\
271 	static inline int						\
272 	register_trace_##name(void (*probe)(data_proto), void *data)	\
273 	{								\
274 		return tracepoint_probe_register(&__tracepoint_##name,	\
275 						(void *)probe, data);	\
276 	}								\
277 	static inline int						\
278 	register_trace_prio_##name(void (*probe)(data_proto), void *data,\
279 				   int prio)				\
280 	{								\
281 		return tracepoint_probe_register_prio(&__tracepoint_##name, \
282 					      (void *)probe, data, prio); \
283 	}								\
284 	static inline int						\
285 	unregister_trace_##name(void (*probe)(data_proto), void *data)	\
286 	{								\
287 		return tracepoint_probe_unregister(&__tracepoint_##name,\
288 						(void *)probe, data);	\
289 	}								\
290 	static inline void						\
291 	check_trace_callback_type_##name(void (*cb)(data_proto))	\
292 	{								\
293 	}								\
294 	static inline bool						\
295 	__trace_##name##_enabled(void)					\
296 	{								\
297 		return static_branch_unlikely(&__tracepoint_##name.key);\
298 	}								\
299 	static inline bool						\
300 	trace_##name##_enabled(void)					\
301 	{								\
302 		if (IS_ENABLED(CONFIG_LOCKDEP)) {			\
303 			WARN_ONCE(!rcu_is_watching(),			\
304 				  "RCU not watching for tracepoint");	\
305 		}							\
306 		return __trace_##name##_enabled();			\
307 	}
308 
309 #define __DECLARE_TRACE(name, proto, args, cond, data_proto)			\
310 	__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \
311 	static inline void __do_trace_##name(proto)			\
312 	{								\
313 		TRACEPOINT_CHECK(name)					\
314 		if (cond) {						\
315 			guard(srcu_fast_notrace)(&tracepoint_srcu);	\
316 			__DO_TRACE_CALL(name, TP_ARGS(args));		\
317 		}							\
318 	}								\
319 	static inline void trace_##name(proto)				\
320 	{								\
321 		if (static_branch_unlikely(&__tracepoint_##name.key))	\
322 			__do_trace_##name(args);			\
323 		if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) {		\
324 			WARN_ONCE(!rcu_is_watching(),			\
325 				  "RCU not watching for tracepoint");	\
326 		}							\
327 	}								\
328 	static inline void trace_call__##name(proto)			\
329 	{								\
330 		__do_trace_##name(args);				\
331 	}
332 
333 #define __DECLARE_TRACE_SYSCALL(name, proto, args, data_proto)		\
334 	__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \
335 	static inline void __do_trace_##name(proto)			\
336 	{								\
337 		TRACEPOINT_CHECK(name)					\
338 		guard(rcu_tasks_trace)();				\
339 		__DO_TRACE_CALL(name, TP_ARGS(args));			\
340 	}								\
341 	static inline void trace_##name(proto)				\
342 	{								\
343 		might_fault();						\
344 		if (static_branch_unlikely(&__tracepoint_##name.key))	\
345 			__do_trace_##name(args);			\
346 		if (IS_ENABLED(CONFIG_LOCKDEP)) {			\
347 			WARN_ONCE(!rcu_is_watching(),			\
348 				  "RCU not watching for tracepoint");	\
349 		}							\
350 	}								\
351 	static inline void trace_call__##name(proto)			\
352 	{								\
353 		might_fault();						\
354 		__do_trace_##name(args);				\
355 	}
356 
357 /*
358  * We have no guarantee that gcc and the linker won't up-align the tracepoint
359  * structures, so we create an array of pointers that will be used for iteration
360  * on the tracepoints.
361  *
362  * it_func[0] is never NULL because there is at least one element in the array
363  * when the array itself is non NULL.
364  */
365 #define __DEFINE_TRACE_EXT(_name, _ext, proto, args)			\
366 	static const char __tpstrtab_##_name[]				\
367 	__section("__tracepoints_strings") = #_name;			\
368 	extern struct static_call_key STATIC_CALL_KEY(tp_func_##_name);	\
369 	int __traceiter_##_name(void *__data, proto);			\
370 	void __probestub_##_name(void *__data, proto);			\
371 	struct tracepoint __tracepoint_##_name	__used			\
372 	__section("__tracepoints") = {					\
373 		.name = __tpstrtab_##_name,				\
374 		.key = STATIC_KEY_FALSE_INIT,				\
375 		.static_call_key = &STATIC_CALL_KEY(tp_func_##_name),	\
376 		.static_call_tramp = STATIC_CALL_TRAMP_ADDR(tp_func_##_name), \
377 		.iterator = &__traceiter_##_name,			\
378 		.probestub = &__probestub_##_name,			\
379 		.funcs = NULL,						\
380 		.ext = _ext,						\
381 	};								\
382 	__TRACEPOINT_ENTRY(_name);					\
383 	int __traceiter_##_name(void *__data, proto)			\
384 	{								\
385 		struct tracepoint_func *it_func_ptr;			\
386 		void *it_func;						\
387 									\
388 		it_func_ptr =						\
389 			rcu_dereference_raw((&__tracepoint_##_name)->funcs); \
390 		if (it_func_ptr) {					\
391 			do {						\
392 				it_func = READ_ONCE((it_func_ptr)->func); \
393 				__data = (it_func_ptr)->data;		\
394 				((void(*)(void *, proto))(it_func))(__data, args); \
395 			} while ((++it_func_ptr)->func);		\
396 		}							\
397 		return 0;						\
398 	}								\
399 	void __probestub_##_name(void *__data, proto)			\
400 	{								\
401 	}								\
402 	/*								\
403 	 * Annotate the probestub 'CFI_NOSEAL' to stop objtool from	\
404 	 * requesting the kernel remove the ENDBR, because the only	\
405 	 * references to the function are in the __tracepoint section,	\
406 	 * that objtool doesn't scan.					\
407 	 */								\
408 	CFI_NOSEAL(__probestub_##_name);				\
409 	DEFINE_STATIC_CALL(tp_func_##_name, __traceiter_##_name);	\
410 	DEFINE_RUST_DO_TRACE(_name, TP_PROTO(proto), TP_ARGS(args))
411 
412 #define DEFINE_TRACE_FN(_name, _reg, _unreg, _proto, _args)		\
413 	static struct tracepoint_ext __tracepoint_ext_##_name = {	\
414 		.regfunc = _reg,					\
415 		.unregfunc = _unreg,					\
416 		.faultable = false,					\
417 	};								\
418 	__DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARAMS(_args));
419 
420 #define DEFINE_TRACE_SYSCALL(_name, _reg, _unreg, _proto, _args)	\
421 	static struct tracepoint_ext __tracepoint_ext_##_name = {	\
422 		.regfunc = _reg,					\
423 		.unregfunc = _unreg,					\
424 		.faultable = true,					\
425 	};								\
426 	__DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARAMS(_args));
427 
428 #define DEFINE_TRACE(_name, _proto, _args)				\
429 	__DEFINE_TRACE_EXT(_name, NULL, PARAMS(_proto), PARAMS(_args));
430 
431 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)				\
432 	TRACEPOINT_CHECK(name)						\
433 	EXPORT_SYMBOL_GPL(__tracepoint_##name);				\
434 	EXPORT_SYMBOL_GPL(__traceiter_##name);				\
435 	EXPORT_STATIC_CALL_GPL(tp_func_##name)
436 #define EXPORT_TRACEPOINT_SYMBOL(name)					\
437 	TRACEPOINT_CHECK(name)						\
438 	EXPORT_SYMBOL(__tracepoint_##name);				\
439 	EXPORT_SYMBOL(__traceiter_##name);				\
440 	EXPORT_STATIC_CALL(tp_func_##name)
441 
442 
443 #else /* !TRACEPOINTS_ENABLED */
444 #define __DECLARE_TRACE_COMMON(name, proto, args, data_proto)		\
445 	static inline void trace_##name(proto)				\
446 	{ }								\
447 	static inline void trace_call__##name(proto)			\
448 	{ }								\
449 	static inline int						\
450 	register_trace_##name(void (*probe)(data_proto),		\
451 			      void *data)				\
452 	{								\
453 		return -ENOSYS;						\
454 	}								\
455 	static inline int						\
456 	unregister_trace_##name(void (*probe)(data_proto),		\
457 				void *data)				\
458 	{								\
459 		return -ENOSYS;						\
460 	}								\
461 	static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
462 	{								\
463 	}								\
464 	static inline bool						\
465 	__trace_##name##_enabled(void)					\
466 	{								\
467 		return false;						\
468 	}								\
469 	static inline bool						\
470 	trace_##name##_enabled(void)					\
471 	{								\
472 		return false;						\
473 	}
474 
475 #define __DECLARE_TRACE(name, proto, args, cond, data_proto)		\
476 	__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto))
477 
478 #define __DECLARE_TRACE_SYSCALL(name, proto, args, data_proto)		\
479 	__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto))
480 
481 #define DEFINE_TRACE_FN(name, reg, unreg, proto, args)
482 #define DEFINE_TRACE_SYSCALL(name, reg, unreg, proto, args)
483 #define DEFINE_TRACE(name, proto, args)
484 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
485 #define EXPORT_TRACEPOINT_SYMBOL(name)
486 
487 #endif /* TRACEPOINTS_ENABLED */
488 
489 #ifdef CONFIG_TRACING
490 /**
491  * tracepoint_string - register constant persistent string to trace system
492  * @str - a constant persistent string that will be referenced in tracepoints
493  *
494  * If constant strings are being used in tracepoints, it is faster and
495  * more efficient to just save the pointer to the string and reference
496  * that with a printf "%s" instead of saving the string in the ring buffer
497  * and wasting space and time.
498  *
499  * The problem with the above approach is that userspace tools that read
500  * the binary output of the trace buffers do not have access to the string.
501  * Instead they just show the address of the string which is not very
502  * useful to users.
503  *
504  * With tracepoint_string(), the string will be registered to the tracing
505  * system and exported to userspace via the debugfs/tracing/printk_formats
506  * file that maps the string address to the string text. This way userspace
507  * tools that read the binary buffers have a way to map the pointers to
508  * the ASCII strings they represent.
509  *
510  * The @str used must be a constant string and persistent as it would not
511  * make sense to show a string that no longer exists. But it is still fine
512  * to be used with modules, because when modules are unloaded, if they
513  * had tracepoints, the ring buffers are cleared too. As long as the string
514  * does not change during the life of the module, it is fine to use
515  * tracepoint_string() within a module.
516  */
517 #define tracepoint_string(str)						\
518 	({								\
519 		static const char *___tp_str __tracepoint_string = str; \
520 		___tp_str;						\
521 	})
522 #define __tracepoint_string	__used __section("__tracepoint_str")
523 #else
524 /*
525  * tracepoint_string() is used to save the string address for userspace
526  * tracing tools. When tracing isn't configured, there's no need to save
527  * anything.
528  */
529 # define tracepoint_string(str) str
530 # define __tracepoint_string
531 #endif
532 
533 #define DECLARE_TRACE(name, proto, args)				\
534 	__DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args),		\
535 			cpu_online(raw_smp_processor_id()),		\
536 			PARAMS(void *__data, proto))
537 
538 #define DECLARE_TRACE_CONDITION(name, proto, args, cond)		\
539 	__DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args),		\
540 			cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
541 			PARAMS(void *__data, proto))
542 
543 #define DECLARE_TRACE_SYSCALL(name, proto, args)			\
544 	__DECLARE_TRACE_SYSCALL(name##_tp, PARAMS(proto), PARAMS(args),	\
545 				PARAMS(void *__data, proto))
546 
547 #define DECLARE_TRACE_EVENT(name, proto, args)				\
548 	__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),		\
549 			cpu_online(raw_smp_processor_id()),		\
550 			PARAMS(void *__data, proto))
551 
552 #define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond)		\
553 	__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),		\
554 			cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
555 			PARAMS(void *__data, proto))
556 
557 #define DECLARE_TRACE_EVENT_SYSCALL(name, proto, args)			\
558 	__DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args),	\
559 				PARAMS(void *__data, proto))
560 
561 #define TRACE_EVENT_FLAGS(event, flag)
562 
563 #define TRACE_EVENT_PERF_PERM(event, expr...)
564 
565 #endif /* DECLARE_TRACE */
566 
567 #ifndef TRACE_EVENT
568 /*
569  * For use with the TRACE_EVENT macro:
570  *
571  * We define a tracepoint, its arguments, its printk format
572  * and its 'fast binary record' layout.
573  *
574  * Firstly, name your tracepoint via TRACE_EVENT(name : the
575  * 'subsystem_event' notation is fine.
576  *
577  * Think about this whole construct as the
578  * 'trace_sched_switch() function' from now on.
579  *
580  *
581  *  TRACE_EVENT(sched_switch,
582  *
583  *	*
584  *	* A function has a regular function arguments
585  *	* prototype, declare it via TP_PROTO():
586  *	*
587  *
588  *	TP_PROTO(struct rq *rq, struct task_struct *prev,
589  *		 struct task_struct *next),
590  *
591  *	*
592  *	* Define the call signature of the 'function'.
593  *	* (Design sidenote: we use this instead of a
594  *	*  TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
595  *	*
596  *
597  *	TP_ARGS(rq, prev, next),
598  *
599  *	*
600  *	* Fast binary tracing: define the trace record via
601  *	* TP_STRUCT__entry(). You can think about it like a
602  *	* regular C structure local variable definition.
603  *	*
604  *	* This is how the trace record is structured and will
605  *	* be saved into the ring buffer. These are the fields
606  *	* that will be exposed to user-space in
607  *	* /sys/kernel/tracing/events/<*>/format.
608  *	*
609  *	* The declared 'local variable' is called '__entry'
610  *	*
611  *	* __field(pid_t, prev_pid) is equivalent to a standard declaration:
612  *	*
613  *	*	pid_t	prev_pid;
614  *	*
615  *	* __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
616  *	*
617  *	*	char	prev_comm[TASK_COMM_LEN];
618  *	*
619  *
620  *	TP_STRUCT__entry(
621  *		__array(	char,	prev_comm,	TASK_COMM_LEN	)
622  *		__field(	pid_t,	prev_pid			)
623  *		__field(	int,	prev_prio			)
624  *		__array(	char,	next_comm,	TASK_COMM_LEN	)
625  *		__field(	pid_t,	next_pid			)
626  *		__field(	int,	next_prio			)
627  *	),
628  *
629  *	*
630  *	* Assign the entry into the trace record, by embedding
631  *	* a full C statement block into TP_fast_assign(). You
632  *	* can refer to the trace record as '__entry' -
633  *	* otherwise you can put arbitrary C code in here.
634  *	*
635  *	* Note: this C code will execute every time a trace event
636  *	* happens, on an active tracepoint.
637  *	*
638  *
639  *	TP_fast_assign(
640  *		memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
641  *		__entry->prev_pid	= prev->pid;
642  *		__entry->prev_prio	= prev->prio;
643  *		memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
644  *		__entry->next_pid	= next->pid;
645  *		__entry->next_prio	= next->prio;
646  *	),
647  *
648  *	*
649  *	* Formatted output of a trace record via TP_printk().
650  *	* This is how the tracepoint will appear under ftrace
651  *	* plugins that make use of this tracepoint.
652  *	*
653  *	* (raw-binary tracing wont actually perform this step.)
654  *	*
655  *
656  *	TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
657  *		__entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
658  *		__entry->next_comm, __entry->next_pid, __entry->next_prio),
659  *
660  * );
661  *
662  * This macro construct is thus used for the regular printk format
663  * tracing setup, it is used to construct a function pointer based
664  * tracepoint callback (this is used by programmatic plugins and
665  * can also by used by generic instrumentation like SystemTap), and
666  * it is also used to expose a structured trace record in
667  * /sys/kernel/tracing/events/.
668  *
669  * A set of (un)registration functions can be passed to the variant
670  * TRACE_EVENT_FN to perform any (un)registration work.
671  */
672 
673 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
674 #define DEFINE_EVENT(template, name, proto, args)		\
675 	DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
676 #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
677 	DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
678 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
679 	DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
680 #define DEFINE_EVENT_CONDITION(template, name, proto,		\
681 			       args, cond)			\
682 	DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto),	\
683 				PARAMS(args), PARAMS(cond))
684 
685 #define TRACE_EVENT(name, proto, args, struct, assign, print)	\
686 	DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
687 #define TRACE_EVENT_FN(name, proto, args, struct,		\
688 		assign, print, reg, unreg)			\
689 	DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
690 #define TRACE_EVENT_FN_COND(name, proto, args, cond, struct,	\
691 		assign, print, reg, unreg)			\
692 	DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto),	\
693 			PARAMS(args), PARAMS(cond))
694 #define TRACE_EVENT_CONDITION(name, proto, args, cond,		\
695 			      struct, assign, print)		\
696 	DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto),	\
697 				PARAMS(args), PARAMS(cond))
698 #define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign,	\
699 			    print, reg, unreg)			\
700 	DECLARE_TRACE_EVENT_SYSCALL(name, PARAMS(proto), PARAMS(args))
701 
702 #define TRACE_EVENT_FLAGS(event, flag)
703 
704 #define TRACE_EVENT_PERF_PERM(event, expr...)
705 
706 #define DECLARE_EVENT_NOP(name, proto, args)				\
707 	static inline void trace_##name(proto)				\
708 	{ }								\
709 	static inline bool trace_##name##_enabled(void)			\
710 	{								\
711 		return false;						\
712 	}
713 
714 #define TRACE_EVENT_NOP(name, proto, args, struct, assign, print)	\
715 	DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args))
716 
717 #define DECLARE_EVENT_CLASS_NOP(name, proto, args, tstruct, assign, print)
718 #define DEFINE_EVENT_NOP(template, name, proto, args)			\
719 	DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args))
720 
721 #endif /* ifdef TRACE_EVENT (see note above) */
722