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