2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <urcu/compiler.h>
11 #include <urcu/rculist.h>
12 #include <lttng/ust-events.h>
13 #include <lttng/ringbuffer-config.h>
14 #include <lttng/ust-compiler.h>
15 #include <lttng/tracepoint.h>
16 #include <lttng/ust-endian.h>
19 #define __LTTNG_UST_NULL_STRING "(null)"
21 #undef tp_list_for_each_entry_rcu
22 #define tp_list_for_each_entry_rcu(pos, head, member) \
23 for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \
24 &pos->member != (head); \
25 pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member))
28 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
29 * same arguments and having the same field layout.
31 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
32 * its own provider and name. It refers to a class (template).
34 * TRACEPOINT_EVENT declared both a class and an instance and does a
35 * direct mapping from the instance to the class.
38 #undef TRACEPOINT_EVENT
39 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
40 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
42 _TP_PARAMS(_fields)) \
43 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
46 #undef TRACEPOINT_EVENT_CLASS
47 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
48 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
50 #undef TRACEPOINT_EVENT_INSTANCE
51 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
52 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
55 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
57 #define _tp_max_t(type, x, y) \
61 __max1 > __max2 ? __max1: __max2; \
65 * Stage 0 of tracepoint event generation.
67 * Check that each TRACEPOINT_EVENT provider argument match the
68 * TRACEPOINT_PROVIDER by creating dummy callbacks.
71 /* Reset all macros within TRACEPOINT_EVENT */
72 #include <lttng/ust-tracepoint-event-reset.h>
74 static inline lttng_ust_notrace
75 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
77 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
81 #undef _TRACEPOINT_EVENT_CLASS
82 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
83 __tracepoint_provider_mismatch_##_provider();
85 #undef _TRACEPOINT_EVENT_INSTANCE
86 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
87 __tracepoint_provider_mismatch_##_provider();
89 static inline lttng_ust_notrace
90 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
92 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
94 #include TRACEPOINT_INCLUDE
98 * Stage 0.1 of tracepoint event generation.
100 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
101 * tracepoint name length limit.
104 /* Reset all macros within TRACEPOINT_EVENT */
105 #include <lttng/ust-tracepoint-event-reset.h>
107 #undef _TRACEPOINT_EVENT_INSTANCE
108 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
110 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
111 __attribute__((unused)) = \
112 #_provider ":" #_name;
114 #include TRACEPOINT_INCLUDE
117 * Stage 0.2 of tracepoint event generation.
119 * Create dummy trace prototypes for each event class, and for each used
120 * template. This will allow checking whether the prototypes from the
121 * class and the instance using the class actually match.
124 /* Reset all macros within TRACEPOINT_EVENT */
125 #include <lttng/ust-tracepoint-event-reset.h>
128 #define TP_ARGS(...) __VA_ARGS__
130 #undef _TRACEPOINT_EVENT_INSTANCE
131 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
132 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
134 #undef _TRACEPOINT_EVENT_CLASS
135 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
136 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
138 #include TRACEPOINT_INCLUDE
141 * Stage 0.9 of tracepoint event generation
143 * Unfolding the enums
145 #include <lttng/ust-tracepoint-event-reset.h>
147 /* Enumeration entry (single value) */
148 #undef ctf_enum_value
149 #define ctf_enum_value(_string, _value) \
152 .value = lttng_is_signed_type(__typeof__(_value)) ? \
153 (long long) (_value) : (_value), \
154 .signedness = lttng_is_signed_type(__typeof__(_value)), \
157 .value = lttng_is_signed_type(__typeof__(_value)) ? \
158 (long long) (_value) : (_value), \
159 .signedness = lttng_is_signed_type(__typeof__(_value)), \
161 .string = (_string), \
164 /* Enumeration entry (range) */
165 #undef ctf_enum_range
166 #define ctf_enum_range(_string, _range_start, _range_end) \
169 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
170 (long long) (_range_start) : (_range_start), \
171 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
174 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
175 (long long) (_range_end) : (_range_end), \
176 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
178 .string = (_string), \
181 /* Enumeration entry (automatic value; follows the rules of CTF) */
183 #define ctf_enum_auto(_string) \
193 .string = (_string), \
196 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
201 #undef TP_ENUM_VALUES
202 #define TP_ENUM_VALUES(...) \
205 #undef TRACEPOINT_ENUM
206 #define TRACEPOINT_ENUM(_provider, _name, _values) \
207 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
209 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
211 #include TRACEPOINT_INCLUDE
215 * Verifying array and sequence elements are of an integer type.
218 /* Reset all macros within TRACEPOINT_EVENT */
219 #include <lttng/ust-tracepoint-event-reset.h>
220 #include <lttng/ust-tracepoint-event-write.h>
221 #include <lttng/ust-tracepoint-event-nowrite.h>
223 #undef _ctf_array_encoded
224 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
225 _length, _encoding, _nowrite, \
227 _lttng_array_element_type_is_supported(_type, _item)
229 #undef _ctf_sequence_encoded
230 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
231 _length_type, _src_length, _encoding, _nowrite, \
233 _lttng_array_element_type_is_supported(_type, _item)
236 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
238 #undef _TRACEPOINT_EVENT_CLASS
239 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
242 #include TRACEPOINT_INCLUDE
245 * Stage 1 of tracepoint event generation.
247 * Create event field type metadata section.
248 * Each event produce an array of fields.
251 /* Reset all macros within TRACEPOINT_EVENT */
252 #include <lttng/ust-tracepoint-event-reset.h>
253 #include <lttng/ust-tracepoint-event-write.h>
254 #include <lttng/ust-tracepoint-event-nowrite.h>
256 #undef _ctf_integer_ext
257 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
260 .type = __type_integer(_type, _byte_order, _base, none),\
261 .nowrite = _nowrite, \
270 #define _ctf_float(_type, _item, _src, _nowrite) \
273 .type = __type_float(_type), \
274 .nowrite = _nowrite, \
282 #undef _ctf_array_encoded
283 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
284 _length, _encoding, _nowrite, \
290 .atype = atype_array_nestable, \
295 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
296 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
302 .nowrite = _nowrite, \
310 #undef _ctf_sequence_encoded
311 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
312 _length_type, _src_length, _encoding, _nowrite, \
315 .name = "_" #_item "_length", \
316 .type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
317 .nowrite = _nowrite, \
328 .atype = atype_sequence_nestable, \
331 .sequence_nestable = \
333 .length_name = "_" #_item "_length", \
334 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
335 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
340 .nowrite = _nowrite, \
349 #define _ctf_string(_item, _src, _nowrite) \
354 .atype = atype_string, \
357 .string = { .encoding = lttng_encode_UTF8 } \
360 .nowrite = _nowrite, \
369 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
373 .atype = atype_enum_nestable, \
376 .desc = &__enum_##_provider##_##_name, \
377 .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
378 __type_integer(_type, BYTE_ORDER, 10, none)), \
382 .nowrite = _nowrite, \
391 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
393 #undef _TRACEPOINT_EVENT_CLASS
394 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
395 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
397 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
400 #undef TRACEPOINT_ENUM
401 #define TRACEPOINT_ENUM(_provider, _name, _values) \
402 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
403 .name = #_provider "_" #_name, \
404 .entries = __enum_values__##_provider##_##_name, \
405 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
408 #include TRACEPOINT_INCLUDE
411 * Stage 2 of tracepoint event generation.
413 * Create probe callback prototypes.
416 /* Reset all macros within TRACEPOINT_EVENT */
417 #include <lttng/ust-tracepoint-event-reset.h>
420 #define TP_ARGS(...) __VA_ARGS__
422 #undef _TRACEPOINT_EVENT_CLASS
423 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
424 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
426 #include TRACEPOINT_INCLUDE
429 * Stage 2.1 of tracepoint event generation.
431 * Create probe event notifier callback prototypes.
434 /* Reset all macros within TRACEPOINT_EVENT */
435 #include <lttng/ust-tracepoint-event-reset.h>
438 #define TP_ARGS(...) __VA_ARGS__
440 #undef _TRACEPOINT_EVENT_CLASS
441 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
442 static void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
444 #include TRACEPOINT_INCLUDE
447 * Stage 3.0 of tracepoint event generation.
449 * Create static inline function that calculates event size.
452 /* Reset all macros within TRACEPOINT_EVENT */
453 #include <lttng/ust-tracepoint-event-reset.h>
454 #include <lttng/ust-tracepoint-event-write.h>
456 #undef _ctf_integer_ext
457 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
458 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
459 __event_len += sizeof(_type);
462 #define _ctf_float(_type, _item, _src, _nowrite) \
463 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
464 __event_len += sizeof(_type);
466 #undef _ctf_array_encoded
467 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
468 _nowrite, _elem_type_base) \
469 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
470 __event_len += sizeof(_type) * (_length);
472 #undef _ctf_sequence_encoded
473 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
474 _src_length, _encoding, _nowrite, _elem_type_base) \
475 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
476 __event_len += sizeof(_length_type); \
477 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
478 __dynamic_len[__dynamic_len_idx] = (_src_length); \
479 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
483 #define _ctf_string(_item, _src, _nowrite) \
484 __event_len += __dynamic_len[__dynamic_len_idx++] = \
485 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
488 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
489 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
492 #define TP_ARGS(...) __VA_ARGS__
495 #define TP_FIELDS(...) __VA_ARGS__
497 #undef _TRACEPOINT_EVENT_CLASS
498 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
499 static inline lttng_ust_notrace \
500 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
502 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
504 size_t __event_len = 0; \
505 unsigned int __dynamic_len_idx = 0; \
508 (void) __dynamic_len_idx; /* don't warn if unused */ \
510 return __event_len; \
513 #include TRACEPOINT_INCLUDE
516 * Stage 3.1 of tracepoint event generation.
518 * Create static inline function that layout the filter stack data.
519 * We make both write and nowrite data available to the filter.
522 /* Reset all macros within TRACEPOINT_EVENT */
523 #include <lttng/ust-tracepoint-event-reset.h>
524 #include <lttng/ust-tracepoint-event-write.h>
525 #include <lttng/ust-tracepoint-event-nowrite.h>
527 #undef _ctf_integer_ext
528 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
529 if (lttng_is_signed_type(_type)) { \
530 int64_t __ctf_tmp_int64; \
531 switch (sizeof(_type)) { \
534 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
535 __ctf_tmp_int64 = (int64_t) __tmp.v; \
540 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
541 if (_byte_order != BYTE_ORDER) \
542 __tmp.v = bswap_16(__tmp.v); \
543 __ctf_tmp_int64 = (int64_t) __tmp.v; \
548 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
549 if (_byte_order != BYTE_ORDER) \
550 __tmp.v = bswap_32(__tmp.v); \
551 __ctf_tmp_int64 = (int64_t) __tmp.v; \
556 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
557 if (_byte_order != BYTE_ORDER) \
558 __tmp.v = bswap_64(__tmp.v); \
559 __ctf_tmp_int64 = (int64_t) __tmp.v; \
565 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
567 uint64_t __ctf_tmp_uint64; \
568 switch (sizeof(_type)) { \
571 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
572 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
577 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
578 if (_byte_order != BYTE_ORDER) \
579 __tmp.v = bswap_16(__tmp.v); \
580 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
585 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
586 if (_byte_order != BYTE_ORDER) \
587 __tmp.v = bswap_32(__tmp.v); \
588 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
593 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
594 if (_byte_order != BYTE_ORDER) \
595 __tmp.v = bswap_64(__tmp.v); \
596 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
602 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
604 __stack_data += sizeof(int64_t);
607 #define _ctf_float(_type, _item, _src, _nowrite) \
609 double __ctf_tmp_double = (double) (_type) (_src); \
610 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
611 __stack_data += sizeof(double); \
614 #undef _ctf_array_encoded
615 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
616 _encoding, _nowrite, _elem_type_base) \
618 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
619 const void *__ctf_tmp_ptr = (_src); \
620 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
621 __stack_data += sizeof(unsigned long); \
622 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
623 __stack_data += sizeof(void *); \
626 #undef _ctf_sequence_encoded
627 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
628 _src_length, _encoding, _nowrite, _elem_type_base) \
630 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
631 const void *__ctf_tmp_ptr = (_src); \
632 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
633 __stack_data += sizeof(unsigned long); \
634 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
635 __stack_data += sizeof(void *); \
639 #define _ctf_string(_item, _src, _nowrite) \
641 const void *__ctf_tmp_ptr = \
642 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
643 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
644 __stack_data += sizeof(void *); \
648 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
649 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
652 #define TP_ARGS(...) __VA_ARGS__
655 #define TP_FIELDS(...) __VA_ARGS__
657 #undef _TRACEPOINT_EVENT_CLASS
658 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
660 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
661 _TP_ARGS_DATA_PROTO(_args)) \
666 #include TRACEPOINT_INCLUDE
669 * Stage 4 of tracepoint event generation.
671 * Create static inline function that calculates event payload alignment.
674 /* Reset all macros within TRACEPOINT_EVENT */
675 #include <lttng/ust-tracepoint-event-reset.h>
676 #include <lttng/ust-tracepoint-event-write.h>
678 #undef _ctf_integer_ext
679 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
680 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
683 #define _ctf_float(_type, _item, _src, _nowrite) \
684 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
686 #undef _ctf_array_encoded
687 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
688 _encoding, _nowrite, _elem_type_base) \
689 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
691 #undef _ctf_sequence_encoded
692 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
693 _src_length, _encoding, _nowrite, _elem_type_base) \
694 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
695 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
698 #define _ctf_string(_item, _src, _nowrite)
701 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
702 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
705 #define TP_ARGS(...) __VA_ARGS__
708 #define TP_FIELDS(...) __VA_ARGS__
710 #undef _TRACEPOINT_EVENT_CLASS
711 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
712 static inline lttng_ust_notrace \
713 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
715 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
717 size_t __event_align = 1; \
719 return __event_align; \
722 #include TRACEPOINT_INCLUDE
726 * Stage 5 of tracepoint event generation.
728 * Create the probe function. This function calls event size calculation
729 * and writes event data into the buffer.
732 /* Reset all macros within TRACEPOINT_EVENT */
733 #include <lttng/ust-tracepoint-event-reset.h>
734 #include <lttng/ust-tracepoint-event-write.h>
736 #undef _ctf_integer_ext
737 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
739 _type __tmp = (_src); \
740 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
741 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
745 #define _ctf_float(_type, _item, _src, _nowrite) \
747 _type __tmp = (_src); \
748 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
749 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
752 #undef _ctf_array_encoded
753 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
754 _encoding, _nowrite, _elem_type_base) \
755 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
756 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
758 #undef _ctf_sequence_encoded
759 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
760 _src_length, _encoding, _nowrite, _elem_type_base) \
762 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
763 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
764 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
766 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
767 __chan->ops->event_write(&__ctx, _src, \
768 sizeof(_type) * __get_dynamic_len(dest));
771 #define _ctf_string(_item, _src, _nowrite) \
773 const char *__ctf_tmp_string = \
774 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
775 lib_ring_buffer_align_ctx(&__ctx, \
776 lttng_alignof(*__ctf_tmp_string)); \
777 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
778 __get_dynamic_len(dest)); \
783 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
784 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
786 /* Beware: this get len actually consumes the len value */
787 #undef __get_dynamic_len
788 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
791 #define TP_ARGS(...) __VA_ARGS__
794 #define TP_FIELDS(...) __VA_ARGS__
797 * For state dump, check that "session" argument (mandatory) matches the
798 * session this event belongs to. Ensures that we write state dump data only
799 * into the started session, not into all sessions.
801 #undef _TP_SESSION_CHECK
802 #ifdef TP_SESSION_CHECK
803 #define _TP_SESSION_CHECK(session, csession) (session == csession)
804 #else /* TP_SESSION_CHECK */
805 #define _TP_SESSION_CHECK(session, csession) 1
806 #endif /* TP_SESSION_CHECK */
809 * Use of __builtin_return_address(0) sometimes seems to cause stack
810 * corruption on 32-bit PowerPC. Disable this feature on that
811 * architecture for now by always using the NULL value for the ip
816 #define _TP_IP_PARAM(x) (x)
817 #else /* TP_IP_PARAM */
819 #if defined(__PPC__) && !defined(__PPC64__)
820 #define _TP_IP_PARAM(x) NULL
821 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
822 #define _TP_IP_PARAM(x) __builtin_return_address(0)
823 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
825 #endif /* TP_IP_PARAM */
828 * Using twice size for filter stack data to hold size and pointer for
829 * each field (worse case). For integers, max size required is 64-bit.
830 * Same for double-precision floats. Those fit within
831 * 2*sizeof(unsigned long) for all supported architectures.
832 * Perform UNION (||) of filter runtime list.
834 #undef _TRACEPOINT_EVENT_CLASS
835 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
836 static lttng_ust_notrace \
837 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
839 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
841 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
842 struct lttng_channel *__chan = __event->chan; \
843 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
844 struct lttng_stack_ctx __lttng_ctx; \
845 size_t __event_len, __event_align; \
846 size_t __dynamic_len_idx = 0; \
847 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
849 size_t __dynamic_len[__num_fields]; \
850 char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
855 (void) __dynamic_len_idx; /* don't warn if unused */ \
856 if (!_TP_SESSION_CHECK(session, __chan->session)) \
858 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
860 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
862 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
864 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
866 if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \
867 struct lttng_bytecode_runtime *__filter_bc_runtime; \
868 int __filter_record = __event->has_enablers_without_bytecode; \
870 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
871 _TP_ARGS_DATA_VAR(_args)); \
872 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
873 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
874 __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \
875 __filter_record = 1; \
879 if (caa_likely(!__filter_record)) \
882 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
883 _TP_ARGS_DATA_VAR(_args)); \
884 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
885 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
886 __lttng_ctx.event = __event; \
887 __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \
888 __lttng_ctx.event_ctx = tp_rcu_dereference(__event->ctx); \
889 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
890 __event_align, -1, __chan->handle, &__lttng_ctx); \
891 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
892 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
896 __chan->ops->event_commit(&__ctx); \
899 #include TRACEPOINT_INCLUDE
901 #undef __get_dynamic_len
904 * Stage 5.1 of tracepoint event generation.
906 * Create probe signature
909 /* Reset all macros within TRACEPOINT_EVENT */
910 #include <lttng/ust-tracepoint-event-reset.h>
913 #define TP_ARGS(...) __VA_ARGS__
915 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
917 #undef _TRACEPOINT_EVENT_CLASS
918 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
919 static const char __tp_event_signature___##_provider##___##_name[] = \
920 _TP_EXTRACT_STRING2(_args);
922 #include TRACEPOINT_INCLUDE
924 #undef _TP_EXTRACT_STRING2
927 * Stage 5.2 of tracepoint event generation.
929 * Create the event notifier probe function.
931 #undef _TRACEPOINT_EVENT_CLASS
932 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
933 static lttng_ust_notrace \
934 void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
936 void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
938 struct lttng_event_notifier *__event_notifier = (struct lttng_event_notifier *) __tp_data; \
939 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1;\
941 size_t __dynamic_len[__num_fields]; \
942 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
945 if (caa_unlikely(!CMM_ACCESS_ONCE(__event_notifier->enabled))) \
947 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
949 if (caa_unlikely(!cds_list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \
950 struct lttng_bytecode_runtime *__filter_bc_runtime; \
951 int __filter_record = __event_notifier->has_enablers_without_bytecode; \
953 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
954 _TP_ARGS_DATA_VAR(_args)); \
955 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \
956 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
957 __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \
958 __filter_record = 1; \
960 if (caa_likely(!__filter_record)) \
963 if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \
964 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
965 _TP_ARGS_DATA_VAR(_args)); \
967 __event_notifier->notification_send(__event_notifier, \
968 __stackvar.__interpreter_stack_data); \
971 #include TRACEPOINT_INCLUDE
974 * Stage 6 of tracepoint event generation.
976 * Tracepoint loglevel mapping definition generation. We generate a
977 * symbol for each mapping for a provider/event to ensure at most a 1 to
978 * 1 mapping between events and loglevels. If the symbol is repeated,
979 * the compiler will complain.
982 /* Reset all macros within TRACEPOINT_EVENT */
983 #include <lttng/ust-tracepoint-event-reset.h>
986 * Declare _loglevel___##__provider##___##__name as non-static, with
987 * hidden visibility for c++ handling of weakref. We do a weakref to the
988 * symbol in a later stage, which requires that the symbol is not
992 #define LTTNG_TP_EXTERN_C extern "C"
994 #define LTTNG_TP_EXTERN_C
997 #undef TRACEPOINT_LOGLEVEL
998 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
999 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
1000 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
1001 __attribute__((visibility("hidden"))) = \
1002 &_loglevel_value___##__provider##___##__name;
1004 #include TRACEPOINT_INCLUDE
1006 #undef LTTNG_TP_EXTERN_C
1009 * Stage 6.1 of tracepoint event generation.
1011 * Tracepoint UML URI info.
1014 /* Reset all macros within TRACEPOINT_EVENT */
1015 #include <lttng/ust-tracepoint-event-reset.h>
1018 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1019 * with hidden visibility for c++ handling of weakref. We do a weakref
1020 * to the symbol in a later stage, which requires that the symbol is not
1024 #define LTTNG_TP_EXTERN_C extern "C"
1026 #define LTTNG_TP_EXTERN_C
1029 #undef TRACEPOINT_MODEL_EMF_URI
1030 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1031 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
1032 __attribute__((visibility("hidden"))) = __uri; \
1034 #include TRACEPOINT_INCLUDE
1036 #undef LTTNG_TP_EXTERN_C
1039 * Stage 7.1 of tracepoint event generation.
1041 * Create events description structures. We use a weakref because
1042 * loglevels are optional. If not declared, the event will point to the
1043 * a loglevel that contains NULL.
1046 /* Reset all macros within TRACEPOINT_EVENT */
1047 #include <lttng/ust-tracepoint-event-reset.h>
1049 #undef _TRACEPOINT_EVENT_INSTANCE
1050 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1051 static const int * \
1052 __ref_loglevel___##_provider##___##_name \
1053 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1054 static const char * \
1055 __ref_model_emf_uri___##_provider##___##_name \
1056 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1057 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
1058 .name = #_provider ":" #_name, \
1059 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
1061 .fields = __event_fields___##_provider##___##_template, \
1062 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1063 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1064 .signature = __tp_event_signature___##_provider##___##_template, \
1067 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1068 .event_notifier_callback = (void (*)(void)) &__event_notifier_probe__##_provider##___##_template,\
1073 #include TRACEPOINT_INCLUDE
1076 * Stage 7.2 of tracepoint event generation.
1078 * Create array of events.
1081 /* Reset all macros within TRACEPOINT_EVENT */
1082 #include <lttng/ust-tracepoint-event-reset.h>
1084 #undef _TRACEPOINT_EVENT_INSTANCE
1085 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1086 &__event_desc___##_provider##_##_name,
1088 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1089 #include TRACEPOINT_INCLUDE
1090 NULL
, /* Dummy, C99 forbids 0-len array. */
1095 * Stage 8 of tracepoint event generation.
1097 * Create a toplevel descriptor for the whole probe.
1100 /* non-const because list head will be modified when registered. */
1101 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1102 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
1103 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1104 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1105 .head
= { NULL
, NULL
},
1106 .lazy_init_head
= { NULL
, NULL
},
1108 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1109 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1112 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1115 * Stage 9 of tracepoint event generation.
1117 * Register/unregister probes at module load/unload.
1119 * Generate the constructor as an externally visible symbol for use when
1120 * linking the probe statically.
1122 * Register refcount is protected by libc dynamic loader mutex.
1125 /* Reset all macros within TRACEPOINT_EVENT */
1126 #include <lttng/ust-tracepoint-event-reset.h>
1127 static void lttng_ust_notrace
__attribute__((constructor
))
1128 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1130 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1134 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1135 TRACEPOINT_PROVIDER
)++) {
1139 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1140 * static inline function that ensures every probe PROVIDER
1141 * argument match the provider within which they appear. It
1142 * calls empty static inline functions, and therefore has no
1143 * runtime effect. However, if it detects an error, a linker
1144 * error will appear.
1146 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1147 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1149 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1154 static void lttng_ust_notrace
__attribute__((destructor
))
1155 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1157 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1159 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1160 TRACEPOINT_PROVIDER
)) {
1163 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1166 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1167 __attribute__((visibility("default")));