ARM: Kirkwood: Remove mach-kirkwood
[cascardo/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 __bitmask
57 #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
58
59 #undef TP_STRUCT__entry
60 #define TP_STRUCT__entry(args...) args
61
62 #undef DECLARE_EVENT_CLASS
63 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)  \
64         struct ftrace_raw_##name {                                      \
65                 struct trace_entry      ent;                            \
66                 tstruct                                                 \
67                 char                    __data[0];                      \
68         };                                                              \
69                                                                         \
70         static struct ftrace_event_class event_class_##name;
71
72 #undef DEFINE_EVENT
73 #define DEFINE_EVENT(template, name, proto, args)       \
74         static struct ftrace_event_call __used          \
75         __attribute__((__aligned__(4))) event_##name
76
77 #undef DEFINE_EVENT_FN
78 #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)        \
79         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
80
81 #undef DEFINE_EVENT_PRINT
82 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
83         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
84
85 /* Callbacks are meaningless to ftrace. */
86 #undef TRACE_EVENT_FN
87 #define TRACE_EVENT_FN(name, proto, args, tstruct,                      \
88                 assign, print, reg, unreg)                              \
89         TRACE_EVENT(name, PARAMS(proto), PARAMS(args),                  \
90                 PARAMS(tstruct), PARAMS(assign), PARAMS(print))         \
91
92 #undef TRACE_EVENT_FLAGS
93 #define TRACE_EVENT_FLAGS(name, value)                                  \
94         __TRACE_EVENT_FLAGS(name, value)
95
96 #undef TRACE_EVENT_PERF_PERM
97 #define TRACE_EVENT_PERF_PERM(name, expr...)                            \
98         __TRACE_EVENT_PERF_PERM(name, expr)
99
100 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
101
102
103 /*
104  * Stage 2 of the trace events.
105  *
106  * Include the following:
107  *
108  * struct ftrace_data_offsets_<call> {
109  *      u32                             <item1>;
110  *      u32                             <item2>;
111  *      [...]
112  * };
113  *
114  * The __dynamic_array() macro will create each u32 <item>, this is
115  * to keep the offset of each array from the beginning of the event.
116  * The size of an array is also encoded, in the higher 16 bits of <item>.
117  */
118
119 #undef __field
120 #define __field(type, item)
121
122 #undef __field_ext
123 #define __field_ext(type, item, filter_type)
124
125 #undef __array
126 #define __array(type, item, len)
127
128 #undef __dynamic_array
129 #define __dynamic_array(type, item, len)        u32 item;
130
131 #undef __string
132 #define __string(item, src) __dynamic_array(char, item, -1)
133
134 #undef __bitmask
135 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
136
137 #undef DECLARE_EVENT_CLASS
138 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
139         struct ftrace_data_offsets_##call {                             \
140                 tstruct;                                                \
141         };
142
143 #undef DEFINE_EVENT
144 #define DEFINE_EVENT(template, name, proto, args)
145
146 #undef DEFINE_EVENT_PRINT
147 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
148         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
149
150 #undef TRACE_EVENT_FLAGS
151 #define TRACE_EVENT_FLAGS(event, flag)
152
153 #undef TRACE_EVENT_PERF_PERM
154 #define TRACE_EVENT_PERF_PERM(event, expr...)
155
156 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
157
158 /*
159  * Stage 3 of the trace events.
160  *
161  * Override the macros in <trace/trace_events.h> to include the following:
162  *
163  * enum print_line_t
164  * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
165  * {
166  *      struct trace_seq *s = &iter->seq;
167  *      struct ftrace_raw_<call> *field; <-- defined in stage 1
168  *      struct trace_entry *entry;
169  *      struct trace_seq *p = &iter->tmp_seq;
170  *      int ret;
171  *
172  *      entry = iter->ent;
173  *
174  *      if (entry->type != event_<call>->event.type) {
175  *              WARN_ON_ONCE(1);
176  *              return TRACE_TYPE_UNHANDLED;
177  *      }
178  *
179  *      field = (typeof(field))entry;
180  *
181  *      trace_seq_init(p);
182  *      ret = trace_seq_printf(s, "%s: ", <call>);
183  *      if (ret)
184  *              ret = trace_seq_printf(s, <TP_printk> "\n");
185  *      if (!ret)
186  *              return TRACE_TYPE_PARTIAL_LINE;
187  *
188  *      return TRACE_TYPE_HANDLED;
189  * }
190  *
191  * This is the method used to print the raw event to the trace
192  * output format. Note, this is not needed if the data is read
193  * in binary.
194  */
195
196 #undef __entry
197 #define __entry field
198
199 #undef TP_printk
200 #define TP_printk(fmt, args...) fmt "\n", args
201
202 #undef __get_dynamic_array
203 #define __get_dynamic_array(field)      \
204                 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
205
206 #undef __get_dynamic_array_len
207 #define __get_dynamic_array_len(field)  \
208                 ((__entry->__data_loc_##field >> 16) & 0xffff)
209
210 #undef __get_str
211 #define __get_str(field) (char *)__get_dynamic_array(field)
212
213 #undef __get_bitmask
214 #define __get_bitmask(field)                                            \
215         ({                                                              \
216                 void *__bitmask = __get_dynamic_array(field);           \
217                 unsigned int __bitmask_size;                            \
218                 __bitmask_size = __get_dynamic_array_len(field);        \
219                 ftrace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
220         })
221
222 #undef __print_flags
223 #define __print_flags(flag, delim, flag_array...)                       \
224         ({                                                              \
225                 static const struct trace_print_flags __flags[] =       \
226                         { flag_array, { -1, NULL }};                    \
227                 ftrace_print_flags_seq(p, delim, flag, __flags);        \
228         })
229
230 #undef __print_symbolic
231 #define __print_symbolic(value, symbol_array...)                        \
232         ({                                                              \
233                 static const struct trace_print_flags symbols[] =       \
234                         { symbol_array, { -1, NULL }};                  \
235                 ftrace_print_symbols_seq(p, value, symbols);            \
236         })
237
238 #undef __print_symbolic_u64
239 #if BITS_PER_LONG == 32
240 #define __print_symbolic_u64(value, symbol_array...)                    \
241         ({                                                              \
242                 static const struct trace_print_flags_u64 symbols[] =   \
243                         { symbol_array, { -1, NULL } };                 \
244                 ftrace_print_symbols_seq_u64(p, value, symbols);        \
245         })
246 #else
247 #define __print_symbolic_u64(value, symbol_array...)                    \
248                         __print_symbolic(value, symbol_array)
249 #endif
250
251 #undef __print_hex
252 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
253
254 #undef DECLARE_EVENT_CLASS
255 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
256 static notrace enum print_line_t                                        \
257 ftrace_raw_output_##call(struct trace_iterator *iter, int flags,        \
258                          struct trace_event *trace_event)               \
259 {                                                                       \
260         struct trace_seq *s = &iter->seq;                               \
261         struct trace_seq __maybe_unused *p = &iter->tmp_seq;            \
262         struct ftrace_raw_##call *field;                                \
263         int ret;                                                        \
264                                                                         \
265         field = (typeof(field))iter->ent;                               \
266                                                                         \
267         ret = ftrace_raw_output_prep(iter, trace_event);                \
268         if (ret)                                                        \
269                 return ret;                                             \
270                                                                         \
271         ret = trace_seq_printf(s, print);                               \
272         if (!ret)                                                       \
273                 return TRACE_TYPE_PARTIAL_LINE;                         \
274                                                                         \
275         return TRACE_TYPE_HANDLED;                                      \
276 }                                                                       \
277 static struct trace_event_functions ftrace_event_type_funcs_##call = {  \
278         .trace                  = ftrace_raw_output_##call,             \
279 };
280
281 #undef DEFINE_EVENT_PRINT
282 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)          \
283 static notrace enum print_line_t                                        \
284 ftrace_raw_output_##call(struct trace_iterator *iter, int flags,        \
285                          struct trace_event *event)                     \
286 {                                                                       \
287         struct ftrace_raw_##template *field;                            \
288         struct trace_entry *entry;                                      \
289         struct trace_seq *p = &iter->tmp_seq;                           \
290                                                                         \
291         entry = iter->ent;                                              \
292                                                                         \
293         if (entry->type != event_##call.event.type) {                   \
294                 WARN_ON_ONCE(1);                                        \
295                 return TRACE_TYPE_UNHANDLED;                            \
296         }                                                               \
297                                                                         \
298         field = (typeof(field))entry;                                   \
299                                                                         \
300         trace_seq_init(p);                                              \
301         return ftrace_output_call(iter, #call, print);                  \
302 }                                                                       \
303 static struct trace_event_functions ftrace_event_type_funcs_##call = {  \
304         .trace                  = ftrace_raw_output_##call,             \
305 };
306
307 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
308
309 #undef __field_ext
310 #define __field_ext(type, item, filter_type)                            \
311         ret = trace_define_field(event_call, #type, #item,              \
312                                  offsetof(typeof(field), item),         \
313                                  sizeof(field.item),                    \
314                                  is_signed_type(type), filter_type);    \
315         if (ret)                                                        \
316                 return ret;
317
318 #undef __field
319 #define __field(type, item)     __field_ext(type, item, FILTER_OTHER)
320
321 #undef __array
322 #define __array(type, item, len)                                        \
323         do {                                                            \
324                 char *type_str = #type"["__stringify(len)"]";           \
325                 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL);                 \
326                 ret = trace_define_field(event_call, type_str, #item,   \
327                                  offsetof(typeof(field), item),         \
328                                  sizeof(field.item),                    \
329                                  is_signed_type(type), FILTER_OTHER);   \
330                 if (ret)                                                \
331                         return ret;                                     \
332         } while (0);
333
334 #undef __dynamic_array
335 #define __dynamic_array(type, item, len)                                       \
336         ret = trace_define_field(event_call, "__data_loc " #type "[]", #item,  \
337                                  offsetof(typeof(field), __data_loc_##item),   \
338                                  sizeof(field.__data_loc_##item),              \
339                                  is_signed_type(type), FILTER_OTHER);
340
341 #undef __string
342 #define __string(item, src) __dynamic_array(char, item, -1)
343
344 #undef __bitmask
345 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
346
347 #undef DECLARE_EVENT_CLASS
348 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print)    \
349 static int notrace __init                                               \
350 ftrace_define_fields_##call(struct ftrace_event_call *event_call)       \
351 {                                                                       \
352         struct ftrace_raw_##call field;                                 \
353         int ret;                                                        \
354                                                                         \
355         tstruct;                                                        \
356                                                                         \
357         return ret;                                                     \
358 }
359
360 #undef DEFINE_EVENT
361 #define DEFINE_EVENT(template, name, proto, args)
362
363 #undef DEFINE_EVENT_PRINT
364 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
365         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
366
367 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
368
369 /*
370  * remember the offset of each array from the beginning of the event.
371  */
372
373 #undef __entry
374 #define __entry entry
375
376 #undef __field
377 #define __field(type, item)
378
379 #undef __field_ext
380 #define __field_ext(type, item, filter_type)
381
382 #undef __array
383 #define __array(type, item, len)
384
385 #undef __dynamic_array
386 #define __dynamic_array(type, item, len)                                \
387         __item_length = (len) * sizeof(type);                           \
388         __data_offsets->item = __data_size +                            \
389                                offsetof(typeof(*entry), __data);        \
390         __data_offsets->item |= __item_length << 16;                    \
391         __data_size += __item_length;
392
393 #undef __string
394 #define __string(item, src) __dynamic_array(char, item,                 \
395                     strlen((src) ? (const char *)(src) : "(null)") + 1)
396
397 /*
398  * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
399  * num_possible_cpus().
400  */
401 #define __bitmask_size_in_bytes_raw(nr_bits)    \
402         (((nr_bits) + 7) / 8)
403
404 #define __bitmask_size_in_longs(nr_bits)                        \
405         ((__bitmask_size_in_bytes_raw(nr_bits) +                \
406           ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
407
408 /*
409  * __bitmask_size_in_bytes is the number of bytes needed to hold
410  * num_possible_cpus() padded out to the nearest long. This is what
411  * is saved in the buffer, just to be consistent.
412  */
413 #define __bitmask_size_in_bytes(nr_bits)                                \
414         (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
415
416 #undef __bitmask
417 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item,   \
418                                          __bitmask_size_in_longs(nr_bits))
419
420 #undef DECLARE_EVENT_CLASS
421 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
422 static inline notrace int ftrace_get_offsets_##call(                    \
423         struct ftrace_data_offsets_##call *__data_offsets, proto)       \
424 {                                                                       \
425         int __data_size = 0;                                            \
426         int __maybe_unused __item_length;                               \
427         struct ftrace_raw_##call __maybe_unused *entry;                 \
428                                                                         \
429         tstruct;                                                        \
430                                                                         \
431         return __data_size;                                             \
432 }
433
434 #undef DEFINE_EVENT
435 #define DEFINE_EVENT(template, name, proto, args)
436
437 #undef DEFINE_EVENT_PRINT
438 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
439         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
440
441 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
442
443 /*
444  * Stage 4 of the trace events.
445  *
446  * Override the macros in <trace/trace_events.h> to include the following:
447  *
448  * For those macros defined with TRACE_EVENT:
449  *
450  * static struct ftrace_event_call event_<call>;
451  *
452  * static void ftrace_raw_event_<call>(void *__data, proto)
453  * {
454  *      struct ftrace_event_file *ftrace_file = __data;
455  *      struct ftrace_event_call *event_call = ftrace_file->event_call;
456  *      struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
457  *      unsigned long eflags = ftrace_file->flags;
458  *      enum event_trigger_type __tt = ETT_NONE;
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  *      if (!(eflags & FTRACE_EVENT_FL_TRIGGER_COND)) {
467  *              if (eflags & FTRACE_EVENT_FL_TRIGGER_MODE)
468  *                      event_triggers_call(ftrace_file, NULL);
469  *              if (eflags & FTRACE_EVENT_FL_SOFT_DISABLED)
470  *                      return;
471  *      }
472  *
473  *      local_save_flags(irq_flags);
474  *      pc = preempt_count();
475  *
476  *      __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
477  *
478  *      event = trace_event_buffer_lock_reserve(&buffer, ftrace_file,
479  *                                event_<call>->event.type,
480  *                                sizeof(*entry) + __data_size,
481  *                                irq_flags, pc);
482  *      if (!event)
483  *              return;
484  *      entry   = ring_buffer_event_data(event);
485  *
486  *      { <assign>; }  <-- Here we assign the entries by the __field and
487  *                         __array macros.
488  *
489  *      if (eflags & FTRACE_EVENT_FL_TRIGGER_COND)
490  *              __tt = event_triggers_call(ftrace_file, entry);
491  *
492  *      if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
493  *                   &ftrace_file->flags))
494  *              ring_buffer_discard_commit(buffer, event);
495  *      else if (!filter_check_discard(ftrace_file, entry, buffer, event))
496  *              trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
497  *
498  *      if (__tt)
499  *              event_triggers_post_call(ftrace_file, __tt);
500  * }
501  *
502  * static struct trace_event ftrace_event_type_<call> = {
503  *      .trace                  = ftrace_raw_output_<call>, <-- stage 2
504  * };
505  *
506  * static const char print_fmt_<call>[] = <TP_printk>;
507  *
508  * static struct ftrace_event_class __used event_class_<template> = {
509  *      .system                 = "<system>",
510  *      .define_fields          = ftrace_define_fields_<call>,
511  *      .fields                 = LIST_HEAD_INIT(event_class_##call.fields),
512  *      .raw_init               = trace_event_raw_init,
513  *      .probe                  = ftrace_raw_event_##call,
514  *      .reg                    = ftrace_event_reg,
515  * };
516  *
517  * static struct ftrace_event_call event_<call> = {
518  *      .class                  = event_class_<template>,
519  *      {
520  *              .tp                     = &__tracepoint_<call>,
521  *      },
522  *      .event                  = &ftrace_event_type_<call>,
523  *      .print_fmt              = print_fmt_<call>,
524  *      .flags                  = TRACE_EVENT_FL_TRACEPOINT,
525  * };
526  * // its only safe to use pointers when doing linker tricks to
527  * // create an array.
528  * static struct ftrace_event_call __used
529  * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
530  *
531  */
532
533 #ifdef CONFIG_PERF_EVENTS
534
535 #define _TRACE_PERF_PROTO(call, proto)                                  \
536         static notrace void                                             \
537         perf_trace_##call(void *__data, proto);
538
539 #define _TRACE_PERF_INIT(call)                                          \
540         .perf_probe             = perf_trace_##call,
541
542 #else
543 #define _TRACE_PERF_PROTO(call, proto)
544 #define _TRACE_PERF_INIT(call)
545 #endif /* CONFIG_PERF_EVENTS */
546
547 #undef __entry
548 #define __entry entry
549
550 #undef __field
551 #define __field(type, item)
552
553 #undef __array
554 #define __array(type, item, len)
555
556 #undef __dynamic_array
557 #define __dynamic_array(type, item, len)                                \
558         __entry->__data_loc_##item = __data_offsets.item;
559
560 #undef __string
561 #define __string(item, src) __dynamic_array(char, item, -1)
562
563 #undef __assign_str
564 #define __assign_str(dst, src)                                          \
565         strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
566
567 #undef __bitmask
568 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
569
570 #undef __get_bitmask
571 #define __get_bitmask(field) (char *)__get_dynamic_array(field)
572
573 #undef __assign_bitmask
574 #define __assign_bitmask(dst, src, nr_bits)                                     \
575         memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
576
577 #undef TP_fast_assign
578 #define TP_fast_assign(args...) args
579
580 #undef __perf_addr
581 #define __perf_addr(a)  (a)
582
583 #undef __perf_count
584 #define __perf_count(c) (c)
585
586 #undef __perf_task
587 #define __perf_task(t)  (t)
588
589 #undef DECLARE_EVENT_CLASS
590 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
591                                                                         \
592 static notrace void                                                     \
593 ftrace_raw_event_##call(void *__data, proto)                            \
594 {                                                                       \
595         struct ftrace_event_file *ftrace_file = __data;                 \
596         struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
597         struct ftrace_event_buffer fbuffer;                             \
598         struct ftrace_raw_##call *entry;                                \
599         int __data_size;                                                \
600                                                                         \
601         if (ftrace_trigger_soft_disabled(ftrace_file))                  \
602                 return;                                                 \
603                                                                         \
604         __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
605                                                                         \
606         entry = ftrace_event_buffer_reserve(&fbuffer, ftrace_file,      \
607                                  sizeof(*entry) + __data_size);         \
608                                                                         \
609         if (!entry)                                                     \
610                 return;                                                 \
611                                                                         \
612         tstruct                                                         \
613                                                                         \
614         { assign; }                                                     \
615                                                                         \
616         ftrace_event_buffer_commit(&fbuffer);                           \
617 }
618 /*
619  * The ftrace_test_probe is compiled out, it is only here as a build time check
620  * to make sure that if the tracepoint handling changes, the ftrace probe will
621  * fail to compile unless it too is updated.
622  */
623
624 #undef DEFINE_EVENT
625 #define DEFINE_EVENT(template, call, proto, args)                       \
626 static inline void ftrace_test_probe_##call(void)                       \
627 {                                                                       \
628         check_trace_callback_type_##call(ftrace_raw_event_##template);  \
629 }
630
631 #undef DEFINE_EVENT_PRINT
632 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
633
634 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
635
636 #undef __entry
637 #define __entry REC
638
639 #undef __print_flags
640 #undef __print_symbolic
641 #undef __print_hex
642 #undef __get_dynamic_array
643 #undef __get_dynamic_array_len
644 #undef __get_str
645 #undef __get_bitmask
646
647 #undef TP_printk
648 #define TP_printk(fmt, args...) "\"" fmt "\", "  __stringify(args)
649
650 #undef DECLARE_EVENT_CLASS
651 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
652 _TRACE_PERF_PROTO(call, PARAMS(proto));                                 \
653 static const char print_fmt_##call[] = print;                           \
654 static struct ftrace_event_class __used __refdata event_class_##call = { \
655         .system                 = __stringify(TRACE_SYSTEM),            \
656         .define_fields          = ftrace_define_fields_##call,          \
657         .fields                 = LIST_HEAD_INIT(event_class_##call.fields),\
658         .raw_init               = trace_event_raw_init,                 \
659         .probe                  = ftrace_raw_event_##call,              \
660         .reg                    = ftrace_event_reg,                     \
661         _TRACE_PERF_INIT(call)                                          \
662 };
663
664 #undef DEFINE_EVENT
665 #define DEFINE_EVENT(template, call, proto, args)                       \
666                                                                         \
667 static struct ftrace_event_call __used event_##call = {                 \
668         .class                  = &event_class_##template,              \
669         {                                                               \
670                 .tp                     = &__tracepoint_##call,         \
671         },                                                              \
672         .event.funcs            = &ftrace_event_type_funcs_##template,  \
673         .print_fmt              = print_fmt_##template,                 \
674         .flags                  = TRACE_EVENT_FL_TRACEPOINT,            \
675 };                                                                      \
676 static struct ftrace_event_call __used                                  \
677 __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
678
679 #undef DEFINE_EVENT_PRINT
680 #define DEFINE_EVENT_PRINT(template, call, proto, args, print)          \
681                                                                         \
682 static const char print_fmt_##call[] = print;                           \
683                                                                         \
684 static struct ftrace_event_call __used event_##call = {                 \
685         .class                  = &event_class_##template,              \
686         {                                                               \
687                 .tp                     = &__tracepoint_##call,         \
688         },                                                              \
689         .event.funcs            = &ftrace_event_type_funcs_##call,      \
690         .print_fmt              = print_fmt_##call,                     \
691         .flags                  = TRACE_EVENT_FL_TRACEPOINT,            \
692 };                                                                      \
693 static struct ftrace_event_call __used                                  \
694 __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
695
696 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
697
698
699 #ifdef CONFIG_PERF_EVENTS
700
701 #undef __entry
702 #define __entry entry
703
704 #undef __get_dynamic_array
705 #define __get_dynamic_array(field)      \
706                 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
707
708 #undef __get_dynamic_array_len
709 #define __get_dynamic_array_len(field)  \
710                 ((__entry->__data_loc_##field >> 16) & 0xffff)
711
712 #undef __get_str
713 #define __get_str(field) (char *)__get_dynamic_array(field)
714
715 #undef __get_bitmask
716 #define __get_bitmask(field) (char *)__get_dynamic_array(field)
717
718 #undef __perf_addr
719 #define __perf_addr(a)  (__addr = (a))
720
721 #undef __perf_count
722 #define __perf_count(c) (__count = (c))
723
724 #undef __perf_task
725 #define __perf_task(t)  (__task = (t))
726
727 #undef DECLARE_EVENT_CLASS
728 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
729 static notrace void                                                     \
730 perf_trace_##call(void *__data, proto)                                  \
731 {                                                                       \
732         struct ftrace_event_call *event_call = __data;                  \
733         struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
734         struct ftrace_raw_##call *entry;                                \
735         struct pt_regs __regs;                                          \
736         u64 __addr = 0, __count = 1;                                    \
737         struct task_struct *__task = NULL;                              \
738         struct hlist_head *head;                                        \
739         int __entry_size;                                               \
740         int __data_size;                                                \
741         int rctx;                                                       \
742                                                                         \
743         __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
744                                                                         \
745         head = this_cpu_ptr(event_call->perf_events);                   \
746         if (__builtin_constant_p(!__task) && !__task &&                 \
747                                 hlist_empty(head))                      \
748                 return;                                                 \
749                                                                         \
750         __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
751                              sizeof(u64));                              \
752         __entry_size -= sizeof(u32);                                    \
753                                                                         \
754         perf_fetch_caller_regs(&__regs);                                \
755         entry = perf_trace_buf_prepare(__entry_size,                    \
756                         event_call->event.type, &__regs, &rctx);        \
757         if (!entry)                                                     \
758                 return;                                                 \
759                                                                         \
760         tstruct                                                         \
761                                                                         \
762         { assign; }                                                     \
763                                                                         \
764         perf_trace_buf_submit(entry, __entry_size, rctx, __addr,        \
765                 __count, &__regs, head, __task);                        \
766 }
767
768 /*
769  * This part is compiled out, it is only here as a build time check
770  * to make sure that if the tracepoint handling changes, the
771  * perf probe will fail to compile unless it too is updated.
772  */
773 #undef DEFINE_EVENT
774 #define DEFINE_EVENT(template, call, proto, args)                       \
775 static inline void perf_test_probe_##call(void)                         \
776 {                                                                       \
777         check_trace_callback_type_##call(perf_trace_##template);        \
778 }
779
780
781 #undef DEFINE_EVENT_PRINT
782 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
783         DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
784
785 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
786 #endif /* CONFIG_PERF_EVENTS */
787