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);
23 /* TODO: tp_memcpy_dyn */
27 #define tp_strcpy(dest, src) __assign_str(dest, src);
31 /* TODO : deal with DEFINE_EVENT vs event class */
33 struct lttng_event_field
{
35 const struct lttng_type type
;
38 struct lttng_event_desc
{
39 const struct lttng_event_field
*fields
;
41 unsigned int nr_fields
;
45 * Macro declarations used for all stages.
49 * DECLARE_EVENT_CLASS can be used to add a generic function
50 * handlers for events. That is, if all events have the same
51 * parameters and just have distinct trace points.
52 * Each tracepoint can be defined with DEFINE_EVENT and that
53 * will map the DECLARE_EVENT_CLASS to the tracepoint.
55 * TRACE_EVENT is a one to one mapping between tracepoint and template.
59 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
60 DECLARE_EVENT_CLASS(name, \
66 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
68 #undef DEFINE_EVENT_PRINT
69 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
70 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
72 /* Callbacks are meaningless to LTTng. */
74 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
75 assign, print, reg, unreg) \
76 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
77 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
80 * Stage 1 of the trace events.
82 * Create event field type metadata section.
83 * Each event produce an array of fields.
86 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
88 /* Named field types must be defined in lttng-types.h */
91 #define __field(_type, _item) \
92 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
95 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
98 #define __array(_type, _item, _length) \
102 .atype = atype_array, \
104 .u.array.elem_type = #_type, \
105 .u.array.length = _length, \
109 #undef __dynamic_array
110 #define __dynamic_array(_type, _item, _length) \
114 .atype = atype_sequence, \
116 .u.sequence.elem_type = #_type, \
117 .u.sequence.length_type = "u32", \
122 #define __string(_item, _src) \
126 .atype = atype_string, \
128 .u.string.encoding = lttng_encode_UTF8, \
132 #undef TP_STRUCT__entry
133 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
135 #undef DECLARE_EVENT_CLASS
136 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
137 static const struct lttng_event_field __event_fields___##_name[] = { \
141 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
144 * Stage 2 of the trace events.
146 * Create an array of events.
149 /* Named field types must be defined in lttng-types.h */
151 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
154 #define DEFINE_EVENT(_template, _name, _proto, _args) \
156 .fields = __event_fields___##_template, \
158 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
161 #define TP_ID1(_token, _system) _token##_system
162 #define TP_ID(_token, _system) TP_ID1(_token, _system)
164 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
165 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
172 * Stage 3 of the trace events.
174 * Create seq file metadata output.
177 #define TP_ID1(_token, _system) _token##_system
178 #define TP_ID(_token, _system) TP_ID1(_token, _system)
179 #define module_init_eval1(_token, _system) module_init(_token##_system)
180 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
181 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
182 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
184 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
187 const struct lttng_event_desc
*desc
=
188 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
190 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
191 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
193 return (void *) desc
;
196 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
197 void *p
, loff_t
*ppos
)
199 const struct lttng_event_desc
*desc
=
200 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
202 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
203 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
205 return (void *) desc
;
208 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
213 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
216 const struct lttng_event_desc
*desc
= p
;
219 seq_printf(m
, "event {\n"
222 "\tstream = UNKNOWN;\n"
225 for (i
= 0; i
< desc
->nr_fields
; i
++) {
226 if (desc
->fields
[i
].type
.name
) /* Named type */
227 seq_printf(m
, "\t\t%s",
228 desc
->fields
[i
].type
.name
);
229 else /* Nameless type */
230 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
231 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
233 seq_printf(m
, "\t};\n");
234 seq_printf(m
, "};\n");
239 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
240 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
241 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
242 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
243 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
247 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
249 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
253 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
254 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
257 .release
= seq_release_private
,
260 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
262 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
266 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
267 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
269 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
270 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
271 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
272 printk(KERN_ERR
"Error creating LTTng type export file\n");
280 module_init_eval(__lttng_types_init__
, TRACE_SYSTEM
);
282 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
284 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
287 module_exit_eval(__lttng_types_exit__
, TRACE_SYSTEM
);
289 #undef module_init_eval
290 #undef module_exit_eval
296 * Stage 4 of the trace events.
298 * Create static inline function that calculates event size.
301 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
303 /* Named field types must be defined in lttng-types.h */
306 #define __field(_type, _item) \
307 __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
308 __event_len += sizeof(_type);
311 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
314 #define __array(_type, _item, _length) \
315 __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
316 __event_len += sizeof(_type) * (_length);
318 #undef __dynamic_array
319 #define __dynamic_array(_type, _item, _length) \
320 __event_len += lib_ring_buffer_align(__event_len, sizeof(u32)); \
321 __event_len += sizeof(u32); \
322 __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
323 __event_len += sizeof(_type) * (_length);
326 #define __string(_item, _src) \
327 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
330 #define TP_PROTO(args...) args
332 #undef TP_STRUCT__entry
333 #define TP_STRUCT__entry(args...) args
335 #undef DECLARE_EVENT_CLASS
336 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
337 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
339 size_t __event_len = 0; \
340 unsigned int __dynamic_len_idx = 0; \
343 (void) __dynamic_len_idx; /* don't warn if unused */ \
345 return __event_len; \
348 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
354 * Stage 4 of the trace events.
356 * Create the probe function : call even size calculation and write event data
362 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
367 #include <linux/ftrace_event.h>
370 * DECLARE_EVENT_CLASS can be used to add a generic function
371 * handlers for events. That is, if all events have the same
372 * parameters and just have distinct trace points.
373 * Each tracepoint can be defined with DEFINE_EVENT and that
374 * will map the DECLARE_EVENT_CLASS to the tracepoint.
376 * TRACE_EVENT is a one to one mapping between tracepoint and template.
379 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
380 DECLARE_EVENT_CLASS(name, \
386 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
390 #define __field(type, item) type item;
393 #define __field_ext(type, item, filter_type) type item;
396 #define __array(type, item, len) type item[len];
398 #undef __dynamic_array
399 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
402 #define __string(item, src) __dynamic_array(char, item, -1)
404 #undef TP_STRUCT__entry
405 #define TP_STRUCT__entry(args...) args
407 #undef DECLARE_EVENT_CLASS
408 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
409 struct ftrace_raw_##name { \
410 struct trace_entry ent; \
415 static struct ftrace_event_class event_class_##name;
418 #define DEFINE_EVENT(template, name, proto, args) \
419 static struct ftrace_event_call __used \
420 __attribute__((__aligned__(4))) event_##name
422 #undef DEFINE_EVENT_PRINT
423 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
424 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
426 /* Callbacks are meaningless to ftrace. */
427 #undef TRACE_EVENT_FN
428 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
429 assign, print, reg, unreg) \
430 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
431 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
433 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
437 * Stage 2 of the trace events.
439 * Create static inline function that calculates event size.
443 #define __field(type, item)
446 #define __field_ext(type, item, filter_type)
449 #define __array(type, item, len)
451 #undef __dynamic_array
452 #define __dynamic_array(type, item, len) u32 item;
455 #define __string(item, src) __dynamic_array(char, item, -1)
457 #undef DECLARE_EVENT_CLASS
458 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
459 struct ftrace_data_offsets_##call { \
464 #define DEFINE_EVENT(template, name, proto, args)
466 #undef DEFINE_EVENT_PRINT
467 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
468 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
470 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
473 * Stage 3 of the trace events.
475 * Create the probe function : call even size calculation and write event data
480 #define __entry field
483 #define TP_printk(fmt, args...) fmt "\n", args
485 #undef __get_dynamic_array
486 #define __get_dynamic_array(field) \
487 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
490 #define __get_str(field) (char *)__get_dynamic_array(field)
493 #define __print_flags(flag, delim, flag_array...) \
495 static const struct trace_print_flags __flags[] = \
496 { flag_array, { -1, NULL }}; \
497 ftrace_print_flags_seq(p, delim, flag, __flags); \
500 #undef __print_symbolic
501 #define __print_symbolic(value, symbol_array...) \
503 static const struct trace_print_flags symbols[] = \
504 { symbol_array, { -1, NULL }}; \
505 ftrace_print_symbols_seq(p, value, symbols); \
509 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
511 #undef DECLARE_EVENT_CLASS
512 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
513 static notrace enum print_line_t \
514 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
515 struct trace_event *trace_event) \
517 struct ftrace_event_call *event; \
518 struct trace_seq *s = &iter->seq; \
519 struct ftrace_raw_##call *field; \
520 struct trace_entry *entry; \
521 struct trace_seq *p = &iter->tmp_seq; \
524 event = container_of(trace_event, struct ftrace_event_call, \
529 if (entry->type != event->event.type) { \
531 return TRACE_TYPE_UNHANDLED; \
534 field = (typeof(field))entry; \
537 ret = trace_seq_printf(s, "%s: ", event->name); \
539 ret = trace_seq_printf(s, print); \
541 return TRACE_TYPE_PARTIAL_LINE; \
543 return TRACE_TYPE_HANDLED; \
545 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
546 .trace = ftrace_raw_output_##call, \
549 #undef DEFINE_EVENT_PRINT
550 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
551 static notrace enum print_line_t \
552 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
553 struct trace_event *event) \
555 struct trace_seq *s = &iter->seq; \
556 struct ftrace_raw_##template *field; \
557 struct trace_entry *entry; \
558 struct trace_seq *p = &iter->tmp_seq; \
563 if (entry->type != event_##call.event.type) { \
565 return TRACE_TYPE_UNHANDLED; \
568 field = (typeof(field))entry; \
571 ret = trace_seq_printf(s, "%s: ", #call); \
573 ret = trace_seq_printf(s, print); \
575 return TRACE_TYPE_PARTIAL_LINE; \
577 return TRACE_TYPE_HANDLED; \
579 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
580 .trace = ftrace_raw_output_##call, \
583 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
586 #define __field_ext(type, item, filter_type) \
587 ret = trace_define_field(event_call, #type, #item, \
588 offsetof(typeof(field), item), \
589 sizeof(field.item), \
590 is_signed_type(type), filter_type); \
595 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
598 #define __array(type, item, len) \
599 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
600 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
601 offsetof(typeof(field), item), \
602 sizeof(field.item), \
603 is_signed_type(type), FILTER_OTHER); \
607 #undef __dynamic_array
608 #define __dynamic_array(type, item, len) \
609 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
610 offsetof(typeof(field), __data_loc_##item), \
611 sizeof(field.__data_loc_##item), \
612 is_signed_type(type), FILTER_OTHER);
615 #define __string(item, src) __dynamic_array(char, item, -1)
617 #undef DECLARE_EVENT_CLASS
618 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
620 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
622 struct ftrace_raw_##call field; \
631 #define DEFINE_EVENT(template, name, proto, args)
633 #undef DEFINE_EVENT_PRINT
634 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
635 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
637 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
640 * remember the offset of each array from the beginning of the event.
644 #define __entry entry
647 #define __field(type, item)
650 #define __field_ext(type, item, filter_type)
653 #define __array(type, item, len)
655 #undef __dynamic_array
656 #define __dynamic_array(type, item, len) \
657 __data_offsets->item = __data_size + \
658 offsetof(typeof(*entry), __data); \
659 __data_offsets->item |= (len * sizeof(type)) << 16; \
660 __data_size += (len) * sizeof(type);
663 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
665 #undef DECLARE_EVENT_CLASS
666 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
667 static inline notrace int ftrace_get_offsets_##call( \
668 struct ftrace_data_offsets_##call *__data_offsets, proto) \
670 int __data_size = 0; \
671 struct ftrace_raw_##call __maybe_unused *entry; \
675 return __data_size; \
679 #define DEFINE_EVENT(template, name, proto, args)
681 #undef DEFINE_EVENT_PRINT
682 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
683 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
685 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
688 * Stage 4 of the trace events.
690 * Override the macros in <trace/trace_events.h> to include the following:
692 * For those macros defined with TRACE_EVENT:
694 * static struct ftrace_event_call event_<call>;
696 * static void ftrace_raw_event_<call>(void *__data, proto)
698 * struct ftrace_event_call *event_call = __data;
699 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
700 * struct ring_buffer_event *event;
701 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
702 * struct ring_buffer *buffer;
703 * unsigned long irq_flags;
707 * local_save_flags(irq_flags);
708 * pc = preempt_count();
710 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
712 * event = trace_current_buffer_lock_reserve(&buffer,
713 * event_<call>->event.type,
714 * sizeof(*entry) + __data_size,
718 * entry = ring_buffer_event_data(event);
720 * { <assign>; } <-- Here we assign the entries by the __field and
723 * if (!filter_current_check_discard(buffer, event_call, entry, event))
724 * trace_current_buffer_unlock_commit(buffer,
725 * event, irq_flags, pc);
728 * static struct trace_event ftrace_event_type_<call> = {
729 * .trace = ftrace_raw_output_<call>, <-- stage 2
732 * static const char print_fmt_<call>[] = <TP_printk>;
734 * static struct ftrace_event_class __used event_class_<template> = {
735 * .system = "<system>",
736 * .define_fields = ftrace_define_fields_<call>,
737 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
738 * .raw_init = trace_event_raw_init,
739 * .probe = ftrace_raw_event_##call,
740 * .reg = ftrace_event_reg,
743 * static struct ftrace_event_call __used
744 * __attribute__((__aligned__(4)))
745 * __attribute__((section("_ftrace_events"))) event_<call> = {
747 * .class = event_class_<template>,
748 * .event = &ftrace_event_type_<call>,
749 * .print_fmt = print_fmt_<call>,
754 #ifdef CONFIG_PERF_EVENTS
756 #define _TRACE_PERF_PROTO(call, proto) \
757 static notrace void \
758 perf_trace_##call(void *__data, proto);
760 #define _TRACE_PERF_INIT(call) \
761 .perf_probe = perf_trace_##call,
764 #define _TRACE_PERF_PROTO(call, proto)
765 #define _TRACE_PERF_INIT(call)
766 #endif /* CONFIG_PERF_EVENTS */
769 #define __entry entry
772 #define __field(type, item)
775 #define __array(type, item, len)
777 #undef __dynamic_array
778 #define __dynamic_array(type, item, len) \
779 __entry->__data_loc_##item = __data_offsets.item;
782 #define __string(item, src) __dynamic_array(char, item, -1) \
785 #define __assign_str(dst, src) \
786 strcpy(__get_str(dst), src);
788 #undef TP_fast_assign
789 #define TP_fast_assign(args...) args
791 #undef TP_perf_assign
792 #define TP_perf_assign(args...)
794 #undef DECLARE_EVENT_CLASS
795 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
797 static notrace void \
798 ftrace_raw_event_##call(void *__data, proto) \
800 struct ftrace_event_call *event_call = __data; \
801 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
802 struct ring_buffer_event *event; \
803 struct ftrace_raw_##call *entry; \
804 struct ring_buffer *buffer; \
805 unsigned long irq_flags; \
809 local_save_flags(irq_flags); \
810 pc = preempt_count(); \
812 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
814 event = trace_current_buffer_lock_reserve(&buffer, \
815 event_call->event.type, \
816 sizeof(*entry) + __data_size, \
820 entry = ring_buffer_event_data(event); \
826 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
827 trace_nowake_buffer_unlock_commit(buffer, \
828 event, irq_flags, pc); \
831 * The ftrace_test_probe is compiled out, it is only here as a build time check
832 * to make sure that if the tracepoint handling changes, the ftrace probe will
833 * fail to compile unless it too is updated.
837 #define DEFINE_EVENT(template, call, proto, args) \
838 static inline void ftrace_test_probe_##call(void) \
840 check_trace_callback_type_##call(ftrace_raw_event_##template); \
843 #undef DEFINE_EVENT_PRINT
844 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
846 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
852 #undef __print_symbolic
853 #undef __get_dynamic_array
857 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
859 #undef DECLARE_EVENT_CLASS
860 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
861 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
862 static const char print_fmt_##call[] = print; \
863 static struct ftrace_event_class __used event_class_##call = { \
864 .system = __stringify(TRACE_SYSTEM), \
865 .define_fields = ftrace_define_fields_##call, \
866 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
867 .raw_init = trace_event_raw_init, \
868 .probe = ftrace_raw_event_##call, \
869 .reg = ftrace_event_reg, \
870 _TRACE_PERF_INIT(call) \
874 #define DEFINE_EVENT(template, call, proto, args) \
876 static struct ftrace_event_call __used \
877 __attribute__((__aligned__(4))) \
878 __attribute__((section("_ftrace_events"))) event_##call = { \
880 .class = &event_class_##template, \
881 .event.funcs = &ftrace_event_type_funcs_##template, \
882 .print_fmt = print_fmt_##template, \
885 #undef DEFINE_EVENT_PRINT
886 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
888 static const char print_fmt_##call[] = print; \
890 static struct ftrace_event_call __used \
891 __attribute__((__aligned__(4))) \
892 __attribute__((section("_ftrace_events"))) event_##call = { \
894 .class = &event_class_##template, \
895 .event.funcs = &ftrace_event_type_funcs_##call, \
896 .print_fmt = print_fmt_##call, \
899 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
902 * Define the insertion callback to perf events
904 * The job is very similar to ftrace_raw_event_<call> except that we don't
905 * insert in the ring buffer but in a perf counter.
907 * static void ftrace_perf_<call>(proto)
909 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
910 * struct ftrace_event_call *event_call = &event_<call>;
911 * extern void perf_tp_event(int, u64, u64, void *, int);
912 * struct ftrace_raw_##call *entry;
913 * struct perf_trace_buf *trace_buf;
914 * u64 __addr = 0, __count = 1;
915 * unsigned long irq_flags;
916 * struct trace_entry *ent;
922 * pc = preempt_count();
924 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
926 * // Below we want to get the aligned size by taking into account
927 * // the u32 field that will later store the buffer size
928 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
930 * __entry_size -= sizeof(u32);
932 * // Protect the non nmi buffer
933 * // This also protects the rcu read side
934 * local_irq_save(irq_flags);
935 * __cpu = smp_processor_id();
938 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
940 * trace_buf = rcu_dereference_sched(perf_trace_buf);
945 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
947 * // Avoid recursion from perf that could mess up the buffer
948 * if (trace_buf->recursion++)
949 * goto end_recursion;
951 * raw_data = trace_buf->buf;
953 * // Make recursion update visible before entering perf_tp_event
954 * // so that we protect from perf recursions.
958 * //zero dead bytes from alignment to avoid stack leak to userspace:
959 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
960 * entry = (struct ftrace_raw_<call> *)raw_data;
962 * tracing_generic_entry_update(ent, irq_flags, pc);
963 * ent->type = event_call->id;
965 * <tstruct> <- do some jobs with dynamic arrays
967 * <assign> <- affect our values
969 * perf_tp_event(event_call->id, __addr, __count, entry,
970 * __entry_size); <- submit them to perf counter
975 #ifdef CONFIG_PERF_EVENTS
978 #define __entry entry
980 #undef __get_dynamic_array
981 #define __get_dynamic_array(field) \
982 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
985 #define __get_str(field) (char *)__get_dynamic_array(field)
988 #define __perf_addr(a) __addr = (a)
991 #define __perf_count(c) __count = (c)
993 #undef DECLARE_EVENT_CLASS
994 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
995 static notrace void \
996 perf_trace_##call(void *__data, proto) \
998 struct ftrace_event_call *event_call = __data; \
999 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
1000 struct ftrace_raw_##call *entry; \
1001 struct pt_regs __regs; \
1002 u64 __addr = 0, __count = 1; \
1003 struct hlist_head *head; \
1008 perf_fetch_caller_regs(&__regs); \
1010 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1011 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
1013 __entry_size -= sizeof(u32); \
1015 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
1016 "profile buffer not large enough")) \
1019 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
1020 __entry_size, event_call->event.type, &__regs, &rctx); \
1028 head = this_cpu_ptr(event_call->perf_events); \
1029 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
1030 __count, &__regs, head); \
1034 * This part is compiled out, it is only here as a build time check
1035 * to make sure that if the tracepoint handling changes, the
1036 * perf probe will fail to compile unless it too is updated.
1039 #define DEFINE_EVENT(template, call, proto, args) \
1040 static inline void perf_test_probe_##call(void) \
1042 check_trace_callback_type_##call(perf_trace_##template); \
1046 #undef DEFINE_EVENT_PRINT
1047 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
1048 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
1050 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1051 #endif /* CONFIG_PERF_EVENTS */
1053 #undef _TRACE_PROFILE_INIT
This page took 0.072419 seconds and 4 git commands to generate.