b4bac43c7dde81eb814cc43d63fe4ccf7ef1aaa7
4 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
8 #define tp_assign(dest, src) \
9 lib_ring_buffer_align_ctx(config, &ctx, sizeof(src)); \
10 lib_ring_buffer_write(config, &ctx, &src, sizeof(src));
13 #define tp_memcpy(dest, src, len) \
14 lib_ring_buffer_align_ctx(config, &ctx, sizeof(*(src))); \
15 lib_ring_buffer_write(config, &ctx, &src, len);
19 #define tp_strcpy(dest, src) __assign_str(dest, src)
22 * Stage 1 of the trace events.
24 * Create event field type metadata section.
28 * DECLARE_EVENT_CLASS can be used to add a generic function
29 * handlers for events. That is, if all events have the same
30 * parameters and just have distinct trace points.
31 * Each tracepoint can be defined with DEFINE_EVENT and that
32 * will map the DECLARE_EVENT_CLASS to the tracepoint.
34 * TRACE_EVENT is a one to one mapping between tracepoint and template.
37 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
38 DECLARE_EVENT_CLASS(name, \
44 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
46 /* Named field types must be defined in lttng-types.h */
48 /* TODO turn into a structure definition ? */
51 #define __field(_type, _item) #_type " " #_item ";\n"
54 #define __field_ext(_type, _item, _filter_type) #_type " " #_item ";\n"
57 #define __array(_type, _item, _len) \
58 "type { parent = array; length = " #_len "; elem_type = " #_type "; } " #_item";\n"
60 #undef __dynamic_array
61 #define __dynamic_array(_type, _item, _len) \
62 "type { parent = sequence; length_type = u32; elem_type = " #_type "; } " #_item ";\n"
65 #define __string(_item, _src) \
66 "type { parent = string; encoding = UTF8; } " #_item ";\n"
69 #define TP_PROTO(args...)
72 #define TP_ARGS(args...)
74 #undef TP_STRUCT__entry
75 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
78 #define TP_fast_assign(args...)
81 #define TP_printk(args...)
83 #undef DECLARE_EVENT_CLASS
84 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
88 #define DEFINE_EVENT(template, name, proto, args)
90 #undef DEFINE_EVENT_PRINT
91 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
92 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
94 /* Callbacks are meaningless to LTTng. */
96 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
97 assign, print, reg, unreg) \
98 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
99 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
101 #undef DEFINE_TRACE_EVENT_METADATA
102 #define DEFINE_TRACE_EVENT_METADATA \
103 const char trace_event_metadata_##TRACE_SYSTEM[]
105 //static DEFINE_TRACE_EVENT_METADATA =
106 static const char blah
[] =
107 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
113 * Stage 2 of the trace events.
115 * Create static inline function that calculates event size.
120 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
123 * Stage 3 of the trace events.
125 * Create the probe function : call even size calculation and write event data
131 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
136 #include <linux/ftrace_event.h>
139 * DECLARE_EVENT_CLASS can be used to add a generic function
140 * handlers for events. That is, if all events have the same
141 * parameters and just have distinct trace points.
142 * Each tracepoint can be defined with DEFINE_EVENT and that
143 * will map the DECLARE_EVENT_CLASS to the tracepoint.
145 * TRACE_EVENT is a one to one mapping between tracepoint and template.
148 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
149 DECLARE_EVENT_CLASS(name, \
155 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
159 #define __field(type, item) type item;
162 #define __field_ext(type, item, filter_type) type item;
165 #define __array(type, item, len) type item[len];
167 #undef __dynamic_array
168 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
171 #define __string(item, src) __dynamic_array(char, item, -1)
173 #undef TP_STRUCT__entry
174 #define TP_STRUCT__entry(args...) args
176 #undef DECLARE_EVENT_CLASS
177 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
178 struct ftrace_raw_##name { \
179 struct trace_entry ent; \
184 static struct ftrace_event_class event_class_##name;
187 #define DEFINE_EVENT(template, name, proto, args) \
188 static struct ftrace_event_call __used \
189 __attribute__((__aligned__(4))) event_##name
191 #undef DEFINE_EVENT_PRINT
192 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
193 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
195 /* Callbacks are meaningless to ftrace. */
196 #undef TRACE_EVENT_FN
197 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
198 assign, print, reg, unreg) \
199 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
200 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
202 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
206 * Stage 2 of the trace events.
208 * Create static inline function that calculates event size.
212 #define __field(type, item)
215 #define __field_ext(type, item, filter_type)
218 #define __array(type, item, len)
220 #undef __dynamic_array
221 #define __dynamic_array(type, item, len) u32 item;
224 #define __string(item, src) __dynamic_array(char, item, -1)
226 #undef DECLARE_EVENT_CLASS
227 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
228 struct ftrace_data_offsets_##call { \
233 #define DEFINE_EVENT(template, name, proto, args)
235 #undef DEFINE_EVENT_PRINT
236 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
237 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
239 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
242 * Stage 3 of the trace events.
244 * Create the probe function : call even size calculation and write event data
249 #define __entry field
252 #define TP_printk(fmt, args...) fmt "\n", args
254 #undef __get_dynamic_array
255 #define __get_dynamic_array(field) \
256 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
259 #define __get_str(field) (char *)__get_dynamic_array(field)
262 #define __print_flags(flag, delim, flag_array...) \
264 static const struct trace_print_flags __flags[] = \
265 { flag_array, { -1, NULL }}; \
266 ftrace_print_flags_seq(p, delim, flag, __flags); \
269 #undef __print_symbolic
270 #define __print_symbolic(value, symbol_array...) \
272 static const struct trace_print_flags symbols[] = \
273 { symbol_array, { -1, NULL }}; \
274 ftrace_print_symbols_seq(p, value, symbols); \
278 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
280 #undef DECLARE_EVENT_CLASS
281 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
282 static notrace enum print_line_t \
283 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
284 struct trace_event *trace_event) \
286 struct ftrace_event_call *event; \
287 struct trace_seq *s = &iter->seq; \
288 struct ftrace_raw_##call *field; \
289 struct trace_entry *entry; \
290 struct trace_seq *p = &iter->tmp_seq; \
293 event = container_of(trace_event, struct ftrace_event_call, \
298 if (entry->type != event->event.type) { \
300 return TRACE_TYPE_UNHANDLED; \
303 field = (typeof(field))entry; \
306 ret = trace_seq_printf(s, "%s: ", event->name); \
308 ret = trace_seq_printf(s, print); \
310 return TRACE_TYPE_PARTIAL_LINE; \
312 return TRACE_TYPE_HANDLED; \
314 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
315 .trace = ftrace_raw_output_##call, \
318 #undef DEFINE_EVENT_PRINT
319 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
320 static notrace enum print_line_t \
321 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
322 struct trace_event *event) \
324 struct trace_seq *s = &iter->seq; \
325 struct ftrace_raw_##template *field; \
326 struct trace_entry *entry; \
327 struct trace_seq *p = &iter->tmp_seq; \
332 if (entry->type != event_##call.event.type) { \
334 return TRACE_TYPE_UNHANDLED; \
337 field = (typeof(field))entry; \
340 ret = trace_seq_printf(s, "%s: ", #call); \
342 ret = trace_seq_printf(s, print); \
344 return TRACE_TYPE_PARTIAL_LINE; \
346 return TRACE_TYPE_HANDLED; \
348 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
349 .trace = ftrace_raw_output_##call, \
352 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
355 #define __field_ext(type, item, filter_type) \
356 ret = trace_define_field(event_call, #type, #item, \
357 offsetof(typeof(field), item), \
358 sizeof(field.item), \
359 is_signed_type(type), filter_type); \
364 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
367 #define __array(type, item, len) \
368 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
369 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
370 offsetof(typeof(field), item), \
371 sizeof(field.item), \
372 is_signed_type(type), FILTER_OTHER); \
376 #undef __dynamic_array
377 #define __dynamic_array(type, item, len) \
378 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
379 offsetof(typeof(field), __data_loc_##item), \
380 sizeof(field.__data_loc_##item), \
381 is_signed_type(type), FILTER_OTHER);
384 #define __string(item, src) __dynamic_array(char, item, -1)
386 #undef DECLARE_EVENT_CLASS
387 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
389 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
391 struct ftrace_raw_##call field; \
400 #define DEFINE_EVENT(template, name, proto, args)
402 #undef DEFINE_EVENT_PRINT
403 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
404 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
406 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
409 * remember the offset of each array from the beginning of the event.
413 #define __entry entry
416 #define __field(type, item)
419 #define __field_ext(type, item, filter_type)
422 #define __array(type, item, len)
424 #undef __dynamic_array
425 #define __dynamic_array(type, item, len) \
426 __data_offsets->item = __data_size + \
427 offsetof(typeof(*entry), __data); \
428 __data_offsets->item |= (len * sizeof(type)) << 16; \
429 __data_size += (len) * sizeof(type);
432 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
434 #undef DECLARE_EVENT_CLASS
435 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
436 static inline notrace int ftrace_get_offsets_##call( \
437 struct ftrace_data_offsets_##call *__data_offsets, proto) \
439 int __data_size = 0; \
440 struct ftrace_raw_##call __maybe_unused *entry; \
444 return __data_size; \
448 #define DEFINE_EVENT(template, name, proto, args)
450 #undef DEFINE_EVENT_PRINT
451 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
452 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
454 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
457 * Stage 4 of the trace events.
459 * Override the macros in <trace/trace_events.h> to include the following:
461 * For those macros defined with TRACE_EVENT:
463 * static struct ftrace_event_call event_<call>;
465 * static void ftrace_raw_event_<call>(void *__data, proto)
467 * struct ftrace_event_call *event_call = __data;
468 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
469 * struct ring_buffer_event *event;
470 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
471 * struct ring_buffer *buffer;
472 * unsigned long irq_flags;
476 * local_save_flags(irq_flags);
477 * pc = preempt_count();
479 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
481 * event = trace_current_buffer_lock_reserve(&buffer,
482 * event_<call>->event.type,
483 * sizeof(*entry) + __data_size,
487 * entry = ring_buffer_event_data(event);
489 * { <assign>; } <-- Here we assign the entries by the __field and
492 * if (!filter_current_check_discard(buffer, event_call, entry, event))
493 * trace_current_buffer_unlock_commit(buffer,
494 * event, irq_flags, pc);
497 * static struct trace_event ftrace_event_type_<call> = {
498 * .trace = ftrace_raw_output_<call>, <-- stage 2
501 * static const char print_fmt_<call>[] = <TP_printk>;
503 * static struct ftrace_event_class __used event_class_<template> = {
504 * .system = "<system>",
505 * .define_fields = ftrace_define_fields_<call>,
506 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
507 * .raw_init = trace_event_raw_init,
508 * .probe = ftrace_raw_event_##call,
509 * .reg = ftrace_event_reg,
512 * static struct ftrace_event_call __used
513 * __attribute__((__aligned__(4)))
514 * __attribute__((section("_ftrace_events"))) event_<call> = {
516 * .class = event_class_<template>,
517 * .event = &ftrace_event_type_<call>,
518 * .print_fmt = print_fmt_<call>,
523 #ifdef CONFIG_PERF_EVENTS
525 #define _TRACE_PERF_PROTO(call, proto) \
526 static notrace void \
527 perf_trace_##call(void *__data, proto);
529 #define _TRACE_PERF_INIT(call) \
530 .perf_probe = perf_trace_##call,
533 #define _TRACE_PERF_PROTO(call, proto)
534 #define _TRACE_PERF_INIT(call)
535 #endif /* CONFIG_PERF_EVENTS */
538 #define __entry entry
541 #define __field(type, item)
544 #define __array(type, item, len)
546 #undef __dynamic_array
547 #define __dynamic_array(type, item, len) \
548 __entry->__data_loc_##item = __data_offsets.item;
551 #define __string(item, src) __dynamic_array(char, item, -1) \
554 #define __assign_str(dst, src) \
555 strcpy(__get_str(dst), src);
557 #undef TP_fast_assign
558 #define TP_fast_assign(args...) args
560 #undef TP_perf_assign
561 #define TP_perf_assign(args...)
563 #undef DECLARE_EVENT_CLASS
564 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
566 static notrace void \
567 ftrace_raw_event_##call(void *__data, proto) \
569 struct ftrace_event_call *event_call = __data; \
570 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
571 struct ring_buffer_event *event; \
572 struct ftrace_raw_##call *entry; \
573 struct ring_buffer *buffer; \
574 unsigned long irq_flags; \
578 local_save_flags(irq_flags); \
579 pc = preempt_count(); \
581 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
583 event = trace_current_buffer_lock_reserve(&buffer, \
584 event_call->event.type, \
585 sizeof(*entry) + __data_size, \
589 entry = ring_buffer_event_data(event); \
595 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
596 trace_nowake_buffer_unlock_commit(buffer, \
597 event, irq_flags, pc); \
600 * The ftrace_test_probe is compiled out, it is only here as a build time check
601 * to make sure that if the tracepoint handling changes, the ftrace probe will
602 * fail to compile unless it too is updated.
606 #define DEFINE_EVENT(template, call, proto, args) \
607 static inline void ftrace_test_probe_##call(void) \
609 check_trace_callback_type_##call(ftrace_raw_event_##template); \
612 #undef DEFINE_EVENT_PRINT
613 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
615 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
621 #undef __print_symbolic
622 #undef __get_dynamic_array
626 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
628 #undef DECLARE_EVENT_CLASS
629 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
630 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
631 static const char print_fmt_##call[] = print; \
632 static struct ftrace_event_class __used event_class_##call = { \
633 .system = __stringify(TRACE_SYSTEM), \
634 .define_fields = ftrace_define_fields_##call, \
635 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
636 .raw_init = trace_event_raw_init, \
637 .probe = ftrace_raw_event_##call, \
638 .reg = ftrace_event_reg, \
639 _TRACE_PERF_INIT(call) \
643 #define DEFINE_EVENT(template, call, proto, args) \
645 static struct ftrace_event_call __used \
646 __attribute__((__aligned__(4))) \
647 __attribute__((section("_ftrace_events"))) event_##call = { \
649 .class = &event_class_##template, \
650 .event.funcs = &ftrace_event_type_funcs_##template, \
651 .print_fmt = print_fmt_##template, \
654 #undef DEFINE_EVENT_PRINT
655 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
657 static const char print_fmt_##call[] = print; \
659 static struct ftrace_event_call __used \
660 __attribute__((__aligned__(4))) \
661 __attribute__((section("_ftrace_events"))) event_##call = { \
663 .class = &event_class_##template, \
664 .event.funcs = &ftrace_event_type_funcs_##call, \
665 .print_fmt = print_fmt_##call, \
668 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
671 * Define the insertion callback to perf events
673 * The job is very similar to ftrace_raw_event_<call> except that we don't
674 * insert in the ring buffer but in a perf counter.
676 * static void ftrace_perf_<call>(proto)
678 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
679 * struct ftrace_event_call *event_call = &event_<call>;
680 * extern void perf_tp_event(int, u64, u64, void *, int);
681 * struct ftrace_raw_##call *entry;
682 * struct perf_trace_buf *trace_buf;
683 * u64 __addr = 0, __count = 1;
684 * unsigned long irq_flags;
685 * struct trace_entry *ent;
691 * pc = preempt_count();
693 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
695 * // Below we want to get the aligned size by taking into account
696 * // the u32 field that will later store the buffer size
697 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
699 * __entry_size -= sizeof(u32);
701 * // Protect the non nmi buffer
702 * // This also protects the rcu read side
703 * local_irq_save(irq_flags);
704 * __cpu = smp_processor_id();
707 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
709 * trace_buf = rcu_dereference_sched(perf_trace_buf);
714 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
716 * // Avoid recursion from perf that could mess up the buffer
717 * if (trace_buf->recursion++)
718 * goto end_recursion;
720 * raw_data = trace_buf->buf;
722 * // Make recursion update visible before entering perf_tp_event
723 * // so that we protect from perf recursions.
727 * //zero dead bytes from alignment to avoid stack leak to userspace:
728 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
729 * entry = (struct ftrace_raw_<call> *)raw_data;
731 * tracing_generic_entry_update(ent, irq_flags, pc);
732 * ent->type = event_call->id;
734 * <tstruct> <- do some jobs with dynamic arrays
736 * <assign> <- affect our values
738 * perf_tp_event(event_call->id, __addr, __count, entry,
739 * __entry_size); <- submit them to perf counter
744 #ifdef CONFIG_PERF_EVENTS
747 #define __entry entry
749 #undef __get_dynamic_array
750 #define __get_dynamic_array(field) \
751 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
754 #define __get_str(field) (char *)__get_dynamic_array(field)
757 #define __perf_addr(a) __addr = (a)
760 #define __perf_count(c) __count = (c)
762 #undef DECLARE_EVENT_CLASS
763 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
764 static notrace void \
765 perf_trace_##call(void *__data, proto) \
767 struct ftrace_event_call *event_call = __data; \
768 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
769 struct ftrace_raw_##call *entry; \
770 struct pt_regs __regs; \
771 u64 __addr = 0, __count = 1; \
772 struct hlist_head *head; \
777 perf_fetch_caller_regs(&__regs); \
779 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
780 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
782 __entry_size -= sizeof(u32); \
784 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
785 "profile buffer not large enough")) \
788 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
789 __entry_size, event_call->event.type, &__regs, &rctx); \
797 head = this_cpu_ptr(event_call->perf_events); \
798 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
799 __count, &__regs, head); \
803 * This part is compiled out, it is only here as a build time check
804 * to make sure that if the tracepoint handling changes, the
805 * perf probe will fail to compile unless it too is updated.
808 #define DEFINE_EVENT(template, call, proto, args) \
809 static inline void perf_test_probe_##call(void) \
811 check_trace_callback_type_##call(perf_trace_##template); \
815 #undef DEFINE_EVENT_PRINT
816 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
817 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
819 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
820 #endif /* CONFIG_PERF_EVENTS */
822 #undef _TRACE_PROFILE_INIT
This page took 0.046937 seconds and 4 git commands to generate.