tracing: Make syscall tracepoints conditional
[linux-2.6-block.git] / include / trace / ftrace.h
CommitLineData
f42c85e7
SR
1/*
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
7fcb7c47
LZ
21#undef __field
22#define __field(type, item) type item;
23
f42c85e7
SR
24#undef __array
25#define __array(type, item, len) type item[len];
26
7fcb7c47 27#undef __dynamic_array
7d536cb3 28#define __dynamic_array(type, item, len) u32 __data_loc_##item;
f42c85e7 29
9cbf1176 30#undef __string
7fcb7c47 31#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 32
f42c85e7
SR
33#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 \
7fcb7c47 41 char __data[0]; \
f42c85e7
SR
42 }; \
43 static struct ftrace_event_call event_##name
44
45#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
46
9cbf1176 47
f42c85e7
SR
48/*
49 * Stage 2 of the trace events.
50 *
9cbf1176
FW
51 * Include the following:
52 *
7fcb7c47 53 * struct ftrace_data_offsets_<call> {
7d536cb3
LZ
54 * u32 <item1>;
55 * u32 <item2>;
9cbf1176
FW
56 * [...]
57 * };
58 *
7d536cb3 59 * The __dynamic_array() macro will create each u32 <item>, this is
7fcb7c47 60 * to keep the offset of each array from the beginning of the event.
7d536cb3 61 * The size of an array is also encoded, in the higher 16 bits of <item>.
9cbf1176
FW
62 */
63
7fcb7c47
LZ
64#undef __field
65#define __field(type, item);
66
9cbf1176
FW
67#undef __array
68#define __array(type, item, len)
69
7fcb7c47 70#undef __dynamic_array
7d536cb3 71#define __dynamic_array(type, item, len) u32 item;
9cbf1176
FW
72
73#undef __string
7fcb7c47 74#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176
FW
75
76#undef TRACE_EVENT
77#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
7fcb7c47 78 struct ftrace_data_offsets_##call { \
9cbf1176
FW
79 tstruct; \
80 };
81
82#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
83
6ff9a64d
SR
84/*
85 * Setup the showing format of trace point.
86 *
87 * int
88 * ftrace_format_##call(struct trace_seq *s)
89 * {
90 * struct ftrace_raw_##call field;
91 * int ret;
92 *
93 * ret = trace_seq_printf(s, #type " " #item ";"
94 * " offset:%u; size:%u;\n",
95 * offsetof(struct ftrace_raw_##call, item),
96 * sizeof(field.type));
97 *
98 * }
99 */
100
101#undef TP_STRUCT__entry
102#define TP_STRUCT__entry(args...) args
103
104#undef __field
105#define __field(type, item) \
106 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
107 "offset:%u;\tsize:%u;\n", \
108 (unsigned int)offsetof(typeof(field), item), \
109 (unsigned int)sizeof(field.item)); \
110 if (!ret) \
111 return 0;
112
113#undef __array
114#define __array(type, item, len) \
115 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\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 __dynamic_array
123#define __dynamic_array(type, item, len) \
68fd60a8 124 ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
6ff9a64d
SR
125 "offset:%u;\tsize:%u;\n", \
126 (unsigned int)offsetof(typeof(field), \
127 __data_loc_##item), \
128 (unsigned int)sizeof(field.__data_loc_##item)); \
129 if (!ret) \
130 return 0;
131
132#undef __string
133#define __string(item, src) __dynamic_array(char, item, -1)
134
135#undef __entry
136#define __entry REC
137
138#undef __print_symbolic
139#undef __get_dynamic_array
140#undef __get_str
141
142#undef TP_printk
143#define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
144
145#undef TP_fast_assign
146#define TP_fast_assign(args...) args
147
3a659305
PZ
148#undef TP_perf_assign
149#define TP_perf_assign(args...)
150
6ff9a64d
SR
151#undef TRACE_EVENT
152#define TRACE_EVENT(call, proto, args, tstruct, func, print) \
153static int \
e8f9f4d7
FW
154ftrace_format_##call(struct ftrace_event_call *unused, \
155 struct trace_seq *s) \
6ff9a64d
SR
156{ \
157 struct ftrace_raw_##call field __attribute__((unused)); \
158 int ret = 0; \
159 \
160 tstruct; \
161 \
162 trace_seq_printf(s, "\nprint fmt: " print); \
163 \
164 return ret; \
165}
166
167#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
168
9cbf1176
FW
169/*
170 * Stage 3 of the trace events.
171 *
f42c85e7
SR
172 * Override the macros in <trace/trace_events.h> to include the following:
173 *
174 * enum print_line_t
175 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
176 * {
177 * struct trace_seq *s = &iter->seq;
178 * struct ftrace_raw_<call> *field; <-- defined in stage 1
179 * struct trace_entry *entry;
be74b73a 180 * struct trace_seq *p;
f42c85e7
SR
181 * int ret;
182 *
183 * entry = iter->ent;
184 *
185 * if (entry->type != event_<call>.id) {
186 * WARN_ON_ONCE(1);
187 * return TRACE_TYPE_UNHANDLED;
188 * }
189 *
190 * field = (typeof(field))entry;
191 *
be74b73a 192 * p = get_cpu_var(ftrace_event_seq);
56d8bd3f 193 * trace_seq_init(p);
f42c85e7 194 * ret = trace_seq_printf(s, <TP_printk> "\n");
be74b73a 195 * put_cpu();
f42c85e7
SR
196 * if (!ret)
197 * return TRACE_TYPE_PARTIAL_LINE;
198 *
199 * return TRACE_TYPE_HANDLED;
200 * }
201 *
202 * This is the method used to print the raw event to the trace
203 * output format. Note, this is not needed if the data is read
204 * in binary.
205 */
206
207#undef __entry
208#define __entry field
209
210#undef TP_printk
211#define TP_printk(fmt, args...) fmt "\n", args
212
7fcb7c47
LZ
213#undef __get_dynamic_array
214#define __get_dynamic_array(field) \
7d536cb3 215 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
7fcb7c47 216
9cbf1176 217#undef __get_str
7fcb7c47 218#define __get_str(field) (char *)__get_dynamic_array(field)
9cbf1176 219
be74b73a
SR
220#undef __print_flags
221#define __print_flags(flag, delim, flag_array...) \
222 ({ \
223 static const struct trace_print_flags flags[] = \
224 { flag_array, { -1, NULL }}; \
225 ftrace_print_flags_seq(p, delim, flag, flags); \
226 })
227
0f4fc29d
SR
228#undef __print_symbolic
229#define __print_symbolic(value, symbol_array...) \
230 ({ \
231 static const struct trace_print_flags symbols[] = \
232 { symbol_array, { -1, NULL }}; \
233 ftrace_print_symbols_seq(p, value, symbols); \
234 })
235
f42c85e7
SR
236#undef TRACE_EVENT
237#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
238enum print_line_t \
239ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
240{ \
241 struct trace_seq *s = &iter->seq; \
242 struct ftrace_raw_##call *field; \
243 struct trace_entry *entry; \
be74b73a 244 struct trace_seq *p; \
f42c85e7
SR
245 int ret; \
246 \
247 entry = iter->ent; \
248 \
249 if (entry->type != event_##call.id) { \
250 WARN_ON_ONCE(1); \
251 return TRACE_TYPE_UNHANDLED; \
252 } \
253 \
254 field = (typeof(field))entry; \
255 \
be74b73a 256 p = &get_cpu_var(ftrace_event_seq); \
56d8bd3f 257 trace_seq_init(p); \
f42c85e7 258 ret = trace_seq_printf(s, #call ": " print); \
be74b73a 259 put_cpu(); \
f42c85e7
SR
260 if (!ret) \
261 return TRACE_TYPE_PARTIAL_LINE; \
262 \
263 return TRACE_TYPE_HANDLED; \
264}
265
266#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
267
f42c85e7
SR
268#undef __field
269#define __field(type, item) \
270 ret = trace_define_field(event_call, #type, #item, \
271 offsetof(typeof(field), item), \
a118e4d1 272 sizeof(field.item), is_signed_type(type)); \
f42c85e7
SR
273 if (ret) \
274 return ret;
275
276#undef __array
277#define __array(type, item, len) \
278 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
279 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
280 offsetof(typeof(field), item), \
a118e4d1 281 sizeof(field.item), 0); \
f42c85e7
SR
282 if (ret) \
283 return ret;
284
7fcb7c47
LZ
285#undef __dynamic_array
286#define __dynamic_array(type, item, len) \
68fd60a8 287 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
7fcb7c47
LZ
288 offsetof(typeof(field), __data_loc_##item), \
289 sizeof(field.__data_loc_##item), 0);
290
9cbf1176 291#undef __string
7fcb7c47 292#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 293
f42c85e7
SR
294#undef TRACE_EVENT
295#define TRACE_EVENT(call, proto, args, tstruct, func, print) \
296int \
14be96c9 297ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
f42c85e7
SR
298{ \
299 struct ftrace_raw_##call field; \
f42c85e7
SR
300 int ret; \
301 \
e647d6b3
LZ
302 ret = trace_define_common_fields(event_call); \
303 if (ret) \
304 return ret; \
f42c85e7
SR
305 \
306 tstruct; \
307 \
308 return ret; \
309}
310
311#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
312
7fcb7c47
LZ
313/*
314 * remember the offset of each array from the beginning of the event.
315 */
316
317#undef __entry
318#define __entry entry
319
320#undef __field
321#define __field(type, item)
322
323#undef __array
324#define __array(type, item, len)
325
326#undef __dynamic_array
327#define __dynamic_array(type, item, len) \
328 __data_offsets->item = __data_size + \
329 offsetof(typeof(*entry), __data); \
7d536cb3 330 __data_offsets->item |= (len * sizeof(type)) << 16; \
7fcb7c47
LZ
331 __data_size += (len) * sizeof(type);
332
333#undef __string
334#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \
335
336#undef TRACE_EVENT
337#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
338static inline int ftrace_get_offsets_##call( \
339 struct ftrace_data_offsets_##call *__data_offsets, proto) \
340{ \
341 int __data_size = 0; \
342 struct ftrace_raw_##call __maybe_unused *entry; \
343 \
344 tstruct; \
345 \
346 return __data_size; \
347}
348
349#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
350
3a659305
PZ
351#ifdef CONFIG_EVENT_PROFILE
352
353/*
354 * Generate the functions needed for tracepoint perf_counter support.
355 *
f413cdb8 356 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
3a659305
PZ
357 *
358 * static int ftrace_profile_enable_<call>(struct ftrace_event_call *event_call)
359 * {
360 * int ret = 0;
361 *
362 * if (!atomic_inc_return(&event_call->profile_count))
363 * ret = register_trace_<call>(ftrace_profile_<call>);
364 *
365 * return ret;
366 * }
367 *
368 * static void ftrace_profile_disable_<call>(struct ftrace_event_call *event_call)
369 * {
370 * if (atomic_add_negative(-1, &event->call->profile_count))
371 * unregister_trace_<call>(ftrace_profile_<call>);
372 * }
373 *
374 */
375
3a659305
PZ
376#undef TRACE_EVENT
377#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
378 \
f413cdb8 379static void ftrace_profile_##call(proto); \
3a659305
PZ
380 \
381static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
382{ \
383 int ret = 0; \
384 \
385 if (!atomic_inc_return(&event_call->profile_count)) \
386 ret = register_trace_##call(ftrace_profile_##call); \
387 \
388 return ret; \
389} \
390 \
391static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
392{ \
393 if (atomic_add_negative(-1, &event_call->profile_count)) \
394 unregister_trace_##call(ftrace_profile_##call); \
395}
396
397#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
398
3a659305
PZ
399#endif
400
c32e827b 401/*
9cbf1176 402 * Stage 4 of the trace events.
c32e827b 403 *
ea20d929 404 * Override the macros in <trace/trace_events.h> to include the following:
c32e827b
SR
405 *
406 * static void ftrace_event_<call>(proto)
407 * {
ef18012b 408 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
c32e827b
SR
409 * }
410 *
411 * static int ftrace_reg_event_<call>(void)
412 * {
ef18012b 413 * int ret;
c32e827b 414 *
ef18012b
SR
415 * ret = register_trace_<call>(ftrace_event_<call>);
416 * if (!ret)
417 * pr_info("event trace: Could not activate trace point "
418 * "probe to <call>");
419 * return ret;
c32e827b
SR
420 * }
421 *
422 * static void ftrace_unreg_event_<call>(void)
423 * {
ef18012b 424 * unregister_trace_<call>(ftrace_event_<call>);
c32e827b
SR
425 * }
426 *
c32e827b 427 *
157587d7 428 * For those macros defined with TRACE_EVENT:
c32e827b
SR
429 *
430 * static struct ftrace_event_call event_<call>;
431 *
432 * static void ftrace_raw_event_<call>(proto)
433 * {
ef18012b
SR
434 * struct ring_buffer_event *event;
435 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
436 * unsigned long irq_flags;
437 * int pc;
438 *
439 * local_save_flags(irq_flags);
440 * pc = preempt_count();
441 *
442 * event = trace_current_buffer_lock_reserve(event_<call>.id,
443 * sizeof(struct ftrace_raw_<call>),
444 * irq_flags, pc);
445 * if (!event)
446 * return;
447 * entry = ring_buffer_event_data(event);
448 *
449 * <assign>; <-- Here we assign the entries by the __field and
0e3d0f05 450 * __array macros.
c32e827b 451 *
ef18012b 452 * trace_current_buffer_unlock_commit(event, irq_flags, pc);
c32e827b
SR
453 * }
454 *
455 * static int ftrace_raw_reg_event_<call>(void)
456 * {
ef18012b 457 * int ret;
c32e827b 458 *
ef18012b
SR
459 * ret = register_trace_<call>(ftrace_raw_event_<call>);
460 * if (!ret)
461 * pr_info("event trace: Could not activate trace point "
462 * "probe to <call>");
463 * return ret;
c32e827b
SR
464 * }
465 *
466 * static void ftrace_unreg_event_<call>(void)
467 * {
ef18012b 468 * unregister_trace_<call>(ftrace_raw_event_<call>);
c32e827b
SR
469 * }
470 *
471 * static struct trace_event ftrace_event_type_<call> = {
ef18012b 472 * .trace = ftrace_raw_output_<call>, <-- stage 2
c32e827b
SR
473 * };
474 *
475 * static int ftrace_raw_init_event_<call>(void)
476 * {
ef18012b 477 * int id;
c32e827b 478 *
ef18012b
SR
479 * id = register_ftrace_event(&ftrace_event_type_<call>);
480 * if (!id)
481 * return -ENODEV;
482 * event_<call>.id = id;
483 * return 0;
c32e827b
SR
484 * }
485 *
486 * static struct ftrace_event_call __used
487 * __attribute__((__aligned__(4)))
488 * __attribute__((section("_ftrace_events"))) event_<call> = {
ef18012b 489 * .name = "<call>",
0e3d0f05 490 * .system = "<system>",
ef18012b
SR
491 * .raw_init = ftrace_raw_init_event_<call>,
492 * .regfunc = ftrace_reg_event_<call>,
493 * .unregfunc = ftrace_unreg_event_<call>,
981d081e 494 * .show_format = ftrace_format_<call>,
c32e827b
SR
495 * }
496 *
497 */
498
2939b046
SR
499#undef TP_FMT
500#define TP_FMT(fmt, args...) fmt "\n", ##args
c32e827b 501
ac199db0 502#ifdef CONFIG_EVENT_PROFILE
ac199db0
PZ
503
504#define _TRACE_PROFILE_INIT(call) \
505 .profile_count = ATOMIC_INIT(-1), \
506 .profile_enable = ftrace_profile_enable_##call, \
507 .profile_disable = ftrace_profile_disable_##call,
508
509#else
ac199db0
PZ
510#define _TRACE_PROFILE_INIT(call)
511#endif
512
da4d0302
SR
513#undef __entry
514#define __entry entry
d20e3b03 515
9cbf1176
FW
516#undef __field
517#define __field(type, item)
518
519#undef __array
520#define __array(type, item, len)
521
7fcb7c47
LZ
522#undef __dynamic_array
523#define __dynamic_array(type, item, len) \
524 __entry->__data_loc_##item = __data_offsets.item;
525
9cbf1176 526#undef __string
7fcb7c47 527#define __string(item, src) __dynamic_array(char, item, -1) \
9cbf1176
FW
528
529#undef __assign_str
530#define __assign_str(dst, src) \
9cbf1176
FW
531 strcpy(__get_str(dst), src);
532
da4d0302 533#undef TRACE_EVENT
30a8fecc 534#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
c32e827b
SR
535 \
536static struct ftrace_event_call event_##call; \
537 \
538static void ftrace_raw_event_##call(proto) \
539{ \
7fcb7c47 540 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
f2aebaee 541 struct ftrace_event_call *event_call = &event_##call; \
c32e827b
SR
542 struct ring_buffer_event *event; \
543 struct ftrace_raw_##call *entry; \
544 unsigned long irq_flags; \
7fcb7c47 545 int __data_size; \
c32e827b
SR
546 int pc; \
547 \
548 local_save_flags(irq_flags); \
549 pc = preempt_count(); \
550 \
7fcb7c47 551 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
9cbf1176 552 \
c32e827b 553 event = trace_current_buffer_lock_reserve(event_##call.id, \
7fcb7c47 554 sizeof(*entry) + __data_size, \
9cbf1176 555 irq_flags, pc); \
c32e827b
SR
556 if (!event) \
557 return; \
558 entry = ring_buffer_event_data(event); \
559 \
7fcb7c47
LZ
560 \
561 tstruct \
562 \
a9c1c3ab 563 { assign; } \
c32e827b 564 \
f2aebaee 565 if (!filter_current_check_discard(event_call, entry, event)) \
77d9f465 566 trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \
c32e827b
SR
567} \
568 \
69fd4f0e 569static int ftrace_raw_reg_event_##call(void *ptr) \
c32e827b
SR
570{ \
571 int ret; \
572 \
573 ret = register_trace_##call(ftrace_raw_event_##call); \
633ddaa7 574 if (ret) \
c32e827b 575 pr_info("event trace: Could not activate trace point " \
633ddaa7 576 "probe to " #call "\n"); \
c32e827b
SR
577 return ret; \
578} \
579 \
69fd4f0e 580static void ftrace_raw_unreg_event_##call(void *ptr) \
c32e827b
SR
581{ \
582 unregister_trace_##call(ftrace_raw_event_##call); \
583} \
584 \
585static struct trace_event ftrace_event_type_##call = { \
586 .trace = ftrace_raw_output_##call, \
587}; \
588 \
589static int ftrace_raw_init_event_##call(void) \
590{ \
591 int id; \
592 \
593 id = register_ftrace_event(&ftrace_event_type_##call); \
594 if (!id) \
595 return -ENODEV; \
596 event_##call.id = id; \
cf027f64 597 INIT_LIST_HEAD(&event_##call.fields); \
0a19e53c 598 init_preds(&event_##call); \
c32e827b
SR
599 return 0; \
600} \
601 \
602static struct ftrace_event_call __used \
603__attribute__((__aligned__(4))) \
604__attribute__((section("_ftrace_events"))) event_##call = { \
ef18012b 605 .name = #call, \
9cc26a26 606 .system = __stringify(TRACE_SYSTEM), \
6d723736 607 .event = &ftrace_event_type_##call, \
c32e827b 608 .raw_init = ftrace_raw_init_event_##call, \
da4d0302
SR
609 .regfunc = ftrace_raw_reg_event_##call, \
610 .unregfunc = ftrace_raw_unreg_event_##call, \
981d081e 611 .show_format = ftrace_format_##call, \
cf027f64 612 .define_fields = ftrace_define_fields_##call, \
ac199db0 613 _TRACE_PROFILE_INIT(call) \
c32e827b 614}
ac199db0 615
f42c85e7 616#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
ac199db0 617
f413cdb8
FW
618/*
619 * Define the insertion callback to profile events
620 *
621 * The job is very similar to ftrace_raw_event_<call> except that we don't
622 * insert in the ring buffer but in a perf counter.
623 *
624 * static void ftrace_profile_<call>(proto)
625 * {
626 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
627 * struct ftrace_event_call *event_call = &event_<call>;
628 * extern void perf_tpcounter_event(int, u64, u64, void *, int);
629 * struct ftrace_raw_##call *entry;
630 * u64 __addr = 0, __count = 1;
631 * unsigned long irq_flags;
632 * int __entry_size;
633 * int __data_size;
634 * int pc;
635 *
636 * local_save_flags(irq_flags);
637 * pc = preempt_count();
638 *
639 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
304703ab
FW
640 *
641 * // Below we want to get the aligned size by taking into account
642 * // the u32 field that will later store the buffer size
643 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
644 * sizeof(u64));
645 * __entry_size -= sizeof(u32);
f413cdb8
FW
646 *
647 * do {
648 * char raw_data[__entry_size]; <- allocate our sample in the stack
649 * struct trace_entry *ent;
650 *
1853db0e
FW
651 * zero dead bytes from alignment to avoid stack leak to userspace:
652 *
653 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
f413cdb8
FW
654 * entry = (struct ftrace_raw_<call> *)raw_data;
655 * ent = &entry->ent;
656 * tracing_generic_entry_update(ent, irq_flags, pc);
657 * ent->type = event_call->id;
658 *
659 * <tstruct> <- do some jobs with dynamic arrays
660 *
661 * <assign> <- affect our values
662 *
663 * perf_tpcounter_event(event_call->id, __addr, __count, entry,
664 * __entry_size); <- submit them to perf counter
665 * } while (0);
666 *
667 * }
668 */
669
670#ifdef CONFIG_EVENT_PROFILE
671
672#undef __perf_addr
673#define __perf_addr(a) __addr = (a)
674
675#undef __perf_count
676#define __perf_count(c) __count = (c)
677
678#undef TRACE_EVENT
679#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
680static void ftrace_profile_##call(proto) \
681{ \
682 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
683 struct ftrace_event_call *event_call = &event_##call; \
684 extern void perf_tpcounter_event(int, u64, u64, void *, int); \
685 struct ftrace_raw_##call *entry; \
686 u64 __addr = 0, __count = 1; \
687 unsigned long irq_flags; \
688 int __entry_size; \
689 int __data_size; \
690 int pc; \
691 \
692 local_save_flags(irq_flags); \
693 pc = preempt_count(); \
694 \
695 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
a044560c
PZ
696 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
697 sizeof(u64)); \
304703ab 698 __entry_size -= sizeof(u32); \
f413cdb8
FW
699 \
700 do { \
701 char raw_data[__entry_size]; \
702 struct trace_entry *ent; \
703 \
1853db0e 704 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
f413cdb8
FW
705 entry = (struct ftrace_raw_##call *)raw_data; \
706 ent = &entry->ent; \
707 tracing_generic_entry_update(ent, irq_flags, pc); \
708 ent->type = event_call->id; \
709 \
710 tstruct \
711 \
712 { assign; } \
713 \
714 perf_tpcounter_event(event_call->id, __addr, __count, entry,\
715 __entry_size); \
716 } while (0); \
717 \
718}
719
720#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
721#endif /* CONFIG_EVENT_PROFILE */
722
ac199db0
PZ
723#undef _TRACE_PROFILE_INIT
724