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((head)->next), __typeof__(*pos), member); \
40 &pos->member != (head); \
41 pos = cds_list_entry(tp_rcu_dereference(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, \
62 #undef TRACEPOINT_EVENT_CLASS
63 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
64 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
66 #undef TRACEPOINT_EVENT_INSTANCE
67 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
68 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
71 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
73 #define _tp_max_t(type, x, y) \
77 __max1 > __max2 ? __max1: __max2; \
81 * Stage 0 of tracepoint event generation.
83 * Check that each TRACEPOINT_EVENT provider argument match the
84 * TRACEPOINT_PROVIDER by creating dummy callbacks.
87 /* Reset all macros within TRACEPOINT_EVENT */
88 #include <lttng/ust-tracepoint-event-reset.h>
90 static inline lttng_ust_notrace
91 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
93 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
97 #undef _TRACEPOINT_EVENT_CLASS
98 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
99 __tracepoint_provider_mismatch_##_provider();
101 #undef _TRACEPOINT_EVENT_INSTANCE
102 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
103 __tracepoint_provider_mismatch_##_provider();
105 static inline lttng_ust_notrace
106 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
108 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
110 #include TRACEPOINT_INCLUDE
114 * Stage 0.1 of tracepoint event generation.
116 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
117 * tracepoint name length limit.
120 /* Reset all macros within TRACEPOINT_EVENT */
121 #include <lttng/ust-tracepoint-event-reset.h>
123 #undef _TRACEPOINT_EVENT_INSTANCE
124 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
126 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
127 __attribute__((unused)) = \
128 #_provider ":" #_name;
130 #include TRACEPOINT_INCLUDE
133 * Stage 0.2 of tracepoint event generation.
135 * Create dummy trace prototypes for each event class, and for each used
136 * template. This will allow checking whether the prototypes from the
137 * class and the instance using the class actually match.
140 /* Reset all macros within TRACEPOINT_EVENT */
141 #include <lttng/ust-tracepoint-event-reset.h>
144 #define TP_ARGS(...) __VA_ARGS__
146 #undef _TRACEPOINT_EVENT_INSTANCE
147 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
148 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
150 #undef _TRACEPOINT_EVENT_CLASS
151 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
152 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
154 #include TRACEPOINT_INCLUDE
157 * Stage 0.9 of tracepoint event generation
159 * Unfolding the enums
161 #include <lttng/ust-tracepoint-event-reset.h>
163 /* Enumeration entry (single value) */
164 #undef ctf_enum_value
165 #define ctf_enum_value(_string, _value) \
168 .value = lttng_is_signed_type(__typeof__(_value)) ? \
169 (long long) (_value) : (_value), \
170 .signedness = lttng_is_signed_type(__typeof__(_value)), \
173 .value = lttng_is_signed_type(__typeof__(_value)) ? \
174 (long long) (_value) : (_value), \
175 .signedness = lttng_is_signed_type(__typeof__(_value)), \
177 .string = (_string), \
180 /* Enumeration entry (range) */
181 #undef ctf_enum_range
182 #define ctf_enum_range(_string, _range_start, _range_end) \
185 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
186 (long long) (_range_start) : (_range_start), \
187 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
190 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
191 (long long) (_range_end) : (_range_end), \
192 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
194 .string = (_string), \
197 /* Enumeration entry (automatic value; follows the rules of CTF) */
199 #define ctf_enum_auto(_string) \
209 .string = (_string), \
212 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
217 #undef TP_ENUM_VALUES
218 #define TP_ENUM_VALUES(...) \
221 #undef TRACEPOINT_ENUM
222 #define TRACEPOINT_ENUM(_provider, _name, _values) \
223 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
225 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
227 #include TRACEPOINT_INCLUDE
231 * Verifying array and sequence elements are of an integer type.
234 /* Reset all macros within TRACEPOINT_EVENT */
235 #include <lttng/ust-tracepoint-event-reset.h>
236 #include <lttng/ust-tracepoint-event-write.h>
237 #include <lttng/ust-tracepoint-event-nowrite.h>
239 #undef _ctf_array_encoded
240 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
241 _length, _encoding, _nowrite, \
243 _lttng_array_element_type_is_supported(_type, _item)
245 #undef _ctf_sequence_encoded
246 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
247 _length_type, _src_length, _encoding, _nowrite, \
249 _lttng_array_element_type_is_supported(_type, _item)
252 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
254 #undef _TRACEPOINT_EVENT_CLASS
255 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
258 #include TRACEPOINT_INCLUDE
261 * Stage 1 of tracepoint event generation.
263 * Create event field type metadata section.
264 * Each event produce an array of fields.
267 /* Reset all macros within TRACEPOINT_EVENT */
268 #include <lttng/ust-tracepoint-event-reset.h>
269 #include <lttng/ust-tracepoint-event-write.h>
270 #include <lttng/ust-tracepoint-event-nowrite.h>
272 #undef _ctf_integer_ext
273 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
276 .type = __type_integer(_type, _byte_order, _base, none),\
277 .nowrite = _nowrite, \
286 #define _ctf_float(_type, _item, _src, _nowrite) \
289 .type = __type_float(_type), \
290 .nowrite = _nowrite, \
298 #undef _ctf_array_encoded
299 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
300 _length, _encoding, _nowrite, \
306 .atype = atype_array_nestable, \
311 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
312 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
318 .nowrite = _nowrite, \
326 #undef _ctf_sequence_encoded
327 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
328 _length_type, _src_length, _encoding, _nowrite, \
331 .name = "_" #_item "_length", \
332 .type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
333 .nowrite = _nowrite, \
344 .atype = atype_sequence_nestable, \
347 .sequence_nestable = \
349 .length_name = "_" #_item "_length", \
350 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
351 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
356 .nowrite = _nowrite, \
365 #define _ctf_string(_item, _src, _nowrite) \
370 .atype = atype_string, \
373 .string = { .encoding = lttng_encode_UTF8 } \
376 .nowrite = _nowrite, \
385 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
389 .atype = atype_enum_nestable, \
392 .desc = &__enum_##_provider##_##_name, \
393 .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
394 __type_integer(_type, BYTE_ORDER, 10, none)), \
398 .nowrite = _nowrite, \
407 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
409 #undef _TRACEPOINT_EVENT_CLASS
410 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
411 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
413 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
416 #undef TRACEPOINT_ENUM
417 #define TRACEPOINT_ENUM(_provider, _name, _values) \
418 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
419 .name = #_provider "_" #_name, \
420 .entries = __enum_values__##_provider##_##_name, \
421 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
424 #include TRACEPOINT_INCLUDE
427 * Stage 2 of tracepoint event generation.
429 * Create probe callback prototypes.
432 /* Reset all macros within TRACEPOINT_EVENT */
433 #include <lttng/ust-tracepoint-event-reset.h>
436 #define TP_ARGS(...) __VA_ARGS__
438 #undef _TRACEPOINT_EVENT_CLASS
439 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
440 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
442 #include TRACEPOINT_INCLUDE
445 * Stage 2.1 of tracepoint event generation.
447 * Create probe event notifier callback prototypes.
450 /* Reset all macros within TRACEPOINT_EVENT */
451 #include <lttng/ust-tracepoint-event-reset.h>
454 #define TP_ARGS(...) __VA_ARGS__
456 #undef _TRACEPOINT_EVENT_CLASS
457 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
458 static void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
460 #include TRACEPOINT_INCLUDE
463 * Stage 3.0 of tracepoint event generation.
465 * Create static inline function that calculates event size.
468 /* Reset all macros within TRACEPOINT_EVENT */
469 #include <lttng/ust-tracepoint-event-reset.h>
470 #include <lttng/ust-tracepoint-event-write.h>
472 #undef _ctf_integer_ext
473 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
474 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
475 __event_len += sizeof(_type);
478 #define _ctf_float(_type, _item, _src, _nowrite) \
479 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
480 __event_len += sizeof(_type);
482 #undef _ctf_array_encoded
483 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
484 _nowrite, _elem_type_base) \
485 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
486 __event_len += sizeof(_type) * (_length);
488 #undef _ctf_sequence_encoded
489 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
490 _src_length, _encoding, _nowrite, _elem_type_base) \
491 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
492 __event_len += sizeof(_length_type); \
493 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
494 __dynamic_len[__dynamic_len_idx] = (_src_length); \
495 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
499 #define _ctf_string(_item, _src, _nowrite) \
500 __event_len += __dynamic_len[__dynamic_len_idx++] = \
501 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
504 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
505 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
508 #define TP_ARGS(...) __VA_ARGS__
511 #define TP_FIELDS(...) __VA_ARGS__
513 #undef _TRACEPOINT_EVENT_CLASS
514 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
515 static inline lttng_ust_notrace \
516 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
518 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
520 size_t __event_len = 0; \
521 unsigned int __dynamic_len_idx = 0; \
524 (void) __dynamic_len_idx; /* don't warn if unused */ \
526 return __event_len; \
529 #include TRACEPOINT_INCLUDE
532 * Stage 3.1 of tracepoint event generation.
534 * Create static inline function that layout the filter stack data.
535 * We make both write and nowrite data available to the filter.
538 /* Reset all macros within TRACEPOINT_EVENT */
539 #include <lttng/ust-tracepoint-event-reset.h>
540 #include <lttng/ust-tracepoint-event-write.h>
541 #include <lttng/ust-tracepoint-event-nowrite.h>
543 #undef _ctf_integer_ext
544 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
545 if (lttng_is_signed_type(_type)) { \
546 int64_t __ctf_tmp_int64; \
547 switch (sizeof(_type)) { \
550 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
551 __ctf_tmp_int64 = (int64_t) __tmp.v; \
556 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
557 if (_byte_order != BYTE_ORDER) \
558 __tmp.v = bswap_16(__tmp.v); \
559 __ctf_tmp_int64 = (int64_t) __tmp.v; \
564 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
565 if (_byte_order != BYTE_ORDER) \
566 __tmp.v = bswap_32(__tmp.v); \
567 __ctf_tmp_int64 = (int64_t) __tmp.v; \
572 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
573 if (_byte_order != BYTE_ORDER) \
574 __tmp.v = bswap_64(__tmp.v); \
575 __ctf_tmp_int64 = (int64_t) __tmp.v; \
581 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
583 uint64_t __ctf_tmp_uint64; \
584 switch (sizeof(_type)) { \
587 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
588 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
593 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
594 if (_byte_order != BYTE_ORDER) \
595 __tmp.v = bswap_16(__tmp.v); \
596 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
601 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
602 if (_byte_order != BYTE_ORDER) \
603 __tmp.v = bswap_32(__tmp.v); \
604 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
609 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
610 if (_byte_order != BYTE_ORDER) \
611 __tmp.v = bswap_64(__tmp.v); \
612 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
618 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
620 __stack_data += sizeof(int64_t);
623 #define _ctf_float(_type, _item, _src, _nowrite) \
625 double __ctf_tmp_double = (double) (_type) (_src); \
626 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
627 __stack_data += sizeof(double); \
630 #undef _ctf_array_encoded
631 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
632 _encoding, _nowrite, _elem_type_base) \
634 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
635 const void *__ctf_tmp_ptr = (_src); \
636 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
637 __stack_data += sizeof(unsigned long); \
638 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
639 __stack_data += sizeof(void *); \
642 #undef _ctf_sequence_encoded
643 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
644 _src_length, _encoding, _nowrite, _elem_type_base) \
646 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
647 const void *__ctf_tmp_ptr = (_src); \
648 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
649 __stack_data += sizeof(unsigned long); \
650 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
651 __stack_data += sizeof(void *); \
655 #define _ctf_string(_item, _src, _nowrite) \
657 const void *__ctf_tmp_ptr = \
658 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
659 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
660 __stack_data += sizeof(void *); \
664 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
665 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
668 #define TP_ARGS(...) __VA_ARGS__
671 #define TP_FIELDS(...) __VA_ARGS__
673 #undef _TRACEPOINT_EVENT_CLASS
674 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
676 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
677 _TP_ARGS_DATA_PROTO(_args)) \
682 #include TRACEPOINT_INCLUDE
685 * Stage 4 of tracepoint event generation.
687 * Create static inline function that calculates event payload alignment.
690 /* Reset all macros within TRACEPOINT_EVENT */
691 #include <lttng/ust-tracepoint-event-reset.h>
692 #include <lttng/ust-tracepoint-event-write.h>
694 #undef _ctf_integer_ext
695 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
696 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
699 #define _ctf_float(_type, _item, _src, _nowrite) \
700 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
702 #undef _ctf_array_encoded
703 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
704 _encoding, _nowrite, _elem_type_base) \
705 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
707 #undef _ctf_sequence_encoded
708 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
709 _src_length, _encoding, _nowrite, _elem_type_base) \
710 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
711 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
714 #define _ctf_string(_item, _src, _nowrite)
717 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
718 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
721 #define TP_ARGS(...) __VA_ARGS__
724 #define TP_FIELDS(...) __VA_ARGS__
726 #undef _TRACEPOINT_EVENT_CLASS
727 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
728 static inline lttng_ust_notrace \
729 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
731 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
733 size_t __event_align = 1; \
735 return __event_align; \
738 #include TRACEPOINT_INCLUDE
742 * Stage 5 of tracepoint event generation.
744 * Create the probe function. This function calls event size calculation
745 * and writes event data into the buffer.
748 /* Reset all macros within TRACEPOINT_EVENT */
749 #include <lttng/ust-tracepoint-event-reset.h>
750 #include <lttng/ust-tracepoint-event-write.h>
752 #undef _ctf_integer_ext
753 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
755 _type __tmp = (_src); \
756 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
757 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
761 #define _ctf_float(_type, _item, _src, _nowrite) \
763 _type __tmp = (_src); \
764 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
765 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
768 #undef _ctf_array_encoded
769 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
770 _encoding, _nowrite, _elem_type_base) \
771 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
772 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
774 #undef _ctf_sequence_encoded
775 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
776 _src_length, _encoding, _nowrite, _elem_type_base) \
778 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
779 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
780 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
782 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
783 __chan->ops->event_write(&__ctx, _src, \
784 sizeof(_type) * __get_dynamic_len(dest));
787 #define _ctf_string(_item, _src, _nowrite) \
789 const char *__ctf_tmp_string = \
790 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
791 lib_ring_buffer_align_ctx(&__ctx, \
792 lttng_alignof(*__ctf_tmp_string)); \
793 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
794 __get_dynamic_len(dest)); \
799 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
800 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
802 /* Beware: this get len actually consumes the len value */
803 #undef __get_dynamic_len
804 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
807 #define TP_ARGS(...) __VA_ARGS__
810 #define TP_FIELDS(...) __VA_ARGS__
813 * For state dump, check that "session" argument (mandatory) matches the
814 * session this event belongs to. Ensures that we write state dump data only
815 * into the started session, not into all sessions.
817 #undef _TP_SESSION_CHECK
818 #ifdef TP_SESSION_CHECK
819 #define _TP_SESSION_CHECK(session, csession) (session == csession)
820 #else /* TP_SESSION_CHECK */
821 #define _TP_SESSION_CHECK(session, csession) 1
822 #endif /* TP_SESSION_CHECK */
825 * Use of __builtin_return_address(0) sometimes seems to cause stack
826 * corruption on 32-bit PowerPC. Disable this feature on that
827 * architecture for now by always using the NULL value for the ip
832 #define _TP_IP_PARAM(x) (x)
833 #else /* TP_IP_PARAM */
835 #if defined(__PPC__) && !defined(__PPC64__)
836 #define _TP_IP_PARAM(x) NULL
837 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
838 #define _TP_IP_PARAM(x) __builtin_return_address(0)
839 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
841 #endif /* TP_IP_PARAM */
844 * Using twice size for filter stack data to hold size and pointer for
845 * each field (worse case). For integers, max size required is 64-bit.
846 * Same for double-precision floats. Those fit within
847 * 2*sizeof(unsigned long) for all supported architectures.
848 * Perform UNION (||) of filter runtime list.
850 #undef _TRACEPOINT_EVENT_CLASS
851 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
852 static lttng_ust_notrace \
853 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
855 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
857 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
858 struct lttng_channel *__chan = __event->chan; \
859 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
860 struct lttng_stack_ctx __lttng_ctx; \
861 size_t __event_len, __event_align; \
862 size_t __dynamic_len_idx = 0; \
863 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
865 size_t __dynamic_len[__num_fields]; \
866 char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
871 (void) __dynamic_len_idx; /* don't warn if unused */ \
872 if (!_TP_SESSION_CHECK(session, __chan->session)) \
874 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
876 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
878 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
880 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
882 if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \
883 struct lttng_bytecode_runtime *__filter_bc_runtime; \
884 int __filter_record = __event->has_enablers_without_bytecode; \
886 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
887 _TP_ARGS_DATA_VAR(_args)); \
888 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
889 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
890 __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \
891 __filter_record = 1; \
895 if (caa_likely(!__filter_record)) \
898 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
899 _TP_ARGS_DATA_VAR(_args)); \
900 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
901 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
902 __lttng_ctx.event = __event; \
903 __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \
904 __lttng_ctx.event_ctx = tp_rcu_dereference(__event->ctx); \
905 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
906 __event_align, -1, __chan->handle, &__lttng_ctx); \
907 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
908 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
912 __chan->ops->event_commit(&__ctx); \
915 #include TRACEPOINT_INCLUDE
917 #undef __get_dynamic_len
920 * Stage 5.1 of tracepoint event generation.
922 * Create probe signature
925 /* Reset all macros within TRACEPOINT_EVENT */
926 #include <lttng/ust-tracepoint-event-reset.h>
929 #define TP_ARGS(...) __VA_ARGS__
931 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
933 #undef _TRACEPOINT_EVENT_CLASS
934 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
935 static const char __tp_event_signature___##_provider##___##_name[] = \
936 _TP_EXTRACT_STRING2(_args);
938 #include TRACEPOINT_INCLUDE
940 #undef _TP_EXTRACT_STRING2
943 * Stage 5.2 of tracepoint event generation.
945 * Create the event notifier probe function.
947 #undef _TRACEPOINT_EVENT_CLASS
948 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
949 static lttng_ust_notrace \
950 void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
952 void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
954 struct lttng_event_notifier *__event_notifier = (struct lttng_event_notifier *) __tp_data; \
955 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1;\
957 size_t __dynamic_len[__num_fields]; \
958 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
960 if (caa_unlikely(!CMM_ACCESS_ONCE(__event_notifier->enabled))) \
962 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
964 if (caa_unlikely(!cds_list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \
965 struct lttng_bytecode_runtime *__filter_bc_runtime; \
966 int __filter_record = __event_notifier->has_enablers_without_bytecode; \
968 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
969 _TP_ARGS_DATA_VAR(_args)); \
970 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \
971 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
972 __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \
973 __filter_record = 1; \
975 if (caa_likely(!__filter_record)) \
978 if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \
979 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
980 _TP_ARGS_DATA_VAR(_args)); \
982 lttng_event_notifier_notification_send(__event_notifier, \
983 __stackvar.__interpreter_stack_data); \
986 #include TRACEPOINT_INCLUDE
989 * Stage 6 of tracepoint event generation.
991 * Tracepoint loglevel mapping definition generation. We generate a
992 * symbol for each mapping for a provider/event to ensure at most a 1 to
993 * 1 mapping between events and loglevels. If the symbol is repeated,
994 * the compiler will complain.
997 /* Reset all macros within TRACEPOINT_EVENT */
998 #include <lttng/ust-tracepoint-event-reset.h>
1001 * Declare _loglevel___##__provider##___##__name as non-static, with
1002 * hidden visibility for c++ handling of weakref. We do a weakref to the
1003 * symbol in a later stage, which requires that the symbol is not
1007 #define LTTNG_TP_EXTERN_C extern "C"
1009 #define LTTNG_TP_EXTERN_C
1012 #undef TRACEPOINT_LOGLEVEL
1013 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
1014 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
1015 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
1016 __attribute__((visibility("hidden"))) = \
1017 &_loglevel_value___##__provider##___##__name;
1019 #include TRACEPOINT_INCLUDE
1021 #undef LTTNG_TP_EXTERN_C
1024 * Stage 6.1 of tracepoint event generation.
1026 * Tracepoint UML URI info.
1029 /* Reset all macros within TRACEPOINT_EVENT */
1030 #include <lttng/ust-tracepoint-event-reset.h>
1033 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1034 * with hidden visibility for c++ handling of weakref. We do a weakref
1035 * to the symbol in a later stage, which requires that the symbol is not
1039 #define LTTNG_TP_EXTERN_C extern "C"
1041 #define LTTNG_TP_EXTERN_C
1044 #undef TRACEPOINT_MODEL_EMF_URI
1045 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1046 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
1047 __attribute__((visibility("hidden"))) = __uri; \
1049 #include TRACEPOINT_INCLUDE
1051 #undef LTTNG_TP_EXTERN_C
1054 * Stage 7.1 of tracepoint event generation.
1056 * Create events description structures. We use a weakref because
1057 * loglevels are optional. If not declared, the event will point to the
1058 * a loglevel that contains NULL.
1061 /* Reset all macros within TRACEPOINT_EVENT */
1062 #include <lttng/ust-tracepoint-event-reset.h>
1064 #undef _TRACEPOINT_EVENT_INSTANCE
1065 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1066 static const int * \
1067 __ref_loglevel___##_provider##___##_name \
1068 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1069 static const char * \
1070 __ref_model_emf_uri___##_provider##___##_name \
1071 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1072 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
1073 .name = #_provider ":" #_name, \
1074 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
1076 .fields = __event_fields___##_provider##___##_template, \
1077 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1078 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1079 .signature = __tp_event_signature___##_provider##___##_template, \
1082 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1083 .event_notifier_callback = (void (*)(void)) &__event_notifier_probe__##_provider##___##_template,\
1088 #include TRACEPOINT_INCLUDE
1091 * Stage 7.2 of tracepoint event generation.
1093 * Create array of events.
1096 /* Reset all macros within TRACEPOINT_EVENT */
1097 #include <lttng/ust-tracepoint-event-reset.h>
1099 #undef _TRACEPOINT_EVENT_INSTANCE
1100 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1101 &__event_desc___##_provider##_##_name,
1103 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1104 #include TRACEPOINT_INCLUDE
1105 NULL
, /* Dummy, C99 forbids 0-len array. */
1110 * Stage 8 of tracepoint event generation.
1112 * Create a toplevel descriptor for the whole probe.
1115 /* non-const because list head will be modified when registered. */
1116 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1117 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
1118 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1119 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1120 .head
= { NULL
, NULL
},
1121 .lazy_init_head
= { NULL
, NULL
},
1123 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1124 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1127 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1130 * Stage 9 of tracepoint event generation.
1132 * Register/unregister probes at module load/unload.
1134 * Generate the constructor as an externally visible symbol for use when
1135 * linking the probe statically.
1137 * Register refcount is protected by libc dynamic loader mutex.
1140 /* Reset all macros within TRACEPOINT_EVENT */
1141 #include <lttng/ust-tracepoint-event-reset.h>
1142 static void lttng_ust_notrace
__attribute__((constructor
))
1143 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1145 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1149 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1150 TRACEPOINT_PROVIDER
)++) {
1154 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1155 * static inline function that ensures every probe PROVIDER
1156 * argument match the provider within which they appear. It
1157 * calls empty static inline functions, and therefore has no
1158 * runtime effect. However, if it detects an error, a linker
1159 * error will appear.
1161 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1162 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1164 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1169 static void lttng_ust_notrace
__attribute__((destructor
))
1170 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1172 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1174 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1175 TRACEPOINT_PROVIDER
)) {
1178 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1181 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);