blob: 08810a4638805dd79c075a78557d2a3c8942a3f1 [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
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400111#undef TP_STRUCT__entry
112#define TP_STRUCT__entry(args...) args
113
Ingo Molnar091ad362009-11-26 09:04:55 +0100114#undef DECLARE_EVENT_CLASS
115#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400116 struct trace_event_raw_##name { \
Steven Rostedtff038f52009-11-18 20:27:27 -0500117 struct trace_entry ent; \
118 tstruct \
119 char __data[0]; \
Steven Rostedt8f082012010-04-20 10:47:33 -0400120 }; \
121 \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400122 static struct trace_event_class event_class_##name;
Steven Rostedt8f082012010-04-20 10:47:33 -0400123
Steven Rostedtff038f52009-11-18 20:27:27 -0500124#undef DEFINE_EVENT
125#define DEFINE_EVENT(template, name, proto, args) \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400126 static struct trace_event_call __used \
Jeff Mahoney86c38a32010-02-24 13:59:23 -0500127 __attribute__((__aligned__(4))) event_##name
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400128
Steven Rostedtf5abaa12013-06-20 11:44:44 -0400129#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
Steven Rostedte5bc9722009-11-18 20:36:26 -0500133#undef DEFINE_EVENT_PRINT
134#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
135 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
136
Josh Stone97419872009-08-24 14:43:13 -0700137/* Callbacks are meaningless to ftrace. */
138#undef TRACE_EVENT_FN
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +0200139#define TRACE_EVENT_FN(name, proto, args, tstruct, \
140 assign, print, reg, unreg) \
Frederic Weisbecker819ce452010-07-20 18:41:24 +0200141 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
142 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
Josh Stone97419872009-08-24 14:43:13 -0700143
Denis Kirjanov27011212015-12-14 23:18:05 +0300144#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
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100150#undef TRACE_EVENT_FLAGS
151#define TRACE_EVENT_FLAGS(name, value) \
Frederic Weisbecker53cf810b2010-11-18 02:11:42 +0100152 __TRACE_EVENT_FLAGS(name, value)
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100153
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100154#undef TRACE_EVENT_PERF_PERM
155#define TRACE_EVENT_PERF_PERM(name, expr...) \
156 __TRACE_EVENT_PERF_PERM(name, expr)
157
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400158#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
159
160/*
161 * Stage 2 of the trace events.
162 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200163 * Include the following:
164 *
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400165 * struct trace_event_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +0800166 * u32 <item1>;
167 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200168 * [...]
169 * };
170 *
Li Zefan7d536cb2009-07-16 10:54:02 +0800171 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +0800172 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +0800173 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200174 */
175
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -0400176#undef TRACE_DEFINE_ENUM
177#define TRACE_DEFINE_ENUM(a)
178
Jeremy Linton4f0dfd72017-05-31 16:56:50 -0500179#undef TRACE_DEFINE_SIZEOF
180#define TRACE_DEFINE_SIZEOF(a)
181
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200182#undef __field
Li Zefan43b51ea2009-08-07 10:33:22 +0800183#define __field(type, item)
184
185#undef __field_ext
186#define __field_ext(type, item, filter_type)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200187
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400188#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
Li Zefan7fcb7c42009-06-01 15:35:46 +0800194#undef __array
195#define __array(type, item, len)
196
197#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +0800198#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800199
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200200#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800201#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200202
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400203#undef __string_len
204#define __string_len(item, src, len) __dynamic_array(char, item, -1)
205
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400206#undef __bitmask
207#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
208
Ingo Molnar091ad362009-11-26 09:04:55 +0100209#undef DECLARE_EVENT_CLASS
210#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400211 struct trace_event_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200212 tstruct; \
213 };
214
Steven Rostedtff038f52009-11-18 20:27:27 -0500215#undef DEFINE_EVENT
216#define DEFINE_EVENT(template, name, proto, args)
217
Steven Rostedte5bc9722009-11-18 20:36:26 -0500218#undef DEFINE_EVENT_PRINT
Wei Yang61df16f2020-06-12 17:28:43 +0800219#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
Steven Rostedte5bc9722009-11-18 20:36:26 -0500220
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100221#undef TRACE_EVENT_FLAGS
222#define TRACE_EVENT_FLAGS(event, flag)
223
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100224#undef TRACE_EVENT_PERF_PERM
225#define TRACE_EVENT_PERF_PERM(event, expr...)
226
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200227#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
228
229/*
230 * Stage 3 of the trace events.
231 *
Hou Pengyangeba12ab2015-03-03 21:48:18 +0000232 * Override the macros in the event tracepoint header <trace/events/XXX.h>
233 * to include the following:
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400234 *
235 * enum print_line_t
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400236 * trace_raw_output_<call>(struct trace_iterator *iter, int flags)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400237 * {
238 * struct trace_seq *s = &iter->seq;
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400239 * struct trace_event_raw_<call> *field; <-- defined in stage 1
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800240 * struct trace_seq *p = &iter->tmp_seq;
Masami Hiramatsu1600cbc2020-10-15 23:55:16 +0900241 *
242 * -------(for event)-------
243 *
244 * struct trace_entry *entry;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400245 *
246 * entry = iter->ent;
247 *
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400248 * if (entry->type != event_<call>->event.type) {
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400249 * WARN_ON_ONCE(1);
250 * return TRACE_TYPE_UNHANDLED;
251 * }
252 *
253 * field = (typeof(field))entry;
254 *
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100255 * trace_seq_init(p);
Masami Hiramatsu1600cbc2020-10-15 23:55:16 +0900256 * return trace_output_call(iter, <call>, <TP_printk> "\n");
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400257 *
Masami Hiramatsu1600cbc2020-10-15 23:55:16 +0900258 * ------(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 * }
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400273 *
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
Li Zefan7fcb7c42009-06-01 15:35:46 +0800285#undef __get_dynamic_array
286#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800287 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800288
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400289#undef __get_dynamic_array_len
290#define __get_dynamic_array_len(field) \
291 ((__entry->__data_loc_##field >> 16) & 0xffff)
292
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200293#undef __get_str
Daniel Bristot de Oliveira934de5f2016-07-01 20:44:34 -0300294#define __get_str(field) ((char *)__get_dynamic_array(field))
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200295
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400296#undef __get_bitmask
297#define __get_bitmask(field) \
298 ({ \
299 void *__bitmask = __get_dynamic_array(field); \
300 unsigned int __bitmask_size; \
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400301 __bitmask_size = __get_dynamic_array_len(field); \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400302 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400303 })
304
Steven Rostedtbe74b732009-05-26 20:25:22 +0200305#undef __print_flags
306#define __print_flags(flag, delim, flag_array...) \
307 ({ \
Steven Rostedta48f4942009-09-14 11:18:02 -0400308 static const struct trace_print_flags __flags[] = \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200309 { flag_array, { -1, NULL }}; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400310 trace_print_flags_seq(p, delim, flag, __flags); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200311 })
312
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400313#undef __print_symbolic
314#define __print_symbolic(value, symbol_array...) \
315 ({ \
316 static const struct trace_print_flags symbols[] = \
317 { symbol_array, { -1, NULL }}; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400318 trace_print_symbols_seq(p, value, symbols); \
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400319 })
320
Ross Zwislerd3213e82017-02-22 15:39:47 -0800321#undef __print_flags_u64
liubo2fc1b6f2011-04-19 09:35:28 +0800322#undef __print_symbolic_u64
323#if BITS_PER_LONG == 32
Ross Zwislerd3213e82017-02-22 15:39:47 -0800324#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
liubo2fc1b6f2011-04-19 09:35:28 +0800331#define __print_symbolic_u64(value, symbol_array...) \
332 ({ \
333 static const struct trace_print_flags_u64 symbols[] = \
334 { symbol_array, { -1, NULL } }; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400335 trace_print_symbols_seq_u64(p, value, symbols); \
liubo2fc1b6f2011-04-19 09:35:28 +0800336 })
337#else
Ross Zwislerd3213e82017-02-22 15:39:47 -0800338#define __print_flags_u64(flag, delim, flag_array...) \
339 __print_flags(flag, delim, flag_array)
340
liubo2fc1b6f2011-04-19 09:35:28 +0800341#define __print_symbolic_u64(value, symbol_array...) \
342 __print_symbolic(value, symbol_array)
343#endif
344
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900345#undef __print_hex
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100346#define __print_hex(buf, buf_len) \
Daniel Borkmann3898fac2017-02-02 17:09:54 +0100347 trace_print_hex_seq(p, buf, buf_len, false)
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100348
349#undef __print_hex_str
350#define __print_hex_str(buf, buf_len) \
Daniel Borkmann3898fac2017-02-02 17:09:54 +0100351 trace_print_hex_seq(p, buf, buf_len, true)
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900352
Dave Martin6ea22482015-01-28 12:48:53 +0000353#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); \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400358 trace_print_array_seq(p, array, count, el_size); \
Dave Martin6ea22482015-01-28 12:48:53 +0000359 })
360
Piotr Maziarzef56e042019-11-07 13:45:38 +0100361#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
Steven Rostedt62de4f22021-06-22 16:42:26 +0200367#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
Ingo Molnar091ad362009-11-26 09:04:55 +0100382#undef DECLARE_EVENT_CLASS
383#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500384static notrace enum print_line_t \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400385trace_raw_output_##call(struct trace_iterator *iter, int flags, \
386 struct trace_event *trace_event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400387{ \
388 struct trace_seq *s = &iter->seq; \
Li Zefanf71130d2013-02-21 10:32:38 +0800389 struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400390 struct trace_event_raw_##call *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400391 int ret; \
392 \
Li Zefanf71130d2013-02-21 10:32:38 +0800393 field = (typeof(field))iter->ent; \
Steven Rostedt80decc72010-04-23 10:00:22 -0400394 \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400395 ret = trace_raw_output_prep(iter, trace_event); \
Steven Rostedt (Red Hat)8e2e0952014-11-14 11:42:06 -0500396 if (ret != TRACE_TYPE_HANDLED) \
Li Zefanf71130d2013-02-21 10:32:38 +0800397 return ret; \
398 \
Masami Hiramatsuefbbdaa2020-10-15 23:55:07 +0900399 trace_event_printf(iter, print); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400400 \
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500401 return trace_handle_return(s); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400402} \
Steven Rostedt (Red Hat)3ad017b2015-05-13 15:35:44 -0400403static struct trace_event_functions trace_event_type_funcs_##call = { \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400404 .trace = trace_raw_output_##call, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400405};
Steven Rostedtff038f52009-11-18 20:27:27 -0500406
Steven Rostedte5bc9722009-11-18 20:36:26 -0500407#undef DEFINE_EVENT_PRINT
408#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500409static notrace enum print_line_t \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400410trace_raw_output_##call(struct trace_iterator *iter, int flags, \
Steven Rostedta9a57762010-04-22 18:46:14 -0400411 struct trace_event *event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400412{ \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400413 struct trace_event_raw_##template *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400414 struct trace_entry *entry; \
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800415 struct trace_seq *p = &iter->tmp_seq; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400416 \
417 entry = iter->ent; \
418 \
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400419 if (entry->type != event_##call.event.type) { \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400420 WARN_ON_ONCE(1); \
421 return TRACE_TYPE_UNHANDLED; \
422 } \
423 \
424 field = (typeof(field))entry; \
425 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400426 trace_seq_init(p); \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400427 return trace_output_call(iter, #call, print); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400428} \
Steven Rostedt (Red Hat)3ad017b2015-05-13 15:35:44 -0400429static struct trace_event_functions trace_event_type_funcs_##call = { \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400430 .trace = trace_raw_output_##call, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400431};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500432
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400433#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
434
Li Zefan43b51ea2009-08-07 10:33:22 +0800435#undef __field_ext
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200436#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 },
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400440
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400441#undef __field_struct_ext
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200442#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 },
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400446
Li Zefan43b51ea2009-08-07 10:33:22 +0800447#undef __field
448#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
449
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400450#undef __field_struct
451#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
452
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400453#undef __array
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200454#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 },
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400458
Li Zefan7fcb7c42009-06-01 15:35:46 +0800459#undef __dynamic_array
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200460#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 },
Li Zefan7fcb7c42009-06-01 15:35:46 +0800464
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200465#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800466#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200467
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400468#undef __string_len
469#define __string_len(item, src, len) __dynamic_array(char, item, -1)
470
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400471#undef __bitmask
472#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
473
Ingo Molnar091ad362009-11-26 09:04:55 +0100474#undef DECLARE_EVENT_CLASS
475#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200476static struct trace_event_fields trace_event_fields_##call[] = { \
477 tstruct \
478 {} };
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400479
Steven Rostedte5bc9722009-11-18 20:36:26 -0500480#undef DEFINE_EVENT_PRINT
Wei Yang61df16f2020-06-12 17:28:43 +0800481#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
Steven Rostedte5bc9722009-11-18 20:36:26 -0500482
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400483#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
484
485/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800486 * 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
Li Zefan43b51ea2009-08-07 10:33:22 +0800495#undef __field_ext
496#define __field_ext(type, item, filter_type)
497
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400498#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
Li Zefan7fcb7c42009-06-01 15:35:46 +0800504#undef __array
505#define __array(type, item, len)
506
507#undef __dynamic_array
508#define __dynamic_array(type, item, len) \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800509 __item_length = (len) * sizeof(type); \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800510 __data_offsets->item = __data_size + \
511 offsetof(typeof(*entry), __data); \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800512 __data_offsets->item |= __item_length << 16; \
513 __data_size += __item_length;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800514
515#undef __string
Steven Rostedt (Red Hat)4e58e542013-11-26 09:22:54 -0500516#define __string(item, src) __dynamic_array(char, item, \
517 strlen((src) ? (const char *)(src) : "(null)") + 1)
Li Zefan7fcb7c42009-06-01 15:35:46 +0800518
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400519#undef __string_len
520#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
521
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400522/*
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
Ingo Molnar091ad362009-11-26 09:04:55 +0100545#undef DECLARE_EVENT_CLASS
546#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)d0ee8f42015-05-13 15:40:23 -0400547static inline notrace int trace_event_get_offsets_##call( \
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400548 struct trace_event_data_offsets_##call *__data_offsets, proto) \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800549{ \
550 int __data_size = 0; \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800551 int __maybe_unused __item_length; \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400552 struct trace_event_raw_##call __maybe_unused *entry; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800553 \
554 tstruct; \
555 \
556 return __data_size; \
557}
558
559#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
560
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400561/*
562 * Stage 4 of the trace events.
563 *
Hou Pengyangeba12ab2015-03-03 21:48:18 +0000564 * Override the macros in the event tracepoint header <trace/events/XXX.h>
565 * to include the following:
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400566 *
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
Steven Rostedt (VMware)13292492019-12-13 13:58:57 -0500580 * struct trace_buffer *buffer;
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400581 * 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>",
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200629 * .fields_array = trace_event_fields_<call>,
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400630 * .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
Joe Perches33def842020-10-21 19:36:07 -0700648 * __section("_ftrace_events") *__event_<call> = &event_<call>;
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400649 *
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
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400685#undef __string_len
686#define __string_len(item, src, len) __dynamic_array(char, item, -1)
687
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400688#undef __assign_str
689#define __assign_str(dst, src) \
690 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
691
Steven Rostedt (VMware)883b4ae2021-07-16 20:55:10 -0400692#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
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400699#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
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400712#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 \
721static notrace void \
722trace_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) \
755static inline void ftrace_test_probe_##call(void) \
756{ \
757 check_trace_callback_type_##call(trace_event_raw_event_##template); \
758}
759
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400760#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
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100768#undef __print_hex_str
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400769#undef __get_dynamic_array
770#undef __get_dynamic_array_len
771#undef __get_str
772#undef __get_bitmask
773#undef __print_array
Piotr Maziarz02a65a02019-11-26 11:06:31 +0100774#undef __print_hex_dump
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400775
Steven Rostedt62de4f22021-06-22 16:42:26 +0200776/*
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
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400786#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)); \
792static char print_fmt_##call[] = print; \
793static struct trace_event_class __used __refdata event_class_##call = { \
794 .system = TRACE_SYSTEM_STRING, \
Peter Zijlstra04ae87a2019-10-24 22:26:59 +0200795 .fields_array = trace_event_fields_##call, \
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400796 .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 \
806static 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}; \
815static struct trace_event_call __used \
Joe Perches33def842020-10-21 19:36:07 -0700816__section("_ftrace_events") *__event_##call = &event_##call
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400817
818#undef DEFINE_EVENT_PRINT
819#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
820 \
821static char print_fmt_##call[] = print; \
822 \
823static 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}; \
832static struct trace_event_call __used \
Joe Perches33def842020-10-21 19:36:07 -0700833__section("_ftrace_events") *__event_##call = &event_##call
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400834
835#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)