blob: 7dcdfd824aab62c36e33bbf0bf05adbab1626a3e [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 Rostedtff038f52009-11-18 20:27:27 -0500209ftrace_raw_output_id_##call(int event_id, const char *name, \
210 struct trace_iterator *iter, int flags) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400211{ \
212 struct trace_seq *s = &iter->seq; \
213 struct ftrace_raw_##call *field; \
214 struct trace_entry *entry; \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200215 struct trace_seq *p; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400216 int ret; \
217 \
218 entry = iter->ent; \
219 \
Steven Rostedtff038f52009-11-18 20:27:27 -0500220 if (entry->type != event_id) { \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400221 WARN_ON_ONCE(1); \
222 return TRACE_TYPE_UNHANDLED; \
223 } \
224 \
225 field = (typeof(field))entry; \
226 \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200227 p = &get_cpu_var(ftrace_event_seq); \
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100228 trace_seq_init(p); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500229 ret = trace_seq_printf(s, "%s: ", name); \
230 if (ret) \
231 ret = trace_seq_printf(s, print); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200232 put_cpu(); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400233 if (!ret) \
234 return TRACE_TYPE_PARTIAL_LINE; \
235 \
236 return TRACE_TYPE_HANDLED; \
237}
Steven Rostedtff038f52009-11-18 20:27:27 -0500238
239#undef DEFINE_EVENT
240#define DEFINE_EVENT(template, name, proto, args) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500241static notrace enum print_line_t \
Steven Rostedtff038f52009-11-18 20:27:27 -0500242ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
243{ \
244 return ftrace_raw_output_id_##template(event_##name.id, \
245 #name, iter, flags); \
246}
247
Steven Rostedte5bc9722009-11-18 20:36:26 -0500248#undef DEFINE_EVENT_PRINT
249#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500250static notrace enum print_line_t \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400251ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
252{ \
253 struct trace_seq *s = &iter->seq; \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500254 struct ftrace_raw_##template *field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400255 struct trace_entry *entry; \
256 struct trace_seq *p; \
257 int ret; \
258 \
259 entry = iter->ent; \
260 \
261 if (entry->type != event_##call.id) { \
262 WARN_ON_ONCE(1); \
263 return TRACE_TYPE_UNHANDLED; \
264 } \
265 \
266 field = (typeof(field))entry; \
267 \
268 p = &get_cpu_var(ftrace_event_seq); \
269 trace_seq_init(p); \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500270 ret = trace_seq_printf(s, "%s: ", #call); \
271 if (ret) \
272 ret = trace_seq_printf(s, print); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400273 put_cpu(); \
274 if (!ret) \
275 return TRACE_TYPE_PARTIAL_LINE; \
276 \
277 return TRACE_TYPE_HANDLED; \
278}
Steven Rostedte5bc9722009-11-18 20:36:26 -0500279
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400280#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
281
Li Zefan43b51ea2009-08-07 10:33:22 +0800282#undef __field_ext
283#define __field_ext(type, item, filter_type) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400284 ret = trace_define_field(event_call, #type, #item, \
285 offsetof(typeof(field), item), \
Li Zefan43b51ea2009-08-07 10:33:22 +0800286 sizeof(field.item), \
287 is_signed_type(type), filter_type); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400288 if (ret) \
289 return ret;
290
Li Zefan43b51ea2009-08-07 10:33:22 +0800291#undef __field
292#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
293
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400294#undef __array
295#define __array(type, item, len) \
296 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
297 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
298 offsetof(typeof(field), item), \
Lai Jiangshanfb7ae9812009-12-15 15:39:38 +0800299 sizeof(field.item), \
300 is_signed_type(type), FILTER_OTHER); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400301 if (ret) \
302 return ret;
303
Li Zefan7fcb7c42009-06-01 15:35:46 +0800304#undef __dynamic_array
305#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800306 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
Li Zefan43b51ea2009-08-07 10:33:22 +0800307 offsetof(typeof(field), __data_loc_##item), \
Lai Jiangshanfb7ae9812009-12-15 15:39:38 +0800308 sizeof(field.__data_loc_##item), \
309 is_signed_type(type), FILTER_OTHER);
Li Zefan7fcb7c42009-06-01 15:35:46 +0800310
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200311#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800312#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200313
Ingo Molnar091ad362009-11-26 09:04:55 +0100314#undef DECLARE_EVENT_CLASS
315#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500316static int notrace \
Li Zefan14be96c2009-08-19 15:53:52 +0800317ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400318{ \
319 struct ftrace_raw_##call field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400320 int ret; \
321 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400322 tstruct; \
323 \
324 return ret; \
325}
326
Steven Rostedtff038f52009-11-18 20:27:27 -0500327#undef DEFINE_EVENT
328#define DEFINE_EVENT(template, name, proto, args)
329
Steven Rostedte5bc9722009-11-18 20:36:26 -0500330#undef DEFINE_EVENT_PRINT
331#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
332 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
333
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400334#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
335
336/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800337 * remember the offset of each array from the beginning of the event.
338 */
339
340#undef __entry
341#define __entry entry
342
343#undef __field
344#define __field(type, item)
345
Li Zefan43b51ea2009-08-07 10:33:22 +0800346#undef __field_ext
347#define __field_ext(type, item, filter_type)
348
Li Zefan7fcb7c42009-06-01 15:35:46 +0800349#undef __array
350#define __array(type, item, len)
351
352#undef __dynamic_array
353#define __dynamic_array(type, item, len) \
354 __data_offsets->item = __data_size + \
355 offsetof(typeof(*entry), __data); \
Li Zefan7d536cb2009-07-16 10:54:02 +0800356 __data_offsets->item |= (len * sizeof(type)) << 16; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800357 __data_size += (len) * sizeof(type);
358
359#undef __string
Steven Rostedtff038f52009-11-18 20:27:27 -0500360#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
Li Zefan7fcb7c42009-06-01 15:35:46 +0800361
Ingo Molnar091ad362009-11-26 09:04:55 +0100362#undef DECLARE_EVENT_CLASS
363#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500364static inline notrace int ftrace_get_offsets_##call( \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800365 struct ftrace_data_offsets_##call *__data_offsets, proto) \
366{ \
367 int __data_size = 0; \
368 struct ftrace_raw_##call __maybe_unused *entry; \
369 \
370 tstruct; \
371 \
372 return __data_size; \
373}
374
Steven Rostedtff038f52009-11-18 20:27:27 -0500375#undef DEFINE_EVENT
376#define DEFINE_EVENT(template, name, proto, args)
377
Steven Rostedte5bc9722009-11-18 20:36:26 -0500378#undef DEFINE_EVENT_PRINT
379#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
380 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
381
Li Zefan7fcb7c42009-06-01 15:35:46 +0800382#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
383
Li Zefan07b139c2009-12-21 14:27:35 +0800384#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra3a659302009-07-21 17:34:57 +0200385
386/*
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200387 * Generate the functions needed for tracepoint perf_event support.
Peter Zijlstra3a659302009-07-21 17:34:57 +0200388 *
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200389 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
Peter Zijlstra3a659302009-07-21 17:34:57 +0200390 *
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200391 * static int ftrace_profile_enable_<call>(void)
Peter Zijlstra3a659302009-07-21 17:34:57 +0200392 * {
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200393 * return register_trace_<call>(ftrace_profile_<call>);
Peter Zijlstra3a659302009-07-21 17:34:57 +0200394 * }
395 *
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200396 * static void ftrace_profile_disable_<call>(void)
Peter Zijlstra3a659302009-07-21 17:34:57 +0200397 * {
Frederic Weisbeckere5e25cf2009-09-18 00:54:43 +0200398 * unregister_trace_<call>(ftrace_profile_<call>);
Peter Zijlstra3a659302009-07-21 17:34:57 +0200399 * }
400 *
401 */
402
Ingo Molnar091ad362009-11-26 09:04:55 +0100403#undef DECLARE_EVENT_CLASS
404#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
Steven Rostedtff038f52009-11-18 20:27:27 -0500405
406#undef DEFINE_EVENT
407#define DEFINE_EVENT(template, name, proto, args) \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200408 \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100409static void perf_trace_##name(proto); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200410 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500411static notrace int \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100412perf_trace_enable_##name(struct ftrace_event_call *unused) \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200413{ \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100414 return register_trace_##name(perf_trace_##name); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200415} \
416 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500417static notrace void \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100418perf_trace_disable_##name(struct ftrace_event_call *unused) \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200419{ \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100420 unregister_trace_##name(perf_trace_##name); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200421}
422
Steven Rostedte5bc9722009-11-18 20:36:26 -0500423#undef DEFINE_EVENT_PRINT
424#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
425 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
426
Peter Zijlstra3a659302009-07-21 17:34:57 +0200427#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
428
Li Zefan07b139c2009-12-21 14:27:35 +0800429#endif /* CONFIG_PERF_EVENTS */
Peter Zijlstra3a659302009-07-21 17:34:57 +0200430
Li Zefan7fcb7c42009-06-01 15:35:46 +0800431/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200432 * Stage 4 of the trace events.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400433 *
434 * Override the macros in <trace/trace_events.h> to include the following:
435 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400436 * For those macros defined with TRACE_EVENT:
437 *
438 * static struct ftrace_event_call event_<call>;
439 *
440 * static void ftrace_raw_event_<call>(proto)
441 * {
Li Zefan50354a82010-03-24 10:58:24 +0800442 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400443 * struct ring_buffer_event *event;
444 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
Steven Rostedte77405a2009-09-02 14:17:06 -0400445 * struct ring_buffer *buffer;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400446 * unsigned long irq_flags;
Li Zefan50354a82010-03-24 10:58:24 +0800447 * int __data_size;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400448 * int pc;
449 *
450 * local_save_flags(irq_flags);
451 * pc = preempt_count();
452 *
Li Zefan50354a82010-03-24 10:58:24 +0800453 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
454 *
Steven Rostedte77405a2009-09-02 14:17:06 -0400455 * event = trace_current_buffer_lock_reserve(&buffer,
456 * event_<call>.id,
Li Zefan50354a82010-03-24 10:58:24 +0800457 * sizeof(*entry) + __data_size,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400458 * irq_flags, pc);
459 * if (!event)
460 * return;
461 * entry = ring_buffer_event_data(event);
462 *
Li Zefan50354a82010-03-24 10:58:24 +0800463 * { <assign>; } <-- Here we assign the entries by the __field and
464 * __array macros.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400465 *
Li Zefan50354a82010-03-24 10:58:24 +0800466 * if (!filter_current_check_discard(buffer, event_call, entry, event))
467 * trace_current_buffer_unlock_commit(buffer,
468 * event, irq_flags, pc);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400469 * }
470 *
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400471 * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400472 * {
Li Zefan50354a82010-03-24 10:58:24 +0800473 * return register_trace_<call>(ftrace_raw_event_<call>);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400474 * }
475 *
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400476 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400477 * {
478 * unregister_trace_<call>(ftrace_raw_event_<call>);
479 * }
480 *
481 * static struct trace_event ftrace_event_type_<call> = {
482 * .trace = ftrace_raw_output_<call>, <-- stage 2
483 * };
484 *
Li Zefan50354a82010-03-24 10:58:24 +0800485 * static const char print_fmt_<call>[] = <TP_printk>;
486 *
Steven Rostedt8f082012010-04-20 10:47:33 -0400487 * static struct ftrace_event_class __used event_class_<template> = {
488 * .system = "<system>",
489 * };
490 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400491 * static struct ftrace_event_call __used
492 * __attribute__((__aligned__(4)))
493 * __attribute__((section("_ftrace_events"))) event_<call> = {
494 * .name = "<call>",
Steven Rostedt8f082012010-04-20 10:47:33 -0400495 * .class = event_class_<template>,
Li Zefan87d9b4e2009-12-08 11:14:20 +0800496 * .raw_init = trace_event_raw_init,
Steven Rostedt8f082012010-04-20 10:47:33 -0400497 * .regfunc = ftrace_raw_reg_event_<call>,
498 * .unregfunc = ftrace_raw_unreg_event_<call>,
Li Zefan50354a82010-03-24 10:58:24 +0800499 * .print_fmt = print_fmt_<call>,
500 * .define_fields = ftrace_define_fields_<call>,
Steven Rostedt8f082012010-04-20 10:47:33 -0400501 * };
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400502 *
503 */
504
Li Zefan07b139c2009-12-21 14:27:35 +0800505#ifdef CONFIG_PERF_EVENTS
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400506
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100507#define _TRACE_PERF_INIT(call) \
508 .perf_event_enable = perf_trace_enable_##call, \
509 .perf_event_disable = perf_trace_disable_##call,
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400510
511#else
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100512#define _TRACE_PERF_INIT(call)
Li Zefan07b139c2009-12-21 14:27:35 +0800513#endif /* CONFIG_PERF_EVENTS */
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400514
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400515#undef __entry
516#define __entry entry
517
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200518#undef __field
519#define __field(type, item)
520
521#undef __array
522#define __array(type, item, len)
523
Li Zefan7fcb7c42009-06-01 15:35:46 +0800524#undef __dynamic_array
525#define __dynamic_array(type, item, len) \
526 __entry->__data_loc_##item = __data_offsets.item;
527
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200528#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800529#define __string(item, src) __dynamic_array(char, item, -1) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200530
531#undef __assign_str
532#define __assign_str(dst, src) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200533 strcpy(__get_str(dst), src);
534
Lai Jiangshan0fa0eda2009-12-15 15:39:57 +0800535#undef TP_fast_assign
536#define TP_fast_assign(args...) args
537
538#undef TP_perf_assign
539#define TP_perf_assign(args...)
540
Ingo Molnar091ad362009-11-26 09:04:55 +0100541#undef DECLARE_EVENT_CLASS
542#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400543 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500544static notrace void \
545ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
Steven Rostedtff038f52009-11-18 20:27:27 -0500546 proto) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400547{ \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800548 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400549 struct ring_buffer_event *event; \
550 struct ftrace_raw_##call *entry; \
Steven Rostedte77405a2009-09-02 14:17:06 -0400551 struct ring_buffer *buffer; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400552 unsigned long irq_flags; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800553 int __data_size; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400554 int pc; \
555 \
556 local_save_flags(irq_flags); \
557 pc = preempt_count(); \
558 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800559 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200560 \
Steven Rostedte77405a2009-09-02 14:17:06 -0400561 event = trace_current_buffer_lock_reserve(&buffer, \
Steven Rostedtff038f52009-11-18 20:27:27 -0500562 event_call->id, \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800563 sizeof(*entry) + __data_size, \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200564 irq_flags, pc); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400565 if (!event) \
566 return; \
567 entry = ring_buffer_event_data(event); \
568 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800569 tstruct \
570 \
Li Zefana9c1c3a2009-06-01 15:35:13 +0800571 { assign; } \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400572 \
Steven Rostedte77405a2009-09-02 14:17:06 -0400573 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
574 trace_nowake_buffer_unlock_commit(buffer, \
575 event, irq_flags, pc); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500576}
577
578#undef DEFINE_EVENT
579#define DEFINE_EVENT(template, call, proto, args) \
580 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500581static notrace void ftrace_raw_event_##call(proto) \
Steven Rostedtff038f52009-11-18 20:27:27 -0500582{ \
583 ftrace_raw_event_id_##template(&event_##call, args); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400584} \
585 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500586static notrace int \
587ftrace_raw_reg_event_##call(struct ftrace_event_call *unused) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400588{ \
Li Zefan3b8e4272009-12-08 11:14:52 +0800589 return register_trace_##call(ftrace_raw_event_##call); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400590} \
591 \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500592static notrace void \
593ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400594{ \
595 unregister_trace_##call(ftrace_raw_event_##call); \
596} \
597 \
598static struct trace_event ftrace_event_type_##call = { \
599 .trace = ftrace_raw_output_##call, \
Li Zefan87d9b4e2009-12-08 11:14:20 +0800600};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500601
602#undef DEFINE_EVENT_PRINT
603#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
604 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
605
606#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
607
Lai Jiangshan509e7602009-12-15 15:39:42 +0800608#undef __entry
609#define __entry REC
610
611#undef __print_flags
612#undef __print_symbolic
613#undef __get_dynamic_array
614#undef __get_str
615
616#undef TP_printk
617#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
618
Ingo Molnar091ad362009-11-26 09:04:55 +0100619#undef DECLARE_EVENT_CLASS
Lai Jiangshan509e7602009-12-15 15:39:42 +0800620#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt8f082012010-04-20 10:47:33 -0400621static const char print_fmt_##call[] = print; \
622static struct ftrace_event_class __used event_class_##call = { \
623 .system = __stringify(TRACE_SYSTEM) \
624};
Steven Rostedte5bc9722009-11-18 20:36:26 -0500625
626#undef DEFINE_EVENT
627#define DEFINE_EVENT(template, call, proto, args) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400628 \
629static struct ftrace_event_call __used \
630__attribute__((__aligned__(4))) \
631__attribute__((section("_ftrace_events"))) event_##call = { \
632 .name = #call, \
Steven Rostedt8f082012010-04-20 10:47:33 -0400633 .class = &event_class_##template, \
Steven Rostedt6d723732009-04-10 14:53:50 -0400634 .event = &ftrace_event_type_##call, \
Li Zefan87d9b4e2009-12-08 11:14:20 +0800635 .raw_init = trace_event_raw_init, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400636 .regfunc = ftrace_raw_reg_event_##call, \
637 .unregfunc = ftrace_raw_unreg_event_##call, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800638 .print_fmt = print_fmt_##template, \
Steven Rostedtff038f52009-11-18 20:27:27 -0500639 .define_fields = ftrace_define_fields_##template, \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100640 _TRACE_PERF_INIT(call) \
Steven Rostedt8f082012010-04-20 10:47:33 -0400641};
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400642
Steven Rostedte5bc9722009-11-18 20:36:26 -0500643#undef DEFINE_EVENT_PRINT
644#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400645 \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800646static const char print_fmt_##call[] = print; \
647 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400648static struct ftrace_event_call __used \
649__attribute__((__aligned__(4))) \
650__attribute__((section("_ftrace_events"))) event_##call = { \
651 .name = #call, \
Steven Rostedt8f082012010-04-20 10:47:33 -0400652 .class = &event_class_##template, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400653 .event = &ftrace_event_type_##call, \
Li Zefan87d9b4e2009-12-08 11:14:20 +0800654 .raw_init = trace_event_raw_init, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400655 .regfunc = ftrace_raw_reg_event_##call, \
656 .unregfunc = ftrace_raw_unreg_event_##call, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800657 .print_fmt = print_fmt_##call, \
Steven Rostedte5bc9722009-11-18 20:36:26 -0500658 .define_fields = ftrace_define_fields_##template, \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100659 _TRACE_PERF_INIT(call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400660}
661
662#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
663
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200664/*
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100665 * Define the insertion callback to perf events
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200666 *
667 * The job is very similar to ftrace_raw_event_<call> except that we don't
668 * insert in the ring buffer but in a perf counter.
669 *
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100670 * static void ftrace_perf_<call>(proto)
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200671 * {
672 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
673 * struct ftrace_event_call *event_call = &event_<call>;
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200674 * extern void perf_tp_event(int, u64, u64, void *, int);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200675 * struct ftrace_raw_##call *entry;
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100676 * struct perf_trace_buf *trace_buf;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200677 * u64 __addr = 0, __count = 1;
678 * unsigned long irq_flags;
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200679 * struct trace_entry *ent;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200680 * int __entry_size;
681 * int __data_size;
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200682 * int __cpu
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200683 * int pc;
684 *
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200685 * pc = preempt_count();
686 *
687 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200688 *
689 * // Below we want to get the aligned size by taking into account
690 * // the u32 field that will later store the buffer size
691 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
692 * sizeof(u64));
693 * __entry_size -= sizeof(u32);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200694 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200695 * // Protect the non nmi buffer
696 * // This also protects the rcu read side
697 * local_irq_save(irq_flags);
698 * __cpu = smp_processor_id();
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200699 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200700 * if (in_nmi())
Paul E. McKenney8d53dd52010-03-03 17:50:18 -0800701 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200702 * else
Paul E. McKenney8d53dd52010-03-03 17:50:18 -0800703 * trace_buf = rcu_dereference_sched(perf_trace_buf);
Frederic Weisbecker1853db02009-08-10 16:38:36 +0200704 *
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100705 * if (!trace_buf)
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200706 * goto end;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200707 *
Frederic Weisbecker444a2a32009-11-06 04:13:05 +0100708 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
709 *
710 * // Avoid recursion from perf that could mess up the buffer
711 * if (trace_buf->recursion++)
712 * goto end_recursion;
713 *
714 * raw_data = trace_buf->buf;
715 *
716 * // Make recursion update visible before entering perf_tp_event
717 * // so that we protect from perf recursions.
718 *
719 * barrier();
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200720 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200721 * //zero dead bytes from alignment to avoid stack leak to userspace:
722 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
723 * entry = (struct ftrace_raw_<call> *)raw_data;
724 * ent = &entry->ent;
725 * tracing_generic_entry_update(ent, irq_flags, pc);
726 * ent->type = event_call->id;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200727 *
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200728 * <tstruct> <- do some jobs with dynamic arrays
729 *
730 * <assign> <- affect our values
731 *
Linus Torvalds43c12662009-09-21 09:15:07 -0700732 * perf_tp_event(event_call->id, __addr, __count, entry,
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200733 * __entry_size); <- submit them to perf counter
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200734 *
735 * }
736 */
737
Li Zefan07b139c2009-12-21 14:27:35 +0800738#ifdef CONFIG_PERF_EVENTS
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200739
Lai Jiangshan509e7602009-12-15 15:39:42 +0800740#undef __entry
741#define __entry entry
742
743#undef __get_dynamic_array
744#define __get_dynamic_array(field) \
745 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
746
747#undef __get_str
748#define __get_str(field) (char *)__get_dynamic_array(field)
749
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200750#undef __perf_addr
751#define __perf_addr(a) __addr = (a)
752
753#undef __perf_count
754#define __perf_count(c) __count = (c)
755
Ingo Molnar091ad362009-11-26 09:04:55 +0100756#undef DECLARE_EVENT_CLASS
757#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
Steven Rostedt83f0d532010-02-16 10:38:47 -0500758static notrace void \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100759perf_trace_templ_##call(struct ftrace_event_call *event_call, \
Steven Rostedtff038f52009-11-18 20:27:27 -0500760 proto) \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200761{ \
762 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200763 struct ftrace_raw_##call *entry; \
764 u64 __addr = 0, __count = 1; \
765 unsigned long irq_flags; \
Frederic Weisbeckerc5306652010-03-03 07:16:16 +0100766 struct pt_regs *__regs; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200767 int __entry_size; \
768 int __data_size; \
Peter Zijlstra4ed7c922009-11-23 11:37:29 +0100769 int rctx; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200770 \
771 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Peter Zijlstraa0445602009-08-10 11:16:52 +0200772 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
773 sizeof(u64)); \
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200774 __entry_size -= sizeof(u32); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200775 \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100776 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200777 "profile buffer not large enough")) \
778 return; \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100779 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
Xiao Guangrong430ad5a2010-01-28 09:32:29 +0800780 __entry_size, event_call->id, &rctx, &irq_flags); \
781 if (!entry) \
782 return; \
Frederic Weisbecker20ab44252009-09-18 06:10:28 +0200783 tstruct \
784 \
785 { assign; } \
786 \
Frederic Weisbeckerc5306652010-03-03 07:16:16 +0100787 __regs = &__get_cpu_var(perf_trace_regs); \
788 perf_fetch_caller_regs(__regs, 2); \
789 \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100790 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
Frederic Weisbeckerc5306652010-03-03 07:16:16 +0100791 __count, irq_flags, __regs); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200792}
793
Steven Rostedtff038f52009-11-18 20:27:27 -0500794#undef DEFINE_EVENT
795#define DEFINE_EVENT(template, call, proto, args) \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100796static notrace void perf_trace_##call(proto) \
Steven Rostedtff038f52009-11-18 20:27:27 -0500797{ \
798 struct ftrace_event_call *event_call = &event_##call; \
799 \
Frederic Weisbecker97d5a222010-03-05 05:35:37 +0100800 perf_trace_templ_##template(event_call, args); \
Steven Rostedtff038f52009-11-18 20:27:27 -0500801}
802
Steven Rostedte5bc9722009-11-18 20:36:26 -0500803#undef DEFINE_EVENT_PRINT
804#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
805 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
806
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200807#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
Li Zefan07b139c2009-12-21 14:27:35 +0800808#endif /* CONFIG_PERF_EVENTS */
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200809
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400810#undef _TRACE_PROFILE_INIT
811