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
25 #include <urcu/compiler.h>
26 #include <urcu/rculist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/ringbuffer-config.h>
29 #include <lttng/ust-compiler.h>
30 #include <lttng/tracepoint.h>
34 #define __LTTNG_UST_NULL_STRING "(null)"
36 #undef tp_list_for_each_entry_rcu
37 #define tp_list_for_each_entry_rcu(pos, head, member) \
38 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
39 &pos->member != (head); \
40 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
43 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
44 * same arguments and having the same field layout.
46 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
47 * its own provider and name. It refers to a class (template).
49 * TRACEPOINT_EVENT declared both a class and an instance and does a
50 * direct mapping from the instance to the class.
53 #undef TRACEPOINT_EVENT
54 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
55 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
57 _TP_PARAMS(_fields)) \
58 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
61 #undef TRACEPOINT_EVENT_CLASS
62 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
63 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
65 #undef TRACEPOINT_EVENT_INSTANCE
66 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
67 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
70 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
72 #define _tp_max_t(type, x, y) \
76 __max1 > __max2 ? __max1: __max2; \
80 * Stage 0 of tracepoint event generation.
82 * Check that each TRACEPOINT_EVENT provider argument match the
83 * TRACEPOINT_PROVIDER by creating dummy callbacks.
86 /* Reset all macros within TRACEPOINT_EVENT */
87 #include <lttng/ust-tracepoint-event-reset.h>
89 static inline lttng_ust_notrace
90 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
92 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
96 #undef _TRACEPOINT_EVENT_CLASS
97 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
98 __tracepoint_provider_mismatch_##_provider();
100 #undef _TRACEPOINT_EVENT_INSTANCE
101 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
102 __tracepoint_provider_mismatch_##_provider();
104 static inline lttng_ust_notrace
105 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
107 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
109 #include TRACEPOINT_INCLUDE
113 * Stage 0.1 of tracepoint event generation.
115 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
116 * tracepoint name length limit.
119 /* Reset all macros within TRACEPOINT_EVENT */
120 #include <lttng/ust-tracepoint-event-reset.h>
122 #undef _TRACEPOINT_EVENT_INSTANCE
123 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
125 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
126 __attribute__((unused)) = \
127 #_provider ":" #_name;
129 #include TRACEPOINT_INCLUDE
132 * Stage 0.2 of tracepoint event generation.
134 * Create dummy trace prototypes for each event class, and for each used
135 * template. This will allow checking whether the prototypes from the
136 * class and the instance using the class actually match.
139 /* Reset all macros within TRACEPOINT_EVENT */
140 #include <lttng/ust-tracepoint-event-reset.h>
143 #define TP_ARGS(...) __VA_ARGS__
145 #undef _TRACEPOINT_EVENT_INSTANCE
146 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
147 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
149 #undef _TRACEPOINT_EVENT_CLASS
150 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
151 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
153 #include TRACEPOINT_INCLUDE
156 * Stage 0.9 of tracepoint event generation
158 * Unfolding the enums
160 #include <lttng/ust-tracepoint-event-reset.h>
162 /* Enumeration entry (single value) */
163 #undef ctf_enum_value
164 #define ctf_enum_value(_string, _value) \
167 .value = lttng_is_signed_type(__typeof__(_value)) ? \
168 (long long) (_value) : (_value), \
169 .signedness = lttng_is_signed_type(__typeof__(_value)), \
172 .value = lttng_is_signed_type(__typeof__(_value)) ? \
173 (long long) (_value) : (_value), \
174 .signedness = lttng_is_signed_type(__typeof__(_value)), \
176 .string = (_string), \
179 /* Enumeration entry (range) */
180 #undef ctf_enum_range
181 #define ctf_enum_range(_string, _range_start, _range_end) \
184 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
185 (long long) (_range_start) : (_range_start), \
186 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
189 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
190 (long long) (_range_end) : (_range_end), \
191 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
193 .string = (_string), \
196 /* Enumeration entry (automatic value; follows the rules of CTF) */
198 #define ctf_enum_auto(_string) \
208 .string = (_string), \
211 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
216 #undef TP_ENUM_VALUES
217 #define TP_ENUM_VALUES(...) \
220 #undef TRACEPOINT_ENUM
221 #define TRACEPOINT_ENUM(_provider, _name, _values) \
222 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
224 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
227 #include TRACEPOINT_INCLUDE
230 * Stage 1 of tracepoint event generation.
232 * Create event field type metadata section.
233 * Each event produce an array of fields.
236 /* Reset all macros within TRACEPOINT_EVENT */
237 #include <lttng/ust-tracepoint-event-reset.h>
238 #include <lttng/ust-tracepoint-event-write.h>
239 #include <lttng/ust-tracepoint-event-nowrite.h>
241 #undef _ctf_integer_ext
242 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
245 .type = __type_integer(_type, _byte_order, _base, none),\
246 .nowrite = _nowrite, \
250 #define _ctf_float(_type, _item, _src, _nowrite) \
253 .type = __type_float(_type), \
254 .nowrite = _nowrite, \
257 #undef _ctf_array_encoded
258 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
259 _length, _encoding, _nowrite, \
265 .atype = atype_array, \
270 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
275 .nowrite = _nowrite, \
278 #undef _ctf_sequence_encoded
279 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
280 _length_type, _src_length, _encoding, _nowrite, \
286 .atype = atype_sequence, \
291 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
292 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
296 .nowrite = _nowrite, \
300 #define _ctf_string(_item, _src, _nowrite) \
305 .atype = atype_string, \
308 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
311 .nowrite = _nowrite, \
315 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
319 .atype = atype_enum, \
323 .desc = &__enum_##_provider##_##_name, \
324 .container_type = { \
325 .size = sizeof(_type) * CHAR_BIT, \
326 .alignment = lttng_alignof(_type) * CHAR_BIT, \
327 .signedness = lttng_is_signed_type(_type), \
328 .reverse_byte_order = 0, \
330 .encoding = lttng_encode_none, \
336 .nowrite = _nowrite, \
340 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
342 #undef _TRACEPOINT_EVENT_CLASS
343 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
344 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
346 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
349 #undef TRACEPOINT_ENUM
350 #define TRACEPOINT_ENUM(_provider, _name, _values) \
351 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
352 .name = #_provider "_" #_name, \
353 .entries = __enum_values__##_provider##_##_name, \
354 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
357 #include TRACEPOINT_INCLUDE
360 * Stage 2 of tracepoint event generation.
362 * Create probe callback prototypes.
365 /* Reset all macros within TRACEPOINT_EVENT */
366 #include <lttng/ust-tracepoint-event-reset.h>
369 #define TP_ARGS(...) __VA_ARGS__
371 #undef _TRACEPOINT_EVENT_CLASS
372 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
373 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
375 #include TRACEPOINT_INCLUDE
378 * Stage 3.0 of tracepoint event generation.
380 * Create static inline function that calculates event size.
383 /* Reset all macros within TRACEPOINT_EVENT */
384 #include <lttng/ust-tracepoint-event-reset.h>
385 #include <lttng/ust-tracepoint-event-write.h>
387 #undef _ctf_integer_ext
388 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
389 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
390 __event_len += sizeof(_type);
393 #define _ctf_float(_type, _item, _src, _nowrite) \
394 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
395 __event_len += sizeof(_type);
397 #undef _ctf_array_encoded
398 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
399 _nowrite, _elem_type_base) \
400 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
401 __event_len += sizeof(_type) * (_length);
403 #undef _ctf_sequence_encoded
404 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
405 _src_length, _encoding, _nowrite, _elem_type_base) \
406 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
407 __event_len += sizeof(_length_type); \
408 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
409 __dynamic_len[__dynamic_len_idx] = (_src_length); \
410 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
414 #define _ctf_string(_item, _src, _nowrite) \
415 __event_len += __dynamic_len[__dynamic_len_idx++] = \
416 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
419 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
420 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
423 #define TP_ARGS(...) __VA_ARGS__
426 #define TP_FIELDS(...) __VA_ARGS__
428 #undef _TRACEPOINT_EVENT_CLASS
429 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
430 static inline lttng_ust_notrace \
431 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
433 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
435 size_t __event_len = 0; \
436 unsigned int __dynamic_len_idx = 0; \
439 (void) __dynamic_len_idx; /* don't warn if unused */ \
441 return __event_len; \
444 #include TRACEPOINT_INCLUDE
447 * Stage 3.1 of tracepoint event generation.
449 * Create static inline function that layout the filter stack data.
450 * We make both write and nowrite data available to the filter.
453 /* Reset all macros within TRACEPOINT_EVENT */
454 #include <lttng/ust-tracepoint-event-reset.h>
455 #include <lttng/ust-tracepoint-event-write.h>
456 #include <lttng/ust-tracepoint-event-nowrite.h>
458 #undef _ctf_integer_ext
459 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
460 if (lttng_is_signed_type(_type)) { \
461 int64_t __ctf_tmp_int64; \
462 switch (sizeof(_type)) { \
465 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
466 __ctf_tmp_int64 = (int64_t) __tmp.v; \
471 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
472 if (_byte_order != BYTE_ORDER) \
473 __tmp.v = bswap_16(__tmp.v); \
474 __ctf_tmp_int64 = (int64_t) __tmp.v; \
479 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
480 if (_byte_order != BYTE_ORDER) \
481 __tmp.v = bswap_32(__tmp.v); \
482 __ctf_tmp_int64 = (int64_t) __tmp.v; \
487 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
488 if (_byte_order != BYTE_ORDER) \
489 __tmp.v = bswap_64(__tmp.v); \
490 __ctf_tmp_int64 = (int64_t) __tmp.v; \
496 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
498 uint64_t __ctf_tmp_uint64; \
499 switch (sizeof(_type)) { \
502 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
503 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
508 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
509 if (_byte_order != BYTE_ORDER) \
510 __tmp.v = bswap_16(__tmp.v); \
511 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
516 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
517 if (_byte_order != BYTE_ORDER) \
518 __tmp.v = bswap_32(__tmp.v); \
519 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
524 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
525 if (_byte_order != BYTE_ORDER) \
526 __tmp.v = bswap_64(__tmp.v); \
527 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
533 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
535 __stack_data += sizeof(int64_t);
538 #define _ctf_float(_type, _item, _src, _nowrite) \
540 double __ctf_tmp_double = (double) (_type) (_src); \
541 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
542 __stack_data += sizeof(double); \
545 #undef _ctf_array_encoded
546 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
547 _encoding, _nowrite, _elem_type_base) \
549 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
550 const void *__ctf_tmp_ptr = (_src); \
551 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
552 __stack_data += sizeof(unsigned long); \
553 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
554 __stack_data += sizeof(void *); \
557 #undef _ctf_sequence_encoded
558 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
559 _src_length, _encoding, _nowrite, _elem_type_base) \
561 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
562 const void *__ctf_tmp_ptr = (_src); \
563 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
564 __stack_data += sizeof(unsigned long); \
565 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
566 __stack_data += sizeof(void *); \
570 #define _ctf_string(_item, _src, _nowrite) \
572 const void *__ctf_tmp_ptr = \
573 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
574 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
575 __stack_data += sizeof(void *); \
579 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
580 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
583 #define TP_ARGS(...) __VA_ARGS__
586 #define TP_FIELDS(...) __VA_ARGS__
588 #undef _TRACEPOINT_EVENT_CLASS
589 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
591 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
592 _TP_ARGS_DATA_PROTO(_args)) \
597 #include TRACEPOINT_INCLUDE
600 * Stage 4 of tracepoint event generation.
602 * Create static inline function that calculates event payload alignment.
605 /* Reset all macros within TRACEPOINT_EVENT */
606 #include <lttng/ust-tracepoint-event-reset.h>
607 #include <lttng/ust-tracepoint-event-write.h>
609 #undef _ctf_integer_ext
610 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
611 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
614 #define _ctf_float(_type, _item, _src, _nowrite) \
615 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
617 #undef _ctf_array_encoded
618 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
619 _encoding, _nowrite, _elem_type_base) \
620 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
622 #undef _ctf_sequence_encoded
623 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
624 _src_length, _encoding, _nowrite, _elem_type_base) \
625 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
626 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
629 #define _ctf_string(_item, _src, _nowrite)
632 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
633 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
636 #define TP_ARGS(...) __VA_ARGS__
639 #define TP_FIELDS(...) __VA_ARGS__
641 #undef _TRACEPOINT_EVENT_CLASS
642 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
643 static inline lttng_ust_notrace \
644 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
646 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
648 size_t __event_align = 1; \
650 return __event_align; \
653 #include TRACEPOINT_INCLUDE
657 * Stage 5 of tracepoint event generation.
659 * Create the probe function. This function calls event size calculation
660 * and writes event data into the buffer.
663 /* Reset all macros within TRACEPOINT_EVENT */
664 #include <lttng/ust-tracepoint-event-reset.h>
665 #include <lttng/ust-tracepoint-event-write.h>
667 #undef _ctf_integer_ext
668 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
670 _type __tmp = (_src); \
671 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
672 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
676 #define _ctf_float(_type, _item, _src, _nowrite) \
678 _type __tmp = (_src); \
679 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
680 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
683 #undef _ctf_array_encoded
684 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
685 _encoding, _nowrite, _elem_type_base) \
686 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
687 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
689 #undef _ctf_sequence_encoded
690 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
691 _src_length, _encoding, _nowrite, _elem_type_base) \
693 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
694 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
695 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
697 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
698 __chan->ops->event_write(&__ctx, _src, \
699 sizeof(_type) * __get_dynamic_len(dest));
702 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
703 * tracepoint provider ABI implements event_strcpy. This dynamic check
704 * can be removed when the tracepoint provider ABI moves to 2.
706 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
707 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
711 #define _ctf_string(_item, _src, _nowrite) \
713 const char *__ctf_tmp_string = \
714 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
715 lib_ring_buffer_align_ctx(&__ctx, \
716 lttng_alignof(*__ctf_tmp_string)); \
717 if (__chan->ops->u.has_strcpy) \
718 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
719 __get_dynamic_len(dest)); \
721 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
722 __get_dynamic_len(dest)); \
727 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
728 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
730 /* Beware: this get len actually consumes the len value */
731 #undef __get_dynamic_len
732 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
735 #define TP_ARGS(...) __VA_ARGS__
738 #define TP_FIELDS(...) __VA_ARGS__
741 * For state dump, check that "session" argument (mandatory) matches the
742 * session this event belongs to. Ensures that we write state dump data only
743 * into the started session, not into all sessions.
745 #undef _TP_SESSION_CHECK
746 #ifdef TP_SESSION_CHECK
747 #define _TP_SESSION_CHECK(session, csession) (session == csession)
748 #else /* TP_SESSION_CHECK */
749 #define _TP_SESSION_CHECK(session, csession) 1
750 #endif /* TP_SESSION_CHECK */
753 * Use of __builtin_return_address(0) sometimes seems to cause stack
754 * corruption on 32-bit PowerPC. Disable this feature on that
755 * architecture for now by always using the NULL value for the ip
760 #define _TP_IP_PARAM(x) (x)
761 #else /* TP_IP_PARAM */
763 #if defined(__PPC__) && !defined(__PPC64__)
764 #define _TP_IP_PARAM(x) NULL
765 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
766 #define _TP_IP_PARAM(x) __builtin_return_address(0)
767 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
769 #endif /* TP_IP_PARAM */
772 * Using twice size for filter stack data to hold size and pointer for
773 * each field (worse case). For integers, max size required is 64-bit.
774 * Same for double-precision floats. Those fit within
775 * 2*sizeof(unsigned long) for all supported architectures.
776 * Perform UNION (||) of filter runtime list.
778 #undef _TRACEPOINT_EVENT_CLASS
779 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
780 static lttng_ust_notrace \
781 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
783 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
785 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
786 struct lttng_channel *__chan = __event->chan; \
787 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
788 struct lttng_stack_ctx __lttng_ctx; \
789 size_t __event_len, __event_align; \
790 size_t __dynamic_len_idx = 0; \
792 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
793 char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
798 (void) __dynamic_len_idx; /* don't warn if unused */ \
799 if (!_TP_SESSION_CHECK(session, __chan->session)) \
801 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
803 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
805 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
807 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
809 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
810 struct lttng_bytecode_runtime *bc_runtime; \
811 int __filter_record = __event->has_enablers_without_bytecode; \
813 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
814 _TP_ARGS_DATA_VAR(_args)); \
815 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
816 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
817 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
818 __filter_record = 1; \
820 if (caa_likely(!__filter_record)) \
823 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
824 _TP_ARGS_DATA_VAR(_args)); \
825 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
826 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
827 __lttng_ctx.event = __event; \
828 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
829 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
830 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
831 __event_align, -1, __chan->handle, &__lttng_ctx); \
832 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
833 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
837 __chan->ops->event_commit(&__ctx); \
840 #include TRACEPOINT_INCLUDE
842 #undef __get_dynamic_len
845 * Stage 5.1 of tracepoint event generation.
847 * Create probe signature
850 /* Reset all macros within TRACEPOINT_EVENT */
851 #include <lttng/ust-tracepoint-event-reset.h>
854 #define TP_ARGS(...) __VA_ARGS__
856 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
858 #undef _TRACEPOINT_EVENT_CLASS
859 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
860 static const char __tp_event_signature___##_provider##___##_name[] = \
861 _TP_EXTRACT_STRING2(_args);
863 #include TRACEPOINT_INCLUDE
865 #undef _TP_EXTRACT_STRING2
868 * Stage 6 of tracepoint event generation.
870 * Tracepoint loglevel mapping definition generation. We generate a
871 * symbol for each mapping for a provider/event to ensure at most a 1 to
872 * 1 mapping between events and loglevels. If the symbol is repeated,
873 * the compiler will complain.
876 /* Reset all macros within TRACEPOINT_EVENT */
877 #include <lttng/ust-tracepoint-event-reset.h>
880 * Declare _loglevel___##__provider##___##__name as non-static, with
881 * hidden visibility for c++ handling of weakref. We do a weakref to the
882 * symbol in a later stage, which requires that the symbol is not
886 #define LTTNG_TP_EXTERN_C extern "C"
888 #define LTTNG_TP_EXTERN_C
891 #undef TRACEPOINT_LOGLEVEL
892 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
893 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
894 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
895 __attribute__((visibility("hidden"))) = \
896 &_loglevel_value___##__provider##___##__name;
898 #include TRACEPOINT_INCLUDE
900 #undef LTTNG_TP_EXTERN_C
903 * Stage 6.1 of tracepoint event generation.
905 * Tracepoint UML URI info.
908 /* Reset all macros within TRACEPOINT_EVENT */
909 #include <lttng/ust-tracepoint-event-reset.h>
912 * Declare _model_emf_uri___##__provider##___##__name as non-static,
913 * with hidden visibility for c++ handling of weakref. We do a weakref
914 * to the symbol in a later stage, which requires that the symbol is not
918 #define LTTNG_TP_EXTERN_C extern "C"
920 #define LTTNG_TP_EXTERN_C
923 #undef TRACEPOINT_MODEL_EMF_URI
924 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
925 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
926 __attribute__((visibility("hidden"))) = __uri; \
928 #include TRACEPOINT_INCLUDE
930 #undef LTTNG_TP_EXTERN_C
933 * Stage 7.1 of tracepoint event generation.
935 * Create events description structures. We use a weakref because
936 * loglevels are optional. If not declared, the event will point to the
937 * a loglevel that contains NULL.
940 /* Reset all macros within TRACEPOINT_EVENT */
941 #include <lttng/ust-tracepoint-event-reset.h>
943 #undef _TRACEPOINT_EVENT_INSTANCE
944 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
946 __ref_loglevel___##_provider##___##_name \
947 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
948 static const char * \
949 __ref_model_emf_uri___##_provider##___##_name \
950 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
951 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
952 .name = #_provider ":" #_name, \
953 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
955 .fields = __event_fields___##_provider##___##_template, \
956 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
957 .loglevel = &__ref_loglevel___##_provider##___##_name, \
958 .signature = __tp_event_signature___##_provider##___##_template, \
961 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
966 #include TRACEPOINT_INCLUDE
969 * Stage 7.2 of tracepoint event generation.
971 * Create array of events.
974 /* Reset all macros within TRACEPOINT_EVENT */
975 #include <lttng/ust-tracepoint-event-reset.h>
977 #undef _TRACEPOINT_EVENT_INSTANCE
978 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
979 &__event_desc___##_provider##_##_name,
981 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
982 #include TRACEPOINT_INCLUDE
983 NULL
, /* Dummy, C99 forbids 0-len array. */
988 * Stage 8 of tracepoint event generation.
990 * Create a toplevel descriptor for the whole probe.
993 /* non-const because list head will be modified when registered. */
994 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
995 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
996 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
997 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
998 .head
= { NULL
, NULL
},
999 .lazy_init_head
= { NULL
, NULL
},
1001 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1002 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1005 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1008 * Stage 9 of tracepoint event generation.
1010 * Register/unregister probes at module load/unload.
1012 * Generate the constructor as an externally visible symbol for use when
1013 * linking the probe statically.
1015 * Register refcount is protected by libc dynamic loader mutex.
1018 /* Reset all macros within TRACEPOINT_EVENT */
1019 #include <lttng/ust-tracepoint-event-reset.h>
1020 static void lttng_ust_notrace
__attribute__((constructor
))
1021 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1023 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1027 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1028 TRACEPOINT_PROVIDER
)++) {
1032 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1033 * static inline function that ensures every probe PROVIDER
1034 * argument match the provider within which they appear. It
1035 * calls empty static inline functions, and therefore has no
1036 * runtime effect. However, if it detects an error, a linker
1037 * error will appear.
1039 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1040 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1042 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1047 static void lttng_ust_notrace
__attribute__((destructor
))
1048 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1050 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1052 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1053 TRACEPOINT_PROVIDER
)) {
1056 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1059 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1060 __attribute__((visibility("default")));