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, sizeof(_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, sizeof(_type));
347 #undef __dynamic_array
348 #define __dynamic_array(_type, _item, _length) \
349 __event_align = max_t(size_t, __event_align, sizeof(u32)); \
350 __event_align = max_t(size_t, __event_align, sizeof(_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 * Note: the order of fields in TP_fast_assign and TP_STRUCT__entry must be the
384 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
387 #define __field(_type, _item) \
388 lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
389 goto __assign_##_item; \
393 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
396 #define __array(_type, _item, _length) \
397 lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
398 goto __assign_##_item; \
401 #undef __dynamic_array
402 #define __dynamic_array(_type, _item, _length) \
403 lib_ring_buffer_align_ctx(&ctx, sizeof(u32)); \
404 goto __assign_##_item##_1; \
405 __end_field_##_item##_1: \
406 lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
407 goto __assign_##_item##_2; \
408 __end_field_##_item##_2:
411 #define __string(_item, _src) \
412 goto __assign_##_item; \
416 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
420 #define tp_assign(dest, src) \
423 __typeof__(src) __tmp = (src); \
424 __chan->ops->event_write(&ctx, &__tmp, sizeof(src)); \
426 goto __end_field_##dest;
429 #define tp_memcpy(dest, src, len) \
431 __chan->ops->event_write(&ctx, src, len); \
432 goto __end_field_##dest;
435 #define tp_memcpy_dyn(dest, src, len) \
436 __assign_##dest##_1: \
438 __typeof__(len) __tmpl = (len); \
439 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
441 goto __end_field_##dest##_1; \
442 __assign_##dest##_2: \
443 __chan->ops->event_write(&ctx, src, len); \
444 goto __end_field_##dest##_2;
447 #define tp_strcpy(dest, src) \
448 tp_memcpy(dest, src, __get_dynamic_array_len(dest)); \
450 /* Named field types must be defined in lttng-types.h */
453 #define __get_str(field) field
455 #undef __get_dynamic_array
456 #define __get_dynamic_array(field) field
458 /* Beware: this get len actually consumes the len value */
459 #undef __get_dynamic_array_len
460 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
463 #define TP_PROTO(args...) args
466 #define TP_ARGS(args...) args
468 #undef TP_STRUCT__entry
469 #define TP_STRUCT__entry(args...) args
471 #undef TP_fast_assign
472 #define TP_fast_assign(args...) args
474 #undef DECLARE_EVENT_CLASS
475 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
476 static void __event_probe__##_name(void *__data, _proto) \
478 struct ltt_event *__event = __data; \
479 struct ltt_channel *__chan = __event->chan; \
480 struct lib_ring_buffer_ctx ctx; \
481 size_t __event_len, __event_align; \
482 size_t __dynamic_len_idx = 0; \
483 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
487 (void) __dynamic_len_idx; /* don't warn if unused */ \
488 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
489 __event_align = __event_get_align__##_name(_args); \
490 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
491 __event_align, -1); \
492 __ret = __chan->ops->event_reserve(&ctx); \
495 /* Control code (field ordering) */ \
497 __chan->ops->event_commit(&ctx); \
499 /* Copy code, steered by control code */ \
503 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
508 #include <linux/ftrace_event.h>
511 * DECLARE_EVENT_CLASS can be used to add a generic function
512 * handlers for events. That is, if all events have the same
513 * parameters and just have distinct trace points.
514 * Each tracepoint can be defined with DEFINE_EVENT and that
515 * will map the DECLARE_EVENT_CLASS to the tracepoint.
517 * TRACE_EVENT is a one to one mapping between tracepoint and template.
520 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
521 DECLARE_EVENT_CLASS(name, \
527 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
531 #define __field(type, item) type item;
534 #define __field_ext(type, item, filter_type) type item;
537 #define __array(type, item, len) type item[len];
539 #undef __dynamic_array
540 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
543 #define __string(item, src) __dynamic_array(char, item, -1)
545 #undef TP_STRUCT__entry
546 #define TP_STRUCT__entry(args...) args
548 #undef DECLARE_EVENT_CLASS
549 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
550 struct ftrace_raw_##name { \
551 struct trace_entry ent; \
556 static struct ftrace_event_class event_class_##name;
559 #define DEFINE_EVENT(template, name, proto, args) \
560 static struct ftrace_event_call __used \
561 __attribute__((__aligned__(4))) event_##name
563 #undef DEFINE_EVENT_PRINT
564 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
565 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
567 /* Callbacks are meaningless to ftrace. */
568 #undef TRACE_EVENT_FN
569 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
570 assign, print, reg, unreg) \
571 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
572 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
574 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
578 * Stage 2 of the trace events.
580 * Create static inline function that calculates event size.
584 #define __field(type, item)
587 #define __field_ext(type, item, filter_type)
590 #define __array(type, item, len)
592 #undef __dynamic_array
593 #define __dynamic_array(type, item, len) u32 item;
596 #define __string(item, src) __dynamic_array(char, item, -1)
598 #undef DECLARE_EVENT_CLASS
599 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
600 struct ftrace_data_offsets_##call { \
605 #define DEFINE_EVENT(template, name, proto, args)
607 #undef DEFINE_EVENT_PRINT
608 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
609 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
611 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
614 * Stage 3 of the trace events.
616 * Create the probe function : call even size calculation and write event data
621 #define __entry field
624 #define TP_printk(fmt, args...) fmt "\n", args
626 #undef __get_dynamic_array
627 #define __get_dynamic_array(field) \
628 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
631 #define __get_str(field) (char *)__get_dynamic_array(field)
634 #define __print_flags(flag, delim, flag_array...) \
636 static const struct trace_print_flags __flags[] = \
637 { flag_array, { -1, NULL }}; \
638 ftrace_print_flags_seq(p, delim, flag, __flags); \
641 #undef __print_symbolic
642 #define __print_symbolic(value, symbol_array...) \
644 static const struct trace_print_flags symbols[] = \
645 { symbol_array, { -1, NULL }}; \
646 ftrace_print_symbols_seq(p, value, symbols); \
650 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
652 #undef DECLARE_EVENT_CLASS
653 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
654 static notrace enum print_line_t \
655 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
656 struct trace_event *trace_event) \
658 struct ftrace_event_call *event; \
659 struct trace_seq *s = &iter->seq; \
660 struct ftrace_raw_##call *field; \
661 struct trace_entry *entry; \
662 struct trace_seq *p = &iter->tmp_seq; \
665 event = container_of(trace_event, struct ftrace_event_call, \
670 if (entry->type != event->event.type) { \
672 return TRACE_TYPE_UNHANDLED; \
675 field = (typeof(field))entry; \
678 ret = trace_seq_printf(s, "%s: ", event->name); \
680 ret = trace_seq_printf(s, print); \
682 return TRACE_TYPE_PARTIAL_LINE; \
684 return TRACE_TYPE_HANDLED; \
686 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
687 .trace = ftrace_raw_output_##call, \
690 #undef DEFINE_EVENT_PRINT
691 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
692 static notrace enum print_line_t \
693 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
694 struct trace_event *event) \
696 struct trace_seq *s = &iter->seq; \
697 struct ftrace_raw_##template *field; \
698 struct trace_entry *entry; \
699 struct trace_seq *p = &iter->tmp_seq; \
704 if (entry->type != event_##call.event.type) { \
706 return TRACE_TYPE_UNHANDLED; \
709 field = (typeof(field))entry; \
712 ret = trace_seq_printf(s, "%s: ", #call); \
714 ret = trace_seq_printf(s, print); \
716 return TRACE_TYPE_PARTIAL_LINE; \
718 return TRACE_TYPE_HANDLED; \
720 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
721 .trace = ftrace_raw_output_##call, \
724 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
727 #define __field_ext(type, item, filter_type) \
728 ret = trace_define_field(event_call, #type, #item, \
729 offsetof(typeof(field), item), \
730 sizeof(field.item), \
731 is_signed_type(type), filter_type); \
736 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
739 #define __array(type, item, len) \
740 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
741 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
742 offsetof(typeof(field), item), \
743 sizeof(field.item), \
744 is_signed_type(type), FILTER_OTHER); \
748 #undef __dynamic_array
749 #define __dynamic_array(type, item, len) \
750 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
751 offsetof(typeof(field), __data_loc_##item), \
752 sizeof(field.__data_loc_##item), \
753 is_signed_type(type), FILTER_OTHER);
756 #define __string(item, src) __dynamic_array(char, item, -1)
758 #undef DECLARE_EVENT_CLASS
759 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
761 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
763 struct ftrace_raw_##call field; \
772 #define DEFINE_EVENT(template, name, proto, args)
774 #undef DEFINE_EVENT_PRINT
775 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
776 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
778 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
781 * remember the offset of each array from the beginning of the event.
785 #define __entry entry
788 #define __field(type, item)
791 #define __field_ext(type, item, filter_type)
794 #define __array(type, item, len)
796 #undef __dynamic_array
797 #define __dynamic_array(type, item, len) \
798 __data_offsets->item = __data_size + \
799 offsetof(typeof(*entry), __data); \
800 __data_offsets->item |= (len * sizeof(type)) << 16; \
801 __data_size += (len) * sizeof(type);
804 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
806 #undef DECLARE_EVENT_CLASS
807 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
808 static inline notrace int ftrace_get_offsets_##call( \
809 struct ftrace_data_offsets_##call *__data_offsets, proto) \
811 int __data_size = 0; \
812 struct ftrace_raw_##call __maybe_unused *entry; \
816 return __data_size; \
820 #define DEFINE_EVENT(template, name, proto, args)
822 #undef DEFINE_EVENT_PRINT
823 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
824 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
826 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
829 * Stage 4 of the trace events.
831 * Override the macros in <trace/trace_events.h> to include the following:
833 * For those macros defined with TRACE_EVENT:
835 * static struct ftrace_event_call event_<call>;
837 * static void ftrace_raw_event_<call>(void *__data, proto)
839 * struct ftrace_event_call *event_call = __data;
840 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
841 * struct ring_buffer_event *event;
842 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
843 * struct ring_buffer *buffer;
844 * unsigned long irq_flags;
848 * local_save_flags(irq_flags);
849 * pc = preempt_count();
851 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
853 * event = trace_current_buffer_lock_reserve(&buffer,
854 * event_<call>->event.type,
855 * sizeof(*entry) + __data_size,
859 * entry = ring_buffer_event_data(event);
861 * { <assign>; } <-- Here we assign the entries by the __field and
864 * if (!filter_current_check_discard(buffer, event_call, entry, event))
865 * trace_current_buffer_unlock_commit(buffer,
866 * event, irq_flags, pc);
869 * static struct trace_event ftrace_event_type_<call> = {
870 * .trace = ftrace_raw_output_<call>, <-- stage 2
873 * static const char print_fmt_<call>[] = <TP_printk>;
875 * static struct ftrace_event_class __used event_class_<template> = {
876 * .system = "<system>",
877 * .define_fields = ftrace_define_fields_<call>,
878 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
879 * .raw_init = trace_event_raw_init,
880 * .probe = ftrace_raw_event_##call,
881 * .reg = ftrace_event_reg,
884 * static struct ftrace_event_call __used
885 * __attribute__((__aligned__(4)))
886 * __attribute__((section("_ftrace_events"))) event_<call> = {
888 * .class = event_class_<template>,
889 * .event = &ftrace_event_type_<call>,
890 * .print_fmt = print_fmt_<call>,
895 #ifdef CONFIG_PERF_EVENTS
897 #define _TRACE_PERF_PROTO(call, proto) \
898 static notrace void \
899 perf_trace_##call(void *__data, proto);
901 #define _TRACE_PERF_INIT(call) \
902 .perf_probe = perf_trace_##call,
905 #define _TRACE_PERF_PROTO(call, proto)
906 #define _TRACE_PERF_INIT(call)
907 #endif /* CONFIG_PERF_EVENTS */
910 #define __entry entry
913 #define __field(type, item)
916 #define __array(type, item, len)
918 #undef __dynamic_array
919 #define __dynamic_array(type, item, len) \
920 __entry->__data_loc_##item = __data_offsets.item;
923 #define __string(item, src) __dynamic_array(char, item, -1) \
926 #define __assign_str(dst, src) \
927 strcpy(__get_str(dst), src);
929 #undef TP_fast_assign
930 #define TP_fast_assign(args...) args
932 #undef TP_perf_assign
933 #define TP_perf_assign(args...)
935 #undef DECLARE_EVENT_CLASS
936 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
938 static notrace void \
939 ftrace_raw_event_##call(void *__data, proto) \
941 struct ftrace_event_call *event_call = __data; \
942 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
943 struct ring_buffer_event *event; \
944 struct ftrace_raw_##call *entry; \
945 struct ring_buffer *buffer; \
946 unsigned long irq_flags; \
950 local_save_flags(irq_flags); \
951 pc = preempt_count(); \
953 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
955 event = trace_current_buffer_lock_reserve(&buffer, \
956 event_call->event.type, \
957 sizeof(*entry) + __data_size, \
961 entry = ring_buffer_event_data(event); \
967 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
968 trace_nowake_buffer_unlock_commit(buffer, \
969 event, irq_flags, pc); \
972 * The ftrace_test_probe is compiled out, it is only here as a build time check
973 * to make sure that if the tracepoint handling changes, the ftrace probe will
974 * fail to compile unless it too is updated.
978 #define DEFINE_EVENT(template, call, proto, args) \
979 static inline void ftrace_test_probe_##call(void) \
981 check_trace_callback_type_##call(ftrace_raw_event_##template); \
984 #undef DEFINE_EVENT_PRINT
985 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
987 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
993 #undef __print_symbolic
994 #undef __get_dynamic_array
998 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
1000 #undef DECLARE_EVENT_CLASS
1001 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1002 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
1003 static const char print_fmt_##call[] = print; \
1004 static struct ftrace_event_class __used event_class_##call = { \
1005 .system = __stringify(TRACE_SYSTEM), \
1006 .define_fields = ftrace_define_fields_##call, \
1007 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
1008 .raw_init = trace_event_raw_init, \
1009 .probe = ftrace_raw_event_##call, \
1010 .reg = ftrace_event_reg, \
1011 _TRACE_PERF_INIT(call) \
1015 #define DEFINE_EVENT(template, call, proto, args) \
1017 static struct ftrace_event_call __used \
1018 __attribute__((__aligned__(4))) \
1019 __attribute__((section("_ftrace_events"))) event_##call = { \
1021 .class = &event_class_##template, \
1022 .event.funcs = &ftrace_event_type_funcs_##template, \
1023 .print_fmt = print_fmt_##template, \
1026 #undef DEFINE_EVENT_PRINT
1027 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
1029 static const char print_fmt_##call[] = print; \
1031 static struct ftrace_event_call __used \
1032 __attribute__((__aligned__(4))) \
1033 __attribute__((section("_ftrace_events"))) event_##call = { \
1035 .class = &event_class_##template, \
1036 .event.funcs = &ftrace_event_type_funcs_##call, \
1037 .print_fmt = print_fmt_##call, \
1040 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1043 * Define the insertion callback to perf events
1045 * The job is very similar to ftrace_raw_event_<call> except that we don't
1046 * insert in the ring buffer but in a perf counter.
1048 * static void ftrace_perf_<call>(proto)
1050 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
1051 * struct ftrace_event_call *event_call = &event_<call>;
1052 * extern void perf_tp_event(int, u64, u64, void *, int);
1053 * struct ftrace_raw_##call *entry;
1054 * struct perf_trace_buf *trace_buf;
1055 * u64 __addr = 0, __count = 1;
1056 * unsigned long irq_flags;
1057 * struct trace_entry *ent;
1063 * pc = preempt_count();
1065 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
1067 * // Below we want to get the aligned size by taking into account
1068 * // the u32 field that will later store the buffer size
1069 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
1071 * __entry_size -= sizeof(u32);
1073 * // Protect the non nmi buffer
1074 * // This also protects the rcu read side
1075 * local_irq_save(irq_flags);
1076 * __cpu = smp_processor_id();
1079 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
1081 * trace_buf = rcu_dereference_sched(perf_trace_buf);
1086 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
1088 * // Avoid recursion from perf that could mess up the buffer
1089 * if (trace_buf->recursion++)
1090 * goto end_recursion;
1092 * raw_data = trace_buf->buf;
1094 * // Make recursion update visible before entering perf_tp_event
1095 * // so that we protect from perf recursions.
1099 * //zero dead bytes from alignment to avoid stack leak to userspace:
1100 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
1101 * entry = (struct ftrace_raw_<call> *)raw_data;
1102 * ent = &entry->ent;
1103 * tracing_generic_entry_update(ent, irq_flags, pc);
1104 * ent->type = event_call->id;
1106 * <tstruct> <- do some jobs with dynamic arrays
1108 * <assign> <- affect our values
1110 * perf_tp_event(event_call->id, __addr, __count, entry,
1111 * __entry_size); <- submit them to perf counter
1116 #ifdef CONFIG_PERF_EVENTS
1119 #define __entry entry
1121 #undef __get_dynamic_array
1122 #define __get_dynamic_array(field) \
1123 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
1126 #define __get_str(field) (char *)__get_dynamic_array(field)
1129 #define __perf_addr(a) __addr = (a)
1132 #define __perf_count(c) __count = (c)
1134 #undef DECLARE_EVENT_CLASS
1135 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
1136 static notrace void \
1137 perf_trace_##call(void *__data, proto) \
1139 struct ftrace_event_call *event_call = __data; \
1140 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
1141 struct ftrace_raw_##call *entry; \
1142 struct pt_regs __regs; \
1143 u64 __addr = 0, __count = 1; \
1144 struct hlist_head *head; \
1149 perf_fetch_caller_regs(&__regs); \
1151 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
1152 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
1154 __entry_size -= sizeof(u32); \
1156 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
1157 "profile buffer not large enough")) \
1160 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
1161 __entry_size, event_call->event.type, &__regs, &rctx); \
1169 head = this_cpu_ptr(event_call->perf_events); \
1170 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
1171 __count, &__regs, head); \
1175 * This part is compiled out, it is only here as a build time check
1176 * to make sure that if the tracepoint handling changes, the
1177 * perf probe will fail to compile unless it too is updated.
1180 #define DEFINE_EVENT(template, call, proto, args) \
1181 static inline void perf_test_probe_##call(void) \
1183 check_trace_callback_type_##call(perf_trace_##template); \
1187 #undef DEFINE_EVENT_PRINT
1188 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
1189 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
1191 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1192 #endif /* CONFIG_PERF_EVENTS */
1194 #undef _TRACE_PROFILE_INIT
This page took 0.074281 seconds and 5 git commands to generate.