xref: /openbmc/linux/include/trace/trace_events.h (revision 09717af7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Stage 1 of the trace events.
4  *
5  * Override the macros in the event tracepoint header <trace/events/XXX.h>
6  * to include the following:
7  *
8  * struct trace_event_raw_<call> {
9  *	struct trace_entry		ent;
10  *	<type>				<item>;
11  *	<type2>				<item2>[<len>];
12  *	[...]
13  * };
14  *
15  * The <type> <item> is created by the __field(type, item) macro or
16  * the __array(type2, item2, len) macro.
17  * We simply do "type item;", and that will create the fields
18  * in the structure.
19  */
20 
21 #include <linux/trace_events.h>
22 
23 #ifndef TRACE_SYSTEM_VAR
24 #define TRACE_SYSTEM_VAR TRACE_SYSTEM
25 #endif
26 
27 #define __app__(x, y) str__##x##y
28 #define __app(x, y) __app__(x, y)
29 
30 #define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
31 
32 #define TRACE_MAKE_SYSTEM_STR()				\
33 	static const char TRACE_SYSTEM_STRING[] =	\
34 		__stringify(TRACE_SYSTEM)
35 
36 TRACE_MAKE_SYSTEM_STR();
37 
38 #undef TRACE_DEFINE_ENUM
39 #define TRACE_DEFINE_ENUM(a)				\
40 	static struct trace_eval_map __used __initdata	\
41 	__##TRACE_SYSTEM##_##a =			\
42 	{						\
43 		.system = TRACE_SYSTEM_STRING,		\
44 		.eval_string = #a,			\
45 		.eval_value = a				\
46 	};						\
47 	static struct trace_eval_map __used		\
48 	__section("_ftrace_eval_map")			\
49 	*TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
50 
51 #undef TRACE_DEFINE_SIZEOF
52 #define TRACE_DEFINE_SIZEOF(a)				\
53 	static struct trace_eval_map __used __initdata	\
54 	__##TRACE_SYSTEM##_##a =			\
55 	{						\
56 		.system = TRACE_SYSTEM_STRING,		\
57 		.eval_string = "sizeof(" #a ")",	\
58 		.eval_value = sizeof(a)			\
59 	};						\
60 	static struct trace_eval_map __used		\
61 	__section("_ftrace_eval_map")			\
62 	*TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
63 
64 /*
65  * DECLARE_EVENT_CLASS can be used to add a generic function
66  * handlers for events. That is, if all events have the same
67  * parameters and just have distinct trace points.
68  * Each tracepoint can be defined with DEFINE_EVENT and that
69  * will map the DECLARE_EVENT_CLASS to the tracepoint.
70  *
71  * TRACE_EVENT is a one to one mapping between tracepoint and template.
72  */
73 #undef TRACE_EVENT
74 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
75 	DECLARE_EVENT_CLASS(name,			       \
76 			     PARAMS(proto),		       \
77 			     PARAMS(args),		       \
78 			     PARAMS(tstruct),		       \
79 			     PARAMS(assign),		       \
80 			     PARAMS(print));		       \
81 	DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
82 
83 
84 #undef __field
85 #define __field(type, item)		type	item;
86 
87 #undef __field_ext
88 #define __field_ext(type, item, filter_type)	type	item;
89 
90 #undef __field_struct
91 #define __field_struct(type, item)	type	item;
92 
93 #undef __field_struct_ext
94 #define __field_struct_ext(type, item, filter_type)	type	item;
95 
96 #undef __array
97 #define __array(type, item, len)	type	item[len];
98 
99 #undef __dynamic_array
100 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
101 
102 #undef __string
103 #define __string(item, src) __dynamic_array(char, item, -1)
104 
105 #undef __string_len
106 #define __string_len(item, src, len) __dynamic_array(char, item, -1)
107 
108 #undef __bitmask
109 #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
110 
111 #undef TP_STRUCT__entry
112 #define TP_STRUCT__entry(args...) args
113 
114 #undef DECLARE_EVENT_CLASS
115 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)	\
116 	struct trace_event_raw_##name {					\
117 		struct trace_entry	ent;				\
118 		tstruct							\
119 		char			__data[0];			\
120 	};								\
121 									\
122 	static struct trace_event_class event_class_##name;
123 
124 #undef DEFINE_EVENT
125 #define DEFINE_EVENT(template, name, proto, args)	\
126 	static struct trace_event_call	__used		\
127 	__attribute__((__aligned__(4))) event_##name
128 
129 #undef DEFINE_EVENT_FN
130 #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)	\
131 	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
132 
133 #undef DEFINE_EVENT_PRINT
134 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
135 	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
136 
137 /* Callbacks are meaningless to ftrace. */
138 #undef TRACE_EVENT_FN
139 #define TRACE_EVENT_FN(name, proto, args, tstruct,			\
140 		assign, print, reg, unreg)				\
141 	TRACE_EVENT(name, PARAMS(proto), PARAMS(args),			\
142 		PARAMS(tstruct), PARAMS(assign), PARAMS(print))		\
143 
144 #undef TRACE_EVENT_FN_COND
145 #define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct,	\
146 		assign, print, reg, unreg)				\
147 	TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond),		\
148 		PARAMS(tstruct), PARAMS(assign), PARAMS(print))		\
149 
150 #undef TRACE_EVENT_FLAGS
151 #define TRACE_EVENT_FLAGS(name, value)					\
152 	__TRACE_EVENT_FLAGS(name, value)
153 
154 #undef TRACE_EVENT_PERF_PERM
155 #define TRACE_EVENT_PERF_PERM(name, expr...)				\
156 	__TRACE_EVENT_PERF_PERM(name, expr)
157 
158 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
159 
160 /*
161  * Stage 2 of the trace events.
162  *
163  * Include the following:
164  *
165  * struct trace_event_data_offsets_<call> {
166  *	u32				<item1>;
167  *	u32				<item2>;
168  *	[...]
169  * };
170  *
171  * The __dynamic_array() macro will create each u32 <item>, this is
172  * to keep the offset of each array from the beginning of the event.
173  * The size of an array is also encoded, in the higher 16 bits of <item>.
174  */
175 
176 #undef TRACE_DEFINE_ENUM
177 #define TRACE_DEFINE_ENUM(a)
178 
179 #undef TRACE_DEFINE_SIZEOF
180 #define TRACE_DEFINE_SIZEOF(a)
181 
182 #undef __field
183 #define __field(type, item)
184 
185 #undef __field_ext
186 #define __field_ext(type, item, filter_type)
187 
188 #undef __field_struct
189 #define __field_struct(type, item)
190 
191 #undef __field_struct_ext
192 #define __field_struct_ext(type, item, filter_type)
193 
194 #undef __array
195 #define __array(type, item, len)
196 
197 #undef __dynamic_array
198 #define __dynamic_array(type, item, len)	u32 item;
199 
200 #undef __string
201 #define __string(item, src) __dynamic_array(char, item, -1)
202 
203 #undef __string_len
204 #define __string_len(item, src, len) __dynamic_array(char, item, -1)
205 
206 #undef __bitmask
207 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
208 
209 #undef DECLARE_EVENT_CLASS
210 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
211 	struct trace_event_data_offsets_##call {			\
212 		tstruct;						\
213 	};
214 
215 #undef DEFINE_EVENT
216 #define DEFINE_EVENT(template, name, proto, args)
217 
218 #undef DEFINE_EVENT_PRINT
219 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
220 
221 #undef TRACE_EVENT_FLAGS
222 #define TRACE_EVENT_FLAGS(event, flag)
223 
224 #undef TRACE_EVENT_PERF_PERM
225 #define TRACE_EVENT_PERF_PERM(event, expr...)
226 
227 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
228 
229 /*
230  * Stage 3 of the trace events.
231  *
232  * Override the macros in the event tracepoint header <trace/events/XXX.h>
233  * to include the following:
234  *
235  * enum print_line_t
236  * trace_raw_output_<call>(struct trace_iterator *iter, int flags)
237  * {
238  *	struct trace_seq *s = &iter->seq;
239  *	struct trace_event_raw_<call> *field; <-- defined in stage 1
240  *	struct trace_seq *p = &iter->tmp_seq;
241  *
242  * -------(for event)-------
243  *
244  *	struct trace_entry *entry;
245  *
246  *	entry = iter->ent;
247  *
248  *	if (entry->type != event_<call>->event.type) {
249  *		WARN_ON_ONCE(1);
250  *		return TRACE_TYPE_UNHANDLED;
251  *	}
252  *
253  *	field = (typeof(field))entry;
254  *
255  *	trace_seq_init(p);
256  *	return trace_output_call(iter, <call>, <TP_printk> "\n");
257  *
258  * ------(or, for event class)------
259  *
260  *	int ret;
261  *
262  *	field = (typeof(field))iter->ent;
263  *
264  *	ret = trace_raw_output_prep(iter, trace_event);
265  *	if (ret != TRACE_TYPE_HANDLED)
266  *		return ret;
267  *
268  *	trace_event_printf(iter, <TP_printk> "\n");
269  *
270  *	return trace_handle_return(s);
271  * -------
272  *  }
273  *
274  * This is the method used to print the raw event to the trace
275  * output format. Note, this is not needed if the data is read
276  * in binary.
277  */
278 
279 #undef __entry
280 #define __entry field
281 
282 #undef TP_printk
283 #define TP_printk(fmt, args...) fmt "\n", args
284 
285 #undef __get_dynamic_array
286 #define __get_dynamic_array(field)	\
287 		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
288 
289 #undef __get_dynamic_array_len
290 #define __get_dynamic_array_len(field)	\
291 		((__entry->__data_loc_##field >> 16) & 0xffff)
292 
293 #undef __get_str
294 #define __get_str(field) ((char *)__get_dynamic_array(field))
295 
296 #undef __get_bitmask
297 #define __get_bitmask(field)						\
298 	({								\
299 		void *__bitmask = __get_dynamic_array(field);		\
300 		unsigned int __bitmask_size;				\
301 		__bitmask_size = __get_dynamic_array_len(field);	\
302 		trace_print_bitmask_seq(p, __bitmask, __bitmask_size);	\
303 	})
304 
305 #undef __print_flags
306 #define __print_flags(flag, delim, flag_array...)			\
307 	({								\
308 		static const struct trace_print_flags __flags[] =	\
309 			{ flag_array, { -1, NULL }};			\
310 		trace_print_flags_seq(p, delim, flag, __flags);	\
311 	})
312 
313 #undef __print_symbolic
314 #define __print_symbolic(value, symbol_array...)			\
315 	({								\
316 		static const struct trace_print_flags symbols[] =	\
317 			{ symbol_array, { -1, NULL }};			\
318 		trace_print_symbols_seq(p, value, symbols);		\
319 	})
320 
321 #undef __print_flags_u64
322 #undef __print_symbolic_u64
323 #if BITS_PER_LONG == 32
324 #define __print_flags_u64(flag, delim, flag_array...)			\
325 	({								\
326 		static const struct trace_print_flags_u64 __flags[] =	\
327 			{ flag_array, { -1, NULL } };			\
328 		trace_print_flags_seq_u64(p, delim, flag, __flags);	\
329 	})
330 
331 #define __print_symbolic_u64(value, symbol_array...)			\
332 	({								\
333 		static const struct trace_print_flags_u64 symbols[] =	\
334 			{ symbol_array, { -1, NULL } };			\
335 		trace_print_symbols_seq_u64(p, value, symbols);	\
336 	})
337 #else
338 #define __print_flags_u64(flag, delim, flag_array...)			\
339 			__print_flags(flag, delim, flag_array)
340 
341 #define __print_symbolic_u64(value, symbol_array...)			\
342 			__print_symbolic(value, symbol_array)
343 #endif
344 
345 #undef __print_hex
346 #define __print_hex(buf, buf_len)					\
347 	trace_print_hex_seq(p, buf, buf_len, false)
348 
349 #undef __print_hex_str
350 #define __print_hex_str(buf, buf_len)					\
351 	trace_print_hex_seq(p, buf, buf_len, true)
352 
353 #undef __print_array
354 #define __print_array(array, count, el_size)				\
355 	({								\
356 		BUILD_BUG_ON(el_size != 1 && el_size != 2 &&		\
357 			     el_size != 4 && el_size != 8);		\
358 		trace_print_array_seq(p, array, count, el_size);	\
359 	})
360 
361 #undef __print_hex_dump
362 #define __print_hex_dump(prefix_str, prefix_type,			\
363 			 rowsize, groupsize, buf, len, ascii)		\
364 	trace_print_hex_dump_seq(p, prefix_str, prefix_type,		\
365 				 rowsize, groupsize, buf, len, ascii)
366 
367 #undef __print_ns_to_secs
368 #define __print_ns_to_secs(value)			\
369 	({						\
370 		u64 ____val = (u64)(value);		\
371 		do_div(____val, NSEC_PER_SEC);		\
372 		____val;				\
373 	})
374 
375 #undef __print_ns_without_secs
376 #define __print_ns_without_secs(value)			\
377 	({						\
378 		u64 ____val = (u64)(value);		\
379 		(u32) do_div(____val, NSEC_PER_SEC);	\
380 	})
381 
382 #undef DECLARE_EVENT_CLASS
383 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
384 static notrace enum print_line_t					\
385 trace_raw_output_##call(struct trace_iterator *iter, int flags,		\
386 			struct trace_event *trace_event)		\
387 {									\
388 	struct trace_seq *s = &iter->seq;				\
389 	struct trace_seq __maybe_unused *p = &iter->tmp_seq;		\
390 	struct trace_event_raw_##call *field;				\
391 	int ret;							\
392 									\
393 	field = (typeof(field))iter->ent;				\
394 									\
395 	ret = trace_raw_output_prep(iter, trace_event);			\
396 	if (ret != TRACE_TYPE_HANDLED)					\
397 		return ret;						\
398 									\
399 	trace_event_printf(iter, print);				\
400 									\
401 	return trace_handle_return(s);					\
402 }									\
403 static struct trace_event_functions trace_event_type_funcs_##call = {	\
404 	.trace			= trace_raw_output_##call,		\
405 };
406 
407 #undef DEFINE_EVENT_PRINT
408 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)		\
409 static notrace enum print_line_t					\
410 trace_raw_output_##call(struct trace_iterator *iter, int flags,		\
411 			 struct trace_event *event)			\
412 {									\
413 	struct trace_event_raw_##template *field;			\
414 	struct trace_entry *entry;					\
415 	struct trace_seq *p = &iter->tmp_seq;				\
416 									\
417 	entry = iter->ent;						\
418 									\
419 	if (entry->type != event_##call.event.type) {			\
420 		WARN_ON_ONCE(1);					\
421 		return TRACE_TYPE_UNHANDLED;				\
422 	}								\
423 									\
424 	field = (typeof(field))entry;					\
425 									\
426 	trace_seq_init(p);						\
427 	return trace_output_call(iter, #call, print);			\
428 }									\
429 static struct trace_event_functions trace_event_type_funcs_##call = {	\
430 	.trace			= trace_raw_output_##call,		\
431 };
432 
433 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
434 
435 #undef __field_ext
436 #define __field_ext(_type, _item, _filter_type) {			\
437 	.type = #_type, .name = #_item,					\
438 	.size = sizeof(_type), .align = __alignof__(_type),		\
439 	.is_signed = is_signed_type(_type), .filter_type = _filter_type },
440 
441 #undef __field_struct_ext
442 #define __field_struct_ext(_type, _item, _filter_type) {		\
443 	.type = #_type, .name = #_item,					\
444 	.size = sizeof(_type), .align = __alignof__(_type),		\
445 	0, .filter_type = _filter_type },
446 
447 #undef __field
448 #define __field(type, item)	__field_ext(type, item, FILTER_OTHER)
449 
450 #undef __field_struct
451 #define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
452 
453 #undef __array
454 #define __array(_type, _item, _len) {					\
455 	.type = #_type"["__stringify(_len)"]", .name = #_item,		\
456 	.size = sizeof(_type[_len]), .align = __alignof__(_type),	\
457 	.is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
458 
459 #undef __dynamic_array
460 #define __dynamic_array(_type, _item, _len) {				\
461 	.type = "__data_loc " #_type "[]", .name = #_item,		\
462 	.size = 4, .align = 4,						\
463 	.is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
464 
465 #undef __string
466 #define __string(item, src) __dynamic_array(char, item, -1)
467 
468 #undef __string_len
469 #define __string_len(item, src, len) __dynamic_array(char, item, -1)
470 
471 #undef __bitmask
472 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
473 
474 #undef DECLARE_EVENT_CLASS
475 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print)	\
476 static struct trace_event_fields trace_event_fields_##call[] = {	\
477 	tstruct								\
478 	{} };
479 
480 #undef DEFINE_EVENT_PRINT
481 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
482 
483 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
484 
485 /*
486  * remember the offset of each array from the beginning of the event.
487  */
488 
489 #undef __entry
490 #define __entry entry
491 
492 #undef __field
493 #define __field(type, item)
494 
495 #undef __field_ext
496 #define __field_ext(type, item, filter_type)
497 
498 #undef __field_struct
499 #define __field_struct(type, item)
500 
501 #undef __field_struct_ext
502 #define __field_struct_ext(type, item, filter_type)
503 
504 #undef __array
505 #define __array(type, item, len)
506 
507 #undef __dynamic_array
508 #define __dynamic_array(type, item, len)				\
509 	__item_length = (len) * sizeof(type);				\
510 	__data_offsets->item = __data_size +				\
511 			       offsetof(typeof(*entry), __data);	\
512 	__data_offsets->item |= __item_length << 16;			\
513 	__data_size += __item_length;
514 
515 #undef __string
516 #define __string(item, src) __dynamic_array(char, item,			\
517 		    strlen((src) ? (const char *)(src) : "(null)") + 1)
518 
519 #undef __string_len
520 #define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
521 
522 /*
523  * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
524  * num_possible_cpus().
525  */
526 #define __bitmask_size_in_bytes_raw(nr_bits)	\
527 	(((nr_bits) + 7) / 8)
528 
529 #define __bitmask_size_in_longs(nr_bits)			\
530 	((__bitmask_size_in_bytes_raw(nr_bits) +		\
531 	  ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
532 
533 /*
534  * __bitmask_size_in_bytes is the number of bytes needed to hold
535  * num_possible_cpus() padded out to the nearest long. This is what
536  * is saved in the buffer, just to be consistent.
537  */
538 #define __bitmask_size_in_bytes(nr_bits)				\
539 	(__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
540 
541 #undef __bitmask
542 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item,	\
543 					 __bitmask_size_in_longs(nr_bits))
544 
545 #undef DECLARE_EVENT_CLASS
546 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
547 static inline notrace int trace_event_get_offsets_##call(		\
548 	struct trace_event_data_offsets_##call *__data_offsets, proto)	\
549 {									\
550 	int __data_size = 0;						\
551 	int __maybe_unused __item_length;				\
552 	struct trace_event_raw_##call __maybe_unused *entry;		\
553 									\
554 	tstruct;							\
555 									\
556 	return __data_size;						\
557 }
558 
559 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
560 
561 /*
562  * Stage 4 of the trace events.
563  *
564  * Override the macros in the event tracepoint header <trace/events/XXX.h>
565  * to include the following:
566  *
567  * For those macros defined with TRACE_EVENT:
568  *
569  * static struct trace_event_call event_<call>;
570  *
571  * static void trace_event_raw_event_<call>(void *__data, proto)
572  * {
573  *	struct trace_event_file *trace_file = __data;
574  *	struct trace_event_call *event_call = trace_file->event_call;
575  *	struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
576  *	unsigned long eflags = trace_file->flags;
577  *	enum event_trigger_type __tt = ETT_NONE;
578  *	struct ring_buffer_event *event;
579  *	struct trace_event_raw_<call> *entry; <-- defined in stage 1
580  *	struct trace_buffer *buffer;
581  *	unsigned long irq_flags;
582  *	int __data_size;
583  *	int pc;
584  *
585  *	if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
586  *		if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
587  *			event_triggers_call(trace_file, NULL);
588  *		if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
589  *			return;
590  *	}
591  *
592  *	local_save_flags(irq_flags);
593  *	pc = preempt_count();
594  *
595  *	__data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
596  *
597  *	event = trace_event_buffer_lock_reserve(&buffer, trace_file,
598  *				  event_<call>->event.type,
599  *				  sizeof(*entry) + __data_size,
600  *				  irq_flags, pc);
601  *	if (!event)
602  *		return;
603  *	entry	= ring_buffer_event_data(event);
604  *
605  *	{ <assign>; }  <-- Here we assign the entries by the __field and
606  *			   __array macros.
607  *
608  *	if (eflags & EVENT_FILE_FL_TRIGGER_COND)
609  *		__tt = event_triggers_call(trace_file, entry);
610  *
611  *	if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
612  *		     &trace_file->flags))
613  *		ring_buffer_discard_commit(buffer, event);
614  *	else if (!filter_check_discard(trace_file, entry, buffer, event))
615  *		trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
616  *
617  *	if (__tt)
618  *		event_triggers_post_call(trace_file, __tt);
619  * }
620  *
621  * static struct trace_event ftrace_event_type_<call> = {
622  *	.trace			= trace_raw_output_<call>, <-- stage 2
623  * };
624  *
625  * static char print_fmt_<call>[] = <TP_printk>;
626  *
627  * static struct trace_event_class __used event_class_<template> = {
628  *	.system			= "<system>",
629  *	.fields_array		= trace_event_fields_<call>,
630  *	.fields			= LIST_HEAD_INIT(event_class_##call.fields),
631  *	.raw_init		= trace_event_raw_init,
632  *	.probe			= trace_event_raw_event_##call,
633  *	.reg			= trace_event_reg,
634  * };
635  *
636  * static struct trace_event_call event_<call> = {
637  *	.class			= event_class_<template>,
638  *	{
639  *		.tp			= &__tracepoint_<call>,
640  *	},
641  *	.event			= &ftrace_event_type_<call>,
642  *	.print_fmt		= print_fmt_<call>,
643  *	.flags			= TRACE_EVENT_FL_TRACEPOINT,
644  * };
645  * // its only safe to use pointers when doing linker tricks to
646  * // create an array.
647  * static struct trace_event_call __used
648  * __section("_ftrace_events") *__event_<call> = &event_<call>;
649  *
650  */
651 
652 #ifdef CONFIG_PERF_EVENTS
653 
654 #define _TRACE_PERF_PROTO(call, proto)					\
655 	static notrace void						\
656 	perf_trace_##call(void *__data, proto);
657 
658 #define _TRACE_PERF_INIT(call)						\
659 	.perf_probe		= perf_trace_##call,
660 
661 #else
662 #define _TRACE_PERF_PROTO(call, proto)
663 #define _TRACE_PERF_INIT(call)
664 #endif /* CONFIG_PERF_EVENTS */
665 
666 #undef __entry
667 #define __entry entry
668 
669 #undef __field
670 #define __field(type, item)
671 
672 #undef __field_struct
673 #define __field_struct(type, item)
674 
675 #undef __array
676 #define __array(type, item, len)
677 
678 #undef __dynamic_array
679 #define __dynamic_array(type, item, len)				\
680 	__entry->__data_loc_##item = __data_offsets.item;
681 
682 #undef __string
683 #define __string(item, src) __dynamic_array(char, item, -1)
684 
685 #undef __string_len
686 #define __string_len(item, src, len) __dynamic_array(char, item, -1)
687 
688 #undef __assign_str
689 #define __assign_str(dst, src)						\
690 	strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
691 
692 #undef __assign_str_len
693 #define __assign_str_len(dst, src, len)					\
694 	do {								\
695 		memcpy(__get_str(dst), (src), (len));			\
696 		__get_str(dst)[len] = '\0';				\
697 	} while(0)
698 
699 #undef __bitmask
700 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
701 
702 #undef __get_bitmask
703 #define __get_bitmask(field) (char *)__get_dynamic_array(field)
704 
705 #undef __assign_bitmask
706 #define __assign_bitmask(dst, src, nr_bits)					\
707 	memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
708 
709 #undef TP_fast_assign
710 #define TP_fast_assign(args...) args
711 
712 #undef __perf_count
713 #define __perf_count(c)	(c)
714 
715 #undef __perf_task
716 #define __perf_task(t)	(t)
717 
718 #undef DECLARE_EVENT_CLASS
719 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
720 									\
721 static notrace void							\
722 trace_event_raw_event_##call(void *__data, proto)			\
723 {									\
724 	struct trace_event_file *trace_file = __data;			\
725 	struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
726 	struct trace_event_buffer fbuffer;				\
727 	struct trace_event_raw_##call *entry;				\
728 	int __data_size;						\
729 									\
730 	if (trace_trigger_soft_disabled(trace_file))			\
731 		return;							\
732 									\
733 	__data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
734 									\
735 	entry = trace_event_buffer_reserve(&fbuffer, trace_file,	\
736 				 sizeof(*entry) + __data_size);		\
737 									\
738 	if (!entry)							\
739 		return;							\
740 									\
741 	tstruct								\
742 									\
743 	{ assign; }							\
744 									\
745 	trace_event_buffer_commit(&fbuffer);				\
746 }
747 /*
748  * The ftrace_test_probe is compiled out, it is only here as a build time check
749  * to make sure that if the tracepoint handling changes, the ftrace probe will
750  * fail to compile unless it too is updated.
751  */
752 
753 #undef DEFINE_EVENT
754 #define DEFINE_EVENT(template, call, proto, args)			\
755 static inline void ftrace_test_probe_##call(void)			\
756 {									\
757 	check_trace_callback_type_##call(trace_event_raw_event_##template); \
758 }
759 
760 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
761 
762 #undef __entry
763 #define __entry REC
764 
765 #undef __print_flags
766 #undef __print_symbolic
767 #undef __print_hex
768 #undef __print_hex_str
769 #undef __get_dynamic_array
770 #undef __get_dynamic_array_len
771 #undef __get_str
772 #undef __get_bitmask
773 #undef __print_array
774 #undef __print_hex_dump
775 
776 /*
777  * The below is not executed in the kernel. It is only what is
778  * displayed in the print format for userspace to parse.
779  */
780 #undef __print_ns_to_secs
781 #define __print_ns_to_secs(val) (val) / 1000000000UL
782 
783 #undef __print_ns_without_secs
784 #define __print_ns_without_secs(val) (val) % 1000000000UL
785 
786 #undef TP_printk
787 #define TP_printk(fmt, args...) "\"" fmt "\", "  __stringify(args)
788 
789 #undef DECLARE_EVENT_CLASS
790 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
791 _TRACE_PERF_PROTO(call, PARAMS(proto));					\
792 static char print_fmt_##call[] = print;					\
793 static struct trace_event_class __used __refdata event_class_##call = { \
794 	.system			= TRACE_SYSTEM_STRING,			\
795 	.fields_array		= trace_event_fields_##call,		\
796 	.fields			= LIST_HEAD_INIT(event_class_##call.fields),\
797 	.raw_init		= trace_event_raw_init,			\
798 	.probe			= trace_event_raw_event_##call,		\
799 	.reg			= trace_event_reg,			\
800 	_TRACE_PERF_INIT(call)						\
801 };
802 
803 #undef DEFINE_EVENT
804 #define DEFINE_EVENT(template, call, proto, args)			\
805 									\
806 static struct trace_event_call __used event_##call = {			\
807 	.class			= &event_class_##template,		\
808 	{								\
809 		.tp			= &__tracepoint_##call,		\
810 	},								\
811 	.event.funcs		= &trace_event_type_funcs_##template,	\
812 	.print_fmt		= print_fmt_##template,			\
813 	.flags			= TRACE_EVENT_FL_TRACEPOINT,		\
814 };									\
815 static struct trace_event_call __used					\
816 __section("_ftrace_events") *__event_##call = &event_##call
817 
818 #undef DEFINE_EVENT_PRINT
819 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)		\
820 									\
821 static char print_fmt_##call[] = print;					\
822 									\
823 static struct trace_event_call __used event_##call = {			\
824 	.class			= &event_class_##template,		\
825 	{								\
826 		.tp			= &__tracepoint_##call,		\
827 	},								\
828 	.event.funcs		= &trace_event_type_funcs_##call,	\
829 	.print_fmt		= print_fmt_##call,			\
830 	.flags			= TRACE_EVENT_FL_TRACEPOINT,		\
831 };									\
832 static struct trace_event_call __used					\
833 __section("_ftrace_events") *__event_##call = &event_##call
834 
835 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
836