blob: 3976fa1f6e42b91191391a72fb2fe51e4fc6512b [file] [log] [blame]
Steven Rostedtf42c85e2009-04-13 12:25:37 -04001/*
2 * Stage 1 of the trace events.
3 *
4 * Override the macros in <trace/trace_events.h> to include the following:
5 *
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -04006 * struct trace_event_raw_<call> {
Steven Rostedtf42c85e2009-04-13 12:25:37 -04007 * struct trace_entry ent;
8 * <type> <item>;
9 * <type2> <item2>[<len>];
10 * [...]
11 * };
12 *
13 * The <type> <item> is created by the __field(type, item) macro or
14 * the __array(type2, item2, len) macro.
15 * We simply do "type item;", and that will create the fields
16 * in the structure.
17 */
18
Steven Rostedt (Red Hat)af658dc2015-04-29 14:36:05 -040019#include <linux/trace_events.h>
Steven Rostedtf42c85e2009-04-13 12:25:37 -040020
Steven Rostedt (Red Hat)acd388f2015-03-31 14:37:12 -040021#ifndef TRACE_SYSTEM_VAR
22#define TRACE_SYSTEM_VAR TRACE_SYSTEM
23#endif
24
25#define __app__(x, y) str__##x##y
26#define __app(x, y) __app__(x, y)
27
28#define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
29
30#define TRACE_MAKE_SYSTEM_STR() \
31 static const char TRACE_SYSTEM_STRING[] = \
32 __stringify(TRACE_SYSTEM)
33
34TRACE_MAKE_SYSTEM_STR();
35
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040036#undef TRACE_DEFINE_ENUM
37#define TRACE_DEFINE_ENUM(a) \
Jeremy Linton00f4b652017-05-31 16:56:43 -050038 static struct trace_eval_map __used __initdata \
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040039 __##TRACE_SYSTEM##_##a = \
40 { \
41 .system = TRACE_SYSTEM_STRING, \
Jeremy Linton00f4b652017-05-31 16:56:43 -050042 .eval_string = #a, \
43 .eval_value = a \
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040044 }; \
Jeremy Linton00f4b652017-05-31 16:56:43 -050045 static struct trace_eval_map __used \
Jeremy Linton02fd7f62017-05-31 16:56:42 -050046 __attribute__((section("_ftrace_eval_map"))) \
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040047 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
48
Jeremy Linton4f0dfd72017-05-31 16:56:50 -050049#undef TRACE_DEFINE_SIZEOF
50#define TRACE_DEFINE_SIZEOF(a) \
51 static struct trace_eval_map __used __initdata \
52 __##TRACE_SYSTEM##_##a = \
53 { \
54 .system = TRACE_SYSTEM_STRING, \
55 .eval_string = "sizeof(" #a ")", \
56 .eval_value = sizeof(a) \
57 }; \
58 static struct trace_eval_map __used \
59 __attribute__((section("_ftrace_eval_map"))) \
60 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
61
Steven Rostedtff038f52009-11-18 20:27:27 -050062/*
Ingo Molnar091ad362009-11-26 09:04:55 +010063 * DECLARE_EVENT_CLASS can be used to add a generic function
Steven Rostedtff038f52009-11-18 20:27:27 -050064 * handlers for events. That is, if all events have the same
65 * parameters and just have distinct trace points.
66 * Each tracepoint can be defined with DEFINE_EVENT and that
Ingo Molnar091ad362009-11-26 09:04:55 +010067 * will map the DECLARE_EVENT_CLASS to the tracepoint.
Steven Rostedtff038f52009-11-18 20:27:27 -050068 *
69 * TRACE_EVENT is a one to one mapping between tracepoint and template.
70 */
71#undef TRACE_EVENT
72#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
Ingo Molnar091ad362009-11-26 09:04:55 +010073 DECLARE_EVENT_CLASS(name, \
Steven Rostedtff038f52009-11-18 20:27:27 -050074 PARAMS(proto), \
75 PARAMS(args), \
76 PARAMS(tstruct), \
77 PARAMS(assign), \
78 PARAMS(print)); \
79 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
80
81
Steven Rostedtf42c85e2009-04-13 12:25:37 -040082#undef __field
83#define __field(type, item) type item;
84
Li Zefan43b51ea2009-08-07 10:33:22 +080085#undef __field_ext
86#define __field_ext(type, item, filter_type) type item;
87
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -040088#undef __field_struct
89#define __field_struct(type, item) type item;
90
91#undef __field_struct_ext
92#define __field_struct_ext(type, item, filter_type) type item;
93
Li Zefan7fcb7c42009-06-01 15:35:46 +080094#undef __array
95#define __array(type, item, len) type item[len];
96
97#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +080098#define __dynamic_array(type, item, len) u32 __data_loc_##item;
Li Zefan7fcb7c42009-06-01 15:35:46 +080099
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200100#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800101#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200102
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400103#undef __bitmask
104#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
105
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400106#undef TP_STRUCT__entry
107#define TP_STRUCT__entry(args...) args
108
Ingo Molnar091ad362009-11-26 09:04:55 +0100109#undef DECLARE_EVENT_CLASS
110#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400111 struct trace_event_raw_##name { \
Steven Rostedtff038f52009-11-18 20:27:27 -0500112 struct trace_entry ent; \
113 tstruct \
114 char __data[0]; \
Steven Rostedt8f082012010-04-20 10:47:33 -0400115 }; \
116 \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400117 static struct trace_event_class event_class_##name;
Steven Rostedt8f082012010-04-20 10:47:33 -0400118
Steven Rostedtff038f52009-11-18 20:27:27 -0500119#undef DEFINE_EVENT
120#define DEFINE_EVENT(template, name, proto, args) \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400121 static struct trace_event_call __used \
Jeff Mahoney86c38a32010-02-24 13:59:23 -0500122 __attribute__((__aligned__(4))) event_##name
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400123
Steven Rostedtf5abaa12013-06-20 11:44:44 -0400124#undef DEFINE_EVENT_FN
125#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
126 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
127
Steven Rostedte5bc9722009-11-18 20:36:26 -0500128#undef DEFINE_EVENT_PRINT
129#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
130 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
131
Josh Stone97419872009-08-24 14:43:13 -0700132/* Callbacks are meaningless to ftrace. */
133#undef TRACE_EVENT_FN
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +0200134#define TRACE_EVENT_FN(name, proto, args, tstruct, \
135 assign, print, reg, unreg) \
Frederic Weisbecker819ce452010-07-20 18:41:24 +0200136 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
137 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
Josh Stone97419872009-08-24 14:43:13 -0700138
Denis Kirjanov27011212015-12-14 23:18:05 +0300139#undef TRACE_EVENT_FN_COND
140#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
141 assign, print, reg, unreg) \
142 TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
143 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
144
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100145#undef TRACE_EVENT_FLAGS
146#define TRACE_EVENT_FLAGS(name, value) \
Frederic Weisbecker53cf810b2010-11-18 02:11:42 +0100147 __TRACE_EVENT_FLAGS(name, value)
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100148
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100149#undef TRACE_EVENT_PERF_PERM
150#define TRACE_EVENT_PERF_PERM(name, expr...) \
151 __TRACE_EVENT_PERF_PERM(name, expr)
152
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400153#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
154
155/*
156 * Stage 2 of the trace events.
157 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200158 * Include the following:
159 *
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400160 * struct trace_event_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +0800161 * u32 <item1>;
162 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200163 * [...]
164 * };
165 *
Li Zefan7d536cb2009-07-16 10:54:02 +0800166 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +0800167 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +0800168 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200169 */
170
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -0400171#undef TRACE_DEFINE_ENUM
172#define TRACE_DEFINE_ENUM(a)
173
Jeremy Linton4f0dfd72017-05-31 16:56:50 -0500174#undef TRACE_DEFINE_SIZEOF
175#define TRACE_DEFINE_SIZEOF(a)
176
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200177#undef __field
Li Zefan43b51ea2009-08-07 10:33:22 +0800178#define __field(type, item)
179
180#undef __field_ext
181#define __field_ext(type, item, filter_type)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200182
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400183#undef __field_struct
184#define __field_struct(type, item)
185
186#undef __field_struct_ext
187#define __field_struct_ext(type, item, filter_type)
188
Li Zefan7fcb7c42009-06-01 15:35:46 +0800189#undef __array
190#define __array(type, item, len)
191
192#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +0800193#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800194
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200195#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800196#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200197
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400198#undef __bitmask
199#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
200
Ingo Molnar091ad362009-11-26 09:04:55 +0100201#undef DECLARE_EVENT_CLASS
202#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400203 struct trace_event_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200204 tstruct; \
205 };
206
Steven Rostedtff038f52009-11-18 20:27:27 -0500207#undef DEFINE_EVENT
208#define DEFINE_EVENT(template, name, proto, args)
209
Steven Rostedte5bc9722009-11-18 20:36:26 -0500210#undef DEFINE_EVENT_PRINT
211#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
212 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
213
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100214#undef TRACE_EVENT_FLAGS
215#define TRACE_EVENT_FLAGS(event, flag)
216
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100217#undef TRACE_EVENT_PERF_PERM
218#define TRACE_EVENT_PERF_PERM(event, expr...)
219
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200220#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
221
222/*
223 * Stage 3 of the trace events.
224 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400225 * Override the macros in <trace/trace_events.h> to include the following:
226 *
227 * enum print_line_t
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400228 * trace_raw_output_<call>(struct trace_iterator *iter, int flags)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400229 * {
230 * struct trace_seq *s = &iter->seq;
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400231 * struct trace_event_raw_<call> *field; <-- defined in stage 1
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400232 * struct trace_entry *entry;
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800233 * struct trace_seq *p = &iter->tmp_seq;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400234 * int ret;
235 *
236 * entry = iter->ent;
237 *
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400238 * if (entry->type != event_<call>->event.type) {
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400239 * WARN_ON_ONCE(1);
240 * return TRACE_TYPE_UNHANDLED;
241 * }
242 *
243 * field = (typeof(field))entry;
244 *
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100245 * trace_seq_init(p);
Li Zefan50354a82010-03-24 10:58:24 +0800246 * ret = trace_seq_printf(s, "%s: ", <call>);
247 * if (ret)
248 * ret = trace_seq_printf(s, <TP_printk> "\n");
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400249 * if (!ret)
250 * return TRACE_TYPE_PARTIAL_LINE;
251 *
252 * return TRACE_TYPE_HANDLED;
253 * }
254 *
255 * This is the method used to print the raw event to the trace
256 * output format. Note, this is not needed if the data is read
257 * in binary.
258 */
259
260#undef __entry
261#define __entry field
262
263#undef TP_printk
264#define TP_printk(fmt, args...) fmt "\n", args
265
Li Zefan7fcb7c42009-06-01 15:35:46 +0800266#undef __get_dynamic_array
267#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800268 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800269
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400270#undef __get_dynamic_array_len
271#define __get_dynamic_array_len(field) \
272 ((__entry->__data_loc_##field >> 16) & 0xffff)
273
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200274#undef __get_str
Daniel Bristot de Oliveira934de5f2016-07-01 20:44:34 -0300275#define __get_str(field) ((char *)__get_dynamic_array(field))
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200276
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400277#undef __get_bitmask
278#define __get_bitmask(field) \
279 ({ \
280 void *__bitmask = __get_dynamic_array(field); \
281 unsigned int __bitmask_size; \
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400282 __bitmask_size = __get_dynamic_array_len(field); \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400283 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400284 })
285
Steven Rostedtbe74b732009-05-26 20:25:22 +0200286#undef __print_flags
287#define __print_flags(flag, delim, flag_array...) \
288 ({ \
Steven Rostedta48f4942009-09-14 11:18:02 -0400289 static const struct trace_print_flags __flags[] = \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200290 { flag_array, { -1, NULL }}; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400291 trace_print_flags_seq(p, delim, flag, __flags); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200292 })
293
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400294#undef __print_symbolic
295#define __print_symbolic(value, symbol_array...) \
296 ({ \
297 static const struct trace_print_flags symbols[] = \
298 { symbol_array, { -1, NULL }}; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400299 trace_print_symbols_seq(p, value, symbols); \
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400300 })
301
Ross Zwislerd3213e82017-02-22 15:39:47 -0800302#undef __print_flags_u64
liubo2fc1b6f2011-04-19 09:35:28 +0800303#undef __print_symbolic_u64
304#if BITS_PER_LONG == 32
Ross Zwislerd3213e82017-02-22 15:39:47 -0800305#define __print_flags_u64(flag, delim, flag_array...) \
306 ({ \
307 static const struct trace_print_flags_u64 __flags[] = \
308 { flag_array, { -1, NULL } }; \
309 trace_print_flags_seq_u64(p, delim, flag, __flags); \
310 })
311
liubo2fc1b6f2011-04-19 09:35:28 +0800312#define __print_symbolic_u64(value, symbol_array...) \
313 ({ \
314 static const struct trace_print_flags_u64 symbols[] = \
315 { symbol_array, { -1, NULL } }; \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400316 trace_print_symbols_seq_u64(p, value, symbols); \
liubo2fc1b6f2011-04-19 09:35:28 +0800317 })
318#else
Ross Zwislerd3213e82017-02-22 15:39:47 -0800319#define __print_flags_u64(flag, delim, flag_array...) \
320 __print_flags(flag, delim, flag_array)
321
liubo2fc1b6f2011-04-19 09:35:28 +0800322#define __print_symbolic_u64(value, symbol_array...) \
323 __print_symbolic(value, symbol_array)
324#endif
325
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900326#undef __print_hex
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100327#define __print_hex(buf, buf_len) \
Daniel Borkmann3898fac2017-02-02 17:09:54 +0100328 trace_print_hex_seq(p, buf, buf_len, false)
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100329
330#undef __print_hex_str
331#define __print_hex_str(buf, buf_len) \
Daniel Borkmann3898fac2017-02-02 17:09:54 +0100332 trace_print_hex_seq(p, buf, buf_len, true)
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900333
Dave Martin6ea22482015-01-28 12:48:53 +0000334#undef __print_array
335#define __print_array(array, count, el_size) \
336 ({ \
337 BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
338 el_size != 4 && el_size != 8); \
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400339 trace_print_array_seq(p, array, count, el_size); \
Dave Martin6ea22482015-01-28 12:48:53 +0000340 })
341
Ingo Molnar091ad362009-11-26 09:04:55 +0100342#undef DECLARE_EVENT_CLASS
343#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500344static notrace enum print_line_t \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400345trace_raw_output_##call(struct trace_iterator *iter, int flags, \
346 struct trace_event *trace_event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400347{ \
348 struct trace_seq *s = &iter->seq; \
Li Zefanf71130d2013-02-21 10:32:38 +0800349 struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400350 struct trace_event_raw_##call *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400351 int ret; \
352 \
Li Zefanf71130d2013-02-21 10:32:38 +0800353 field = (typeof(field))iter->ent; \
Steven Rostedt80decc72010-04-23 10:00:22 -0400354 \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400355 ret = trace_raw_output_prep(iter, trace_event); \
Steven Rostedt (Red Hat)8e2e0952014-11-14 11:42:06 -0500356 if (ret != TRACE_TYPE_HANDLED) \
Li Zefanf71130d2013-02-21 10:32:38 +0800357 return ret; \
358 \
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500359 trace_seq_printf(s, print); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400360 \
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500361 return trace_handle_return(s); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400362} \
Steven Rostedt (Red Hat)3ad017b2015-05-13 15:35:44 -0400363static struct trace_event_functions trace_event_type_funcs_##call = { \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400364 .trace = trace_raw_output_##call, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400365};
Steven Rostedtff038f52009-11-18 20:27:27 -0500366
Steven Rostedte5bc9722009-11-18 20:36:26 -0500367#undef DEFINE_EVENT_PRINT
368#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500369static notrace enum print_line_t \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400370trace_raw_output_##call(struct trace_iterator *iter, int flags, \
Steven Rostedta9a57762010-04-22 18:46:14 -0400371 struct trace_event *event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400372{ \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400373 struct trace_event_raw_##template *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400374 struct trace_entry *entry; \
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800375 struct trace_seq *p = &iter->tmp_seq; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400376 \
377 entry = iter->ent; \
378 \
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400379 if (entry->type != event_##call.event.type) { \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400380 WARN_ON_ONCE(1); \
381 return TRACE_TYPE_UNHANDLED; \
382 } \
383 \
384 field = (typeof(field))entry; \
385 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400386 trace_seq_init(p); \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400387 return trace_output_call(iter, #call, print); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400388} \
Steven Rostedt (Red Hat)3ad017b2015-05-13 15:35:44 -0400389static struct trace_event_functions trace_event_type_funcs_##call = { \
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400390 .trace = trace_raw_output_##call, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400391};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500392
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400393#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
394
Li Zefan43b51ea2009-08-07 10:33:22 +0800395#undef __field_ext
396#define __field_ext(type, item, filter_type) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400397 ret = trace_define_field(event_call, #type, #item, \
398 offsetof(typeof(field), item), \
Li Zefan43b51ea2009-08-07 10:33:22 +0800399 sizeof(field.item), \
400 is_signed_type(type), filter_type); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400401 if (ret) \
402 return ret;
403
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400404#undef __field_struct_ext
405#define __field_struct_ext(type, item, filter_type) \
406 ret = trace_define_field(event_call, #type, #item, \
407 offsetof(typeof(field), item), \
408 sizeof(field.item), \
409 0, filter_type); \
410 if (ret) \
411 return ret;
412
Li Zefan43b51ea2009-08-07 10:33:22 +0800413#undef __field
414#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
415
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400416#undef __field_struct
417#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
418
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400419#undef __array
420#define __array(type, item, len) \
Steven Rostedt04295782010-11-12 22:32:11 -0500421 do { \
Vaibhav Nagarnaik87291342014-02-13 19:51:48 -0800422 char *type_str = #type"["__stringify(len)"]"; \
Steven Rostedt04295782010-11-12 22:32:11 -0500423 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
Vaibhav Nagarnaik87291342014-02-13 19:51:48 -0800424 ret = trace_define_field(event_call, type_str, #item, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400425 offsetof(typeof(field), item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800426 sizeof(field.item), \
427 is_signed_type(type), FILTER_OTHER); \
Steven Rostedt04295782010-11-12 22:32:11 -0500428 if (ret) \
429 return ret; \
430 } while (0);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400431
Li Zefan7fcb7c42009-06-01 15:35:46 +0800432#undef __dynamic_array
433#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800434 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
Li Zefan43b51ea2009-08-07 10:33:22 +0800435 offsetof(typeof(field), __data_loc_##item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800436 sizeof(field.__data_loc_##item), \
437 is_signed_type(type), FILTER_OTHER);
Li Zefan7fcb7c42009-06-01 15:35:46 +0800438
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200439#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800440#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200441
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400442#undef __bitmask
443#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
444
Ingo Molnar091ad362009-11-26 09:04:55 +0100445#undef DECLARE_EVENT_CLASS
446#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Li Zefan7e4f44b2013-02-21 10:33:33 +0800447static int notrace __init \
Steven Rostedt (Red Hat)33d0f352015-05-13 15:37:57 -0400448trace_event_define_fields_##call(struct trace_event_call *event_call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400449{ \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400450 struct trace_event_raw_##call field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400451 int ret; \
452 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400453 tstruct; \
454 \
455 return ret; \
456}
457
Steven Rostedtff038f52009-11-18 20:27:27 -0500458#undef DEFINE_EVENT
459#define DEFINE_EVENT(template, name, proto, args)
460
Steven Rostedte5bc9722009-11-18 20:36:26 -0500461#undef DEFINE_EVENT_PRINT
462#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
463 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
464
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400465#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
466
467/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800468 * remember the offset of each array from the beginning of the event.
469 */
470
471#undef __entry
472#define __entry entry
473
474#undef __field
475#define __field(type, item)
476
Li Zefan43b51ea2009-08-07 10:33:22 +0800477#undef __field_ext
478#define __field_ext(type, item, filter_type)
479
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400480#undef __field_struct
481#define __field_struct(type, item)
482
483#undef __field_struct_ext
484#define __field_struct_ext(type, item, filter_type)
485
Li Zefan7fcb7c42009-06-01 15:35:46 +0800486#undef __array
487#define __array(type, item, len)
488
489#undef __dynamic_array
490#define __dynamic_array(type, item, len) \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800491 __item_length = (len) * sizeof(type); \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800492 __data_offsets->item = __data_size + \
493 offsetof(typeof(*entry), __data); \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800494 __data_offsets->item |= __item_length << 16; \
495 __data_size += __item_length;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800496
497#undef __string
Steven Rostedt (Red Hat)4e58e542013-11-26 09:22:54 -0500498#define __string(item, src) __dynamic_array(char, item, \
499 strlen((src) ? (const char *)(src) : "(null)") + 1)
Li Zefan7fcb7c42009-06-01 15:35:46 +0800500
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400501/*
502 * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
503 * num_possible_cpus().
504 */
505#define __bitmask_size_in_bytes_raw(nr_bits) \
506 (((nr_bits) + 7) / 8)
507
508#define __bitmask_size_in_longs(nr_bits) \
509 ((__bitmask_size_in_bytes_raw(nr_bits) + \
510 ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
511
512/*
513 * __bitmask_size_in_bytes is the number of bytes needed to hold
514 * num_possible_cpus() padded out to the nearest long. This is what
515 * is saved in the buffer, just to be consistent.
516 */
517#define __bitmask_size_in_bytes(nr_bits) \
518 (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
519
520#undef __bitmask
521#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
522 __bitmask_size_in_longs(nr_bits))
523
Ingo Molnar091ad362009-11-26 09:04:55 +0100524#undef DECLARE_EVENT_CLASS
525#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt (Red Hat)d0ee8f42015-05-13 15:40:23 -0400526static inline notrace int trace_event_get_offsets_##call( \
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -0400527 struct trace_event_data_offsets_##call *__data_offsets, proto) \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800528{ \
529 int __data_size = 0; \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800530 int __maybe_unused __item_length; \
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -0400531 struct trace_event_raw_##call __maybe_unused *entry; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800532 \
533 tstruct; \
534 \
535 return __data_size; \
536}
537
Steven Rostedtff038f52009-11-18 20:27:27 -0500538#undef DEFINE_EVENT
539#define DEFINE_EVENT(template, name, proto, args)
540
Steven Rostedte5bc9722009-11-18 20:36:26 -0500541#undef DEFINE_EVENT_PRINT
542#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
543 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
544
Li Zefan7fcb7c42009-06-01 15:35:46 +0800545#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
546
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400547/*
548 * Stage 4 of the trace events.
549 *
550 * Override the macros in <trace/trace_events.h> to include the following:
551 *
552 * For those macros defined with TRACE_EVENT:
553 *
554 * static struct trace_event_call event_<call>;
555 *
556 * static void trace_event_raw_event_<call>(void *__data, proto)
557 * {
558 * struct trace_event_file *trace_file = __data;
559 * struct trace_event_call *event_call = trace_file->event_call;
560 * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
561 * unsigned long eflags = trace_file->flags;
562 * enum event_trigger_type __tt = ETT_NONE;
563 * struct ring_buffer_event *event;
564 * struct trace_event_raw_<call> *entry; <-- defined in stage 1
565 * struct ring_buffer *buffer;
566 * unsigned long irq_flags;
567 * int __data_size;
568 * int pc;
569 *
570 * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
571 * if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
572 * event_triggers_call(trace_file, NULL);
573 * if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
574 * return;
575 * }
576 *
577 * local_save_flags(irq_flags);
578 * pc = preempt_count();
579 *
580 * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
581 *
582 * event = trace_event_buffer_lock_reserve(&buffer, trace_file,
583 * event_<call>->event.type,
584 * sizeof(*entry) + __data_size,
585 * irq_flags, pc);
586 * if (!event)
587 * return;
588 * entry = ring_buffer_event_data(event);
589 *
590 * { <assign>; } <-- Here we assign the entries by the __field and
591 * __array macros.
592 *
593 * if (eflags & EVENT_FILE_FL_TRIGGER_COND)
594 * __tt = event_triggers_call(trace_file, entry);
595 *
596 * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
597 * &trace_file->flags))
598 * ring_buffer_discard_commit(buffer, event);
599 * else if (!filter_check_discard(trace_file, entry, buffer, event))
600 * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
601 *
602 * if (__tt)
603 * event_triggers_post_call(trace_file, __tt);
604 * }
605 *
606 * static struct trace_event ftrace_event_type_<call> = {
607 * .trace = trace_raw_output_<call>, <-- stage 2
608 * };
609 *
610 * static char print_fmt_<call>[] = <TP_printk>;
611 *
612 * static struct trace_event_class __used event_class_<template> = {
613 * .system = "<system>",
614 * .define_fields = trace_event_define_fields_<call>,
615 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
616 * .raw_init = trace_event_raw_init,
617 * .probe = trace_event_raw_event_##call,
618 * .reg = trace_event_reg,
619 * };
620 *
621 * static struct trace_event_call event_<call> = {
622 * .class = event_class_<template>,
623 * {
624 * .tp = &__tracepoint_<call>,
625 * },
626 * .event = &ftrace_event_type_<call>,
627 * .print_fmt = print_fmt_<call>,
628 * .flags = TRACE_EVENT_FL_TRACEPOINT,
629 * };
630 * // its only safe to use pointers when doing linker tricks to
631 * // create an array.
632 * static struct trace_event_call __used
633 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
634 *
635 */
636
637#ifdef CONFIG_PERF_EVENTS
638
639#define _TRACE_PERF_PROTO(call, proto) \
640 static notrace void \
641 perf_trace_##call(void *__data, proto);
642
643#define _TRACE_PERF_INIT(call) \
644 .perf_probe = perf_trace_##call,
645
646#else
647#define _TRACE_PERF_PROTO(call, proto)
648#define _TRACE_PERF_INIT(call)
649#endif /* CONFIG_PERF_EVENTS */
650
651#undef __entry
652#define __entry entry
653
654#undef __field
655#define __field(type, item)
656
657#undef __field_struct
658#define __field_struct(type, item)
659
660#undef __array
661#define __array(type, item, len)
662
663#undef __dynamic_array
664#define __dynamic_array(type, item, len) \
665 __entry->__data_loc_##item = __data_offsets.item;
666
667#undef __string
668#define __string(item, src) __dynamic_array(char, item, -1)
669
670#undef __assign_str
671#define __assign_str(dst, src) \
672 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
673
674#undef __bitmask
675#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
676
677#undef __get_bitmask
678#define __get_bitmask(field) (char *)__get_dynamic_array(field)
679
680#undef __assign_bitmask
681#define __assign_bitmask(dst, src, nr_bits) \
682 memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
683
684#undef TP_fast_assign
685#define TP_fast_assign(args...) args
686
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400687#undef __perf_count
688#define __perf_count(c) (c)
689
690#undef __perf_task
691#define __perf_task(t) (t)
692
693#undef DECLARE_EVENT_CLASS
694#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
695 \
696static notrace void \
697trace_event_raw_event_##call(void *__data, proto) \
698{ \
699 struct trace_event_file *trace_file = __data; \
700 struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
701 struct trace_event_buffer fbuffer; \
702 struct trace_event_raw_##call *entry; \
703 int __data_size; \
704 \
705 if (trace_trigger_soft_disabled(trace_file)) \
706 return; \
707 \
708 __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
709 \
710 entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
711 sizeof(*entry) + __data_size); \
712 \
713 if (!entry) \
714 return; \
715 \
716 tstruct \
717 \
718 { assign; } \
719 \
720 trace_event_buffer_commit(&fbuffer); \
721}
722/*
723 * The ftrace_test_probe is compiled out, it is only here as a build time check
724 * to make sure that if the tracepoint handling changes, the ftrace probe will
725 * fail to compile unless it too is updated.
726 */
727
728#undef DEFINE_EVENT
729#define DEFINE_EVENT(template, call, proto, args) \
730static inline void ftrace_test_probe_##call(void) \
731{ \
732 check_trace_callback_type_##call(trace_event_raw_event_##template); \
733}
734
735#undef DEFINE_EVENT_PRINT
736#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
737
738#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
739
740#undef __entry
741#define __entry REC
742
743#undef __print_flags
744#undef __print_symbolic
745#undef __print_hex
Daniel Borkmann2acae0d2017-01-25 02:28:16 +0100746#undef __print_hex_str
Steven Rostedt (Red Hat)46ac5182015-09-23 09:26:27 -0400747#undef __get_dynamic_array
748#undef __get_dynamic_array_len
749#undef __get_str
750#undef __get_bitmask
751#undef __print_array
752
753#undef TP_printk
754#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
755
756#undef DECLARE_EVENT_CLASS
757#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
758_TRACE_PERF_PROTO(call, PARAMS(proto)); \
759static char print_fmt_##call[] = print; \
760static struct trace_event_class __used __refdata event_class_##call = { \
761 .system = TRACE_SYSTEM_STRING, \
762 .define_fields = trace_event_define_fields_##call, \
763 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
764 .raw_init = trace_event_raw_init, \
765 .probe = trace_event_raw_event_##call, \
766 .reg = trace_event_reg, \
767 _TRACE_PERF_INIT(call) \
768};
769
770#undef DEFINE_EVENT
771#define DEFINE_EVENT(template, call, proto, args) \
772 \
773static struct trace_event_call __used event_##call = { \
774 .class = &event_class_##template, \
775 { \
776 .tp = &__tracepoint_##call, \
777 }, \
778 .event.funcs = &trace_event_type_funcs_##template, \
779 .print_fmt = print_fmt_##template, \
780 .flags = TRACE_EVENT_FL_TRACEPOINT, \
781}; \
782static struct trace_event_call __used \
783__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
784
785#undef DEFINE_EVENT_PRINT
786#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
787 \
788static char print_fmt_##call[] = print; \
789 \
790static struct trace_event_call __used event_##call = { \
791 .class = &event_class_##template, \
792 { \
793 .tp = &__tracepoint_##call, \
794 }, \
795 .event.funcs = &trace_event_type_funcs_##call, \
796 .print_fmt = print_fmt_##call, \
797 .flags = TRACE_EVENT_FL_TRACEPOINT, \
798}; \
799static struct trace_event_call __used \
800__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
801
802#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)