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, sizeof(_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, sizeof(_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, sizeof(u32)); \
295 __event_len += sizeof(u32); \
296 __event_len += lib_ring_buffer_align(__event_len, sizeof(_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)
375 * Stage 6 of the trace events.
377 * Create the probe function : call even size calculation and write event data
380 * We use both the field and assignment macros to write the fields in the order
381 * defined in the field declaration. The field declarations control the
382 * execution order, jumping to the appropriate assignment block.
385 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
388 #define __field(_type, _item) \
389 lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
390 goto __assign_##_item; \
394 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
397 #define __array(_type, _item, _length) \
398 lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
399 goto __assign_##_item; \
402 #undef __dynamic_array
403 #define __dynamic_array(_type, _item, _length) \
404 lib_ring_buffer_align_ctx(&ctx, sizeof(u32)); \
405 goto __assign_##_item##_1; \
406 __end_field_##_item##_1: \
407 lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
408 goto __assign_##_item##_2; \
409 __end_field_##_item##_2:
412 #define __string(_item, _src) \
413 goto __assign_##_item; \
417 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
421 #define tp_assign(dest, src) \
424 __typeof__(src) __tmp = (src); \
425 __chan->ops->event_write(&ctx, &__tmp, sizeof(src)); \
427 goto __end_field_##dest;
430 #define tp_memcpy(dest, src, len) \
432 __chan->ops->event_write(&ctx, src, len); \
433 goto __end_field_##dest;
436 #define tp_memcpy_dyn(dest, src, len) \
437 __assign_##dest##_1: \
439 __typeof__(len) __tmpl = (len); \
440 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
442 goto __end_field_##dest##_1; \
443 __assign_##dest##_2: \
444 __chan->ops->event_write(&ctx, src, len); \
445 goto __end_field_##dest##_2;
448 #define tp_strcpy(dest, src) \
449 tp_memcpy(dest, src, __get_dynamic_array_len(dest)); \
451 /* Named field types must be defined in lttng-types.h */
454 #define __get_str(field) field
456 #undef __get_dynamic_array
457 #define __get_dynamic_array(field) field
459 /* Beware: this get len actually consumes the len value */
460 #undef __get_dynamic_array_len
461 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
464 #define TP_PROTO(args...) args
467 #define TP_ARGS(args...) args
469 #undef TP_STRUCT__entry
470 #define TP_STRUCT__entry(args...) args
472 #undef TP_fast_assign
473 #define TP_fast_assign(args...) args
475 #undef DECLARE_EVENT_CLASS
476 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
477 static void __event_probe__##_name(void *__data, _proto) \
479 struct ltt_event *__event = __data; \
480 struct ltt_channel *__chan = __event->chan; \
481 struct lib_ring_buffer_ctx ctx; \
482 size_t __event_len, __event_align; \
483 size_t __dynamic_len_idx = 0; \
484 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
488 (void) __dynamic_len_idx; /* don't warn if unused */ \
489 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
490 __event_align = __event_get_align__##_name(_args); \
491 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
492 __event_align, -1); \
493 __ret = __chan->ops->event_reserve(&ctx); \
496 /* Control code (field ordering) */ \
498 __chan->ops->event_commit(&ctx); \
500 /* Copy code, steered by control code */ \
504 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
509 #include <linux/ftrace_event.h>
512 * DECLARE_EVENT_CLASS can be used to add a generic function
513 * handlers for events. That is, if all events have the same
514 * parameters and just have distinct trace points.
515 * Each tracepoint can be defined with DEFINE_EVENT and that
516 * will map the DECLARE_EVENT_CLASS to the tracepoint.
518 * TRACE_EVENT is a one to one mapping between tracepoint and template.
521 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
522 DECLARE_EVENT_CLASS(name, \
528 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
532 #define __field(type, item) type item;
535 #define __field_ext(type, item, filter_type) type item;
538 #define __array(type, item, len) type item[len];
540 #undef __dynamic_array
541 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
544 #define __string(item, src) __dynamic_array(char, item, -1)
546 #undef TP_STRUCT__entry
547 #define TP_STRUCT__entry(args...) args
549 #undef DECLARE_EVENT_CLASS
550 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
551 struct ftrace_raw_##name { \
552 struct trace_entry ent; \
557 static struct ftrace_event_class event_class_##name;
560 #define DEFINE_EVENT(template, name, proto, args) \
561 static struct ftrace_event_call __used \
562 __attribute__((__aligned__(4))) event_##name
564 #undef DEFINE_EVENT_PRINT
565 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
566 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
568 /* Callbacks are meaningless to ftrace. */
569 #undef TRACE_EVENT_FN
570 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
571 assign, print, reg, unreg) \
572 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
573 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
575 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
579 * Stage 2 of the trace events.
581 * Create static inline function that calculates event size.
585 #define __field(type, item)
588 #define __field_ext(type, item, filter_type)
591 #define __array(type, item, len)
593 #undef __dynamic_array
594 #define __dynamic_array(type, item, len) u32 item;
597 #define __string(item, src) __dynamic_array(char, item, -1)
599 #undef DECLARE_EVENT_CLASS
600 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
601 struct ftrace_data_offsets_##call { \
606 #define DEFINE_EVENT(template, name, proto, args)
608 #undef DEFINE_EVENT_PRINT
609 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
610 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
612 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
615 * Stage 3 of the trace events.
617 * Create the probe function : call even size calculation and write event data
622 #define __entry field
625 #define TP_printk(fmt, args...) fmt "\n", args
627 #undef __get_dynamic_array
628 #define __get_dynamic_array(field) \
629 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
632 #define __get_str(field) (char *)__get_dynamic_array(field)
635 #define __print_flags(flag, delim, flag_array...) \
637 static const struct trace_print_flags __flags[] = \
638 { flag_array, { -1, NULL }}; \
639 ftrace_print_flags_seq(p, delim, flag, __flags); \
642 #undef __print_symbolic
643 #define __print_symbolic(value, symbol_array...) \
645 static const struct trace_print_flags symbols[] = \
646 { symbol_array, { -1, NULL }}; \
647 ftrace_print_symbols_seq(p, value, symbols); \
651 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
653 #undef DECLARE_EVENT_CLASS
654 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
655 static notrace enum print_line_t \
656 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
657 struct trace_event *trace_event) \
659 struct ftrace_event_call *event; \
660 struct trace_seq *s = &iter->seq; \
661 struct ftrace_raw_##call *field; \
662 struct trace_entry *entry; \
663 struct trace_seq *p = &iter->tmp_seq; \
666 event = container_of(trace_event, struct ftrace_event_call, \
671 if (entry->type != event->event.type) { \
673 return TRACE_TYPE_UNHANDLED; \
676 field = (typeof(field))entry; \
679 ret = trace_seq_printf(s, "%s: ", event->name); \
681 ret = trace_seq_printf(s, print); \
683 return TRACE_TYPE_PARTIAL_LINE; \
685 return TRACE_TYPE_HANDLED; \
687 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
688 .trace = ftrace_raw_output_##call, \
691 #undef DEFINE_EVENT_PRINT
692 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
693 static notrace enum print_line_t \
694 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
695 struct trace_event *event) \
697 struct trace_seq *s = &iter->seq; \
698 struct ftrace_raw_##template *field; \
699 struct trace_entry *entry; \
700 struct trace_seq *p = &iter->tmp_seq; \
705 if (entry->type != event_##call.event.type) { \
707 return TRACE_TYPE_UNHANDLED; \
710 field = (typeof(field))entry; \
713 ret = trace_seq_printf(s, "%s: ", #call); \
715 ret = trace_seq_printf(s, print); \
717 return TRACE_TYPE_PARTIAL_LINE; \
719 return TRACE_TYPE_HANDLED; \
721 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
722 .trace = ftrace_raw_output_##call, \
725 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
728 #define __field_ext(type, item, filter_type) \
729 ret = trace_define_field(event_call, #type, #item, \
730 offsetof(typeof(field), item), \
731 sizeof(field.item), \
732 is_signed_type(type), filter_type); \
737 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
740 #define __array(type, item, len) \
741 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
742 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
743 offsetof(typeof(field), item), \
744 sizeof(field.item), \
745 is_signed_type(type), FILTER_OTHER); \
749 #undef __dynamic_array
750 #define __dynamic_array(type, item, len) \
751 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
752 offsetof(typeof(field), __data_loc_##item), \
753 sizeof(field.__data_loc_##item), \
754 is_signed_type(type), FILTER_OTHER);
757 #define __string(item, src) __dynamic_array(char, item, -1)
759 #undef DECLARE_EVENT_CLASS
760 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
762 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
764 struct ftrace_raw_##call field; \
773 #define DEFINE_EVENT(template, name, proto, args)
775 #undef DEFINE_EVENT_PRINT
776 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
777 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
779 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
782 * remember the offset of each array from the beginning of the event.
786 #define __entry entry
789 #define __field(type, item)
792 #define __field_ext(type, item, filter_type)
795 #define __array(type, item, len)
797 #undef __dynamic_array
798 #define __dynamic_array(type, item, len) \
799 __data_offsets->item = __data_size + \
800 offsetof(typeof(*entry), __data); \
801 __data_offsets->item |= (len * sizeof(type)) << 16; \
802 __data_size += (len) * sizeof(type);
805 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
807 #undef DECLARE_EVENT_CLASS
808 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
809 static inline notrace int ftrace_get_offsets_##call( \
810 struct ftrace_data_offsets_##call *__data_offsets, proto) \
812 int __data_size = 0; \
813 struct ftrace_raw_##call __maybe_unused *entry; \
817 return __data_size; \
821 #define DEFINE_EVENT(template, name, proto, args)
823 #undef DEFINE_EVENT_PRINT
824 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
825 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
827 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
830 * Stage 4 of the trace events.
832 * Override the macros in <trace/trace_events.h> to include the following:
834 * For those macros defined with TRACE_EVENT:
836 * static struct ftrace_event_call event_<call>;
838 * static void ftrace_raw_event_<call>(void *__data, proto)
840 * struct ftrace_event_call *event_call = __data;
841 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
842 * struct ring_buffer_event *event;
843 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
844 * struct ring_buffer *buffer;
845 * unsigned long irq_flags;
849 * local_save_flags(irq_flags);
850 * pc = preempt_count();
852 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
854 * event = trace_current_buffer_lock_reserve(&buffer,
855 * event_<call>->event.type,
856 * sizeof(*entry) + __data_size,
860 * entry = ring_buffer_event_data(event);
862 * { <assign>; } <-- Here we assign the entries by the __field and
865 * if (!filter_current_check_discard(buffer, event_call, entry, event))
866 * trace_current_buffer_unlock_commit(buffer,
867 * event, irq_flags, pc);
870 * static struct trace_event ftrace_event_type_<call> = {
871 * .trace = ftrace_raw_output_<call>, <-- stage 2
874 * static const char print_fmt_<call>[] = <TP_printk>;
876 * static struct ftrace_event_class __used event_class_<template> = {
877 * .system = "<system>",
878 * .define_fields = ftrace_define_fields_<call>,
879 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
880 * .raw_init = trace_event_raw_init,
881 * .probe = ftrace_raw_event_##call,
882 * .reg = ftrace_event_reg,
885 * static struct ftrace_event_call __used
886 * __attribute__((__aligned__(4)))
887 * __attribute__((section("_ftrace_events"))) event_<call> = {
889 * .class = event_class_<template>,
890 * .event = &ftrace_event_type_<call>,
891 * .print_fmt = print_fmt_<call>,
896 #ifdef CONFIG_PERF_EVENTS
898 #define _TRACE_PERF_PROTO(call, proto) \
899 static notrace void \
900 perf_trace_##call(void *__data, proto);
902 #define _TRACE_PERF_INIT(call) \
903 .perf_probe = perf_trace_##call,
906 #define _TRACE_PERF_PROTO(call, proto)
907 #define _TRACE_PERF_INIT(call)
908 #endif /* CONFIG_PERF_EVENTS */
911 #define __entry entry
914 #define __field(type, item)
917 #define __array(type, item, len)
919 #undef __dynamic_array
920 #define __dynamic_array(type, item, len) \
921 __entry->__data_loc_##item = __data_offsets.item;
924 #define __string(item, src) __dynamic_array(char, item, -1) \
927 #define __assign_str(dst, src) \
928 strcpy(__get_str(dst), src);
930 #undef TP_fast_assign
931 #define TP_fast_assign(args...) args
933 #undef TP_perf_assign
934 #define TP_perf_assign(args...)
936 #undef DECLARE_EVENT_CLASS
937 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
939 static notrace void \
940 ftrace_raw_event_##call(void *__data, proto) \
942 struct ftrace_event_call *event_call = __data; \
943 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
944 struct ring_buffer_event *event; \
945 struct ftrace_raw_##call *entry; \
946 struct ring_buffer *buffer; \
947 unsigned long irq_flags; \
951 local_save_flags(irq_flags); \
952 pc = preempt_count(); \
954 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
956 event = trace_current_buffer_lock_reserve(&buffer, \
957 event_call->event.type, \
958 sizeof(*entry) + __data_size, \
962 entry = ring_buffer_event_data(event); \
968 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
969 trace_nowake_buffer_unlock_commit(buffer, \
970 event, irq_flags, pc); \
973 * The ftrace_test_probe is compiled out, it is only here as a build time check
974 * to make sure that if the tracepoint handling changes, the ftrace probe will
975 * fail to compile unless it too is updated.
979 #define DEFINE_EVENT(template, call, proto, args) \
980 static inline void ftrace_test_probe_##call(void) \
982 check_trace_callback_type_##call(ftrace_raw_event_##template); \
985 #undef DEFINE_EVENT_PRINT
986 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
988 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
994 #undef __print_symbolic
995 #undef __get_dynamic_array
999 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
1001 #undef DECLARE_EVENT_CLASS
1002 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1003 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
1004 static const char print_fmt_##call[] = print; \
1005 static struct ftrace_event_class __used event_class_##call = { \
1006 .system = __stringify(TRACE_SYSTEM), \
1007 .define_fields = ftrace_define_fields_##call, \
1008 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
1009 .raw_init = trace_event_raw_init, \
1010 .probe = ftrace_raw_event_##call, \
1011 .reg = ftrace_event_reg, \
1012 _TRACE_PERF_INIT(call) \
1016 #define DEFINE_EVENT(template, call, proto, args) \
1018 static struct ftrace_event_call __used \
1019 __attribute__((__aligned__(4))) \
1020 __attribute__((section("_ftrace_events"))) event_##call = { \
1022 .class = &event_class_##template, \
1023 .event.funcs = &ftrace_event_type_funcs_##template, \
1024 .print_fmt = print_fmt_##template, \
1027 #undef DEFINE_EVENT_PRINT
1028 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
1030 static const char print_fmt_##call[] = print; \
1032 static struct ftrace_event_call __used \
1033 __attribute__((__aligned__(4))) \
1034 __attribute__((section("_ftrace_events"))) event_##call = { \
1036 .class = &event_class_##template, \
1037 .event.funcs = &ftrace_event_type_funcs_##call, \
1038 .print_fmt = print_fmt_##call, \
1041 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1044 * Define the insertion callback to perf events
1046 * The job is very similar to ftrace_raw_event_<call> except that we don't
1047 * insert in the ring buffer but in a perf counter.
1049 * static void ftrace_perf_<call>(proto)
1051 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
1052 * struct ftrace_event_call *event_call = &event_<call>;
1053 * extern void perf_tp_event(int, u64, u64, void *, int);
1054 * struct ftrace_raw_##call *entry;
1055 * struct perf_trace_buf *trace_buf;
1056 * u64 __addr = 0, __count = 1;
1057 * unsigned long irq_flags;
1058 * struct trace_entry *ent;
1064 * pc = preempt_count();
1066 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
1068 * // Below we want to get the aligned size by taking into account
1069 * // the u32 field that will later store the buffer size
1070 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
1072 * __entry_size -= sizeof(u32);
1074 * // Protect the non nmi buffer
1075 * // This also protects the rcu read side
1076 * local_irq_save(irq_flags);
1077 * __cpu = smp_processor_id();
1080 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
1082 * trace_buf = rcu_dereference_sched(perf_trace_buf);
1087 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
1089 * // Avoid recursion from perf that could mess up the buffer
1090 * if (trace_buf->recursion++)
1091 * goto end_recursion;
1093 * raw_data = trace_buf->buf;
1095 * // Make recursion update visible before entering perf_tp_event
1096 * // so that we protect from perf recursions.
1100 * //zero dead bytes from alignment to avoid stack leak to userspace:
1101 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
1102 * entry = (struct ftrace_raw_<call> *)raw_data;
1103 * ent = &entry->ent;
1104 * tracing_generic_entry_update(ent, irq_flags, pc);
1105 * ent->type = event_call->id;
1107 * <tstruct> <- do some jobs with dynamic arrays
1109 * <assign> <- affect our values
1111 * perf_tp_event(event_call->id, __addr, __count, entry,
1112 * __entry_size); <- submit them to perf counter
1117 #ifdef CONFIG_PERF_EVENTS
1120 #define __entry entry
1122 #undef __get_dynamic_array
1123 #define __get_dynamic_array(field) \
1124 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
1127 #define __get_str(field) (char *)__get_dynamic_array(field)
1130 #define __perf_addr(a) __addr = (a)
1133 #define __perf_count(c) __count = (c)
1135 #undef DECLARE_EVENT_CLASS
1136 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1137 static notrace void \
1138 perf_trace_##call(void *__data, proto) \
1140 struct ftrace_event_call *event_call = __data; \
1141 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
1142 struct ftrace_raw_##call *entry; \
1143 struct pt_regs __regs; \
1144 u64 __addr = 0, __count = 1; \
1145 struct hlist_head *head; \
1150 perf_fetch_caller_regs(&__regs); \
1152 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1153 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
1155 __entry_size -= sizeof(u32); \
1157 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
1158 "profile buffer not large enough")) \
1161 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
1162 __entry_size, event_call->event.type, &__regs, &rctx); \
1170 head = this_cpu_ptr(event_call->perf_events); \
1171 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
1172 __count, &__regs, head); \
1176 * This part is compiled out, it is only here as a build time check
1177 * to make sure that if the tracepoint handling changes, the
1178 * perf probe will fail to compile unless it too is updated.
1181 #define DEFINE_EVENT(template, call, proto, args) \
1182 static inline void perf_test_probe_##call(void) \
1184 check_trace_callback_type_##call(perf_trace_##template); \
1188 #undef DEFINE_EVENT_PRINT
1189 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
1190 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
1192 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1193 #endif /* CONFIG_PERF_EVENTS */
1195 #undef _TRACE_PROFILE_INIT
This page took 0.081384 seconds and 6 git commands to generate.