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