blob: 824141d5cf04b4469f50fe07b1b4ee83f984706e [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]; \
Steven Rostedt8f082012010-04-20 10:47:33 -040065 }; \
66 \
67 static struct ftrace_event_class event_class_##name;
68
Steven Rostedtff038f52009-11-18 20:27:27 -050069#undef DEFINE_EVENT
70#define DEFINE_EVENT(template, name, proto, args) \
Jeff Mahoney86c38a32010-02-24 13:59:23 -050071 static struct ftrace_event_call \
72 __attribute__((__aligned__(4))) event_##name
Steven Rostedtf42c85e2009-04-13 12:25:37 -040073
Steven Rostedte5bc9722009-11-18 20:36:26 -050074#undef DEFINE_EVENT_PRINT
75#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
76 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
77
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +020078#undef __cpparg
79#define __cpparg(arg...) arg
80
Josh Stone97419872009-08-24 14:43:13 -070081/* Callbacks are meaningless to ftrace. */
82#undef TRACE_EVENT_FN
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +020083#define TRACE_EVENT_FN(name, proto, args, tstruct, \
84 assign, print, reg, unreg) \
85 TRACE_EVENT(name, __cpparg(proto), __cpparg(args), \
86 __cpparg(tstruct), __cpparg(assign), __cpparg(print)) \
Josh Stone97419872009-08-24 14:43:13 -070087
Steven Rostedtf42c85e2009-04-13 12:25:37 -040088#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
89
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020090
Steven Rostedtf42c85e2009-04-13 12:25:37 -040091/*
92 * Stage 2 of the trace events.
93 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020094 * Include the following:
95 *
Li Zefan7fcb7c42009-06-01 15:35:46 +080096 * struct ftrace_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +080097 * u32 <item1>;
98 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020099 * [...]
100 * };
101 *
Li Zefan7d536cb2009-07-16 10:54:02 +0800102 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +0800103 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +0800104 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200105 */
106
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200107#undef __field
Li Zefan43b51ea2009-08-07 10:33:22 +0800108#define __field(type, item)
109
110#undef __field_ext
111#define __field_ext(type, item, filter_type)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200112
Li Zefan7fcb7c42009-06-01 15:35:46 +0800113#undef __array
114#define __array(type, item, len)
115
116#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +0800117#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +0800118
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200119#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800120#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200121
Ingo Molnar091ad362009-11-26 09:04:55 +0100122#undef DECLARE_EVENT_CLASS
123#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800124 struct ftrace_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200125 tstruct; \
126 };
127
Steven Rostedtff038f52009-11-18 20:27:27 -0500128#undef DEFINE_EVENT
129#define DEFINE_EVENT(template, name, proto, args)
130
Steven Rostedte5bc9722009-11-18 20:36:26 -0500131#undef DEFINE_EVENT_PRINT
132#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
133 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
134
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200135#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
136
137/*
138 * Stage 3 of the trace events.
139 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400140 * Override the macros in <trace/trace_events.h> to include the following:
141 *
142 * enum print_line_t
143 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
144 * {
145 * struct trace_seq *s = &iter->seq;
146 * struct ftrace_raw_<call> *field; <-- defined in stage 1
147 * struct trace_entry *entry;
Steven Rostedtbe74b732009-05-26 20:25:22 +0200148 * struct trace_seq *p;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400149 * int ret;
150 *
151 * entry = iter->ent;
152 *
153 * if (entry->type != event_<call>.id) {
154 * WARN_ON_ONCE(1);
155 * return TRACE_TYPE_UNHANDLED;
156 * }
157 *
158 * field = (typeof(field))entry;
159 *
Li Zefan50354a82010-03-24 10:58:24 +0800160 * p = &get_cpu_var(ftrace_event_seq);
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100161 * trace_seq_init(p);
Li Zefan50354a82010-03-24 10:58:24 +0800162 * ret = trace_seq_printf(s, "%s: ", <call>);
163 * if (ret)
164 * ret = trace_seq_printf(s, <TP_printk> "\n");
Steven Rostedtbe74b732009-05-26 20:25:22 +0200165 * put_cpu();
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400166 * if (!ret)
167 * return TRACE_TYPE_PARTIAL_LINE;
168 *
169 * return TRACE_TYPE_HANDLED;
170 * }
171 *
172 * This is the method used to print the raw event to the trace
173 * output format. Note, this is not needed if the data is read
174 * in binary.
175 */
176
177#undef __entry
178#define __entry field
179
180#undef TP_printk
181#define TP_printk(fmt, args...) fmt "\n", args
182
Li Zefan7fcb7c42009-06-01 15:35:46 +0800183#undef __get_dynamic_array
184#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800185 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800186
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200187#undef __get_str
Li Zefan7fcb7c42009-06-01 15:35:46 +0800188#define __get_str(field) (char *)__get_dynamic_array(field)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200189
Steven Rostedtbe74b732009-05-26 20:25:22 +0200190#undef __print_flags
191#define __print_flags(flag, delim, flag_array...) \
192 ({ \
Steven Rostedta48f4942009-09-14 11:18:02 -0400193 static const struct trace_print_flags __flags[] = \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200194 { flag_array, { -1, NULL }}; \
Steven Rostedta48f4942009-09-14 11:18:02 -0400195 ftrace_print_flags_seq(p, delim, flag, __flags); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200196 })
197
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400198#undef __print_symbolic
199#define __print_symbolic(value, symbol_array...) \
200 ({ \
201 static const struct trace_print_flags symbols[] = \
202 { symbol_array, { -1, NULL }}; \
203 ftrace_print_symbols_seq(p, value, symbols); \
204 })
205
Ingo Molnar091ad362009-11-26 09:04:55 +0100206#undef DECLARE_EVENT_CLASS
207#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500208static notrace enum print_line_t \
Steven Rostedt80decc72010-04-23 10:00:22 -0400209ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
210 struct trace_event *trace_event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400211{ \
Steven Rostedt80decc72010-04-23 10:00:22 -0400212 struct ftrace_event_call *event; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400213 struct trace_seq *s = &iter->seq; \
214 struct ftrace_raw_##call *field; \
215 struct trace_entry *entry; \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200216 struct trace_seq *p; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400217 int ret; \
218 \
Steven Rostedt80decc72010-04-23 10:00:22 -0400219 event = container_of(trace_event, struct ftrace_event_call, \
220 event); \
221 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400222 entry = iter->ent; \
223 \
Steven Rostedt80decc72010-04-23 10:00:22 -0400224 if (entry->type != event->id) { \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400225 WARN_ON_ONCE(1); \
226 return TRACE_TYPE_UNHANDLED; \
227 } \
228 \
229 field = (typeof(field))entry; \
230 \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200231 p = &get_cpu_var(ftrace_event_seq); \
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100232 trace_seq_init(p); \
Steven Rostedt80decc72010-04-23 10:00:22 -0400233 ret = trace_seq_printf(s, "%s: ", event->name); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500234 if (ret) \
235 ret = trace_seq_printf(s, print); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200236 put_cpu(); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400237 if (!ret) \
238 return TRACE_TYPE_PARTIAL_LINE; \
239 \
240 return TRACE_TYPE_HANDLED; \
Steven Rostedt80decc72010-04-23 10:00:22 -0400241} \
242static struct trace_event_functions ftrace_event_type_funcs_##call = { \
243 .trace = ftrace_raw_output_##call, \
244};
Steven Rostedtff038f52009-11-18 20:27:27 -0500245
Steven Rostedte5bc9722009-11-18 20:36:26 -0500246#undef DEFINE_EVENT_PRINT
247#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500248static notrace enum print_line_t \
Steven Rostedta9a57762010-04-22 18:46:14 -0400249ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
250 struct trace_event *event) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400251{ \
252 struct trace_seq *s = &iter->seq; \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500253 struct ftrace_raw_##template *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400254 struct trace_entry *entry; \
255 struct trace_seq *p; \
256 int ret; \
257 \
258 entry = iter->ent; \
259 \
260 if (entry->type != event_##call.id) { \
261 WARN_ON_ONCE(1); \
262 return TRACE_TYPE_UNHANDLED; \
263 } \
264 \
265 field = (typeof(field))entry; \
266 \
267 p = &get_cpu_var(ftrace_event_seq); \
268 trace_seq_init(p); \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500269 ret = trace_seq_printf(s, "%s: ", #call); \
270 if (ret) \
271 ret = trace_seq_printf(s, print); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400272 put_cpu(); \
273 if (!ret) \
274 return TRACE_TYPE_PARTIAL_LINE; \
275 \
276 return TRACE_TYPE_HANDLED; \
Steven Rostedt80decc72010-04-23 10:00:22 -0400277} \
278static struct trace_event_functions ftrace_event_type_funcs_##call = { \
279 .trace = ftrace_raw_output_##call, \
280};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500281
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400282#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
283
Li Zefan43b51ea2009-08-07 10:33:22 +0800284#undef __field_ext
285#define __field_ext(type, item, filter_type) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400286 ret = trace_define_field(event_call, #type, #item, \
287 offsetof(typeof(field), item), \
Li Zefan43b51ea2009-08-07 10:33:22 +0800288 sizeof(field.item), \
289 is_signed_type(type), filter_type); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400290 if (ret) \
291 return ret;
292
Li Zefan43b51ea2009-08-07 10:33:22 +0800293#undef __field
294#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
295
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400296#undef __array
297#define __array(type, item, len) \
298 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
299 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
300 offsetof(typeof(field), item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800301 sizeof(field.item), \
302 is_signed_type(type), FILTER_OTHER); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400303 if (ret) \
304 return ret;
305
Li Zefan7fcb7c42009-06-01 15:35:46 +0800306#undef __dynamic_array
307#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800308 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
Li Zefan43b51ea2009-08-07 10:33:22 +0800309 offsetof(typeof(field), __data_loc_##item), \
Lai Jiangshanfb7ae982009-12-15 15:39:38 +0800310 sizeof(field.__data_loc_##item), \
311 is_signed_type(type), FILTER_OTHER);
Li Zefan7fcb7c42009-06-01 15:35:46 +0800312
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200313#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800314#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200315
Ingo Molnar091ad362009-11-26 09:04:55 +0100316#undef DECLARE_EVENT_CLASS
317#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500318static int notrace \
Li Zefan14be96c2009-08-19 15:53:52 +0800319ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400320{ \
321 struct ftrace_raw_##call field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400322 int ret; \
323 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400324 tstruct; \
325 \
326 return ret; \
327}
328
Steven Rostedtff038f52009-11-18 20:27:27 -0500329#undef DEFINE_EVENT
330#define DEFINE_EVENT(template, name, proto, args)
331
Steven Rostedte5bc9722009-11-18 20:36:26 -0500332#undef DEFINE_EVENT_PRINT
333#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
334 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
335
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400336#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
337
338/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800339 * remember the offset of each array from the beginning of the event.
340 */
341
342#undef __entry
343#define __entry entry
344
345#undef __field
346#define __field(type, item)
347
Li Zefan43b51ea2009-08-07 10:33:22 +0800348#undef __field_ext
349#define __field_ext(type, item, filter_type)
350
Li Zefan7fcb7c42009-06-01 15:35:46 +0800351#undef __array
352#define __array(type, item, len)
353
354#undef __dynamic_array
355#define __dynamic_array(type, item, len) \
356 __data_offsets->item = __data_size + \
357 offsetof(typeof(*entry), __data); \
Li Zefan7d536cb2009-07-16 10:54:02 +0800358 __data_offsets->item |= (len * sizeof(type)) << 16; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800359 __data_size += (len) * sizeof(type);
360
361#undef __string
Steven Rostedtff038f52009-11-18 20:27:27 -0500362#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
Li Zefan7fcb7c42009-06-01 15:35:46 +0800363
Ingo Molnar091ad362009-11-26 09:04:55 +0100364#undef DECLARE_EVENT_CLASS
365#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500366static inline notrace int ftrace_get_offsets_##call( \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800367 struct ftrace_data_offsets_##call *__data_offsets, proto) \
368{ \
369 int __data_size = 0; \
370 struct ftrace_raw_##call __maybe_unused *entry; \
371 \
372 tstruct; \
373 \
374 return __data_size; \
375}
376
Steven Rostedtff038f52009-11-18 20:27:27 -0500377#undef DEFINE_EVENT
378#define DEFINE_EVENT(template, name, proto, args)
379
Steven Rostedte5bc9722009-11-18 20:36:26 -0500380#undef DEFINE_EVENT_PRINT
381#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
382 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
383
Li Zefan7fcb7c42009-06-01 15:35:46 +0800384#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
385
386/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200387 * Stage 4 of the trace events.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400388 *
389 * Override the macros in <trace/trace_events.h> to include the following:
390 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400391 * For those macros defined with TRACE_EVENT:
392 *
393 * static struct ftrace_event_call event_<call>;
394 *
Steven Rostedt22392912010-04-21 12:27:06 -0400395 * static void ftrace_raw_event_<call>(void *__data, proto)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400396 * {
Steven Rostedt22392912010-04-21 12:27:06 -0400397 * struct ftrace_event_call *event_call = __data;
Li Zefan50354a82010-03-24 10:58:24 +0800398 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400399 * struct ring_buffer_event *event;
400 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
Steven Rostedte77405a2009-09-02 14:17:06 -0400401 * struct ring_buffer *buffer;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400402 * unsigned long irq_flags;
Li Zefan50354a82010-03-24 10:58:24 +0800403 * int __data_size;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400404 * int pc;
405 *
406 * local_save_flags(irq_flags);
407 * pc = preempt_count();
408 *
Li Zefan50354a82010-03-24 10:58:24 +0800409 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
410 *
Steven Rostedte77405a2009-09-02 14:17:06 -0400411 * event = trace_current_buffer_lock_reserve(&buffer,
412 * event_<call>.id,
Li Zefan50354a82010-03-24 10:58:24 +0800413 * sizeof(*entry) + __data_size,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400414 * irq_flags, pc);
415 * if (!event)
416 * return;
417 * entry = ring_buffer_event_data(event);
418 *
Li Zefan50354a82010-03-24 10:58:24 +0800419 * { <assign>; } <-- Here we assign the entries by the __field and
420 * __array macros.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400421 *
Li Zefan50354a82010-03-24 10:58:24 +0800422 * if (!filter_current_check_discard(buffer, event_call, entry, event))
423 * trace_current_buffer_unlock_commit(buffer,
424 * event, irq_flags, pc);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400425 * }
426 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400427 * static struct trace_event ftrace_event_type_<call> = {
428 * .trace = ftrace_raw_output_<call>, <-- stage 2
429 * };
430 *
Li Zefan50354a82010-03-24 10:58:24 +0800431 * static const char print_fmt_<call>[] = <TP_printk>;
432 *
Steven Rostedt8f082012010-04-20 10:47:33 -0400433 * static struct ftrace_event_class __used event_class_<template> = {
434 * .system = "<system>",
Steven Rostedt2e33af02010-04-22 10:35:55 -0400435 * .define_fields = ftrace_define_fields_<call>,
Steven Rostedt0405ab82010-04-22 11:46:44 -0400436 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
437 * .raw_init = trace_event_raw_init,
438 * .probe = ftrace_raw_event_##call,
Steven Rostedt8f082012010-04-20 10:47:33 -0400439 * };
440 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400441 * static struct ftrace_event_call __used
442 * __attribute__((__aligned__(4)))
443 * __attribute__((section("_ftrace_events"))) event_<call> = {
444 * .name = "<call>",
Steven Rostedt8f082012010-04-20 10:47:33 -0400445 * .class = event_class_<template>,
Steven Rostedt2e33af02010-04-22 10:35:55 -0400446 * .event = &ftrace_event_type_<call>,
Li Zefan50354a82010-03-24 10:58:24 +0800447 * .print_fmt = print_fmt_<call>,
Steven Rostedt8f082012010-04-20 10:47:33 -0400448 * };
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400449 *
450 */
451
Li Zefan07b139c2009-12-21 14:27:35 +0800452#ifdef CONFIG_PERF_EVENTS
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400453
Steven Rostedt22392912010-04-21 12:27:06 -0400454#define _TRACE_PERF_PROTO(call, proto) \
455 static notrace void \
456 perf_trace_##call(void *__data, proto);
457
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100458#define _TRACE_PERF_INIT(call) \
Steven Rostedt22392912010-04-21 12:27:06 -0400459 .perf_probe = perf_trace_##call,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400460
461#else
Steven Rostedt22392912010-04-21 12:27:06 -0400462#define _TRACE_PERF_PROTO(call, proto)
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100463#define _TRACE_PERF_INIT(call)
Li Zefan07b139c2009-12-21 14:27:35 +0800464#endif /* CONFIG_PERF_EVENTS */
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400465
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400466#undef __entry
467#define __entry entry
468
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200469#undef __field
470#define __field(type, item)
471
472#undef __array
473#define __array(type, item, len)
474
Li Zefan7fcb7c42009-06-01 15:35:46 +0800475#undef __dynamic_array
476#define __dynamic_array(type, item, len) \
477 __entry->__data_loc_##item = __data_offsets.item;
478
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200479#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800480#define __string(item, src) __dynamic_array(char, item, -1) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200481
482#undef __assign_str
483#define __assign_str(dst, src) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200484 strcpy(__get_str(dst), src);
485
Lai Jiangshan0fa0eda2009-12-15 15:39:57 +0800486#undef TP_fast_assign
487#define TP_fast_assign(args...) args
488
489#undef TP_perf_assign
490#define TP_perf_assign(args...)
491
Ingo Molnar091ad362009-11-26 09:04:55 +0100492#undef DECLARE_EVENT_CLASS
493#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400494 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500495static notrace void \
Steven Rostedt22392912010-04-21 12:27:06 -0400496ftrace_raw_event_##call(void *__data, proto) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400497{ \
Steven Rostedt22392912010-04-21 12:27:06 -0400498 struct ftrace_event_call *event_call = __data; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800499 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400500 struct ring_buffer_event *event; \
501 struct ftrace_raw_##call *entry; \
Steven Rostedte77405a2009-09-02 14:17:06 -0400502 struct ring_buffer *buffer; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400503 unsigned long irq_flags; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800504 int __data_size; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400505 int pc; \
506 \
507 local_save_flags(irq_flags); \
508 pc = preempt_count(); \
509 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800510 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200511 \
Steven Rostedte77405a2009-09-02 14:17:06 -0400512 event = trace_current_buffer_lock_reserve(&buffer, \
Steven Rostedtff038f52009-11-18 20:27:27 -0500513 event_call->id, \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800514 sizeof(*entry) + __data_size, \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200515 irq_flags, pc); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400516 if (!event) \
517 return; \
518 entry = ring_buffer_event_data(event); \
519 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800520 tstruct \
521 \
Li Zefana9c1c3a2009-06-01 15:35:13 +0800522 { assign; } \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400523 \
Steven Rostedte77405a2009-09-02 14:17:06 -0400524 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
525 trace_nowake_buffer_unlock_commit(buffer, \
526 event, irq_flags, pc); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500527}
Steven Rostedt22392912010-04-21 12:27:06 -0400528/*
529 * The ftrace_test_probe is compiled out, it is only here as a build time check
530 * to make sure that if the tracepoint handling changes, the ftrace probe will
531 * fail to compile unless it too is updated.
532 */
Steven Rostedtff038f52009-11-18 20:27:27 -0500533
534#undef DEFINE_EVENT
535#define DEFINE_EVENT(template, call, proto, args) \
Steven Rostedt22392912010-04-21 12:27:06 -0400536static inline void ftrace_test_probe_##call(void) \
537{ \
538 check_trace_callback_type_##call(ftrace_raw_event_##template); \
539}
Steven Rostedte5bc9722009-11-18 20:36:26 -0500540
541#undef DEFINE_EVENT_PRINT
Steven Rostedt80decc72010-04-23 10:00:22 -0400542#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
Steven Rostedte5bc9722009-11-18 20:36:26 -0500543
544#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
545
Lai Jiangshan509e7602009-12-15 15:39:42 +0800546#undef __entry
547#define __entry REC
548
549#undef __print_flags
550#undef __print_symbolic
551#undef __get_dynamic_array
552#undef __get_str
553
554#undef TP_printk
555#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
556
Ingo Molnar091ad362009-11-26 09:04:55 +0100557#undef DECLARE_EVENT_CLASS
Lai Jiangshan509e7602009-12-15 15:39:42 +0800558#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt22392912010-04-21 12:27:06 -0400559_TRACE_PERF_PROTO(call, PARAMS(proto)); \
Steven Rostedt8f082012010-04-20 10:47:33 -0400560static const char print_fmt_##call[] = print; \
561static struct ftrace_event_class __used event_class_##call = { \
Steven Rostedt22392912010-04-21 12:27:06 -0400562 .system = __stringify(TRACE_SYSTEM), \
Steven Rostedt2e33af02010-04-22 10:35:55 -0400563 .define_fields = ftrace_define_fields_##call, \
564 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
Steven Rostedt0405ab82010-04-22 11:46:44 -0400565 .raw_init = trace_event_raw_init, \
Steven Rostedt22392912010-04-21 12:27:06 -0400566 .probe = ftrace_raw_event_##call, \
567 _TRACE_PERF_INIT(call) \
Steven Rostedt8f082012010-04-20 10:47:33 -0400568};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500569
570#undef DEFINE_EVENT
571#define DEFINE_EVENT(template, call, proto, args) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400572 \
573static struct ftrace_event_call __used \
574__attribute__((__aligned__(4))) \
575__attribute__((section("_ftrace_events"))) event_##call = { \
576 .name = #call, \
Steven Rostedt8f082012010-04-20 10:47:33 -0400577 .class = &event_class_##template, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400578 .event.funcs = &ftrace_event_type_funcs_##template, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800579 .print_fmt = print_fmt_##template, \
Steven Rostedt8f082012010-04-20 10:47:33 -0400580};
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400581
Steven Rostedte5bc9722009-11-18 20:36:26 -0500582#undef DEFINE_EVENT_PRINT
583#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400584 \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800585static const char print_fmt_##call[] = print; \
586 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400587static struct ftrace_event_call __used \
588__attribute__((__aligned__(4))) \
589__attribute__((section("_ftrace_events"))) event_##call = { \
590 .name = #call, \
Steven Rostedt8f082012010-04-20 10:47:33 -0400591 .class = &event_class_##template, \
Steven Rostedt80decc72010-04-23 10:00:22 -0400592 .event.funcs = &ftrace_event_type_funcs_##call, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800593 .print_fmt = print_fmt_##call, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400594}
595
596#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
597
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200598/*
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100599 * Define the insertion callback to perf events
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200600 *
601 * The job is very similar to ftrace_raw_event_<call> except that we don't
602 * insert in the ring buffer but in a perf counter.
603 *
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100604 * static void ftrace_perf_<call>(proto)
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200605 * {
606 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
607 * struct ftrace_event_call *event_call = &event_<call>;
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200608 * extern void perf_tp_event(int, u64, u64, void *, int);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200609 * struct ftrace_raw_##call *entry;
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100610 * struct perf_trace_buf *trace_buf;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200611 * u64 __addr = 0, __count = 1;
612 * unsigned long irq_flags;
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200613 * struct trace_entry *ent;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200614 * int __entry_size;
615 * int __data_size;
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200616 * int __cpu
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200617 * int pc;
618 *
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200619 * pc = preempt_count();
620 *
621 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200622 *
623 * // Below we want to get the aligned size by taking into account
624 * // the u32 field that will later store the buffer size
625 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
626 * sizeof(u64));
627 * __entry_size -= sizeof(u32);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200628 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200629 * // Protect the non nmi buffer
630 * // This also protects the rcu read side
631 * local_irq_save(irq_flags);
632 * __cpu = smp_processor_id();
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200633 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200634 * if (in_nmi())
Paul E. McKenney8d53dd52010-03-03 17:50:18 -0800635 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200636 * else
Paul E. McKenney8d53dd52010-03-03 17:50:18 -0800637 * trace_buf = rcu_dereference_sched(perf_trace_buf);
Frederic Weisbecker1853db02009-08-10 16:38:36 +0200638 *
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100639 * if (!trace_buf)
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200640 * goto end;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200641 *
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100642 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
643 *
644 * // Avoid recursion from perf that could mess up the buffer
645 * if (trace_buf->recursion++)
646 * goto end_recursion;
647 *
648 * raw_data = trace_buf->buf;
649 *
650 * // Make recursion update visible before entering perf_tp_event
651 * // so that we protect from perf recursions.
652 *
653 * barrier();
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200654 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200655 * //zero dead bytes from alignment to avoid stack leak to userspace:
656 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
657 * entry = (struct ftrace_raw_<call> *)raw_data;
658 * ent = &entry->ent;
659 * tracing_generic_entry_update(ent, irq_flags, pc);
660 * ent->type = event_call->id;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200661 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200662 * <tstruct> <- do some jobs with dynamic arrays
663 *
664 * <assign> <- affect our values
665 *
Linus Torvalds43c12662009-09-21 09:15:07 -0700666 * perf_tp_event(event_call->id, __addr, __count, entry,
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200667 * __entry_size); <- submit them to perf counter
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200668 *
669 * }
670 */
671
Li Zefan07b139c2009-12-21 14:27:35 +0800672#ifdef CONFIG_PERF_EVENTS
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200673
Lai Jiangshan509e7602009-12-15 15:39:42 +0800674#undef __entry
675#define __entry entry
676
677#undef __get_dynamic_array
678#define __get_dynamic_array(field) \
679 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
680
681#undef __get_str
682#define __get_str(field) (char *)__get_dynamic_array(field)
683
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200684#undef __perf_addr
685#define __perf_addr(a) __addr = (a)
686
687#undef __perf_count
688#define __perf_count(c) __count = (c)
689
Ingo Molnar091ad362009-11-26 09:04:55 +0100690#undef DECLARE_EVENT_CLASS
691#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500692static notrace void \
Steven Rostedt22392912010-04-21 12:27:06 -0400693perf_trace_##call(void *__data, proto) \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200694{ \
Steven Rostedt22392912010-04-21 12:27:06 -0400695 struct ftrace_event_call *event_call = __data; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200696 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200697 struct ftrace_raw_##call *entry; \
698 u64 __addr = 0, __count = 1; \
699 unsigned long irq_flags; \
Frederic Weisbeckerc5306652010-03-03 07:16:16 +0100700 struct pt_regs *__regs; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200701 int __entry_size; \
702 int __data_size; \
Peter Zijlstra4ed7c922009-11-23 11:37:29 +0100703 int rctx; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200704 \
705 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Peter Zijlstraa0445602009-08-10 11:16:52 +0200706 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
707 sizeof(u64)); \
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200708 __entry_size -= sizeof(u32); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200709 \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100710 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200711 "profile buffer not large enough")) \
712 return; \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100713 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
Xiao Guangrong430ad5a2010-01-28 09:32:29 +0800714 __entry_size, event_call->id, &rctx, &irq_flags); \
715 if (!entry) \
716 return; \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200717 tstruct \
718 \
719 { assign; } \
720 \
Frederic Weisbeckerc5306652010-03-03 07:16:16 +0100721 __regs = &__get_cpu_var(perf_trace_regs); \
722 perf_fetch_caller_regs(__regs, 2); \
723 \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100724 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
Frederic Weisbeckerc5306652010-03-03 07:16:16 +0100725 __count, irq_flags, __regs); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200726}
727
Steven Rostedt22392912010-04-21 12:27:06 -0400728/*
729 * This part is compiled out, it is only here as a build time check
730 * to make sure that if the tracepoint handling changes, the
731 * perf probe will fail to compile unless it too is updated.
732 */
Steven Rostedtff038f52009-11-18 20:27:27 -0500733#undef DEFINE_EVENT
Steven Rostedt22392912010-04-21 12:27:06 -0400734#define DEFINE_EVENT(template, call, proto, args) \
735static inline void perf_test_probe_##call(void) \
736{ \
737 check_trace_callback_type_##call(perf_trace_##template); \
738 \
Steven Rostedtff038f52009-11-18 20:27:27 -0500739}
740
Steven Rostedt22392912010-04-21 12:27:06 -0400741
Steven Rostedte5bc9722009-11-18 20:36:26 -0500742#undef DEFINE_EVENT_PRINT
743#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
744 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
745
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200746#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
Li Zefan07b139c2009-12-21 14:27:35 +0800747#endif /* CONFIG_PERF_EVENTS */
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200748
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400749#undef _TRACE_PROFILE_INIT
750