blob: 3a0b44bdabf7d6d9b9a448a3e22bb607913200e5 [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 Rostedtf42c85e2009-04-13 12:25:37 -040021#undef __field
22#define __field(type, item) type item;
23
Li Zefan7fcb7c42009-06-01 15:35:46 +080024#undef __array
25#define __array(type, item, len) type item[len];
26
27#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +080028#define __dynamic_array(type, item, len) u32 __data_loc_##item;
Li Zefan7fcb7c42009-06-01 15:35:46 +080029
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020030#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +080031#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020032
Steven Rostedtf42c85e2009-04-13 12:25:37 -040033#undef TP_STRUCT__entry
34#define TP_STRUCT__entry(args...) args
35
36#undef TRACE_EVENT
37#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
38 struct ftrace_raw_##name { \
39 struct trace_entry ent; \
40 tstruct \
Li Zefan7fcb7c42009-06-01 15:35:46 +080041 char __data[0]; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -040042 }; \
43 static struct ftrace_event_call event_##name
44
Josh Stone97419872009-08-24 14:43:13 -070045/* Callbacks are meaningless to ftrace. */
46#undef TRACE_EVENT_FN
47#define TRACE_EVENT_FN(name, proto, args, tstruct, \
48 assign, print, reg, unreg) \
49 TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args), \
50 TP_STRUCT__entry(tstruct), \
51 TP_fast_assign(assign), \
52 TP_printk(print))
53
Steven Rostedtf42c85e2009-04-13 12:25:37 -040054#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
55
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020056
Steven Rostedtf42c85e2009-04-13 12:25:37 -040057/*
58 * Stage 2 of the trace events.
59 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020060 * Include the following:
61 *
Li Zefan7fcb7c42009-06-01 15:35:46 +080062 * struct ftrace_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +080063 * u32 <item1>;
64 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020065 * [...]
66 * };
67 *
Li Zefan7d536cb2009-07-16 10:54:02 +080068 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +080069 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +080070 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020071 */
72
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020073#undef __field
74#define __field(type, item);
75
Li Zefan7fcb7c42009-06-01 15:35:46 +080076#undef __array
77#define __array(type, item, len)
78
79#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +080080#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +080081
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020082#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +080083#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020084
85#undef TRACE_EVENT
86#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
Li Zefan7fcb7c42009-06-01 15:35:46 +080087 struct ftrace_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020088 tstruct; \
89 };
90
91#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
92
93/*
Steven Rostedt6ff9a642009-06-10 14:28:34 -040094 * Setup the showing format of trace point.
95 *
96 * int
97 * ftrace_format_##call(struct trace_seq *s)
98 * {
99 * struct ftrace_raw_##call field;
100 * int ret;
101 *
102 * ret = trace_seq_printf(s, #type " " #item ";"
103 * " offset:%u; size:%u;\n",
104 * offsetof(struct ftrace_raw_##call, item),
105 * sizeof(field.type));
106 *
107 * }
108 */
109
110#undef TP_STRUCT__entry
111#define TP_STRUCT__entry(args...) args
112
113#undef __field
114#define __field(type, item) \
115 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
116 "offset:%u;\tsize:%u;\n", \
117 (unsigned int)offsetof(typeof(field), item), \
118 (unsigned int)sizeof(field.item)); \
119 if (!ret) \
120 return 0;
121
122#undef __array
123#define __array(type, item, len) \
124 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
125 "offset:%u;\tsize:%u;\n", \
126 (unsigned int)offsetof(typeof(field), item), \
127 (unsigned int)sizeof(field.item)); \
128 if (!ret) \
129 return 0;
130
131#undef __dynamic_array
132#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800133 ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400134 "offset:%u;\tsize:%u;\n", \
135 (unsigned int)offsetof(typeof(field), \
136 __data_loc_##item), \
137 (unsigned int)sizeof(field.__data_loc_##item)); \
138 if (!ret) \
139 return 0;
140
141#undef __string
142#define __string(item, src) __dynamic_array(char, item, -1)
143
144#undef __entry
145#define __entry REC
146
147#undef __print_symbolic
148#undef __get_dynamic_array
149#undef __get_str
150
151#undef TP_printk
152#define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
153
154#undef TP_fast_assign
155#define TP_fast_assign(args...) args
156
Peter Zijlstra3a659302009-07-21 17:34:57 +0200157#undef TP_perf_assign
158#define TP_perf_assign(args...)
159
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400160#undef TRACE_EVENT
161#define TRACE_EVENT(call, proto, args, tstruct, func, print) \
162static int \
Frederic Weisbeckere8f9f4d2009-08-11 17:42:52 +0200163ftrace_format_##call(struct ftrace_event_call *unused, \
164 struct trace_seq *s) \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400165{ \
166 struct ftrace_raw_##call field __attribute__((unused)); \
167 int ret = 0; \
168 \
169 tstruct; \
170 \
171 trace_seq_printf(s, "\nprint fmt: " print); \
172 \
173 return ret; \
174}
175
176#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
177
178/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200179 * Stage 3 of the trace events.
180 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400181 * Override the macros in <trace/trace_events.h> to include the following:
182 *
183 * enum print_line_t
184 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
185 * {
186 * struct trace_seq *s = &iter->seq;
187 * struct ftrace_raw_<call> *field; <-- defined in stage 1
188 * struct trace_entry *entry;
Steven Rostedtbe74b732009-05-26 20:25:22 +0200189 * struct trace_seq *p;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400190 * int ret;
191 *
192 * entry = iter->ent;
193 *
194 * if (entry->type != event_<call>.id) {
195 * WARN_ON_ONCE(1);
196 * return TRACE_TYPE_UNHANDLED;
197 * }
198 *
199 * field = (typeof(field))entry;
200 *
Steven Rostedtbe74b732009-05-26 20:25:22 +0200201 * p = get_cpu_var(ftrace_event_seq);
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100202 * trace_seq_init(p);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400203 * ret = trace_seq_printf(s, <TP_printk> "\n");
Steven Rostedtbe74b732009-05-26 20:25:22 +0200204 * put_cpu();
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400205 * if (!ret)
206 * return TRACE_TYPE_PARTIAL_LINE;
207 *
208 * return TRACE_TYPE_HANDLED;
209 * }
210 *
211 * This is the method used to print the raw event to the trace
212 * output format. Note, this is not needed if the data is read
213 * in binary.
214 */
215
216#undef __entry
217#define __entry field
218
219#undef TP_printk
220#define TP_printk(fmt, args...) fmt "\n", args
221
Li Zefan7fcb7c42009-06-01 15:35:46 +0800222#undef __get_dynamic_array
223#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800224 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800225
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200226#undef __get_str
Li Zefan7fcb7c42009-06-01 15:35:46 +0800227#define __get_str(field) (char *)__get_dynamic_array(field)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200228
Steven Rostedtbe74b732009-05-26 20:25:22 +0200229#undef __print_flags
230#define __print_flags(flag, delim, flag_array...) \
231 ({ \
232 static const struct trace_print_flags flags[] = \
233 { flag_array, { -1, NULL }}; \
234 ftrace_print_flags_seq(p, delim, flag, flags); \
235 })
236
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400237#undef __print_symbolic
238#define __print_symbolic(value, symbol_array...) \
239 ({ \
240 static const struct trace_print_flags symbols[] = \
241 { symbol_array, { -1, NULL }}; \
242 ftrace_print_symbols_seq(p, value, symbols); \
243 })
244
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400245#undef TRACE_EVENT
246#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
247enum print_line_t \
248ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
249{ \
250 struct trace_seq *s = &iter->seq; \
251 struct ftrace_raw_##call *field; \
252 struct trace_entry *entry; \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200253 struct trace_seq *p; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400254 int ret; \
255 \
256 entry = iter->ent; \
257 \
258 if (entry->type != event_##call.id) { \
259 WARN_ON_ONCE(1); \
260 return TRACE_TYPE_UNHANDLED; \
261 } \
262 \
263 field = (typeof(field))entry; \
264 \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200265 p = &get_cpu_var(ftrace_event_seq); \
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100266 trace_seq_init(p); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400267 ret = trace_seq_printf(s, #call ": " print); \
Steven Rostedtbe74b732009-05-26 20:25:22 +0200268 put_cpu(); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400269 if (!ret) \
270 return TRACE_TYPE_PARTIAL_LINE; \
271 \
272 return TRACE_TYPE_HANDLED; \
273}
274
275#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
276
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400277#undef __field
278#define __field(type, item) \
279 ret = trace_define_field(event_call, #type, #item, \
280 offsetof(typeof(field), item), \
Tom Zanussia118e4d2009-04-28 03:04:53 -0500281 sizeof(field.item), is_signed_type(type)); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400282 if (ret) \
283 return ret;
284
285#undef __array
286#define __array(type, item, len) \
287 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
288 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
289 offsetof(typeof(field), item), \
Tom Zanussia118e4d2009-04-28 03:04:53 -0500290 sizeof(field.item), 0); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400291 if (ret) \
292 return ret;
293
Li Zefan7fcb7c42009-06-01 15:35:46 +0800294#undef __dynamic_array
295#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800296 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800297 offsetof(typeof(field), __data_loc_##item), \
298 sizeof(field.__data_loc_##item), 0);
299
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200300#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800301#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200302
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400303#undef TRACE_EVENT
304#define TRACE_EVENT(call, proto, args, tstruct, func, print) \
305int \
Li Zefan14be96c2009-08-19 15:53:52 +0800306ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400307{ \
308 struct ftrace_raw_##call field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400309 int ret; \
310 \
Li Zefane647d6b2009-08-19 15:54:32 +0800311 ret = trace_define_common_fields(event_call); \
312 if (ret) \
313 return ret; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400314 \
315 tstruct; \
316 \
317 return ret; \
318}
319
320#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
321
322/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800323 * remember the offset of each array from the beginning of the event.
324 */
325
326#undef __entry
327#define __entry entry
328
329#undef __field
330#define __field(type, item)
331
332#undef __array
333#define __array(type, item, len)
334
335#undef __dynamic_array
336#define __dynamic_array(type, item, len) \
337 __data_offsets->item = __data_size + \
338 offsetof(typeof(*entry), __data); \
Li Zefan7d536cb2009-07-16 10:54:02 +0800339 __data_offsets->item |= (len * sizeof(type)) << 16; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800340 __data_size += (len) * sizeof(type);
341
342#undef __string
343#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \
344
345#undef TRACE_EVENT
346#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
347static inline int ftrace_get_offsets_##call( \
348 struct ftrace_data_offsets_##call *__data_offsets, proto) \
349{ \
350 int __data_size = 0; \
351 struct ftrace_raw_##call __maybe_unused *entry; \
352 \
353 tstruct; \
354 \
355 return __data_size; \
356}
357
358#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
359
Peter Zijlstra3a659302009-07-21 17:34:57 +0200360#ifdef CONFIG_EVENT_PROFILE
361
362/*
363 * Generate the functions needed for tracepoint perf_counter support.
364 *
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200365 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
Peter Zijlstra3a659302009-07-21 17:34:57 +0200366 *
367 * static int ftrace_profile_enable_<call>(struct ftrace_event_call *event_call)
368 * {
369 * int ret = 0;
370 *
371 * if (!atomic_inc_return(&event_call->profile_count))
372 * ret = register_trace_<call>(ftrace_profile_<call>);
373 *
374 * return ret;
375 * }
376 *
377 * static void ftrace_profile_disable_<call>(struct ftrace_event_call *event_call)
378 * {
379 * if (atomic_add_negative(-1, &event->call->profile_count))
380 * unregister_trace_<call>(ftrace_profile_<call>);
381 * }
382 *
383 */
384
Peter Zijlstra3a659302009-07-21 17:34:57 +0200385#undef TRACE_EVENT
386#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
387 \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200388static void ftrace_profile_##call(proto); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200389 \
390static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
391{ \
392 int ret = 0; \
393 \
394 if (!atomic_inc_return(&event_call->profile_count)) \
395 ret = register_trace_##call(ftrace_profile_##call); \
396 \
397 return ret; \
398} \
399 \
400static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
401{ \
402 if (atomic_add_negative(-1, &event_call->profile_count)) \
403 unregister_trace_##call(ftrace_profile_##call); \
404}
405
406#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
407
Peter Zijlstra3a659302009-07-21 17:34:57 +0200408#endif
409
Li Zefan7fcb7c42009-06-01 15:35:46 +0800410/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200411 * Stage 4 of the trace events.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400412 *
413 * Override the macros in <trace/trace_events.h> to include the following:
414 *
415 * static void ftrace_event_<call>(proto)
416 * {
417 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
418 * }
419 *
420 * static int ftrace_reg_event_<call>(void)
421 * {
422 * int ret;
423 *
424 * ret = register_trace_<call>(ftrace_event_<call>);
425 * if (!ret)
426 * pr_info("event trace: Could not activate trace point "
427 * "probe to <call>");
428 * return ret;
429 * }
430 *
431 * static void ftrace_unreg_event_<call>(void)
432 * {
433 * unregister_trace_<call>(ftrace_event_<call>);
434 * }
435 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400436 *
437 * For those macros defined with TRACE_EVENT:
438 *
439 * static struct ftrace_event_call event_<call>;
440 *
441 * static void ftrace_raw_event_<call>(proto)
442 * {
443 * struct ring_buffer_event *event;
444 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
445 * unsigned long irq_flags;
446 * int pc;
447 *
448 * local_save_flags(irq_flags);
449 * pc = preempt_count();
450 *
451 * event = trace_current_buffer_lock_reserve(event_<call>.id,
452 * sizeof(struct ftrace_raw_<call>),
453 * irq_flags, pc);
454 * if (!event)
455 * return;
456 * entry = ring_buffer_event_data(event);
457 *
458 * <assign>; <-- Here we assign the entries by the __field and
459 * __array macros.
460 *
461 * trace_current_buffer_unlock_commit(event, irq_flags, pc);
462 * }
463 *
464 * static int ftrace_raw_reg_event_<call>(void)
465 * {
466 * int ret;
467 *
468 * ret = register_trace_<call>(ftrace_raw_event_<call>);
469 * if (!ret)
470 * pr_info("event trace: Could not activate trace point "
471 * "probe to <call>");
472 * return ret;
473 * }
474 *
475 * static void ftrace_unreg_event_<call>(void)
476 * {
477 * unregister_trace_<call>(ftrace_raw_event_<call>);
478 * }
479 *
480 * static struct trace_event ftrace_event_type_<call> = {
481 * .trace = ftrace_raw_output_<call>, <-- stage 2
482 * };
483 *
484 * static int ftrace_raw_init_event_<call>(void)
485 * {
486 * int id;
487 *
488 * id = register_ftrace_event(&ftrace_event_type_<call>);
489 * if (!id)
490 * return -ENODEV;
491 * event_<call>.id = id;
492 * return 0;
493 * }
494 *
495 * static struct ftrace_event_call __used
496 * __attribute__((__aligned__(4)))
497 * __attribute__((section("_ftrace_events"))) event_<call> = {
498 * .name = "<call>",
499 * .system = "<system>",
500 * .raw_init = ftrace_raw_init_event_<call>,
501 * .regfunc = ftrace_reg_event_<call>,
502 * .unregfunc = ftrace_unreg_event_<call>,
503 * .show_format = ftrace_format_<call>,
504 * }
505 *
506 */
507
508#undef TP_FMT
509#define TP_FMT(fmt, args...) fmt "\n", ##args
510
511#ifdef CONFIG_EVENT_PROFILE
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400512
513#define _TRACE_PROFILE_INIT(call) \
514 .profile_count = ATOMIC_INIT(-1), \
515 .profile_enable = ftrace_profile_enable_##call, \
516 .profile_disable = ftrace_profile_disable_##call,
517
518#else
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400519#define _TRACE_PROFILE_INIT(call)
520#endif
521
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400522#undef __entry
523#define __entry entry
524
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200525#undef __field
526#define __field(type, item)
527
528#undef __array
529#define __array(type, item, len)
530
Li Zefan7fcb7c42009-06-01 15:35:46 +0800531#undef __dynamic_array
532#define __dynamic_array(type, item, len) \
533 __entry->__data_loc_##item = __data_offsets.item;
534
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200535#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800536#define __string(item, src) __dynamic_array(char, item, -1) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200537
538#undef __assign_str
539#define __assign_str(dst, src) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200540 strcpy(__get_str(dst), src);
541
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400542#undef TRACE_EVENT
543#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400544 \
545static struct ftrace_event_call event_##call; \
546 \
547static void ftrace_raw_event_##call(proto) \
548{ \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800549 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Zhaoleif2aebae2009-05-27 21:36:02 +0800550 struct ftrace_event_call *event_call = &event_##call; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400551 struct ring_buffer_event *event; \
552 struct ftrace_raw_##call *entry; \
553 unsigned long irq_flags; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800554 int __data_size; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400555 int pc; \
556 \
557 local_save_flags(irq_flags); \
558 pc = preempt_count(); \
559 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800560 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200561 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400562 event = trace_current_buffer_lock_reserve(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 \
570 tstruct \
571 \
Li Zefana9c1c3a2009-06-01 15:35:13 +0800572 { assign; } \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400573 \
Zhaoleif2aebae2009-05-27 21:36:02 +0800574 if (!filter_current_check_discard(event_call, entry, event)) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400575 trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \
576} \
577 \
Jason Baron69fd4f02009-08-10 16:52:44 -0400578static int ftrace_raw_reg_event_##call(void *ptr) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400579{ \
580 int ret; \
581 \
582 ret = register_trace_##call(ftrace_raw_event_##call); \
583 if (ret) \
584 pr_info("event trace: Could not activate trace point " \
585 "probe to " #call "\n"); \
586 return ret; \
587} \
588 \
Jason Baron69fd4f02009-08-10 16:52:44 -0400589static void ftrace_raw_unreg_event_##call(void *ptr) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400590{ \
591 unregister_trace_##call(ftrace_raw_event_##call); \
592} \
593 \
594static struct trace_event ftrace_event_type_##call = { \
595 .trace = ftrace_raw_output_##call, \
596}; \
597 \
598static int ftrace_raw_init_event_##call(void) \
599{ \
600 int id; \
601 \
602 id = register_ftrace_event(&ftrace_event_type_##call); \
603 if (!id) \
604 return -ENODEV; \
605 event_##call.id = id; \
606 INIT_LIST_HEAD(&event_##call.fields); \
607 init_preds(&event_##call); \
608 return 0; \
609} \
610 \
611static struct ftrace_event_call __used \
612__attribute__((__aligned__(4))) \
613__attribute__((section("_ftrace_events"))) event_##call = { \
614 .name = #call, \
615 .system = __stringify(TRACE_SYSTEM), \
Steven Rostedt6d723732009-04-10 14:53:50 -0400616 .event = &ftrace_event_type_##call, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400617 .raw_init = ftrace_raw_init_event_##call, \
618 .regfunc = ftrace_raw_reg_event_##call, \
619 .unregfunc = ftrace_raw_unreg_event_##call, \
620 .show_format = ftrace_format_##call, \
621 .define_fields = ftrace_define_fields_##call, \
622 _TRACE_PROFILE_INIT(call) \
623}
624
625#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
626
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200627/*
628 * Define the insertion callback to profile events
629 *
630 * The job is very similar to ftrace_raw_event_<call> except that we don't
631 * insert in the ring buffer but in a perf counter.
632 *
633 * static void ftrace_profile_<call>(proto)
634 * {
635 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
636 * struct ftrace_event_call *event_call = &event_<call>;
637 * extern void perf_tpcounter_event(int, u64, u64, void *, int);
638 * struct ftrace_raw_##call *entry;
639 * u64 __addr = 0, __count = 1;
640 * unsigned long irq_flags;
641 * int __entry_size;
642 * int __data_size;
643 * int pc;
644 *
645 * local_save_flags(irq_flags);
646 * pc = preempt_count();
647 *
648 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200649 *
650 * // Below we want to get the aligned size by taking into account
651 * // the u32 field that will later store the buffer size
652 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
653 * sizeof(u64));
654 * __entry_size -= sizeof(u32);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200655 *
656 * do {
657 * char raw_data[__entry_size]; <- allocate our sample in the stack
658 * struct trace_entry *ent;
659 *
Frederic Weisbecker1853db02009-08-10 16:38:36 +0200660 * zero dead bytes from alignment to avoid stack leak to userspace:
661 *
662 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200663 * entry = (struct ftrace_raw_<call> *)raw_data;
664 * ent = &entry->ent;
665 * tracing_generic_entry_update(ent, irq_flags, pc);
666 * ent->type = event_call->id;
667 *
668 * <tstruct> <- do some jobs with dynamic arrays
669 *
670 * <assign> <- affect our values
671 *
672 * perf_tpcounter_event(event_call->id, __addr, __count, entry,
673 * __entry_size); <- submit them to perf counter
674 * } while (0);
675 *
676 * }
677 */
678
679#ifdef CONFIG_EVENT_PROFILE
680
681#undef __perf_addr
682#define __perf_addr(a) __addr = (a)
683
684#undef __perf_count
685#define __perf_count(c) __count = (c)
686
687#undef TRACE_EVENT
688#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
689static void ftrace_profile_##call(proto) \
690{ \
691 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
692 struct ftrace_event_call *event_call = &event_##call; \
693 extern void perf_tpcounter_event(int, u64, u64, void *, int); \
694 struct ftrace_raw_##call *entry; \
695 u64 __addr = 0, __count = 1; \
696 unsigned long irq_flags; \
697 int __entry_size; \
698 int __data_size; \
699 int pc; \
700 \
701 local_save_flags(irq_flags); \
702 pc = preempt_count(); \
703 \
704 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Peter Zijlstraa0445602009-08-10 11:16:52 +0200705 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
706 sizeof(u64)); \
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200707 __entry_size -= sizeof(u32); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200708 \
709 do { \
710 char raw_data[__entry_size]; \
711 struct trace_entry *ent; \
712 \
Frederic Weisbecker1853db02009-08-10 16:38:36 +0200713 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200714 entry = (struct ftrace_raw_##call *)raw_data; \
715 ent = &entry->ent; \
716 tracing_generic_entry_update(ent, irq_flags, pc); \
717 ent->type = event_call->id; \
718 \
719 tstruct \
720 \
721 { assign; } \
722 \
723 perf_tpcounter_event(event_call->id, __addr, __count, entry,\
724 __entry_size); \
725 } while (0); \
726 \
727}
728
729#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
730#endif /* CONFIG_EVENT_PROFILE */
731
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400732#undef _TRACE_PROFILE_INIT
733