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, \
62 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
64 #define _tp_max_t(type, x, y) \
68 __max1 > __max2 ? __max1: __max2; \
72 * Stage 0 of tracepoint event generation.
74 * Check that each TRACEPOINT_EVENT provider argument match the
75 * TRACEPOINT_PROVIDER by creating dummy callbacks.
78 /* Reset all macros within TRACEPOINT_EVENT */
79 #include <lttng/ust-tracepoint-event-reset.h>
81 static inline lttng_ust_notrace
82 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
84 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
88 #undef TRACEPOINT_EVENT_CLASS
89 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
90 __tracepoint_provider_mismatch_##_provider();
92 #undef TRACEPOINT_EVENT_INSTANCE
93 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
94 __tracepoint_provider_mismatch_##_provider();
96 static inline lttng_ust_notrace
97 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
99 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
101 #include TRACEPOINT_INCLUDE
105 * Stage 0.1 of tracepoint event generation.
107 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
108 * tracepoint name length limit.
111 /* Reset all macros within TRACEPOINT_EVENT */
112 #include <lttng/ust-tracepoint-event-reset.h>
114 #undef TRACEPOINT_EVENT_INSTANCE
115 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
117 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
118 __attribute__((unused)) = \
119 #_provider ":" #_name;
121 #include TRACEPOINT_INCLUDE
124 * Stage 0.2 of tracepoint event generation.
126 * Create dummy trace prototypes for each event class, and for each used
127 * template. This will allow checking whether the prototypes from the
128 * class and the instance using the class actually match.
131 /* Reset all macros within TRACEPOINT_EVENT */
132 #include <lttng/ust-tracepoint-event-reset.h>
135 #define TP_ARGS(...) __VA_ARGS__
137 #undef TRACEPOINT_EVENT_INSTANCE
138 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
139 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
141 #undef TRACEPOINT_EVENT_CLASS
142 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
143 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
145 #include TRACEPOINT_INCLUDE
148 * Stage 0.9 of tracepoint event generation
150 * Unfolding the enums
152 #include <lttng/ust-tracepoint-event-reset.h>
154 /* Enumeration entry (single value) */
155 #undef ctf_enum_value
156 #define ctf_enum_value(_string, _value) \
159 .value = lttng_is_signed_type(__typeof__(_value)) ? \
160 (long long) (_value) : (_value), \
161 .signedness = lttng_is_signed_type(__typeof__(_value)), \
164 .value = lttng_is_signed_type(__typeof__(_value)) ? \
165 (long long) (_value) : (_value), \
166 .signedness = lttng_is_signed_type(__typeof__(_value)), \
168 .string = (_string), \
171 /* Enumeration entry (range) */
172 #undef ctf_enum_range
173 #define ctf_enum_range(_string, _range_start, _range_end) \
176 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
177 (long long) (_range_start) : (_range_start), \
178 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
181 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
182 (long long) (_range_end) : (_range_end), \
183 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
185 .string = (_string), \
188 /* Enumeration entry (automatic value; follows the rules of CTF) */
190 #define ctf_enum_auto(_string) \
200 .string = (_string), \
203 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
208 #undef TP_ENUM_VALUES
209 #define TP_ENUM_VALUES(...) \
212 #undef TRACEPOINT_ENUM
213 #define TRACEPOINT_ENUM(_provider, _name, _values) \
214 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
216 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
219 #include TRACEPOINT_INCLUDE
222 * Stage 1 of tracepoint event generation.
224 * Create event field type metadata section.
225 * Each event produce an array of fields.
228 /* Reset all macros within TRACEPOINT_EVENT */
229 #include <lttng/ust-tracepoint-event-reset.h>
230 #include <lttng/ust-tracepoint-event-write.h>
231 #include <lttng/ust-tracepoint-event-nowrite.h>
233 #undef _ctf_integer_ext
234 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
237 .type = __type_integer(_type, _byte_order, _base, none),\
238 .nowrite = _nowrite, \
242 #define _ctf_float(_type, _item, _src, _nowrite) \
245 .type = __type_float(_type), \
246 .nowrite = _nowrite, \
249 #undef _ctf_array_encoded
250 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
251 _length, _encoding, _nowrite, \
257 .atype = atype_array, \
262 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
267 .nowrite = _nowrite, \
270 #undef _ctf_sequence_encoded
271 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
272 _length_type, _src_length, _encoding, _nowrite, \
278 .atype = atype_sequence, \
283 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
284 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
288 .nowrite = _nowrite, \
292 #define _ctf_string(_item, _src, _nowrite) \
297 .atype = atype_string, \
300 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
303 .nowrite = _nowrite, \
307 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
311 .atype = atype_enum, \
315 .desc = &__enum_##_provider##_##_name, \
316 .container_type = { \
317 .size = sizeof(_type) * CHAR_BIT, \
318 .alignment = lttng_alignof(_type) * CHAR_BIT, \
319 .signedness = lttng_is_signed_type(_type), \
320 .reverse_byte_order = 0, \
322 .encoding = lttng_encode_none, \
328 .nowrite = _nowrite, \
332 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
334 #undef TRACEPOINT_EVENT_CLASS
335 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
336 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
338 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
341 #undef TRACEPOINT_ENUM
342 #define TRACEPOINT_ENUM(_provider, _name, _values) \
343 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
344 .name = #_provider "_" #_name, \
345 .entries = __enum_values__##_provider##_##_name, \
346 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
349 #include TRACEPOINT_INCLUDE
352 * Stage 2 of tracepoint event generation.
354 * Create probe callback prototypes.
357 /* Reset all macros within TRACEPOINT_EVENT */
358 #include <lttng/ust-tracepoint-event-reset.h>
361 #define TP_ARGS(...) __VA_ARGS__
363 #undef TRACEPOINT_EVENT_CLASS
364 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
365 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
367 #include TRACEPOINT_INCLUDE
370 * Stage 3.0 of tracepoint event generation.
372 * Create static inline function that calculates event size.
375 /* Reset all macros within TRACEPOINT_EVENT */
376 #include <lttng/ust-tracepoint-event-reset.h>
377 #include <lttng/ust-tracepoint-event-write.h>
379 #undef _ctf_integer_ext
380 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
381 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
382 __event_len += sizeof(_type);
385 #define _ctf_float(_type, _item, _src, _nowrite) \
386 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
387 __event_len += sizeof(_type);
389 #undef _ctf_array_encoded
390 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
391 _nowrite, _elem_type_base) \
392 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
393 __event_len += sizeof(_type) * (_length);
395 #undef _ctf_sequence_encoded
396 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
397 _src_length, _encoding, _nowrite, _elem_type_base) \
398 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
399 __event_len += sizeof(_length_type); \
400 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
401 __dynamic_len[__dynamic_len_idx] = (_src_length); \
402 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
406 #define _ctf_string(_item, _src, _nowrite) \
407 __event_len += __dynamic_len[__dynamic_len_idx++] = \
408 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
411 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
412 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
415 #define TP_ARGS(...) __VA_ARGS__
418 #define TP_FIELDS(...) __VA_ARGS__
420 #undef TRACEPOINT_EVENT_CLASS
421 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
422 static inline lttng_ust_notrace \
423 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
425 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
427 size_t __event_len = 0; \
428 unsigned int __dynamic_len_idx = 0; \
431 (void) __dynamic_len_idx; /* don't warn if unused */ \
433 return __event_len; \
436 #include TRACEPOINT_INCLUDE
439 * Stage 3.1 of tracepoint event generation.
441 * Create static inline function that layout the filter stack data.
442 * We make both write and nowrite data available to the filter.
445 /* Reset all macros within TRACEPOINT_EVENT */
446 #include <lttng/ust-tracepoint-event-reset.h>
447 #include <lttng/ust-tracepoint-event-write.h>
448 #include <lttng/ust-tracepoint-event-nowrite.h>
450 #undef _ctf_integer_ext
451 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
452 if (lttng_is_signed_type(_type)) { \
453 int64_t __ctf_tmp_int64; \
454 switch (sizeof(_type)) { \
457 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
458 __ctf_tmp_int64 = (int64_t) __tmp.v; \
463 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
464 if (_byte_order != BYTE_ORDER) \
465 __tmp.v = bswap_16(__tmp.v); \
466 __ctf_tmp_int64 = (int64_t) __tmp.v; \
471 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
472 if (_byte_order != BYTE_ORDER) \
473 __tmp.v = bswap_32(__tmp.v); \
474 __ctf_tmp_int64 = (int64_t) __tmp.v; \
479 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
480 if (_byte_order != BYTE_ORDER) \
481 __tmp.v = bswap_64(__tmp.v); \
482 __ctf_tmp_int64 = (int64_t) __tmp.v; \
488 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
490 uint64_t __ctf_tmp_uint64; \
491 switch (sizeof(_type)) { \
494 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
495 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
500 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
501 if (_byte_order != BYTE_ORDER) \
502 __tmp.v = bswap_16(__tmp.v); \
503 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
508 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
509 if (_byte_order != BYTE_ORDER) \
510 __tmp.v = bswap_32(__tmp.v); \
511 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
516 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
517 if (_byte_order != BYTE_ORDER) \
518 __tmp.v = bswap_64(__tmp.v); \
519 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
525 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
527 __stack_data += sizeof(int64_t);
530 #define _ctf_float(_type, _item, _src, _nowrite) \
532 double __ctf_tmp_double = (double) (_type) (_src); \
533 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
534 __stack_data += sizeof(double); \
537 #undef _ctf_array_encoded
538 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
539 _encoding, _nowrite, _elem_type_base) \
541 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
542 const void *__ctf_tmp_ptr = (_src); \
543 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
544 __stack_data += sizeof(unsigned long); \
545 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
546 __stack_data += sizeof(void *); \
549 #undef _ctf_sequence_encoded
550 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
551 _src_length, _encoding, _nowrite, _elem_type_base) \
553 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
554 const void *__ctf_tmp_ptr = (_src); \
555 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
556 __stack_data += sizeof(unsigned long); \
557 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
558 __stack_data += sizeof(void *); \
562 #define _ctf_string(_item, _src, _nowrite) \
564 const void *__ctf_tmp_ptr = \
565 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
566 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
567 __stack_data += sizeof(void *); \
571 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
572 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
575 #define TP_ARGS(...) __VA_ARGS__
578 #define TP_FIELDS(...) __VA_ARGS__
580 #undef TRACEPOINT_EVENT_CLASS
581 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
583 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
584 _TP_ARGS_DATA_PROTO(_args)) \
589 #include TRACEPOINT_INCLUDE
592 * Stage 4 of tracepoint event generation.
594 * Create static inline function that calculates event payload alignment.
597 /* Reset all macros within TRACEPOINT_EVENT */
598 #include <lttng/ust-tracepoint-event-reset.h>
599 #include <lttng/ust-tracepoint-event-write.h>
601 #undef _ctf_integer_ext
602 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
603 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
606 #define _ctf_float(_type, _item, _src, _nowrite) \
607 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
609 #undef _ctf_array_encoded
610 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
611 _encoding, _nowrite, _elem_type_base) \
612 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
614 #undef _ctf_sequence_encoded
615 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
616 _src_length, _encoding, _nowrite, _elem_type_base) \
617 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
618 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
621 #define _ctf_string(_item, _src, _nowrite)
624 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
625 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
628 #define TP_ARGS(...) __VA_ARGS__
631 #define TP_FIELDS(...) __VA_ARGS__
633 #undef TRACEPOINT_EVENT_CLASS
634 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
635 static inline lttng_ust_notrace \
636 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
638 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
640 size_t __event_align = 1; \
642 return __event_align; \
645 #include TRACEPOINT_INCLUDE
649 * Stage 5 of tracepoint event generation.
651 * Create the probe function. This function calls event size calculation
652 * and writes event data into the buffer.
655 /* Reset all macros within TRACEPOINT_EVENT */
656 #include <lttng/ust-tracepoint-event-reset.h>
657 #include <lttng/ust-tracepoint-event-write.h>
659 #undef _ctf_integer_ext
660 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
662 _type __tmp = (_src); \
663 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
664 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
668 #define _ctf_float(_type, _item, _src, _nowrite) \
670 _type __tmp = (_src); \
671 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
672 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
675 #undef _ctf_array_encoded
676 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
677 _encoding, _nowrite, _elem_type_base) \
678 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
679 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
681 #undef _ctf_sequence_encoded
682 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
683 _src_length, _encoding, _nowrite, _elem_type_base) \
685 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
686 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
687 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
689 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
690 __chan->ops->event_write(&__ctx, _src, \
691 sizeof(_type) * __get_dynamic_len(dest));
694 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
695 * tracepoint provider ABI implements event_strcpy. This dynamic check
696 * can be removed when the tracepoint provider ABI moves to 2.
698 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
699 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
703 #define _ctf_string(_item, _src, _nowrite) \
705 const char *__ctf_tmp_string = \
706 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
707 lib_ring_buffer_align_ctx(&__ctx, \
708 lttng_alignof(*__ctf_tmp_string)); \
709 if (__chan->ops->u.has_strcpy) \
710 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
711 __get_dynamic_len(dest)); \
713 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
714 __get_dynamic_len(dest)); \
719 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
720 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
722 /* Beware: this get len actually consumes the len value */
723 #undef __get_dynamic_len
724 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
727 #define TP_ARGS(...) __VA_ARGS__
730 #define TP_FIELDS(...) __VA_ARGS__
733 * For state dump, check that "session" argument (mandatory) matches the
734 * session this event belongs to. Ensures that we write state dump data only
735 * into the started session, not into all sessions.
737 #undef _TP_SESSION_CHECK
738 #ifdef TP_SESSION_CHECK
739 #define _TP_SESSION_CHECK(session, csession) (session == csession)
740 #else /* TP_SESSION_CHECK */
741 #define _TP_SESSION_CHECK(session, csession) 1
742 #endif /* TP_SESSION_CHECK */
745 * Use of __builtin_return_address(0) sometimes seems to cause stack
746 * corruption on 32-bit PowerPC. Disable this feature on that
747 * architecture for now by always using the NULL value for the ip
752 #define _TP_IP_PARAM(x) (x)
753 #else /* TP_IP_PARAM */
755 #if defined(__PPC__) && !defined(__PPC64__)
756 #define _TP_IP_PARAM(x) NULL
757 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
758 #define _TP_IP_PARAM(x) __builtin_return_address(0)
759 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
761 #endif /* TP_IP_PARAM */
764 * Using twice size for filter stack data to hold size and pointer for
765 * each field (worse case). For integers, max size required is 64-bit.
766 * Same for double-precision floats. Those fit within
767 * 2*sizeof(unsigned long) for all supported architectures.
768 * Perform UNION (||) of filter runtime list.
770 #undef TRACEPOINT_EVENT_CLASS
771 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
772 static lttng_ust_notrace \
773 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
775 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
777 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
778 struct lttng_channel *__chan = __event->chan; \
779 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
780 struct lttng_stack_ctx __lttng_ctx; \
781 size_t __event_len, __event_align; \
782 size_t __dynamic_len_idx = 0; \
784 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
785 char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
790 (void) __dynamic_len_idx; /* don't warn if unused */ \
791 if (!_TP_SESSION_CHECK(session, __chan->session)) \
793 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
795 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
797 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
799 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
801 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
802 struct lttng_bytecode_runtime *bc_runtime; \
803 int __filter_record = __event->has_enablers_without_bytecode; \
805 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
806 _TP_ARGS_DATA_VAR(_args)); \
807 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
808 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
809 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
810 __filter_record = 1; \
812 if (caa_likely(!__filter_record)) \
815 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
816 _TP_ARGS_DATA_VAR(_args)); \
817 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
818 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
819 __lttng_ctx.event = __event; \
820 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
821 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
822 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
823 __event_align, -1, __chan->handle, &__lttng_ctx); \
824 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
825 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
829 __chan->ops->event_commit(&__ctx); \
832 #include TRACEPOINT_INCLUDE
834 #undef __get_dynamic_len
837 * Stage 5.1 of tracepoint event generation.
839 * Create probe signature
842 /* Reset all macros within TRACEPOINT_EVENT */
843 #include <lttng/ust-tracepoint-event-reset.h>
846 #define TP_ARGS(...) __VA_ARGS__
848 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
850 #undef TRACEPOINT_EVENT_CLASS
851 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
852 static const char __tp_event_signature___##_provider##___##_name[] = \
853 _TP_EXTRACT_STRING2(_args);
855 #include TRACEPOINT_INCLUDE
857 #undef _TP_EXTRACT_STRING2
860 * Stage 6 of tracepoint event generation.
862 * Tracepoint loglevel mapping definition generation. We generate a
863 * symbol for each mapping for a provider/event to ensure at most a 1 to
864 * 1 mapping between events and loglevels. If the symbol is repeated,
865 * the compiler will complain.
868 /* Reset all macros within TRACEPOINT_EVENT */
869 #include <lttng/ust-tracepoint-event-reset.h>
872 * Declare _loglevel___##__provider##___##__name as non-static, with
873 * hidden visibility for c++ handling of weakref. We do a weakref to the
874 * symbol in a later stage, which requires that the symbol is not
878 #define LTTNG_TP_EXTERN_C extern "C"
880 #define LTTNG_TP_EXTERN_C
883 #undef TRACEPOINT_LOGLEVEL
884 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
885 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
886 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
887 __attribute__((visibility("hidden"))) = \
888 &_loglevel_value___##__provider##___##__name;
890 #include TRACEPOINT_INCLUDE
892 #undef LTTNG_TP_EXTERN_C
895 * Stage 6.1 of tracepoint event generation.
897 * Tracepoint UML URI info.
900 /* Reset all macros within TRACEPOINT_EVENT */
901 #include <lttng/ust-tracepoint-event-reset.h>
904 * Declare _model_emf_uri___##__provider##___##__name as non-static,
905 * with hidden visibility for c++ handling of weakref. We do a weakref
906 * to the symbol in a later stage, which requires that the symbol is not
910 #define LTTNG_TP_EXTERN_C extern "C"
912 #define LTTNG_TP_EXTERN_C
915 #undef TRACEPOINT_MODEL_EMF_URI
916 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
917 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
918 __attribute__((visibility("hidden"))) = __uri; \
920 #include TRACEPOINT_INCLUDE
922 #undef LTTNG_TP_EXTERN_C
925 * Stage 7.1 of tracepoint event generation.
927 * Create events description structures. We use a weakref because
928 * loglevels are optional. If not declared, the event will point to the
929 * a loglevel that contains NULL.
932 /* Reset all macros within TRACEPOINT_EVENT */
933 #include <lttng/ust-tracepoint-event-reset.h>
935 #undef TRACEPOINT_EVENT_INSTANCE
936 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
938 __ref_loglevel___##_provider##___##_name \
939 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
940 static const char * \
941 __ref_model_emf_uri___##_provider##___##_name \
942 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
943 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
944 .name = #_provider ":" #_name, \
945 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
947 .fields = __event_fields___##_provider##___##_template, \
948 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
949 .loglevel = &__ref_loglevel___##_provider##___##_name, \
950 .signature = __tp_event_signature___##_provider##___##_template, \
953 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
958 #include TRACEPOINT_INCLUDE
961 * Stage 7.2 of tracepoint event generation.
963 * Create array of events.
966 /* Reset all macros within TRACEPOINT_EVENT */
967 #include <lttng/ust-tracepoint-event-reset.h>
969 #undef TRACEPOINT_EVENT_INSTANCE
970 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
971 &__event_desc___##_provider##_##_name,
973 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
974 #include TRACEPOINT_INCLUDE
975 NULL
, /* Dummy, C99 forbids 0-len array. */
980 * Stage 8 of tracepoint event generation.
982 * Create a toplevel descriptor for the whole probe.
985 /* non-const because list head will be modified when registered. */
986 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
987 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
988 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
989 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
990 .head
= { NULL
, NULL
},
991 .lazy_init_head
= { NULL
, NULL
},
993 .major
= LTTNG_UST_PROVIDER_MAJOR
,
994 .minor
= LTTNG_UST_PROVIDER_MINOR
,
997 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1000 * Stage 9 of tracepoint event generation.
1002 * Register/unregister probes at module load/unload.
1004 * Generate the constructor as an externally visible symbol for use when
1005 * linking the probe statically.
1007 * Register refcount is protected by libc dynamic loader mutex.
1010 /* Reset all macros within TRACEPOINT_EVENT */
1011 #include <lttng/ust-tracepoint-event-reset.h>
1012 static void lttng_ust_notrace
__attribute__((constructor
))
1013 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1015 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1019 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1020 TRACEPOINT_PROVIDER
)++) {
1024 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1025 * static inline function that ensures every probe PROVIDER
1026 * argument match the provider within which they appear. It
1027 * calls empty static inline functions, and therefore has no
1028 * runtime effect. However, if it detects an error, a linker
1029 * error will appear.
1031 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1032 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1034 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1039 static void lttng_ust_notrace
__attribute__((destructor
))
1040 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1042 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1044 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1045 TRACEPOINT_PROVIDER
)) {
1048 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1051 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);