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/ust-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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const 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 const 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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
283 .struct_size = sizeof(struct lttng_ust_event_field), \
285 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
311 .struct_size = sizeof(struct lttng_ust_event_field), \
313 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
330 .struct_size = sizeof(struct lttng_ust_event_field), \
332 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const 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_unused(_src)
347 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
348 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
349 .struct_size = sizeof(struct lttng_ust_event_field), \
351 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \
353 .type = lttng_ust_type_enum, \
355 .struct_size = sizeof(struct lttng_ust_type_enum), \
356 .desc = &__enum_##_provider##_##_name, \
357 .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \
359 .nowrite = _nowrite, \
364 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
366 #undef _TRACEPOINT_EVENT_CLASS
367 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
368 static const struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \
370 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
373 #undef TRACEPOINT_ENUM
374 #define TRACEPOINT_ENUM(_provider, _name, _values) \
375 static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
376 .struct_size = sizeof(struct lttng_ust_enum_desc), \
377 .name = #_provider "_" #_name, \
378 .entries = __enum_values__##_provider##_##_name, \
379 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
382 #include TRACEPOINT_INCLUDE
385 * Stage 2 of tracepoint event generation.
387 * Create probe callback prototypes.
390 /* Reset all macros within TRACEPOINT_EVENT */
391 #include <lttng/ust-tracepoint-event-reset.h>
394 #define TP_ARGS(...) __VA_ARGS__
396 #undef _TRACEPOINT_EVENT_CLASS
397 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
398 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
400 #include TRACEPOINT_INCLUDE
403 * Stage 3.0 of tracepoint event generation.
405 * Create static inline function that calculates event size.
408 /* Reset all macros within TRACEPOINT_EVENT */
409 #include <lttng/ust-tracepoint-event-reset.h>
410 #include <lttng/ust-tracepoint-event-write.h>
412 #undef _ctf_integer_ext
413 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
415 (void) (_src); /* Unused */ \
416 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
417 __event_len += sizeof(_type);
420 #define _ctf_float(_type, _item, _src, _nowrite) \
422 (void) (_src); /* Unused */ \
423 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
424 __event_len += sizeof(_type);
426 #undef _ctf_array_encoded
427 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
428 _nowrite, _elem_type_base) \
430 (void) (_src); /* Unused */ \
431 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
432 __event_len += sizeof(_type) * (_length);
434 #undef _ctf_sequence_encoded
435 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
436 _src_length, _encoding, _nowrite, _elem_type_base) \
438 (void) (_src); /* Unused */ \
439 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
440 __event_len += sizeof(_length_type); \
441 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
442 __dynamic_len[__dynamic_len_idx] = (_src_length); \
443 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
447 #define _ctf_string(_item, _src, _nowrite) \
448 __event_len += __dynamic_len[__dynamic_len_idx++] = \
449 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
452 #define _ctf_unused(_src) \
454 (void) (_src); /* Unused */
457 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
458 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
461 #define TP_ARGS(...) __VA_ARGS__
464 #define TP_FIELDS(...) __VA_ARGS__
466 #undef _TRACEPOINT_EVENT_CLASS
467 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
469 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
472 size_t __event_get_size__##_provider##___##_name( \
473 size_t *__dynamic_len __attribute__((__unused__)), \
474 _TP_ARGS_DATA_PROTO(_args)) \
476 size_t __event_len = 0; \
477 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
480 (void) __tp_data; /* don't warn if unused */ \
483 return __event_len; \
486 #include TRACEPOINT_INCLUDE
489 * Stage 3.1 of tracepoint event generation.
491 * Create static inline function that layout the filter stack data.
492 * We make both write and nowrite data available to the filter.
495 /* Reset all macros within TRACEPOINT_EVENT */
496 #include <lttng/ust-tracepoint-event-reset.h>
497 #include <lttng/ust-tracepoint-event-write.h>
498 #include <lttng/ust-tracepoint-event-nowrite.h>
500 #undef _ctf_integer_ext
501 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
502 if (lttng_ust_is_signed_type(_type)) { \
503 int64_t __ctf_tmp_int64; \
504 switch (sizeof(_type)) { \
507 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
508 __ctf_tmp_int64 = (int64_t) __tmp.v; \
513 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
514 if (_byte_order != BYTE_ORDER) \
515 __tmp.v = bswap_16(__tmp.v); \
516 __ctf_tmp_int64 = (int64_t) __tmp.v; \
521 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
522 if (_byte_order != BYTE_ORDER) \
523 __tmp.v = bswap_32(__tmp.v); \
524 __ctf_tmp_int64 = (int64_t) __tmp.v; \
529 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
530 if (_byte_order != BYTE_ORDER) \
531 __tmp.v = bswap_64(__tmp.v); \
532 __ctf_tmp_int64 = (int64_t) __tmp.v; \
538 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
540 uint64_t __ctf_tmp_uint64; \
541 switch (sizeof(_type)) { \
544 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
545 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
550 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
551 if (_byte_order != BYTE_ORDER) \
552 __tmp.v = bswap_16(__tmp.v); \
553 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
558 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
559 if (_byte_order != BYTE_ORDER) \
560 __tmp.v = bswap_32(__tmp.v); \
561 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
566 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
567 if (_byte_order != BYTE_ORDER) \
568 __tmp.v = bswap_64(__tmp.v); \
569 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
575 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
577 __stack_data += sizeof(int64_t);
580 #define _ctf_float(_type, _item, _src, _nowrite) \
582 double __ctf_tmp_double = (double) (_type) (_src); \
583 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
584 __stack_data += sizeof(double); \
587 #undef _ctf_array_encoded
588 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
589 _encoding, _nowrite, _elem_type_base) \
591 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
592 const void *__ctf_tmp_ptr = (_src); \
593 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
594 __stack_data += sizeof(unsigned long); \
595 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
596 __stack_data += sizeof(void *); \
599 #undef _ctf_sequence_encoded
600 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
601 _src_length, _encoding, _nowrite, _elem_type_base) \
603 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
604 const void *__ctf_tmp_ptr = (_src); \
605 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
606 __stack_data += sizeof(unsigned long); \
607 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
608 __stack_data += sizeof(void *); \
612 #define _ctf_string(_item, _src, _nowrite) \
614 const void *__ctf_tmp_ptr = \
615 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
616 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
617 __stack_data += sizeof(void *); \
621 #define _ctf_unused(_src) \
626 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
627 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
630 #define TP_ARGS(...) __VA_ARGS__
633 #define TP_FIELDS(...) __VA_ARGS__
635 #undef _TRACEPOINT_EVENT_CLASS
636 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
638 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
639 _TP_ARGS_DATA_PROTO(_args)) \
642 (void) __tp_data; /* don't warn if unused */ \
643 (void) __stack_data; /* don't warn if unused */ \
649 #include TRACEPOINT_INCLUDE
652 * Stage 4 of tracepoint event generation.
654 * Create static inline function that calculates event payload alignment.
657 /* Reset all macros within TRACEPOINT_EVENT */
658 #include <lttng/ust-tracepoint-event-reset.h>
659 #include <lttng/ust-tracepoint-event-write.h>
661 #undef _ctf_integer_ext
662 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
664 (void) (_src); /* Unused */ \
665 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
668 #define _ctf_float(_type, _item, _src, _nowrite) \
670 (void) (_src); /* Unused */ \
671 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
673 #undef _ctf_array_encoded
674 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
675 _encoding, _nowrite, _elem_type_base) \
677 (void) (_src); /* Unused */ \
678 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
680 #undef _ctf_sequence_encoded
681 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
682 _src_length, _encoding, _nowrite, _elem_type_base) \
684 (void) (_src); /* Unused */ \
686 (void) (_src_length); /* Unused */ \
687 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \
688 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
691 #define _ctf_string(_item, _src, _nowrite) \
693 (void) (_src); /* Unused */
696 #define _ctf_unused(_src) \
698 (void) (_src); /* Unused */
701 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
702 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
705 #define TP_ARGS(...) __VA_ARGS__
708 #define TP_FIELDS(...) __VA_ARGS__
710 #undef _TRACEPOINT_EVENT_CLASS
711 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
713 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
716 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
718 size_t __event_align = 1; \
720 return __event_align; \
723 #include TRACEPOINT_INCLUDE
727 * Stage 5 of tracepoint event generation.
729 * Create the probe function. This function calls event size calculation
730 * and writes event data into the buffer.
733 /* Reset all macros within TRACEPOINT_EVENT */
734 #include <lttng/ust-tracepoint-event-reset.h>
735 #include <lttng/ust-tracepoint-event-write.h>
737 #undef _ctf_integer_ext
738 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
740 _type __tmp = (_src); \
741 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
745 #define _ctf_float(_type, _item, _src, _nowrite) \
747 _type __tmp = (_src); \
748 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
751 #undef _ctf_array_encoded
752 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
753 _encoding, _nowrite, _elem_type_base) \
754 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
755 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
757 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
759 #undef _ctf_sequence_encoded
760 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
761 _src_length, _encoding, _nowrite, _elem_type_base) \
763 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
764 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
766 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
767 __chan->ops->event_write(&__ctx, _src, \
768 sizeof(_type) * __get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
770 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), __get_dynamic_len(dest)); \
773 #define _ctf_string(_item, _src, _nowrite) \
775 const char *__ctf_tmp_string = \
776 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
777 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
778 __get_dynamic_len(dest)); \
782 #define _ctf_unused(_src)
785 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
786 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
788 /* Beware: this get len actually consumes the len value */
789 #undef __get_dynamic_len
790 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
793 #define TP_ARGS(...) __VA_ARGS__
796 #define TP_FIELDS(...) __VA_ARGS__
799 * For state dump, check that "session" argument (mandatory) matches the
800 * session this event belongs to. Ensures that we write state dump data only
801 * into the started session, not into all sessions.
803 #undef _TP_SESSION_CHECK
804 #ifdef TP_SESSION_CHECK
805 #define _TP_SESSION_CHECK(session, csession) (session == csession)
806 #else /* TP_SESSION_CHECK */
807 #define _TP_SESSION_CHECK(session, csession) 1
808 #endif /* TP_SESSION_CHECK */
811 * Use of __builtin_return_address(0) sometimes seems to cause stack
812 * corruption on 32-bit PowerPC. Disable this feature on that
813 * architecture for now by always using the NULL value for the ip
818 #define _TP_IP_PARAM(x) (x)
819 #else /* TP_IP_PARAM */
821 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
822 #define _TP_IP_PARAM(x) NULL
824 #define _TP_IP_PARAM(x) __builtin_return_address(0)
827 #endif /* TP_IP_PARAM */
830 * Using twice size for filter stack data to hold size and pointer for
831 * each field (worse case). For integers, max size required is 64-bit.
832 * Same for double-precision floats. Those fit within
833 * 2*sizeof(unsigned long) for all supported architectures.
834 * Perform UNION (||) of filter runtime list.
836 #undef _TRACEPOINT_EVENT_CLASS
837 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
839 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
842 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
844 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
845 size_t __dynamic_len_idx = 0; \
846 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
848 size_t __dynamic_len[__num_fields]; \
849 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
852 bool __interpreter_stack_prepared = false; \
855 (void) __dynamic_len_idx; /* don't warn if unused */ \
856 switch (__event->type) { \
857 case LTTNG_UST_EVENT_TYPE_RECORDER: \
859 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
860 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
861 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
863 if (!_TP_SESSION_CHECK(session, __chan_common->session)) \
865 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
867 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
871 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
874 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
876 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
878 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
879 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
880 _TP_ARGS_DATA_VAR(_args)); \
881 __interpreter_stack_prepared = true; \
882 if (caa_likely(__event->run_filter(__event, \
883 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
886 switch (__event->type) { \
887 case LTTNG_UST_EVENT_TYPE_RECORDER: \
889 size_t __event_len, __event_align; \
890 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
891 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
892 struct lttng_ust_ring_buffer_ctx __ctx; \
894 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
895 _TP_ARGS_DATA_VAR(_args)); \
896 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
897 lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
898 _TP_IP_PARAM(TP_IP_PARAM)); \
899 __ret = __chan->ops->event_reserve(&__ctx); \
903 __chan->ops->event_commit(&__ctx); \
906 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
908 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
909 struct lttng_ust_notification_ctx __notif_ctx; \
911 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
912 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
914 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
915 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
916 _TP_ARGS_DATA_VAR(_args)); \
918 __event_notifier->notification_send(__event_notifier, \
919 __stackvar.__interpreter_stack_data, \
926 #include TRACEPOINT_INCLUDE
928 #undef __get_dynamic_len
931 * Stage 5.1 of tracepoint event generation.
933 * Create probe signature
936 /* Reset all macros within TRACEPOINT_EVENT */
937 #include <lttng/ust-tracepoint-event-reset.h>
940 #define TP_ARGS(...) __VA_ARGS__
942 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
944 #undef _TRACEPOINT_EVENT_CLASS
945 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
946 static const char __tp_event_signature___##_provider##___##_name[] = \
947 _TP_EXTRACT_STRING2(_args);
949 #include TRACEPOINT_INCLUDE
951 #undef _TP_EXTRACT_STRING2
954 * Stage 6 of tracepoint event generation.
956 * Tracepoint loglevel mapping definition generation. We generate a
957 * symbol for each mapping for a provider/event to ensure at most a 1 to
958 * 1 mapping between events and loglevels. If the symbol is repeated,
959 * the compiler will complain.
962 /* Reset all macros within TRACEPOINT_EVENT */
963 #include <lttng/ust-tracepoint-event-reset.h>
966 * Declare _loglevel___##__provider##___##__name as non-static, with
967 * hidden visibility for c++ handling of weakref. We do a weakref to the
968 * symbol in a later stage, which requires that the symbol is not
972 #define LTTNG_UST_TP_EXTERN_C extern "C"
974 #define LTTNG_UST_TP_EXTERN_C
977 #undef TRACEPOINT_LOGLEVEL
978 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
979 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
980 LTTNG_UST_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
981 __attribute__((visibility("hidden"))) = \
982 &_loglevel_value___##__provider##___##__name;
984 #include TRACEPOINT_INCLUDE
986 #undef LTTNG_UST_TP_EXTERN_C
989 * Stage 6.1 of tracepoint event generation.
991 * Tracepoint UML URI info.
994 /* Reset all macros within TRACEPOINT_EVENT */
995 #include <lttng/ust-tracepoint-event-reset.h>
998 * Declare _model_emf_uri___##__provider##___##__name as non-static,
999 * with hidden visibility for c++ handling of weakref. We do a weakref
1000 * to the symbol in a later stage, which requires that the symbol is not
1004 #define LTTNG_UST_TP_EXTERN_C extern "C"
1006 #define LTTNG_UST_TP_EXTERN_C
1009 #undef TRACEPOINT_MODEL_EMF_URI
1010 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1011 LTTNG_UST_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
1012 __attribute__((visibility("hidden"))) = __uri; \
1014 #include TRACEPOINT_INCLUDE
1016 #undef LTTNG_UST_TP_EXTERN_C
1019 * Stage 7.0 of tracepoint event generation.
1021 * Declare toplevel descriptor for the whole probe.
1022 * Unlike C, C++ does not allow tentative definitions. Therefore, we
1023 * need to explicitly declare the variable with "extern", using hidden
1024 * visibility to keep this symbol from being exported to the global
1028 extern const struct lttng_ust_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
)
1029 __attribute__((visibility("hidden")));
1032 * Stage 7.1 of tracepoint event generation.
1034 * Create events description structures. We use a weakref because
1035 * loglevels are optional. If not declared, the event will point to the
1036 * a loglevel that contains NULL.
1039 /* Reset all macros within TRACEPOINT_EVENT */
1040 #include <lttng/ust-tracepoint-event-reset.h>
1042 #undef _TRACEPOINT_EVENT_INSTANCE
1043 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1044 static const int * \
1045 __ref_loglevel___##_provider##___##_name \
1046 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1047 static const char * \
1048 __ref_model_emf_uri___##_provider##___##_name \
1049 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1050 static const struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \
1051 .struct_size = sizeof(struct lttng_ust_event_desc), \
1052 .event_name = #_name, \
1053 .probe_desc = &__probe_desc___##_provider, \
1054 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \
1055 .fields = __event_fields___##_provider##___##_template, \
1056 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1057 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1058 .signature = __tp_event_signature___##_provider##___##_template, \
1059 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1062 #include TRACEPOINT_INCLUDE
1065 * Stage 7.2 of tracepoint event generation.
1067 * Create array of events.
1070 /* Reset all macros within TRACEPOINT_EVENT */
1071 #include <lttng/ust-tracepoint-event-reset.h>
1073 #undef _TRACEPOINT_EVENT_INSTANCE
1074 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1075 &__event_desc___##_provider##_##_name,
1077 static const struct lttng_ust_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1078 #include TRACEPOINT_INCLUDE
1079 NULL
, /* Dummy, C99 forbids 0-len array. */
1084 * Stage 8 of tracepoint event generation.
1086 * Create a toplevel descriptor for the whole probe.
1089 const struct lttng_ust_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1090 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1091 .provider_name
= __tp_stringify(TRACEPOINT_PROVIDER
),
1092 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1093 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1094 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1095 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1098 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1099 static struct lttng_ust_registered_probe
*_TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
);
1102 * Stage 9 of tracepoint event generation.
1104 * Register/unregister probes at module load/unload.
1106 * Generate the constructor as an externally visible symbol for use when
1107 * linking the probe statically.
1109 * Register refcount is protected by libc dynamic loader mutex.
1112 /* Reset all macros within TRACEPOINT_EVENT */
1113 #include <lttng/ust-tracepoint-event-reset.h>
1115 _TP_COMBINE_TOKENS(__lttng_ust_events_init__
, TRACEPOINT_PROVIDER
)(void)
1116 lttng_ust_notrace
__attribute__((constructor
));
1118 _TP_COMBINE_TOKENS(__lttng_ust_events_init__
, TRACEPOINT_PROVIDER
)(void)
1120 struct lttng_ust_registered_probe
*reg_probe
;
1122 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1123 TRACEPOINT_PROVIDER
)++) {
1127 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1128 * static inline function that ensures every probe PROVIDER
1129 * argument match the provider within which they appear. It
1130 * calls empty static inline functions, and therefore has no
1131 * runtime effect. However, if it detects an error, a linker
1132 * error will appear.
1134 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1135 assert(!_TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
));
1136 reg_probe
= lttng_ust_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1138 fprintf(stderr
, "LTTng-UST: Error while registering tracepoint probe.\n");
1141 _TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
) = reg_probe
;
1145 _TP_COMBINE_TOKENS(__lttng_ust_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1146 lttng_ust_notrace
__attribute__((destructor
));
1148 _TP_COMBINE_TOKENS(__lttng_ust_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1150 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1151 TRACEPOINT_PROVIDER
)) {
1154 lttng_ust_probe_unregister(_TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
));
1155 _TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
) = NULL
;
1158 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1159 __attribute__((visibility("default")));