c5eeac28cbf8aea5fba345dbabcc3c73195cd2e3
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 /* TODO : deal with DEFINE_EVENT vs event class */
31 struct lttng_event_field
{
33 const struct lttng_type type
;
36 struct lttng_event_desc
{
37 const struct lttng_event_field
*fields
;
39 unsigned int nr_fields
;
43 * Macro declarations used for all stages.
47 * DECLARE_EVENT_CLASS can be used to add a generic function
48 * handlers for events. That is, if all events have the same
49 * parameters and just have distinct trace points.
50 * Each tracepoint can be defined with DEFINE_EVENT and that
51 * will map the DECLARE_EVENT_CLASS to the tracepoint.
53 * TRACE_EVENT is a one to one mapping between tracepoint and template.
57 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
58 DECLARE_EVENT_CLASS(name, \
64 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
66 #undef DEFINE_EVENT_PRINT
67 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
68 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
70 /* Callbacks are meaningless to LTTng. */
72 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
73 assign, print, reg, unreg) \
74 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
75 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
78 * Stage 1 of the trace events.
80 * Create event field type metadata section.
81 * Each event produce an array of fields.
84 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
86 /* Named field types must be defined in lttng-types.h */
89 #define __field(_type, _item) \
90 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
93 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
96 #define __array(_type, _item, _length) \
100 .atype = atype_array, \
102 .u.array.elem_type = #_type, \
103 .u.array.length = _length, \
107 #undef __dynamic_array
108 #define __dynamic_array(_type, _item, _length) \
112 .atype = atype_sequence, \
114 .u.sequence.elem_type = #_type, \
115 .u.sequence.length_type = "u32", \
120 #define __string(_item, _src) \
124 .atype = atype_string, \
126 .u.string.encoding = lttng_encode_UTF8, \
130 #undef TP_STRUCT__entry
131 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
133 #undef DECLARE_EVENT_CLASS
134 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
135 static const struct lttng_event_field __event_fields___##_name[] = { \
139 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
142 * Stage 2 of the trace events.
144 * Create an array of events.
147 /* Named field types must be defined in lttng-types.h */
149 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
151 #undef DECLARE_EVENT_CLASS
152 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
154 .fields = __event_fields___##_name, \
156 .nr_fields = ARRAY_SIZE(__event_fields___##_name), \
159 #define TP_ID1(_token, _system) _token##_system
160 #define TP_ID(_token, _system) TP_ID1(_token, _system)
162 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
163 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
170 * Stage 3 of the trace events.
172 * Create seq file metadata output.
175 #define TP_ID1(_token, _system) _token##_system
176 #define TP_ID(_token, _system) TP_ID1(_token, _system)
177 #define module_init_eval1(_token, _system) module_init(_token##_system)
178 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
179 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
180 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
182 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
185 const struct lttng_event_desc
*desc
=
186 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
188 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
189 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
191 return (void *) desc
;
194 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
195 void *p
, loff_t
*ppos
)
197 const struct lttng_event_desc
*desc
=
198 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
200 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
201 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
203 return (void *) desc
;
206 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
211 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
214 const struct lttng_event_desc
*desc
= p
;
217 seq_printf(m
, "event {\n"
220 "\tstream = UNKNOWN;\n"
223 for (i
= 0; i
< desc
->nr_fields
; i
++) {
224 if (desc
->fields
[i
].type
.name
) /* Named type */
225 seq_printf(m
, "\t\t%s",
226 desc
->fields
[i
].type
.name
);
227 else /* Nameless type */
228 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
229 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
231 seq_printf(m
, "\t};\n");
232 seq_printf(m
, "};\n");
237 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
238 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
239 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
240 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
241 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
245 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
247 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
251 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
252 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
255 .release
= seq_release_private
,
258 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
260 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
264 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
265 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
267 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
268 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
269 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
270 printk(KERN_ERR
"Error creating LTTng type export file\n");
278 module_init_eval(__lttng_types_init__
, TRACE_SYSTEM
);
280 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
282 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
285 module_exit_eval(__lttng_types_exit__
, TRACE_SYSTEM
);
287 #undef module_init_eval
288 #undef module_exit_eval
294 * Stage 4 of the trace events.
296 * Create static inline function that calculates event size.
299 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
301 /* Named field types must be defined in lttng-types.h */
304 #define __field(_type, _item) \
305 __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
306 __event_len += sizeof(_type);
309 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
312 #define __array(_type, _item, _length) \
313 __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
314 __event_len += sizeof(_type) * (_length);
316 #undef __dynamic_array
317 #define __dynamic_array(_type, _item, _length) \
318 __event_len += lib_ring_buffer_align(__event_len, sizeof(u32)); \
319 __event_len += sizeof(u32); \
320 __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
321 __event_len += sizeof(_type) * (_length);
324 #define __string(_item, _src) \
325 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
328 #define TP_PROTO(args...) args
330 #undef TP_STRUCT__entry
331 #define TP_STRUCT__entry(args...) args
333 #undef DECLARE_EVENT_CLASS
334 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
335 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
337 size_t __event_len = 0; \
338 unsigned int __dynamic_len_idx = 0; \
341 (void) __dynamic_len_idx; /* don't warn if unused */ \
343 return __event_len; \
346 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
352 * Stage 4 of the trace events.
354 * Create the probe function : call even size calculation and write event data
360 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
365 #include <linux/ftrace_event.h>
368 * DECLARE_EVENT_CLASS can be used to add a generic function
369 * handlers for events. That is, if all events have the same
370 * parameters and just have distinct trace points.
371 * Each tracepoint can be defined with DEFINE_EVENT and that
372 * will map the DECLARE_EVENT_CLASS to the tracepoint.
374 * TRACE_EVENT is a one to one mapping between tracepoint and template.
377 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
378 DECLARE_EVENT_CLASS(name, \
384 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
388 #define __field(type, item) type item;
391 #define __field_ext(type, item, filter_type) type item;
394 #define __array(type, item, len) type item[len];
396 #undef __dynamic_array
397 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
400 #define __string(item, src) __dynamic_array(char, item, -1)
402 #undef TP_STRUCT__entry
403 #define TP_STRUCT__entry(args...) args
405 #undef DECLARE_EVENT_CLASS
406 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
407 struct ftrace_raw_##name { \
408 struct trace_entry ent; \
413 static struct ftrace_event_class event_class_##name;
416 #define DEFINE_EVENT(template, name, proto, args) \
417 static struct ftrace_event_call __used \
418 __attribute__((__aligned__(4))) event_##name
420 #undef DEFINE_EVENT_PRINT
421 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
422 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
424 /* Callbacks are meaningless to ftrace. */
425 #undef TRACE_EVENT_FN
426 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
427 assign, print, reg, unreg) \
428 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
429 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
431 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
435 * Stage 2 of the trace events.
437 * Create static inline function that calculates event size.
441 #define __field(type, item)
444 #define __field_ext(type, item, filter_type)
447 #define __array(type, item, len)
449 #undef __dynamic_array
450 #define __dynamic_array(type, item, len) u32 item;
453 #define __string(item, src) __dynamic_array(char, item, -1)
455 #undef DECLARE_EVENT_CLASS
456 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
457 struct ftrace_data_offsets_##call { \
462 #define DEFINE_EVENT(template, name, proto, args)
464 #undef DEFINE_EVENT_PRINT
465 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
466 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
468 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
471 * Stage 3 of the trace events.
473 * Create the probe function : call even size calculation and write event data
478 #define __entry field
481 #define TP_printk(fmt, args...) fmt "\n", args
483 #undef __get_dynamic_array
484 #define __get_dynamic_array(field) \
485 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
488 #define __get_str(field) (char *)__get_dynamic_array(field)
491 #define __print_flags(flag, delim, flag_array...) \
493 static const struct trace_print_flags __flags[] = \
494 { flag_array, { -1, NULL }}; \
495 ftrace_print_flags_seq(p, delim, flag, __flags); \
498 #undef __print_symbolic
499 #define __print_symbolic(value, symbol_array...) \
501 static const struct trace_print_flags symbols[] = \
502 { symbol_array, { -1, NULL }}; \
503 ftrace_print_symbols_seq(p, value, symbols); \
507 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
509 #undef DECLARE_EVENT_CLASS
510 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
511 static notrace enum print_line_t \
512 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
513 struct trace_event *trace_event) \
515 struct ftrace_event_call *event; \
516 struct trace_seq *s = &iter->seq; \
517 struct ftrace_raw_##call *field; \
518 struct trace_entry *entry; \
519 struct trace_seq *p = &iter->tmp_seq; \
522 event = container_of(trace_event, struct ftrace_event_call, \
527 if (entry->type != event->event.type) { \
529 return TRACE_TYPE_UNHANDLED; \
532 field = (typeof(field))entry; \
535 ret = trace_seq_printf(s, "%s: ", event->name); \
537 ret = trace_seq_printf(s, print); \
539 return TRACE_TYPE_PARTIAL_LINE; \
541 return TRACE_TYPE_HANDLED; \
543 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
544 .trace = ftrace_raw_output_##call, \
547 #undef DEFINE_EVENT_PRINT
548 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
549 static notrace enum print_line_t \
550 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
551 struct trace_event *event) \
553 struct trace_seq *s = &iter->seq; \
554 struct ftrace_raw_##template *field; \
555 struct trace_entry *entry; \
556 struct trace_seq *p = &iter->tmp_seq; \
561 if (entry->type != event_##call.event.type) { \
563 return TRACE_TYPE_UNHANDLED; \
566 field = (typeof(field))entry; \
569 ret = trace_seq_printf(s, "%s: ", #call); \
571 ret = trace_seq_printf(s, print); \
573 return TRACE_TYPE_PARTIAL_LINE; \
575 return TRACE_TYPE_HANDLED; \
577 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
578 .trace = ftrace_raw_output_##call, \
581 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
584 #define __field_ext(type, item, filter_type) \
585 ret = trace_define_field(event_call, #type, #item, \
586 offsetof(typeof(field), item), \
587 sizeof(field.item), \
588 is_signed_type(type), filter_type); \
593 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
596 #define __array(type, item, len) \
597 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
598 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
599 offsetof(typeof(field), item), \
600 sizeof(field.item), \
601 is_signed_type(type), FILTER_OTHER); \
605 #undef __dynamic_array
606 #define __dynamic_array(type, item, len) \
607 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
608 offsetof(typeof(field), __data_loc_##item), \
609 sizeof(field.__data_loc_##item), \
610 is_signed_type(type), FILTER_OTHER);
613 #define __string(item, src) __dynamic_array(char, item, -1)
615 #undef DECLARE_EVENT_CLASS
616 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
618 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
620 struct ftrace_raw_##call field; \
629 #define DEFINE_EVENT(template, name, proto, args)
631 #undef DEFINE_EVENT_PRINT
632 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
633 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
635 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
638 * remember the offset of each array from the beginning of the event.
642 #define __entry entry
645 #define __field(type, item)
648 #define __field_ext(type, item, filter_type)
651 #define __array(type, item, len)
653 #undef __dynamic_array
654 #define __dynamic_array(type, item, len) \
655 __data_offsets->item = __data_size + \
656 offsetof(typeof(*entry), __data); \
657 __data_offsets->item |= (len * sizeof(type)) << 16; \
658 __data_size += (len) * sizeof(type);
661 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
663 #undef DECLARE_EVENT_CLASS
664 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
665 static inline notrace int ftrace_get_offsets_##call( \
666 struct ftrace_data_offsets_##call *__data_offsets, proto) \
668 int __data_size = 0; \
669 struct ftrace_raw_##call __maybe_unused *entry; \
673 return __data_size; \
677 #define DEFINE_EVENT(template, name, proto, args)
679 #undef DEFINE_EVENT_PRINT
680 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
681 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
683 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
686 * Stage 4 of the trace events.
688 * Override the macros in <trace/trace_events.h> to include the following:
690 * For those macros defined with TRACE_EVENT:
692 * static struct ftrace_event_call event_<call>;
694 * static void ftrace_raw_event_<call>(void *__data, proto)
696 * struct ftrace_event_call *event_call = __data;
697 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
698 * struct ring_buffer_event *event;
699 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
700 * struct ring_buffer *buffer;
701 * unsigned long irq_flags;
705 * local_save_flags(irq_flags);
706 * pc = preempt_count();
708 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
710 * event = trace_current_buffer_lock_reserve(&buffer,
711 * event_<call>->event.type,
712 * sizeof(*entry) + __data_size,
716 * entry = ring_buffer_event_data(event);
718 * { <assign>; } <-- Here we assign the entries by the __field and
721 * if (!filter_current_check_discard(buffer, event_call, entry, event))
722 * trace_current_buffer_unlock_commit(buffer,
723 * event, irq_flags, pc);
726 * static struct trace_event ftrace_event_type_<call> = {
727 * .trace = ftrace_raw_output_<call>, <-- stage 2
730 * static const char print_fmt_<call>[] = <TP_printk>;
732 * static struct ftrace_event_class __used event_class_<template> = {
733 * .system = "<system>",
734 * .define_fields = ftrace_define_fields_<call>,
735 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
736 * .raw_init = trace_event_raw_init,
737 * .probe = ftrace_raw_event_##call,
738 * .reg = ftrace_event_reg,
741 * static struct ftrace_event_call __used
742 * __attribute__((__aligned__(4)))
743 * __attribute__((section("_ftrace_events"))) event_<call> = {
745 * .class = event_class_<template>,
746 * .event = &ftrace_event_type_<call>,
747 * .print_fmt = print_fmt_<call>,
752 #ifdef CONFIG_PERF_EVENTS
754 #define _TRACE_PERF_PROTO(call, proto) \
755 static notrace void \
756 perf_trace_##call(void *__data, proto);
758 #define _TRACE_PERF_INIT(call) \
759 .perf_probe = perf_trace_##call,
762 #define _TRACE_PERF_PROTO(call, proto)
763 #define _TRACE_PERF_INIT(call)
764 #endif /* CONFIG_PERF_EVENTS */
767 #define __entry entry
770 #define __field(type, item)
773 #define __array(type, item, len)
775 #undef __dynamic_array
776 #define __dynamic_array(type, item, len) \
777 __entry->__data_loc_##item = __data_offsets.item;
780 #define __string(item, src) __dynamic_array(char, item, -1) \
783 #define __assign_str(dst, src) \
784 strcpy(__get_str(dst), src);
786 #undef TP_fast_assign
787 #define TP_fast_assign(args...) args
789 #undef TP_perf_assign
790 #define TP_perf_assign(args...)
792 #undef DECLARE_EVENT_CLASS
793 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
795 static notrace void \
796 ftrace_raw_event_##call(void *__data, proto) \
798 struct ftrace_event_call *event_call = __data; \
799 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
800 struct ring_buffer_event *event; \
801 struct ftrace_raw_##call *entry; \
802 struct ring_buffer *buffer; \
803 unsigned long irq_flags; \
807 local_save_flags(irq_flags); \
808 pc = preempt_count(); \
810 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
812 event = trace_current_buffer_lock_reserve(&buffer, \
813 event_call->event.type, \
814 sizeof(*entry) + __data_size, \
818 entry = ring_buffer_event_data(event); \
824 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
825 trace_nowake_buffer_unlock_commit(buffer, \
826 event, irq_flags, pc); \
829 * The ftrace_test_probe is compiled out, it is only here as a build time check
830 * to make sure that if the tracepoint handling changes, the ftrace probe will
831 * fail to compile unless it too is updated.
835 #define DEFINE_EVENT(template, call, proto, args) \
836 static inline void ftrace_test_probe_##call(void) \
838 check_trace_callback_type_##call(ftrace_raw_event_##template); \
841 #undef DEFINE_EVENT_PRINT
842 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
844 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
850 #undef __print_symbolic
851 #undef __get_dynamic_array
855 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
857 #undef DECLARE_EVENT_CLASS
858 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
859 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
860 static const char print_fmt_##call[] = print; \
861 static struct ftrace_event_class __used event_class_##call = { \
862 .system = __stringify(TRACE_SYSTEM), \
863 .define_fields = ftrace_define_fields_##call, \
864 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
865 .raw_init = trace_event_raw_init, \
866 .probe = ftrace_raw_event_##call, \
867 .reg = ftrace_event_reg, \
868 _TRACE_PERF_INIT(call) \
872 #define DEFINE_EVENT(template, call, proto, args) \
874 static struct ftrace_event_call __used \
875 __attribute__((__aligned__(4))) \
876 __attribute__((section("_ftrace_events"))) event_##call = { \
878 .class = &event_class_##template, \
879 .event.funcs = &ftrace_event_type_funcs_##template, \
880 .print_fmt = print_fmt_##template, \
883 #undef DEFINE_EVENT_PRINT
884 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
886 static const char print_fmt_##call[] = print; \
888 static struct ftrace_event_call __used \
889 __attribute__((__aligned__(4))) \
890 __attribute__((section("_ftrace_events"))) event_##call = { \
892 .class = &event_class_##template, \
893 .event.funcs = &ftrace_event_type_funcs_##call, \
894 .print_fmt = print_fmt_##call, \
897 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
900 * Define the insertion callback to perf events
902 * The job is very similar to ftrace_raw_event_<call> except that we don't
903 * insert in the ring buffer but in a perf counter.
905 * static void ftrace_perf_<call>(proto)
907 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
908 * struct ftrace_event_call *event_call = &event_<call>;
909 * extern void perf_tp_event(int, u64, u64, void *, int);
910 * struct ftrace_raw_##call *entry;
911 * struct perf_trace_buf *trace_buf;
912 * u64 __addr = 0, __count = 1;
913 * unsigned long irq_flags;
914 * struct trace_entry *ent;
920 * pc = preempt_count();
922 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
924 * // Below we want to get the aligned size by taking into account
925 * // the u32 field that will later store the buffer size
926 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
928 * __entry_size -= sizeof(u32);
930 * // Protect the non nmi buffer
931 * // This also protects the rcu read side
932 * local_irq_save(irq_flags);
933 * __cpu = smp_processor_id();
936 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
938 * trace_buf = rcu_dereference_sched(perf_trace_buf);
943 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
945 * // Avoid recursion from perf that could mess up the buffer
946 * if (trace_buf->recursion++)
947 * goto end_recursion;
949 * raw_data = trace_buf->buf;
951 * // Make recursion update visible before entering perf_tp_event
952 * // so that we protect from perf recursions.
956 * //zero dead bytes from alignment to avoid stack leak to userspace:
957 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
958 * entry = (struct ftrace_raw_<call> *)raw_data;
960 * tracing_generic_entry_update(ent, irq_flags, pc);
961 * ent->type = event_call->id;
963 * <tstruct> <- do some jobs with dynamic arrays
965 * <assign> <- affect our values
967 * perf_tp_event(event_call->id, __addr, __count, entry,
968 * __entry_size); <- submit them to perf counter
973 #ifdef CONFIG_PERF_EVENTS
976 #define __entry entry
978 #undef __get_dynamic_array
979 #define __get_dynamic_array(field) \
980 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
983 #define __get_str(field) (char *)__get_dynamic_array(field)
986 #define __perf_addr(a) __addr = (a)
989 #define __perf_count(c) __count = (c)
991 #undef DECLARE_EVENT_CLASS
992 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
993 static notrace void \
994 perf_trace_##call(void *__data, proto) \
996 struct ftrace_event_call *event_call = __data; \
997 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
998 struct ftrace_raw_##call *entry; \
999 struct pt_regs __regs; \
1000 u64 __addr = 0, __count = 1; \
1001 struct hlist_head *head; \
1006 perf_fetch_caller_regs(&__regs); \
1008 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1009 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
1011 __entry_size -= sizeof(u32); \
1013 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
1014 "profile buffer not large enough")) \
1017 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
1018 __entry_size, event_call->event.type, &__regs, &rctx); \
1026 head = this_cpu_ptr(event_call->perf_events); \
1027 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
1028 __count, &__regs, head); \
1032 * This part is compiled out, it is only here as a build time check
1033 * to make sure that if the tracepoint handling changes, the
1034 * perf probe will fail to compile unless it too is updated.
1037 #define DEFINE_EVENT(template, call, proto, args) \
1038 static inline void perf_test_probe_##call(void) \
1040 check_trace_callback_type_##call(perf_trace_##template); \
1044 #undef DEFINE_EVENT_PRINT
1045 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
1046 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
1048 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1049 #endif /* CONFIG_PERF_EVENTS */
1051 #undef _TRACE_PROFILE_INIT
This page took 0.072348 seconds and 4 git commands to generate.