• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 __sockaddr
112 #define __sockaddr(field, len) __dynamic_array(u8, field, len)
113 
114 #undef __rel_dynamic_array
115 #define __rel_dynamic_array(type, item, len) u32 __rel_loc_##item;
116 
117 #undef __rel_string
118 #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
119 
120 #undef __rel_string_len
121 #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
122 
123 #undef __rel_bitmask
124 #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(char, item, -1)
125 
126 #undef __rel_sockaddr
127 #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
128 
129 #undef TP_STRUCT__entry
130 #define TP_STRUCT__entry(args...) args
131 
132 #undef DECLARE_EVENT_CLASS
133 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)	\
134 	struct trace_event_raw_##name {					\
135 		struct trace_entry	ent;				\
136 		tstruct							\
137 		char			__data[];			\
138 	};								\
139 									\
140 	static struct trace_event_class event_class_##name;
141 
142 #undef DEFINE_EVENT
143 #define DEFINE_EVENT(template, name, proto, args)	\
144 	static struct trace_event_call	__used		\
145 	__attribute__((__aligned__(4))) event_##name
146 
147 #undef DEFINE_EVENT_FN
148 #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)	\
149 	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
150 
151 #undef DEFINE_EVENT_PRINT
152 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
153 	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
154 
155 /* Callbacks are meaningless to ftrace. */
156 #undef TRACE_EVENT_FN
157 #define TRACE_EVENT_FN(name, proto, args, tstruct,			\
158 		assign, print, reg, unreg)				\
159 	TRACE_EVENT(name, PARAMS(proto), PARAMS(args),			\
160 		PARAMS(tstruct), PARAMS(assign), PARAMS(print))		\
161 
162 #undef TRACE_EVENT_FN_COND
163 #define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct,	\
164 		assign, print, reg, unreg)				\
165 	TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond),		\
166 		PARAMS(tstruct), PARAMS(assign), PARAMS(print))		\
167 
168 #undef TRACE_EVENT_FLAGS
169 #define TRACE_EVENT_FLAGS(name, value)					\
170 	__TRACE_EVENT_FLAGS(name, value)
171 
172 #undef TRACE_EVENT_PERF_PERM
173 #define TRACE_EVENT_PERF_PERM(name, expr...)				\
174 	__TRACE_EVENT_PERF_PERM(name, expr)
175 
176 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
177 
178 /*
179  * Stage 2 of the trace events.
180  *
181  * Include the following:
182  *
183  * struct trace_event_data_offsets_<call> {
184  *	u32				<item1>;
185  *	u32				<item2>;
186  *	[...]
187  * };
188  *
189  * The __dynamic_array() macro will create each u32 <item>, this is
190  * to keep the offset of each array from the beginning of the event.
191  * The size of an array is also encoded, in the higher 16 bits of <item>.
192  */
193 
194 #undef TRACE_DEFINE_ENUM
195 #define TRACE_DEFINE_ENUM(a)
196 
197 #undef TRACE_DEFINE_SIZEOF
198 #define TRACE_DEFINE_SIZEOF(a)
199 
200 #undef __field
201 #define __field(type, item)
202 
203 #undef __field_ext
204 #define __field_ext(type, item, filter_type)
205 
206 #undef __field_struct
207 #define __field_struct(type, item)
208 
209 #undef __field_struct_ext
210 #define __field_struct_ext(type, item, filter_type)
211 
212 #undef __array
213 #define __array(type, item, len)
214 
215 #undef __dynamic_array
216 #define __dynamic_array(type, item, len)	u32 item;
217 
218 #undef __string
219 #define __string(item, src) __dynamic_array(char, item, -1)
220 
221 #undef __string_len
222 #define __string_len(item, src, len) __dynamic_array(char, item, -1)
223 
224 #undef __bitmask
225 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
226 
227 #undef __sockaddr
228 #define __sockaddr(field, len) __dynamic_array(u8, field, len)
229 
230 #undef __rel_dynamic_array
231 #define __rel_dynamic_array(type, item, len)	u32 item;
232 
233 #undef __rel_string
234 #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
235 
236 #undef __rel_string_len
237 #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
238 
239 #undef __rel_bitmask
240 #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
241 
242 #undef __rel_sockaddr
243 #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
244 
245 #undef DECLARE_EVENT_CLASS
246 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
247 	struct trace_event_data_offsets_##call {			\
248 		tstruct;						\
249 	};
250 
251 #undef DEFINE_EVENT
252 #define DEFINE_EVENT(template, name, proto, args)
253 
254 #undef DEFINE_EVENT_PRINT
255 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
256 
257 #undef TRACE_EVENT_FLAGS
258 #define TRACE_EVENT_FLAGS(event, flag)
259 
260 #undef TRACE_EVENT_PERF_PERM
261 #define TRACE_EVENT_PERF_PERM(event, expr...)
262 
263 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
264 
265 /*
266  * Stage 3 of the trace events.
267  *
268  * Override the macros in the event tracepoint header <trace/events/XXX.h>
269  * to include the following:
270  *
271  * enum print_line_t
272  * trace_raw_output_<call>(struct trace_iterator *iter, int flags)
273  * {
274  *	struct trace_seq *s = &iter->seq;
275  *	struct trace_event_raw_<call> *field; <-- defined in stage 1
276  *	struct trace_seq *p = &iter->tmp_seq;
277  *
278  * -------(for event)-------
279  *
280  *	struct trace_entry *entry;
281  *
282  *	entry = iter->ent;
283  *
284  *	if (entry->type != event_<call>->event.type) {
285  *		WARN_ON_ONCE(1);
286  *		return TRACE_TYPE_UNHANDLED;
287  *	}
288  *
289  *	field = (typeof(field))entry;
290  *
291  *	trace_seq_init(p);
292  *	return trace_output_call(iter, <call>, <TP_printk> "\n");
293  *
294  * ------(or, for event class)------
295  *
296  *	int ret;
297  *
298  *	field = (typeof(field))iter->ent;
299  *
300  *	ret = trace_raw_output_prep(iter, trace_event);
301  *	if (ret != TRACE_TYPE_HANDLED)
302  *		return ret;
303  *
304  *	trace_event_printf(iter, <TP_printk> "\n");
305  *
306  *	return trace_handle_return(s);
307  * -------
308  *  }
309  *
310  * This is the method used to print the raw event to the trace
311  * output format. Note, this is not needed if the data is read
312  * in binary.
313  */
314 
315 #undef __entry
316 #define __entry field
317 
318 #undef TP_printk
319 #define TP_printk(fmt, args...) fmt "\n", args
320 
321 #undef __get_dynamic_array
322 #define __get_dynamic_array(field)	\
323 		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
324 
325 #undef __get_dynamic_array_len
326 #define __get_dynamic_array_len(field)	\
327 		((__entry->__data_loc_##field >> 16) & 0xffff)
328 
329 #undef __get_str
330 #define __get_str(field) ((char *)__get_dynamic_array(field))
331 
332 #undef __get_rel_dynamic_array
333 #define __get_rel_dynamic_array(field)					\
334 		((void *)__entry + 					\
335 		 offsetof(typeof(*__entry), __rel_loc_##field) +	\
336 		 sizeof(__entry->__rel_loc_##field) +			\
337 		 (__entry->__rel_loc_##field & 0xffff))
338 
339 #undef __get_rel_dynamic_array_len
340 #define __get_rel_dynamic_array_len(field)	\
341 		((__entry->__rel_loc_##field >> 16) & 0xffff)
342 
343 #undef __get_rel_str
344 #define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field))
345 
346 #undef __get_bitmask
347 #define __get_bitmask(field)						\
348 	({								\
349 		void *__bitmask = __get_dynamic_array(field);		\
350 		unsigned int __bitmask_size;				\
351 		__bitmask_size = __get_dynamic_array_len(field);	\
352 		trace_print_bitmask_seq(p, __bitmask, __bitmask_size);	\
353 	})
354 
355 #undef __get_rel_bitmask
356 #define __get_rel_bitmask(field)						\
357 	({								\
358 		void *__bitmask = __get_rel_dynamic_array(field);		\
359 		unsigned int __bitmask_size;				\
360 		__bitmask_size = __get_rel_dynamic_array_len(field);	\
361 		trace_print_bitmask_seq(p, __bitmask, __bitmask_size);	\
362 	})
363 
364 #undef __get_sockaddr
365 #define __get_sockaddr(field)	((struct sockaddr *)__get_dynamic_array(field))
366 
367 #undef __get_rel_sockaddr
368 #define __get_rel_sockaddr(field)	((struct sockaddr *)__get_rel_dynamic_array(field))
369 
370 #undef __print_flags
371 #define __print_flags(flag, delim, flag_array...)			\
372 	({								\
373 		static const struct trace_print_flags __flags[] =	\
374 			{ flag_array, { -1, NULL }};			\
375 		trace_print_flags_seq(p, delim, flag, __flags);	\
376 	})
377 
378 #undef __print_symbolic
379 #define __print_symbolic(value, symbol_array...)			\
380 	({								\
381 		static const struct trace_print_flags symbols[] =	\
382 			{ symbol_array, { -1, NULL }};			\
383 		trace_print_symbols_seq(p, value, symbols);		\
384 	})
385 
386 #undef __print_flags_u64
387 #undef __print_symbolic_u64
388 #if BITS_PER_LONG == 32
389 #define __print_flags_u64(flag, delim, flag_array...)			\
390 	({								\
391 		static const struct trace_print_flags_u64 __flags[] =	\
392 			{ flag_array, { -1, NULL } };			\
393 		trace_print_flags_seq_u64(p, delim, flag, __flags);	\
394 	})
395 
396 #define __print_symbolic_u64(value, symbol_array...)			\
397 	({								\
398 		static const struct trace_print_flags_u64 symbols[] =	\
399 			{ symbol_array, { -1, NULL } };			\
400 		trace_print_symbols_seq_u64(p, value, symbols);	\
401 	})
402 #else
403 #define __print_flags_u64(flag, delim, flag_array...)			\
404 			__print_flags(flag, delim, flag_array)
405 
406 #define __print_symbolic_u64(value, symbol_array...)			\
407 			__print_symbolic(value, symbol_array)
408 #endif
409 
410 #undef __print_hex
411 #define __print_hex(buf, buf_len)					\
412 	trace_print_hex_seq(p, buf, buf_len, false)
413 
414 #undef __print_hex_str
415 #define __print_hex_str(buf, buf_len)					\
416 	trace_print_hex_seq(p, buf, buf_len, true)
417 
418 #undef __print_array
419 #define __print_array(array, count, el_size)				\
420 	({								\
421 		BUILD_BUG_ON(el_size != 1 && el_size != 2 &&		\
422 			     el_size != 4 && el_size != 8);		\
423 		trace_print_array_seq(p, array, count, el_size);	\
424 	})
425 
426 #undef __print_hex_dump
427 #define __print_hex_dump(prefix_str, prefix_type,			\
428 			 rowsize, groupsize, buf, len, ascii)		\
429 	trace_print_hex_dump_seq(p, prefix_str, prefix_type,		\
430 				 rowsize, groupsize, buf, len, ascii)
431 
432 #undef __print_ns_to_secs
433 #define __print_ns_to_secs(value)			\
434 	({						\
435 		u64 ____val = (u64)(value);		\
436 		do_div(____val, NSEC_PER_SEC);		\
437 		____val;				\
438 	})
439 
440 #undef __print_ns_without_secs
441 #define __print_ns_without_secs(value)			\
442 	({						\
443 		u64 ____val = (u64)(value);		\
444 		(u32) do_div(____val, NSEC_PER_SEC);	\
445 	})
446 
447 #undef DECLARE_EVENT_CLASS
448 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
449 static notrace enum print_line_t					\
450 trace_raw_output_##call(struct trace_iterator *iter, int flags,		\
451 			struct trace_event *trace_event)		\
452 {									\
453 	struct trace_seq *s = &iter->seq;				\
454 	struct trace_seq __maybe_unused *p = &iter->tmp_seq;		\
455 	struct trace_event_raw_##call *field;				\
456 	int ret;							\
457 									\
458 	field = (typeof(field))iter->ent;				\
459 									\
460 	ret = trace_raw_output_prep(iter, trace_event);			\
461 	if (ret != TRACE_TYPE_HANDLED)					\
462 		return ret;						\
463 									\
464 	trace_event_printf(iter, print);				\
465 									\
466 	return trace_handle_return(s);					\
467 }									\
468 static struct trace_event_functions trace_event_type_funcs_##call = {	\
469 	.trace			= trace_raw_output_##call,		\
470 };
471 
472 #undef DEFINE_EVENT_PRINT
473 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)		\
474 static notrace enum print_line_t					\
475 trace_raw_output_##call(struct trace_iterator *iter, int flags,		\
476 			 struct trace_event *event)			\
477 {									\
478 	struct trace_event_raw_##template *field;			\
479 	struct trace_entry *entry;					\
480 	struct trace_seq *p = &iter->tmp_seq;				\
481 									\
482 	entry = iter->ent;						\
483 									\
484 	if (entry->type != event_##call.event.type) {			\
485 		WARN_ON_ONCE(1);					\
486 		return TRACE_TYPE_UNHANDLED;				\
487 	}								\
488 									\
489 	field = (typeof(field))entry;					\
490 									\
491 	trace_seq_init(p);						\
492 	return trace_output_call(iter, #call, print);			\
493 }									\
494 static struct trace_event_functions trace_event_type_funcs_##call = {	\
495 	.trace			= trace_raw_output_##call,		\
496 };
497 
498 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
499 
500 #define ALIGN_STRUCTFIELD(type) ((int)(__alignof__(struct {type b;})))
501 
502 #undef __field_ext
503 #define __field_ext(_type, _item, _filter_type) {			\
504 	.type = #_type, .name = #_item,					\
505 	.size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type),	\
506 	.is_signed = is_signed_type(_type), .filter_type = _filter_type },
507 
508 #undef __field_struct_ext
509 #define __field_struct_ext(_type, _item, _filter_type) {		\
510 	.type = #_type, .name = #_item,					\
511 	.size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type),	\
512 	0, .filter_type = _filter_type },
513 
514 #undef __field
515 #define __field(type, item)	__field_ext(type, item, FILTER_OTHER)
516 
517 #undef __field_struct
518 #define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
519 
520 #undef __array
521 #define __array(_type, _item, _len) {					\
522 	.type = #_type"["__stringify(_len)"]", .name = #_item,		\
523 	.size = sizeof(_type[_len]), .align = ALIGN_STRUCTFIELD(_type),	\
524 	.is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
525 
526 #undef __dynamic_array
527 #define __dynamic_array(_type, _item, _len) {				\
528 	.type = "__data_loc " #_type "[]", .name = #_item,		\
529 	.size = 4, .align = 4,						\
530 	.is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
531 
532 #undef __string
533 #define __string(item, src) __dynamic_array(char, item, -1)
534 
535 #undef __string_len
536 #define __string_len(item, src, len) __dynamic_array(char, item, -1)
537 
538 #undef __bitmask
539 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
540 
541 #undef __sockaddr
542 #define __sockaddr(field, len) __dynamic_array(u8, field, len)
543 
544 #undef __rel_dynamic_array
545 #define __rel_dynamic_array(_type, _item, _len) {			\
546 	.type = "__rel_loc " #_type "[]", .name = #_item,		\
547 	.size = 4, .align = 4,						\
548 	.is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
549 
550 #undef __rel_string
551 #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
552 
553 #undef __rel_string_len
554 #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
555 
556 #undef __rel_bitmask
557 #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
558 
559 #undef __rel_sockaddr
560 #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
561 
562 #undef DECLARE_EVENT_CLASS
563 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print)	\
564 static struct trace_event_fields trace_event_fields_##call[] = {	\
565 	tstruct								\
566 	{} };
567 
568 #undef DEFINE_EVENT_PRINT
569 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
570 
571 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
572 
573 /*
574  * remember the offset of each array from the beginning of the event.
575  */
576 
577 #undef __entry
578 #define __entry entry
579 
580 #undef __field
581 #define __field(type, item)
582 
583 #undef __field_ext
584 #define __field_ext(type, item, filter_type)
585 
586 #undef __field_struct
587 #define __field_struct(type, item)
588 
589 #undef __field_struct_ext
590 #define __field_struct_ext(type, item, filter_type)
591 
592 #undef __array
593 #define __array(type, item, len)
594 
595 #undef __dynamic_array
596 #define __dynamic_array(type, item, len)				\
597 	__item_length = (len) * sizeof(type);				\
598 	__data_offsets->item = __data_size +				\
599 			       offsetof(typeof(*entry), __data);	\
600 	__data_offsets->item |= __item_length << 16;			\
601 	__data_size += __item_length;
602 
603 #undef __string
604 #define __string(item, src) __dynamic_array(char, item,			\
605 		    strlen((src) ? (const char *)(src) : "(null)") + 1)
606 
607 #undef __string_len
608 #define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
609 
610 #undef __rel_dynamic_array
611 #define __rel_dynamic_array(type, item, len)				\
612 	__item_length = (len) * sizeof(type);				\
613 	__data_offsets->item = __data_size +				\
614 			       offsetof(typeof(*entry), __data) -	\
615 			       offsetof(typeof(*entry), __rel_loc_##item) -	\
616 			       sizeof(u32);				\
617 	__data_offsets->item |= __item_length << 16;			\
618 	__data_size += __item_length;
619 
620 #undef __rel_string
621 #define __rel_string(item, src) __rel_dynamic_array(char, item,			\
622 		    strlen((src) ? (const char *)(src) : "(null)") + 1)
623 
624 #undef __rel_string_len
625 #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)
626 /*
627  * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
628  * num_possible_cpus().
629  */
630 #define __bitmask_size_in_bytes_raw(nr_bits)	\
631 	(((nr_bits) + 7) / 8)
632 
633 #define __bitmask_size_in_longs(nr_bits)			\
634 	((__bitmask_size_in_bytes_raw(nr_bits) +		\
635 	  ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
636 
637 /*
638  * __bitmask_size_in_bytes is the number of bytes needed to hold
639  * num_possible_cpus() padded out to the nearest long. This is what
640  * is saved in the buffer, just to be consistent.
641  */
642 #define __bitmask_size_in_bytes(nr_bits)				\
643 	(__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
644 
645 #undef __bitmask
646 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item,	\
647 					 __bitmask_size_in_longs(nr_bits))
648 
649 #undef __rel_bitmask
650 #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item,	\
651 					 __bitmask_size_in_longs(nr_bits))
652 
653 #undef __sockaddr
654 #define __sockaddr(field, len) __dynamic_array(u8, field, len)
655 
656 #undef __rel_sockaddr
657 #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
658 
659 #undef DECLARE_EVENT_CLASS
660 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
661 static inline notrace int trace_event_get_offsets_##call(		\
662 	struct trace_event_data_offsets_##call *__data_offsets, proto)	\
663 {									\
664 	int __data_size = 0;						\
665 	int __maybe_unused __item_length;				\
666 	struct trace_event_raw_##call __maybe_unused *entry;		\
667 									\
668 	tstruct;							\
669 									\
670 	return __data_size;						\
671 }
672 
673 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
674 
675 /*
676  * Stage 4 of the trace events.
677  *
678  * Override the macros in the event tracepoint header <trace/events/XXX.h>
679  * to include the following:
680  *
681  * For those macros defined with TRACE_EVENT:
682  *
683  * static struct trace_event_call event_<call>;
684  *
685  * static void trace_event_raw_event_<call>(void *__data, proto)
686  * {
687  *	struct trace_event_file *trace_file = __data;
688  *	struct trace_event_call *event_call = trace_file->event_call;
689  *	struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
690  *	unsigned long eflags = trace_file->flags;
691  *	enum event_trigger_type __tt = ETT_NONE;
692  *	struct ring_buffer_event *event;
693  *	struct trace_event_raw_<call> *entry; <-- defined in stage 1
694  *	struct trace_buffer *buffer;
695  *	unsigned long irq_flags;
696  *	int __data_size;
697  *	int pc;
698  *
699  *	if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
700  *		if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
701  *			event_triggers_call(trace_file, NULL);
702  *		if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
703  *			return;
704  *	}
705  *
706  *	local_save_flags(irq_flags);
707  *	pc = preempt_count();
708  *
709  *	__data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
710  *
711  *	event = trace_event_buffer_lock_reserve(&buffer, trace_file,
712  *				  event_<call>->event.type,
713  *				  sizeof(*entry) + __data_size,
714  *				  irq_flags, pc);
715  *	if (!event)
716  *		return;
717  *	entry	= ring_buffer_event_data(event);
718  *
719  *	{ <assign>; }  <-- Here we assign the entries by the __field and
720  *			   __array macros.
721  *
722  *	if (eflags & EVENT_FILE_FL_TRIGGER_COND)
723  *		__tt = event_triggers_call(trace_file, entry);
724  *
725  *	if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
726  *		     &trace_file->flags))
727  *		ring_buffer_discard_commit(buffer, event);
728  *	else if (!filter_check_discard(trace_file, entry, buffer, event))
729  *		trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
730  *
731  *	if (__tt)
732  *		event_triggers_post_call(trace_file, __tt);
733  * }
734  *
735  * static struct trace_event ftrace_event_type_<call> = {
736  *	.trace			= trace_raw_output_<call>, <-- stage 2
737  * };
738  *
739  * static char print_fmt_<call>[] = <TP_printk>;
740  *
741  * static struct trace_event_class __used event_class_<template> = {
742  *	.system			= "<system>",
743  *	.fields_array		= trace_event_fields_<call>,
744  *	.fields			= LIST_HEAD_INIT(event_class_##call.fields),
745  *	.raw_init		= trace_event_raw_init,
746  *	.probe			= trace_event_raw_event_##call,
747  *	.reg			= trace_event_reg,
748  * };
749  *
750  * static struct trace_event_call event_<call> = {
751  *	.class			= event_class_<template>,
752  *	{
753  *		.tp			= &__tracepoint_<call>,
754  *	},
755  *	.event			= &ftrace_event_type_<call>,
756  *	.print_fmt		= print_fmt_<call>,
757  *	.flags			= TRACE_EVENT_FL_TRACEPOINT,
758  * };
759  * // its only safe to use pointers when doing linker tricks to
760  * // create an array.
761  * static struct trace_event_call __used
762  * __section("_ftrace_events") *__event_<call> = &event_<call>;
763  *
764  */
765 
766 #ifdef CONFIG_PERF_EVENTS
767 
768 #define _TRACE_PERF_PROTO(call, proto)					\
769 	static notrace void						\
770 	perf_trace_##call(void *__data, proto);
771 
772 #define _TRACE_PERF_INIT(call)						\
773 	.perf_probe		= perf_trace_##call,
774 
775 #else
776 #define _TRACE_PERF_PROTO(call, proto)
777 #define _TRACE_PERF_INIT(call)
778 #endif /* CONFIG_PERF_EVENTS */
779 
780 #undef __entry
781 #define __entry entry
782 
783 #undef __field
784 #define __field(type, item)
785 
786 #undef __field_struct
787 #define __field_struct(type, item)
788 
789 #undef __array
790 #define __array(type, item, len)
791 
792 #undef __dynamic_array
793 #define __dynamic_array(type, item, len)				\
794 	__entry->__data_loc_##item = __data_offsets.item;
795 
796 #undef __string
797 #define __string(item, src) __dynamic_array(char, item, -1)
798 
799 #undef __string_len
800 #define __string_len(item, src, len) __dynamic_array(char, item, -1)
801 
802 #undef __assign_str
803 #define __assign_str(dst, src)						\
804 	strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
805 
806 #undef __assign_str_len
807 #define __assign_str_len(dst, src, len)					\
808 	do {								\
809 		memcpy(__get_str(dst), (src), (len));			\
810 		__get_str(dst)[len] = '\0';				\
811 	} while(0)
812 
813 #undef __bitmask
814 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
815 
816 #undef __get_bitmask
817 #define __get_bitmask(field) (char *)__get_dynamic_array(field)
818 
819 #undef __assign_bitmask
820 #define __assign_bitmask(dst, src, nr_bits)					\
821 	memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
822 
823 #undef __sockaddr
824 #define __sockaddr(field, len) __dynamic_array(u8, field, len)
825 
826 #undef __get_sockaddr
827 #define __get_sockaddr(field)	((struct sockaddr *)__get_dynamic_array(field))
828 
829 #define __assign_sockaddr(dest, src, len)					\
830 	memcpy(__get_dynamic_array(dest), src, len)
831 
832 #undef __rel_dynamic_array
833 #define __rel_dynamic_array(type, item, len)				\
834 	__entry->__rel_loc_##item = __data_offsets.item;
835 
836 #undef __rel_string
837 #define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
838 
839 #undef __rel_string_len
840 #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
841 
842 #undef __assign_rel_str
843 #define __assign_rel_str(dst, src)					\
844 	strcpy(__get_rel_str(dst), (src) ? (const char *)(src) : "(null)");
845 
846 #undef __assign_rel_str_len
847 #define __assign_rel_str_len(dst, src, len)				\
848 	do {								\
849 		memcpy(__get_rel_str(dst), (src), (len));		\
850 		__get_rel_str(dst)[len] = '\0';				\
851 	} while (0)
852 
853 #undef __rel_bitmask
854 #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
855 
856 #undef __get_rel_bitmask
857 #define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field)
858 
859 #undef __assign_rel_bitmask
860 #define __assign_rel_bitmask(dst, src, nr_bits)					\
861 	memcpy(__get_rel_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
862 
863 #undef __rel_sockaddr
864 #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
865 
866 #undef __get_rel_sockaddr
867 #define __get_rel_sockaddr(field)	((struct sockaddr *)__get_rel_dynamic_array(field))
868 
869 #define __assign_rel_sockaddr(dest, src, len)					\
870 	memcpy(__get_rel_dynamic_array(dest), src, len)
871 
872 
873 #undef TP_fast_assign
874 #define TP_fast_assign(args...) args
875 
876 #undef __perf_count
877 #define __perf_count(c)	(c)
878 
879 #undef __perf_task
880 #define __perf_task(t)	(t)
881 
882 #undef DECLARE_EVENT_CLASS
883 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
884 									\
885 static notrace void							\
886 trace_event_raw_event_##call(void *__data, proto)			\
887 {									\
888 	struct trace_event_file *trace_file = __data;			\
889 	struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
890 	struct trace_event_buffer fbuffer;				\
891 	struct trace_event_raw_##call *entry;				\
892 	int __data_size;						\
893 									\
894 	if (trace_trigger_soft_disabled(trace_file))			\
895 		return;							\
896 									\
897 	__data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
898 									\
899 	entry = trace_event_buffer_reserve(&fbuffer, trace_file,	\
900 				 sizeof(*entry) + __data_size);		\
901 									\
902 	if (!entry)							\
903 		return;							\
904 									\
905 	tstruct								\
906 									\
907 	{ assign; }							\
908 									\
909 	trace_event_buffer_commit(&fbuffer);				\
910 }
911 /*
912  * The ftrace_test_probe is compiled out, it is only here as a build time check
913  * to make sure that if the tracepoint handling changes, the ftrace probe will
914  * fail to compile unless it too is updated.
915  */
916 
917 #undef DEFINE_EVENT
918 #define DEFINE_EVENT(template, call, proto, args)			\
919 static inline void ftrace_test_probe_##call(void)			\
920 {									\
921 	check_trace_callback_type_##call(trace_event_raw_event_##template); \
922 }
923 
924 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
925 
926 #undef __entry
927 #define __entry REC
928 
929 #undef __print_flags
930 #undef __print_symbolic
931 #undef __print_hex
932 #undef __print_hex_str
933 #undef __get_dynamic_array
934 #undef __get_dynamic_array_len
935 #undef __get_str
936 #undef __get_bitmask
937 #undef __get_sockaddr
938 #undef __get_rel_dynamic_array
939 #undef __get_rel_dynamic_array_len
940 #undef __get_rel_str
941 #undef __get_rel_bitmask
942 #undef __get_rel_sockaddr
943 #undef __print_array
944 #undef __print_hex_dump
945 
946 /*
947  * The below is not executed in the kernel. It is only what is
948  * displayed in the print format for userspace to parse.
949  */
950 #undef __print_ns_to_secs
951 #define __print_ns_to_secs(val) (val) / 1000000000UL
952 
953 #undef __print_ns_without_secs
954 #define __print_ns_without_secs(val) (val) % 1000000000UL
955 
956 #undef TP_printk
957 #define TP_printk(fmt, args...) "\"" fmt "\", "  __stringify(args)
958 
959 #undef DECLARE_EVENT_CLASS
960 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
961 _TRACE_PERF_PROTO(call, PARAMS(proto));					\
962 static char print_fmt_##call[] = print;					\
963 static struct trace_event_class __used __refdata event_class_##call = { \
964 	.system			= TRACE_SYSTEM_STRING,			\
965 	.fields_array		= trace_event_fields_##call,		\
966 	.fields			= LIST_HEAD_INIT(event_class_##call.fields),\
967 	.raw_init		= trace_event_raw_init,			\
968 	.probe			= trace_event_raw_event_##call,		\
969 	.reg			= trace_event_reg,			\
970 	_TRACE_PERF_INIT(call)						\
971 };
972 
973 #undef DEFINE_EVENT
974 #define DEFINE_EVENT(template, call, proto, args)			\
975 									\
976 static struct trace_event_call __used event_##call = {			\
977 	.class			= &event_class_##template,		\
978 	{								\
979 		.tp			= &__tracepoint_##call,		\
980 	},								\
981 	.event.funcs		= &trace_event_type_funcs_##template,	\
982 	.print_fmt		= print_fmt_##template,			\
983 	.flags			= TRACE_EVENT_FL_TRACEPOINT,		\
984 };									\
985 static struct trace_event_call __used					\
986 __section("_ftrace_events") *__event_##call = &event_##call
987 
988 #undef DEFINE_EVENT_PRINT
989 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)		\
990 									\
991 static char print_fmt_##call[] = print;					\
992 									\
993 static struct trace_event_call __used event_##call = {			\
994 	.class			= &event_class_##template,		\
995 	{								\
996 		.tp			= &__tracepoint_##call,		\
997 	},								\
998 	.event.funcs		= &trace_event_type_funcs_##call,	\
999 	.print_fmt		= print_fmt_##call,			\
1000 	.flags			= TRACE_EVENT_FL_TRACEPOINT,		\
1001 };									\
1002 static struct trace_event_call __used					\
1003 __section("_ftrace_events") *__event_##call = &event_##call
1004 
1005 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1006