2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <urcu/compiler.h>
11 #include <urcu/rculist.h>
12 #include <lttng/ust-events.h>
13 #include <lttng/ringbuffer-context.h>
14 #include <lttng/ust-compiler.h>
15 #include <lttng/tracepoint.h>
16 #include <lttng/ust-endian.h>
19 #define __LTTNG_UST_NULL_STRING "(null)"
21 #undef tp_list_for_each_entry_rcu
22 #define tp_list_for_each_entry_rcu(pos, head, member) \
23 for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \
24 &pos->member != (head); \
25 pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member))
28 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
29 * same arguments and having the same field layout.
31 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
32 * its own provider and name. It refers to a class (template).
34 * TRACEPOINT_EVENT declared both a class and an instance and does a
35 * direct mapping from the instance to the class.
38 #undef TRACEPOINT_EVENT
39 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
40 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
42 _TP_PARAMS(_fields)) \
43 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
46 #undef TRACEPOINT_EVENT_CLASS
47 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
48 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
50 #undef TRACEPOINT_EVENT_INSTANCE
51 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
52 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
55 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
57 #define _tp_max_t(type, x, y) \
61 __max1 > __max2 ? __max1: __max2; \
65 * Stage 0 of tracepoint event generation.
67 * Check that each TRACEPOINT_EVENT provider argument match the
68 * TRACEPOINT_PROVIDER by creating dummy callbacks.
71 /* Reset all macros within TRACEPOINT_EVENT */
72 #include <lttng/ust-tracepoint-event-reset.h>
74 static inline lttng_ust_notrace
75 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
77 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
81 #undef _TRACEPOINT_EVENT_CLASS
82 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
83 __tracepoint_provider_mismatch_##_provider();
85 #undef _TRACEPOINT_EVENT_INSTANCE
86 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
87 __tracepoint_provider_mismatch_##_provider();
89 static inline lttng_ust_notrace
90 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
92 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
94 #include TRACEPOINT_INCLUDE
98 * Stage 0.1 of tracepoint event generation.
100 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
101 * tracepoint name length limit.
104 /* Reset all macros within TRACEPOINT_EVENT */
105 #include <lttng/ust-tracepoint-event-reset.h>
107 #undef _TRACEPOINT_EVENT_INSTANCE
108 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
110 __tp_name_len_check##_provider##___##_name[LTTNG_UST_ABI_SYM_NAME_LEN] \
111 __attribute__((unused)) = \
112 #_provider ":" #_name;
114 #include TRACEPOINT_INCLUDE
117 * Stage 0.2 of tracepoint event generation.
119 * Create dummy trace prototypes for each event class, and for each used
120 * template. This will allow checking whether the prototypes from the
121 * class and the instance using the class actually match.
124 /* Reset all macros within TRACEPOINT_EVENT */
125 #include <lttng/ust-tracepoint-event-reset.h>
128 #define TP_ARGS(...) __VA_ARGS__
130 #undef _TRACEPOINT_EVENT_INSTANCE
131 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
132 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
134 #undef _TRACEPOINT_EVENT_CLASS
135 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
136 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
138 #include TRACEPOINT_INCLUDE
141 * Stage 0.9 of tracepoint event generation
143 * Unfolding the enums
145 #include <lttng/ust-tracepoint-event-reset.h>
147 /* Enumeration entry (single value) */
148 #undef ctf_enum_value
149 #define ctf_enum_value(_string, _value) \
150 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
151 .struct_size = sizeof(struct lttng_ust_enum_entry), \
153 .value = lttng_is_signed_type(__typeof__(_value)) ? \
154 (long long) (_value) : (_value), \
155 .signedness = lttng_is_signed_type(__typeof__(_value)), \
158 .value = lttng_is_signed_type(__typeof__(_value)) ? \
159 (long long) (_value) : (_value), \
160 .signedness = lttng_is_signed_type(__typeof__(_value)), \
162 .string = (_string), \
165 /* Enumeration entry (range) */
166 #undef ctf_enum_range
167 #define ctf_enum_range(_string, _range_start, _range_end) \
168 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
169 .struct_size = sizeof(struct lttng_ust_enum_entry), \
171 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
172 (long long) (_range_start) : (_range_start), \
173 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
176 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
177 (long long) (_range_end) : (_range_end), \
178 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
180 .string = (_string), \
183 /* Enumeration entry (automatic value; follows the rules of CTF) */
185 #define ctf_enum_auto(_string) \
186 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
187 .struct_size = sizeof(struct lttng_ust_enum_entry), \
196 .string = (_string), \
197 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
200 #undef TP_ENUM_VALUES
201 #define TP_ENUM_VALUES(...) \
204 #undef TRACEPOINT_ENUM
205 #define TRACEPOINT_ENUM(_provider, _name, _values) \
206 struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \
208 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
210 #include TRACEPOINT_INCLUDE
214 * Verifying array and sequence elements are of an integer type.
217 /* Reset all macros within TRACEPOINT_EVENT */
218 #include <lttng/ust-tracepoint-event-reset.h>
219 #include <lttng/ust-tracepoint-event-write.h>
220 #include <lttng/ust-tracepoint-event-nowrite.h>
222 #undef _ctf_array_encoded
223 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
224 _length, _encoding, _nowrite, \
226 _lttng_array_element_type_is_supported(_type, _item)
228 #undef _ctf_sequence_encoded
229 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
230 _length_type, _src_length, _encoding, _nowrite, \
232 _lttng_array_element_type_is_supported(_type, _item)
235 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
237 #undef _TRACEPOINT_EVENT_CLASS
238 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
241 #include TRACEPOINT_INCLUDE
244 * Stage 1 of tracepoint event generation.
246 * Create event field type metadata section.
247 * Each event produce an array of fields.
250 /* Reset all macros within TRACEPOINT_EVENT */
251 #include <lttng/ust-tracepoint-event-reset.h>
252 #include <lttng/ust-tracepoint-event-write.h>
253 #include <lttng/ust-tracepoint-event-nowrite.h>
255 #undef _ctf_integer_ext
256 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
257 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
258 .struct_size = sizeof(struct lttng_ust_event_field), \
260 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
261 .nowrite = _nowrite, \
266 #define _ctf_float(_type, _item, _src, _nowrite) \
267 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
268 .struct_size = sizeof(struct lttng_ust_event_field), \
270 .type = lttng_ust_type_float_define(_type), \
271 .nowrite = _nowrite, \
275 #undef _ctf_array_encoded
276 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
277 _length, _encoding, _nowrite, \
279 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
280 .struct_size = sizeof(struct lttng_ust_event_field), \
282 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_array, { \
284 .type = lttng_ust_type_array, \
286 .struct_size = sizeof(struct lttng_ust_type_array), \
287 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
290 .encoding = lttng_ust_string_encoding_##_encoding, \
292 .nowrite = _nowrite, \
296 #undef _ctf_sequence_encoded
297 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
298 _length_type, _src_length, _encoding, _nowrite, \
300 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
301 .struct_size = sizeof(struct lttng_ust_event_field), \
302 .name = "_" #_item "_length", \
303 .type = lttng_ust_type_integer_define(_length_type, BYTE_ORDER, 10), \
304 .nowrite = _nowrite, \
307 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
308 .struct_size = sizeof(struct lttng_ust_event_field), \
310 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_sequence, { \
312 .type = lttng_ust_type_sequence, \
314 .struct_size = sizeof(struct lttng_ust_type_sequence), \
315 .length_name = "_" #_item "_length", \
316 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
318 .encoding = lttng_ust_string_encoding_##_encoding, \
320 .nowrite = _nowrite, \
325 #define _ctf_string(_item, _src, _nowrite) \
326 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
327 .struct_size = sizeof(struct lttng_ust_event_field), \
329 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_string, { \
331 .type = lttng_ust_type_string, \
333 .struct_size = sizeof(struct lttng_ust_type_string), \
334 .encoding = lttng_ust_string_encoding_UTF8, \
336 .nowrite = _nowrite, \
341 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
342 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
343 .struct_size = sizeof(struct lttng_ust_event_field), \
345 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_enum, { \
347 .type = lttng_ust_type_enum, \
349 .struct_size = sizeof(struct lttng_ust_type_enum), \
350 .desc = &__enum_##_provider##_##_name, \
351 .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \
353 .nowrite = _nowrite, \
358 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
360 #undef _TRACEPOINT_EVENT_CLASS
361 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
362 static struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \
364 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
367 #undef TRACEPOINT_ENUM
368 #define TRACEPOINT_ENUM(_provider, _name, _values) \
369 static struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
370 .struct_size = sizeof(struct lttng_ust_enum_desc), \
371 .name = #_provider "_" #_name, \
372 .entries = __enum_values__##_provider##_##_name, \
373 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
376 #include TRACEPOINT_INCLUDE
379 * Stage 2 of tracepoint event generation.
381 * Create probe callback prototypes.
384 /* Reset all macros within TRACEPOINT_EVENT */
385 #include <lttng/ust-tracepoint-event-reset.h>
388 #define TP_ARGS(...) __VA_ARGS__
390 #undef _TRACEPOINT_EVENT_CLASS
391 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
392 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
394 #include TRACEPOINT_INCLUDE
397 * Stage 3.0 of tracepoint event generation.
399 * Create static inline function that calculates event size.
402 /* Reset all macros within TRACEPOINT_EVENT */
403 #include <lttng/ust-tracepoint-event-reset.h>
404 #include <lttng/ust-tracepoint-event-write.h>
406 #undef _ctf_integer_ext
407 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
408 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
409 __event_len += sizeof(_type);
412 #define _ctf_float(_type, _item, _src, _nowrite) \
413 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
414 __event_len += sizeof(_type);
416 #undef _ctf_array_encoded
417 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
418 _nowrite, _elem_type_base) \
419 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
420 __event_len += sizeof(_type) * (_length);
422 #undef _ctf_sequence_encoded
423 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
424 _src_length, _encoding, _nowrite, _elem_type_base) \
425 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
426 __event_len += sizeof(_length_type); \
427 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
428 __dynamic_len[__dynamic_len_idx] = (_src_length); \
429 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
433 #define _ctf_string(_item, _src, _nowrite) \
434 __event_len += __dynamic_len[__dynamic_len_idx++] = \
435 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
438 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
439 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
442 #define TP_ARGS(...) __VA_ARGS__
445 #define TP_FIELDS(...) __VA_ARGS__
447 #undef _TRACEPOINT_EVENT_CLASS
448 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
449 static inline lttng_ust_notrace \
450 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
452 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
454 size_t __event_len = 0; \
455 unsigned int __dynamic_len_idx = 0; \
458 (void) __dynamic_len_idx; /* don't warn if unused */ \
460 return __event_len; \
463 #include TRACEPOINT_INCLUDE
466 * Stage 3.1 of tracepoint event generation.
468 * Create static inline function that layout the filter stack data.
469 * We make both write and nowrite data available to the filter.
472 /* Reset all macros within TRACEPOINT_EVENT */
473 #include <lttng/ust-tracepoint-event-reset.h>
474 #include <lttng/ust-tracepoint-event-write.h>
475 #include <lttng/ust-tracepoint-event-nowrite.h>
477 #undef _ctf_integer_ext
478 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
479 if (lttng_is_signed_type(_type)) { \
480 int64_t __ctf_tmp_int64; \
481 switch (sizeof(_type)) { \
484 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
485 __ctf_tmp_int64 = (int64_t) __tmp.v; \
490 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
491 if (_byte_order != BYTE_ORDER) \
492 __tmp.v = bswap_16(__tmp.v); \
493 __ctf_tmp_int64 = (int64_t) __tmp.v; \
498 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
499 if (_byte_order != BYTE_ORDER) \
500 __tmp.v = bswap_32(__tmp.v); \
501 __ctf_tmp_int64 = (int64_t) __tmp.v; \
506 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
507 if (_byte_order != BYTE_ORDER) \
508 __tmp.v = bswap_64(__tmp.v); \
509 __ctf_tmp_int64 = (int64_t) __tmp.v; \
515 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
517 uint64_t __ctf_tmp_uint64; \
518 switch (sizeof(_type)) { \
521 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
522 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
527 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
528 if (_byte_order != BYTE_ORDER) \
529 __tmp.v = bswap_16(__tmp.v); \
530 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
535 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
536 if (_byte_order != BYTE_ORDER) \
537 __tmp.v = bswap_32(__tmp.v); \
538 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
543 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
544 if (_byte_order != BYTE_ORDER) \
545 __tmp.v = bswap_64(__tmp.v); \
546 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
552 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
554 __stack_data += sizeof(int64_t);
557 #define _ctf_float(_type, _item, _src, _nowrite) \
559 double __ctf_tmp_double = (double) (_type) (_src); \
560 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
561 __stack_data += sizeof(double); \
564 #undef _ctf_array_encoded
565 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
566 _encoding, _nowrite, _elem_type_base) \
568 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
569 const void *__ctf_tmp_ptr = (_src); \
570 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
571 __stack_data += sizeof(unsigned long); \
572 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
573 __stack_data += sizeof(void *); \
576 #undef _ctf_sequence_encoded
577 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
578 _src_length, _encoding, _nowrite, _elem_type_base) \
580 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
581 const void *__ctf_tmp_ptr = (_src); \
582 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
583 __stack_data += sizeof(unsigned long); \
584 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
585 __stack_data += sizeof(void *); \
589 #define _ctf_string(_item, _src, _nowrite) \
591 const void *__ctf_tmp_ptr = \
592 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
593 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
594 __stack_data += sizeof(void *); \
598 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
599 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
602 #define TP_ARGS(...) __VA_ARGS__
605 #define TP_FIELDS(...) __VA_ARGS__
607 #undef _TRACEPOINT_EVENT_CLASS
608 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
610 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
611 _TP_ARGS_DATA_PROTO(_args)) \
616 #include TRACEPOINT_INCLUDE
619 * Stage 4 of tracepoint event generation.
621 * Create static inline function that calculates event payload alignment.
624 /* Reset all macros within TRACEPOINT_EVENT */
625 #include <lttng/ust-tracepoint-event-reset.h>
626 #include <lttng/ust-tracepoint-event-write.h>
628 #undef _ctf_integer_ext
629 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
630 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
633 #define _ctf_float(_type, _item, _src, _nowrite) \
634 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
636 #undef _ctf_array_encoded
637 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
638 _encoding, _nowrite, _elem_type_base) \
639 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
641 #undef _ctf_sequence_encoded
642 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
643 _src_length, _encoding, _nowrite, _elem_type_base) \
644 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
645 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
648 #define _ctf_string(_item, _src, _nowrite)
651 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
652 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
655 #define TP_ARGS(...) __VA_ARGS__
658 #define TP_FIELDS(...) __VA_ARGS__
660 #undef _TRACEPOINT_EVENT_CLASS
661 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
662 static inline lttng_ust_notrace \
663 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
665 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
667 size_t __event_align = 1; \
669 return __event_align; \
672 #include TRACEPOINT_INCLUDE
676 * Stage 5 of tracepoint event generation.
678 * Create the probe function. This function calls event size calculation
679 * and writes event data into the buffer.
682 /* Reset all macros within TRACEPOINT_EVENT */
683 #include <lttng/ust-tracepoint-event-reset.h>
684 #include <lttng/ust-tracepoint-event-write.h>
686 #undef _ctf_integer_ext
687 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
689 _type __tmp = (_src); \
690 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
691 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
695 #define _ctf_float(_type, _item, _src, _nowrite) \
697 _type __tmp = (_src); \
698 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
699 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
702 #undef _ctf_array_encoded
703 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
704 _encoding, _nowrite, _elem_type_base) \
705 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
706 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
708 #undef _ctf_sequence_encoded
709 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
710 _src_length, _encoding, _nowrite, _elem_type_base) \
712 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
713 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
714 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
716 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
717 __chan->ops->event_write(&__ctx, _src, \
718 sizeof(_type) * __get_dynamic_len(dest));
721 #define _ctf_string(_item, _src, _nowrite) \
723 const char *__ctf_tmp_string = \
724 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
725 lib_ring_buffer_align_ctx(&__ctx, \
726 lttng_alignof(*__ctf_tmp_string)); \
727 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
728 __get_dynamic_len(dest)); \
733 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
734 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
736 /* Beware: this get len actually consumes the len value */
737 #undef __get_dynamic_len
738 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
741 #define TP_ARGS(...) __VA_ARGS__
744 #define TP_FIELDS(...) __VA_ARGS__
747 * For state dump, check that "session" argument (mandatory) matches the
748 * session this event belongs to. Ensures that we write state dump data only
749 * into the started session, not into all sessions.
751 #undef _TP_SESSION_CHECK
752 #ifdef TP_SESSION_CHECK
753 #define _TP_SESSION_CHECK(session, csession) (session == csession)
754 #else /* TP_SESSION_CHECK */
755 #define _TP_SESSION_CHECK(session, csession) 1
756 #endif /* TP_SESSION_CHECK */
759 * Use of __builtin_return_address(0) sometimes seems to cause stack
760 * corruption on 32-bit PowerPC. Disable this feature on that
761 * architecture for now by always using the NULL value for the ip
766 #define _TP_IP_PARAM(x) (x)
767 #else /* TP_IP_PARAM */
769 #if defined(__PPC__) && !defined(__PPC64__)
770 #define _TP_IP_PARAM(x) NULL
771 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
772 #define _TP_IP_PARAM(x) __builtin_return_address(0)
773 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
775 #endif /* TP_IP_PARAM */
778 * Using twice size for filter stack data to hold size and pointer for
779 * each field (worse case). For integers, max size required is 64-bit.
780 * Same for double-precision floats. Those fit within
781 * 2*sizeof(unsigned long) for all supported architectures.
782 * Perform UNION (||) of filter runtime list.
784 #undef _TRACEPOINT_EVENT_CLASS
785 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
786 static lttng_ust_notrace \
787 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
789 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
791 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
792 size_t __dynamic_len_idx = 0; \
793 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
795 size_t __dynamic_len[__num_fields]; \
796 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
801 (void) __dynamic_len_idx; /* don't warn if unused */ \
802 switch (__event->type) { \
803 case LTTNG_UST_EVENT_TYPE_RECORDER: \
805 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
806 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
807 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
809 if (!_TP_SESSION_CHECK(session, __chan_common->session)) \
811 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
813 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
817 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
820 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
822 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
824 if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \
825 struct lttng_ust_bytecode_runtime *__filter_bc_runtime; \
826 int __filter_record = __event->has_enablers_without_bytecode; \
828 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
829 _TP_ARGS_DATA_VAR(_args)); \
830 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
831 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
832 __stackvar.__interpreter_stack_data) & LTTNG_UST_BYTECODE_INTERPRETER_RECORD_FLAG)) { \
833 __filter_record = 1; \
837 if (caa_likely(!__filter_record)) \
840 switch (__event->type) { \
841 case LTTNG_UST_EVENT_TYPE_RECORDER: \
843 size_t __event_len, __event_align; \
844 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
845 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
846 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
847 struct lttng_ust_stack_ctx __lttng_ctx; \
849 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
850 _TP_ARGS_DATA_VAR(_args)); \
851 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
852 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
853 __lttng_ctx.struct_size = sizeof(struct lttng_ust_stack_ctx); \
854 __lttng_ctx.event_recorder = __event_recorder; \
855 __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \
856 __lttng_ctx.event_ctx = tp_rcu_dereference(__event_recorder->ctx); \
857 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_ctx, __event_len, \
858 __event_align, -1, __chan->handle); \
859 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
860 __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \
864 __chan->ops->event_commit(&__ctx); \
867 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
869 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
871 if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \
872 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
873 _TP_ARGS_DATA_VAR(_args)); \
875 __event_notifier->notification_send(__event_notifier, \
876 __stackvar.__interpreter_stack_data); \
882 #include TRACEPOINT_INCLUDE
884 #undef __get_dynamic_len
887 * Stage 5.1 of tracepoint event generation.
889 * Create probe signature
892 /* Reset all macros within TRACEPOINT_EVENT */
893 #include <lttng/ust-tracepoint-event-reset.h>
896 #define TP_ARGS(...) __VA_ARGS__
898 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
900 #undef _TRACEPOINT_EVENT_CLASS
901 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
902 static const char __tp_event_signature___##_provider##___##_name[] = \
903 _TP_EXTRACT_STRING2(_args);
905 #include TRACEPOINT_INCLUDE
907 #undef _TP_EXTRACT_STRING2
910 * Stage 6 of tracepoint event generation.
912 * Tracepoint loglevel mapping definition generation. We generate a
913 * symbol for each mapping for a provider/event to ensure at most a 1 to
914 * 1 mapping between events and loglevels. If the symbol is repeated,
915 * the compiler will complain.
918 /* Reset all macros within TRACEPOINT_EVENT */
919 #include <lttng/ust-tracepoint-event-reset.h>
922 * Declare _loglevel___##__provider##___##__name as non-static, with
923 * hidden visibility for c++ handling of weakref. We do a weakref to the
924 * symbol in a later stage, which requires that the symbol is not
928 #define LTTNG_TP_EXTERN_C extern "C"
930 #define LTTNG_TP_EXTERN_C
933 #undef TRACEPOINT_LOGLEVEL
934 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
935 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
936 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
937 __attribute__((visibility("hidden"))) = \
938 &_loglevel_value___##__provider##___##__name;
940 #include TRACEPOINT_INCLUDE
942 #undef LTTNG_TP_EXTERN_C
945 * Stage 6.1 of tracepoint event generation.
947 * Tracepoint UML URI info.
950 /* Reset all macros within TRACEPOINT_EVENT */
951 #include <lttng/ust-tracepoint-event-reset.h>
954 * Declare _model_emf_uri___##__provider##___##__name as non-static,
955 * with hidden visibility for c++ handling of weakref. We do a weakref
956 * to the symbol in a later stage, which requires that the symbol is not
960 #define LTTNG_TP_EXTERN_C extern "C"
962 #define LTTNG_TP_EXTERN_C
965 #undef TRACEPOINT_MODEL_EMF_URI
966 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
967 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
968 __attribute__((visibility("hidden"))) = __uri; \
970 #include TRACEPOINT_INCLUDE
972 #undef LTTNG_TP_EXTERN_C
975 * Stage 7.1 of tracepoint event generation.
977 * Create events description structures. We use a weakref because
978 * loglevels are optional. If not declared, the event will point to the
979 * a loglevel that contains NULL.
982 /* Reset all macros within TRACEPOINT_EVENT */
983 #include <lttng/ust-tracepoint-event-reset.h>
985 #undef _TRACEPOINT_EVENT_INSTANCE
986 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
988 __ref_loglevel___##_provider##___##_name \
989 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
990 static const char * \
991 __ref_model_emf_uri___##_provider##___##_name \
992 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
993 static struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \
994 .struct_size = sizeof(struct lttng_ust_event_desc), \
995 .name = #_provider ":" #_name, \
996 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \
998 .fields = __event_fields___##_provider##___##_template, \
999 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1000 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1001 .signature = __tp_event_signature___##_provider##___##_template, \
1002 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1005 #include TRACEPOINT_INCLUDE
1008 * Stage 7.2 of tracepoint event generation.
1010 * Create array of events.
1013 /* Reset all macros within TRACEPOINT_EVENT */
1014 #include <lttng/ust-tracepoint-event-reset.h>
1016 #undef _TRACEPOINT_EVENT_INSTANCE
1017 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1018 &__event_desc___##_provider##_##_name,
1020 static struct lttng_ust_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1021 #include TRACEPOINT_INCLUDE
1022 NULL
, /* Dummy, C99 forbids 0-len array. */
1027 * Stage 8 of tracepoint event generation.
1029 * Create a toplevel descriptor for the whole probe.
1032 /* non-const because list head will be modified when registered. */
1033 static struct lttng_ust_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1034 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1035 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
1036 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1037 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1038 .head
= { NULL
, NULL
},
1039 .lazy_init_head
= { NULL
, NULL
},
1041 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1042 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1045 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1048 * Stage 9 of tracepoint event generation.
1050 * Register/unregister probes at module load/unload.
1052 * Generate the constructor as an externally visible symbol for use when
1053 * linking the probe statically.
1055 * Register refcount is protected by libc dynamic loader mutex.
1058 /* Reset all macros within TRACEPOINT_EVENT */
1059 #include <lttng/ust-tracepoint-event-reset.h>
1060 static void lttng_ust_notrace
__attribute__((constructor
))
1061 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1063 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1067 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1068 TRACEPOINT_PROVIDER
)++) {
1072 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1073 * static inline function that ensures every probe PROVIDER
1074 * argument match the provider within which they appear. It
1075 * calls empty static inline functions, and therefore has no
1076 * runtime effect. However, if it detects an error, a linker
1077 * error will appear.
1079 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1080 ret
= lttng_ust_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1082 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1087 static void lttng_ust_notrace
__attribute__((destructor
))
1088 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1090 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1092 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1093 TRACEPOINT_PROVIDER
)) {
1096 lttng_ust_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1099 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1100 __attribute__((visibility("default")));