blob: 57c56a998ee6279dead48b6d2f2ad566b711de69 [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 Zefan43b51ea2009-08-07 10:33:22 +080024#undef __field_ext
25#define __field_ext(type, item, filter_type) type item;
26
Li Zefan7fcb7c42009-06-01 15:35:46 +080027#undef __array
28#define __array(type, item, len) type item[len];
29
30#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +080031#define __dynamic_array(type, item, len) u32 __data_loc_##item;
Li Zefan7fcb7c42009-06-01 15:35:46 +080032
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020033#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +080034#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020035
Steven Rostedtf42c85e2009-04-13 12:25:37 -040036#undef TP_STRUCT__entry
37#define TP_STRUCT__entry(args...) args
38
39#undef TRACE_EVENT
40#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
41 struct ftrace_raw_##name { \
42 struct trace_entry ent; \
43 tstruct \
Li Zefan7fcb7c42009-06-01 15:35:46 +080044 char __data[0]; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -040045 }; \
46 static struct ftrace_event_call event_##name
47
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +020048#undef __cpparg
49#define __cpparg(arg...) arg
50
Josh Stone97419872009-08-24 14:43:13 -070051/* Callbacks are meaningless to ftrace. */
52#undef TRACE_EVENT_FN
Frederic Weisbecker0dd7b742009-08-28 00:50:06 +020053#define TRACE_EVENT_FN(name, proto, args, tstruct, \
54 assign, print, reg, unreg) \
55 TRACE_EVENT(name, __cpparg(proto), __cpparg(args), \
56 __cpparg(tstruct), __cpparg(assign), __cpparg(print)) \
Josh Stone97419872009-08-24 14:43:13 -070057
Steven Rostedtf42c85e2009-04-13 12:25:37 -040058#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
59
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020060
Steven Rostedtf42c85e2009-04-13 12:25:37 -040061/*
62 * Stage 2 of the trace events.
63 *
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020064 * Include the following:
65 *
Li Zefan7fcb7c42009-06-01 15:35:46 +080066 * struct ftrace_data_offsets_<call> {
Li Zefan7d536cb2009-07-16 10:54:02 +080067 * u32 <item1>;
68 * u32 <item2>;
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020069 * [...]
70 * };
71 *
Li Zefan7d536cb2009-07-16 10:54:02 +080072 * The __dynamic_array() macro will create each u32 <item>, this is
Li Zefan7fcb7c42009-06-01 15:35:46 +080073 * to keep the offset of each array from the beginning of the event.
Li Zefan7d536cb2009-07-16 10:54:02 +080074 * The size of an array is also encoded, in the higher 16 bits of <item>.
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020075 */
76
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020077#undef __field
Li Zefan43b51ea2009-08-07 10:33:22 +080078#define __field(type, item)
79
80#undef __field_ext
81#define __field_ext(type, item, filter_type)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020082
Li Zefan7fcb7c42009-06-01 15:35:46 +080083#undef __array
84#define __array(type, item, len)
85
86#undef __dynamic_array
Li Zefan7d536cb2009-07-16 10:54:02 +080087#define __dynamic_array(type, item, len) u32 item;
Li Zefan7fcb7c42009-06-01 15:35:46 +080088
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020089#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +080090#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020091
92#undef TRACE_EVENT
93#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
Li Zefan7fcb7c42009-06-01 15:35:46 +080094 struct ftrace_data_offsets_##call { \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +020095 tstruct; \
96 };
97
98#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
99
100/*
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400101 * Setup the showing format of trace point.
102 *
103 * int
104 * ftrace_format_##call(struct trace_seq *s)
105 * {
106 * struct ftrace_raw_##call field;
107 * int ret;
108 *
109 * ret = trace_seq_printf(s, #type " " #item ";"
110 * " offset:%u; size:%u;\n",
111 * offsetof(struct ftrace_raw_##call, item),
112 * sizeof(field.type));
113 *
114 * }
115 */
116
117#undef TP_STRUCT__entry
118#define TP_STRUCT__entry(args...) args
119
120#undef __field
121#define __field(type, item) \
122 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
123 "offset:%u;\tsize:%u;\n", \
124 (unsigned int)offsetof(typeof(field), item), \
125 (unsigned int)sizeof(field.item)); \
126 if (!ret) \
127 return 0;
128
Li Zefan43b51ea2009-08-07 10:33:22 +0800129#undef __field_ext
130#define __field_ext(type, item, filter_type) __field(type, item)
131
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400132#undef __array
133#define __array(type, item, len) \
134 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
135 "offset:%u;\tsize:%u;\n", \
136 (unsigned int)offsetof(typeof(field), item), \
137 (unsigned int)sizeof(field.item)); \
138 if (!ret) \
139 return 0;
140
141#undef __dynamic_array
142#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800143 ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400144 "offset:%u;\tsize:%u;\n", \
145 (unsigned int)offsetof(typeof(field), \
146 __data_loc_##item), \
147 (unsigned int)sizeof(field.__data_loc_##item)); \
148 if (!ret) \
149 return 0;
150
151#undef __string
152#define __string(item, src) __dynamic_array(char, item, -1)
153
154#undef __entry
155#define __entry REC
156
157#undef __print_symbolic
158#undef __get_dynamic_array
159#undef __get_str
160
161#undef TP_printk
162#define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
163
164#undef TP_fast_assign
165#define TP_fast_assign(args...) args
166
Peter Zijlstra3a659302009-07-21 17:34:57 +0200167#undef TP_perf_assign
168#define TP_perf_assign(args...)
169
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400170#undef TRACE_EVENT
171#define TRACE_EVENT(call, proto, args, tstruct, func, print) \
172static int \
Frederic Weisbeckere8f9f4d2009-08-11 17:42:52 +0200173ftrace_format_##call(struct ftrace_event_call *unused, \
174 struct trace_seq *s) \
Steven Rostedt6ff9a642009-06-10 14:28:34 -0400175{ \
176 struct ftrace_raw_##call field __attribute__((unused)); \
177 int ret = 0; \
178 \
179 tstruct; \
180 \
181 trace_seq_printf(s, "\nprint fmt: " print); \
182 \
183 return ret; \
184}
185
186#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
187
188/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200189 * Stage 3 of the trace events.
190 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400191 * Override the macros in <trace/trace_events.h> to include the following:
192 *
193 * enum print_line_t
194 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
195 * {
196 * struct trace_seq *s = &iter->seq;
197 * struct ftrace_raw_<call> *field; <-- defined in stage 1
198 * struct trace_entry *entry;
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200199 * struct trace_seq *p;
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400200 * int ret;
201 *
202 * entry = iter->ent;
203 *
204 * if (entry->type != event_<call>.id) {
205 * WARN_ON_ONCE(1);
206 * return TRACE_TYPE_UNHANDLED;
207 * }
208 *
209 * field = (typeof(field))entry;
210 *
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200211 * p = get_cpu_var(ftrace_event_seq);
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100212 * trace_seq_init(p);
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400213 * ret = trace_seq_printf(s, <TP_printk> "\n");
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200214 * put_cpu();
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400215 * if (!ret)
216 * return TRACE_TYPE_PARTIAL_LINE;
217 *
218 * return TRACE_TYPE_HANDLED;
219 * }
220 *
221 * This is the method used to print the raw event to the trace
222 * output format. Note, this is not needed if the data is read
223 * in binary.
224 */
225
226#undef __entry
227#define __entry field
228
229#undef TP_printk
230#define TP_printk(fmt, args...) fmt "\n", args
231
Li Zefan7fcb7c42009-06-01 15:35:46 +0800232#undef __get_dynamic_array
233#define __get_dynamic_array(field) \
Li Zefan7d536cb2009-07-16 10:54:02 +0800234 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
Li Zefan7fcb7c42009-06-01 15:35:46 +0800235
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200236#undef __get_str
Li Zefan7fcb7c42009-06-01 15:35:46 +0800237#define __get_str(field) (char *)__get_dynamic_array(field)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200238
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200239#undef __print_flags
240#define __print_flags(flag, delim, flag_array...) \
241 ({ \
242 static const struct trace_print_flags flags[] = \
243 { flag_array, { -1, NULL }}; \
244 ftrace_print_flags_seq(p, delim, flag, flags); \
245 })
246
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400247#undef __print_symbolic
248#define __print_symbolic(value, symbol_array...) \
249 ({ \
250 static const struct trace_print_flags symbols[] = \
251 { symbol_array, { -1, NULL }}; \
252 ftrace_print_symbols_seq(p, value, symbols); \
253 })
254
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400255#undef TRACE_EVENT
256#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
257enum print_line_t \
258ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
259{ \
260 struct trace_seq *s = &iter->seq; \
261 struct ftrace_raw_##call *field; \
262 struct trace_entry *entry; \
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200263 struct trace_seq *p; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400264 int ret; \
265 \
266 entry = iter->ent; \
267 \
268 if (entry->type != event_##call.id) { \
269 WARN_ON_ONCE(1); \
270 return TRACE_TYPE_UNHANDLED; \
271 } \
272 \
273 field = (typeof(field))entry; \
274 \
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200275 p = &get_cpu_var(ftrace_event_seq); \
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100276 trace_seq_init(p); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400277 ret = trace_seq_printf(s, #call ": " print); \
Steven Rostedtbe74b73a2009-05-26 20:25:22 +0200278 put_cpu(); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400279 if (!ret) \
280 return TRACE_TYPE_PARTIAL_LINE; \
281 \
282 return TRACE_TYPE_HANDLED; \
283}
284
285#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
286
Li Zefan43b51ea2009-08-07 10:33:22 +0800287#undef __field_ext
288#define __field_ext(type, item, filter_type) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400289 ret = trace_define_field(event_call, #type, #item, \
290 offsetof(typeof(field), item), \
Li Zefan43b51ea2009-08-07 10:33:22 +0800291 sizeof(field.item), \
292 is_signed_type(type), filter_type); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400293 if (ret) \
294 return ret;
295
Li Zefan43b51ea2009-08-07 10:33:22 +0800296#undef __field
297#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
298
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400299#undef __array
300#define __array(type, item, len) \
301 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
302 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
303 offsetof(typeof(field), item), \
Li Zefan43b51ea2009-08-07 10:33:22 +0800304 sizeof(field.item), 0, FILTER_OTHER); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400305 if (ret) \
306 return ret;
307
Li Zefan7fcb7c42009-06-01 15:35:46 +0800308#undef __dynamic_array
309#define __dynamic_array(type, item, len) \
Lai Jiangshan68fd60a2009-07-16 10:53:34 +0800310 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
Li Zefan43b51ea2009-08-07 10:33:22 +0800311 offsetof(typeof(field), __data_loc_##item), \
312 sizeof(field.__data_loc_##item), 0, \
313 FILTER_OTHER);
Li Zefan7fcb7c42009-06-01 15:35:46 +0800314
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200315#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800316#define __string(item, src) __dynamic_array(char, item, -1)
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200317
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400318#undef TRACE_EVENT
319#define TRACE_EVENT(call, proto, args, tstruct, func, print) \
320int \
Li Zefan14be96c2009-08-19 15:53:52 +0800321ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400322{ \
323 struct ftrace_raw_##call field; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400324 int ret; \
325 \
Li Zefane647d6b2009-08-19 15:54:32 +0800326 ret = trace_define_common_fields(event_call); \
327 if (ret) \
328 return ret; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400329 \
330 tstruct; \
331 \
332 return ret; \
333}
334
335#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
336
337/*
Li Zefan7fcb7c42009-06-01 15:35:46 +0800338 * remember the offset of each array from the beginning of the event.
339 */
340
341#undef __entry
342#define __entry entry
343
344#undef __field
345#define __field(type, item)
346
Li Zefan43b51ea2009-08-07 10:33:22 +0800347#undef __field_ext
348#define __field_ext(type, item, filter_type)
349
Li Zefan7fcb7c42009-06-01 15:35:46 +0800350#undef __array
351#define __array(type, item, len)
352
353#undef __dynamic_array
354#define __dynamic_array(type, item, len) \
355 __data_offsets->item = __data_size + \
356 offsetof(typeof(*entry), __data); \
Li Zefan7d536cb2009-07-16 10:54:02 +0800357 __data_offsets->item |= (len * sizeof(type)) << 16; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800358 __data_size += (len) * sizeof(type);
359
360#undef __string
361#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \
362
363#undef TRACE_EVENT
364#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
365static inline int ftrace_get_offsets_##call( \
366 struct ftrace_data_offsets_##call *__data_offsets, proto) \
367{ \
368 int __data_size = 0; \
369 struct ftrace_raw_##call __maybe_unused *entry; \
370 \
371 tstruct; \
372 \
373 return __data_size; \
374}
375
376#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
377
Peter Zijlstra3a659302009-07-21 17:34:57 +0200378#ifdef CONFIG_EVENT_PROFILE
379
380/*
381 * Generate the functions needed for tracepoint perf_counter support.
382 *
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200383 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
Peter Zijlstra3a659302009-07-21 17:34:57 +0200384 *
385 * static int ftrace_profile_enable_<call>(struct ftrace_event_call *event_call)
386 * {
387 * int ret = 0;
388 *
389 * if (!atomic_inc_return(&event_call->profile_count))
390 * ret = register_trace_<call>(ftrace_profile_<call>);
391 *
392 * return ret;
393 * }
394 *
395 * static void ftrace_profile_disable_<call>(struct ftrace_event_call *event_call)
396 * {
397 * if (atomic_add_negative(-1, &event->call->profile_count))
398 * unregister_trace_<call>(ftrace_profile_<call>);
399 * }
400 *
401 */
402
Peter Zijlstra3a659302009-07-21 17:34:57 +0200403#undef TRACE_EVENT
404#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
405 \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200406static void ftrace_profile_##call(proto); \
Peter Zijlstra3a659302009-07-21 17:34:57 +0200407 \
408static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
409{ \
410 int ret = 0; \
411 \
412 if (!atomic_inc_return(&event_call->profile_count)) \
413 ret = register_trace_##call(ftrace_profile_##call); \
414 \
415 return ret; \
416} \
417 \
418static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
419{ \
420 if (atomic_add_negative(-1, &event_call->profile_count)) \
421 unregister_trace_##call(ftrace_profile_##call); \
422}
423
424#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
425
Peter Zijlstra3a659302009-07-21 17:34:57 +0200426#endif
427
Li Zefan7fcb7c42009-06-01 15:35:46 +0800428/*
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200429 * Stage 4 of the trace events.
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400430 *
431 * Override the macros in <trace/trace_events.h> to include the following:
432 *
433 * static void ftrace_event_<call>(proto)
434 * {
435 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
436 * }
437 *
438 * static int ftrace_reg_event_<call>(void)
439 * {
440 * int ret;
441 *
442 * ret = register_trace_<call>(ftrace_event_<call>);
443 * if (!ret)
444 * pr_info("event trace: Could not activate trace point "
445 * "probe to <call>");
446 * return ret;
447 * }
448 *
449 * static void ftrace_unreg_event_<call>(void)
450 * {
451 * unregister_trace_<call>(ftrace_event_<call>);
452 * }
453 *
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400454 *
455 * For those macros defined with TRACE_EVENT:
456 *
457 * static struct ftrace_event_call event_<call>;
458 *
459 * static void ftrace_raw_event_<call>(proto)
460 * {
461 * struct ring_buffer_event *event;
462 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
463 * unsigned long irq_flags;
464 * int pc;
465 *
466 * local_save_flags(irq_flags);
467 * pc = preempt_count();
468 *
469 * event = trace_current_buffer_lock_reserve(event_<call>.id,
470 * sizeof(struct ftrace_raw_<call>),
471 * irq_flags, pc);
472 * if (!event)
473 * return;
474 * entry = ring_buffer_event_data(event);
475 *
476 * <assign>; <-- Here we assign the entries by the __field and
477 * __array macros.
478 *
479 * trace_current_buffer_unlock_commit(event, irq_flags, pc);
480 * }
481 *
482 * static int ftrace_raw_reg_event_<call>(void)
483 * {
484 * int ret;
485 *
486 * ret = register_trace_<call>(ftrace_raw_event_<call>);
487 * if (!ret)
488 * pr_info("event trace: Could not activate trace point "
489 * "probe to <call>");
490 * return ret;
491 * }
492 *
493 * static void ftrace_unreg_event_<call>(void)
494 * {
495 * unregister_trace_<call>(ftrace_raw_event_<call>);
496 * }
497 *
498 * static struct trace_event ftrace_event_type_<call> = {
499 * .trace = ftrace_raw_output_<call>, <-- stage 2
500 * };
501 *
502 * static int ftrace_raw_init_event_<call>(void)
503 * {
504 * int id;
505 *
506 * id = register_ftrace_event(&ftrace_event_type_<call>);
507 * if (!id)
508 * return -ENODEV;
509 * event_<call>.id = id;
510 * return 0;
511 * }
512 *
513 * static struct ftrace_event_call __used
514 * __attribute__((__aligned__(4)))
515 * __attribute__((section("_ftrace_events"))) event_<call> = {
516 * .name = "<call>",
517 * .system = "<system>",
518 * .raw_init = ftrace_raw_init_event_<call>,
519 * .regfunc = ftrace_reg_event_<call>,
520 * .unregfunc = ftrace_unreg_event_<call>,
521 * .show_format = ftrace_format_<call>,
522 * }
523 *
524 */
525
526#undef TP_FMT
527#define TP_FMT(fmt, args...) fmt "\n", ##args
528
529#ifdef CONFIG_EVENT_PROFILE
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400530
531#define _TRACE_PROFILE_INIT(call) \
532 .profile_count = ATOMIC_INIT(-1), \
533 .profile_enable = ftrace_profile_enable_##call, \
534 .profile_disable = ftrace_profile_disable_##call,
535
536#else
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400537#define _TRACE_PROFILE_INIT(call)
538#endif
539
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400540#undef __entry
541#define __entry entry
542
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200543#undef __field
544#define __field(type, item)
545
546#undef __array
547#define __array(type, item, len)
548
Li Zefan7fcb7c42009-06-01 15:35:46 +0800549#undef __dynamic_array
550#define __dynamic_array(type, item, len) \
551 __entry->__data_loc_##item = __data_offsets.item;
552
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200553#undef __string
Li Zefan7fcb7c42009-06-01 15:35:46 +0800554#define __string(item, src) __dynamic_array(char, item, -1) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200555
556#undef __assign_str
557#define __assign_str(dst, src) \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200558 strcpy(__get_str(dst), src);
559
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400560#undef TRACE_EVENT
561#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400562 \
563static struct ftrace_event_call event_##call; \
564 \
565static void ftrace_raw_event_##call(proto) \
566{ \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800567 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
Zhaoleif2aebae2009-05-27 21:36:02 +0800568 struct ftrace_event_call *event_call = &event_##call; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400569 struct ring_buffer_event *event; \
570 struct ftrace_raw_##call *entry; \
571 unsigned long irq_flags; \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800572 int __data_size; \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400573 int pc; \
574 \
575 local_save_flags(irq_flags); \
576 pc = preempt_count(); \
577 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800578 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200579 \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400580 event = trace_current_buffer_lock_reserve(event_##call.id, \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800581 sizeof(*entry) + __data_size, \
Frederic Weisbecker9cbf1172009-04-19 04:51:29 +0200582 irq_flags, pc); \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400583 if (!event) \
584 return; \
585 entry = ring_buffer_event_data(event); \
586 \
Li Zefan7fcb7c42009-06-01 15:35:46 +0800587 \
588 tstruct \
589 \
Li Zefana9c1c3a2009-06-01 15:35:13 +0800590 { assign; } \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400591 \
Zhaoleif2aebae2009-05-27 21:36:02 +0800592 if (!filter_current_check_discard(event_call, entry, event)) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400593 trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \
594} \
595 \
Jason Baron69fd4f02009-08-10 16:52:44 -0400596static int ftrace_raw_reg_event_##call(void *ptr) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400597{ \
598 int ret; \
599 \
600 ret = register_trace_##call(ftrace_raw_event_##call); \
601 if (ret) \
602 pr_info("event trace: Could not activate trace point " \
603 "probe to " #call "\n"); \
604 return ret; \
605} \
606 \
Jason Baron69fd4f02009-08-10 16:52:44 -0400607static void ftrace_raw_unreg_event_##call(void *ptr) \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400608{ \
609 unregister_trace_##call(ftrace_raw_event_##call); \
610} \
611 \
612static struct trace_event ftrace_event_type_##call = { \
613 .trace = ftrace_raw_output_##call, \
614}; \
615 \
616static int ftrace_raw_init_event_##call(void) \
617{ \
618 int id; \
619 \
620 id = register_ftrace_event(&ftrace_event_type_##call); \
621 if (!id) \
622 return -ENODEV; \
623 event_##call.id = id; \
624 INIT_LIST_HEAD(&event_##call.fields); \
625 init_preds(&event_##call); \
626 return 0; \
627} \
628 \
629static struct ftrace_event_call __used \
630__attribute__((__aligned__(4))) \
631__attribute__((section("_ftrace_events"))) event_##call = { \
632 .name = #call, \
633 .system = __stringify(TRACE_SYSTEM), \
Steven Rostedt6d723732009-04-10 14:53:50 -0400634 .event = &ftrace_event_type_##call, \
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400635 .raw_init = ftrace_raw_init_event_##call, \
636 .regfunc = ftrace_raw_reg_event_##call, \
637 .unregfunc = ftrace_raw_unreg_event_##call, \
638 .show_format = ftrace_format_##call, \
639 .define_fields = ftrace_define_fields_##call, \
640 _TRACE_PROFILE_INIT(call) \
641}
642
643#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
644
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200645/*
646 * Define the insertion callback to profile events
647 *
648 * The job is very similar to ftrace_raw_event_<call> except that we don't
649 * insert in the ring buffer but in a perf counter.
650 *
651 * static void ftrace_profile_<call>(proto)
652 * {
653 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
654 * struct ftrace_event_call *event_call = &event_<call>;
655 * extern void perf_tpcounter_event(int, u64, u64, void *, int);
656 * struct ftrace_raw_##call *entry;
657 * u64 __addr = 0, __count = 1;
658 * unsigned long irq_flags;
659 * int __entry_size;
660 * int __data_size;
661 * int pc;
662 *
663 * local_save_flags(irq_flags);
664 * pc = preempt_count();
665 *
666 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200667 *
668 * // Below we want to get the aligned size by taking into account
669 * // the u32 field that will later store the buffer size
670 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
671 * sizeof(u64));
672 * __entry_size -= sizeof(u32);
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200673 *
674 * do {
675 * char raw_data[__entry_size]; <- allocate our sample in the stack
676 * struct trace_entry *ent;
677 *
Frederic Weisbecker1853db02009-08-10 16:38:36 +0200678 * zero dead bytes from alignment to avoid stack leak to userspace:
679 *
680 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200681 * entry = (struct ftrace_raw_<call> *)raw_data;
682 * ent = &entry->ent;
683 * tracing_generic_entry_update(ent, irq_flags, pc);
684 * ent->type = event_call->id;
685 *
686 * <tstruct> <- do some jobs with dynamic arrays
687 *
688 * <assign> <- affect our values
689 *
690 * perf_tpcounter_event(event_call->id, __addr, __count, entry,
691 * __entry_size); <- submit them to perf counter
692 * } while (0);
693 *
694 * }
695 */
696
697#ifdef CONFIG_EVENT_PROFILE
698
699#undef __perf_addr
700#define __perf_addr(a) __addr = (a)
701
702#undef __perf_count
703#define __perf_count(c) __count = (c)
704
705#undef TRACE_EVENT
706#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
707static void ftrace_profile_##call(proto) \
708{ \
709 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
710 struct ftrace_event_call *event_call = &event_##call; \
711 extern void perf_tpcounter_event(int, u64, u64, void *, int); \
712 struct ftrace_raw_##call *entry; \
713 u64 __addr = 0, __count = 1; \
714 unsigned long irq_flags; \
715 int __entry_size; \
716 int __data_size; \
717 int pc; \
718 \
719 local_save_flags(irq_flags); \
720 pc = preempt_count(); \
721 \
722 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
Peter Zijlstraa0445602009-08-10 11:16:52 +0200723 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
724 sizeof(u64)); \
Frederic Weisbecker304703a2009-08-10 16:11:32 +0200725 __entry_size -= sizeof(u32); \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200726 \
727 do { \
728 char raw_data[__entry_size]; \
729 struct trace_entry *ent; \
730 \
Frederic Weisbecker1853db02009-08-10 16:38:36 +0200731 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
Frederic Weisbeckerf413cdb2009-08-07 01:25:54 +0200732 entry = (struct ftrace_raw_##call *)raw_data; \
733 ent = &entry->ent; \
734 tracing_generic_entry_update(ent, irq_flags, pc); \
735 ent->type = event_call->id; \
736 \
737 tstruct \
738 \
739 { assign; } \
740 \
741 perf_tpcounter_event(event_call->id, __addr, __count, entry,\
742 __entry_size); \
743 } while (0); \
744 \
745}
746
747#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
748#endif /* CONFIG_EVENT_PROFILE */
749
Steven Rostedtf42c85e2009-04-13 12:25:37 -0400750#undef _TRACE_PROFILE_INIT
751