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 2.1 of tracepoint event generation.
439 * Create probe event notifier callback prototypes.
442 /* Reset all macros within TRACEPOINT_EVENT */
443 #include <lttng/ust-tracepoint-event-reset.h>
446 #define TP_ARGS(...) __VA_ARGS__
448 #undef TRACEPOINT_EVENT_CLASS
449 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
450 static void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
452 #include TRACEPOINT_INCLUDE
455 * Stage 3.0 of tracepoint event generation.
457 * Create static inline function that calculates event size.
460 /* Reset all macros within TRACEPOINT_EVENT */
461 #include <lttng/ust-tracepoint-event-reset.h>
462 #include <lttng/ust-tracepoint-event-write.h>
464 #undef _ctf_integer_ext
465 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
466 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
467 __event_len += sizeof(_type);
470 #define _ctf_float(_type, _item, _src, _nowrite) \
471 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
472 __event_len += sizeof(_type);
474 #undef _ctf_array_encoded
475 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
476 _nowrite, _elem_type_base) \
477 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
478 __event_len += sizeof(_type) * (_length);
480 #undef _ctf_sequence_encoded
481 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
482 _src_length, _encoding, _nowrite, _elem_type_base) \
483 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
484 __event_len += sizeof(_length_type); \
485 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
486 __dynamic_len[__dynamic_len_idx] = (_src_length); \
487 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
491 #define _ctf_string(_item, _src, _nowrite) \
492 __event_len += __dynamic_len[__dynamic_len_idx++] = \
493 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
496 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
497 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
500 #define TP_ARGS(...) __VA_ARGS__
503 #define TP_FIELDS(...) __VA_ARGS__
505 #undef TRACEPOINT_EVENT_CLASS
506 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
507 static inline lttng_ust_notrace \
508 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
510 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
512 size_t __event_len = 0; \
513 unsigned int __dynamic_len_idx = 0; \
516 (void) __dynamic_len_idx; /* don't warn if unused */ \
518 return __event_len; \
521 #include TRACEPOINT_INCLUDE
524 * Stage 3.1 of tracepoint event generation.
526 * Create static inline function that layout the filter stack data.
527 * We make both write and nowrite data available to the filter.
530 /* Reset all macros within TRACEPOINT_EVENT */
531 #include <lttng/ust-tracepoint-event-reset.h>
532 #include <lttng/ust-tracepoint-event-write.h>
533 #include <lttng/ust-tracepoint-event-nowrite.h>
535 #undef _ctf_integer_ext
536 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
537 if (lttng_is_signed_type(_type)) { \
538 int64_t __ctf_tmp_int64; \
539 switch (sizeof(_type)) { \
542 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
543 __ctf_tmp_int64 = (int64_t) __tmp.v; \
548 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
549 if (_byte_order != BYTE_ORDER) \
550 __tmp.v = bswap_16(__tmp.v); \
551 __ctf_tmp_int64 = (int64_t) __tmp.v; \
556 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
557 if (_byte_order != BYTE_ORDER) \
558 __tmp.v = bswap_32(__tmp.v); \
559 __ctf_tmp_int64 = (int64_t) __tmp.v; \
564 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
565 if (_byte_order != BYTE_ORDER) \
566 __tmp.v = bswap_64(__tmp.v); \
567 __ctf_tmp_int64 = (int64_t) __tmp.v; \
573 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
575 uint64_t __ctf_tmp_uint64; \
576 switch (sizeof(_type)) { \
579 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
580 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
585 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
586 if (_byte_order != BYTE_ORDER) \
587 __tmp.v = bswap_16(__tmp.v); \
588 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
593 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
594 if (_byte_order != BYTE_ORDER) \
595 __tmp.v = bswap_32(__tmp.v); \
596 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
601 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
602 if (_byte_order != BYTE_ORDER) \
603 __tmp.v = bswap_64(__tmp.v); \
604 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
610 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
612 __stack_data += sizeof(int64_t);
615 #define _ctf_float(_type, _item, _src, _nowrite) \
617 double __ctf_tmp_double = (double) (_type) (_src); \
618 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
619 __stack_data += sizeof(double); \
622 #undef _ctf_array_encoded
623 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
624 _encoding, _nowrite, _elem_type_base) \
626 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
627 const void *__ctf_tmp_ptr = (_src); \
628 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
629 __stack_data += sizeof(unsigned long); \
630 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
631 __stack_data += sizeof(void *); \
634 #undef _ctf_sequence_encoded
635 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
636 _src_length, _encoding, _nowrite, _elem_type_base) \
638 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
639 const void *__ctf_tmp_ptr = (_src); \
640 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
641 __stack_data += sizeof(unsigned long); \
642 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
643 __stack_data += sizeof(void *); \
647 #define _ctf_string(_item, _src, _nowrite) \
649 const void *__ctf_tmp_ptr = \
650 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
651 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
652 __stack_data += sizeof(void *); \
656 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
657 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
660 #define TP_ARGS(...) __VA_ARGS__
663 #define TP_FIELDS(...) __VA_ARGS__
665 #undef TRACEPOINT_EVENT_CLASS
666 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
668 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
669 _TP_ARGS_DATA_PROTO(_args)) \
674 #include TRACEPOINT_INCLUDE
677 * Stage 4 of tracepoint event generation.
679 * Create static inline function that calculates event payload alignment.
682 /* Reset all macros within TRACEPOINT_EVENT */
683 #include <lttng/ust-tracepoint-event-reset.h>
684 #include <lttng/ust-tracepoint-event-write.h>
686 #undef _ctf_integer_ext
687 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
688 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
691 #define _ctf_float(_type, _item, _src, _nowrite) \
692 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
694 #undef _ctf_array_encoded
695 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
696 _encoding, _nowrite, _elem_type_base) \
697 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
699 #undef _ctf_sequence_encoded
700 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
701 _src_length, _encoding, _nowrite, _elem_type_base) \
702 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
703 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
706 #define _ctf_string(_item, _src, _nowrite)
709 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
710 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
713 #define TP_ARGS(...) __VA_ARGS__
716 #define TP_FIELDS(...) __VA_ARGS__
718 #undef TRACEPOINT_EVENT_CLASS
719 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
720 static inline lttng_ust_notrace \
721 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
723 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
725 size_t __event_align = 1; \
727 return __event_align; \
730 #include TRACEPOINT_INCLUDE
734 * Stage 5 of tracepoint event generation.
736 * Create the probe function. This function calls event size calculation
737 * and writes event data into the buffer.
740 /* Reset all macros within TRACEPOINT_EVENT */
741 #include <lttng/ust-tracepoint-event-reset.h>
742 #include <lttng/ust-tracepoint-event-write.h>
744 #undef _ctf_integer_ext
745 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
747 _type __tmp = (_src); \
748 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
749 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
753 #define _ctf_float(_type, _item, _src, _nowrite) \
755 _type __tmp = (_src); \
756 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
757 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
760 #undef _ctf_array_encoded
761 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
762 _encoding, _nowrite, _elem_type_base) \
763 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
764 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
766 #undef _ctf_sequence_encoded
767 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
768 _src_length, _encoding, _nowrite, _elem_type_base) \
770 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
771 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
772 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
774 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
775 __chan->ops->event_write(&__ctx, _src, \
776 sizeof(_type) * __get_dynamic_len(dest));
779 #define _ctf_string(_item, _src, _nowrite) \
781 const char *__ctf_tmp_string = \
782 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
783 lib_ring_buffer_align_ctx(&__ctx, \
784 lttng_alignof(*__ctf_tmp_string)); \
785 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
786 __get_dynamic_len(dest)); \
791 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
792 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
794 /* Beware: this get len actually consumes the len value */
795 #undef __get_dynamic_len
796 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
799 #define TP_ARGS(...) __VA_ARGS__
802 #define TP_FIELDS(...) __VA_ARGS__
805 * For state dump, check that "session" argument (mandatory) matches the
806 * session this event belongs to. Ensures that we write state dump data only
807 * into the started session, not into all sessions.
809 #undef _TP_SESSION_CHECK
810 #ifdef TP_SESSION_CHECK
811 #define _TP_SESSION_CHECK(session, csession) (session == csession)
812 #else /* TP_SESSION_CHECK */
813 #define _TP_SESSION_CHECK(session, csession) 1
814 #endif /* TP_SESSION_CHECK */
817 * Use of __builtin_return_address(0) sometimes seems to cause stack
818 * corruption on 32-bit PowerPC. Disable this feature on that
819 * architecture for now by always using the NULL value for the ip
824 #define _TP_IP_PARAM(x) (x)
825 #else /* TP_IP_PARAM */
827 #if defined(__PPC__) && !defined(__PPC64__)
828 #define _TP_IP_PARAM(x) NULL
829 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
830 #define _TP_IP_PARAM(x) __builtin_return_address(0)
831 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
833 #endif /* TP_IP_PARAM */
836 * Using twice size for filter stack data to hold size and pointer for
837 * each field (worse case). For integers, max size required is 64-bit.
838 * Same for double-precision floats. Those fit within
839 * 2*sizeof(unsigned long) for all supported architectures.
840 * Perform UNION (||) of filter runtime list.
842 #undef TRACEPOINT_EVENT_CLASS
843 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
844 static lttng_ust_notrace \
845 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
847 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
849 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
850 struct lttng_channel *__chan = __event->chan; \
851 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
852 struct lttng_stack_ctx __lttng_ctx; \
853 size_t __event_len, __event_align; \
854 size_t __dynamic_len_idx = 0; \
855 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
857 size_t __dynamic_len[__num_fields]; \
858 char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
863 (void) __dynamic_len_idx; /* don't warn if unused */ \
864 if (!_TP_SESSION_CHECK(session, __chan->session)) \
866 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
868 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
870 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
872 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
874 if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \
875 struct lttng_bytecode_runtime *__filter_bc_runtime; \
876 int __filter_record = __event->has_enablers_without_bytecode; \
878 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
879 _TP_ARGS_DATA_VAR(_args)); \
880 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
881 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
882 __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \
883 __filter_record = 1; \
887 if (caa_likely(!__filter_record)) \
890 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
891 _TP_ARGS_DATA_VAR(_args)); \
892 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
893 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
894 __lttng_ctx.event = __event; \
895 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
896 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
897 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
898 __event_align, -1, __chan->handle, &__lttng_ctx); \
899 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
900 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
904 __chan->ops->event_commit(&__ctx); \
907 #include TRACEPOINT_INCLUDE
909 #undef __get_dynamic_len
912 * Stage 5.1 of tracepoint event generation.
914 * Create probe signature
917 /* Reset all macros within TRACEPOINT_EVENT */
918 #include <lttng/ust-tracepoint-event-reset.h>
921 #define TP_ARGS(...) __VA_ARGS__
923 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
925 #undef TRACEPOINT_EVENT_CLASS
926 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
927 static const char __tp_event_signature___##_provider##___##_name[] = \
928 _TP_EXTRACT_STRING2(_args);
930 #include TRACEPOINT_INCLUDE
932 #undef _TP_EXTRACT_STRING2
935 * Stage 5.2 of tracepoint event generation.
937 * Create the event notifier probe function.
939 #undef TRACEPOINT_EVENT_CLASS
940 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
941 static lttng_ust_notrace \
942 void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
944 void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
946 struct lttng_event_notifier *__event_notifier = (struct lttng_event_notifier *) __tp_data; \
947 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1;\
949 size_t __dynamic_len[__num_fields]; \
950 char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
952 if (caa_unlikely(!CMM_ACCESS_ONCE(__event_notifier->enabled))) \
954 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
956 if (caa_unlikely(!cds_list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \
957 struct lttng_bytecode_runtime *__filter_bc_runtime; \
958 int __filter_record = __event_notifier->has_enablers_without_bytecode; \
960 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
961 _TP_ARGS_DATA_VAR(_args)); \
962 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \
963 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
964 __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \
965 __filter_record = 1; \
967 if (caa_likely(!__filter_record)) \
971 lttng_event_notifier_notification_send(__event_notifier); \
974 #include TRACEPOINT_INCLUDE
977 * Stage 6 of tracepoint event generation.
979 * Tracepoint loglevel mapping definition generation. We generate a
980 * symbol for each mapping for a provider/event to ensure at most a 1 to
981 * 1 mapping between events and loglevels. If the symbol is repeated,
982 * the compiler will complain.
985 /* Reset all macros within TRACEPOINT_EVENT */
986 #include <lttng/ust-tracepoint-event-reset.h>
989 * Declare _loglevel___##__provider##___##__name as non-static, with
990 * hidden visibility for c++ handling of weakref. We do a weakref to the
991 * symbol in a later stage, which requires that the symbol is not
995 #define LTTNG_TP_EXTERN_C extern "C"
997 #define LTTNG_TP_EXTERN_C
1000 #undef TRACEPOINT_LOGLEVEL
1001 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
1002 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
1003 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
1004 __attribute__((visibility("hidden"))) = \
1005 &_loglevel_value___##__provider##___##__name;
1007 #include TRACEPOINT_INCLUDE
1009 #undef LTTNG_TP_EXTERN_C
1012 * Stage 6.1 of tracepoint event generation.
1014 * Tracepoint UML URI info.
1017 /* Reset all macros within TRACEPOINT_EVENT */
1018 #include <lttng/ust-tracepoint-event-reset.h>
1021 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1022 * with hidden visibility for c++ handling of weakref. We do a weakref
1023 * to the symbol in a later stage, which requires that the symbol is not
1027 #define LTTNG_TP_EXTERN_C extern "C"
1029 #define LTTNG_TP_EXTERN_C
1032 #undef TRACEPOINT_MODEL_EMF_URI
1033 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1034 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
1035 __attribute__((visibility("hidden"))) = __uri; \
1037 #include TRACEPOINT_INCLUDE
1039 #undef LTTNG_TP_EXTERN_C
1042 * Stage 7.1 of tracepoint event generation.
1044 * Create events description structures. We use a weakref because
1045 * loglevels are optional. If not declared, the event will point to the
1046 * a loglevel that contains NULL.
1049 /* Reset all macros within TRACEPOINT_EVENT */
1050 #include <lttng/ust-tracepoint-event-reset.h>
1052 #undef TRACEPOINT_EVENT_INSTANCE
1053 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1054 static const int * \
1055 __ref_loglevel___##_provider##___##_name \
1056 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1057 static const char * \
1058 __ref_model_emf_uri___##_provider##___##_name \
1059 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1060 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
1061 .name = #_provider ":" #_name, \
1062 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
1064 .fields = __event_fields___##_provider##___##_template, \
1065 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1066 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1067 .signature = __tp_event_signature___##_provider##___##_template, \
1070 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1071 .event_notifier_callback = (void (*)(void)) &__event_notifier_probe__##_provider##___##_template,\
1076 #include TRACEPOINT_INCLUDE
1079 * Stage 7.2 of tracepoint event generation.
1081 * Create array of events.
1084 /* Reset all macros within TRACEPOINT_EVENT */
1085 #include <lttng/ust-tracepoint-event-reset.h>
1087 #undef TRACEPOINT_EVENT_INSTANCE
1088 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1089 &__event_desc___##_provider##_##_name,
1091 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1092 #include TRACEPOINT_INCLUDE
1093 NULL
, /* Dummy, C99 forbids 0-len array. */
1098 * Stage 8 of tracepoint event generation.
1100 * Create a toplevel descriptor for the whole probe.
1103 /* non-const because list head will be modified when registered. */
1104 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1105 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
1106 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1107 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1108 .head
= { NULL
, NULL
},
1109 .lazy_init_head
= { NULL
, NULL
},
1111 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1112 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1115 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1118 * Stage 9 of tracepoint event generation.
1120 * Register/unregister probes at module load/unload.
1122 * Generate the constructor as an externally visible symbol for use when
1123 * linking the probe statically.
1125 * Register refcount is protected by libc dynamic loader mutex.
1128 /* Reset all macros within TRACEPOINT_EVENT */
1129 #include <lttng/ust-tracepoint-event-reset.h>
1130 static void lttng_ust_notrace
__attribute__((constructor
))
1131 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1133 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1137 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1138 TRACEPOINT_PROVIDER
)++) {
1142 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1143 * static inline function that ensures every probe PROVIDER
1144 * argument match the provider within which they appear. It
1145 * calls empty static inline functions, and therefore has no
1146 * runtime effect. However, if it detects an error, a linker
1147 * error will appear.
1149 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1150 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1152 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1157 static void lttng_ust_notrace
__attribute__((destructor
))
1158 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1160 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1162 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1163 TRACEPOINT_PROVIDER
)) {
1166 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1169 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);