asm-generic: remove ARCH_HAS_SG_CHAIN in scatterlist.h
[linux-2.6.git] / include / trace / ftrace.h
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
21 /*
22  * DECLARE_EVENT_CLASS can be used to add a generic function
23  * 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
26  * will map the DECLARE_EVENT_CLASS to the tracepoint.
27  *
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) \
32         DECLARE_EVENT_CLASS(name,                              \
33                              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
41 #undef __field
42 #define __field(type, item)             type    item;
43
44 #undef __field_ext
45 #define __field_ext(type, item, filter_type)    type    item;
46
47 #undef __array
48 #define __array(type, item, len)        type    item[len];
49
50 #undef __dynamic_array
51 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
52
53 #undef __string
54 #define __string(item, src) __dynamic_array(char, item, -1)
55
56 #undef TP_STRUCT__entry
57 #define TP_STRUCT__entry(args...) args
58
59 #undef DECLARE_EVENT_CLASS
60 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)  \
61         struct ftrace_raw_##name {                                      \
62                 struct trace_entry      ent;                            \
63                 tstruct                                                 \
64                 char                    __data[0];                      \
65         };
66 #undef DEFINE_EVENT
67 #define DEFINE_EVENT(template, name, proto, args)       \
68         static struct ftrace_event_call                 \
69         __attribute__((__aligned__(4))) event_##name
70
71 #undef DEFINE_EVENT_PRINT
72 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
73         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
74
75 #undef __cpparg
76 #define __cpparg(arg...) arg
77
78 /* Callbacks are meaningless to ftrace. */
79 #undef TRACE_EVENT_FN
80 #define TRACE_EVENT_FN(name, proto, args, tstruct,                      \
81                 assign, print, reg, unreg)                              \
82         TRACE_EVENT(name, __cpparg(proto), __cpparg(args),              \
83                 __cpparg(tstruct), __cpparg(assign), __cpparg(print))   \
84
85 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
86
87
88 /*
89  * Stage 2 of the trace events.
90  *
91  * Include the following:
92  *
93  * struct ftrace_data_offsets_<call> {
94  *      u32                             <item1>;
95  *      u32                             <item2>;
96  *      [...]
97  * };
98  *
99  * The __dynamic_array() macro will create each u32 <item>, this is
100  * to keep the offset of each array from the beginning of the event.
101  * The size of an array is also encoded, in the higher 16 bits of <item>.
102  */
103
104 #undef __field
105 #define __field(type, item)
106
107 #undef __field_ext
108 #define __field_ext(type, item, filter_type)
109
110 #undef __array
111 #define __array(type, item, len)
112
113 #undef __dynamic_array
114 #define __dynamic_array(type, item, len)        u32 item;
115
116 #undef __string
117 #define __string(item, src) __dynamic_array(char, item, -1)
118
119 #undef DECLARE_EVENT_CLASS
120 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
121         struct ftrace_data_offsets_##call {                             \
122                 tstruct;                                                \
123         };
124
125 #undef DEFINE_EVENT
126 #define DEFINE_EVENT(template, name, proto, args)
127
128 #undef DEFINE_EVENT_PRINT
129 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
130         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
131
132 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
133
134 /*
135  * Stage 3 of the trace events.
136  *
137  * Override the macros in <trace/trace_events.h> to include the following:
138  *
139  * enum print_line_t
140  * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
141  * {
142  *      struct trace_seq *s = &iter->seq;
143  *      struct ftrace_raw_<call> *field; <-- defined in stage 1
144  *      struct trace_entry *entry;
145  *      struct trace_seq *p;
146  *      int ret;
147  *
148  *      entry = iter->ent;
149  *
150  *      if (entry->type != event_<call>.id) {
151  *              WARN_ON_ONCE(1);
152  *              return TRACE_TYPE_UNHANDLED;
153  *      }
154  *
155  *      field = (typeof(field))entry;
156  *
157  *      p = &get_cpu_var(ftrace_event_seq);
158  *      trace_seq_init(p);
159  *      ret = trace_seq_printf(s, "%s: ", <call>);
160  *      if (ret)
161  *              ret = trace_seq_printf(s, <TP_printk> "\n");
162  *      put_cpu();
163  *      if (!ret)
164  *              return TRACE_TYPE_PARTIAL_LINE;
165  *
166  *      return TRACE_TYPE_HANDLED;
167  * }
168  *
169  * This is the method used to print the raw event to the trace
170  * output format. Note, this is not needed if the data is read
171  * in binary.
172  */
173
174 #undef __entry
175 #define __entry field
176
177 #undef TP_printk
178 #define TP_printk(fmt, args...) fmt "\n", args
179
180 #undef __get_dynamic_array
181 #define __get_dynamic_array(field)      \
182                 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
183
184 #undef __get_str
185 #define __get_str(field) (char *)__get_dynamic_array(field)
186
187 #undef __print_flags
188 #define __print_flags(flag, delim, flag_array...)                       \
189         ({                                                              \
190                 static const struct trace_print_flags __flags[] =       \
191                         { flag_array, { -1, NULL }};                    \
192                 ftrace_print_flags_seq(p, delim, flag, __flags);        \
193         })
194
195 #undef __print_symbolic
196 #define __print_symbolic(value, symbol_array...)                        \
197         ({                                                              \
198                 static const struct trace_print_flags symbols[] =       \
199                         { symbol_array, { -1, NULL }};                  \
200                 ftrace_print_symbols_seq(p, value, symbols);            \
201         })
202
203 #undef __print_hex
204 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
205
206 #undef DECLARE_EVENT_CLASS
207 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
208 static notrace enum print_line_t                                        \
209 ftrace_raw_output_id_##call(int event_id, const char *name,             \
210                             struct trace_iterator *iter, int flags)     \
211 {                                                                       \
212         struct trace_seq *s = &iter->seq;                               \
213         struct ftrace_raw_##call *field;                                \
214         struct trace_entry *entry;                                      \
215         struct trace_seq *p;                                            \
216         int ret;                                                        \
217                                                                         \
218         entry = iter->ent;                                              \
219                                                                         \
220         if (entry->type != event_id) {                                  \
221                 WARN_ON_ONCE(1);                                        \
222                 return TRACE_TYPE_UNHANDLED;                            \
223         }                                                               \
224                                                                         \
225         field = (typeof(field))entry;                                   \
226                                                                         \
227         p = &get_cpu_var(ftrace_event_seq);                             \
228         trace_seq_init(p);                                              \
229         ret = trace_seq_printf(s, "%s: ", name);                        \
230         if (ret)                                                        \
231                 ret = trace_seq_printf(s, print);                       \
232         put_cpu();                                                      \
233         if (!ret)                                                       \
234                 return TRACE_TYPE_PARTIAL_LINE;                         \
235                                                                         \
236         return TRACE_TYPE_HANDLED;                                      \
237 }
238
239 #undef DEFINE_EVENT
240 #define DEFINE_EVENT(template, name, proto, args)                       \
241 static notrace enum print_line_t                                        \
242 ftrace_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
248 #undef DEFINE_EVENT_PRINT
249 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)          \
250 static notrace enum print_line_t                                        \
251 ftrace_raw_output_##call(struct trace_iterator *iter, int flags)        \
252 {                                                                       \
253         struct trace_seq *s = &iter->seq;                               \
254         struct ftrace_raw_##template *field;                            \
255         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);                                              \
270         ret = trace_seq_printf(s, "%s: ", #call);                       \
271         if (ret)                                                        \
272                 ret = trace_seq_printf(s, print);                       \
273         put_cpu();                                                      \
274         if (!ret)                                                       \
275                 return TRACE_TYPE_PARTIAL_LINE;                         \
276                                                                         \
277         return TRACE_TYPE_HANDLED;                                      \
278 }
279
280 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
281
282 #undef __field_ext
283 #define __field_ext(type, item, filter_type)                            \
284         ret = trace_define_field(event_call, #type, #item,              \
285                                  offsetof(typeof(field), item),         \
286                                  sizeof(field.item),                    \
287                                  is_signed_type(type), filter_type);    \
288         if (ret)                                                        \
289                 return ret;
290
291 #undef __field
292 #define __field(type, item)     __field_ext(type, item, FILTER_OTHER)
293
294 #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),         \
299                                  sizeof(field.item),                    \
300                                  is_signed_type(type), FILTER_OTHER);   \
301         if (ret)                                                        \
302                 return ret;
303
304 #undef __dynamic_array
305 #define __dynamic_array(type, item, len)                                       \
306         ret = trace_define_field(event_call, "__data_loc " #type "[]", #item,  \
307                                  offsetof(typeof(field), __data_loc_##item),   \
308                                  sizeof(field.__data_loc_##item),              \
309                                  is_signed_type(type), FILTER_OTHER);
310
311 #undef __string
312 #define __string(item, src) __dynamic_array(char, item, -1)
313
314 #undef DECLARE_EVENT_CLASS
315 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print)    \
316 static int notrace                                                      \
317 ftrace_define_fields_##call(struct ftrace_event_call *event_call)       \
318 {                                                                       \
319         struct ftrace_raw_##call field;                                 \
320         int ret;                                                        \
321                                                                         \
322         tstruct;                                                        \
323                                                                         \
324         return ret;                                                     \
325 }
326
327 #undef DEFINE_EVENT
328 #define DEFINE_EVENT(template, name, proto, args)
329
330 #undef DEFINE_EVENT_PRINT
331 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
332         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
333
334 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
335
336 /*
337  * 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
346 #undef __field_ext
347 #define __field_ext(type, item, filter_type)
348
349 #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);        \
356         __data_offsets->item |= (len * sizeof(type)) << 16;             \
357         __data_size += (len) * sizeof(type);
358
359 #undef __string
360 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
361
362 #undef DECLARE_EVENT_CLASS
363 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
364 static inline notrace int ftrace_get_offsets_##call(                    \
365         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
375 #undef DEFINE_EVENT
376 #define DEFINE_EVENT(template, name, proto, args)
377
378 #undef DEFINE_EVENT_PRINT
379 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
380         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
381
382 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
383
384 #ifdef CONFIG_PERF_EVENTS
385
386 /*
387  * Generate the functions needed for tracepoint perf_event support.
388  *
389  * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
390  *
391  * static int ftrace_profile_enable_<call>(void)
392  * {
393  *      return register_trace_<call>(ftrace_profile_<call>);
394  * }
395  *
396  * static void ftrace_profile_disable_<call>(void)
397  * {
398  *      unregister_trace_<call>(ftrace_profile_<call>);
399  * }
400  *
401  */
402
403 #undef DECLARE_EVENT_CLASS
404 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
405
406 #undef DEFINE_EVENT
407 #define DEFINE_EVENT(template, name, proto, args)                       \
408                                                                         \
409 static void perf_trace_##name(proto);                                   \
410                                                                         \
411 static notrace int                                                      \
412 perf_trace_enable_##name(struct ftrace_event_call *unused)              \
413 {                                                                       \
414         return register_trace_##name(perf_trace_##name);                \
415 }                                                                       \
416                                                                         \
417 static notrace void                                                     \
418 perf_trace_disable_##name(struct ftrace_event_call *unused)             \
419 {                                                                       \
420         unregister_trace_##name(perf_trace_##name);                     \
421 }
422
423 #undef DEFINE_EVENT_PRINT
424 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
425         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
426
427 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
428
429 #endif /* CONFIG_PERF_EVENTS */
430
431 /*
432  * Stage 4 of the trace events.
433  *
434  * Override the macros in <trace/trace_events.h> to include the following:
435  *
436  * static void ftrace_event_<call>(proto)
437  * {
438  *      event_trace_printk(_RET_IP_, "<call>: " <fmt>);
439  * }
440  *
441  * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused)
442  * {
443  *      return register_trace_<call>(ftrace_event_<call>);
444  * }
445  *
446  * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
447  * {
448  *      unregister_trace_<call>(ftrace_event_<call>);
449  * }
450  *
451  *
452  * For those macros defined with TRACE_EVENT:
453  *
454  * static struct ftrace_event_call event_<call>;
455  *
456  * static void ftrace_raw_event_<call>(proto)
457  * {
458  *      struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
459  *      struct ring_buffer_event *event;
460  *      struct ftrace_raw_<call> *entry; <-- defined in stage 1
461  *      struct ring_buffer *buffer;
462  *      unsigned long irq_flags;
463  *      int __data_size;
464  *      int pc;
465  *
466  *      local_save_flags(irq_flags);
467  *      pc = preempt_count();
468  *
469  *      __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
470  *
471  *      event = trace_current_buffer_lock_reserve(&buffer,
472  *                                event_<call>.id,
473  *                                sizeof(*entry) + __data_size,
474  *                                irq_flags, pc);
475  *      if (!event)
476  *              return;
477  *      entry   = ring_buffer_event_data(event);
478  *
479  *      { <assign>; }  <-- Here we assign the entries by the __field and
480  *                         __array macros.
481  *
482  *      if (!filter_current_check_discard(buffer, event_call, entry, event))
483  *              trace_current_buffer_unlock_commit(buffer,
484  *                                                 event, irq_flags, pc);
485  * }
486  *
487  * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
488  * {
489  *      return register_trace_<call>(ftrace_raw_event_<call>);
490  * }
491  *
492  * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
493  * {
494  *      unregister_trace_<call>(ftrace_raw_event_<call>);
495  * }
496  *
497  * static struct trace_event ftrace_event_type_<call> = {
498  *      .trace                  = ftrace_raw_output_<call>, <-- stage 2
499  * };
500  *
501  * static const char print_fmt_<call>[] = <TP_printk>;
502  *
503  * static struct ftrace_event_call __used
504  * __attribute__((__aligned__(4)))
505  * __attribute__((section("_ftrace_events"))) event_<call> = {
506  *      .name                   = "<call>",
507  *      .system                 = "<system>",
508  *      .raw_init               = trace_event_raw_init,
509  *      .regfunc                = ftrace_reg_event_<call>,
510  *      .unregfunc              = ftrace_unreg_event_<call>,
511  *      .print_fmt              = print_fmt_<call>,
512  *      .define_fields          = ftrace_define_fields_<call>,
513  * }
514  *
515  */
516
517 #ifdef CONFIG_PERF_EVENTS
518
519 #define _TRACE_PERF_INIT(call)                                          \
520         .perf_event_enable = perf_trace_enable_##call,                  \
521         .perf_event_disable = perf_trace_disable_##call,
522
523 #else
524 #define _TRACE_PERF_INIT(call)
525 #endif /* CONFIG_PERF_EVENTS */
526
527 #undef __entry
528 #define __entry entry
529
530 #undef __field
531 #define __field(type, item)
532
533 #undef __array
534 #define __array(type, item, len)
535
536 #undef __dynamic_array
537 #define __dynamic_array(type, item, len)                                \
538         __entry->__data_loc_##item = __data_offsets.item;
539
540 #undef __string
541 #define __string(item, src) __dynamic_array(char, item, -1)             \
542
543 #undef __assign_str
544 #define __assign_str(dst, src)                                          \
545         strcpy(__get_str(dst), src);
546
547 #undef TP_fast_assign
548 #define TP_fast_assign(args...) args
549
550 #undef TP_perf_assign
551 #define TP_perf_assign(args...)
552
553 #undef DECLARE_EVENT_CLASS
554 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
555                                                                         \
556 static notrace void                                                     \
557 ftrace_raw_event_id_##call(struct ftrace_event_call *event_call,        \
558                                        proto)                           \
559 {                                                                       \
560         struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
561         struct ring_buffer_event *event;                                \
562         struct ftrace_raw_##call *entry;                                \
563         struct ring_buffer *buffer;                                     \
564         unsigned long irq_flags;                                        \
565         int __data_size;                                                \
566         int pc;                                                         \
567                                                                         \
568         local_save_flags(irq_flags);                                    \
569         pc = preempt_count();                                           \
570                                                                         \
571         __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
572                                                                         \
573         event = trace_current_buffer_lock_reserve(&buffer,              \
574                                  event_call->id,                        \
575                                  sizeof(*entry) + __data_size,          \
576                                  irq_flags, pc);                        \
577         if (!event)                                                     \
578                 return;                                                 \
579         entry   = ring_buffer_event_data(event);                        \
580                                                                         \
581         tstruct                                                         \
582                                                                         \
583         { assign; }                                                     \
584                                                                         \
585         if (!filter_current_check_discard(buffer, event_call, entry, event)) \
586                 trace_nowake_buffer_unlock_commit(buffer,               \
587                                                   event, irq_flags, pc); \
588 }
589
590 #undef DEFINE_EVENT
591 #define DEFINE_EVENT(template, call, proto, args)                       \
592                                                                         \
593 static notrace void ftrace_raw_event_##call(proto)                      \
594 {                                                                       \
595         ftrace_raw_event_id_##template(&event_##call, args);            \
596 }                                                                       \
597                                                                         \
598 static notrace int                                                      \
599 ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)           \
600 {                                                                       \
601         return register_trace_##call(ftrace_raw_event_##call);          \
602 }                                                                       \
603                                                                         \
604 static notrace void                                                     \
605 ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused)         \
606 {                                                                       \
607         unregister_trace_##call(ftrace_raw_event_##call);               \
608 }                                                                       \
609                                                                         \
610 static struct trace_event ftrace_event_type_##call = {                  \
611         .trace                  = ftrace_raw_output_##call,             \
612 };
613
614 #undef DEFINE_EVENT_PRINT
615 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
616         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
617
618 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
619
620 #undef __entry
621 #define __entry REC
622
623 #undef __print_flags
624 #undef __print_symbolic
625 #undef __get_dynamic_array
626 #undef __get_str
627
628 #undef TP_printk
629 #define TP_printk(fmt, args...) "\"" fmt "\", "  __stringify(args)
630
631 #undef DECLARE_EVENT_CLASS
632 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
633 static const char print_fmt_##call[] = print;
634
635 #undef DEFINE_EVENT
636 #define DEFINE_EVENT(template, call, proto, args)                       \
637                                                                         \
638 static struct ftrace_event_call __used                                  \
639 __attribute__((__aligned__(4)))                                         \
640 __attribute__((section("_ftrace_events"))) event_##call = {             \
641         .name                   = #call,                                \
642         .system                 = __stringify(TRACE_SYSTEM),            \
643         .event                  = &ftrace_event_type_##call,            \
644         .raw_init               = trace_event_raw_init,                 \
645         .regfunc                = ftrace_raw_reg_event_##call,          \
646         .unregfunc              = ftrace_raw_unreg_event_##call,        \
647         .print_fmt              = print_fmt_##template,                 \
648         .define_fields          = ftrace_define_fields_##template,      \
649         _TRACE_PERF_INIT(call)                                  \
650 }
651
652 #undef DEFINE_EVENT_PRINT
653 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)          \
654                                                                         \
655 static const char print_fmt_##call[] = print;                           \
656                                                                         \
657 static struct ftrace_event_call __used                                  \
658 __attribute__((__aligned__(4)))                                         \
659 __attribute__((section("_ftrace_events"))) event_##call = {             \
660         .name                   = #call,                                \
661         .system                 = __stringify(TRACE_SYSTEM),            \
662         .event                  = &ftrace_event_type_##call,            \
663         .raw_init               = trace_event_raw_init,                 \
664         .regfunc                = ftrace_raw_reg_event_##call,          \
665         .unregfunc              = ftrace_raw_unreg_event_##call,        \
666         .print_fmt              = print_fmt_##call,                     \
667         .define_fields          = ftrace_define_fields_##template,      \
668         _TRACE_PERF_INIT(call)                                  \
669 }
670
671 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
672
673 /*
674  * Define the insertion callback to perf events
675  *
676  * The job is very similar to ftrace_raw_event_<call> except that we don't
677  * insert in the ring buffer but in a perf counter.
678  *
679  * static void ftrace_perf_<call>(proto)
680  * {
681  *      struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
682  *      struct ftrace_event_call *event_call = &event_<call>;
683  *      extern void perf_tp_event(int, u64, u64, void *, int);
684  *      struct ftrace_raw_##call *entry;
685  *      struct perf_trace_buf *trace_buf;
686  *      u64 __addr = 0, __count = 1;
687  *      unsigned long irq_flags;
688  *      struct trace_entry *ent;
689  *      int __entry_size;
690  *      int __data_size;
691  *      int __cpu
692  *      int pc;
693  *
694  *      pc = preempt_count();
695  *
696  *      __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
697  *
698  *      // Below we want to get the aligned size by taking into account
699  *      // the u32 field that will later store the buffer size
700  *      __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
701  *                           sizeof(u64));
702  *      __entry_size -= sizeof(u32);
703  *
704  *      // Protect the non nmi buffer
705  *      // This also protects the rcu read side
706  *      local_irq_save(irq_flags);
707  *      __cpu = smp_processor_id();
708  *
709  *      if (in_nmi())
710  *              trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
711  *      else
712  *              trace_buf = rcu_dereference_sched(perf_trace_buf);
713  *
714  *      if (!trace_buf)
715  *              goto end;
716  *
717  *      trace_buf = per_cpu_ptr(trace_buf, __cpu);
718  *
719  *      // Avoid recursion from perf that could mess up the buffer
720  *      if (trace_buf->recursion++)
721  *              goto end_recursion;
722  *
723  *      raw_data = trace_buf->buf;
724  *
725  *      // Make recursion update visible before entering perf_tp_event
726  *      // so that we protect from perf recursions.
727  *
728  *      barrier();
729  *
730  *      //zero dead bytes from alignment to avoid stack leak to userspace:
731  *      *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
732  *      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> <- do some jobs with dynamic arrays
738  *
739  *      <assign>  <- affect our values
740  *
741  *      perf_tp_event(event_call->id, __addr, __count, entry,
742  *                   __entry_size);  <- submit them to perf counter
743  *
744  * }
745  */
746
747 #ifdef CONFIG_PERF_EVENTS
748
749 #undef __entry
750 #define __entry entry
751
752 #undef __get_dynamic_array
753 #define __get_dynamic_array(field)      \
754                 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
755
756 #undef __get_str
757 #define __get_str(field) (char *)__get_dynamic_array(field)
758
759 #undef __perf_addr
760 #define __perf_addr(a) __addr = (a)
761
762 #undef __perf_count
763 #define __perf_count(c) __count = (c)
764
765 #undef DECLARE_EVENT_CLASS
766 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
767 static notrace void                                                     \
768 perf_trace_templ_##call(struct ftrace_event_call *event_call,           \
769                         struct pt_regs *__regs, proto)                  \
770 {                                                                       \
771         struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
772         struct ftrace_raw_##call *entry;                                \
773         u64 __addr = 0, __count = 1;                                    \
774         unsigned long irq_flags;                                        \
775         int __entry_size;                                               \
776         int __data_size;                                                \
777         int rctx;                                                       \
778                                                                         \
779         __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
780         __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
781                              sizeof(u64));                              \
782         __entry_size -= sizeof(u32);                                    \
783                                                                         \
784         if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE,               \
785                       "profile buffer not large enough"))               \
786                 return;                                                 \
787         entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare(     \
788                 __entry_size, event_call->id, &rctx, &irq_flags);       \
789         if (!entry)                                                     \
790                 return;                                                 \
791         tstruct                                                         \
792                                                                         \
793         { assign; }                                                     \
794                                                                         \
795         perf_trace_buf_submit(entry, __entry_size, rctx, __addr,        \
796                                __count, irq_flags, __regs);             \
797 }
798
799 #undef DEFINE_EVENT
800 #define DEFINE_EVENT(template, call, proto, args)                       \
801 static notrace void perf_trace_##call(proto)                            \
802 {                                                                       \
803         struct ftrace_event_call *event_call = &event_##call;           \
804         struct pt_regs *__regs = &get_cpu_var(perf_trace_regs);         \
805                                                                         \
806         perf_fetch_caller_regs(__regs, 1);                              \
807                                                                         \
808         perf_trace_templ_##template(event_call, __regs, args);          \
809                                                                         \
810         put_cpu_var(perf_trace_regs);                                   \
811 }
812
813 #undef DEFINE_EVENT_PRINT
814 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
815         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
816
817 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
818 #endif /* CONFIG_PERF_EVENTS */
819
820 #undef _TRACE_PROFILE_INIT
821