2 #include <lttng-types.h>
3 #include <linux/debugfs.h>
4 #include "../ltt-tracer-core.h"
8 /* keep for a later stage (copy stage) */
10 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
14 #define tp_assign(dest, src) \
15 lib_ring_buffer_align_ctx(config, &ctx, sizeof(src)); \
16 lib_ring_buffer_write(config, &ctx, &src, sizeof(src));
19 #define tp_memcpy(dest, src, len) \
20 lib_ring_buffer_align_ctx(config, &ctx, sizeof(*(src))); \
21 lib_ring_buffer_write(config, &ctx, &src, len);
25 #define tp_strcpy(dest, src) __assign_str(dest, src);
29 struct lttng_event_field
{
31 const struct lttng_type type
;
34 struct lttng_event_desc
{
35 const struct lttng_event_field
*fields
;
37 unsigned int nr_fields
;
41 * Macro declarations used for all stages.
45 * DECLARE_EVENT_CLASS can be used to add a generic function
46 * handlers for events. That is, if all events have the same
47 * parameters and just have distinct trace points.
48 * Each tracepoint can be defined with DEFINE_EVENT and that
49 * will map the DECLARE_EVENT_CLASS to the tracepoint.
51 * TRACE_EVENT is a one to one mapping between tracepoint and template.
55 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
56 DECLARE_EVENT_CLASS(name, \
62 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
64 #undef DEFINE_EVENT_PRINT
65 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
66 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
68 /* Callbacks are meaningless to LTTng. */
70 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
71 assign, print, reg, unreg) \
72 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
73 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
76 * Stage 1 of the trace events.
78 * Create event field type metadata section.
79 * Each event produce an array of fields.
82 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
84 /* Named field types must be defined in lttng-types.h */
87 #define __field(_type, _item) \
88 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
91 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
94 #define __array(_type, _item, _length) \
98 .atype = atype_array, \
100 .u.array.elem_type = #_type, \
101 .u.array.length = _length, \
105 #undef __dynamic_array
106 #define __dynamic_array(_type, _item, _length) \
110 .atype = atype_sequence, \
112 .u.sequence.elem_type = #_type, \
113 .u.sequence.length_type = "u32", \
118 #define __string(_item, _src) \
122 .atype = atype_string, \
124 .u.string.encoding = lttng_encode_UTF8, \
128 #undef TP_STRUCT__entry
129 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
131 #undef DECLARE_EVENT_CLASS
132 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
133 static const struct lttng_event_field __event_fields___##_name[] = { \
137 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
140 * Stage 2 of the trace events.
142 * Create an array of events.
145 /* Named field types must be defined in lttng-types.h */
147 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
149 #undef DECLARE_EVENT_CLASS
150 #define DECLARE_EVENT_CLASS(_name, proto, args, tstruct, assign, print) \
152 .fields = __event_fields___##_name, \
154 .nr_fields = ARRAY_SIZE(__event_fields___##_name), \
157 #define TP_ID1(_token, _system) _token##_system
158 #define TP_ID(_token, _system) TP_ID1(_token, _system)
160 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
161 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
168 * Stage 3 of the trace events.
170 * Create seq file metadata output.
173 #define TP_ID1(_token, _system) _token##_system
174 #define TP_ID(_token, _system) TP_ID1(_token, _system)
175 #define module_init_eval1(_token, _system) module_init(_token##_system)
176 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
177 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
178 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
180 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
183 const struct lttng_event_desc
*desc
=
184 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
186 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
187 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
189 return (void *) desc
;
192 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
193 void *p
, loff_t
*ppos
)
195 const struct lttng_event_desc
*desc
=
196 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
198 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
199 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
201 return (void *) desc
;
204 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
209 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
212 const struct lttng_event_desc
*desc
= p
;
215 seq_printf(m
, "event {\n"
218 "\tstream = UNKNOWN;\n"
221 for (i
= 0; i
< desc
->nr_fields
; i
++) {
222 if (desc
->fields
[i
].type
.name
) /* Named type */
223 seq_printf(m
, "\t\t%s",
224 desc
->fields
[i
].type
.name
);
225 else /* Nameless type */
226 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
227 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
229 seq_printf(m
, "\t};\n");
230 seq_printf(m
, "};\n");
235 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
236 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
237 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
238 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
239 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
243 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
245 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
249 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
250 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
253 .release
= seq_release_private
,
256 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
258 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
262 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
263 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
265 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
266 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
267 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
268 printk(KERN_ERR
"Error creating LTTng type export file\n");
276 module_init_eval(__lttng_types_init__
, TRACE_SYSTEM
);
278 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
280 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
283 module_exit_eval(__lttng_types_exit__
, TRACE_SYSTEM
);
285 #undef module_init_eval
286 #undef module_exit_eval
292 * Stage 4 of the trace events.
294 * Create static inline function that calculates event size.
297 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
299 /* Named field types must be defined in lttng-types.h */
302 #define __field(_type, _item) \
303 len += lib_ring_buffer_align(len, sizeof(_type)); \
304 len += sizeof(_type);
307 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
310 #define __array(_type, _item, _length) \
311 len += lib_ring_buffer_align(len, sizeof(_type)); \
312 len += sizeof(_type) * (_length);
314 #undef __dynamic_array
315 #define __dynamic_array(_type, _item, _length) \
316 len += lib_ring_buffer_align(len, sizeof(u32)); \
317 len += sizeof(u32); \
318 len += lib_ring_buffer_align(len, sizeof(_type)); \
319 len += sizeof(_type) * (_length);
322 #define __string(_item, _src) \
323 len += dynamic_len[dynamic_len_idx++] = strlen(_src) + 1;
325 #undef TP_STRUCT__entry
326 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
328 #undef DECLARE_EVENT_CLASS
329 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
330 static inline size_t __event_get_size__##name(size_t *dynamic_len) \
333 unsigned int dynamic_len_idx = 0; \
336 (void) dynamic_len_idx; /* don't warn if unused */ \
341 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
347 * Stage 4 of the trace events.
349 * Create the probe function : call even size calculation and write event data
355 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
360 #include <linux/ftrace_event.h>
363 * DECLARE_EVENT_CLASS can be used to add a generic function
364 * handlers for events. That is, if all events have the same
365 * parameters and just have distinct trace points.
366 * Each tracepoint can be defined with DEFINE_EVENT and that
367 * will map the DECLARE_EVENT_CLASS to the tracepoint.
369 * TRACE_EVENT is a one to one mapping between tracepoint and template.
372 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
373 DECLARE_EVENT_CLASS(name, \
379 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
383 #define __field(type, item) type item;
386 #define __field_ext(type, item, filter_type) type item;
389 #define __array(type, item, len) type item[len];
391 #undef __dynamic_array
392 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
395 #define __string(item, src) __dynamic_array(char, item, -1)
397 #undef TP_STRUCT__entry
398 #define TP_STRUCT__entry(args...) args
400 #undef DECLARE_EVENT_CLASS
401 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
402 struct ftrace_raw_##name { \
403 struct trace_entry ent; \
408 static struct ftrace_event_class event_class_##name;
411 #define DEFINE_EVENT(template, name, proto, args) \
412 static struct ftrace_event_call __used \
413 __attribute__((__aligned__(4))) event_##name
415 #undef DEFINE_EVENT_PRINT
416 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
417 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
419 /* Callbacks are meaningless to ftrace. */
420 #undef TRACE_EVENT_FN
421 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
422 assign, print, reg, unreg) \
423 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
424 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
426 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
430 * Stage 2 of the trace events.
432 * Create static inline function that calculates event size.
436 #define __field(type, item)
439 #define __field_ext(type, item, filter_type)
442 #define __array(type, item, len)
444 #undef __dynamic_array
445 #define __dynamic_array(type, item, len) u32 item;
448 #define __string(item, src) __dynamic_array(char, item, -1)
450 #undef DECLARE_EVENT_CLASS
451 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
452 struct ftrace_data_offsets_##call { \
457 #define DEFINE_EVENT(template, name, proto, args)
459 #undef DEFINE_EVENT_PRINT
460 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
461 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
463 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
466 * Stage 3 of the trace events.
468 * Create the probe function : call even size calculation and write event data
473 #define __entry field
476 #define TP_printk(fmt, args...) fmt "\n", args
478 #undef __get_dynamic_array
479 #define __get_dynamic_array(field) \
480 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
483 #define __get_str(field) (char *)__get_dynamic_array(field)
486 #define __print_flags(flag, delim, flag_array...) \
488 static const struct trace_print_flags __flags[] = \
489 { flag_array, { -1, NULL }}; \
490 ftrace_print_flags_seq(p, delim, flag, __flags); \
493 #undef __print_symbolic
494 #define __print_symbolic(value, symbol_array...) \
496 static const struct trace_print_flags symbols[] = \
497 { symbol_array, { -1, NULL }}; \
498 ftrace_print_symbols_seq(p, value, symbols); \
502 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
504 #undef DECLARE_EVENT_CLASS
505 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
506 static notrace enum print_line_t \
507 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
508 struct trace_event *trace_event) \
510 struct ftrace_event_call *event; \
511 struct trace_seq *s = &iter->seq; \
512 struct ftrace_raw_##call *field; \
513 struct trace_entry *entry; \
514 struct trace_seq *p = &iter->tmp_seq; \
517 event = container_of(trace_event, struct ftrace_event_call, \
522 if (entry->type != event->event.type) { \
524 return TRACE_TYPE_UNHANDLED; \
527 field = (typeof(field))entry; \
530 ret = trace_seq_printf(s, "%s: ", event->name); \
532 ret = trace_seq_printf(s, print); \
534 return TRACE_TYPE_PARTIAL_LINE; \
536 return TRACE_TYPE_HANDLED; \
538 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
539 .trace = ftrace_raw_output_##call, \
542 #undef DEFINE_EVENT_PRINT
543 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
544 static notrace enum print_line_t \
545 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
546 struct trace_event *event) \
548 struct trace_seq *s = &iter->seq; \
549 struct ftrace_raw_##template *field; \
550 struct trace_entry *entry; \
551 struct trace_seq *p = &iter->tmp_seq; \
556 if (entry->type != event_##call.event.type) { \
558 return TRACE_TYPE_UNHANDLED; \
561 field = (typeof(field))entry; \
564 ret = trace_seq_printf(s, "%s: ", #call); \
566 ret = trace_seq_printf(s, print); \
568 return TRACE_TYPE_PARTIAL_LINE; \
570 return TRACE_TYPE_HANDLED; \
572 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
573 .trace = ftrace_raw_output_##call, \
576 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
579 #define __field_ext(type, item, filter_type) \
580 ret = trace_define_field(event_call, #type, #item, \
581 offsetof(typeof(field), item), \
582 sizeof(field.item), \
583 is_signed_type(type), filter_type); \
588 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
591 #define __array(type, item, len) \
592 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
593 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
594 offsetof(typeof(field), item), \
595 sizeof(field.item), \
596 is_signed_type(type), FILTER_OTHER); \
600 #undef __dynamic_array
601 #define __dynamic_array(type, item, len) \
602 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
603 offsetof(typeof(field), __data_loc_##item), \
604 sizeof(field.__data_loc_##item), \
605 is_signed_type(type), FILTER_OTHER);
608 #define __string(item, src) __dynamic_array(char, item, -1)
610 #undef DECLARE_EVENT_CLASS
611 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
613 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
615 struct ftrace_raw_##call field; \
624 #define DEFINE_EVENT(template, name, proto, args)
626 #undef DEFINE_EVENT_PRINT
627 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
628 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
630 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
633 * remember the offset of each array from the beginning of the event.
637 #define __entry entry
640 #define __field(type, item)
643 #define __field_ext(type, item, filter_type)
646 #define __array(type, item, len)
648 #undef __dynamic_array
649 #define __dynamic_array(type, item, len) \
650 __data_offsets->item = __data_size + \
651 offsetof(typeof(*entry), __data); \
652 __data_offsets->item |= (len * sizeof(type)) << 16; \
653 __data_size += (len) * sizeof(type);
656 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
658 #undef DECLARE_EVENT_CLASS
659 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
660 static inline notrace int ftrace_get_offsets_##call( \
661 struct ftrace_data_offsets_##call *__data_offsets, proto) \
663 int __data_size = 0; \
664 struct ftrace_raw_##call __maybe_unused *entry; \
668 return __data_size; \
672 #define DEFINE_EVENT(template, name, proto, args)
674 #undef DEFINE_EVENT_PRINT
675 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
676 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
678 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
681 * Stage 4 of the trace events.
683 * Override the macros in <trace/trace_events.h> to include the following:
685 * For those macros defined with TRACE_EVENT:
687 * static struct ftrace_event_call event_<call>;
689 * static void ftrace_raw_event_<call>(void *__data, proto)
691 * struct ftrace_event_call *event_call = __data;
692 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
693 * struct ring_buffer_event *event;
694 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
695 * struct ring_buffer *buffer;
696 * unsigned long irq_flags;
700 * local_save_flags(irq_flags);
701 * pc = preempt_count();
703 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
705 * event = trace_current_buffer_lock_reserve(&buffer,
706 * event_<call>->event.type,
707 * sizeof(*entry) + __data_size,
711 * entry = ring_buffer_event_data(event);
713 * { <assign>; } <-- Here we assign the entries by the __field and
716 * if (!filter_current_check_discard(buffer, event_call, entry, event))
717 * trace_current_buffer_unlock_commit(buffer,
718 * event, irq_flags, pc);
721 * static struct trace_event ftrace_event_type_<call> = {
722 * .trace = ftrace_raw_output_<call>, <-- stage 2
725 * static const char print_fmt_<call>[] = <TP_printk>;
727 * static struct ftrace_event_class __used event_class_<template> = {
728 * .system = "<system>",
729 * .define_fields = ftrace_define_fields_<call>,
730 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
731 * .raw_init = trace_event_raw_init,
732 * .probe = ftrace_raw_event_##call,
733 * .reg = ftrace_event_reg,
736 * static struct ftrace_event_call __used
737 * __attribute__((__aligned__(4)))
738 * __attribute__((section("_ftrace_events"))) event_<call> = {
740 * .class = event_class_<template>,
741 * .event = &ftrace_event_type_<call>,
742 * .print_fmt = print_fmt_<call>,
747 #ifdef CONFIG_PERF_EVENTS
749 #define _TRACE_PERF_PROTO(call, proto) \
750 static notrace void \
751 perf_trace_##call(void *__data, proto);
753 #define _TRACE_PERF_INIT(call) \
754 .perf_probe = perf_trace_##call,
757 #define _TRACE_PERF_PROTO(call, proto)
758 #define _TRACE_PERF_INIT(call)
759 #endif /* CONFIG_PERF_EVENTS */
762 #define __entry entry
765 #define __field(type, item)
768 #define __array(type, item, len)
770 #undef __dynamic_array
771 #define __dynamic_array(type, item, len) \
772 __entry->__data_loc_##item = __data_offsets.item;
775 #define __string(item, src) __dynamic_array(char, item, -1) \
778 #define __assign_str(dst, src) \
779 strcpy(__get_str(dst), src);
781 #undef TP_fast_assign
782 #define TP_fast_assign(args...) args
784 #undef TP_perf_assign
785 #define TP_perf_assign(args...)
787 #undef DECLARE_EVENT_CLASS
788 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
790 static notrace void \
791 ftrace_raw_event_##call(void *__data, proto) \
793 struct ftrace_event_call *event_call = __data; \
794 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
795 struct ring_buffer_event *event; \
796 struct ftrace_raw_##call *entry; \
797 struct ring_buffer *buffer; \
798 unsigned long irq_flags; \
802 local_save_flags(irq_flags); \
803 pc = preempt_count(); \
805 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
807 event = trace_current_buffer_lock_reserve(&buffer, \
808 event_call->event.type, \
809 sizeof(*entry) + __data_size, \
813 entry = ring_buffer_event_data(event); \
819 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
820 trace_nowake_buffer_unlock_commit(buffer, \
821 event, irq_flags, pc); \
824 * The ftrace_test_probe is compiled out, it is only here as a build time check
825 * to make sure that if the tracepoint handling changes, the ftrace probe will
826 * fail to compile unless it too is updated.
830 #define DEFINE_EVENT(template, call, proto, args) \
831 static inline void ftrace_test_probe_##call(void) \
833 check_trace_callback_type_##call(ftrace_raw_event_##template); \
836 #undef DEFINE_EVENT_PRINT
837 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
839 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
845 #undef __print_symbolic
846 #undef __get_dynamic_array
850 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
852 #undef DECLARE_EVENT_CLASS
853 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
854 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
855 static const char print_fmt_##call[] = print; \
856 static struct ftrace_event_class __used event_class_##call = { \
857 .system = __stringify(TRACE_SYSTEM), \
858 .define_fields = ftrace_define_fields_##call, \
859 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
860 .raw_init = trace_event_raw_init, \
861 .probe = ftrace_raw_event_##call, \
862 .reg = ftrace_event_reg, \
863 _TRACE_PERF_INIT(call) \
867 #define DEFINE_EVENT(template, call, proto, args) \
869 static struct ftrace_event_call __used \
870 __attribute__((__aligned__(4))) \
871 __attribute__((section("_ftrace_events"))) event_##call = { \
873 .class = &event_class_##template, \
874 .event.funcs = &ftrace_event_type_funcs_##template, \
875 .print_fmt = print_fmt_##template, \
878 #undef DEFINE_EVENT_PRINT
879 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
881 static const char print_fmt_##call[] = print; \
883 static struct ftrace_event_call __used \
884 __attribute__((__aligned__(4))) \
885 __attribute__((section("_ftrace_events"))) event_##call = { \
887 .class = &event_class_##template, \
888 .event.funcs = &ftrace_event_type_funcs_##call, \
889 .print_fmt = print_fmt_##call, \
892 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
895 * Define the insertion callback to perf events
897 * The job is very similar to ftrace_raw_event_<call> except that we don't
898 * insert in the ring buffer but in a perf counter.
900 * static void ftrace_perf_<call>(proto)
902 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
903 * struct ftrace_event_call *event_call = &event_<call>;
904 * extern void perf_tp_event(int, u64, u64, void *, int);
905 * struct ftrace_raw_##call *entry;
906 * struct perf_trace_buf *trace_buf;
907 * u64 __addr = 0, __count = 1;
908 * unsigned long irq_flags;
909 * struct trace_entry *ent;
915 * pc = preempt_count();
917 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
919 * // Below we want to get the aligned size by taking into account
920 * // the u32 field that will later store the buffer size
921 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
923 * __entry_size -= sizeof(u32);
925 * // Protect the non nmi buffer
926 * // This also protects the rcu read side
927 * local_irq_save(irq_flags);
928 * __cpu = smp_processor_id();
931 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
933 * trace_buf = rcu_dereference_sched(perf_trace_buf);
938 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
940 * // Avoid recursion from perf that could mess up the buffer
941 * if (trace_buf->recursion++)
942 * goto end_recursion;
944 * raw_data = trace_buf->buf;
946 * // Make recursion update visible before entering perf_tp_event
947 * // so that we protect from perf recursions.
951 * //zero dead bytes from alignment to avoid stack leak to userspace:
952 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
953 * entry = (struct ftrace_raw_<call> *)raw_data;
955 * tracing_generic_entry_update(ent, irq_flags, pc);
956 * ent->type = event_call->id;
958 * <tstruct> <- do some jobs with dynamic arrays
960 * <assign> <- affect our values
962 * perf_tp_event(event_call->id, __addr, __count, entry,
963 * __entry_size); <- submit them to perf counter
968 #ifdef CONFIG_PERF_EVENTS
971 #define __entry entry
973 #undef __get_dynamic_array
974 #define __get_dynamic_array(field) \
975 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
978 #define __get_str(field) (char *)__get_dynamic_array(field)
981 #define __perf_addr(a) __addr = (a)
984 #define __perf_count(c) __count = (c)
986 #undef DECLARE_EVENT_CLASS
987 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
988 static notrace void \
989 perf_trace_##call(void *__data, proto) \
991 struct ftrace_event_call *event_call = __data; \
992 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
993 struct ftrace_raw_##call *entry; \
994 struct pt_regs __regs; \
995 u64 __addr = 0, __count = 1; \
996 struct hlist_head *head; \
1001 perf_fetch_caller_regs(&__regs); \
1003 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1004 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
1006 __entry_size -= sizeof(u32); \
1008 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
1009 "profile buffer not large enough")) \
1012 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
1013 __entry_size, event_call->event.type, &__regs, &rctx); \
1021 head = this_cpu_ptr(event_call->perf_events); \
1022 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
1023 __count, &__regs, head); \
1027 * This part is compiled out, it is only here as a build time check
1028 * to make sure that if the tracepoint handling changes, the
1029 * perf probe will fail to compile unless it too is updated.
1032 #define DEFINE_EVENT(template, call, proto, args) \
1033 static inline void perf_test_probe_##call(void) \
1035 check_trace_callback_type_##call(perf_trace_##template); \
1039 #undef DEFINE_EVENT_PRINT
1040 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
1041 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
1043 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1044 #endif /* CONFIG_PERF_EVENTS */
1046 #undef _TRACE_PROFILE_INIT
This page took 0.051602 seconds and 6 git commands to generate.