]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/trace/ftrace.h
tracing: Reduce latency and remove percpu trace_seq
[karo-tx-linux.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                                                                         \
67         static struct ftrace_event_class event_class_##name;
68
69 #undef DEFINE_EVENT
70 #define DEFINE_EVENT(template, name, proto, args)       \
71         static struct ftrace_event_call __used          \
72         __attribute__((__aligned__(4))) event_##name
73
74 #undef DEFINE_EVENT_PRINT
75 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
76         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
77
78 #undef __cpparg
79 #define __cpparg(arg...) arg
80
81 /* Callbacks are meaningless to ftrace. */
82 #undef TRACE_EVENT_FN
83 #define TRACE_EVENT_FN(name, proto, args, tstruct,                      \
84                 assign, print, reg, unreg)                              \
85         TRACE_EVENT(name, __cpparg(proto), __cpparg(args),              \
86                 __cpparg(tstruct), __cpparg(assign), __cpparg(print))   \
87
88 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
89
90
91 /*
92  * Stage 2 of the trace events.
93  *
94  * Include the following:
95  *
96  * struct ftrace_data_offsets_<call> {
97  *      u32                             <item1>;
98  *      u32                             <item2>;
99  *      [...]
100  * };
101  *
102  * The __dynamic_array() macro will create each u32 <item>, this is
103  * to keep the offset of each array from the beginning of the event.
104  * The size of an array is also encoded, in the higher 16 bits of <item>.
105  */
106
107 #undef __field
108 #define __field(type, item)
109
110 #undef __field_ext
111 #define __field_ext(type, item, filter_type)
112
113 #undef __array
114 #define __array(type, item, len)
115
116 #undef __dynamic_array
117 #define __dynamic_array(type, item, len)        u32 item;
118
119 #undef __string
120 #define __string(item, src) __dynamic_array(char, item, -1)
121
122 #undef DECLARE_EVENT_CLASS
123 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
124         struct ftrace_data_offsets_##call {                             \
125                 tstruct;                                                \
126         };
127
128 #undef DEFINE_EVENT
129 #define DEFINE_EVENT(template, name, proto, args)
130
131 #undef DEFINE_EVENT_PRINT
132 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
133         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
134
135 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
136
137 /*
138  * Stage 3 of the trace events.
139  *
140  * Override the macros in <trace/trace_events.h> to include the following:
141  *
142  * enum print_line_t
143  * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
144  * {
145  *      struct trace_seq *s = &iter->seq;
146  *      struct ftrace_raw_<call> *field; <-- defined in stage 1
147  *      struct trace_entry *entry;
148  *      struct trace_seq *p = &iter->tmp_seq;
149  *      int ret;
150  *
151  *      entry = iter->ent;
152  *
153  *      if (entry->type != event_<call>->event.type) {
154  *              WARN_ON_ONCE(1);
155  *              return TRACE_TYPE_UNHANDLED;
156  *      }
157  *
158  *      field = (typeof(field))entry;
159  *
160  *      trace_seq_init(p);
161  *      ret = trace_seq_printf(s, "%s: ", <call>);
162  *      if (ret)
163  *              ret = trace_seq_printf(s, <TP_printk> "\n");
164  *      if (!ret)
165  *              return TRACE_TYPE_PARTIAL_LINE;
166  *
167  *      return TRACE_TYPE_HANDLED;
168  * }
169  *
170  * This is the method used to print the raw event to the trace
171  * output format. Note, this is not needed if the data is read
172  * in binary.
173  */
174
175 #undef __entry
176 #define __entry field
177
178 #undef TP_printk
179 #define TP_printk(fmt, args...) fmt "\n", args
180
181 #undef __get_dynamic_array
182 #define __get_dynamic_array(field)      \
183                 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
184
185 #undef __get_str
186 #define __get_str(field) (char *)__get_dynamic_array(field)
187
188 #undef __print_flags
189 #define __print_flags(flag, delim, flag_array...)                       \
190         ({                                                              \
191                 static const struct trace_print_flags __flags[] =       \
192                         { flag_array, { -1, NULL }};                    \
193                 ftrace_print_flags_seq(p, delim, flag, __flags);        \
194         })
195
196 #undef __print_symbolic
197 #define __print_symbolic(value, symbol_array...)                        \
198         ({                                                              \
199                 static const struct trace_print_flags symbols[] =       \
200                         { symbol_array, { -1, NULL }};                  \
201                 ftrace_print_symbols_seq(p, value, symbols);            \
202         })
203
204 #undef __print_hex
205 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
206
207 #undef DECLARE_EVENT_CLASS
208 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
209 static notrace enum print_line_t                                        \
210 ftrace_raw_output_##call(struct trace_iterator *iter, int flags,        \
211                          struct trace_event *trace_event)               \
212 {                                                                       \
213         struct ftrace_event_call *event;                                \
214         struct trace_seq *s = &iter->seq;                               \
215         struct ftrace_raw_##call *field;                                \
216         struct trace_entry *entry;                                      \
217         struct trace_seq *p = &iter->tmp_seq;                           \
218         int ret;                                                        \
219                                                                         \
220         event = container_of(trace_event, struct ftrace_event_call,     \
221                              event);                                    \
222                                                                         \
223         entry = iter->ent;                                              \
224                                                                         \
225         if (entry->type != event->event.type) {                         \
226                 WARN_ON_ONCE(1);                                        \
227                 return TRACE_TYPE_UNHANDLED;                            \
228         }                                                               \
229                                                                         \
230         field = (typeof(field))entry;                                   \
231                                                                         \
232         trace_seq_init(p);                                              \
233         ret = trace_seq_printf(s, "%s: ", event->name);                 \
234         if (ret)                                                        \
235                 ret = trace_seq_printf(s, print);                       \
236         if (!ret)                                                       \
237                 return TRACE_TYPE_PARTIAL_LINE;                         \
238                                                                         \
239         return TRACE_TYPE_HANDLED;                                      \
240 }                                                                       \
241 static struct trace_event_functions ftrace_event_type_funcs_##call = {  \
242         .trace                  = ftrace_raw_output_##call,             \
243 };
244
245 #undef DEFINE_EVENT_PRINT
246 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)          \
247 static notrace enum print_line_t                                        \
248 ftrace_raw_output_##call(struct trace_iterator *iter, int flags,        \
249                          struct trace_event *event)                     \
250 {                                                                       \
251         struct trace_seq *s = &iter->seq;                               \
252         struct ftrace_raw_##template *field;                            \
253         struct trace_entry *entry;                                      \
254         struct trace_seq *p = &iter->tmp_seq;                           \
255         int ret;                                                        \
256                                                                         \
257         entry = iter->ent;                                              \
258                                                                         \
259         if (entry->type != event_##call.event.type) {                   \
260                 WARN_ON_ONCE(1);                                        \
261                 return TRACE_TYPE_UNHANDLED;                            \
262         }                                                               \
263                                                                         \
264         field = (typeof(field))entry;                                   \
265                                                                         \
266         trace_seq_init(p);                                              \
267         ret = trace_seq_printf(s, "%s: ", #call);                       \
268         if (ret)                                                        \
269                 ret = trace_seq_printf(s, print);                       \
270         if (!ret)                                                       \
271                 return TRACE_TYPE_PARTIAL_LINE;                         \
272                                                                         \
273         return TRACE_TYPE_HANDLED;                                      \
274 }                                                                       \
275 static struct trace_event_functions ftrace_event_type_funcs_##call = {  \
276         .trace                  = ftrace_raw_output_##call,             \
277 };
278
279 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
280
281 #undef __field_ext
282 #define __field_ext(type, item, filter_type)                            \
283         ret = trace_define_field(event_call, #type, #item,              \
284                                  offsetof(typeof(field), item),         \
285                                  sizeof(field.item),                    \
286                                  is_signed_type(type), filter_type);    \
287         if (ret)                                                        \
288                 return ret;
289
290 #undef __field
291 #define __field(type, item)     __field_ext(type, item, FILTER_OTHER)
292
293 #undef __array
294 #define __array(type, item, len)                                        \
295         BUILD_BUG_ON(len > MAX_FILTER_STR_VAL);                         \
296         ret = trace_define_field(event_call, #type "[" #len "]", #item, \
297                                  offsetof(typeof(field), item),         \
298                                  sizeof(field.item),                    \
299                                  is_signed_type(type), FILTER_OTHER);   \
300         if (ret)                                                        \
301                 return ret;
302
303 #undef __dynamic_array
304 #define __dynamic_array(type, item, len)                                       \
305         ret = trace_define_field(event_call, "__data_loc " #type "[]", #item,  \
306                                  offsetof(typeof(field), __data_loc_##item),   \
307                                  sizeof(field.__data_loc_##item),              \
308                                  is_signed_type(type), FILTER_OTHER);
309
310 #undef __string
311 #define __string(item, src) __dynamic_array(char, item, -1)
312
313 #undef DECLARE_EVENT_CLASS
314 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print)    \
315 static int notrace                                                      \
316 ftrace_define_fields_##call(struct ftrace_event_call *event_call)       \
317 {                                                                       \
318         struct ftrace_raw_##call field;                                 \
319         int ret;                                                        \
320                                                                         \
321         tstruct;                                                        \
322                                                                         \
323         return ret;                                                     \
324 }
325
326 #undef DEFINE_EVENT
327 #define DEFINE_EVENT(template, name, proto, args)
328
329 #undef DEFINE_EVENT_PRINT
330 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
331         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
332
333 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
334
335 /*
336  * remember the offset of each array from the beginning of the event.
337  */
338
339 #undef __entry
340 #define __entry entry
341
342 #undef __field
343 #define __field(type, item)
344
345 #undef __field_ext
346 #define __field_ext(type, item, filter_type)
347
348 #undef __array
349 #define __array(type, item, len)
350
351 #undef __dynamic_array
352 #define __dynamic_array(type, item, len)                                \
353         __data_offsets->item = __data_size +                            \
354                                offsetof(typeof(*entry), __data);        \
355         __data_offsets->item |= (len * sizeof(type)) << 16;             \
356         __data_size += (len) * sizeof(type);
357
358 #undef __string
359 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
360
361 #undef DECLARE_EVENT_CLASS
362 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
363 static inline notrace int ftrace_get_offsets_##call(                    \
364         struct ftrace_data_offsets_##call *__data_offsets, proto)       \
365 {                                                                       \
366         int __data_size = 0;                                            \
367         struct ftrace_raw_##call __maybe_unused *entry;                 \
368                                                                         \
369         tstruct;                                                        \
370                                                                         \
371         return __data_size;                                             \
372 }
373
374 #undef DEFINE_EVENT
375 #define DEFINE_EVENT(template, name, proto, args)
376
377 #undef DEFINE_EVENT_PRINT
378 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
379         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
380
381 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
382
383 /*
384  * Stage 4 of the trace events.
385  *
386  * Override the macros in <trace/trace_events.h> to include the following:
387  *
388  * For those macros defined with TRACE_EVENT:
389  *
390  * static struct ftrace_event_call event_<call>;
391  *
392  * static void ftrace_raw_event_<call>(void *__data, proto)
393  * {
394  *      struct ftrace_event_call *event_call = __data;
395  *      struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
396  *      struct ring_buffer_event *event;
397  *      struct ftrace_raw_<call> *entry; <-- defined in stage 1
398  *      struct ring_buffer *buffer;
399  *      unsigned long irq_flags;
400  *      int __data_size;
401  *      int pc;
402  *
403  *      local_save_flags(irq_flags);
404  *      pc = preempt_count();
405  *
406  *      __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
407  *
408  *      event = trace_current_buffer_lock_reserve(&buffer,
409  *                                event_<call>->event.type,
410  *                                sizeof(*entry) + __data_size,
411  *                                irq_flags, pc);
412  *      if (!event)
413  *              return;
414  *      entry   = ring_buffer_event_data(event);
415  *
416  *      { <assign>; }  <-- Here we assign the entries by the __field and
417  *                         __array macros.
418  *
419  *      if (!filter_current_check_discard(buffer, event_call, entry, event))
420  *              trace_current_buffer_unlock_commit(buffer,
421  *                                                 event, irq_flags, pc);
422  * }
423  *
424  * static struct trace_event ftrace_event_type_<call> = {
425  *      .trace                  = ftrace_raw_output_<call>, <-- stage 2
426  * };
427  *
428  * static const char print_fmt_<call>[] = <TP_printk>;
429  *
430  * static struct ftrace_event_class __used event_class_<template> = {
431  *      .system                 = "<system>",
432  *      .define_fields          = ftrace_define_fields_<call>,
433  *      .fields                 = LIST_HEAD_INIT(event_class_##call.fields),
434  *      .raw_init               = trace_event_raw_init,
435  *      .probe                  = ftrace_raw_event_##call,
436  *      .reg                    = ftrace_event_reg,
437  * };
438  *
439  * static struct ftrace_event_call __used
440  * __attribute__((__aligned__(4)))
441  * __attribute__((section("_ftrace_events"))) event_<call> = {
442  *      .name                   = "<call>",
443  *      .class                  = event_class_<template>,
444  *      .event                  = &ftrace_event_type_<call>,
445  *      .print_fmt              = print_fmt_<call>,
446  * };
447  *
448  */
449
450 #ifdef CONFIG_PERF_EVENTS
451
452 #define _TRACE_PERF_PROTO(call, proto)                                  \
453         static notrace void                                             \
454         perf_trace_##call(void *__data, proto);
455
456 #define _TRACE_PERF_INIT(call)                                          \
457         .perf_probe             = perf_trace_##call,
458
459 #else
460 #define _TRACE_PERF_PROTO(call, proto)
461 #define _TRACE_PERF_INIT(call)
462 #endif /* CONFIG_PERF_EVENTS */
463
464 #undef __entry
465 #define __entry entry
466
467 #undef __field
468 #define __field(type, item)
469
470 #undef __array
471 #define __array(type, item, len)
472
473 #undef __dynamic_array
474 #define __dynamic_array(type, item, len)                                \
475         __entry->__data_loc_##item = __data_offsets.item;
476
477 #undef __string
478 #define __string(item, src) __dynamic_array(char, item, -1)             \
479
480 #undef __assign_str
481 #define __assign_str(dst, src)                                          \
482         strcpy(__get_str(dst), src);
483
484 #undef TP_fast_assign
485 #define TP_fast_assign(args...) args
486
487 #undef TP_perf_assign
488 #define TP_perf_assign(args...)
489
490 #undef DECLARE_EVENT_CLASS
491 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
492                                                                         \
493 static notrace void                                                     \
494 ftrace_raw_event_##call(void *__data, proto)                            \
495 {                                                                       \
496         struct ftrace_event_call *event_call = __data;                  \
497         struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
498         struct ring_buffer_event *event;                                \
499         struct ftrace_raw_##call *entry;                                \
500         struct ring_buffer *buffer;                                     \
501         unsigned long irq_flags;                                        \
502         int __data_size;                                                \
503         int pc;                                                         \
504                                                                         \
505         local_save_flags(irq_flags);                                    \
506         pc = preempt_count();                                           \
507                                                                         \
508         __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
509                                                                         \
510         event = trace_current_buffer_lock_reserve(&buffer,              \
511                                  event_call->event.type,                \
512                                  sizeof(*entry) + __data_size,          \
513                                  irq_flags, pc);                        \
514         if (!event)                                                     \
515                 return;                                                 \
516         entry   = ring_buffer_event_data(event);                        \
517                                                                         \
518         tstruct                                                         \
519                                                                         \
520         { assign; }                                                     \
521                                                                         \
522         if (!filter_current_check_discard(buffer, event_call, entry, event)) \
523                 trace_nowake_buffer_unlock_commit(buffer,               \
524                                                   event, irq_flags, pc); \
525 }
526 /*
527  * The ftrace_test_probe is compiled out, it is only here as a build time check
528  * to make sure that if the tracepoint handling changes, the ftrace probe will
529  * fail to compile unless it too is updated.
530  */
531
532 #undef DEFINE_EVENT
533 #define DEFINE_EVENT(template, call, proto, args)                       \
534 static inline void ftrace_test_probe_##call(void)                       \
535 {                                                                       \
536         check_trace_callback_type_##call(ftrace_raw_event_##template);  \
537 }
538
539 #undef DEFINE_EVENT_PRINT
540 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
541
542 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
543
544 #undef __entry
545 #define __entry REC
546
547 #undef __print_flags
548 #undef __print_symbolic
549 #undef __get_dynamic_array
550 #undef __get_str
551
552 #undef TP_printk
553 #define TP_printk(fmt, args...) "\"" fmt "\", "  __stringify(args)
554
555 #undef DECLARE_EVENT_CLASS
556 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
557 _TRACE_PERF_PROTO(call, PARAMS(proto));                                 \
558 static const char print_fmt_##call[] = print;                           \
559 static struct ftrace_event_class __used event_class_##call = {          \
560         .system                 = __stringify(TRACE_SYSTEM),            \
561         .define_fields          = ftrace_define_fields_##call,          \
562         .fields                 = LIST_HEAD_INIT(event_class_##call.fields),\
563         .raw_init               = trace_event_raw_init,                 \
564         .probe                  = ftrace_raw_event_##call,              \
565         .reg                    = ftrace_event_reg,                     \
566         _TRACE_PERF_INIT(call)                                          \
567 };
568
569 #undef DEFINE_EVENT
570 #define DEFINE_EVENT(template, call, proto, args)                       \
571                                                                         \
572 static struct ftrace_event_call __used                                  \
573 __attribute__((__aligned__(4)))                                         \
574 __attribute__((section("_ftrace_events"))) event_##call = {             \
575         .name                   = #call,                                \
576         .class                  = &event_class_##template,              \
577         .event.funcs            = &ftrace_event_type_funcs_##template,  \
578         .print_fmt              = print_fmt_##template,                 \
579 };
580
581 #undef DEFINE_EVENT_PRINT
582 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)          \
583                                                                         \
584 static const char print_fmt_##call[] = print;                           \
585                                                                         \
586 static struct ftrace_event_call __used                                  \
587 __attribute__((__aligned__(4)))                                         \
588 __attribute__((section("_ftrace_events"))) event_##call = {             \
589         .name                   = #call,                                \
590         .class                  = &event_class_##template,              \
591         .event.funcs            = &ftrace_event_type_funcs_##call,      \
592         .print_fmt              = print_fmt_##call,                     \
593 }
594
595 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
596
597 /*
598  * Define the insertion callback to perf events
599  *
600  * The job is very similar to ftrace_raw_event_<call> except that we don't
601  * insert in the ring buffer but in a perf counter.
602  *
603  * static void ftrace_perf_<call>(proto)
604  * {
605  *      struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
606  *      struct ftrace_event_call *event_call = &event_<call>;
607  *      extern void perf_tp_event(int, u64, u64, void *, int);
608  *      struct ftrace_raw_##call *entry;
609  *      struct perf_trace_buf *trace_buf;
610  *      u64 __addr = 0, __count = 1;
611  *      unsigned long irq_flags;
612  *      struct trace_entry *ent;
613  *      int __entry_size;
614  *      int __data_size;
615  *      int __cpu
616  *      int pc;
617  *
618  *      pc = preempt_count();
619  *
620  *      __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
621  *
622  *      // Below we want to get the aligned size by taking into account
623  *      // the u32 field that will later store the buffer size
624  *      __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
625  *                           sizeof(u64));
626  *      __entry_size -= sizeof(u32);
627  *
628  *      // Protect the non nmi buffer
629  *      // This also protects the rcu read side
630  *      local_irq_save(irq_flags);
631  *      __cpu = smp_processor_id();
632  *
633  *      if (in_nmi())
634  *              trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
635  *      else
636  *              trace_buf = rcu_dereference_sched(perf_trace_buf);
637  *
638  *      if (!trace_buf)
639  *              goto end;
640  *
641  *      trace_buf = per_cpu_ptr(trace_buf, __cpu);
642  *
643  *      // Avoid recursion from perf that could mess up the buffer
644  *      if (trace_buf->recursion++)
645  *              goto end_recursion;
646  *
647  *      raw_data = trace_buf->buf;
648  *
649  *      // Make recursion update visible before entering perf_tp_event
650  *      // so that we protect from perf recursions.
651  *
652  *      barrier();
653  *
654  *      //zero dead bytes from alignment to avoid stack leak to userspace:
655  *      *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
656  *      entry = (struct ftrace_raw_<call> *)raw_data;
657  *      ent = &entry->ent;
658  *      tracing_generic_entry_update(ent, irq_flags, pc);
659  *      ent->type = event_call->id;
660  *
661  *      <tstruct> <- do some jobs with dynamic arrays
662  *
663  *      <assign>  <- affect our values
664  *
665  *      perf_tp_event(event_call->id, __addr, __count, entry,
666  *                   __entry_size);  <- submit them to perf counter
667  *
668  * }
669  */
670
671 #ifdef CONFIG_PERF_EVENTS
672
673 #undef __entry
674 #define __entry entry
675
676 #undef __get_dynamic_array
677 #define __get_dynamic_array(field)      \
678                 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
679
680 #undef __get_str
681 #define __get_str(field) (char *)__get_dynamic_array(field)
682
683 #undef __perf_addr
684 #define __perf_addr(a) __addr = (a)
685
686 #undef __perf_count
687 #define __perf_count(c) __count = (c)
688
689 #undef DECLARE_EVENT_CLASS
690 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
691 static notrace void                                                     \
692 perf_trace_##call(void *__data, proto)                                  \
693 {                                                                       \
694         struct ftrace_event_call *event_call = __data;                  \
695         struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
696         struct ftrace_raw_##call *entry;                                \
697         struct pt_regs __regs;                                          \
698         u64 __addr = 0, __count = 1;                                    \
699         struct hlist_head *head;                                        \
700         int __entry_size;                                               \
701         int __data_size;                                                \
702         int rctx;                                                       \
703                                                                         \
704         perf_fetch_caller_regs(&__regs);                                \
705                                                                         \
706         __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
707         __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
708                              sizeof(u64));                              \
709         __entry_size -= sizeof(u32);                                    \
710                                                                         \
711         if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE,               \
712                       "profile buffer not large enough"))               \
713                 return;                                                 \
714                                                                         \
715         entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare(     \
716                 __entry_size, event_call->event.type, &__regs, &rctx);  \
717         if (!entry)                                                     \
718                 return;                                                 \
719                                                                         \
720         tstruct                                                         \
721                                                                         \
722         { assign; }                                                     \
723                                                                         \
724         head = this_cpu_ptr(event_call->perf_events);                   \
725         perf_trace_buf_submit(entry, __entry_size, rctx, __addr,        \
726                 __count, &__regs, head);                                \
727 }
728
729 /*
730  * This part is compiled out, it is only here as a build time check
731  * to make sure that if the tracepoint handling changes, the
732  * perf probe will fail to compile unless it too is updated.
733  */
734 #undef DEFINE_EVENT
735 #define DEFINE_EVENT(template, call, proto, args)                       \
736 static inline void perf_test_probe_##call(void)                         \
737 {                                                                       \
738         check_trace_callback_type_##call(perf_trace_##template);        \
739 }
740
741
742 #undef DEFINE_EVENT_PRINT
743 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
744         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
745
746 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
747 #endif /* CONFIG_PERF_EVENTS */
748
749 #undef _TRACE_PROFILE_INIT
750