b8f710baf691ea0c2dd8a120325e09c624db6a8b
2 #include <lttng-types.h>
3 #include <linux/debugfs.h>
4 #include <linux/ringbuffer/frontend_types.h>
5 #include "../ltt-events.h"
6 #include "../ltt-tracer-core.h"
8 struct lttng_event_field
{
10 const struct lttng_type type
;
13 struct lttng_event_desc
{
14 const struct lttng_event_field
*fields
;
16 unsigned int nr_fields
;
20 * Macro declarations used for all stages.
24 * DECLARE_EVENT_CLASS can be used to add a generic function
25 * handlers for events. That is, if all events have the same
26 * parameters and just have distinct trace points.
27 * Each tracepoint can be defined with DEFINE_EVENT and that
28 * will map the DECLARE_EVENT_CLASS to the tracepoint.
30 * TRACE_EVENT is a one to one mapping between tracepoint and template.
34 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
35 DECLARE_EVENT_CLASS(name, \
41 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
43 #undef DEFINE_EVENT_PRINT
44 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
45 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
47 /* Callbacks are meaningless to LTTng. */
49 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
50 assign, print, reg, unreg) \
51 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
52 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
55 * Stage 1 of the trace events.
57 * Create event field type metadata section.
58 * Each event produce an array of fields.
61 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
63 /* Named field types must be defined in lttng-types.h */
66 #define __field(_type, _item) \
67 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
70 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
73 #define __array(_type, _item, _length) \
77 .atype = atype_array, \
79 .u.array.elem_type = #_type, \
80 .u.array.length = _length, \
84 #undef __dynamic_array
85 #define __dynamic_array(_type, _item, _length) \
89 .atype = atype_sequence, \
91 .u.sequence.elem_type = #_type, \
92 .u.sequence.length_type = "u32", \
97 #define __string(_item, _src) \
101 .atype = atype_string, \
103 .u.string.encoding = lttng_encode_UTF8, \
107 #undef TP_STRUCT__entry
108 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
110 #undef DECLARE_EVENT_CLASS
111 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
112 static const struct lttng_event_field __event_fields___##_name[] = { \
116 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
119 * Stage 2 of the trace events.
121 * Create an array of events.
124 /* Named field types must be defined in lttng-types.h */
126 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
129 #define DEFINE_EVENT(_template, _name, _proto, _args) \
131 .fields = __event_fields___##_template, \
133 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
136 #define TP_ID1(_token, _system) _token##_system
137 #define TP_ID(_token, _system) TP_ID1(_token, _system)
139 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
140 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
147 * Stage 3 of the trace events.
149 * Create seq file metadata output.
152 #define TP_ID1(_token, _system) _token##_system
153 #define TP_ID(_token, _system) TP_ID1(_token, _system)
154 #define module_init_eval1(_token, _system) module_init(_token##_system)
155 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
156 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
157 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
159 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
162 const struct lttng_event_desc
*desc
=
163 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
165 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
166 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
168 return (void *) desc
;
171 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
172 void *p
, loff_t
*ppos
)
174 const struct lttng_event_desc
*desc
=
175 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
177 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
178 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
180 return (void *) desc
;
183 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
188 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
191 const struct lttng_event_desc
*desc
= p
;
194 seq_printf(m
, "event {\n"
197 "\tstream = UNKNOWN;\n"
200 for (i
= 0; i
< desc
->nr_fields
; i
++) {
201 if (desc
->fields
[i
].type
.name
) /* Named type */
202 seq_printf(m
, "\t\t%s",
203 desc
->fields
[i
].type
.name
);
204 else /* Nameless type */
205 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
206 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
208 seq_printf(m
, "\t};\n");
209 seq_printf(m
, "};\n");
214 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
215 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
216 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
217 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
218 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
222 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
224 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
228 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
229 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
232 .release
= seq_release_private
,
235 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
237 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
241 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
242 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
244 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
245 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
246 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
247 printk(KERN_ERR
"Error creating LTTng type export file\n");
255 module_init_eval(__lttng_types_init__
, TRACE_SYSTEM
);
257 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
259 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
262 module_exit_eval(__lttng_types_exit__
, TRACE_SYSTEM
);
264 #undef module_init_eval
265 #undef module_exit_eval
270 * Stage 4 of the trace events.
272 * Create static inline function that calculates event size.
275 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
277 /* Named field types must be defined in lttng-types.h */
280 #define __field(_type, _item) \
281 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
282 __event_len += sizeof(_type);
285 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
288 #define __array(_type, _item, _length) \
289 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
290 __event_len += sizeof(_type) * (_length);
292 #undef __dynamic_array
293 #define __dynamic_array(_type, _item, _length) \
294 __event_len += lib_ring_buffer_align(__event_len, __alignof__(u32)); \
295 __event_len += sizeof(u32); \
296 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
297 __event_len += sizeof(_type) * (_length);
300 #define __string(_item, _src) \
301 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
304 #define TP_PROTO(args...) args
306 #undef TP_STRUCT__entry
307 #define TP_STRUCT__entry(args...) args
309 #undef DECLARE_EVENT_CLASS
310 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
311 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
313 size_t __event_len = 0; \
314 unsigned int __dynamic_len_idx = 0; \
317 (void) __dynamic_len_idx; /* don't warn if unused */ \
319 return __event_len; \
322 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
327 * Stage 5 of the trace events.
329 * Create static inline function that calculates event payload alignment.
332 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
334 /* Named field types must be defined in lttng-types.h */
337 #define __field(_type, _item) \
338 __event_align = max_t(size_t, __event_align, __alignof__(_type));
341 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
344 #define __array(_type, _item, _length) \
345 __event_align = max_t(size_t, __event_align, __alignof__(_type));
347 #undef __dynamic_array
348 #define __dynamic_array(_type, _item, _length) \
349 __event_align = max_t(size_t, __event_align, __alignof__(u32)); \
350 __event_align = max_t(size_t, __event_align, __alignof__(_type));
353 #define __string(_item, _src)
356 #define TP_PROTO(args...) args
358 #undef TP_STRUCT__entry
359 #define TP_STRUCT__entry(args...) args
361 #undef DECLARE_EVENT_CLASS
362 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
363 static inline size_t __event_get_align__##_name(_proto) \
365 size_t __event_align = 1; \
367 return __event_align; \
370 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
374 * Stage 6 of the trace events.
376 * Create structure declaration that allows the "assign" macros to access the
380 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
382 /* Named field types must be defined in lttng-types.h */
385 #define __field(_type, _item) _type _item;
388 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
391 #define __array(_type, _item, _length) _type _item;
393 #undef __dynamic_array
394 #define __dynamic_array(_type, _item, _length) _type _item;
397 #define __string(_item, _src) char _item;
399 #undef TP_STRUCT__entry
400 #define TP_STRUCT__entry(args...) args
402 #undef DECLARE_EVENT_CLASS
403 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
404 struct __event_typemap__##_name { \
408 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
412 * Stage 7 of the trace events.
414 * Create the probe function : call even size calculation and write event data
417 * We use both the field and assignment macros to write the fields in the order
418 * defined in the field declaration. The field declarations control the
419 * execution order, jumping to the appropriate assignment block.
422 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
425 #define __field(_type, _item) \
426 goto __assign_##_item; \
430 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
433 #define __array(_type, _item, _length) \
434 goto __assign_##_item; \
437 #undef __dynamic_array
438 #define __dynamic_array(_type, _item, _length) \
439 goto __assign_##_item##_1; \
440 __end_field_##_item##_1: \
441 goto __assign_##_item##_2; \
442 __end_field_##_item##_2:
445 #define __string(_item, _src) \
446 goto __assign_##_item; \
450 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
454 #define tp_assign(dest, src) \
457 __typeof__(__typemap.dest) __tmp = (src); \
458 lib_ring_buffer_align_ctx(&ctx, __alignof__(__tmp)); \
459 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
461 goto __end_field_##dest;
464 #define tp_memcpy(dest, src, len) \
466 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
467 __chan->ops->event_write(&ctx, src, len); \
468 goto __end_field_##dest;
471 #define tp_memcpy_dyn(dest, src, len) \
472 __assign_##dest##_1: \
474 u32 __tmpl = (len); \
475 lib_ring_buffer_align_ctx(&ctx, __alignof__(u32)); \
476 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
478 goto __end_field_##dest##_1; \
479 __assign_##dest##_2: \
480 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
481 __chan->ops->event_write(&ctx, src, len); \
482 goto __end_field_##dest##_2;
485 #define tp_strcpy(dest, src) \
486 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
488 /* Named field types must be defined in lttng-types.h */
491 #define __get_str(field) field
493 #undef __get_dynamic_array
494 #define __get_dynamic_array(field) field
496 /* Beware: this get len actually consumes the len value */
497 #undef __get_dynamic_array_len
498 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
501 #define TP_PROTO(args...) args
504 #define TP_ARGS(args...) args
506 #undef TP_STRUCT__entry
507 #define TP_STRUCT__entry(args...) args
509 #undef TP_fast_assign
510 #define TP_fast_assign(args...) args
512 #undef DECLARE_EVENT_CLASS
513 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
514 static void __event_probe__##_name(void *__data, _proto) \
516 struct ltt_event *__event = __data; \
517 struct ltt_channel *__chan = __event->chan; \
518 struct lib_ring_buffer_ctx ctx; \
519 size_t __event_len, __event_align; \
520 size_t __dynamic_len_idx = 0; \
521 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
522 struct __event_typemap__##_name __typemap; \
526 (void) __dynamic_len_idx; /* don't warn if unused */ \
527 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
528 __event_align = __event_get_align__##_name(_args); \
529 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
530 __event_align, -1); \
531 __ret = __chan->ops->event_reserve(&ctx); \
534 /* Control code (field ordering) */ \
536 __chan->ops->event_commit(&ctx); \
538 /* Copy code, steered by control code */ \
542 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
547 #include <linux/ftrace_event.h>
550 * DECLARE_EVENT_CLASS can be used to add a generic function
551 * handlers for events. That is, if all events have the same
552 * parameters and just have distinct trace points.
553 * Each tracepoint can be defined with DEFINE_EVENT and that
554 * will map the DECLARE_EVENT_CLASS to the tracepoint.
556 * TRACE_EVENT is a one to one mapping between tracepoint and template.
559 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
560 DECLARE_EVENT_CLASS(name, \
566 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
570 #define __field(type, item) type item;
573 #define __field_ext(type, item, filter_type) type item;
576 #define __array(type, item, len) type item[len];
578 #undef __dynamic_array
579 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
582 #define __string(item, src) __dynamic_array(char, item, -1)
584 #undef TP_STRUCT__entry
585 #define TP_STRUCT__entry(args...) args
587 #undef DECLARE_EVENT_CLASS
588 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
589 struct ftrace_raw_##name { \
590 struct trace_entry ent; \
595 static struct ftrace_event_class event_class_##name;
598 #define DEFINE_EVENT(template, name, proto, args) \
599 static struct ftrace_event_call __used \
600 __attribute__((__aligned__(4))) event_##name
602 #undef DEFINE_EVENT_PRINT
603 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
604 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
606 /* Callbacks are meaningless to ftrace. */
607 #undef TRACE_EVENT_FN
608 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
609 assign, print, reg, unreg) \
610 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
611 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
613 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
617 * Stage 2 of the trace events.
619 * Create static inline function that calculates event size.
623 #define __field(type, item)
626 #define __field_ext(type, item, filter_type)
629 #define __array(type, item, len)
631 #undef __dynamic_array
632 #define __dynamic_array(type, item, len) u32 item;
635 #define __string(item, src) __dynamic_array(char, item, -1)
637 #undef DECLARE_EVENT_CLASS
638 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
639 struct ftrace_data_offsets_##call { \
644 #define DEFINE_EVENT(template, name, proto, args)
646 #undef DEFINE_EVENT_PRINT
647 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
648 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
650 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
653 * Stage 3 of the trace events.
655 * Create the probe function : call even size calculation and write event data
660 #define __entry field
663 #define TP_printk(fmt, args...) fmt "\n", args
665 #undef __get_dynamic_array
666 #define __get_dynamic_array(field) \
667 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
670 #define __get_str(field) (char *)__get_dynamic_array(field)
673 #define __print_flags(flag, delim, flag_array...) \
675 static const struct trace_print_flags __flags[] = \
676 { flag_array, { -1, NULL }}; \
677 ftrace_print_flags_seq(p, delim, flag, __flags); \
680 #undef __print_symbolic
681 #define __print_symbolic(value, symbol_array...) \
683 static const struct trace_print_flags symbols[] = \
684 { symbol_array, { -1, NULL }}; \
685 ftrace_print_symbols_seq(p, value, symbols); \
689 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
691 #undef DECLARE_EVENT_CLASS
692 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
693 static notrace enum print_line_t \
694 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
695 struct trace_event *trace_event) \
697 struct ftrace_event_call *event; \
698 struct trace_seq *s = &iter->seq; \
699 struct ftrace_raw_##call *field; \
700 struct trace_entry *entry; \
701 struct trace_seq *p = &iter->tmp_seq; \
704 event = container_of(trace_event, struct ftrace_event_call, \
709 if (entry->type != event->event.type) { \
711 return TRACE_TYPE_UNHANDLED; \
714 field = (typeof(field))entry; \
717 ret = trace_seq_printf(s, "%s: ", event->name); \
719 ret = trace_seq_printf(s, print); \
721 return TRACE_TYPE_PARTIAL_LINE; \
723 return TRACE_TYPE_HANDLED; \
725 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
726 .trace = ftrace_raw_output_##call, \
729 #undef DEFINE_EVENT_PRINT
730 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
731 static notrace enum print_line_t \
732 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
733 struct trace_event *event) \
735 struct trace_seq *s = &iter->seq; \
736 struct ftrace_raw_##template *field; \
737 struct trace_entry *entry; \
738 struct trace_seq *p = &iter->tmp_seq; \
743 if (entry->type != event_##call.event.type) { \
745 return TRACE_TYPE_UNHANDLED; \
748 field = (typeof(field))entry; \
751 ret = trace_seq_printf(s, "%s: ", #call); \
753 ret = trace_seq_printf(s, print); \
755 return TRACE_TYPE_PARTIAL_LINE; \
757 return TRACE_TYPE_HANDLED; \
759 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
760 .trace = ftrace_raw_output_##call, \
763 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
766 #define __field_ext(type, item, filter_type) \
767 ret = trace_define_field(event_call, #type, #item, \
768 offsetof(typeof(field), item), \
769 sizeof(field.item), \
770 is_signed_type(type), filter_type); \
775 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
778 #define __array(type, item, len) \
779 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
780 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
781 offsetof(typeof(field), item), \
782 sizeof(field.item), \
783 is_signed_type(type), FILTER_OTHER); \
787 #undef __dynamic_array
788 #define __dynamic_array(type, item, len) \
789 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
790 offsetof(typeof(field), __data_loc_##item), \
791 sizeof(field.__data_loc_##item), \
792 is_signed_type(type), FILTER_OTHER);
795 #define __string(item, src) __dynamic_array(char, item, -1)
797 #undef DECLARE_EVENT_CLASS
798 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
800 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
802 struct ftrace_raw_##call field; \
811 #define DEFINE_EVENT(template, name, proto, args)
813 #undef DEFINE_EVENT_PRINT
814 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
815 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
817 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
820 * remember the offset of each array from the beginning of the event.
824 #define __entry entry
827 #define __field(type, item)
830 #define __field_ext(type, item, filter_type)
833 #define __array(type, item, len)
835 #undef __dynamic_array
836 #define __dynamic_array(type, item, len) \
837 __data_offsets->item = __data_size + \
838 offsetof(typeof(*entry), __data); \
839 __data_offsets->item |= (len * sizeof(type)) << 16; \
840 __data_size += (len) * sizeof(type);
843 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
845 #undef DECLARE_EVENT_CLASS
846 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
847 static inline notrace int ftrace_get_offsets_##call( \
848 struct ftrace_data_offsets_##call *__data_offsets, proto) \
850 int __data_size = 0; \
851 struct ftrace_raw_##call __maybe_unused *entry; \
855 return __data_size; \
859 #define DEFINE_EVENT(template, name, proto, args)
861 #undef DEFINE_EVENT_PRINT
862 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
863 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
865 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
868 * Stage 4 of the trace events.
870 * Override the macros in <trace/trace_events.h> to include the following:
872 * For those macros defined with TRACE_EVENT:
874 * static struct ftrace_event_call event_<call>;
876 * static void ftrace_raw_event_<call>(void *__data, proto)
878 * struct ftrace_event_call *event_call = __data;
879 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
880 * struct ring_buffer_event *event;
881 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
882 * struct ring_buffer *buffer;
883 * unsigned long irq_flags;
887 * local_save_flags(irq_flags);
888 * pc = preempt_count();
890 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
892 * event = trace_current_buffer_lock_reserve(&buffer,
893 * event_<call>->event.type,
894 * sizeof(*entry) + __data_size,
898 * entry = ring_buffer_event_data(event);
900 * { <assign>; } <-- Here we assign the entries by the __field and
903 * if (!filter_current_check_discard(buffer, event_call, entry, event))
904 * trace_current_buffer_unlock_commit(buffer,
905 * event, irq_flags, pc);
908 * static struct trace_event ftrace_event_type_<call> = {
909 * .trace = ftrace_raw_output_<call>, <-- stage 2
912 * static const char print_fmt_<call>[] = <TP_printk>;
914 * static struct ftrace_event_class __used event_class_<template> = {
915 * .system = "<system>",
916 * .define_fields = ftrace_define_fields_<call>,
917 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
918 * .raw_init = trace_event_raw_init,
919 * .probe = ftrace_raw_event_##call,
920 * .reg = ftrace_event_reg,
923 * static struct ftrace_event_call __used
924 * __attribute__((__aligned__(4)))
925 * __attribute__((section("_ftrace_events"))) event_<call> = {
927 * .class = event_class_<template>,
928 * .event = &ftrace_event_type_<call>,
929 * .print_fmt = print_fmt_<call>,
934 #ifdef CONFIG_PERF_EVENTS
936 #define _TRACE_PERF_PROTO(call, proto) \
937 static notrace void \
938 perf_trace_##call(void *__data, proto);
940 #define _TRACE_PERF_INIT(call) \
941 .perf_probe = perf_trace_##call,
944 #define _TRACE_PERF_PROTO(call, proto)
945 #define _TRACE_PERF_INIT(call)
946 #endif /* CONFIG_PERF_EVENTS */
949 #define __entry entry
952 #define __field(type, item)
955 #define __array(type, item, len)
957 #undef __dynamic_array
958 #define __dynamic_array(type, item, len) \
959 __entry->__data_loc_##item = __data_offsets.item;
962 #define __string(item, src) __dynamic_array(char, item, -1) \
965 #define __assign_str(dst, src) \
966 strcpy(__get_str(dst), src);
968 #undef TP_fast_assign
969 #define TP_fast_assign(args...) args
971 #undef TP_perf_assign
972 #define TP_perf_assign(args...)
974 #undef DECLARE_EVENT_CLASS
975 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
977 static notrace void \
978 ftrace_raw_event_##call(void *__data, proto) \
980 struct ftrace_event_call *event_call = __data; \
981 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
982 struct ring_buffer_event *event; \
983 struct ftrace_raw_##call *entry; \
984 struct ring_buffer *buffer; \
985 unsigned long irq_flags; \
989 local_save_flags(irq_flags); \
990 pc = preempt_count(); \
992 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
994 event = trace_current_buffer_lock_reserve(&buffer, \
995 event_call->event.type, \
996 sizeof(*entry) + __data_size, \
1000 entry = ring_buffer_event_data(event); \
1006 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
1007 trace_nowake_buffer_unlock_commit(buffer, \
1008 event, irq_flags, pc); \
1011 * The ftrace_test_probe is compiled out, it is only here as a build time check
1012 * to make sure that if the tracepoint handling changes, the ftrace probe will
1013 * fail to compile unless it too is updated.
1017 #define DEFINE_EVENT(template, call, proto, args) \
1018 static inline void ftrace_test_probe_##call(void) \
1020 check_trace_callback_type_##call(ftrace_raw_event_##template); \
1023 #undef DEFINE_EVENT_PRINT
1024 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
1026 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1031 #undef __print_flags
1032 #undef __print_symbolic
1033 #undef __get_dynamic_array
1037 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
1039 #undef DECLARE_EVENT_CLASS
1040 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1041 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
1042 static const char print_fmt_##call[] = print; \
1043 static struct ftrace_event_class __used event_class_##call = { \
1044 .system = __stringify(TRACE_SYSTEM), \
1045 .define_fields = ftrace_define_fields_##call, \
1046 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
1047 .raw_init = trace_event_raw_init, \
1048 .probe = ftrace_raw_event_##call, \
1049 .reg = ftrace_event_reg, \
1050 _TRACE_PERF_INIT(call) \
1054 #define DEFINE_EVENT(template, call, proto, args) \
1056 static struct ftrace_event_call __used \
1057 __attribute__((__aligned__(4))) \
1058 __attribute__((section("_ftrace_events"))) event_##call = { \
1060 .class = &event_class_##template, \
1061 .event.funcs = &ftrace_event_type_funcs_##template, \
1062 .print_fmt = print_fmt_##template, \
1065 #undef DEFINE_EVENT_PRINT
1066 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
1068 static const char print_fmt_##call[] = print; \
1070 static struct ftrace_event_call __used \
1071 __attribute__((__aligned__(4))) \
1072 __attribute__((section("_ftrace_events"))) event_##call = { \
1074 .class = &event_class_##template, \
1075 .event.funcs = &ftrace_event_type_funcs_##call, \
1076 .print_fmt = print_fmt_##call, \
1079 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1082 * Define the insertion callback to perf events
1084 * The job is very similar to ftrace_raw_event_<call> except that we don't
1085 * insert in the ring buffer but in a perf counter.
1087 * static void ftrace_perf_<call>(proto)
1089 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
1090 * struct ftrace_event_call *event_call = &event_<call>;
1091 * extern void perf_tp_event(int, u64, u64, void *, int);
1092 * struct ftrace_raw_##call *entry;
1093 * struct perf_trace_buf *trace_buf;
1094 * u64 __addr = 0, __count = 1;
1095 * unsigned long irq_flags;
1096 * struct trace_entry *ent;
1102 * pc = preempt_count();
1104 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
1106 * // Below we want to get the aligned size by taking into account
1107 * // the u32 field that will later store the buffer size
1108 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
1110 * __entry_size -= sizeof(u32);
1112 * // Protect the non nmi buffer
1113 * // This also protects the rcu read side
1114 * local_irq_save(irq_flags);
1115 * __cpu = smp_processor_id();
1118 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
1120 * trace_buf = rcu_dereference_sched(perf_trace_buf);
1125 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
1127 * // Avoid recursion from perf that could mess up the buffer
1128 * if (trace_buf->recursion++)
1129 * goto end_recursion;
1131 * raw_data = trace_buf->buf;
1133 * // Make recursion update visible before entering perf_tp_event
1134 * // so that we protect from perf recursions.
1138 * //zero dead bytes from alignment to avoid stack leak to userspace:
1139 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
1140 * entry = (struct ftrace_raw_<call> *)raw_data;
1141 * ent = &entry->ent;
1142 * tracing_generic_entry_update(ent, irq_flags, pc);
1143 * ent->type = event_call->id;
1145 * <tstruct> <- do some jobs with dynamic arrays
1147 * <assign> <- affect our values
1149 * perf_tp_event(event_call->id, __addr, __count, entry,
1150 * __entry_size); <- submit them to perf counter
1155 #ifdef CONFIG_PERF_EVENTS
1158 #define __entry entry
1160 #undef __get_dynamic_array
1161 #define __get_dynamic_array(field) \
1162 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
1165 #define __get_str(field) (char *)__get_dynamic_array(field)
1168 #define __perf_addr(a) __addr = (a)
1171 #define __perf_count(c) __count = (c)
1173 #undef DECLARE_EVENT_CLASS
1174 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1175 static notrace void \
1176 perf_trace_##call(void *__data, proto) \
1178 struct ftrace_event_call *event_call = __data; \
1179 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
1180 struct ftrace_raw_##call *entry; \
1181 struct pt_regs __regs; \
1182 u64 __addr = 0, __count = 1; \
1183 struct hlist_head *head; \
1188 perf_fetch_caller_regs(&__regs); \
1190 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1191 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
1193 __entry_size -= sizeof(u32); \
1195 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
1196 "profile buffer not large enough")) \
1199 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
1200 __entry_size, event_call->event.type, &__regs, &rctx); \
1208 head = this_cpu_ptr(event_call->perf_events); \
1209 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
1210 __count, &__regs, head); \
1214 * This part is compiled out, it is only here as a build time check
1215 * to make sure that if the tracepoint handling changes, the
1216 * perf probe will fail to compile unless it too is updated.
1219 #define DEFINE_EVENT(template, call, proto, args) \
1220 static inline void perf_test_probe_##call(void) \
1222 check_trace_callback_type_##call(perf_trace_##template); \
1226 #undef DEFINE_EVENT_PRINT
1227 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
1228 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
1230 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1231 #endif /* CONFIG_PERF_EVENTS */
1233 #undef _TRACE_PROFILE_INIT
This page took 0.057682 seconds and 4 git commands to generate.