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)
155 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
158 const struct lttng_event_desc
*desc
=
159 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
161 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
162 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
164 return (void *) desc
;
167 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
168 void *p
, loff_t
*ppos
)
170 const struct lttng_event_desc
*desc
=
171 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
173 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
174 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
176 return (void *) desc
;
179 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
184 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
187 const struct lttng_event_desc
*desc
= p
;
190 seq_printf(m
, "event {\n"
193 "\tstream = UNKNOWN;\n"
196 for (i
= 0; i
< desc
->nr_fields
; i
++) {
197 if (desc
->fields
[i
].type
.name
) /* Named type */
198 seq_printf(m
, "\t\t%s",
199 desc
->fields
[i
].type
.name
);
200 else /* Nameless type */
201 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
202 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
204 seq_printf(m
, "\t};\n");
205 seq_printf(m
, "};\n");
210 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
211 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
212 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
213 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
214 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
218 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
220 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
224 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
225 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
228 .release
= seq_release_private
,
231 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
233 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
237 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
238 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
240 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
241 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
242 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
243 printk(KERN_ERR
"Error creating LTTng type export file\n");
251 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
253 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
260 * Stage 4 of the trace events.
262 * Create static inline function that calculates event size.
265 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
267 /* Named field types must be defined in lttng-types.h */
270 #define __field(_type, _item) \
271 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
272 __event_len += sizeof(_type);
275 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
278 #define __array(_type, _item, _length) \
279 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
280 __event_len += sizeof(_type) * (_length);
282 #undef __dynamic_array
283 #define __dynamic_array(_type, _item, _length) \
284 __event_len += lib_ring_buffer_align(__event_len, __alignof__(u32)); \
285 __event_len += sizeof(u32); \
286 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
287 __event_len += sizeof(_type) * (_length);
290 #define __string(_item, _src) \
291 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
294 #define TP_PROTO(args...) args
296 #undef TP_STRUCT__entry
297 #define TP_STRUCT__entry(args...) args
299 #undef DECLARE_EVENT_CLASS
300 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
301 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
303 size_t __event_len = 0; \
304 unsigned int __dynamic_len_idx = 0; \
307 (void) __dynamic_len_idx; /* don't warn if unused */ \
309 return __event_len; \
312 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
317 * Stage 5 of the trace events.
319 * Create static inline function that calculates event payload alignment.
322 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
324 /* Named field types must be defined in lttng-types.h */
327 #define __field(_type, _item) \
328 __event_align = max_t(size_t, __event_align, __alignof__(_type));
331 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
334 #define __array(_type, _item, _length) \
335 __event_align = max_t(size_t, __event_align, __alignof__(_type));
337 #undef __dynamic_array
338 #define __dynamic_array(_type, _item, _length) \
339 __event_align = max_t(size_t, __event_align, __alignof__(u32)); \
340 __event_align = max_t(size_t, __event_align, __alignof__(_type));
343 #define __string(_item, _src)
346 #define TP_PROTO(args...) args
348 #undef TP_STRUCT__entry
349 #define TP_STRUCT__entry(args...) args
351 #undef DECLARE_EVENT_CLASS
352 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
353 static inline size_t __event_get_align__##_name(_proto) \
355 size_t __event_align = 1; \
357 return __event_align; \
360 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
364 * Stage 6 of the trace events.
366 * Create structure declaration that allows the "assign" macros to access the
370 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
372 /* Named field types must be defined in lttng-types.h */
375 #define __field(_type, _item) _type _item;
378 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
381 #define __array(_type, _item, _length) _type _item;
383 #undef __dynamic_array
384 #define __dynamic_array(_type, _item, _length) _type _item;
387 #define __string(_item, _src) char _item;
389 #undef TP_STRUCT__entry
390 #define TP_STRUCT__entry(args...) args
392 #undef DECLARE_EVENT_CLASS
393 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
394 struct __event_typemap__##_name { \
398 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
402 * Stage 7 of the trace events.
404 * Create the probe function : call even size calculation and write event data
407 * We use both the field and assignment macros to write the fields in the order
408 * defined in the field declaration. The field declarations control the
409 * execution order, jumping to the appropriate assignment block.
412 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
415 #define __field(_type, _item) \
416 goto __assign_##_item; \
420 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
423 #define __array(_type, _item, _length) \
424 goto __assign_##_item; \
427 #undef __dynamic_array
428 #define __dynamic_array(_type, _item, _length) \
429 goto __assign_##_item##_1; \
430 __end_field_##_item##_1: \
431 goto __assign_##_item##_2; \
432 __end_field_##_item##_2:
435 #define __string(_item, _src) \
436 goto __assign_##_item; \
440 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
444 #define tp_assign(dest, src) \
447 __typeof__(__typemap.dest) __tmp = (src); \
448 lib_ring_buffer_align_ctx(&ctx, __alignof__(__tmp)); \
449 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
451 goto __end_field_##dest;
454 #define tp_memcpy(dest, src, len) \
456 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
457 __chan->ops->event_write(&ctx, src, len); \
458 goto __end_field_##dest;
461 #define tp_memcpy_dyn(dest, src, len) \
462 __assign_##dest##_1: \
464 u32 __tmpl = (len); \
465 lib_ring_buffer_align_ctx(&ctx, __alignof__(u32)); \
466 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
468 goto __end_field_##dest##_1; \
469 __assign_##dest##_2: \
470 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
471 __chan->ops->event_write(&ctx, src, len); \
472 goto __end_field_##dest##_2;
475 #define tp_strcpy(dest, src) \
476 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
478 /* Named field types must be defined in lttng-types.h */
481 #define __get_str(field) field
483 #undef __get_dynamic_array
484 #define __get_dynamic_array(field) field
486 /* Beware: this get len actually consumes the len value */
487 #undef __get_dynamic_array_len
488 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
491 #define TP_PROTO(args...) args
494 #define TP_ARGS(args...) args
496 #undef TP_STRUCT__entry
497 #define TP_STRUCT__entry(args...) args
499 #undef TP_fast_assign
500 #define TP_fast_assign(args...) args
502 #undef DECLARE_EVENT_CLASS
503 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
504 static void __event_probe__##_name(void *__data, _proto) \
506 struct ltt_event *__event = __data; \
507 struct ltt_channel *__chan = __event->chan; \
508 struct lib_ring_buffer_ctx ctx; \
509 size_t __event_len, __event_align; \
510 size_t __dynamic_len_idx = 0; \
511 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
512 struct __event_typemap__##_name __typemap; \
516 (void) __dynamic_len_idx; /* don't warn if unused */ \
517 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
518 __event_align = __event_get_align__##_name(_args); \
519 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
520 __event_align, -1); \
521 __ret = __chan->ops->event_reserve(&ctx); \
524 /* Control code (field ordering) */ \
526 __chan->ops->event_commit(&ctx); \
528 /* Copy code, steered by control code */ \
532 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
536 * Stage 8 of the trace events.
538 * Register/unregister probes at module load/unload.
541 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
543 #define TP_ID1(_token, _system) _token##_system
544 #define TP_ID(_token, _system) TP_ID1(_token, _system)
545 #define module_init_eval1(_token, _system) module_init(_token##_system)
546 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
547 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
548 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
551 #define DEFINE_EVENT(_template, _name, _proto, _args) \
552 ret = ltt_probe_register(#_name, (void *) __event_probe__##_template); \
555 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
559 ret
= TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)();
562 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
566 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
569 #define DEFINE_EVENT(_template, _name, _proto, _args) \
570 ltt_probe_unregister(#_name);
572 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
574 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
575 TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)();
578 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
580 #undef module_init_eval
581 #undef module_exit_eval
587 #include <linux/ftrace_event.h>
590 * DECLARE_EVENT_CLASS can be used to add a generic function
591 * handlers for events. That is, if all events have the same
592 * parameters and just have distinct trace points.
593 * Each tracepoint can be defined with DEFINE_EVENT and that
594 * will map the DECLARE_EVENT_CLASS to the tracepoint.
596 * TRACE_EVENT is a one to one mapping between tracepoint and template.
599 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
600 DECLARE_EVENT_CLASS(name, \
606 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
610 #define __field(type, item) type item;
613 #define __field_ext(type, item, filter_type) type item;
616 #define __array(type, item, len) type item[len];
618 #undef __dynamic_array
619 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
622 #define __string(item, src) __dynamic_array(char, item, -1)
624 #undef TP_STRUCT__entry
625 #define TP_STRUCT__entry(args...) args
627 #undef DECLARE_EVENT_CLASS
628 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
629 struct ftrace_raw_##name { \
630 struct trace_entry ent; \
635 static struct ftrace_event_class event_class_##name;
638 #define DEFINE_EVENT(template, name, proto, args) \
639 static struct ftrace_event_call __used \
640 __attribute__((__aligned__(4))) event_##name
642 #undef DEFINE_EVENT_PRINT
643 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
644 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
646 /* Callbacks are meaningless to ftrace. */
647 #undef TRACE_EVENT_FN
648 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
649 assign, print, reg, unreg) \
650 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
651 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
653 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
657 * Stage 2 of the trace events.
659 * Create static inline function that calculates event size.
663 #define __field(type, item)
666 #define __field_ext(type, item, filter_type)
669 #define __array(type, item, len)
671 #undef __dynamic_array
672 #define __dynamic_array(type, item, len) u32 item;
675 #define __string(item, src) __dynamic_array(char, item, -1)
677 #undef DECLARE_EVENT_CLASS
678 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
679 struct ftrace_data_offsets_##call { \
684 #define DEFINE_EVENT(template, name, proto, args)
686 #undef DEFINE_EVENT_PRINT
687 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
688 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
690 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
693 * Stage 3 of the trace events.
695 * Create the probe function : call even size calculation and write event data
700 #define __entry field
703 #define TP_printk(fmt, args...) fmt "\n", args
705 #undef __get_dynamic_array
706 #define __get_dynamic_array(field) \
707 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
710 #define __get_str(field) (char *)__get_dynamic_array(field)
713 #define __print_flags(flag, delim, flag_array...) \
715 static const struct trace_print_flags __flags[] = \
716 { flag_array, { -1, NULL }}; \
717 ftrace_print_flags_seq(p, delim, flag, __flags); \
720 #undef __print_symbolic
721 #define __print_symbolic(value, symbol_array...) \
723 static const struct trace_print_flags symbols[] = \
724 { symbol_array, { -1, NULL }}; \
725 ftrace_print_symbols_seq(p, value, symbols); \
729 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
731 #undef DECLARE_EVENT_CLASS
732 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
733 static notrace enum print_line_t \
734 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
735 struct trace_event *trace_event) \
737 struct ftrace_event_call *event; \
738 struct trace_seq *s = &iter->seq; \
739 struct ftrace_raw_##call *field; \
740 struct trace_entry *entry; \
741 struct trace_seq *p = &iter->tmp_seq; \
744 event = container_of(trace_event, struct ftrace_event_call, \
749 if (entry->type != event->event.type) { \
751 return TRACE_TYPE_UNHANDLED; \
754 field = (typeof(field))entry; \
757 ret = trace_seq_printf(s, "%s: ", event->name); \
759 ret = trace_seq_printf(s, print); \
761 return TRACE_TYPE_PARTIAL_LINE; \
763 return TRACE_TYPE_HANDLED; \
765 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
766 .trace = ftrace_raw_output_##call, \
769 #undef DEFINE_EVENT_PRINT
770 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
771 static notrace enum print_line_t \
772 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
773 struct trace_event *event) \
775 struct trace_seq *s = &iter->seq; \
776 struct ftrace_raw_##template *field; \
777 struct trace_entry *entry; \
778 struct trace_seq *p = &iter->tmp_seq; \
783 if (entry->type != event_##call.event.type) { \
785 return TRACE_TYPE_UNHANDLED; \
788 field = (typeof(field))entry; \
791 ret = trace_seq_printf(s, "%s: ", #call); \
793 ret = trace_seq_printf(s, print); \
795 return TRACE_TYPE_PARTIAL_LINE; \
797 return TRACE_TYPE_HANDLED; \
799 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
800 .trace = ftrace_raw_output_##call, \
803 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
806 #define __field_ext(type, item, filter_type) \
807 ret = trace_define_field(event_call, #type, #item, \
808 offsetof(typeof(field), item), \
809 sizeof(field.item), \
810 is_signed_type(type), filter_type); \
815 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
818 #define __array(type, item, len) \
819 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
820 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
821 offsetof(typeof(field), item), \
822 sizeof(field.item), \
823 is_signed_type(type), FILTER_OTHER); \
827 #undef __dynamic_array
828 #define __dynamic_array(type, item, len) \
829 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
830 offsetof(typeof(field), __data_loc_##item), \
831 sizeof(field.__data_loc_##item), \
832 is_signed_type(type), FILTER_OTHER);
835 #define __string(item, src) __dynamic_array(char, item, -1)
837 #undef DECLARE_EVENT_CLASS
838 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
840 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
842 struct ftrace_raw_##call field; \
851 #define DEFINE_EVENT(template, name, proto, args)
853 #undef DEFINE_EVENT_PRINT
854 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
855 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
857 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
860 * remember the offset of each array from the beginning of the event.
864 #define __entry entry
867 #define __field(type, item)
870 #define __field_ext(type, item, filter_type)
873 #define __array(type, item, len)
875 #undef __dynamic_array
876 #define __dynamic_array(type, item, len) \
877 __data_offsets->item = __data_size + \
878 offsetof(typeof(*entry), __data); \
879 __data_offsets->item |= (len * sizeof(type)) << 16; \
880 __data_size += (len) * sizeof(type);
883 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
885 #undef DECLARE_EVENT_CLASS
886 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
887 static inline notrace int ftrace_get_offsets_##call( \
888 struct ftrace_data_offsets_##call *__data_offsets, proto) \
890 int __data_size = 0; \
891 struct ftrace_raw_##call __maybe_unused *entry; \
895 return __data_size; \
899 #define DEFINE_EVENT(template, name, proto, args)
901 #undef DEFINE_EVENT_PRINT
902 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
903 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
905 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
908 * Stage 4 of the trace events.
910 * Override the macros in <trace/trace_events.h> to include the following:
912 * For those macros defined with TRACE_EVENT:
914 * static struct ftrace_event_call event_<call>;
916 * static void ftrace_raw_event_<call>(void *__data, proto)
918 * struct ftrace_event_call *event_call = __data;
919 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
920 * struct ring_buffer_event *event;
921 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
922 * struct ring_buffer *buffer;
923 * unsigned long irq_flags;
927 * local_save_flags(irq_flags);
928 * pc = preempt_count();
930 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
932 * event = trace_current_buffer_lock_reserve(&buffer,
933 * event_<call>->event.type,
934 * sizeof(*entry) + __data_size,
938 * entry = ring_buffer_event_data(event);
940 * { <assign>; } <-- Here we assign the entries by the __field and
943 * if (!filter_current_check_discard(buffer, event_call, entry, event))
944 * trace_current_buffer_unlock_commit(buffer,
945 * event, irq_flags, pc);
948 * static struct trace_event ftrace_event_type_<call> = {
949 * .trace = ftrace_raw_output_<call>, <-- stage 2
952 * static const char print_fmt_<call>[] = <TP_printk>;
954 * static struct ftrace_event_class __used event_class_<template> = {
955 * .system = "<system>",
956 * .define_fields = ftrace_define_fields_<call>,
957 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
958 * .raw_init = trace_event_raw_init,
959 * .probe = ftrace_raw_event_##call,
960 * .reg = ftrace_event_reg,
963 * static struct ftrace_event_call __used
964 * __attribute__((__aligned__(4)))
965 * __attribute__((section("_ftrace_events"))) event_<call> = {
967 * .class = event_class_<template>,
968 * .event = &ftrace_event_type_<call>,
969 * .print_fmt = print_fmt_<call>,
974 #ifdef CONFIG_PERF_EVENTS
976 #define _TRACE_PERF_PROTO(call, proto) \
977 static notrace void \
978 perf_trace_##call(void *__data, proto);
980 #define _TRACE_PERF_INIT(call) \
981 .perf_probe = perf_trace_##call,
984 #define _TRACE_PERF_PROTO(call, proto)
985 #define _TRACE_PERF_INIT(call)
986 #endif /* CONFIG_PERF_EVENTS */
989 #define __entry entry
992 #define __field(type, item)
995 #define __array(type, item, len)
997 #undef __dynamic_array
998 #define __dynamic_array(type, item, len) \
999 __entry->__data_loc_##item = __data_offsets.item;
1002 #define __string(item, src) __dynamic_array(char, item, -1) \
1005 #define __assign_str(dst, src) \
1006 strcpy(__get_str(dst), src);
1008 #undef TP_fast_assign
1009 #define TP_fast_assign(args...) args
1011 #undef TP_perf_assign
1012 #define TP_perf_assign(args...)
1014 #undef DECLARE_EVENT_CLASS
1015 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1017 static notrace void \
1018 ftrace_raw_event_##call(void *__data, proto) \
1020 struct ftrace_event_call *event_call = __data; \
1021 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
1022 struct ring_buffer_event *event; \
1023 struct ftrace_raw_##call *entry; \
1024 struct ring_buffer *buffer; \
1025 unsigned long irq_flags; \
1029 local_save_flags(irq_flags); \
1030 pc = preempt_count(); \
1032 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1034 event = trace_current_buffer_lock_reserve(&buffer, \
1035 event_call->event.type, \
1036 sizeof(*entry) + __data_size, \
1040 entry = ring_buffer_event_data(event); \
1046 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
1047 trace_nowake_buffer_unlock_commit(buffer, \
1048 event, irq_flags, pc); \
1051 * The ftrace_test_probe is compiled out, it is only here as a build time check
1052 * to make sure that if the tracepoint handling changes, the ftrace probe will
1053 * fail to compile unless it too is updated.
1057 #define DEFINE_EVENT(template, call, proto, args) \
1058 static inline void ftrace_test_probe_##call(void) \
1060 check_trace_callback_type_##call(ftrace_raw_event_##template); \
1063 #undef DEFINE_EVENT_PRINT
1064 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
1066 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1071 #undef __print_flags
1072 #undef __print_symbolic
1073 #undef __get_dynamic_array
1077 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
1079 #undef DECLARE_EVENT_CLASS
1080 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1081 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
1082 static const char print_fmt_##call[] = print; \
1083 static struct ftrace_event_class __used event_class_##call = { \
1084 .system = __stringify(TRACE_SYSTEM), \
1085 .define_fields = ftrace_define_fields_##call, \
1086 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
1087 .raw_init = trace_event_raw_init, \
1088 .probe = ftrace_raw_event_##call, \
1089 .reg = ftrace_event_reg, \
1090 _TRACE_PERF_INIT(call) \
1094 #define DEFINE_EVENT(template, call, proto, args) \
1096 static struct ftrace_event_call __used \
1097 __attribute__((__aligned__(4))) \
1098 __attribute__((section("_ftrace_events"))) event_##call = { \
1100 .class = &event_class_##template, \
1101 .event.funcs = &ftrace_event_type_funcs_##template, \
1102 .print_fmt = print_fmt_##template, \
1105 #undef DEFINE_EVENT_PRINT
1106 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
1108 static const char print_fmt_##call[] = print; \
1110 static struct ftrace_event_call __used \
1111 __attribute__((__aligned__(4))) \
1112 __attribute__((section("_ftrace_events"))) event_##call = { \
1114 .class = &event_class_##template, \
1115 .event.funcs = &ftrace_event_type_funcs_##call, \
1116 .print_fmt = print_fmt_##call, \
1119 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1122 * Define the insertion callback to perf events
1124 * The job is very similar to ftrace_raw_event_<call> except that we don't
1125 * insert in the ring buffer but in a perf counter.
1127 * static void ftrace_perf_<call>(proto)
1129 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
1130 * struct ftrace_event_call *event_call = &event_<call>;
1131 * extern void perf_tp_event(int, u64, u64, void *, int);
1132 * struct ftrace_raw_##call *entry;
1133 * struct perf_trace_buf *trace_buf;
1134 * u64 __addr = 0, __count = 1;
1135 * unsigned long irq_flags;
1136 * struct trace_entry *ent;
1142 * pc = preempt_count();
1144 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
1146 * // Below we want to get the aligned size by taking into account
1147 * // the u32 field that will later store the buffer size
1148 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
1150 * __entry_size -= sizeof(u32);
1152 * // Protect the non nmi buffer
1153 * // This also protects the rcu read side
1154 * local_irq_save(irq_flags);
1155 * __cpu = smp_processor_id();
1158 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
1160 * trace_buf = rcu_dereference_sched(perf_trace_buf);
1165 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
1167 * // Avoid recursion from perf that could mess up the buffer
1168 * if (trace_buf->recursion++)
1169 * goto end_recursion;
1171 * raw_data = trace_buf->buf;
1173 * // Make recursion update visible before entering perf_tp_event
1174 * // so that we protect from perf recursions.
1178 * //zero dead bytes from alignment to avoid stack leak to userspace:
1179 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
1180 * entry = (struct ftrace_raw_<call> *)raw_data;
1181 * ent = &entry->ent;
1182 * tracing_generic_entry_update(ent, irq_flags, pc);
1183 * ent->type = event_call->id;
1185 * <tstruct> <- do some jobs with dynamic arrays
1187 * <assign> <- affect our values
1189 * perf_tp_event(event_call->id, __addr, __count, entry,
1190 * __entry_size); <- submit them to perf counter
1195 #ifdef CONFIG_PERF_EVENTS
1198 #define __entry entry
1200 #undef __get_dynamic_array
1201 #define __get_dynamic_array(field) \
1202 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
1205 #define __get_str(field) (char *)__get_dynamic_array(field)
1208 #define __perf_addr(a) __addr = (a)
1211 #define __perf_count(c) __count = (c)
1213 #undef DECLARE_EVENT_CLASS
1214 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1215 static notrace void \
1216 perf_trace_##call(void *__data, proto) \
1218 struct ftrace_event_call *event_call = __data; \
1219 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
1220 struct ftrace_raw_##call *entry; \
1221 struct pt_regs __regs; \
1222 u64 __addr = 0, __count = 1; \
1223 struct hlist_head *head; \
1228 perf_fetch_caller_regs(&__regs); \
1230 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1231 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
1233 __entry_size -= sizeof(u32); \
1235 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
1236 "profile buffer not large enough")) \
1239 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
1240 __entry_size, event_call->event.type, &__regs, &rctx); \
1248 head = this_cpu_ptr(event_call->perf_events); \
1249 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
1250 __count, &__regs, head); \
1254 * This part is compiled out, it is only here as a build time check
1255 * to make sure that if the tracepoint handling changes, the
1256 * perf probe will fail to compile unless it too is updated.
1259 #define DEFINE_EVENT(template, call, proto, args) \
1260 static inline void perf_test_probe_##call(void) \
1262 check_trace_callback_type_##call(perf_trace_##template); \
1266 #undef DEFINE_EVENT_PRINT
1267 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
1268 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
1270 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1271 #endif /* CONFIG_PERF_EVENTS */
1273 #undef _TRACE_PROFILE_INIT
This page took 0.065998 seconds and 5 git commands to generate.