blob: 8c6f7c43351857905a3dc006a61a0e4b88c352a3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Steven Rostedtf42c85e2009-04-13 12:25:37 -04002/*
3 * Stage 1 of the trace events.
4 *
Hou Pengyangeba12ab2015-03-03 21:48:18 +00005 * Override the macros in the event tracepoint header <trace/events/XXX.h>
6 * to include the following:
Steven Rostedtf42c85e2009-04-13 12:25:37 -04007 *
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -04008 * struct trace_event_raw_<call> {
Steven Rostedtf42c85e2009-04-13 12:25:37 -04009 * 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
Steven Rostedt (Red Hat)af658dc2015-04-29 14:36:05 -040021#include <linux/trace_events.h>
Steven Rostedtf42c85e2009-04-13 12:25:37 -040022
Steven Rostedt (Red Hat)acd388f2015-03-31 14:37:12 -040023#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
36TRACE_MAKE_SYSTEM_STR();
37
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040038#undef TRACE_DEFINE_ENUM
39#define TRACE_DEFINE_ENUM(a) \
Jeremy Linton00f4b652017-05-31 16:56:43 -050040 static struct trace_eval_map __used __initdata \
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040041 __##TRACE_SYSTEM##_##a = \
42 { \
43 .system = TRACE_SYSTEM_STRING, \
Jeremy Linton00f4b652017-05-31 16:56:43 -050044 .eval_string = #a, \
45 .eval_value = a \
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040046 }; \
Jeremy Linton00f4b652017-05-31 16:56:43 -050047 static struct trace_eval_map __used \
Joe Perches33def842020-10-21 19:36:07 -070048 __section("_ftrace_eval_map") \
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040049 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
50
Jeremy Linton4f0dfd72017-05-31 16:56:50 -050051#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 \
Joe Perches33def842020-10-21 19:36:07 -070061 __section("_ftrace_eval_map") \
Jeremy Linton4f0dfd72017-05-31 16:56:50 -050062 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
63
Steven Rostedtff038f52009-11-18 20:27:27 -050064/*
Ingo Molnar091ad362009-11-26 09:04:55 +010065 * DECLARE_EVENT_CLASS can be used to add a generic function
Steven Rostedtff038f52009-11-18 20:27:27 -050066 * 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
Ingo Molnar091ad362009-11-26 09:04:55 +010069 * will map the DECLARE_EVENT_CLASS to the tracepoint.
Steven Rostedtff038f52009-11-18 20:27:27 -050070 *
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) \
Ingo Molnar091ad362009-11-26 09:04:55 +010075 DECLARE_EVENT_CLASS(name, \
Steven Rostedtff038f52009-11-18 20:27:27 -050076 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
Steven Rostedtf42c85e2009-04-13 12:25:37 -040084#undef __field
85#define __field(type, item) type item;
86
Li Zefan43b51ea2009-08-07 10:33:22 +080087#undef __field_ext
88#define __field_ext(type, item, filter_type) type item;
89
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -040090#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
Li Zefan7fcb7c42009-06-01 15:35:46 +080096#undef __array
97#define __array(type, item, len) type item[len];
98
99#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +0800100#define __dynamic_array(type, item, len) u32 __data_loc_##item;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800101
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200102#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800103#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200104
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400105#undef __string_len
106#define __string_len(item, src, len) __dynamic_array(char, item, -1)
107
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400108#undef __bitmask
109#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
110
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900111#undef __rel_dynamic_array
112#define __rel_dynamic_array(type, item, len) u32 __rel_loc_##item;
113
114#undef __rel_string
115#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
116
117#undef __rel_string_len
118#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
119
120#undef __rel_bitmask
121#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(char, item, -1)
122
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400123#undef TP_STRUCT__entry
124#define TP_STRUCT__entry(args...) args
125
Ingo Molnar091ad362009-11-26 09:04:55 +0100126#undef DECLARE_EVENT_CLASS
127#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400128 struct trace_event_raw_##name { \
Steven Rostedtff038f52009-11-18 20:27:27 -0500129 struct trace_entry ent; \
130 tstruct \
131 char __data[0]; \
Steven Rostedt8f082012010-04-20 10:47:33 -0400132 }; \
133 \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400134 static struct trace_event_class event_class_##name;
Steven Rostedt8f082012010-04-20 10:47:33 -0400135
Steven Rostedtff038f52009-11-18 20:27:27 -0500136#undef DEFINE_EVENT
137#define DEFINE_EVENT(template, name, proto, args) \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400138 static struct trace_event_call __used \
Jeff Mahoney86c38a32010-02-24 13:59:23 -0500139 __attribute__((__aligned__(4))) event_##name
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400140
Steven Rostedtf5abaa12013-06-20 11:44:44 -0400141#undef DEFINE_EVENT_FN
142#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
143 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
144
Steven Rostedte5bc9722009-11-18 20:36:26 -0500145#undef DEFINE_EVENT_PRINT
146#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
147 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
148
Josh Stone97419872009-08-24 14:43:13 -0700149/* Callbacks are meaningless to ftrace. */
150#undef TRACE_EVENT_FN
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +0200151#define TRACE_EVENT_FN(name, proto, args, tstruct, \
152 assign, print, reg, unreg) \
Frederic Weisbecker819ce452010-07-20 18:41:24 +0200153 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
154 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
Josh Stone97419872009-08-24 14:43:13 -0700155
Denis Kirjanov27011212015-12-14 23:18:05 +0300156#undef TRACE_EVENT_FN_COND
157#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
158 assign, print, reg, unreg) \
159 TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
160 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
161
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100162#undef TRACE_EVENT_FLAGS
163#define TRACE_EVENT_FLAGS(name, value) \
Frederic Weisbecker53cf810b2010-11-18 02:11:42 +0100164 __TRACE_EVENT_FLAGS(name, value)
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100165
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100166#undef TRACE_EVENT_PERF_PERM
167#define TRACE_EVENT_PERF_PERM(name, expr...) \
168 __TRACE_EVENT_PERF_PERM(name, expr)
169
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400170#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
171
172/*
173 * Stage 2 of the trace events.
174 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200175 * Include the following:
176 *
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400177 * struct trace_event_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +0800178 * u32 <item1>;
179 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200180 * [...]
181 * };
182 *
Li Zefan7d536cb2009-07-16 10:54:02 +0800183 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +0800184 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +0800185 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200186 */
187
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -0400188#undef TRACE_DEFINE_ENUM
189#define TRACE_DEFINE_ENUM(a)
190
Jeremy Linton4f0dfd72017-05-31 16:56:50 -0500191#undef TRACE_DEFINE_SIZEOF
192#define TRACE_DEFINE_SIZEOF(a)
193
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200194#undef __field
Li Zefan43b51ea2009-08-07 10:33:22 +0800195#define __field(type, item)
196
197#undef __field_ext
198#define __field_ext(type, item, filter_type)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200199
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400200#undef __field_struct
201#define __field_struct(type, item)
202
203#undef __field_struct_ext
204#define __field_struct_ext(type, item, filter_type)
205
Li Zefan7fcb7c42009-06-01 15:35:46 +0800206#undef __array
207#define __array(type, item, len)
208
209#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +0800210#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800211
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200212#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800213#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200214
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900215#undef __bitmask
216#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
217
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400218#undef __string_len
219#define __string_len(item, src, len) __dynamic_array(char, item, -1)
220
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900221#undef __rel_dynamic_array
222#define __rel_dynamic_array(type, item, len) u32 item;
223
224#undef __rel_string
225#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
226
227#undef __rel_string_len
228#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
229
230#undef __rel_bitmask
231#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400232
Ingo Molnar091ad362009-11-26 09:04:55 +0100233#undef DECLARE_EVENT_CLASS
234#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400235 struct trace_event_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200236 tstruct; \
237 };
238
Steven Rostedtff038f52009-11-18 20:27:27 -0500239#undef DEFINE_EVENT
240#define DEFINE_EVENT(template, name, proto, args)
241
Steven Rostedte5bc9722009-11-18 20:36:26 -0500242#undef DEFINE_EVENT_PRINT
Wei Yang61df16f2020-06-12 17:28:43 +0800243#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
Steven Rostedte5bc9722009-11-18 20:36:26 -0500244
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100245#undef TRACE_EVENT_FLAGS
246#define TRACE_EVENT_FLAGS(event, flag)
247
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100248#undef TRACE_EVENT_PERF_PERM
249#define TRACE_EVENT_PERF_PERM(event, expr...)
250
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200251#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
252
253/*
254 * Stage 3 of the trace events.
255 *
Hou Pengyangeba12ab2015-03-03 21:48:18 +0000256 * Override the macros in the event tracepoint header <trace/events/XXX.h>
257 * to include the following:
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400258 *
259 * enum print_line_t
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400260 * trace_raw_output_<call>(struct trace_iterator *iter, int flags)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400261 * {
262 * struct trace_seq *s = &iter->seq;
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400263 * struct trace_event_raw_<call> *field; <-- defined in stage 1
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800264 * struct trace_seq *p = &iter->tmp_seq;
Masami Hiramatsu1600cbc2020-10-15 23:55:16 +0900265 *
266 * -------(for event)-------
267 *
268 * struct trace_entry *entry;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400269 *
270 * entry = iter->ent;
271 *
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400272 * if (entry->type != event_<call>->event.type) {
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400273 * WARN_ON_ONCE(1);
274 * return TRACE_TYPE_UNHANDLED;
275 * }
276 *
277 * field = (typeof(field))entry;
278 *
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100279 * trace_seq_init(p);
Masami Hiramatsu1600cbc2020-10-15 23:55:16 +0900280 * return trace_output_call(iter, <call>, <TP_printk> "\n");
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400281 *
Masami Hiramatsu1600cbc2020-10-15 23:55:16 +0900282 * ------(or, for event class)------
283 *
284 * int ret;
285 *
286 * field = (typeof(field))iter->ent;
287 *
288 * ret = trace_raw_output_prep(iter, trace_event);
289 * if (ret != TRACE_TYPE_HANDLED)
290 * return ret;
291 *
292 * trace_event_printf(iter, <TP_printk> "\n");
293 *
294 * return trace_handle_return(s);
295 * -------
296 * }
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400297 *
298 * This is the method used to print the raw event to the trace
299 * output format. Note, this is not needed if the data is read
300 * in binary.
301 */
302
303#undef __entry
304#define __entry field
305
306#undef TP_printk
307#define TP_printk(fmt, args...) fmt "\n", args
308
Li Zefan7fcb7c42009-06-01 15:35:46 +0800309#undef __get_dynamic_array
310#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800311 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800312
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400313#undef __get_dynamic_array_len
314#define __get_dynamic_array_len(field) \
315 ((__entry->__data_loc_##field >> 16) & 0xffff)
316
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200317#undef __get_str
Daniel Bristot de Oliveira934de5f2016-07-01 20:44:34 -0300318#define __get_str(field) ((char *)__get_dynamic_array(field))
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200319
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900320#undef __get_rel_dynamic_array
321#define __get_rel_dynamic_array(field) \
322 ((void *)(&__entry->__rel_loc_##field) + \
323 sizeof(__entry->__rel_loc_##field) + \
324 (__entry->__rel_loc_##field & 0xffff))
325
326#undef __get_rel_dynamic_array_len
327#define __get_rel_dynamic_array_len(field) \
328 ((__entry->__rel_loc_##field >> 16) & 0xffff)
329
330#undef __get_rel_str
331#define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field))
332
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400333#undef __get_bitmask
334#define __get_bitmask(field) \
335 ({ \
336 void *__bitmask = __get_dynamic_array(field); \
337 unsigned int __bitmask_size; \
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400338 __bitmask_size = __get_dynamic_array_len(field); \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400339 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400340 })
341
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900342#undef __get_rel_bitmask
343#define __get_rel_bitmask(field) \
344 ({ \
345 void *__bitmask = __get_rel_dynamic_array(field); \
346 unsigned int __bitmask_size; \
347 __bitmask_size = __get_rel_dynamic_array_len(field); \
348 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
349 })
350
Steven Rostedtbe74b732009-05-26 20:25:22 +0200351#undef __print_flags
352#define __print_flags(flag, delim, flag_array...) \
353 ({ \
Steven Rostedta48f4942009-09-14 11:18:02 -0400354 static const struct trace_print_flags __flags[] = \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200355 { flag_array, { -1, NULL }}; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400356 trace_print_flags_seq(p, delim, flag, __flags); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200357 })
358
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400359#undef __print_symbolic
360#define __print_symbolic(value, symbol_array...) \
361 ({ \
362 static const struct trace_print_flags symbols[] = \
363 { symbol_array, { -1, NULL }}; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400364 trace_print_symbols_seq(p, value, symbols); \
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400365 })
366
Ross Zwislerd3213e82017-02-22 15:39:47 -0800367#undef __print_flags_u64
liubo2fc1b6f2011-04-19 09:35:28 +0800368#undef __print_symbolic_u64
369#if BITS_PER_LONG == 32
Ross Zwislerd3213e82017-02-22 15:39:47 -0800370#define __print_flags_u64(flag, delim, flag_array...) \
371 ({ \
372 static const struct trace_print_flags_u64 __flags[] = \
373 { flag_array, { -1, NULL } }; \
374 trace_print_flags_seq_u64(p, delim, flag, __flags); \
375 })
376
liubo2fc1b6f2011-04-19 09:35:28 +0800377#define __print_symbolic_u64(value, symbol_array...) \
378 ({ \
379 static const struct trace_print_flags_u64 symbols[] = \
380 { symbol_array, { -1, NULL } }; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400381 trace_print_symbols_seq_u64(p, value, symbols); \
liubo2fc1b6f2011-04-19 09:35:28 +0800382 })
383#else
Ross Zwislerd3213e82017-02-22 15:39:47 -0800384#define __print_flags_u64(flag, delim, flag_array...) \
385 __print_flags(flag, delim, flag_array)
386
liubo2fc1b6f2011-04-19 09:35:28 +0800387#define __print_symbolic_u64(value, symbol_array...) \
388 __print_symbolic(value, symbol_array)
389#endif
390
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900391#undef __print_hex
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100392#define __print_hex(buf, buf_len) \
Daniel Borkmann3898fac2017-02-02 17:09:54 +0100393 trace_print_hex_seq(p, buf, buf_len, false)
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100394
395#undef __print_hex_str
396#define __print_hex_str(buf, buf_len) \
Daniel Borkmann3898fac2017-02-02 17:09:54 +0100397 trace_print_hex_seq(p, buf, buf_len, true)
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900398
Dave Martin6ea22482015-01-28 12:48:53 +0000399#undef __print_array
400#define __print_array(array, count, el_size) \
401 ({ \
402 BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
403 el_size != 4 && el_size != 8); \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400404 trace_print_array_seq(p, array, count, el_size); \
Dave Martin6ea22482015-01-28 12:48:53 +0000405 })
406
Piotr Maziarzef56e042019-11-07 13:45:38 +0100407#undef __print_hex_dump
408#define __print_hex_dump(prefix_str, prefix_type, \
409 rowsize, groupsize, buf, len, ascii) \
410 trace_print_hex_dump_seq(p, prefix_str, prefix_type, \
411 rowsize, groupsize, buf, len, ascii)
412
Steven Rostedt62de4f22021-06-22 16:42:26 +0200413#undef __print_ns_to_secs
414#define __print_ns_to_secs(value) \
415 ({ \
416 u64 ____val = (u64)(value); \
417 do_div(____val, NSEC_PER_SEC); \
418 ____val; \
419 })
420
421#undef __print_ns_without_secs
422#define __print_ns_without_secs(value) \
423 ({ \
424 u64 ____val = (u64)(value); \
425 (u32) do_div(____val, NSEC_PER_SEC); \
426 })
427
Ingo Molnar091ad362009-11-26 09:04:55 +0100428#undef DECLARE_EVENT_CLASS
429#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500430static notrace enum print_line_t \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400431trace_raw_output_##call(struct trace_iterator *iter, int flags, \
432 struct trace_event *trace_event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400433{ \
434 struct trace_seq *s = &iter->seq; \
Li Zefanf71130d2013-02-21 10:32:38 +0800435 struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400436 struct trace_event_raw_##call *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400437 int ret; \
438 \
Li Zefanf71130d2013-02-21 10:32:38 +0800439 field = (typeof(field))iter->ent; \
Steven Rostedt80decc72010-04-23 10:00:22 -0400440 \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400441 ret = trace_raw_output_prep(iter, trace_event); \
Steven Rostedt (Red Hat)8e2e0952014-11-14 11:42:06 -0500442 if (ret != TRACE_TYPE_HANDLED) \
Li Zefanf71130d2013-02-21 10:32:38 +0800443 return ret; \
444 \
Masami Hiramatsuefbbdaa2020-10-15 23:55:07 +0900445 trace_event_printf(iter, print); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400446 \
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500447 return trace_handle_return(s); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400448} \
Steven Rostedt (Red Hat)3ad017b2015-05-13 15:35:44 -0400449static struct trace_event_functions trace_event_type_funcs_##call = { \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400450 .trace = trace_raw_output_##call, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400451};
Steven Rostedtff038f52009-11-18 20:27:27 -0500452
Steven Rostedte5bc9722009-11-18 20:36:26 -0500453#undef DEFINE_EVENT_PRINT
454#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500455static notrace enum print_line_t \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400456trace_raw_output_##call(struct trace_iterator *iter, int flags, \
Steven Rostedta9a57762010-04-22 18:46:14 -0400457 struct trace_event *event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400458{ \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400459 struct trace_event_raw_##template *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400460 struct trace_entry *entry; \
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800461 struct trace_seq *p = &iter->tmp_seq; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400462 \
463 entry = iter->ent; \
464 \
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400465 if (entry->type != event_##call.event.type) { \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400466 WARN_ON_ONCE(1); \
467 return TRACE_TYPE_UNHANDLED; \
468 } \
469 \
470 field = (typeof(field))entry; \
471 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400472 trace_seq_init(p); \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400473 return trace_output_call(iter, #call, print); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400474} \
Steven Rostedt (Red Hat)3ad017b2015-05-13 15:35:44 -0400475static struct trace_event_functions trace_event_type_funcs_##call = { \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400476 .trace = trace_raw_output_##call, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400477};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500478
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400479#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
480
Li Zefan43b51ea2009-08-07 10:33:22 +0800481#undef __field_ext
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200482#define __field_ext(_type, _item, _filter_type) { \
483 .type = #_type, .name = #_item, \
484 .size = sizeof(_type), .align = __alignof__(_type), \
485 .is_signed = is_signed_type(_type), .filter_type = _filter_type },
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400486
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400487#undef __field_struct_ext
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200488#define __field_struct_ext(_type, _item, _filter_type) { \
489 .type = #_type, .name = #_item, \
490 .size = sizeof(_type), .align = __alignof__(_type), \
491 0, .filter_type = _filter_type },
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400492
Li Zefan43b51ea2009-08-07 10:33:22 +0800493#undef __field
494#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
495
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400496#undef __field_struct
497#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
498
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400499#undef __array
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200500#define __array(_type, _item, _len) { \
501 .type = #_type"["__stringify(_len)"]", .name = #_item, \
502 .size = sizeof(_type[_len]), .align = __alignof__(_type), \
503 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400504
Li Zefan7fcb7c42009-06-01 15:35:46 +0800505#undef __dynamic_array
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200506#define __dynamic_array(_type, _item, _len) { \
507 .type = "__data_loc " #_type "[]", .name = #_item, \
508 .size = 4, .align = 4, \
509 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
Li Zefan7fcb7c42009-06-01 15:35:46 +0800510
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200511#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800512#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200513
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400514#undef __string_len
515#define __string_len(item, src, len) __dynamic_array(char, item, -1)
516
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400517#undef __bitmask
518#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
519
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900520#undef __rel_dynamic_array
521#define __rel_dynamic_array(_type, _item, _len) { \
522 .type = "__rel_loc " #_type "[]", .name = #_item, \
523 .size = 4, .align = 4, \
524 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
525
526#undef __rel_string
527#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
528
529#undef __rel_string_len
530#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
531
532#undef __rel_bitmask
533#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
534
Ingo Molnar091ad362009-11-26 09:04:55 +0100535#undef DECLARE_EVENT_CLASS
536#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200537static struct trace_event_fields trace_event_fields_##call[] = { \
538 tstruct \
539 {} };
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400540
Steven Rostedte5bc9722009-11-18 20:36:26 -0500541#undef DEFINE_EVENT_PRINT
Wei Yang61df16f2020-06-12 17:28:43 +0800542#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
Steven Rostedte5bc9722009-11-18 20:36:26 -0500543
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400544#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
545
546/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800547 * remember the offset of each array from the beginning of the event.
548 */
549
550#undef __entry
551#define __entry entry
552
553#undef __field
554#define __field(type, item)
555
Li Zefan43b51ea2009-08-07 10:33:22 +0800556#undef __field_ext
557#define __field_ext(type, item, filter_type)
558
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400559#undef __field_struct
560#define __field_struct(type, item)
561
562#undef __field_struct_ext
563#define __field_struct_ext(type, item, filter_type)
564
Li Zefan7fcb7c42009-06-01 15:35:46 +0800565#undef __array
566#define __array(type, item, len)
567
568#undef __dynamic_array
569#define __dynamic_array(type, item, len) \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800570 __item_length = (len) * sizeof(type); \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800571 __data_offsets->item = __data_size + \
572 offsetof(typeof(*entry), __data); \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800573 __data_offsets->item |= __item_length << 16; \
574 __data_size += __item_length;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800575
576#undef __string
Steven Rostedt (Red Hat)4e58e542013-11-26 09:22:54 -0500577#define __string(item, src) __dynamic_array(char, item, \
578 strlen((src) ? (const char *)(src) : "(null)") + 1)
Li Zefan7fcb7c42009-06-01 15:35:46 +0800579
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400580#undef __string_len
581#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
582
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900583#undef __rel_dynamic_array
584#define __rel_dynamic_array(type, item, len) \
585 __item_length = (len) * sizeof(type); \
586 __data_offsets->item = __data_size + \
587 offsetof(typeof(*entry), __data) - \
588 offsetof(typeof(*entry), __rel_loc_##item) - \
589 sizeof(u32); \
590 __data_offsets->item |= __item_length << 16; \
591 __data_size += __item_length;
592
593#undef __rel_string
594#define __rel_string(item, src) __rel_dynamic_array(char, item, \
595 strlen((src) ? (const char *)(src) : "(null)") + 1)
596
597#undef __rel_string_len
598#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400599/*
600 * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
601 * num_possible_cpus().
602 */
603#define __bitmask_size_in_bytes_raw(nr_bits) \
604 (((nr_bits) + 7) / 8)
605
606#define __bitmask_size_in_longs(nr_bits) \
607 ((__bitmask_size_in_bytes_raw(nr_bits) + \
608 ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
609
610/*
611 * __bitmask_size_in_bytes is the number of bytes needed to hold
612 * num_possible_cpus() padded out to the nearest long. This is what
613 * is saved in the buffer, just to be consistent.
614 */
615#define __bitmask_size_in_bytes(nr_bits) \
616 (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
617
618#undef __bitmask
619#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
620 __bitmask_size_in_longs(nr_bits))
621
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900622#undef __rel_bitmask
623#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, \
624 __bitmask_size_in_longs(nr_bits))
625
Ingo Molnar091ad362009-11-26 09:04:55 +0100626#undef DECLARE_EVENT_CLASS
627#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)d0ee8f42015-05-13 15:40:23 -0400628static inline notrace int trace_event_get_offsets_##call( \
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400629 struct trace_event_data_offsets_##call *__data_offsets, proto) \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800630{ \
631 int __data_size = 0; \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800632 int __maybe_unused __item_length; \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400633 struct trace_event_raw_##call __maybe_unused *entry; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800634 \
635 tstruct; \
636 \
637 return __data_size; \
638}
639
640#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
641
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400642/*
643 * Stage 4 of the trace events.
644 *
Hou Pengyangeba12ab2015-03-03 21:48:18 +0000645 * Override the macros in the event tracepoint header <trace/events/XXX.h>
646 * to include the following:
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400647 *
648 * For those macros defined with TRACE_EVENT:
649 *
650 * static struct trace_event_call event_<call>;
651 *
652 * static void trace_event_raw_event_<call>(void *__data, proto)
653 * {
654 * struct trace_event_file *trace_file = __data;
655 * struct trace_event_call *event_call = trace_file->event_call;
656 * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
657 * unsigned long eflags = trace_file->flags;
658 * enum event_trigger_type __tt = ETT_NONE;
659 * struct ring_buffer_event *event;
660 * struct trace_event_raw_<call> *entry; <-- defined in stage 1
Steven Rostedt (VMware)13292492019-12-13 13:58:57 -0500661 * struct trace_buffer *buffer;
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400662 * unsigned long irq_flags;
663 * int __data_size;
664 * int pc;
665 *
666 * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
667 * if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
668 * event_triggers_call(trace_file, NULL);
669 * if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
670 * return;
671 * }
672 *
673 * local_save_flags(irq_flags);
674 * pc = preempt_count();
675 *
676 * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
677 *
678 * event = trace_event_buffer_lock_reserve(&buffer, trace_file,
679 * event_<call>->event.type,
680 * sizeof(*entry) + __data_size,
681 * irq_flags, pc);
682 * if (!event)
683 * return;
684 * entry = ring_buffer_event_data(event);
685 *
686 * { <assign>; } <-- Here we assign the entries by the __field and
687 * __array macros.
688 *
689 * if (eflags & EVENT_FILE_FL_TRIGGER_COND)
690 * __tt = event_triggers_call(trace_file, entry);
691 *
692 * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
693 * &trace_file->flags))
694 * ring_buffer_discard_commit(buffer, event);
695 * else if (!filter_check_discard(trace_file, entry, buffer, event))
696 * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
697 *
698 * if (__tt)
699 * event_triggers_post_call(trace_file, __tt);
700 * }
701 *
702 * static struct trace_event ftrace_event_type_<call> = {
703 * .trace = trace_raw_output_<call>, <-- stage 2
704 * };
705 *
706 * static char print_fmt_<call>[] = <TP_printk>;
707 *
708 * static struct trace_event_class __used event_class_<template> = {
709 * .system = "<system>",
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200710 * .fields_array = trace_event_fields_<call>,
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400711 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
712 * .raw_init = trace_event_raw_init,
713 * .probe = trace_event_raw_event_##call,
714 * .reg = trace_event_reg,
715 * };
716 *
717 * static struct trace_event_call event_<call> = {
718 * .class = event_class_<template>,
719 * {
720 * .tp = &__tracepoint_<call>,
721 * },
722 * .event = &ftrace_event_type_<call>,
723 * .print_fmt = print_fmt_<call>,
724 * .flags = TRACE_EVENT_FL_TRACEPOINT,
725 * };
726 * // its only safe to use pointers when doing linker tricks to
727 * // create an array.
728 * static struct trace_event_call __used
Joe Perches33def842020-10-21 19:36:07 -0700729 * __section("_ftrace_events") *__event_<call> = &event_<call>;
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400730 *
731 */
732
733#ifdef CONFIG_PERF_EVENTS
734
735#define _TRACE_PERF_PROTO(call, proto) \
736 static notrace void \
737 perf_trace_##call(void *__data, proto);
738
739#define _TRACE_PERF_INIT(call) \
740 .perf_probe = perf_trace_##call,
741
742#else
743#define _TRACE_PERF_PROTO(call, proto)
744#define _TRACE_PERF_INIT(call)
745#endif /* CONFIG_PERF_EVENTS */
746
747#undef __entry
748#define __entry entry
749
750#undef __field
751#define __field(type, item)
752
753#undef __field_struct
754#define __field_struct(type, item)
755
756#undef __array
757#define __array(type, item, len)
758
759#undef __dynamic_array
760#define __dynamic_array(type, item, len) \
761 __entry->__data_loc_##item = __data_offsets.item;
762
763#undef __string
764#define __string(item, src) __dynamic_array(char, item, -1)
765
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400766#undef __string_len
767#define __string_len(item, src, len) __dynamic_array(char, item, -1)
768
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400769#undef __assign_str
770#define __assign_str(dst, src) \
771 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
772
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400773#undef __assign_str_len
774#define __assign_str_len(dst, src, len) \
775 do { \
776 memcpy(__get_str(dst), (src), (len)); \
777 __get_str(dst)[len] = '\0'; \
778 } while(0)
779
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400780#undef __bitmask
781#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
782
783#undef __get_bitmask
784#define __get_bitmask(field) (char *)__get_dynamic_array(field)
785
786#undef __assign_bitmask
787#define __assign_bitmask(dst, src, nr_bits) \
788 memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
789
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900790#undef __rel_dynamic_array
791#define __rel_dynamic_array(type, item, len) \
792 __entry->__rel_loc_##item = __data_offsets.item;
793
794#undef __rel_string
795#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
796
797#undef __rel_string_len
798#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
799
800#undef __assign_rel_str
801#define __assign_rel_str(dst, src) \
802 strcpy(__get_rel_str(dst), (src) ? (const char *)(src) : "(null)");
803
804#undef __assign_rel_str_len
805#define __assign_rel_str_len(dst, src, len) \
806 do { \
807 memcpy(__get_rel_str(dst), (src), (len)); \
808 __get_rel_str(dst)[len] = '\0'; \
809 } while (0)
810
811#undef __rel_bitmask
812#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
813
814#undef __get_rel_bitmask
815#define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field)
816
817#undef __assign_rel_bitmask
818#define __assign_rel_bitmask(dst, src, nr_bits) \
819 memcpy(__get_rel_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
820
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400821#undef TP_fast_assign
822#define TP_fast_assign(args...) args
823
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400824#undef __perf_count
825#define __perf_count(c) (c)
826
827#undef __perf_task
828#define __perf_task(t) (t)
829
830#undef DECLARE_EVENT_CLASS
831#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
832 \
833static notrace void \
834trace_event_raw_event_##call(void *__data, proto) \
835{ \
836 struct trace_event_file *trace_file = __data; \
837 struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
838 struct trace_event_buffer fbuffer; \
839 struct trace_event_raw_##call *entry; \
840 int __data_size; \
841 \
842 if (trace_trigger_soft_disabled(trace_file)) \
843 return; \
844 \
845 __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
846 \
847 entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
848 sizeof(*entry) + __data_size); \
849 \
850 if (!entry) \
851 return; \
852 \
853 tstruct \
854 \
855 { assign; } \
856 \
857 trace_event_buffer_commit(&fbuffer); \
858}
859/*
860 * The ftrace_test_probe is compiled out, it is only here as a build time check
861 * to make sure that if the tracepoint handling changes, the ftrace probe will
862 * fail to compile unless it too is updated.
863 */
864
865#undef DEFINE_EVENT
866#define DEFINE_EVENT(template, call, proto, args) \
867static inline void ftrace_test_probe_##call(void) \
868{ \
869 check_trace_callback_type_##call(trace_event_raw_event_##template); \
870}
871
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400872#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
873
874#undef __entry
875#define __entry REC
876
877#undef __print_flags
878#undef __print_symbolic
879#undef __print_hex
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100880#undef __print_hex_str
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400881#undef __get_dynamic_array
882#undef __get_dynamic_array_len
883#undef __get_str
884#undef __get_bitmask
Masami Hiramatsu55de2c02021-11-22 18:30:21 +0900885#undef __get_rel_dynamic_array
886#undef __get_rel_dynamic_array_len
887#undef __get_rel_str
888#undef __get_rel_bitmask
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400889#undef __print_array
Piotr Maziarz02a65a02019-11-26 11:06:31 +0100890#undef __print_hex_dump
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400891
Steven Rostedt62de4f22021-06-22 16:42:26 +0200892/*
893 * The below is not executed in the kernel. It is only what is
894 * displayed in the print format for userspace to parse.
895 */
896#undef __print_ns_to_secs
897#define __print_ns_to_secs(val) (val) / 1000000000UL
898
899#undef __print_ns_without_secs
900#define __print_ns_without_secs(val) (val) % 1000000000UL
901
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400902#undef TP_printk
903#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
904
905#undef DECLARE_EVENT_CLASS
906#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
907_TRACE_PERF_PROTO(call, PARAMS(proto)); \
908static char print_fmt_##call[] = print; \
909static struct trace_event_class __used __refdata event_class_##call = { \
910 .system = TRACE_SYSTEM_STRING, \
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200911 .fields_array = trace_event_fields_##call, \
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400912 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
913 .raw_init = trace_event_raw_init, \
914 .probe = trace_event_raw_event_##call, \
915 .reg = trace_event_reg, \
916 _TRACE_PERF_INIT(call) \
917};
918
919#undef DEFINE_EVENT
920#define DEFINE_EVENT(template, call, proto, args) \
921 \
922static struct trace_event_call __used event_##call = { \
923 .class = &event_class_##template, \
924 { \
925 .tp = &__tracepoint_##call, \
926 }, \
927 .event.funcs = &trace_event_type_funcs_##template, \
928 .print_fmt = print_fmt_##template, \
929 .flags = TRACE_EVENT_FL_TRACEPOINT, \
930}; \
931static struct trace_event_call __used \
Joe Perches33def842020-10-21 19:36:07 -0700932__section("_ftrace_events") *__event_##call = &event_##call
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400933
934#undef DEFINE_EVENT_PRINT
935#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
936 \
937static char print_fmt_##call[] = print; \
938 \
939static struct trace_event_call __used event_##call = { \
940 .class = &event_class_##template, \
941 { \
942 .tp = &__tracepoint_##call, \
943 }, \
944 .event.funcs = &trace_event_type_funcs_##call, \
945 .print_fmt = print_fmt_##call, \
946 .flags = TRACE_EVENT_FL_TRACEPOINT, \
947}; \
948static struct trace_event_call __used \
Joe Perches33def842020-10-21 19:36:07 -0700949__section("_ftrace_events") *__event_##call = &event_##call
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400950
951#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)