blob: 2f9b95b6d3fb92f7cc150dadcba34ce6f7a754a6 [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 *
6 * struct ftrace_raw_<call> {
7 * 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
19#include <linux/ftrace_event.h>
20
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 Rostedtff038f52009-11-18 20:27:27 -050036/*
Ingo Molnar091ad362009-11-26 09:04:55 +010037 * DECLARE_EVENT_CLASS can be used to add a generic function
Steven Rostedtff038f52009-11-18 20:27:27 -050038 * handlers for events. That is, if all events have the same
39 * parameters and just have distinct trace points.
40 * Each tracepoint can be defined with DEFINE_EVENT and that
Ingo Molnar091ad362009-11-26 09:04:55 +010041 * will map the DECLARE_EVENT_CLASS to the tracepoint.
Steven Rostedtff038f52009-11-18 20:27:27 -050042 *
43 * TRACE_EVENT is a one to one mapping between tracepoint and template.
44 */
45#undef TRACE_EVENT
46#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
Ingo Molnar091ad362009-11-26 09:04:55 +010047 DECLARE_EVENT_CLASS(name, \
Steven Rostedtff038f52009-11-18 20:27:27 -050048 PARAMS(proto), \
49 PARAMS(args), \
50 PARAMS(tstruct), \
51 PARAMS(assign), \
52 PARAMS(print)); \
53 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
54
55
Steven Rostedtf42c85e2009-04-13 12:25:37 -040056#undef __field
57#define __field(type, item) type item;
58
Li Zefan43b51ea2009-08-07 10:33:22 +080059#undef __field_ext
60#define __field_ext(type, item, filter_type) type item;
61
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -040062#undef __field_struct
63#define __field_struct(type, item) type item;
64
65#undef __field_struct_ext
66#define __field_struct_ext(type, item, filter_type) type item;
67
Li Zefan7fcb7c42009-06-01 15:35:46 +080068#undef __array
69#define __array(type, item, len) type item[len];
70
71#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +080072#define __dynamic_array(type, item, len) u32 __data_loc_##item;
Li Zefan7fcb7c42009-06-01 15:35:46 +080073
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020074#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +080075#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020076
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -040077#undef __bitmask
78#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
79
Steven Rostedtf42c85e2009-04-13 12:25:37 -040080#undef TP_STRUCT__entry
81#define TP_STRUCT__entry(args...) args
82
Ingo Molnar091ad362009-11-26 09:04:55 +010083#undef DECLARE_EVENT_CLASS
84#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
Steven Rostedtff038f52009-11-18 20:27:27 -050085 struct ftrace_raw_##name { \
86 struct trace_entry ent; \
87 tstruct \
88 char __data[0]; \
Steven Rostedt8f082012010-04-20 10:47:33 -040089 }; \
90 \
91 static struct ftrace_event_class event_class_##name;
92
Steven Rostedtff038f52009-11-18 20:27:27 -050093#undef DEFINE_EVENT
94#define DEFINE_EVENT(template, name, proto, args) \
Steven Rostedt49c17742010-05-25 06:19:35 -070095 static struct ftrace_event_call __used \
Jeff Mahoney86c38a32010-02-24 13:59:23 -050096 __attribute__((__aligned__(4))) event_##name
Steven Rostedtf42c85e2009-04-13 12:25:37 -040097
Steven Rostedtf5abaa12013-06-20 11:44:44 -040098#undef DEFINE_EVENT_FN
99#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
100 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
101
Steven Rostedte5bc9722009-11-18 20:36:26 -0500102#undef DEFINE_EVENT_PRINT
103#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
104 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
105
Josh Stone97419872009-08-24 14:43:13 -0700106/* Callbacks are meaningless to ftrace. */
107#undef TRACE_EVENT_FN
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +0200108#define TRACE_EVENT_FN(name, proto, args, tstruct, \
109 assign, print, reg, unreg) \
Frederic Weisbecker819ce452010-07-20 18:41:24 +0200110 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
111 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
Josh Stone97419872009-08-24 14:43:13 -0700112
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100113#undef TRACE_EVENT_FLAGS
114#define TRACE_EVENT_FLAGS(name, value) \
Frederic Weisbecker53cf810b2010-11-18 02:11:42 +0100115 __TRACE_EVENT_FLAGS(name, value)
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100116
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100117#undef TRACE_EVENT_PERF_PERM
118#define TRACE_EVENT_PERF_PERM(name, expr...) \
119 __TRACE_EVENT_PERF_PERM(name, expr)
120
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400121#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
122
123/*
124 * Stage 2 of the trace events.
125 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200126 * Include the following:
127 *
Li Zefan7fcb7c42009-06-01 15:35:46 +0800128 * struct ftrace_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +0800129 * u32 <item1>;
130 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200131 * [...]
132 * };
133 *
Li Zefan7d536cb2009-07-16 10:54:02 +0800134 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +0800135 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +0800136 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200137 */
138
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200139#undef __field
Li Zefan43b51ea2009-08-07 10:33:22 +0800140#define __field(type, item)
141
142#undef __field_ext
143#define __field_ext(type, item, filter_type)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200144
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400145#undef __field_struct
146#define __field_struct(type, item)
147
148#undef __field_struct_ext
149#define __field_struct_ext(type, item, filter_type)
150
Li Zefan7fcb7c42009-06-01 15:35:46 +0800151#undef __array
152#define __array(type, item, len)
153
154#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +0800155#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800156
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200157#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800158#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200159
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400160#undef __bitmask
161#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
162
Ingo Molnar091ad362009-11-26 09:04:55 +0100163#undef DECLARE_EVENT_CLASS
164#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800165 struct ftrace_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200166 tstruct; \
167 };
168
Steven Rostedtff038f52009-11-18 20:27:27 -0500169#undef DEFINE_EVENT
170#define DEFINE_EVENT(template, name, proto, args)
171
Steven Rostedte5bc9722009-11-18 20:36:26 -0500172#undef DEFINE_EVENT_PRINT
173#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
174 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
175
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100176#undef TRACE_EVENT_FLAGS
177#define TRACE_EVENT_FLAGS(event, flag)
178
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100179#undef TRACE_EVENT_PERF_PERM
180#define TRACE_EVENT_PERF_PERM(event, expr...)
181
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200182#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
183
184/*
185 * Stage 3 of the trace events.
186 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400187 * Override the macros in <trace/trace_events.h> to include the following:
188 *
189 * enum print_line_t
190 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
191 * {
192 * struct trace_seq *s = &iter->seq;
193 * struct ftrace_raw_<call> *field; <-- defined in stage 1
194 * struct trace_entry *entry;
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800195 * struct trace_seq *p = &iter->tmp_seq;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400196 * int ret;
197 *
198 * entry = iter->ent;
199 *
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400200 * if (entry->type != event_<call>->event.type) {
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400201 * WARN_ON_ONCE(1);
202 * return TRACE_TYPE_UNHANDLED;
203 * }
204 *
205 * field = (typeof(field))entry;
206 *
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100207 * trace_seq_init(p);
Li Zefan50354a82010-03-24 10:58:24 +0800208 * ret = trace_seq_printf(s, "%s: ", <call>);
209 * if (ret)
210 * ret = trace_seq_printf(s, <TP_printk> "\n");
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400211 * if (!ret)
212 * return TRACE_TYPE_PARTIAL_LINE;
213 *
214 * return TRACE_TYPE_HANDLED;
215 * }
216 *
217 * This is the method used to print the raw event to the trace
218 * output format. Note, this is not needed if the data is read
219 * in binary.
220 */
221
222#undef __entry
223#define __entry field
224
225#undef TP_printk
226#define TP_printk(fmt, args...) fmt "\n", args
227
Li Zefan7fcb7c42009-06-01 15:35:46 +0800228#undef __get_dynamic_array
229#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800230 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800231
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400232#undef __get_dynamic_array_len
233#define __get_dynamic_array_len(field) \
234 ((__entry->__data_loc_##field >> 16) & 0xffff)
235
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200236#undef __get_str
Li Zefan7fcb7c42009-06-01 15:35:46 +0800237#define __get_str(field) (char *)__get_dynamic_array(field)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200238
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400239#undef __get_bitmask
240#define __get_bitmask(field) \
241 ({ \
242 void *__bitmask = __get_dynamic_array(field); \
243 unsigned int __bitmask_size; \
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400244 __bitmask_size = __get_dynamic_array_len(field); \
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400245 ftrace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
246 })
247
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200248#undef __print_flags
249#define __print_flags(flag, delim, flag_array...) \
250 ({ \
Steven Rostedta48f4942009-09-14 11:18:02 -0400251 static const struct trace_print_flags __flags[] = \
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200252 { flag_array, { -1, NULL }}; \
Steven Rostedta48f4942009-09-14 11:18:02 -0400253 ftrace_print_flags_seq(p, delim, flag, __flags); \
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200254 })
255
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400256#undef __print_symbolic
257#define __print_symbolic(value, symbol_array...) \
258 ({ \
259 static const struct trace_print_flags symbols[] = \
260 { symbol_array, { -1, NULL }}; \
261 ftrace_print_symbols_seq(p, value, symbols); \
262 })
263
liubo2fc1b6f2011-04-19 09:35:28 +0800264#undef __print_symbolic_u64
265#if BITS_PER_LONG == 32
266#define __print_symbolic_u64(value, symbol_array...) \
267 ({ \
268 static const struct trace_print_flags_u64 symbols[] = \
269 { symbol_array, { -1, NULL } }; \
270 ftrace_print_symbols_seq_u64(p, value, symbols); \
271 })
272#else
273#define __print_symbolic_u64(value, symbol_array...) \
274 __print_symbolic(value, symbol_array)
275#endif
276
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900277#undef __print_hex
278#define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
279
Dave Martin6ea22482015-01-28 12:48:53 +0000280#undef __print_array
281#define __print_array(array, count, el_size) \
282 ({ \
283 BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
284 el_size != 4 && el_size != 8); \
285 ftrace_print_array_seq(p, array, count, el_size); \
286 })
287
Ingo Molnar091ad362009-11-26 09:04:55 +0100288#undef DECLARE_EVENT_CLASS
289#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500290static notrace enum print_line_t \
Steven Rostedt80decc72010-04-23 10:00:22 -0400291ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
292 struct trace_event *trace_event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400293{ \
294 struct trace_seq *s = &iter->seq; \
Li Zefanf71130d2013-02-21 10:32:38 +0800295 struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400296 struct ftrace_raw_##call *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400297 int ret; \
298 \
Li Zefanf71130d2013-02-21 10:32:38 +0800299 field = (typeof(field))iter->ent; \
Steven Rostedt80decc72010-04-23 10:00:22 -0400300 \
Li Zefanf71130d2013-02-21 10:32:38 +0800301 ret = ftrace_raw_output_prep(iter, trace_event); \
Steven Rostedt (Red Hat)8e2e0952014-11-14 11:42:06 -0500302 if (ret != TRACE_TYPE_HANDLED) \
Li Zefanf71130d2013-02-21 10:32:38 +0800303 return ret; \
304 \
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500305 trace_seq_printf(s, print); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400306 \
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500307 return trace_handle_return(s); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400308} \
309static struct trace_event_functions ftrace_event_type_funcs_##call = { \
310 .trace = ftrace_raw_output_##call, \
311};
Steven Rostedtff038f52009-11-18 20:27:27 -0500312
Steven Rostedte5bc9722009-11-18 20:36:26 -0500313#undef DEFINE_EVENT_PRINT
314#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500315static notrace enum print_line_t \
Steven Rostedta9a57762010-04-22 18:46:14 -0400316ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
317 struct trace_event *event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400318{ \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500319 struct ftrace_raw_##template *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400320 struct trace_entry *entry; \
Lai Jiangshanbc289ae2010-06-03 18:26:24 +0800321 struct trace_seq *p = &iter->tmp_seq; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400322 \
323 entry = iter->ent; \
324 \
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400325 if (entry->type != event_##call.event.type) { \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400326 WARN_ON_ONCE(1); \
327 return TRACE_TYPE_UNHANDLED; \
328 } \
329 \
330 field = (typeof(field))entry; \
331 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400332 trace_seq_init(p); \
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400333 return ftrace_output_call(iter, #call, print); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400334} \
335static struct trace_event_functions ftrace_event_type_funcs_##call = { \
336 .trace = ftrace_raw_output_##call, \
337};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500338
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400339#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
340
Li Zefan43b51ea2009-08-07 10:33:22 +0800341#undef __field_ext
342#define __field_ext(type, item, filter_type) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400343 ret = trace_define_field(event_call, #type, #item, \
344 offsetof(typeof(field), item), \
Li Zefan43b51ea2009-08-07 10:33:22 +0800345 sizeof(field.item), \
346 is_signed_type(type), filter_type); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400347 if (ret) \
348 return ret;
349
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400350#undef __field_struct_ext
351#define __field_struct_ext(type, item, filter_type) \
352 ret = trace_define_field(event_call, #type, #item, \
353 offsetof(typeof(field), item), \
354 sizeof(field.item), \
355 0, filter_type); \
356 if (ret) \
357 return ret;
358
Li Zefan43b51ea2009-08-07 10:33:22 +0800359#undef __field
360#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
361
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400362#undef __field_struct
363#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
364
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400365#undef __array
366#define __array(type, item, len) \
Steven Rostedt04295782010-11-12 22:32:11 -0500367 do { \
Vaibhav Nagarnaik87291342014-02-13 19:51:48 -0800368 char *type_str = #type"["__stringify(len)"]"; \
Steven Rostedt04295782010-11-12 22:32:11 -0500369 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
Vaibhav Nagarnaik87291342014-02-13 19:51:48 -0800370 ret = trace_define_field(event_call, type_str, #item, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400371 offsetof(typeof(field), item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800372 sizeof(field.item), \
373 is_signed_type(type), FILTER_OTHER); \
Steven Rostedt04295782010-11-12 22:32:11 -0500374 if (ret) \
375 return ret; \
376 } while (0);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400377
Li Zefan7fcb7c42009-06-01 15:35:46 +0800378#undef __dynamic_array
379#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800380 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
Li Zefan43b51ea2009-08-07 10:33:22 +0800381 offsetof(typeof(field), __data_loc_##item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800382 sizeof(field.__data_loc_##item), \
383 is_signed_type(type), FILTER_OTHER);
Li Zefan7fcb7c42009-06-01 15:35:46 +0800384
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200385#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800386#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200387
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400388#undef __bitmask
389#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
390
Ingo Molnar091ad362009-11-26 09:04:55 +0100391#undef DECLARE_EVENT_CLASS
392#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Li Zefan7e4f44b2013-02-21 10:33:33 +0800393static int notrace __init \
Li Zefan14be96c2009-08-19 15:53:52 +0800394ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400395{ \
396 struct ftrace_raw_##call field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400397 int ret; \
398 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400399 tstruct; \
400 \
401 return ret; \
402}
403
Steven Rostedtff038f52009-11-18 20:27:27 -0500404#undef DEFINE_EVENT
405#define DEFINE_EVENT(template, name, proto, args)
406
Steven Rostedte5bc9722009-11-18 20:36:26 -0500407#undef DEFINE_EVENT_PRINT
408#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
409 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
410
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400411#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
412
413/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800414 * remember the offset of each array from the beginning of the event.
415 */
416
417#undef __entry
418#define __entry entry
419
420#undef __field
421#define __field(type, item)
422
Li Zefan43b51ea2009-08-07 10:33:22 +0800423#undef __field_ext
424#define __field_ext(type, item, filter_type)
425
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400426#undef __field_struct
427#define __field_struct(type, item)
428
429#undef __field_struct_ext
430#define __field_struct_ext(type, item, filter_type)
431
Li Zefan7fcb7c42009-06-01 15:35:46 +0800432#undef __array
433#define __array(type, item, len)
434
435#undef __dynamic_array
436#define __dynamic_array(type, item, len) \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800437 __item_length = (len) * sizeof(type); \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800438 __data_offsets->item = __data_size + \
439 offsetof(typeof(*entry), __data); \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800440 __data_offsets->item |= __item_length << 16; \
441 __data_size += __item_length;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800442
443#undef __string
Steven Rostedt (Red Hat)4e58e542013-11-26 09:22:54 -0500444#define __string(item, src) __dynamic_array(char, item, \
445 strlen((src) ? (const char *)(src) : "(null)") + 1)
Li Zefan7fcb7c42009-06-01 15:35:46 +0800446
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400447/*
448 * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
449 * num_possible_cpus().
450 */
451#define __bitmask_size_in_bytes_raw(nr_bits) \
452 (((nr_bits) + 7) / 8)
453
454#define __bitmask_size_in_longs(nr_bits) \
455 ((__bitmask_size_in_bytes_raw(nr_bits) + \
456 ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
457
458/*
459 * __bitmask_size_in_bytes is the number of bytes needed to hold
460 * num_possible_cpus() padded out to the nearest long. This is what
461 * is saved in the buffer, just to be consistent.
462 */
463#define __bitmask_size_in_bytes(nr_bits) \
464 (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
465
466#undef __bitmask
467#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
468 __bitmask_size_in_longs(nr_bits))
469
Ingo Molnar091ad362009-11-26 09:04:55 +0100470#undef DECLARE_EVENT_CLASS
471#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500472static inline notrace int ftrace_get_offsets_##call( \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800473 struct ftrace_data_offsets_##call *__data_offsets, proto) \
474{ \
475 int __data_size = 0; \
Filipe Brandenburger114e7b52014-02-28 21:32:17 -0800476 int __maybe_unused __item_length; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800477 struct ftrace_raw_##call __maybe_unused *entry; \
478 \
479 tstruct; \
480 \
481 return __data_size; \
482}
483
Steven Rostedtff038f52009-11-18 20:27:27 -0500484#undef DEFINE_EVENT
485#define DEFINE_EVENT(template, name, proto, args)
486
Steven Rostedte5bc9722009-11-18 20:36:26 -0500487#undef DEFINE_EVENT_PRINT
488#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
489 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
490
Li Zefan7fcb7c42009-06-01 15:35:46 +0800491#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
492
493/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200494 * Stage 4 of the trace events.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400495 *
496 * Override the macros in <trace/trace_events.h> to include the following:
497 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400498 * For those macros defined with TRACE_EVENT:
499 *
500 * static struct ftrace_event_call event_<call>;
501 *
Steven Rostedt22392912010-04-21 12:27:06 -0400502 * static void ftrace_raw_event_<call>(void *__data, proto)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400503 * {
Steven Rostedtccb469a2012-08-02 10:32:10 -0400504 * struct ftrace_event_file *ftrace_file = __data;
505 * struct ftrace_event_call *event_call = ftrace_file->event_call;
Li Zefan50354a82010-03-24 10:58:24 +0800506 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
Tom Zanussibac5fb92013-10-24 08:59:29 -0500507 * unsigned long eflags = ftrace_file->flags;
508 * enum event_trigger_type __tt = ETT_NONE;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400509 * struct ring_buffer_event *event;
510 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
Steven Rostedte77405a2009-09-02 14:17:06 -0400511 * struct ring_buffer *buffer;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400512 * unsigned long irq_flags;
Li Zefan50354a82010-03-24 10:58:24 +0800513 * int __data_size;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400514 * int pc;
515 *
Tom Zanussibac5fb92013-10-24 08:59:29 -0500516 * if (!(eflags & FTRACE_EVENT_FL_TRIGGER_COND)) {
517 * if (eflags & FTRACE_EVENT_FL_TRIGGER_MODE)
518 * event_triggers_call(ftrace_file, NULL);
519 * if (eflags & FTRACE_EVENT_FL_SOFT_DISABLED)
520 * return;
521 * }
Steven Rostedt (Red Hat)417944c2013-03-12 13:26:18 -0400522 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400523 * local_save_flags(irq_flags);
524 * pc = preempt_count();
525 *
Li Zefan50354a82010-03-24 10:58:24 +0800526 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
527 *
Steven Rostedtccb469a2012-08-02 10:32:10 -0400528 * event = trace_event_buffer_lock_reserve(&buffer, ftrace_file,
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400529 * event_<call>->event.type,
Li Zefan50354a82010-03-24 10:58:24 +0800530 * sizeof(*entry) + __data_size,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400531 * irq_flags, pc);
532 * if (!event)
533 * return;
534 * entry = ring_buffer_event_data(event);
535 *
Li Zefan50354a82010-03-24 10:58:24 +0800536 * { <assign>; } <-- Here we assign the entries by the __field and
537 * __array macros.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400538 *
Tom Zanussibac5fb92013-10-24 08:59:29 -0500539 * if (eflags & FTRACE_EVENT_FL_TRIGGER_COND)
540 * __tt = event_triggers_call(ftrace_file, entry);
541 *
542 * if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
543 * &ftrace_file->flags))
544 * ring_buffer_discard_commit(buffer, event);
545 * else if (!filter_check_discard(ftrace_file, entry, buffer, event))
Tom Zanussif306cc82013-10-24 08:34:17 -0500546 * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
Tom Zanussibac5fb92013-10-24 08:59:29 -0500547 *
548 * if (__tt)
549 * event_triggers_post_call(ftrace_file, __tt);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400550 * }
551 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400552 * static struct trace_event ftrace_event_type_<call> = {
553 * .trace = ftrace_raw_output_<call>, <-- stage 2
554 * };
555 *
Li Zefan50354a82010-03-24 10:58:24 +0800556 * static const char print_fmt_<call>[] = <TP_printk>;
557 *
Steven Rostedt8f082012010-04-20 10:47:33 -0400558 * static struct ftrace_event_class __used event_class_<template> = {
559 * .system = "<system>",
Steven Rostedt2e33af02010-04-22 10:35:55 -0400560 * .define_fields = ftrace_define_fields_<call>,
Steven Rostedt0405ab82010-04-22 11:46:44 -0400561 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
562 * .raw_init = trace_event_raw_init,
563 * .probe = ftrace_raw_event_##call,
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400564 * .reg = ftrace_event_reg,
Steven Rostedt8f082012010-04-20 10:47:33 -0400565 * };
566 *
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500567 * static struct ftrace_event_call event_<call> = {
Steven Rostedt8f082012010-04-20 10:47:33 -0400568 * .class = event_class_<template>,
Mathieu Desnoyersabb43f62014-04-09 17:06:08 -0400569 * {
570 * .tp = &__tracepoint_<call>,
571 * },
Steven Rostedt2e33af02010-04-22 10:35:55 -0400572 * .event = &ftrace_event_type_<call>,
Li Zefan50354a82010-03-24 10:58:24 +0800573 * .print_fmt = print_fmt_<call>,
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -0400574 * .flags = TRACE_EVENT_FL_TRACEPOINT,
Steven Rostedt8f082012010-04-20 10:47:33 -0400575 * };
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500576 * // its only safe to use pointers when doing linker tricks to
577 * // create an array.
578 * static struct ftrace_event_call __used
579 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400580 *
581 */
582
Li Zefan07b139c2009-12-21 14:27:35 +0800583#ifdef CONFIG_PERF_EVENTS
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400584
Steven Rostedt22392912010-04-21 12:27:06 -0400585#define _TRACE_PERF_PROTO(call, proto) \
586 static notrace void \
587 perf_trace_##call(void *__data, proto);
588
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100589#define _TRACE_PERF_INIT(call) \
Steven Rostedt22392912010-04-21 12:27:06 -0400590 .perf_probe = perf_trace_##call,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400591
592#else
Steven Rostedt22392912010-04-21 12:27:06 -0400593#define _TRACE_PERF_PROTO(call, proto)
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100594#define _TRACE_PERF_INIT(call)
Li Zefan07b139c2009-12-21 14:27:35 +0800595#endif /* CONFIG_PERF_EVENTS */
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400596
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400597#undef __entry
598#define __entry entry
599
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200600#undef __field
601#define __field(type, item)
602
Steven Rostedt4d4c9cc2014-06-17 08:59:16 -0400603#undef __field_struct
604#define __field_struct(type, item)
605
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200606#undef __array
607#define __array(type, item, len)
608
Li Zefan7fcb7c42009-06-01 15:35:46 +0800609#undef __dynamic_array
610#define __dynamic_array(type, item, len) \
611 __entry->__data_loc_##item = __data_offsets.item;
612
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200613#undef __string
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400614#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200615
616#undef __assign_str
617#define __assign_str(dst, src) \
Steven Rostedt (Red Hat)4e58e542013-11-26 09:22:54 -0500618 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200619
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400620#undef __bitmask
621#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
622
623#undef __get_bitmask
624#define __get_bitmask(field) (char *)__get_dynamic_array(field)
625
626#undef __assign_bitmask
627#define __assign_bitmask(dst, src, nr_bits) \
628 memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
629
Lai Jiangshan0fa0eda2009-12-15 15:39:57 +0800630#undef TP_fast_assign
631#define TP_fast_assign(args...) args
632
Oleg Nesterov12473962013-08-06 18:08:44 +0200633#undef __perf_addr
634#define __perf_addr(a) (a)
635
636#undef __perf_count
637#define __perf_count(c) (c)
638
639#undef __perf_task
640#define __perf_task(t) (t)
Lai Jiangshan0fa0eda2009-12-15 15:39:57 +0800641
Ingo Molnar091ad362009-11-26 09:04:55 +0100642#undef DECLARE_EVENT_CLASS
643#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400644 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500645static notrace void \
Steven Rostedt22392912010-04-21 12:27:06 -0400646ftrace_raw_event_##call(void *__data, proto) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400647{ \
Steven Rostedtae63b31e2012-05-03 23:09:03 -0400648 struct ftrace_event_file *ftrace_file = __data; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800649 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Steven Rostedt3fd40d12012-08-09 22:42:57 -0400650 struct ftrace_event_buffer fbuffer; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400651 struct ftrace_raw_##call *entry; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800652 int __data_size; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400653 \
Steven Rostedt (Red Hat)13a1e4a2014-01-06 21:32:10 -0500654 if (ftrace_trigger_soft_disabled(ftrace_file)) \
655 return; \
Steven Rostedt (Red Hat)417944c2013-03-12 13:26:18 -0400656 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800657 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200658 \
Steven Rostedt3fd40d12012-08-09 22:42:57 -0400659 entry = ftrace_event_buffer_reserve(&fbuffer, ftrace_file, \
660 sizeof(*entry) + __data_size); \
661 \
662 if (!entry) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400663 return; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400664 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800665 tstruct \
666 \
Li Zefana9c1c3a2009-06-01 15:35:13 +0800667 { assign; } \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400668 \
Steven Rostedt3fd40d12012-08-09 22:42:57 -0400669 ftrace_event_buffer_commit(&fbuffer); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500670}
Steven Rostedt22392912010-04-21 12:27:06 -0400671/*
672 * The ftrace_test_probe is compiled out, it is only here as a build time check
673 * to make sure that if the tracepoint handling changes, the ftrace probe will
674 * fail to compile unless it too is updated.
675 */
Steven Rostedtff038f52009-11-18 20:27:27 -0500676
677#undef DEFINE_EVENT
678#define DEFINE_EVENT(template, call, proto, args) \
Steven Rostedt22392912010-04-21 12:27:06 -0400679static inline void ftrace_test_probe_##call(void) \
Steven Rostedtff038f52009-11-18 20:27:27 -0500680{ \
Steven Rostedt22392912010-04-21 12:27:06 -0400681 check_trace_callback_type_##call(ftrace_raw_event_##template); \
682}
Steven Rostedte5bc9722009-11-18 20:36:26 -0500683
684#undef DEFINE_EVENT_PRINT
Steven Rostedt80decc72010-04-23 10:00:22 -0400685#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
Steven Rostedte5bc9722009-11-18 20:36:26 -0500686
687#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
688
Lai Jiangshan509e7602009-12-15 15:39:42 +0800689#undef __entry
690#define __entry REC
691
692#undef __print_flags
693#undef __print_symbolic
Namhyung Kimb102f1d2012-06-27 09:41:39 +0900694#undef __print_hex
Lai Jiangshan509e7602009-12-15 15:39:42 +0800695#undef __get_dynamic_array
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400696#undef __get_dynamic_array_len
Lai Jiangshan509e7602009-12-15 15:39:42 +0800697#undef __get_str
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400698#undef __get_bitmask
Dave Martin6ea22482015-01-28 12:48:53 +0000699#undef __print_array
Lai Jiangshan509e7602009-12-15 15:39:42 +0800700
701#undef TP_printk
702#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
703
Ingo Molnar091ad362009-11-26 09:04:55 +0100704#undef DECLARE_EVENT_CLASS
Lai Jiangshan509e7602009-12-15 15:39:42 +0800705#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt22392912010-04-21 12:27:06 -0400706_TRACE_PERF_PROTO(call, PARAMS(proto)); \
Steven Rostedt8f082012010-04-20 10:47:33 -0400707static const char print_fmt_##call[] = print; \
Li Zefan523c8112013-03-04 14:15:59 +0800708static struct ftrace_event_class __used __refdata event_class_##call = { \
Steven Rostedt (Red Hat)acd388f2015-03-31 14:37:12 -0400709 .system = TRACE_SYSTEM_STRING, \
Steven Rostedt2e33af02010-04-22 10:35:55 -0400710 .define_fields = ftrace_define_fields_##call, \
711 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
Steven Rostedt0405ab82010-04-22 11:46:44 -0400712 .raw_init = trace_event_raw_init, \
Steven Rostedt22392912010-04-21 12:27:06 -0400713 .probe = ftrace_raw_event_##call, \
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400714 .reg = ftrace_event_reg, \
Steven Rostedt22392912010-04-21 12:27:06 -0400715 _TRACE_PERF_INIT(call) \
Steven Rostedt8f082012010-04-20 10:47:33 -0400716};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500717
718#undef DEFINE_EVENT
719#define DEFINE_EVENT(template, call, proto, args) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400720 \
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500721static struct ftrace_event_call __used event_##call = { \
Steven Rostedt8f082012010-04-20 10:47:33 -0400722 .class = &event_class_##template, \
Mathieu Desnoyersabb43f62014-04-09 17:06:08 -0400723 { \
724 .tp = &__tracepoint_##call, \
725 }, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400726 .event.funcs = &ftrace_event_type_funcs_##template, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800727 .print_fmt = print_fmt_##template, \
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -0400728 .flags = TRACE_EVENT_FL_TRACEPOINT, \
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500729}; \
730static struct ftrace_event_call __used \
731__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400732
Steven Rostedte5bc9722009-11-18 20:36:26 -0500733#undef DEFINE_EVENT_PRINT
734#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400735 \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800736static const char print_fmt_##call[] = print; \
737 \
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500738static struct ftrace_event_call __used event_##call = { \
Steven Rostedt8f082012010-04-20 10:47:33 -0400739 .class = &event_class_##template, \
Mathieu Desnoyersabb43f62014-04-09 17:06:08 -0400740 { \
741 .tp = &__tracepoint_##call, \
742 }, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400743 .event.funcs = &ftrace_event_type_funcs_##call, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800744 .print_fmt = print_fmt_##call, \
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -0400745 .flags = TRACE_EVENT_FL_TRACEPOINT, \
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500746}; \
747static struct ftrace_event_call __used \
748__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400749
750#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
751
Steven Rostedt (Red Hat)acd388f2015-03-31 14:37:12 -0400752#undef TRACE_SYSTEM_VAR
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200753
Li Zefan07b139c2009-12-21 14:27:35 +0800754#ifdef CONFIG_PERF_EVENTS
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200755
Lai Jiangshan509e7602009-12-15 15:39:42 +0800756#undef __entry
757#define __entry entry
758
759#undef __get_dynamic_array
760#define __get_dynamic_array(field) \
761 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
762
Steven Rostedt (Red Hat)beba4bb2014-06-04 14:29:33 -0400763#undef __get_dynamic_array_len
764#define __get_dynamic_array_len(field) \
765 ((__entry->__data_loc_##field >> 16) & 0xffff)
766
Lai Jiangshan509e7602009-12-15 15:39:42 +0800767#undef __get_str
768#define __get_str(field) (char *)__get_dynamic_array(field)
769
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400770#undef __get_bitmask
771#define __get_bitmask(field) (char *)__get_dynamic_array(field)
772
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200773#undef __perf_addr
Oleg Nesterov12473962013-08-06 18:08:44 +0200774#define __perf_addr(a) (__addr = (a))
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200775
776#undef __perf_count
Oleg Nesterov12473962013-08-06 18:08:44 +0200777#define __perf_count(c) (__count = (c))
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200778
Andrew Vagine6dab5f2012-07-11 18:14:58 +0400779#undef __perf_task
Oleg Nesterov12473962013-08-06 18:08:44 +0200780#define __perf_task(t) (__task = (t))
Andrew Vagin92e51932011-09-26 19:55:32 +0400781
Ingo Molnar091ad362009-11-26 09:04:55 +0100782#undef DECLARE_EVENT_CLASS
783#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500784static notrace void \
Steven Rostedt22392912010-04-21 12:27:06 -0400785perf_trace_##call(void *__data, proto) \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200786{ \
Steven Rostedt22392912010-04-21 12:27:06 -0400787 struct ftrace_event_call *event_call = __data; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200788 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200789 struct ftrace_raw_##call *entry; \
Peter Zijlstra (Intel)86038c52014-12-16 12:47:34 +0100790 struct pt_regs *__regs; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200791 u64 __addr = 0, __count = 1; \
Andrew Vagine6dab5f2012-07-11 18:14:58 +0400792 struct task_struct *__task = NULL; \
Peter Zijlstra1c024eca2010-05-19 14:02:22 +0200793 struct hlist_head *head; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200794 int __entry_size; \
795 int __data_size; \
Peter Zijlstra4ed7c922009-11-23 11:37:29 +0100796 int rctx; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200797 \
798 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Oleg Nesterovd027e6a2013-08-06 18:08:47 +0200799 \
800 head = this_cpu_ptr(event_call->perf_events); \
801 if (__builtin_constant_p(!__task) && !__task && \
802 hlist_empty(head)) \
803 return; \
804 \
Peter Zijlstraa0445602009-08-10 11:16:52 +0200805 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
806 sizeof(u64)); \
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200807 __entry_size -= sizeof(u32); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200808 \
Oleg Nesterov36009d072013-08-06 18:08:41 +0200809 entry = perf_trace_buf_prepare(__entry_size, \
810 event_call->event.type, &__regs, &rctx); \
Xiao Guangrong430ad5a2010-01-28 09:32:29 +0800811 if (!entry) \
812 return; \
Peter Zijlstrab7e2ece2010-05-19 10:52:27 +0200813 \
Peter Zijlstra (Intel)86038c52014-12-16 12:47:34 +0100814 perf_fetch_caller_regs(__regs); \
815 \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200816 tstruct \
817 \
818 { assign; } \
819 \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100820 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
Peter Zijlstra (Intel)86038c52014-12-16 12:47:34 +0100821 __count, __regs, head, __task); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200822}
823
Steven Rostedt22392912010-04-21 12:27:06 -0400824/*
825 * This part is compiled out, it is only here as a build time check
826 * to make sure that if the tracepoint handling changes, the
827 * perf probe will fail to compile unless it too is updated.
828 */
Steven Rostedtff038f52009-11-18 20:27:27 -0500829#undef DEFINE_EVENT
Frederic Weisbecker6cc8a7c2010-03-19 01:23:53 +0100830#define DEFINE_EVENT(template, call, proto, args) \
Steven Rostedt22392912010-04-21 12:27:06 -0400831static inline void perf_test_probe_##call(void) \
Frederic Weisbecker6cc8a7c2010-03-19 01:23:53 +0100832{ \
Steven Rostedt22392912010-04-21 12:27:06 -0400833 check_trace_callback_type_##call(perf_trace_##template); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500834}
835
Steven Rostedt22392912010-04-21 12:27:06 -0400836
Steven Rostedte5bc9722009-11-18 20:36:26 -0500837#undef DEFINE_EVENT_PRINT
838#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
839 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
840
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200841#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
Li Zefan07b139c2009-12-21 14:27:35 +0800842#endif /* CONFIG_PERF_EVENTS */
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200843