2 * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include <urcu/compiler.h>
27 #include <urcu/rculist.h>
28 #include <lttng/ust-events.h>
29 #include <lttng/ringbuffer-config.h>
30 #include <lttng/ust-compiler.h>
31 #include <lttng/tracepoint.h>
32 #include <lttng/ust-endian.h>
35 #define __LTTNG_UST_NULL_STRING "(null)"
37 #undef tp_list_for_each_entry_rcu
38 #define tp_list_for_each_entry_rcu(pos, head, member) \
39 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
40 &pos->member != (head); \
41 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
44 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
45 * same arguments and having the same field layout.
47 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
48 * its own provider and name. It refers to a class (template).
50 * TRACEPOINT_EVENT declared both a class and an instance and does a
51 * direct mapping from the instance to the class.
54 #undef TRACEPOINT_EVENT
55 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
56 TRACEPOINT_EVENT_CLASS(_provider, _name, \
58 _TP_PARAMS(_fields)) \
59 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
63 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
65 #define _tp_max_t(type, x, y) \
69 __max1 > __max2 ? __max1: __max2; \
73 * Stage 0 of tracepoint event generation.
75 * Check that each TRACEPOINT_EVENT provider argument match the
76 * TRACEPOINT_PROVIDER by creating dummy callbacks.
79 /* Reset all macros within TRACEPOINT_EVENT */
80 #include <lttng/ust-tracepoint-event-reset.h>
82 static inline lttng_ust_notrace
83 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
85 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
89 #undef TRACEPOINT_EVENT_CLASS
90 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
91 __tracepoint_provider_mismatch_##_provider();
93 #undef TRACEPOINT_EVENT_INSTANCE
94 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
95 __tracepoint_provider_mismatch_##_provider();
97 static inline lttng_ust_notrace
98 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
100 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
102 #include TRACEPOINT_INCLUDE
106 * Stage 0.1 of tracepoint event generation.
108 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
109 * tracepoint name length limit.
112 /* Reset all macros within TRACEPOINT_EVENT */
113 #include <lttng/ust-tracepoint-event-reset.h>
115 #undef TRACEPOINT_EVENT_INSTANCE
116 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
118 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
119 __attribute__((unused)) = \
120 #_provider ":" #_name;
122 #include TRACEPOINT_INCLUDE
125 * Stage 0.2 of tracepoint event generation.
127 * Create dummy trace prototypes for each event class, and for each used
128 * template. This will allow checking whether the prototypes from the
129 * class and the instance using the class actually match.
132 /* Reset all macros within TRACEPOINT_EVENT */
133 #include <lttng/ust-tracepoint-event-reset.h>
136 #define TP_ARGS(...) __VA_ARGS__
138 #undef TRACEPOINT_EVENT_INSTANCE
139 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
140 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
142 #undef TRACEPOINT_EVENT_CLASS
143 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
144 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
146 #include TRACEPOINT_INCLUDE
149 * Stage 0.9 of tracepoint event generation
151 * Unfolding the enums
153 #include <lttng/ust-tracepoint-event-reset.h>
155 /* Enumeration entry (single value) */
156 #undef ctf_enum_value
157 #define ctf_enum_value(_string, _value) \
160 .value = lttng_is_signed_type(__typeof__(_value)) ? \
161 (long long) (_value) : (_value), \
162 .signedness = lttng_is_signed_type(__typeof__(_value)), \
165 .value = lttng_is_signed_type(__typeof__(_value)) ? \
166 (long long) (_value) : (_value), \
167 .signedness = lttng_is_signed_type(__typeof__(_value)), \
169 .string = (_string), \
172 /* Enumeration entry (range) */
173 #undef ctf_enum_range
174 #define ctf_enum_range(_string, _range_start, _range_end) \
177 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
178 (long long) (_range_start) : (_range_start), \
179 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
182 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
183 (long long) (_range_end) : (_range_end), \
184 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
186 .string = (_string), \
189 /* Enumeration entry (automatic value; follows the rules of CTF) */
191 #define ctf_enum_auto(_string) \
201 .string = (_string), \
204 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
209 #undef TP_ENUM_VALUES
210 #define TP_ENUM_VALUES(...) \
213 #undef TRACEPOINT_ENUM
214 #define TRACEPOINT_ENUM(_provider, _name, _values) \
215 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
217 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
219 #include TRACEPOINT_INCLUDE
223 * Verifying array and sequence elements are of an integer type.
226 /* Reset all macros within TRACEPOINT_EVENT */
227 #include <lttng/ust-tracepoint-event-reset.h>
228 #include <lttng/ust-tracepoint-event-write.h>
229 #include <lttng/ust-tracepoint-event-nowrite.h>
231 #undef _ctf_array_encoded
232 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
233 _length, _encoding, _nowrite, \
235 _lttng_array_element_type_is_supported(_type, _item)
237 #undef _ctf_sequence_encoded
238 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
239 _length_type, _src_length, _encoding, _nowrite, \
241 _lttng_array_element_type_is_supported(_type, _item)
244 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
246 #undef TRACEPOINT_EVENT_CLASS
247 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
250 #include TRACEPOINT_INCLUDE
253 * Stage 1 of tracepoint event generation.
255 * Create event field type metadata section.
256 * Each event produce an array of fields.
259 /* Reset all macros within TRACEPOINT_EVENT */
260 #include <lttng/ust-tracepoint-event-reset.h>
261 #include <lttng/ust-tracepoint-event-write.h>
262 #include <lttng/ust-tracepoint-event-nowrite.h>
264 #undef _ctf_integer_ext
265 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
268 .type = __type_integer(_type, _byte_order, _base, none),\
269 .nowrite = _nowrite, \
278 #define _ctf_float(_type, _item, _src, _nowrite) \
281 .type = __type_float(_type), \
282 .nowrite = _nowrite, \
290 #undef _ctf_array_encoded
291 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
292 _length, _encoding, _nowrite, \
298 .atype = atype_array_nestable, \
303 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
304 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
310 .nowrite = _nowrite, \
318 #undef _ctf_sequence_encoded
319 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
320 _length_type, _src_length, _encoding, _nowrite, \
323 .name = "_" #_item "_length", \
324 .type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
325 .nowrite = _nowrite, \
336 .atype = atype_sequence_nestable, \
339 .sequence_nestable = \
341 .length_name = "_" #_item "_length", \
342 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
343 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
348 .nowrite = _nowrite, \
357 #define _ctf_string(_item, _src, _nowrite) \
362 .atype = atype_string, \
365 .string = { .encoding = lttng_encode_UTF8 } \
368 .nowrite = _nowrite, \
377 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
381 .atype = atype_enum_nestable, \
384 .desc = &__enum_##_provider##_##_name, \
385 .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
386 __type_integer(_type, BYTE_ORDER, 10, none)), \
390 .nowrite = _nowrite, \
399 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
401 #undef TRACEPOINT_EVENT_CLASS
402 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
403 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
405 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
408 #undef TRACEPOINT_ENUM
409 #define TRACEPOINT_ENUM(_provider, _name, _values) \
410 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
411 .name = #_provider "_" #_name, \
412 .entries = __enum_values__##_provider##_##_name, \
413 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
416 #include TRACEPOINT_INCLUDE
419 * Stage 2 of tracepoint event generation.
421 * Create probe callback prototypes.
424 /* Reset all macros within TRACEPOINT_EVENT */
425 #include <lttng/ust-tracepoint-event-reset.h>
428 #define TP_ARGS(...) __VA_ARGS__
430 #undef TRACEPOINT_EVENT_CLASS
431 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
432 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
434 #include TRACEPOINT_INCLUDE
437 * Stage 3.0 of tracepoint event generation.
439 * Create static inline function that calculates event size.
442 /* Reset all macros within TRACEPOINT_EVENT */
443 #include <lttng/ust-tracepoint-event-reset.h>
444 #include <lttng/ust-tracepoint-event-write.h>
446 #undef _ctf_integer_ext
447 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
448 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
449 __event_len += sizeof(_type);
452 #define _ctf_float(_type, _item, _src, _nowrite) \
453 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
454 __event_len += sizeof(_type);
456 #undef _ctf_array_encoded
457 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
458 _nowrite, _elem_type_base) \
459 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
460 __event_len += sizeof(_type) * (_length);
462 #undef _ctf_sequence_encoded
463 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
464 _src_length, _encoding, _nowrite, _elem_type_base) \
465 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
466 __event_len += sizeof(_length_type); \
467 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
468 __dynamic_len[__dynamic_len_idx] = (_src_length); \
469 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
473 #define _ctf_string(_item, _src, _nowrite) \
474 __event_len += __dynamic_len[__dynamic_len_idx++] = \
475 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
478 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
479 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
482 #define TP_ARGS(...) __VA_ARGS__
485 #define TP_FIELDS(...) __VA_ARGS__
487 #undef TRACEPOINT_EVENT_CLASS
488 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
489 static inline lttng_ust_notrace \
490 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
492 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
494 size_t __event_len = 0; \
495 unsigned int __dynamic_len_idx = 0; \
498 (void) __dynamic_len_idx; /* don't warn if unused */ \
500 return __event_len; \
503 #include TRACEPOINT_INCLUDE
506 * Stage 3.1 of tracepoint event generation.
508 * Create static inline function that layout the filter stack data.
509 * We make both write and nowrite data available to the filter.
512 /* Reset all macros within TRACEPOINT_EVENT */
513 #include <lttng/ust-tracepoint-event-reset.h>
514 #include <lttng/ust-tracepoint-event-write.h>
515 #include <lttng/ust-tracepoint-event-nowrite.h>
517 #undef _ctf_integer_ext
518 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
519 if (lttng_is_signed_type(_type)) { \
520 int64_t __ctf_tmp_int64; \
521 switch (sizeof(_type)) { \
524 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
525 __ctf_tmp_int64 = (int64_t) __tmp.v; \
530 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
531 if (_byte_order != BYTE_ORDER) \
532 __tmp.v = bswap_16(__tmp.v); \
533 __ctf_tmp_int64 = (int64_t) __tmp.v; \
538 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
539 if (_byte_order != BYTE_ORDER) \
540 __tmp.v = bswap_32(__tmp.v); \
541 __ctf_tmp_int64 = (int64_t) __tmp.v; \
546 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
547 if (_byte_order != BYTE_ORDER) \
548 __tmp.v = bswap_64(__tmp.v); \
549 __ctf_tmp_int64 = (int64_t) __tmp.v; \
555 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
557 uint64_t __ctf_tmp_uint64; \
558 switch (sizeof(_type)) { \
561 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
562 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
567 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
568 if (_byte_order != BYTE_ORDER) \
569 __tmp.v = bswap_16(__tmp.v); \
570 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
575 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
576 if (_byte_order != BYTE_ORDER) \
577 __tmp.v = bswap_32(__tmp.v); \
578 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
583 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
584 if (_byte_order != BYTE_ORDER) \
585 __tmp.v = bswap_64(__tmp.v); \
586 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
592 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
594 __stack_data += sizeof(int64_t);
597 #define _ctf_float(_type, _item, _src, _nowrite) \
599 double __ctf_tmp_double = (double) (_type) (_src); \
600 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
601 __stack_data += sizeof(double); \
604 #undef _ctf_array_encoded
605 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
606 _encoding, _nowrite, _elem_type_base) \
608 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
609 const void *__ctf_tmp_ptr = (_src); \
610 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
611 __stack_data += sizeof(unsigned long); \
612 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
613 __stack_data += sizeof(void *); \
616 #undef _ctf_sequence_encoded
617 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
618 _src_length, _encoding, _nowrite, _elem_type_base) \
620 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
621 const void *__ctf_tmp_ptr = (_src); \
622 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
623 __stack_data += sizeof(unsigned long); \
624 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
625 __stack_data += sizeof(void *); \
629 #define _ctf_string(_item, _src, _nowrite) \
631 const void *__ctf_tmp_ptr = \
632 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
633 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
634 __stack_data += sizeof(void *); \
638 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
639 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
642 #define TP_ARGS(...) __VA_ARGS__
645 #define TP_FIELDS(...) __VA_ARGS__
647 #undef TRACEPOINT_EVENT_CLASS
648 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
650 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
651 _TP_ARGS_DATA_PROTO(_args)) \
656 #include TRACEPOINT_INCLUDE
659 * Stage 4 of tracepoint event generation.
661 * Create static inline function that calculates event payload alignment.
664 /* Reset all macros within TRACEPOINT_EVENT */
665 #include <lttng/ust-tracepoint-event-reset.h>
666 #include <lttng/ust-tracepoint-event-write.h>
668 #undef _ctf_integer_ext
669 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
670 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
673 #define _ctf_float(_type, _item, _src, _nowrite) \
674 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
676 #undef _ctf_array_encoded
677 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
678 _encoding, _nowrite, _elem_type_base) \
679 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
681 #undef _ctf_sequence_encoded
682 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
683 _src_length, _encoding, _nowrite, _elem_type_base) \
684 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
685 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
688 #define _ctf_string(_item, _src, _nowrite)
691 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
692 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
695 #define TP_ARGS(...) __VA_ARGS__
698 #define TP_FIELDS(...) __VA_ARGS__
700 #undef TRACEPOINT_EVENT_CLASS
701 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
702 static inline lttng_ust_notrace \
703 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
705 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
707 size_t __event_align = 1; \
709 return __event_align; \
712 #include TRACEPOINT_INCLUDE
716 * Stage 5 of tracepoint event generation.
718 * Create the probe function. This function calls event size calculation
719 * and writes event data into the buffer.
722 /* Reset all macros within TRACEPOINT_EVENT */
723 #include <lttng/ust-tracepoint-event-reset.h>
724 #include <lttng/ust-tracepoint-event-write.h>
726 #undef _ctf_integer_ext
727 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
729 _type __tmp = (_src); \
730 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
731 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
735 #define _ctf_float(_type, _item, _src, _nowrite) \
737 _type __tmp = (_src); \
738 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
739 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
742 #undef _ctf_array_encoded
743 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
744 _encoding, _nowrite, _elem_type_base) \
745 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
746 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
748 #undef _ctf_sequence_encoded
749 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
750 _src_length, _encoding, _nowrite, _elem_type_base) \
752 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
753 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
754 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
756 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
757 __chan->ops->event_write(&__ctx, _src, \
758 sizeof(_type) * __get_dynamic_len(dest));
761 #define _ctf_string(_item, _src, _nowrite) \
763 const char *__ctf_tmp_string = \
764 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
765 lib_ring_buffer_align_ctx(&__ctx, \
766 lttng_alignof(*__ctf_tmp_string)); \
767 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
768 __get_dynamic_len(dest)); \
773 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
774 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
776 /* Beware: this get len actually consumes the len value */
777 #undef __get_dynamic_len
778 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
781 #define TP_ARGS(...) __VA_ARGS__
784 #define TP_FIELDS(...) __VA_ARGS__
787 * For state dump, check that "session" argument (mandatory) matches the
788 * session this event belongs to. Ensures that we write state dump data only
789 * into the started session, not into all sessions.
791 #undef _TP_SESSION_CHECK
792 #ifdef TP_SESSION_CHECK
793 #define _TP_SESSION_CHECK(session, csession) (session == csession)
794 #else /* TP_SESSION_CHECK */
795 #define _TP_SESSION_CHECK(session, csession) 1
796 #endif /* TP_SESSION_CHECK */
799 * Use of __builtin_return_address(0) sometimes seems to cause stack
800 * corruption on 32-bit PowerPC. Disable this feature on that
801 * architecture for now by always using the NULL value for the ip
806 #define _TP_IP_PARAM(x) (x)
807 #else /* TP_IP_PARAM */
809 #if defined(__PPC__) && !defined(__PPC64__)
810 #define _TP_IP_PARAM(x) NULL
811 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
812 #define _TP_IP_PARAM(x) __builtin_return_address(0)
813 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
815 #endif /* TP_IP_PARAM */
818 * Using twice size for filter stack data to hold size and pointer for
819 * each field (worse case). For integers, max size required is 64-bit.
820 * Same for double-precision floats. Those fit within
821 * 2*sizeof(unsigned long) for all supported architectures.
822 * Perform UNION (||) of filter runtime list.
824 #undef TRACEPOINT_EVENT_CLASS
825 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
826 static lttng_ust_notrace \
827 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
829 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
831 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
832 struct lttng_channel *__chan = __event->chan; \
833 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
834 struct lttng_stack_ctx __lttng_ctx; \
835 size_t __event_len, __event_align; \
836 size_t __dynamic_len_idx = 0; \
837 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
839 size_t __dynamic_len[__num_fields]; \
840 char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
845 (void) __dynamic_len_idx; /* don't warn if unused */ \
846 if (!_TP_SESSION_CHECK(session, __chan->session)) \
848 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
850 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
852 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
854 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
856 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
857 struct lttng_bytecode_runtime *bc_runtime; \
858 int __filter_record = __event->has_enablers_without_bytecode; \
860 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
861 _TP_ARGS_DATA_VAR(_args)); \
862 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
863 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
864 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \
865 __filter_record = 1; \
869 if (caa_likely(!__filter_record)) \
872 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
873 _TP_ARGS_DATA_VAR(_args)); \
874 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
875 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
876 __lttng_ctx.event = __event; \
877 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
878 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
879 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
880 __event_align, -1, __chan->handle, &__lttng_ctx); \
881 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
882 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
886 __chan->ops->event_commit(&__ctx); \
889 #include TRACEPOINT_INCLUDE
891 #undef __get_dynamic_len
894 * Stage 5.1 of tracepoint event generation.
896 * Create probe signature
899 /* Reset all macros within TRACEPOINT_EVENT */
900 #include <lttng/ust-tracepoint-event-reset.h>
903 #define TP_ARGS(...) __VA_ARGS__
905 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
907 #undef TRACEPOINT_EVENT_CLASS
908 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
909 static const char __tp_event_signature___##_provider##___##_name[] = \
910 _TP_EXTRACT_STRING2(_args);
912 #include TRACEPOINT_INCLUDE
914 #undef _TP_EXTRACT_STRING2
917 * Stage 6 of tracepoint event generation.
919 * Tracepoint loglevel mapping definition generation. We generate a
920 * symbol for each mapping for a provider/event to ensure at most a 1 to
921 * 1 mapping between events and loglevels. If the symbol is repeated,
922 * the compiler will complain.
925 /* Reset all macros within TRACEPOINT_EVENT */
926 #include <lttng/ust-tracepoint-event-reset.h>
929 * Declare _loglevel___##__provider##___##__name as non-static, with
930 * hidden visibility for c++ handling of weakref. We do a weakref to the
931 * symbol in a later stage, which requires that the symbol is not
935 #define LTTNG_TP_EXTERN_C extern "C"
937 #define LTTNG_TP_EXTERN_C
940 #undef TRACEPOINT_LOGLEVEL
941 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
942 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
943 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
944 __attribute__((visibility("hidden"))) = \
945 &_loglevel_value___##__provider##___##__name;
947 #include TRACEPOINT_INCLUDE
949 #undef LTTNG_TP_EXTERN_C
952 * Stage 6.1 of tracepoint event generation.
954 * Tracepoint UML URI info.
957 /* Reset all macros within TRACEPOINT_EVENT */
958 #include <lttng/ust-tracepoint-event-reset.h>
961 * Declare _model_emf_uri___##__provider##___##__name as non-static,
962 * with hidden visibility for c++ handling of weakref. We do a weakref
963 * to the symbol in a later stage, which requires that the symbol is not
967 #define LTTNG_TP_EXTERN_C extern "C"
969 #define LTTNG_TP_EXTERN_C
972 #undef TRACEPOINT_MODEL_EMF_URI
973 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
974 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
975 __attribute__((visibility("hidden"))) = __uri; \
977 #include TRACEPOINT_INCLUDE
979 #undef LTTNG_TP_EXTERN_C
982 * Stage 7.1 of tracepoint event generation.
984 * Create events description structures. We use a weakref because
985 * loglevels are optional. If not declared, the event will point to the
986 * a loglevel that contains NULL.
989 /* Reset all macros within TRACEPOINT_EVENT */
990 #include <lttng/ust-tracepoint-event-reset.h>
992 #undef TRACEPOINT_EVENT_INSTANCE
993 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
995 __ref_loglevel___##_provider##___##_name \
996 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
997 static const char * \
998 __ref_model_emf_uri___##_provider##___##_name \
999 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1000 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
1001 .name = #_provider ":" #_name, \
1002 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
1004 .fields = __event_fields___##_provider##___##_template, \
1005 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1006 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1007 .signature = __tp_event_signature___##_provider##___##_template, \
1010 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1015 #include TRACEPOINT_INCLUDE
1018 * Stage 7.2 of tracepoint event generation.
1020 * Create array of events.
1023 /* Reset all macros within TRACEPOINT_EVENT */
1024 #include <lttng/ust-tracepoint-event-reset.h>
1026 #undef TRACEPOINT_EVENT_INSTANCE
1027 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1028 &__event_desc___##_provider##_##_name,
1030 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1031 #include TRACEPOINT_INCLUDE
1032 NULL
, /* Dummy, C99 forbids 0-len array. */
1037 * Stage 8 of tracepoint event generation.
1039 * Create a toplevel descriptor for the whole probe.
1042 /* non-const because list head will be modified when registered. */
1043 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1044 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
1045 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1046 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1047 .head
= { NULL
, NULL
},
1048 .lazy_init_head
= { NULL
, NULL
},
1050 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1051 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1054 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1057 * Stage 9 of tracepoint event generation.
1059 * Register/unregister probes at module load/unload.
1061 * Generate the constructor as an externally visible symbol for use when
1062 * linking the probe statically.
1064 * Register refcount is protected by libc dynamic loader mutex.
1067 /* Reset all macros within TRACEPOINT_EVENT */
1068 #include <lttng/ust-tracepoint-event-reset.h>
1069 static void lttng_ust_notrace
__attribute__((constructor
))
1070 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1072 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1076 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1077 TRACEPOINT_PROVIDER
)++) {
1081 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1082 * static inline function that ensures every probe PROVIDER
1083 * argument match the provider within which they appear. It
1084 * calls empty static inline functions, and therefore has no
1085 * runtime effect. However, if it detects an error, a linker
1086 * error will appear.
1088 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1089 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1091 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1096 static void lttng_ust_notrace
__attribute__((destructor
))
1097 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1099 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1101 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1102 TRACEPOINT_PROVIDER
)) {
1105 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1108 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);