]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/trace/ftrace.h
tracing: Let tracepoints have data passed to tracepoint callbacks
[mirror_ubuntu-bionic-kernel.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 \
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;
149 * int ret;
150 *
151 * entry = iter->ent;
152 *
153 * if (entry->type != event_<call>.id) {
154 * WARN_ON_ONCE(1);
155 * return TRACE_TYPE_UNHANDLED;
156 * }
157 *
158 * field = (typeof(field))entry;
159 *
160 * p = &get_cpu_var(ftrace_event_seq);
161 * trace_seq_init(p);
162 * ret = trace_seq_printf(s, "%s: ", <call>);
163 * if (ret)
164 * ret = trace_seq_printf(s, <TP_printk> "\n");
165 * put_cpu();
166 * if (!ret)
167 * return TRACE_TYPE_PARTIAL_LINE;
168 *
169 * return TRACE_TYPE_HANDLED;
170 * }
171 *
172 * This is the method used to print the raw event to the trace
173 * output format. Note, this is not needed if the data is read
174 * in binary.
175 */
176
177 #undef __entry
178 #define __entry field
179
180 #undef TP_printk
181 #define TP_printk(fmt, args...) fmt "\n", args
182
183 #undef __get_dynamic_array
184 #define __get_dynamic_array(field) \
185 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
186
187 #undef __get_str
188 #define __get_str(field) (char *)__get_dynamic_array(field)
189
190 #undef __print_flags
191 #define __print_flags(flag, delim, flag_array...) \
192 ({ \
193 static const struct trace_print_flags __flags[] = \
194 { flag_array, { -1, NULL }}; \
195 ftrace_print_flags_seq(p, delim, flag, __flags); \
196 })
197
198 #undef __print_symbolic
199 #define __print_symbolic(value, symbol_array...) \
200 ({ \
201 static const struct trace_print_flags symbols[] = \
202 { symbol_array, { -1, NULL }}; \
203 ftrace_print_symbols_seq(p, value, symbols); \
204 })
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(void *, 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, NULL); \
415 } \
416 \
417 static notrace void \
418 perf_trace_disable_##name(struct ftrace_event_call *unused) \
419 { \
420 unregister_trace_##name(perf_trace_##name, NULL); \
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 * For those macros defined with TRACE_EVENT:
437 *
438 * static struct ftrace_event_call event_<call>;
439 *
440 * static void ftrace_raw_event_<call>(proto)
441 * {
442 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
443 * struct ring_buffer_event *event;
444 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
445 * struct ring_buffer *buffer;
446 * unsigned long irq_flags;
447 * int __data_size;
448 * int pc;
449 *
450 * local_save_flags(irq_flags);
451 * pc = preempt_count();
452 *
453 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
454 *
455 * event = trace_current_buffer_lock_reserve(&buffer,
456 * event_<call>.id,
457 * sizeof(*entry) + __data_size,
458 * irq_flags, pc);
459 * if (!event)
460 * return;
461 * entry = ring_buffer_event_data(event);
462 *
463 * { <assign>; } <-- Here we assign the entries by the __field and
464 * __array macros.
465 *
466 * if (!filter_current_check_discard(buffer, event_call, entry, event))
467 * trace_current_buffer_unlock_commit(buffer,
468 * event, irq_flags, pc);
469 * }
470 *
471 * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
472 * {
473 * return register_trace_<call>(ftrace_raw_event_<call>);
474 * }
475 *
476 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
477 * {
478 * unregister_trace_<call>(ftrace_raw_event_<call>);
479 * }
480 *
481 * static struct trace_event ftrace_event_type_<call> = {
482 * .trace = ftrace_raw_output_<call>, <-- stage 2
483 * };
484 *
485 * static const char print_fmt_<call>[] = <TP_printk>;
486 *
487 * static struct ftrace_event_class __used event_class_<template> = {
488 * .system = "<system>",
489 * };
490 *
491 * static struct ftrace_event_call __used
492 * __attribute__((__aligned__(4)))
493 * __attribute__((section("_ftrace_events"))) event_<call> = {
494 * .name = "<call>",
495 * .class = event_class_<template>,
496 * .raw_init = trace_event_raw_init,
497 * .regfunc = ftrace_raw_reg_event_<call>,
498 * .unregfunc = ftrace_raw_unreg_event_<call>,
499 * .print_fmt = print_fmt_<call>,
500 * .define_fields = ftrace_define_fields_<call>,
501 * };
502 *
503 */
504
505 #ifdef CONFIG_PERF_EVENTS
506
507 #define _TRACE_PERF_INIT(call) \
508 .perf_event_enable = perf_trace_enable_##call, \
509 .perf_event_disable = perf_trace_disable_##call,
510
511 #else
512 #define _TRACE_PERF_INIT(call)
513 #endif /* CONFIG_PERF_EVENTS */
514
515 #undef __entry
516 #define __entry entry
517
518 #undef __field
519 #define __field(type, item)
520
521 #undef __array
522 #define __array(type, item, len)
523
524 #undef __dynamic_array
525 #define __dynamic_array(type, item, len) \
526 __entry->__data_loc_##item = __data_offsets.item;
527
528 #undef __string
529 #define __string(item, src) __dynamic_array(char, item, -1) \
530
531 #undef __assign_str
532 #define __assign_str(dst, src) \
533 strcpy(__get_str(dst), src);
534
535 #undef TP_fast_assign
536 #define TP_fast_assign(args...) args
537
538 #undef TP_perf_assign
539 #define TP_perf_assign(args...)
540
541 #undef DECLARE_EVENT_CLASS
542 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
543 \
544 static notrace void \
545 ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
546 proto) \
547 { \
548 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
549 struct ring_buffer_event *event; \
550 struct ftrace_raw_##call *entry; \
551 struct ring_buffer *buffer; \
552 unsigned long irq_flags; \
553 int __data_size; \
554 int pc; \
555 \
556 local_save_flags(irq_flags); \
557 pc = preempt_count(); \
558 \
559 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
560 \
561 event = trace_current_buffer_lock_reserve(&buffer, \
562 event_call->id, \
563 sizeof(*entry) + __data_size, \
564 irq_flags, pc); \
565 if (!event) \
566 return; \
567 entry = ring_buffer_event_data(event); \
568 \
569 tstruct \
570 \
571 { assign; } \
572 \
573 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
574 trace_nowake_buffer_unlock_commit(buffer, \
575 event, irq_flags, pc); \
576 }
577
578 #undef DEFINE_EVENT
579 #define DEFINE_EVENT(template, call, proto, args) \
580 \
581 static notrace void ftrace_raw_event_##call(void *__ignore, proto) \
582 { \
583 ftrace_raw_event_id_##template(&event_##call, args); \
584 } \
585 \
586 static notrace int \
587 ftrace_raw_reg_event_##call(struct ftrace_event_call *unused) \
588 { \
589 return register_trace_##call(ftrace_raw_event_##call, NULL); \
590 } \
591 \
592 static notrace void \
593 ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused) \
594 { \
595 unregister_trace_##call(ftrace_raw_event_##call, NULL); \
596 } \
597 \
598 static struct trace_event ftrace_event_type_##call = { \
599 .trace = ftrace_raw_output_##call, \
600 };
601
602 #undef DEFINE_EVENT_PRINT
603 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
604 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
605
606 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
607
608 #undef __entry
609 #define __entry REC
610
611 #undef __print_flags
612 #undef __print_symbolic
613 #undef __get_dynamic_array
614 #undef __get_str
615
616 #undef TP_printk
617 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
618
619 #undef DECLARE_EVENT_CLASS
620 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
621 static const char print_fmt_##call[] = print; \
622 static struct ftrace_event_class __used event_class_##call = { \
623 .system = __stringify(TRACE_SYSTEM) \
624 };
625
626 #undef DEFINE_EVENT
627 #define DEFINE_EVENT(template, call, proto, args) \
628 \
629 static struct ftrace_event_call __used \
630 __attribute__((__aligned__(4))) \
631 __attribute__((section("_ftrace_events"))) event_##call = { \
632 .name = #call, \
633 .class = &event_class_##template, \
634 .event = &ftrace_event_type_##call, \
635 .raw_init = trace_event_raw_init, \
636 .regfunc = ftrace_raw_reg_event_##call, \
637 .unregfunc = ftrace_raw_unreg_event_##call, \
638 .print_fmt = print_fmt_##template, \
639 .define_fields = ftrace_define_fields_##template, \
640 _TRACE_PERF_INIT(call) \
641 };
642
643 #undef DEFINE_EVENT_PRINT
644 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
645 \
646 static const char print_fmt_##call[] = print; \
647 \
648 static struct ftrace_event_call __used \
649 __attribute__((__aligned__(4))) \
650 __attribute__((section("_ftrace_events"))) event_##call = { \
651 .name = #call, \
652 .class = &event_class_##template, \
653 .event = &ftrace_event_type_##call, \
654 .raw_init = trace_event_raw_init, \
655 .regfunc = ftrace_raw_reg_event_##call, \
656 .unregfunc = ftrace_raw_unreg_event_##call, \
657 .print_fmt = print_fmt_##call, \
658 .define_fields = ftrace_define_fields_##template, \
659 _TRACE_PERF_INIT(call) \
660 }
661
662 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
663
664 /*
665 * Define the insertion callback to perf events
666 *
667 * The job is very similar to ftrace_raw_event_<call> except that we don't
668 * insert in the ring buffer but in a perf counter.
669 *
670 * static void ftrace_perf_<call>(proto)
671 * {
672 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
673 * struct ftrace_event_call *event_call = &event_<call>;
674 * extern void perf_tp_event(int, u64, u64, void *, int);
675 * struct ftrace_raw_##call *entry;
676 * struct perf_trace_buf *trace_buf;
677 * u64 __addr = 0, __count = 1;
678 * unsigned long irq_flags;
679 * struct trace_entry *ent;
680 * int __entry_size;
681 * int __data_size;
682 * int __cpu
683 * int pc;
684 *
685 * pc = preempt_count();
686 *
687 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
688 *
689 * // Below we want to get the aligned size by taking into account
690 * // the u32 field that will later store the buffer size
691 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
692 * sizeof(u64));
693 * __entry_size -= sizeof(u32);
694 *
695 * // Protect the non nmi buffer
696 * // This also protects the rcu read side
697 * local_irq_save(irq_flags);
698 * __cpu = smp_processor_id();
699 *
700 * if (in_nmi())
701 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
702 * else
703 * trace_buf = rcu_dereference_sched(perf_trace_buf);
704 *
705 * if (!trace_buf)
706 * goto end;
707 *
708 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
709 *
710 * // Avoid recursion from perf that could mess up the buffer
711 * if (trace_buf->recursion++)
712 * goto end_recursion;
713 *
714 * raw_data = trace_buf->buf;
715 *
716 * // Make recursion update visible before entering perf_tp_event
717 * // so that we protect from perf recursions.
718 *
719 * barrier();
720 *
721 * //zero dead bytes from alignment to avoid stack leak to userspace:
722 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
723 * entry = (struct ftrace_raw_<call> *)raw_data;
724 * ent = &entry->ent;
725 * tracing_generic_entry_update(ent, irq_flags, pc);
726 * ent->type = event_call->id;
727 *
728 * <tstruct> <- do some jobs with dynamic arrays
729 *
730 * <assign> <- affect our values
731 *
732 * perf_tp_event(event_call->id, __addr, __count, entry,
733 * __entry_size); <- submit them to perf counter
734 *
735 * }
736 */
737
738 #ifdef CONFIG_PERF_EVENTS
739
740 #undef __entry
741 #define __entry entry
742
743 #undef __get_dynamic_array
744 #define __get_dynamic_array(field) \
745 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
746
747 #undef __get_str
748 #define __get_str(field) (char *)__get_dynamic_array(field)
749
750 #undef __perf_addr
751 #define __perf_addr(a) __addr = (a)
752
753 #undef __perf_count
754 #define __perf_count(c) __count = (c)
755
756 #undef DECLARE_EVENT_CLASS
757 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
758 static notrace void \
759 perf_trace_templ_##call(struct ftrace_event_call *event_call, \
760 proto) \
761 { \
762 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
763 struct ftrace_raw_##call *entry; \
764 u64 __addr = 0, __count = 1; \
765 unsigned long irq_flags; \
766 struct pt_regs *__regs; \
767 int __entry_size; \
768 int __data_size; \
769 int rctx; \
770 \
771 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
772 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
773 sizeof(u64)); \
774 __entry_size -= sizeof(u32); \
775 \
776 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
777 "profile buffer not large enough")) \
778 return; \
779 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
780 __entry_size, event_call->id, &rctx, &irq_flags); \
781 if (!entry) \
782 return; \
783 tstruct \
784 \
785 { assign; } \
786 \
787 __regs = &__get_cpu_var(perf_trace_regs); \
788 perf_fetch_caller_regs(__regs, 2); \
789 \
790 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
791 __count, irq_flags, __regs); \
792 }
793
794 #undef DEFINE_EVENT
795 #define DEFINE_EVENT(template, call, proto, args) \
796 static notrace void perf_trace_##call(void *__ignore, proto) \
797 { \
798 struct ftrace_event_call *event_call = &event_##call; \
799 \
800 perf_trace_templ_##template(event_call, args); \
801 }
802
803 #undef DEFINE_EVENT_PRINT
804 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
805 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
806
807 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
808 #endif /* CONFIG_PERF_EVENTS */
809
810 #undef _TRACE_PROFILE_INIT
811