blob: 3351d85c83a3b55515a2d2ef42ef87be1abe422f [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 Rostedtff038f52009-11-18 20:27:27 -050021/*
Ingo Molnar091ad362009-11-26 09:04:55 +010022 * DECLARE_EVENT_CLASS can be used to add a generic function
Steven Rostedtff038f52009-11-18 20:27:27 -050023 * handlers for events. That is, if all events have the same
24 * parameters and just have distinct trace points.
25 * Each tracepoint can be defined with DEFINE_EVENT and that
Ingo Molnar091ad362009-11-26 09:04:55 +010026 * will map the DECLARE_EVENT_CLASS to the tracepoint.
Steven Rostedtff038f52009-11-18 20:27:27 -050027 *
28 * TRACE_EVENT is a one to one mapping between tracepoint and template.
29 */
30#undef TRACE_EVENT
31#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
Ingo Molnar091ad362009-11-26 09:04:55 +010032 DECLARE_EVENT_CLASS(name, \
Steven Rostedtff038f52009-11-18 20:27:27 -050033 PARAMS(proto), \
34 PARAMS(args), \
35 PARAMS(tstruct), \
36 PARAMS(assign), \
37 PARAMS(print)); \
38 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
39
40
Steven Rostedtf42c85e2009-04-13 12:25:37 -040041#undef __field
42#define __field(type, item) type item;
43
Li Zefan43b51ea2009-08-07 10:33:22 +080044#undef __field_ext
45#define __field_ext(type, item, filter_type) type item;
46
Li Zefan7fcb7c42009-06-01 15:35:46 +080047#undef __array
48#define __array(type, item, len) type item[len];
49
50#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +080051#define __dynamic_array(type, item, len) u32 __data_loc_##item;
Li Zefan7fcb7c42009-06-01 15:35:46 +080052
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020053#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +080054#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020055
Steven Rostedtf42c85e2009-04-13 12:25:37 -040056#undef TP_STRUCT__entry
57#define TP_STRUCT__entry(args...) args
58
Ingo Molnar091ad362009-11-26 09:04:55 +010059#undef DECLARE_EVENT_CLASS
60#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
Steven Rostedtff038f52009-11-18 20:27:27 -050061 struct ftrace_raw_##name { \
62 struct trace_entry ent; \
63 tstruct \
64 char __data[0]; \
65 };
66#undef DEFINE_EVENT
67#define DEFINE_EVENT(template, name, proto, args) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -040068 static struct ftrace_event_call event_##name
69
Steven Rostedte5bc9722009-11-18 20:36:26 -050070#undef DEFINE_EVENT_PRINT
71#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
72 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
73
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +020074#undef __cpparg
75#define __cpparg(arg...) arg
76
Josh Stone97419872009-08-24 14:43:13 -070077/* Callbacks are meaningless to ftrace. */
78#undef TRACE_EVENT_FN
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +020079#define TRACE_EVENT_FN(name, proto, args, tstruct, \
80 assign, print, reg, unreg) \
81 TRACE_EVENT(name, __cpparg(proto), __cpparg(args), \
82 __cpparg(tstruct), __cpparg(assign), __cpparg(print)) \
Josh Stone97419872009-08-24 14:43:13 -070083
Steven Rostedtf42c85e2009-04-13 12:25:37 -040084#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
85
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020086
Steven Rostedtf42c85e2009-04-13 12:25:37 -040087/*
88 * Stage 2 of the trace events.
89 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020090 * Include the following:
91 *
Li Zefan7fcb7c42009-06-01 15:35:46 +080092 * struct ftrace_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +080093 * u32 <item1>;
94 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020095 * [...]
96 * };
97 *
Li Zefan7d536cb2009-07-16 10:54:02 +080098 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +080099 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +0800100 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200101 */
102
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200103#undef __field
Li Zefan43b51ea2009-08-07 10:33:22 +0800104#define __field(type, item)
105
106#undef __field_ext
107#define __field_ext(type, item, filter_type)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200108
Li Zefan7fcb7c42009-06-01 15:35:46 +0800109#undef __array
110#define __array(type, item, len)
111
112#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +0800113#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800114
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200115#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800116#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200117
Ingo Molnar091ad362009-11-26 09:04:55 +0100118#undef DECLARE_EVENT_CLASS
119#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800120 struct ftrace_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200121 tstruct; \
122 };
123
Steven Rostedtff038f52009-11-18 20:27:27 -0500124#undef DEFINE_EVENT
125#define DEFINE_EVENT(template, name, proto, args)
126
Steven Rostedte5bc9722009-11-18 20:36:26 -0500127#undef DEFINE_EVENT_PRINT
128#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
129 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
130
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200131#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
132
133/*
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400134 * Setup the showing format of trace point.
135 *
136 * int
137 * ftrace_format_##call(struct trace_seq *s)
138 * {
139 * struct ftrace_raw_##call field;
140 * int ret;
141 *
142 * ret = trace_seq_printf(s, #type " " #item ";"
143 * " offset:%u; size:%u;\n",
144 * offsetof(struct ftrace_raw_##call, item),
145 * sizeof(field.type));
146 *
147 * }
148 */
149
150#undef TP_STRUCT__entry
151#define TP_STRUCT__entry(args...) args
152
153#undef __field
154#define __field(type, item) \
155 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
Tom Zanussi26a50742009-10-06 01:09:50 -0500156 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400157 (unsigned int)offsetof(typeof(field), item), \
Tom Zanussi26a50742009-10-06 01:09:50 -0500158 (unsigned int)sizeof(field.item), \
159 (unsigned int)is_signed_type(type)); \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400160 if (!ret) \
161 return 0;
162
Li Zefan43b51ea2009-08-07 10:33:22 +0800163#undef __field_ext
164#define __field_ext(type, item, filter_type) __field(type, item)
165
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400166#undef __array
167#define __array(type, item, len) \
168 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
Tom Zanussi26a50742009-10-06 01:09:50 -0500169 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400170 (unsigned int)offsetof(typeof(field), item), \
Tom Zanussi26a50742009-10-06 01:09:50 -0500171 (unsigned int)sizeof(field.item), \
172 (unsigned int)is_signed_type(type)); \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400173 if (!ret) \
174 return 0;
175
176#undef __dynamic_array
177#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800178 ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
Tom Zanussi26a50742009-10-06 01:09:50 -0500179 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400180 (unsigned int)offsetof(typeof(field), \
181 __data_loc_##item), \
Tom Zanussi26a50742009-10-06 01:09:50 -0500182 (unsigned int)sizeof(field.__data_loc_##item), \
183 (unsigned int)is_signed_type(type)); \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400184 if (!ret) \
185 return 0;
186
187#undef __string
188#define __string(item, src) __dynamic_array(char, item, -1)
189
190#undef __entry
191#define __entry REC
192
193#undef __print_symbolic
194#undef __get_dynamic_array
195#undef __get_str
196
197#undef TP_printk
Johannes Berg811cb502009-11-13 23:40:09 +0100198#define TP_printk(fmt, args...) "\"%s\", %s\n", fmt, __stringify(args)
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400199
200#undef TP_fast_assign
201#define TP_fast_assign(args...) args
202
Peter Zijlstra3a659302009-07-21 17:34:57 +0200203#undef TP_perf_assign
204#define TP_perf_assign(args...)
205
Ingo Molnar091ad362009-11-26 09:04:55 +0100206#undef DECLARE_EVENT_CLASS
207#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400208static int \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500209ftrace_format_setup_##call(struct ftrace_event_call *unused, \
210 struct trace_seq *s) \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400211{ \
212 struct ftrace_raw_##call field __attribute__((unused)); \
213 int ret = 0; \
214 \
215 tstruct; \
216 \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500217 return ret; \
218} \
219 \
220static int \
221ftrace_format_##call(struct ftrace_event_call *unused, \
222 struct trace_seq *s) \
223{ \
224 int ret = 0; \
225 \
226 ret = ftrace_format_setup_##call(unused, s); \
227 if (!ret) \
228 return ret; \
229 \
230 ret = trace_seq_printf(s, "\nprint fmt: " print); \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400231 \
232 return ret; \
233}
234
Steven Rostedtff038f52009-11-18 20:27:27 -0500235#undef DEFINE_EVENT
236#define DEFINE_EVENT(template, name, proto, args)
237
Steven Rostedte5bc9722009-11-18 20:36:26 -0500238#undef DEFINE_EVENT_PRINT
239#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
240static int \
241ftrace_format_##name(struct ftrace_event_call *unused, \
242 struct trace_seq *s) \
243{ \
244 int ret = 0; \
245 \
246 ret = ftrace_format_setup_##template(unused, s); \
247 if (!ret) \
248 return ret; \
249 \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400250 trace_seq_printf(s, "\nprint fmt: " print); \
251 \
252 return ret; \
253}
254
255#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
256
257/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200258 * Stage 3 of the trace events.
259 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400260 * Override the macros in <trace/trace_events.h> to include the following:
261 *
262 * enum print_line_t
263 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
264 * {
265 * struct trace_seq *s = &iter->seq;
266 * struct ftrace_raw_<call> *field; <-- defined in stage 1
267 * struct trace_entry *entry;
Steven Rostedtbe74b732009-05-26 20:25:22 +0200268 * struct trace_seq *p;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400269 * int ret;
270 *
271 * entry = iter->ent;
272 *
273 * if (entry->type != event_<call>.id) {
274 * WARN_ON_ONCE(1);
275 * return TRACE_TYPE_UNHANDLED;
276 * }
277 *
278 * field = (typeof(field))entry;
279 *
Steven Rostedtbe74b732009-05-26 20:25:22 +0200280 * p = get_cpu_var(ftrace_event_seq);
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100281 * trace_seq_init(p);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400282 * ret = trace_seq_printf(s, <TP_printk> "\n");
Steven Rostedtbe74b732009-05-26 20:25:22 +0200283 * put_cpu();
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400284 * if (!ret)
285 * return TRACE_TYPE_PARTIAL_LINE;
286 *
287 * return TRACE_TYPE_HANDLED;
288 * }
289 *
290 * This is the method used to print the raw event to the trace
291 * output format. Note, this is not needed if the data is read
292 * in binary.
293 */
294
295#undef __entry
296#define __entry field
297
298#undef TP_printk
299#define TP_printk(fmt, args...) fmt "\n", args
300
Li Zefan7fcb7c42009-06-01 15:35:46 +0800301#undef __get_dynamic_array
302#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800303 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800304
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200305#undef __get_str
Li Zefan7fcb7c42009-06-01 15:35:46 +0800306#define __get_str(field) (char *)__get_dynamic_array(field)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200307
Steven Rostedtbe74b732009-05-26 20:25:22 +0200308#undef __print_flags
309#define __print_flags(flag, delim, flag_array...) \
310 ({ \
Steven Rostedta48f4942009-09-14 11:18:02 -0400311 static const struct trace_print_flags __flags[] = \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200312 { flag_array, { -1, NULL }}; \
Steven Rostedta48f4942009-09-14 11:18:02 -0400313 ftrace_print_flags_seq(p, delim, flag, __flags); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200314 })
315
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400316#undef __print_symbolic
317#define __print_symbolic(value, symbol_array...) \
318 ({ \
319 static const struct trace_print_flags symbols[] = \
320 { symbol_array, { -1, NULL }}; \
321 ftrace_print_symbols_seq(p, value, symbols); \
322 })
323
Ingo Molnar091ad362009-11-26 09:04:55 +0100324#undef DECLARE_EVENT_CLASS
325#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedtec827c72009-09-14 10:50:23 -0400326static enum print_line_t \
Steven Rostedtff038f52009-11-18 20:27:27 -0500327ftrace_raw_output_id_##call(int event_id, const char *name, \
328 struct trace_iterator *iter, int flags) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400329{ \
330 struct trace_seq *s = &iter->seq; \
331 struct ftrace_raw_##call *field; \
332 struct trace_entry *entry; \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200333 struct trace_seq *p; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400334 int ret; \
335 \
336 entry = iter->ent; \
337 \
Steven Rostedtff038f52009-11-18 20:27:27 -0500338 if (entry->type != event_id) { \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400339 WARN_ON_ONCE(1); \
340 return TRACE_TYPE_UNHANDLED; \
341 } \
342 \
343 field = (typeof(field))entry; \
344 \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200345 p = &get_cpu_var(ftrace_event_seq); \
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100346 trace_seq_init(p); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500347 ret = trace_seq_printf(s, "%s: ", name); \
348 if (ret) \
349 ret = trace_seq_printf(s, print); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200350 put_cpu(); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400351 if (!ret) \
352 return TRACE_TYPE_PARTIAL_LINE; \
353 \
354 return TRACE_TYPE_HANDLED; \
355}
Steven Rostedtff038f52009-11-18 20:27:27 -0500356
357#undef DEFINE_EVENT
358#define DEFINE_EVENT(template, name, proto, args) \
359static enum print_line_t \
360ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
361{ \
362 return ftrace_raw_output_id_##template(event_##name.id, \
363 #name, iter, flags); \
364}
365
Steven Rostedte5bc9722009-11-18 20:36:26 -0500366#undef DEFINE_EVENT_PRINT
367#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400368static enum print_line_t \
369ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
370{ \
371 struct trace_seq *s = &iter->seq; \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500372 struct ftrace_raw_##template *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400373 struct trace_entry *entry; \
374 struct trace_seq *p; \
375 int ret; \
376 \
377 entry = iter->ent; \
378 \
379 if (entry->type != event_##call.id) { \
380 WARN_ON_ONCE(1); \
381 return TRACE_TYPE_UNHANDLED; \
382 } \
383 \
384 field = (typeof(field))entry; \
385 \
386 p = &get_cpu_var(ftrace_event_seq); \
387 trace_seq_init(p); \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500388 ret = trace_seq_printf(s, "%s: ", #call); \
389 if (ret) \
390 ret = trace_seq_printf(s, print); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400391 put_cpu(); \
392 if (!ret) \
393 return TRACE_TYPE_PARTIAL_LINE; \
394 \
395 return TRACE_TYPE_HANDLED; \
396}
Steven Rostedte5bc9722009-11-18 20:36:26 -0500397
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400398#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
399
Li Zefan43b51ea2009-08-07 10:33:22 +0800400#undef __field_ext
401#define __field_ext(type, item, filter_type) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400402 ret = trace_define_field(event_call, #type, #item, \
403 offsetof(typeof(field), item), \
Li Zefan43b51ea2009-08-07 10:33:22 +0800404 sizeof(field.item), \
405 is_signed_type(type), filter_type); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400406 if (ret) \
407 return ret;
408
Li Zefan43b51ea2009-08-07 10:33:22 +0800409#undef __field
410#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
411
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400412#undef __array
413#define __array(type, item, len) \
414 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
415 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
416 offsetof(typeof(field), item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800417 sizeof(field.item), \
418 is_signed_type(type), FILTER_OTHER); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400419 if (ret) \
420 return ret;
421
Li Zefan7fcb7c42009-06-01 15:35:46 +0800422#undef __dynamic_array
423#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800424 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
Li Zefan43b51ea2009-08-07 10:33:22 +0800425 offsetof(typeof(field), __data_loc_##item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800426 sizeof(field.__data_loc_##item), \
427 is_signed_type(type), FILTER_OTHER);
Li Zefan7fcb7c42009-06-01 15:35:46 +0800428
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200429#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800430#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200431
Ingo Molnar091ad362009-11-26 09:04:55 +0100432#undef DECLARE_EVENT_CLASS
433#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Steven Rostedtec827c72009-09-14 10:50:23 -0400434static int \
Li Zefan14be96c2009-08-19 15:53:52 +0800435ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400436{ \
437 struct ftrace_raw_##call field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400438 int ret; \
439 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400440 tstruct; \
441 \
442 return ret; \
443}
444
Steven Rostedtff038f52009-11-18 20:27:27 -0500445#undef DEFINE_EVENT
446#define DEFINE_EVENT(template, name, proto, args)
447
Steven Rostedte5bc9722009-11-18 20:36:26 -0500448#undef DEFINE_EVENT_PRINT
449#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
450 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
451
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400452#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
453
454/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800455 * remember the offset of each array from the beginning of the event.
456 */
457
458#undef __entry
459#define __entry entry
460
461#undef __field
462#define __field(type, item)
463
Li Zefan43b51ea2009-08-07 10:33:22 +0800464#undef __field_ext
465#define __field_ext(type, item, filter_type)
466
Li Zefan7fcb7c42009-06-01 15:35:46 +0800467#undef __array
468#define __array(type, item, len)
469
470#undef __dynamic_array
471#define __dynamic_array(type, item, len) \
472 __data_offsets->item = __data_size + \
473 offsetof(typeof(*entry), __data); \
Li Zefan7d536cb2009-07-16 10:54:02 +0800474 __data_offsets->item |= (len * sizeof(type)) << 16; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800475 __data_size += (len) * sizeof(type);
476
477#undef __string
Steven Rostedtff038f52009-11-18 20:27:27 -0500478#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
Li Zefan7fcb7c42009-06-01 15:35:46 +0800479
Ingo Molnar091ad362009-11-26 09:04:55 +0100480#undef DECLARE_EVENT_CLASS
481#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800482static inline int ftrace_get_offsets_##call( \
483 struct ftrace_data_offsets_##call *__data_offsets, proto) \
484{ \
485 int __data_size = 0; \
486 struct ftrace_raw_##call __maybe_unused *entry; \
487 \
488 tstruct; \
489 \
490 return __data_size; \
491}
492
Steven Rostedtff038f52009-11-18 20:27:27 -0500493#undef DEFINE_EVENT
494#define DEFINE_EVENT(template, name, proto, args)
495
Steven Rostedte5bc9722009-11-18 20:36:26 -0500496#undef DEFINE_EVENT_PRINT
497#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
498 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
499
Li Zefan7fcb7c42009-06-01 15:35:46 +0800500#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
501
Peter Zijlstra3a659302009-07-21 17:34:57 +0200502#ifdef CONFIG_EVENT_PROFILE
503
504/*
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200505 * Generate the functions needed for tracepoint perf_event support.
Peter Zijlstra3a659302009-07-21 17:34:57 +0200506 *
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200507 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
Peter Zijlstra3a659302009-07-21 17:34:57 +0200508 *
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200509 * static int ftrace_profile_enable_<call>(void)
Peter Zijlstra3a659302009-07-21 17:34:57 +0200510 * {
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200511 * return register_trace_<call>(ftrace_profile_<call>);
Peter Zijlstra3a659302009-07-21 17:34:57 +0200512 * }
513 *
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200514 * static void ftrace_profile_disable_<call>(void)
Peter Zijlstra3a659302009-07-21 17:34:57 +0200515 * {
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200516 * unregister_trace_<call>(ftrace_profile_<call>);
Peter Zijlstra3a659302009-07-21 17:34:57 +0200517 * }
518 *
519 */
520
Ingo Molnar091ad362009-11-26 09:04:55 +0100521#undef DECLARE_EVENT_CLASS
522#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
Steven Rostedtff038f52009-11-18 20:27:27 -0500523
524#undef DEFINE_EVENT
525#define DEFINE_EVENT(template, name, proto, args) \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200526 \
Steven Rostedtff038f52009-11-18 20:27:27 -0500527static void ftrace_profile_##name(proto); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200528 \
Steven Rostedtff038f52009-11-18 20:27:27 -0500529static int ftrace_profile_enable_##name(struct ftrace_event_call *unused)\
Peter Zijlstra3a659302009-07-21 17:34:57 +0200530{ \
Steven Rostedtff038f52009-11-18 20:27:27 -0500531 return register_trace_##name(ftrace_profile_##name); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200532} \
533 \
Steven Rostedtff038f52009-11-18 20:27:27 -0500534static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\
Peter Zijlstra3a659302009-07-21 17:34:57 +0200535{ \
Steven Rostedtff038f52009-11-18 20:27:27 -0500536 unregister_trace_##name(ftrace_profile_##name); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200537}
538
Steven Rostedte5bc9722009-11-18 20:36:26 -0500539#undef DEFINE_EVENT_PRINT
540#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
541 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
542
Peter Zijlstra3a659302009-07-21 17:34:57 +0200543#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
544
Peter Zijlstra3a659302009-07-21 17:34:57 +0200545#endif
546
Li Zefan7fcb7c42009-06-01 15:35:46 +0800547/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200548 * Stage 4 of the trace events.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400549 *
550 * Override the macros in <trace/trace_events.h> to include the following:
551 *
552 * static void ftrace_event_<call>(proto)
553 * {
554 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
555 * }
556 *
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400557 * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400558 * {
Li Zefan3b8e4272009-12-08 11:14:52 +0800559 * return register_trace_<call>(ftrace_event_<call>);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400560 * }
561 *
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400562 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400563 * {
564 * unregister_trace_<call>(ftrace_event_<call>);
565 * }
566 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400567 *
568 * For those macros defined with TRACE_EVENT:
569 *
570 * static struct ftrace_event_call event_<call>;
571 *
572 * static void ftrace_raw_event_<call>(proto)
573 * {
574 * struct ring_buffer_event *event;
575 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
Steven Rostedte77405a2009-09-02 14:17:06 -0400576 * struct ring_buffer *buffer;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400577 * unsigned long irq_flags;
578 * int pc;
579 *
580 * local_save_flags(irq_flags);
581 * pc = preempt_count();
582 *
Steven Rostedte77405a2009-09-02 14:17:06 -0400583 * event = trace_current_buffer_lock_reserve(&buffer,
584 * event_<call>.id,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400585 * sizeof(struct ftrace_raw_<call>),
586 * irq_flags, pc);
587 * if (!event)
588 * return;
589 * entry = ring_buffer_event_data(event);
590 *
591 * <assign>; <-- Here we assign the entries by the __field and
592 * __array macros.
593 *
Steven Rostedte77405a2009-09-02 14:17:06 -0400594 * trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400595 * }
596 *
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400597 * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400598 * {
599 * int ret;
600 *
601 * ret = register_trace_<call>(ftrace_raw_event_<call>);
602 * if (!ret)
603 * pr_info("event trace: Could not activate trace point "
604 * "probe to <call>");
605 * return ret;
606 * }
607 *
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400608 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400609 * {
610 * unregister_trace_<call>(ftrace_raw_event_<call>);
611 * }
612 *
613 * static struct trace_event ftrace_event_type_<call> = {
614 * .trace = ftrace_raw_output_<call>, <-- stage 2
615 * };
616 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400617 * static struct ftrace_event_call __used
618 * __attribute__((__aligned__(4)))
619 * __attribute__((section("_ftrace_events"))) event_<call> = {
620 * .name = "<call>",
621 * .system = "<system>",
Li Zefan87d9b4e2009-12-08 11:14:20 +0800622 * .raw_init = trace_event_raw_init,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400623 * .regfunc = ftrace_reg_event_<call>,
624 * .unregfunc = ftrace_unreg_event_<call>,
625 * .show_format = ftrace_format_<call>,
626 * }
627 *
628 */
629
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400630#ifdef CONFIG_EVENT_PROFILE
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400631
632#define _TRACE_PROFILE_INIT(call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400633 .profile_enable = ftrace_profile_enable_##call, \
634 .profile_disable = ftrace_profile_disable_##call,
635
636#else
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400637#define _TRACE_PROFILE_INIT(call)
638#endif
639
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400640#undef __entry
641#define __entry entry
642
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200643#undef __field
644#define __field(type, item)
645
646#undef __array
647#define __array(type, item, len)
648
Li Zefan7fcb7c42009-06-01 15:35:46 +0800649#undef __dynamic_array
650#define __dynamic_array(type, item, len) \
651 __entry->__data_loc_##item = __data_offsets.item;
652
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200653#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800654#define __string(item, src) __dynamic_array(char, item, -1) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200655
656#undef __assign_str
657#define __assign_str(dst, src) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200658 strcpy(__get_str(dst), src);
659
Ingo Molnar091ad362009-11-26 09:04:55 +0100660#undef DECLARE_EVENT_CLASS
661#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400662 \
Steven Rostedtff038f52009-11-18 20:27:27 -0500663static void ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
664 proto) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400665{ \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800666 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400667 struct ring_buffer_event *event; \
668 struct ftrace_raw_##call *entry; \
Steven Rostedte77405a2009-09-02 14:17:06 -0400669 struct ring_buffer *buffer; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400670 unsigned long irq_flags; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800671 int __data_size; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400672 int pc; \
673 \
674 local_save_flags(irq_flags); \
675 pc = preempt_count(); \
676 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800677 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200678 \
Steven Rostedte77405a2009-09-02 14:17:06 -0400679 event = trace_current_buffer_lock_reserve(&buffer, \
Steven Rostedtff038f52009-11-18 20:27:27 -0500680 event_call->id, \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800681 sizeof(*entry) + __data_size, \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200682 irq_flags, pc); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400683 if (!event) \
684 return; \
685 entry = ring_buffer_event_data(event); \
686 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800687 \
688 tstruct \
689 \
Li Zefana9c1c3a2009-06-01 15:35:13 +0800690 { assign; } \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400691 \
Steven Rostedte77405a2009-09-02 14:17:06 -0400692 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
693 trace_nowake_buffer_unlock_commit(buffer, \
694 event, irq_flags, pc); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500695}
696
697#undef DEFINE_EVENT
698#define DEFINE_EVENT(template, call, proto, args) \
699 \
700static void ftrace_raw_event_##call(proto) \
701{ \
702 ftrace_raw_event_id_##template(&event_##call, args); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400703} \
704 \
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400705static int ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)\
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400706{ \
Li Zefan3b8e4272009-12-08 11:14:52 +0800707 return register_trace_##call(ftrace_raw_event_##call); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400708} \
709 \
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400710static void ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused)\
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400711{ \
712 unregister_trace_##call(ftrace_raw_event_##call); \
713} \
714 \
715static struct trace_event ftrace_event_type_##call = { \
716 .trace = ftrace_raw_output_##call, \
Li Zefan87d9b4e2009-12-08 11:14:20 +0800717};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500718
719#undef DEFINE_EVENT_PRINT
720#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
721 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
722
723#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
724
Lai Jiangshan509e7602009-12-15 15:39:42 +0800725#undef __entry
726#define __entry REC
727
728#undef __print_flags
729#undef __print_symbolic
730#undef __get_dynamic_array
731#undef __get_str
732
733#undef TP_printk
734#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
735
Ingo Molnar091ad362009-11-26 09:04:55 +0100736#undef DECLARE_EVENT_CLASS
Lai Jiangshan509e7602009-12-15 15:39:42 +0800737#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
738static const char print_fmt_##call[] = print;
Steven Rostedte5bc9722009-11-18 20:36:26 -0500739
740#undef DEFINE_EVENT
741#define DEFINE_EVENT(template, call, proto, args) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400742 \
743static struct ftrace_event_call __used \
744__attribute__((__aligned__(4))) \
745__attribute__((section("_ftrace_events"))) event_##call = { \
746 .name = #call, \
747 .system = __stringify(TRACE_SYSTEM), \
Steven Rostedt6d723732009-04-10 14:53:50 -0400748 .event = &ftrace_event_type_##call, \
Li Zefan87d9b4e2009-12-08 11:14:20 +0800749 .raw_init = trace_event_raw_init, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400750 .regfunc = ftrace_raw_reg_event_##call, \
751 .unregfunc = ftrace_raw_unreg_event_##call, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800752 .print_fmt = print_fmt_##template, \
Steven Rostedtff038f52009-11-18 20:27:27 -0500753 .show_format = ftrace_format_##template, \
754 .define_fields = ftrace_define_fields_##template, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400755 _TRACE_PROFILE_INIT(call) \
756}
757
Steven Rostedte5bc9722009-11-18 20:36:26 -0500758#undef DEFINE_EVENT_PRINT
759#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400760 \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800761static const char print_fmt_##call[] = print; \
762 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400763static struct ftrace_event_call __used \
764__attribute__((__aligned__(4))) \
765__attribute__((section("_ftrace_events"))) event_##call = { \
766 .name = #call, \
767 .system = __stringify(TRACE_SYSTEM), \
768 .event = &ftrace_event_type_##call, \
Li Zefan87d9b4e2009-12-08 11:14:20 +0800769 .raw_init = trace_event_raw_init, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400770 .regfunc = ftrace_raw_reg_event_##call, \
771 .unregfunc = ftrace_raw_unreg_event_##call, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800772 .print_fmt = print_fmt_##call, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400773 .show_format = ftrace_format_##call, \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500774 .define_fields = ftrace_define_fields_##template, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400775 _TRACE_PROFILE_INIT(call) \
776}
777
778#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
779
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200780/*
781 * Define the insertion callback to profile events
782 *
783 * The job is very similar to ftrace_raw_event_<call> except that we don't
784 * insert in the ring buffer but in a perf counter.
785 *
786 * static void ftrace_profile_<call>(proto)
787 * {
788 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
789 * struct ftrace_event_call *event_call = &event_<call>;
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200790 * extern void perf_tp_event(int, u64, u64, void *, int);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200791 * struct ftrace_raw_##call *entry;
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100792 * struct perf_trace_buf *trace_buf;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200793 * u64 __addr = 0, __count = 1;
794 * unsigned long irq_flags;
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200795 * struct trace_entry *ent;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200796 * int __entry_size;
797 * int __data_size;
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200798 * int __cpu
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200799 * int pc;
800 *
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200801 * pc = preempt_count();
802 *
803 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200804 *
805 * // Below we want to get the aligned size by taking into account
806 * // the u32 field that will later store the buffer size
807 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
808 * sizeof(u64));
809 * __entry_size -= sizeof(u32);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200810 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200811 * // Protect the non nmi buffer
812 * // This also protects the rcu read side
813 * local_irq_save(irq_flags);
814 * __cpu = smp_processor_id();
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200815 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200816 * if (in_nmi())
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100817 * trace_buf = rcu_dereference(perf_trace_buf_nmi);
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200818 * else
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100819 * trace_buf = rcu_dereference(perf_trace_buf);
Frederic Weisbecker1853db02009-08-10 16:38:36 +0200820 *
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100821 * if (!trace_buf)
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200822 * goto end;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200823 *
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100824 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
825 *
826 * // Avoid recursion from perf that could mess up the buffer
827 * if (trace_buf->recursion++)
828 * goto end_recursion;
829 *
830 * raw_data = trace_buf->buf;
831 *
832 * // Make recursion update visible before entering perf_tp_event
833 * // so that we protect from perf recursions.
834 *
835 * barrier();
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200836 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200837 * //zero dead bytes from alignment to avoid stack leak to userspace:
838 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
839 * entry = (struct ftrace_raw_<call> *)raw_data;
840 * ent = &entry->ent;
841 * tracing_generic_entry_update(ent, irq_flags, pc);
842 * ent->type = event_call->id;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200843 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200844 * <tstruct> <- do some jobs with dynamic arrays
845 *
846 * <assign> <- affect our values
847 *
Linus Torvalds43c12662009-09-21 09:15:07 -0700848 * perf_tp_event(event_call->id, __addr, __count, entry,
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200849 * __entry_size); <- submit them to perf counter
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200850 *
851 * }
852 */
853
854#ifdef CONFIG_EVENT_PROFILE
855
Lai Jiangshan509e7602009-12-15 15:39:42 +0800856#undef __entry
857#define __entry entry
858
859#undef __get_dynamic_array
860#define __get_dynamic_array(field) \
861 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
862
863#undef __get_str
864#define __get_str(field) (char *)__get_dynamic_array(field)
865
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200866#undef __perf_addr
867#define __perf_addr(a) __addr = (a)
868
869#undef __perf_count
870#define __perf_count(c) __count = (c)
871
Ingo Molnar091ad362009-11-26 09:04:55 +0100872#undef DECLARE_EVENT_CLASS
873#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedtff038f52009-11-18 20:27:27 -0500874static void \
875ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
876 proto) \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200877{ \
878 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Peter Zijlstra4ed7c922009-11-23 11:37:29 +0100879 extern int perf_swevent_get_recursion_context(void); \
880 extern void perf_swevent_put_recursion_context(int rctx); \
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100881 extern void perf_tp_event(int, u64, u64, void *, int); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200882 struct ftrace_raw_##call *entry; \
883 u64 __addr = 0, __count = 1; \
884 unsigned long irq_flags; \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200885 struct trace_entry *ent; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200886 int __entry_size; \
887 int __data_size; \
Frederic Weisbeckerce71b9d2009-11-22 05:26:55 +0100888 char *trace_buf; \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200889 char *raw_data; \
890 int __cpu; \
Peter Zijlstra4ed7c922009-11-23 11:37:29 +0100891 int rctx; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200892 int pc; \
893 \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200894 pc = preempt_count(); \
895 \
896 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Peter Zijlstraa0445602009-08-10 11:16:52 +0200897 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
898 sizeof(u64)); \
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200899 __entry_size -= sizeof(u32); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200900 \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200901 if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE, \
902 "profile buffer not large enough")) \
903 return; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200904 \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200905 local_irq_save(irq_flags); \
Frederic Weisbeckerce71b9d2009-11-22 05:26:55 +0100906 \
Peter Zijlstra4ed7c922009-11-23 11:37:29 +0100907 rctx = perf_swevent_get_recursion_context(); \
908 if (rctx < 0) \
909 goto end_recursion; \
Frederic Weisbeckerce71b9d2009-11-22 05:26:55 +0100910 \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200911 __cpu = smp_processor_id(); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200912 \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200913 if (in_nmi()) \
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100914 trace_buf = rcu_dereference(perf_trace_buf_nmi); \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200915 else \
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100916 trace_buf = rcu_dereference(perf_trace_buf); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200917 \
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100918 if (!trace_buf) \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200919 goto end; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200920 \
Frederic Weisbeckerce71b9d2009-11-22 05:26:55 +0100921 raw_data = per_cpu_ptr(trace_buf, __cpu); \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200922 \
923 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
924 entry = (struct ftrace_raw_##call *)raw_data; \
925 ent = &entry->ent; \
926 tracing_generic_entry_update(ent, irq_flags, pc); \
927 ent->type = event_call->id; \
928 \
929 tstruct \
930 \
931 { assign; } \
932 \
Linus Torvalds43c12662009-09-21 09:15:07 -0700933 perf_tp_event(event_call->id, __addr, __count, entry, \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200934 __entry_size); \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200935 \
936end: \
Peter Zijlstra4ed7c922009-11-23 11:37:29 +0100937 perf_swevent_put_recursion_context(rctx); \
938end_recursion: \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200939 local_irq_restore(irq_flags); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200940}
941
Steven Rostedtff038f52009-11-18 20:27:27 -0500942#undef DEFINE_EVENT
943#define DEFINE_EVENT(template, call, proto, args) \
944static void ftrace_profile_##call(proto) \
945{ \
946 struct ftrace_event_call *event_call = &event_##call; \
947 \
948 ftrace_profile_templ_##template(event_call, args); \
949}
950
Steven Rostedte5bc9722009-11-18 20:36:26 -0500951#undef DEFINE_EVENT_PRINT
952#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
953 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
954
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200955#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
956#endif /* CONFIG_EVENT_PROFILE */
957
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400958#undef _TRACE_PROFILE_INIT
959