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-arch.h>
15 #include <lttng/ust-compiler.h>
16 #include <lttng/tracepoint.h>
17 #include <lttng/ust-endian.h>
20 #define __LTTNG_UST_NULL_STRING "(null)"
22 #undef tp_list_for_each_entry_rcu
23 #define tp_list_for_each_entry_rcu(pos, head, member) \
24 for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \
25 &pos->member != (head); \
26 pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member))
29 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
30 * same arguments and having the same field layout.
32 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
33 * its own provider and name. It refers to a class (template).
35 * TRACEPOINT_EVENT declared both a class and an instance and does a
36 * direct mapping from the instance to the class.
39 #undef TRACEPOINT_EVENT
40 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
41 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
43 _TP_PARAMS(_fields)) \
44 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
47 #undef TRACEPOINT_EVENT_CLASS
48 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
49 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
51 #undef TRACEPOINT_EVENT_INSTANCE
52 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
53 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
56 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
58 #define _tp_max_t(type, x, y) \
62 __max1 > __max2 ? __max1: __max2; \
66 * Stage 0 of tracepoint event generation.
68 * Check that each TRACEPOINT_EVENT provider argument match the
69 * TRACEPOINT_PROVIDER by creating dummy callbacks.
72 /* Reset all macros within TRACEPOINT_EVENT */
73 #include <lttng/ust-tracepoint-event-reset.h>
76 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
79 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
83 #undef _TRACEPOINT_EVENT_CLASS
84 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
85 __tracepoint_provider_mismatch_##_provider();
87 #undef _TRACEPOINT_EVENT_INSTANCE
88 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
89 __tracepoint_provider_mismatch_##_provider();
92 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
95 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
97 #include TRACEPOINT_INCLUDE
101 * Stage 0.1 of tracepoint event generation.
103 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
104 * tracepoint name length limit.
107 /* Reset all macros within TRACEPOINT_EVENT */
108 #include <lttng/ust-tracepoint-event-reset.h>
110 #undef _TRACEPOINT_EVENT_INSTANCE
111 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
113 __tp_name_len_check##_provider##___##_name[LTTNG_UST_ABI_SYM_NAME_LEN] \
114 __attribute__((unused)) = \
115 #_provider ":" #_name;
117 #include TRACEPOINT_INCLUDE
120 * Stage 0.2 of tracepoint event generation.
122 * Create dummy trace prototypes for each event class, and for each used
123 * template. This will allow checking whether the prototypes from the
124 * class and the instance using the class actually match.
127 /* Reset all macros within TRACEPOINT_EVENT */
128 #include <lttng/ust-tracepoint-event-reset.h>
131 #define TP_ARGS(...) __VA_ARGS__
133 #undef _TRACEPOINT_EVENT_INSTANCE
134 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
135 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
137 #undef _TRACEPOINT_EVENT_CLASS
138 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
139 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
141 #include TRACEPOINT_INCLUDE
144 * Stage 0.9 of tracepoint event generation
146 * Unfolding the enums
148 #include <lttng/ust-tracepoint-event-reset.h>
150 /* Enumeration entry (single value) */
151 #undef ctf_enum_value
152 #define ctf_enum_value(_string, _value) \
153 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
154 .struct_size = sizeof(struct lttng_ust_enum_entry), \
156 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
157 (long long) (_value) : (_value), \
158 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
161 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
162 (long long) (_value) : (_value), \
163 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
165 .string = (_string), \
168 /* Enumeration entry (range) */
169 #undef ctf_enum_range
170 #define ctf_enum_range(_string, _range_start, _range_end) \
171 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
172 .struct_size = sizeof(struct lttng_ust_enum_entry), \
174 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
175 (long long) (_range_start) : (_range_start), \
176 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
179 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
180 (long long) (_range_end) : (_range_end), \
181 .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \
183 .string = (_string), \
186 /* Enumeration entry (automatic value; follows the rules of CTF) */
188 #define ctf_enum_auto(_string) \
189 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
190 .struct_size = sizeof(struct lttng_ust_enum_entry), \
199 .string = (_string), \
200 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
203 #undef TP_ENUM_VALUES
204 #define TP_ENUM_VALUES(...) \
207 #undef TRACEPOINT_ENUM
208 #define TRACEPOINT_ENUM(_provider, _name, _values) \
209 struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \
211 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
213 #include TRACEPOINT_INCLUDE
217 * Verifying array and sequence elements are of an integer type.
220 /* Reset all macros within TRACEPOINT_EVENT */
221 #include <lttng/ust-tracepoint-event-reset.h>
222 #include <lttng/ust-tracepoint-event-write.h>
223 #include <lttng/ust-tracepoint-event-nowrite.h>
225 #undef _ctf_array_encoded
226 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
227 _length, _encoding, _nowrite, \
229 lttng_ust_ctf_array_element_type_is_supported(_type, _item)
231 #undef _ctf_sequence_encoded
232 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
233 _length_type, _src_length, _encoding, _nowrite, \
235 lttng_ust_ctf_array_element_type_is_supported(_type, _item)
238 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
240 #undef _TRACEPOINT_EVENT_CLASS
241 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
244 #include TRACEPOINT_INCLUDE
247 * Stage 1 of tracepoint event generation.
249 * Create event field type metadata section.
250 * Each event produce an array of fields.
253 /* Reset all macros within TRACEPOINT_EVENT */
254 #include <lttng/ust-tracepoint-event-reset.h>
255 #include <lttng/ust-tracepoint-event-write.h>
256 #include <lttng/ust-tracepoint-event-nowrite.h>
258 #undef _ctf_integer_ext
259 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
260 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
261 .struct_size = sizeof(struct lttng_ust_event_field), \
263 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
264 .nowrite = _nowrite, \
269 #define _ctf_float(_type, _item, _src, _nowrite) \
270 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
271 .struct_size = sizeof(struct lttng_ust_event_field), \
273 .type = lttng_ust_type_float_define(_type), \
274 .nowrite = _nowrite, \
278 #undef _ctf_array_encoded
279 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
280 _length, _encoding, _nowrite, \
282 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
283 .struct_size = sizeof(struct lttng_ust_event_field), \
285 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_array, { \
287 .type = lttng_ust_type_array, \
289 .struct_size = sizeof(struct lttng_ust_type_array), \
290 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
293 .encoding = lttng_ust_string_encoding_##_encoding, \
295 .nowrite = _nowrite, \
299 #undef _ctf_sequence_encoded
300 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
301 _length_type, _src_length, _encoding, _nowrite, \
303 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
304 .struct_size = sizeof(struct lttng_ust_event_field), \
305 .name = "_" #_item "_length", \
306 .type = lttng_ust_type_integer_define(_length_type, BYTE_ORDER, 10), \
307 .nowrite = _nowrite, \
310 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
311 .struct_size = sizeof(struct lttng_ust_event_field), \
313 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_sequence, { \
315 .type = lttng_ust_type_sequence, \
317 .struct_size = sizeof(struct lttng_ust_type_sequence), \
318 .length_name = "_" #_item "_length", \
319 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
321 .encoding = lttng_ust_string_encoding_##_encoding, \
323 .nowrite = _nowrite, \
328 #define _ctf_string(_item, _src, _nowrite) \
329 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
330 .struct_size = sizeof(struct lttng_ust_event_field), \
332 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_string, { \
334 .type = lttng_ust_type_string, \
336 .struct_size = sizeof(struct lttng_ust_type_string), \
337 .encoding = lttng_ust_string_encoding_UTF8, \
339 .nowrite = _nowrite, \
344 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
345 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
346 .struct_size = sizeof(struct lttng_ust_event_field), \
348 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_enum, { \
350 .type = lttng_ust_type_enum, \
352 .struct_size = sizeof(struct lttng_ust_type_enum), \
353 .desc = &__enum_##_provider##_##_name, \
354 .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \
356 .nowrite = _nowrite, \
361 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
363 #undef _TRACEPOINT_EVENT_CLASS
364 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
365 static struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \
367 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
370 #undef TRACEPOINT_ENUM
371 #define TRACEPOINT_ENUM(_provider, _name, _values) \
372 static struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
373 .struct_size = sizeof(struct lttng_ust_enum_desc), \
374 .name = #_provider "_" #_name, \
375 .entries = __enum_values__##_provider##_##_name, \
376 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
379 #include TRACEPOINT_INCLUDE
382 * Stage 2 of tracepoint event generation.
384 * Create probe callback prototypes.
387 /* Reset all macros within TRACEPOINT_EVENT */
388 #include <lttng/ust-tracepoint-event-reset.h>
391 #define TP_ARGS(...) __VA_ARGS__
393 #undef _TRACEPOINT_EVENT_CLASS
394 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
395 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
397 #include TRACEPOINT_INCLUDE
400 * Stage 3.0 of tracepoint event generation.
402 * Create static inline function that calculates event size.
405 /* Reset all macros within TRACEPOINT_EVENT */
406 #include <lttng/ust-tracepoint-event-reset.h>
407 #include <lttng/ust-tracepoint-event-write.h>
409 #undef _ctf_integer_ext
410 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
411 __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
412 __event_len += sizeof(_type);
415 #define _ctf_float(_type, _item, _src, _nowrite) \
416 __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
417 __event_len += sizeof(_type);
419 #undef _ctf_array_encoded
420 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
421 _nowrite, _elem_type_base) \
422 __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
423 __event_len += sizeof(_type) * (_length);
425 #undef _ctf_sequence_encoded
426 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
427 _src_length, _encoding, _nowrite, _elem_type_base) \
428 __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
429 __event_len += sizeof(_length_type); \
430 __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
431 __dynamic_len[__dynamic_len_idx] = (_src_length); \
432 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
436 #define _ctf_string(_item, _src, _nowrite) \
437 __event_len += __dynamic_len[__dynamic_len_idx++] = \
438 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
441 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
442 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
445 #define TP_ARGS(...) __VA_ARGS__
448 #define TP_FIELDS(...) __VA_ARGS__
450 #undef _TRACEPOINT_EVENT_CLASS
451 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
453 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
456 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
458 size_t __event_len = 0; \
459 unsigned int __dynamic_len_idx = 0; \
462 (void) __dynamic_len_idx; /* don't warn if unused */ \
464 return __event_len; \
467 #include TRACEPOINT_INCLUDE
470 * Stage 3.1 of tracepoint event generation.
472 * Create static inline function that layout the filter stack data.
473 * We make both write and nowrite data available to the filter.
476 /* Reset all macros within TRACEPOINT_EVENT */
477 #include <lttng/ust-tracepoint-event-reset.h>
478 #include <lttng/ust-tracepoint-event-write.h>
479 #include <lttng/ust-tracepoint-event-nowrite.h>
481 #undef _ctf_integer_ext
482 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
483 if (lttng_ust_is_signed_type(_type)) { \
484 int64_t __ctf_tmp_int64; \
485 switch (sizeof(_type)) { \
488 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
489 __ctf_tmp_int64 = (int64_t) __tmp.v; \
494 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
495 if (_byte_order != BYTE_ORDER) \
496 __tmp.v = bswap_16(__tmp.v); \
497 __ctf_tmp_int64 = (int64_t) __tmp.v; \
502 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
503 if (_byte_order != BYTE_ORDER) \
504 __tmp.v = bswap_32(__tmp.v); \
505 __ctf_tmp_int64 = (int64_t) __tmp.v; \
510 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
511 if (_byte_order != BYTE_ORDER) \
512 __tmp.v = bswap_64(__tmp.v); \
513 __ctf_tmp_int64 = (int64_t) __tmp.v; \
519 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
521 uint64_t __ctf_tmp_uint64; \
522 switch (sizeof(_type)) { \
525 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
526 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
531 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
532 if (_byte_order != BYTE_ORDER) \
533 __tmp.v = bswap_16(__tmp.v); \
534 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
539 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
540 if (_byte_order != BYTE_ORDER) \
541 __tmp.v = bswap_32(__tmp.v); \
542 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
547 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
548 if (_byte_order != BYTE_ORDER) \
549 __tmp.v = bswap_64(__tmp.v); \
550 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
556 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
558 __stack_data += sizeof(int64_t);
561 #define _ctf_float(_type, _item, _src, _nowrite) \
563 double __ctf_tmp_double = (double) (_type) (_src); \
564 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
565 __stack_data += sizeof(double); \
568 #undef _ctf_array_encoded
569 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
570 _encoding, _nowrite, _elem_type_base) \
572 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
573 const void *__ctf_tmp_ptr = (_src); \
574 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
575 __stack_data += sizeof(unsigned long); \
576 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
577 __stack_data += sizeof(void *); \
580 #undef _ctf_sequence_encoded
581 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
582 _src_length, _encoding, _nowrite, _elem_type_base) \
584 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
585 const void *__ctf_tmp_ptr = (_src); \
586 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
587 __stack_data += sizeof(unsigned long); \
588 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
589 __stack_data += sizeof(void *); \
593 #define _ctf_string(_item, _src, _nowrite) \
595 const void *__ctf_tmp_ptr = \
596 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
597 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
598 __stack_data += sizeof(void *); \
602 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
603 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
606 #define TP_ARGS(...) __VA_ARGS__
609 #define TP_FIELDS(...) __VA_ARGS__
611 #undef _TRACEPOINT_EVENT_CLASS
612 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
614 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
615 _TP_ARGS_DATA_PROTO(_args)) \
620 #include TRACEPOINT_INCLUDE
623 * Stage 4 of tracepoint event generation.
625 * Create static inline function that calculates event payload alignment.
628 /* Reset all macros within TRACEPOINT_EVENT */
629 #include <lttng/ust-tracepoint-event-reset.h>
630 #include <lttng/ust-tracepoint-event-write.h>
632 #undef _ctf_integer_ext
633 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
634 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
637 #define _ctf_float(_type, _item, _src, _nowrite) \
638 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
640 #undef _ctf_array_encoded
641 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
642 _encoding, _nowrite, _elem_type_base) \
643 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
645 #undef _ctf_sequence_encoded
646 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
647 _src_length, _encoding, _nowrite, _elem_type_base) \
648 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \
649 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
652 #define _ctf_string(_item, _src, _nowrite)
655 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
656 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
659 #define TP_ARGS(...) __VA_ARGS__
662 #define TP_FIELDS(...) __VA_ARGS__
664 #undef _TRACEPOINT_EVENT_CLASS
665 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
667 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
670 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
672 size_t __event_align = 1; \
674 return __event_align; \
677 #include TRACEPOINT_INCLUDE
681 * Stage 5 of tracepoint event generation.
683 * Create the probe function. This function calls event size calculation
684 * and writes event data into the buffer.
687 /* Reset all macros within TRACEPOINT_EVENT */
688 #include <lttng/ust-tracepoint-event-reset.h>
689 #include <lttng/ust-tracepoint-event-write.h>
691 #undef _ctf_integer_ext
692 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
694 _type __tmp = (_src); \
695 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
699 #define _ctf_float(_type, _item, _src, _nowrite) \
701 _type __tmp = (_src); \
702 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
705 #undef _ctf_array_encoded
706 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
707 _encoding, _nowrite, _elem_type_base) \
708 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
709 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
711 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
713 #undef _ctf_sequence_encoded
714 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
715 _src_length, _encoding, _nowrite, _elem_type_base) \
717 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
718 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
720 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
721 __chan->ops->event_write(&__ctx, _src, \
722 sizeof(_type) * __get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
724 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), __get_dynamic_len(dest)); \
727 #define _ctf_string(_item, _src, _nowrite) \
729 const char *__ctf_tmp_string = \
730 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
731 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
732 __get_dynamic_len(dest)); \
737 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
738 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
740 /* Beware: this get len actually consumes the len value */
741 #undef __get_dynamic_len
742 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
745 #define TP_ARGS(...) __VA_ARGS__
748 #define TP_FIELDS(...) __VA_ARGS__
751 * For state dump, check that "session" argument (mandatory) matches the
752 * session this event belongs to. Ensures that we write state dump data only
753 * into the started session, not into all sessions.
755 #undef _TP_SESSION_CHECK
756 #ifdef TP_SESSION_CHECK
757 #define _TP_SESSION_CHECK(session, csession) (session == csession)
758 #else /* TP_SESSION_CHECK */
759 #define _TP_SESSION_CHECK(session, csession) 1
760 #endif /* TP_SESSION_CHECK */
763 * Use of __builtin_return_address(0) sometimes seems to cause stack
764 * corruption on 32-bit PowerPC. Disable this feature on that
765 * architecture for now by always using the NULL value for the ip
770 #define _TP_IP_PARAM(x) (x)
771 #else /* TP_IP_PARAM */
773 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
774 #define _TP_IP_PARAM(x) NULL
776 #define _TP_IP_PARAM(x) __builtin_return_address(0)
779 #endif /* TP_IP_PARAM */
782 * Using twice size for filter stack data to hold size and pointer for
783 * each field (worse case). For integers, max size required is 64-bit.
784 * Same for double-precision floats. Those fit within
785 * 2*sizeof(unsigned long) for all supported architectures.
786 * Perform UNION (||) of filter runtime list.
788 #undef _TRACEPOINT_EVENT_CLASS
789 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
791 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
794 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
796 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
797 size_t __dynamic_len_idx = 0; \
798 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
800 size_t __dynamic_len[__num_fields]; \
801 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
804 bool __interpreter_stack_prepared = false; \
807 (void) __dynamic_len_idx; /* don't warn if unused */ \
808 switch (__event->type) { \
809 case LTTNG_UST_EVENT_TYPE_RECORDER: \
811 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
812 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
813 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
815 if (!_TP_SESSION_CHECK(session, __chan_common->session)) \
817 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
819 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
823 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
826 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
828 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
830 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
831 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
832 _TP_ARGS_DATA_VAR(_args)); \
833 __interpreter_stack_prepared = true; \
834 if (caa_likely(__event->run_filter(__event, \
835 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
838 switch (__event->type) { \
839 case LTTNG_UST_EVENT_TYPE_RECORDER: \
841 size_t __event_len, __event_align; \
842 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
843 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
844 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
846 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
847 _TP_ARGS_DATA_VAR(_args)); \
848 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
849 lttng_ust_lib_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
850 _TP_IP_PARAM(TP_IP_PARAM)); \
851 __ret = __chan->ops->event_reserve(&__ctx); \
855 __chan->ops->event_commit(&__ctx); \
858 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
860 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
861 struct lttng_ust_notification_ctx __notif_ctx; \
863 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
864 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
866 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
867 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
868 _TP_ARGS_DATA_VAR(_args)); \
870 __event_notifier->notification_send(__event_notifier, \
871 __stackvar.__interpreter_stack_data, \
878 #include TRACEPOINT_INCLUDE
880 #undef __get_dynamic_len
883 * Stage 5.1 of tracepoint event generation.
885 * Create probe signature
888 /* Reset all macros within TRACEPOINT_EVENT */
889 #include <lttng/ust-tracepoint-event-reset.h>
892 #define TP_ARGS(...) __VA_ARGS__
894 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
896 #undef _TRACEPOINT_EVENT_CLASS
897 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
898 static const char __tp_event_signature___##_provider##___##_name[] = \
899 _TP_EXTRACT_STRING2(_args);
901 #include TRACEPOINT_INCLUDE
903 #undef _TP_EXTRACT_STRING2
906 * Stage 6 of tracepoint event generation.
908 * Tracepoint loglevel mapping definition generation. We generate a
909 * symbol for each mapping for a provider/event to ensure at most a 1 to
910 * 1 mapping between events and loglevels. If the symbol is repeated,
911 * the compiler will complain.
914 /* Reset all macros within TRACEPOINT_EVENT */
915 #include <lttng/ust-tracepoint-event-reset.h>
918 * Declare _loglevel___##__provider##___##__name as non-static, with
919 * hidden visibility for c++ handling of weakref. We do a weakref to the
920 * symbol in a later stage, which requires that the symbol is not
924 #define LTTNG_TP_EXTERN_C extern "C"
926 #define LTTNG_TP_EXTERN_C
929 #undef TRACEPOINT_LOGLEVEL
930 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
931 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
932 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
933 __attribute__((visibility("hidden"))) = \
934 &_loglevel_value___##__provider##___##__name;
936 #include TRACEPOINT_INCLUDE
938 #undef LTTNG_TP_EXTERN_C
941 * Stage 6.1 of tracepoint event generation.
943 * Tracepoint UML URI info.
946 /* Reset all macros within TRACEPOINT_EVENT */
947 #include <lttng/ust-tracepoint-event-reset.h>
950 * Declare _model_emf_uri___##__provider##___##__name as non-static,
951 * with hidden visibility for c++ handling of weakref. We do a weakref
952 * to the symbol in a later stage, which requires that the symbol is not
956 #define LTTNG_TP_EXTERN_C extern "C"
958 #define LTTNG_TP_EXTERN_C
961 #undef TRACEPOINT_MODEL_EMF_URI
962 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
963 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
964 __attribute__((visibility("hidden"))) = __uri; \
966 #include TRACEPOINT_INCLUDE
968 #undef LTTNG_TP_EXTERN_C
971 * Stage 7.0 of tracepoint event generation.
973 * Declare toplevel descriptor for the whole probe.
974 * Unlike C, C++ does not allow tentative definitions. Therefore, we
975 * need to explicitly declare the variable with "extern", using hidden
976 * visibility to keep this symbol from being exported to the global
980 extern struct lttng_ust_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
)
981 __attribute__((visibility("hidden")));
984 * Stage 7.1 of tracepoint event generation.
986 * Create events description structures. We use a weakref because
987 * loglevels are optional. If not declared, the event will point to the
988 * a loglevel that contains NULL.
991 /* Reset all macros within TRACEPOINT_EVENT */
992 #include <lttng/ust-tracepoint-event-reset.h>
994 #undef _TRACEPOINT_EVENT_INSTANCE
995 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
997 __ref_loglevel___##_provider##___##_name \
998 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
999 static const char * \
1000 __ref_model_emf_uri___##_provider##___##_name \
1001 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1002 static struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \
1003 .struct_size = sizeof(struct lttng_ust_event_desc), \
1004 .event_name = #_name, \
1005 .probe_desc = &__probe_desc___##_provider, \
1006 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \
1008 .fields = __event_fields___##_provider##___##_template, \
1009 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1010 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1011 .signature = __tp_event_signature___##_provider##___##_template, \
1012 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1015 #include TRACEPOINT_INCLUDE
1018 * Stage 7.2 of tracepoint event generation.
1020 * Create array of events.
1023 /* Reset all macros within TRACEPOINT_EVENT */
1024 #include <lttng/ust-tracepoint-event-reset.h>
1026 #undef _TRACEPOINT_EVENT_INSTANCE
1027 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1028 &__event_desc___##_provider##_##_name,
1030 static struct lttng_ust_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1031 #include TRACEPOINT_INCLUDE
1032 NULL
, /* Dummy, C99 forbids 0-len array. */
1037 * Stage 8 of tracepoint event generation.
1039 * Create a toplevel descriptor for the whole probe.
1042 struct lttng_ust_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1043 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1044 .provider_name
= __tp_stringify(TRACEPOINT_PROVIDER
),
1045 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1046 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1047 .head
= { NULL
, NULL
},
1048 .lazy_init_head
= { NULL
, NULL
},
1050 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1051 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1054 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1057 * Stage 9 of tracepoint event generation.
1059 * Register/unregister probes at module load/unload.
1061 * Generate the constructor as an externally visible symbol for use when
1062 * linking the probe statically.
1064 * Register refcount is protected by libc dynamic loader mutex.
1067 /* Reset all macros within TRACEPOINT_EVENT */
1068 #include <lttng/ust-tracepoint-event-reset.h>
1070 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1071 lttng_ust_notrace
__attribute__((constructor
));
1073 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1077 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1078 TRACEPOINT_PROVIDER
)++) {
1082 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1083 * static inline function that ensures every probe PROVIDER
1084 * argument match the provider within which they appear. It
1085 * calls empty static inline functions, and therefore has no
1086 * runtime effect. However, if it detects an error, a linker
1087 * error will appear.
1089 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1090 ret
= lttng_ust_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1092 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1098 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1099 lttng_ust_notrace
__attribute__((destructor
));
1101 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1103 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1104 TRACEPOINT_PROVIDER
)) {
1107 lttng_ust_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1110 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1111 __attribute__((visibility("default")));