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_ABI_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 3.0 of tracepoint event generation.
431 * Create static inline function that calculates event size.
434 /* Reset all macros within TRACEPOINT_EVENT */
435 #include <lttng/ust-tracepoint-event-reset.h>
436 #include <lttng/ust-tracepoint-event-write.h>
438 #undef _ctf_integer_ext
439 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
440 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
441 __event_len += sizeof(_type);
444 #define _ctf_float(_type, _item, _src, _nowrite) \
445 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
446 __event_len += sizeof(_type);
448 #undef _ctf_array_encoded
449 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
450 _nowrite, _elem_type_base) \
451 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
452 __event_len += sizeof(_type) * (_length);
454 #undef _ctf_sequence_encoded
455 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
456 _src_length, _encoding, _nowrite, _elem_type_base) \
457 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
458 __event_len += sizeof(_length_type); \
459 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
460 __dynamic_len[__dynamic_len_idx] = (_src_length); \
461 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
465 #define _ctf_string(_item, _src, _nowrite) \
466 __event_len += __dynamic_len[__dynamic_len_idx++] = \
467 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
470 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
471 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
474 #define TP_ARGS(...) __VA_ARGS__
477 #define TP_FIELDS(...) __VA_ARGS__
479 #undef _TRACEPOINT_EVENT_CLASS
480 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
481 static inline lttng_ust_notrace \
482 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
484 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
486 size_t __event_len = 0; \
487 unsigned int __dynamic_len_idx = 0; \
490 (void) __dynamic_len_idx; /* don't warn if unused */ \
492 return __event_len; \
495 #include TRACEPOINT_INCLUDE
498 * Stage 3.1 of tracepoint event generation.
500 * Create static inline function that layout the filter stack data.
501 * We make both write and nowrite data available to the filter.
504 /* Reset all macros within TRACEPOINT_EVENT */
505 #include <lttng/ust-tracepoint-event-reset.h>
506 #include <lttng/ust-tracepoint-event-write.h>
507 #include <lttng/ust-tracepoint-event-nowrite.h>
509 #undef _ctf_integer_ext
510 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
511 if (lttng_is_signed_type(_type)) { \
512 int64_t __ctf_tmp_int64; \
513 switch (sizeof(_type)) { \
516 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
517 __ctf_tmp_int64 = (int64_t) __tmp.v; \
522 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
523 if (_byte_order != BYTE_ORDER) \
524 __tmp.v = bswap_16(__tmp.v); \
525 __ctf_tmp_int64 = (int64_t) __tmp.v; \
530 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
531 if (_byte_order != BYTE_ORDER) \
532 __tmp.v = bswap_32(__tmp.v); \
533 __ctf_tmp_int64 = (int64_t) __tmp.v; \
538 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
539 if (_byte_order != BYTE_ORDER) \
540 __tmp.v = bswap_64(__tmp.v); \
541 __ctf_tmp_int64 = (int64_t) __tmp.v; \
547 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
549 uint64_t __ctf_tmp_uint64; \
550 switch (sizeof(_type)) { \
553 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
554 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
559 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
560 if (_byte_order != BYTE_ORDER) \
561 __tmp.v = bswap_16(__tmp.v); \
562 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
567 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
568 if (_byte_order != BYTE_ORDER) \
569 __tmp.v = bswap_32(__tmp.v); \
570 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
575 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
576 if (_byte_order != BYTE_ORDER) \
577 __tmp.v = bswap_64(__tmp.v); \
578 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
584 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
586 __stack_data += sizeof(int64_t);
589 #define _ctf_float(_type, _item, _src, _nowrite) \
591 double __ctf_tmp_double = (double) (_type) (_src); \
592 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
593 __stack_data += sizeof(double); \
596 #undef _ctf_array_encoded
597 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
598 _encoding, _nowrite, _elem_type_base) \
600 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
601 const void *__ctf_tmp_ptr = (_src); \
602 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
603 __stack_data += sizeof(unsigned long); \
604 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
605 __stack_data += sizeof(void *); \
608 #undef _ctf_sequence_encoded
609 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
610 _src_length, _encoding, _nowrite, _elem_type_base) \
612 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
613 const void *__ctf_tmp_ptr = (_src); \
614 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
615 __stack_data += sizeof(unsigned long); \
616 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
617 __stack_data += sizeof(void *); \
621 #define _ctf_string(_item, _src, _nowrite) \
623 const void *__ctf_tmp_ptr = \
624 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
625 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
626 __stack_data += sizeof(void *); \
630 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
631 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
634 #define TP_ARGS(...) __VA_ARGS__
637 #define TP_FIELDS(...) __VA_ARGS__
639 #undef _TRACEPOINT_EVENT_CLASS
640 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
642 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
643 _TP_ARGS_DATA_PROTO(_args)) \
648 #include TRACEPOINT_INCLUDE
651 * Stage 4 of tracepoint event generation.
653 * Create static inline function that calculates event payload alignment.
656 /* Reset all macros within TRACEPOINT_EVENT */
657 #include <lttng/ust-tracepoint-event-reset.h>
658 #include <lttng/ust-tracepoint-event-write.h>
660 #undef _ctf_integer_ext
661 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
662 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
665 #define _ctf_float(_type, _item, _src, _nowrite) \
666 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
668 #undef _ctf_array_encoded
669 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
670 _encoding, _nowrite, _elem_type_base) \
671 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
673 #undef _ctf_sequence_encoded
674 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
675 _src_length, _encoding, _nowrite, _elem_type_base) \
676 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
677 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
680 #define _ctf_string(_item, _src, _nowrite)
683 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
684 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
687 #define TP_ARGS(...) __VA_ARGS__
690 #define TP_FIELDS(...) __VA_ARGS__
692 #undef _TRACEPOINT_EVENT_CLASS
693 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
694 static inline lttng_ust_notrace \
695 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
697 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
699 size_t __event_align = 1; \
701 return __event_align; \
704 #include TRACEPOINT_INCLUDE
708 * Stage 5 of tracepoint event generation.
710 * Create the probe function. This function calls event size calculation
711 * and writes event data into the buffer.
714 /* Reset all macros within TRACEPOINT_EVENT */
715 #include <lttng/ust-tracepoint-event-reset.h>
716 #include <lttng/ust-tracepoint-event-write.h>
718 #undef _ctf_integer_ext
719 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
721 _type __tmp = (_src); \
722 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
723 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
727 #define _ctf_float(_type, _item, _src, _nowrite) \
729 _type __tmp = (_src); \
730 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
731 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
734 #undef _ctf_array_encoded
735 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
736 _encoding, _nowrite, _elem_type_base) \
737 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
738 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
740 #undef _ctf_sequence_encoded
741 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
742 _src_length, _encoding, _nowrite, _elem_type_base) \
744 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
745 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
746 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
748 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
749 __chan->ops->event_write(&__ctx, _src, \
750 sizeof(_type) * __get_dynamic_len(dest));
753 #define _ctf_string(_item, _src, _nowrite) \
755 const char *__ctf_tmp_string = \
756 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
757 lib_ring_buffer_align_ctx(&__ctx, \
758 lttng_alignof(*__ctf_tmp_string)); \
759 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
760 __get_dynamic_len(dest)); \
765 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
766 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
768 /* Beware: this get len actually consumes the len value */
769 #undef __get_dynamic_len
770 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
773 #define TP_ARGS(...) __VA_ARGS__
776 #define TP_FIELDS(...) __VA_ARGS__
779 * For state dump, check that "session" argument (mandatory) matches the
780 * session this event belongs to. Ensures that we write state dump data only
781 * into the started session, not into all sessions.
783 #undef _TP_SESSION_CHECK
784 #ifdef TP_SESSION_CHECK
785 #define _TP_SESSION_CHECK(session, csession) (session == csession)
786 #else /* TP_SESSION_CHECK */
787 #define _TP_SESSION_CHECK(session, csession) 1
788 #endif /* TP_SESSION_CHECK */
791 * Use of __builtin_return_address(0) sometimes seems to cause stack
792 * corruption on 32-bit PowerPC. Disable this feature on that
793 * architecture for now by always using the NULL value for the ip
798 #define _TP_IP_PARAM(x) (x)
799 #else /* TP_IP_PARAM */
801 #if defined(__PPC__) && !defined(__PPC64__)
802 #define _TP_IP_PARAM(x) NULL
803 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
804 #define _TP_IP_PARAM(x) __builtin_return_address(0)
805 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
807 #endif /* TP_IP_PARAM */
810 * Using twice size for filter stack data to hold size and pointer for
811 * each field (worse case). For integers, max size required is 64-bit.
812 * Same for double-precision floats. Those fit within
813 * 2*sizeof(unsigned long) for all supported architectures.
814 * Perform UNION (||) of filter runtime list.
816 #undef _TRACEPOINT_EVENT_CLASS
817 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
818 static lttng_ust_notrace \
819 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
821 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
823 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
824 size_t __dynamic_len_idx = 0; \
825 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
827 size_t __dynamic_len[__num_fields]; \
828 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
833 (void) __dynamic_len_idx; /* don't warn if unused */ \
834 switch (__event->type) { \
835 case LTTNG_UST_EVENT_TYPE_RECORDER: \
837 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
838 struct lttng_channel *__chan = __event_recorder->chan; \
840 if (!_TP_SESSION_CHECK(session, __chan->session)) \
842 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
844 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
848 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
851 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
853 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
855 if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \
856 struct lttng_bytecode_runtime *__filter_bc_runtime; \
857 int __filter_record = __event->has_enablers_without_bytecode; \
859 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
860 _TP_ARGS_DATA_VAR(_args)); \
861 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
862 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
863 __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \
864 __filter_record = 1; \
868 if (caa_likely(!__filter_record)) \
871 switch (__event->type) { \
872 case LTTNG_UST_EVENT_TYPE_RECORDER: \
874 size_t __event_len, __event_align; \
875 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
876 struct lttng_channel *__chan = __event_recorder->chan; \
877 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
878 struct lttng_stack_ctx __lttng_ctx; \
880 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
881 _TP_ARGS_DATA_VAR(_args)); \
882 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
883 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
884 __lttng_ctx.event_recorder = __event_recorder; \
885 __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \
886 __lttng_ctx.event_ctx = tp_rcu_dereference(__event_recorder->ctx); \
887 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_ctx, __event_len, \
888 __event_align, -1, __chan->handle); \
889 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
890 __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \
894 __chan->ops->event_commit(&__ctx); \
897 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
899 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
901 if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \
902 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
903 _TP_ARGS_DATA_VAR(_args)); \
905 __event_notifier->notification_send(__event_notifier, \
906 __stackvar.__interpreter_stack_data); \
912 #include TRACEPOINT_INCLUDE
914 #undef __get_dynamic_len
917 * Stage 5.1 of tracepoint event generation.
919 * Create probe signature
922 /* Reset all macros within TRACEPOINT_EVENT */
923 #include <lttng/ust-tracepoint-event-reset.h>
926 #define TP_ARGS(...) __VA_ARGS__
928 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
930 #undef _TRACEPOINT_EVENT_CLASS
931 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
932 static const char __tp_event_signature___##_provider##___##_name[] = \
933 _TP_EXTRACT_STRING2(_args);
935 #include TRACEPOINT_INCLUDE
937 #undef _TP_EXTRACT_STRING2
940 * Stage 6 of tracepoint event generation.
942 * Tracepoint loglevel mapping definition generation. We generate a
943 * symbol for each mapping for a provider/event to ensure at most a 1 to
944 * 1 mapping between events and loglevels. If the symbol is repeated,
945 * the compiler will complain.
948 /* Reset all macros within TRACEPOINT_EVENT */
949 #include <lttng/ust-tracepoint-event-reset.h>
952 * Declare _loglevel___##__provider##___##__name as non-static, with
953 * hidden visibility for c++ handling of weakref. We do a weakref to the
954 * symbol in a later stage, which requires that the symbol is not
958 #define LTTNG_TP_EXTERN_C extern "C"
960 #define LTTNG_TP_EXTERN_C
963 #undef TRACEPOINT_LOGLEVEL
964 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
965 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
966 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
967 __attribute__((visibility("hidden"))) = \
968 &_loglevel_value___##__provider##___##__name;
970 #include TRACEPOINT_INCLUDE
972 #undef LTTNG_TP_EXTERN_C
975 * Stage 6.1 of tracepoint event generation.
977 * Tracepoint UML URI info.
980 /* Reset all macros within TRACEPOINT_EVENT */
981 #include <lttng/ust-tracepoint-event-reset.h>
984 * Declare _model_emf_uri___##__provider##___##__name as non-static,
985 * with hidden visibility for c++ handling of weakref. We do a weakref
986 * to the symbol in a later stage, which requires that the symbol is not
990 #define LTTNG_TP_EXTERN_C extern "C"
992 #define LTTNG_TP_EXTERN_C
995 #undef TRACEPOINT_MODEL_EMF_URI
996 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
997 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
998 __attribute__((visibility("hidden"))) = __uri; \
1000 #include TRACEPOINT_INCLUDE
1002 #undef LTTNG_TP_EXTERN_C
1005 * Stage 7.1 of tracepoint event generation.
1007 * Create events description structures. We use a weakref because
1008 * loglevels are optional. If not declared, the event will point to the
1009 * a loglevel that contains NULL.
1012 /* Reset all macros within TRACEPOINT_EVENT */
1013 #include <lttng/ust-tracepoint-event-reset.h>
1015 #undef _TRACEPOINT_EVENT_INSTANCE
1016 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1017 static const int * \
1018 __ref_loglevel___##_provider##___##_name \
1019 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1020 static const char * \
1021 __ref_model_emf_uri___##_provider##___##_name \
1022 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1023 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
1024 .name = #_provider ":" #_name, \
1025 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
1027 .fields = __event_fields___##_provider##___##_template, \
1028 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1029 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1030 .signature = __tp_event_signature___##_provider##___##_template, \
1033 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1038 #include TRACEPOINT_INCLUDE
1041 * Stage 7.2 of tracepoint event generation.
1043 * Create array of events.
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 &__event_desc___##_provider##_##_name,
1053 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1054 #include TRACEPOINT_INCLUDE
1055 NULL
, /* Dummy, C99 forbids 0-len array. */
1060 * Stage 8 of tracepoint event generation.
1062 * Create a toplevel descriptor for the whole probe.
1065 /* non-const because list head will be modified when registered. */
1066 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1067 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
1068 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1069 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1070 .head
= { NULL
, NULL
},
1071 .lazy_init_head
= { NULL
, NULL
},
1073 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1074 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1077 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1080 * Stage 9 of tracepoint event generation.
1082 * Register/unregister probes at module load/unload.
1084 * Generate the constructor as an externally visible symbol for use when
1085 * linking the probe statically.
1087 * Register refcount is protected by libc dynamic loader mutex.
1090 /* Reset all macros within TRACEPOINT_EVENT */
1091 #include <lttng/ust-tracepoint-event-reset.h>
1092 static void lttng_ust_notrace
__attribute__((constructor
))
1093 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1095 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1099 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1100 TRACEPOINT_PROVIDER
)++) {
1104 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1105 * static inline function that ensures every probe PROVIDER
1106 * argument match the provider within which they appear. It
1107 * calls empty static inline functions, and therefore has no
1108 * runtime effect. However, if it detects an error, a linker
1109 * error will appear.
1111 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1112 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1114 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1119 static void lttng_ust_notrace
__attribute__((destructor
))
1120 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1122 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1124 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1125 TRACEPOINT_PROVIDER
)) {
1128 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1131 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1132 __attribute__((visibility("default")));