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 * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
30 * same arguments and having the same field layout.
32 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
33 * its own provider and name. It refers to a class (template).
35 * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a
36 * direct mapping from the instance to the class.
39 #undef LTTNG_UST_TRACEPOINT_EVENT
40 #define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
41 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \
42 LTTNG_UST__TP_PARAMS(_args), \
43 LTTNG_UST__TP_PARAMS(_fields)) \
44 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
45 LTTNG_UST__TP_PARAMS(_args))
47 #undef LTTNG_UST_TRACEPOINT_EVENT_CLASS
48 #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
49 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields))
51 #undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
52 #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
53 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, LTTNG_UST__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 LTTNG_UST_TRACEPOINT_EVENT provider argument match the
69 * TRACEPOINT_PROVIDER by creating dummy callbacks.
72 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
73 #include <lttng/ust-tracepoint-event-reset.h>
76 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
79 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
83 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
84 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
85 lttng_ust_tracepoint_provider_mismatch_##_provider();
87 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
88 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
89 lttng_ust_tracepoint_provider_mismatch_##_provider();
92 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
95 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
97 #include TRACEPOINT_INCLUDE
101 * Stage 0.1 of tracepoint event generation.
103 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the
104 * tracepoint name length limit.
107 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
108 #include <lttng/ust-tracepoint-event-reset.h>
110 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
111 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
112 lttng_ust_tracepoint_validate_name_len(_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 LTTNG_UST_TRACEPOINT_EVENT */
125 #include <lttng/ust-tracepoint-event-reset.h>
127 #undef LTTNG_UST_TP_ARGS
128 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
130 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
131 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
132 void __event_template_proto___##_provider##___##_template(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
134 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
135 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
136 void __event_template_proto___##_provider##___##_name(LTTNG_UST__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_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
151 .struct_size = sizeof(struct lttng_ust_enum_entry), \
153 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
154 (long long) (_value) : (_value), \
155 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
158 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
159 (long long) (_value) : (_value), \
160 .signedness = lttng_ust_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_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
169 .struct_size = sizeof(struct lttng_ust_enum_entry), \
171 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
172 (long long) (_range_start) : (_range_start), \
173 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
176 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
177 (long long) (_range_end) : (_range_end), \
178 .signedness = lttng_ust_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_UST_COMPOUND_LITERAL(const 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 const struct lttng_ust_enum_entry * const __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 LTTNG_UST_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_ust_ctf_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_ust_ctf_array_element_type_is_supported(_type, _item);
234 #undef LTTNG_UST_TP_FIELDS
235 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
237 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
238 #define LTTNG_UST__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 LTTNG_UST_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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
280 .struct_size = sizeof(struct lttng_ust_event_field), \
282 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
308 .struct_size = sizeof(struct lttng_ust_event_field), \
310 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const 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_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
327 .struct_size = sizeof(struct lttng_ust_event_field), \
329 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const 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_unused(_src)
344 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
345 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
346 .struct_size = sizeof(struct lttng_ust_event_field), \
348 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const 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, \
360 #undef LTTNG_UST_TP_FIELDS
361 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
363 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
364 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
365 static const struct lttng_ust_event_field * const __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 const 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 LTTNG_UST_TRACEPOINT_EVENT */
388 #include <lttng/ust-tracepoint-event-reset.h>
390 #undef LTTNG_UST_TP_ARGS
391 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
393 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
394 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
395 static void __event_probe__##_provider##___##_name(LTTNG_UST__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 LTTNG_UST_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) \
412 (void) (_src); /* Unused */ \
413 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
414 __event_len += sizeof(_type);
417 #define _ctf_float(_type, _item, _src, _nowrite) \
419 (void) (_src); /* Unused */ \
420 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
421 __event_len += sizeof(_type);
423 #undef _ctf_array_encoded
424 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
425 _nowrite, _elem_type_base) \
427 (void) (_src); /* Unused */ \
428 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
429 __event_len += sizeof(_type) * (_length);
431 #undef _ctf_sequence_encoded
432 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
433 _src_length, _encoding, _nowrite, _elem_type_base) \
435 (void) (_src); /* Unused */ \
436 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
437 __event_len += sizeof(_length_type); \
438 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
439 __dynamic_len[__dynamic_len_idx] = (_src_length); \
440 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
444 #define _ctf_string(_item, _src, _nowrite) \
445 __event_len += __dynamic_len[__dynamic_len_idx++] = \
446 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
449 #define _ctf_unused(_src) \
451 (void) (_src); /* Unused */
454 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
455 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
457 #undef LTTNG_UST_TP_ARGS
458 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
460 #undef LTTNG_UST_TP_FIELDS
461 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
463 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
464 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
466 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
469 size_t __event_get_size__##_provider##___##_name( \
470 size_t *__dynamic_len __attribute__((__unused__)), \
471 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
473 size_t __event_len = 0; \
474 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
477 (void) __tp_data; /* don't warn if unused */ \
480 return __event_len; \
483 #include TRACEPOINT_INCLUDE
486 * Stage 3.1 of tracepoint event generation.
488 * Create static inline function that layout the filter stack data.
489 * We make both write and nowrite data available to the filter.
492 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
493 #include <lttng/ust-tracepoint-event-reset.h>
494 #include <lttng/ust-tracepoint-event-write.h>
495 #include <lttng/ust-tracepoint-event-nowrite.h>
497 #undef _ctf_integer_ext
498 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
499 if (lttng_ust_is_signed_type(_type)) { \
500 int64_t __ctf_tmp_int64; \
501 switch (sizeof(_type)) { \
504 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
505 __ctf_tmp_int64 = (int64_t) __tmp.v; \
510 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
511 if (_byte_order != BYTE_ORDER) \
512 __tmp.v = bswap_16(__tmp.v); \
513 __ctf_tmp_int64 = (int64_t) __tmp.v; \
518 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
519 if (_byte_order != BYTE_ORDER) \
520 __tmp.v = bswap_32(__tmp.v); \
521 __ctf_tmp_int64 = (int64_t) __tmp.v; \
526 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
527 if (_byte_order != BYTE_ORDER) \
528 __tmp.v = bswap_64(__tmp.v); \
529 __ctf_tmp_int64 = (int64_t) __tmp.v; \
535 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
537 uint64_t __ctf_tmp_uint64; \
538 switch (sizeof(_type)) { \
541 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
542 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
547 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
548 if (_byte_order != BYTE_ORDER) \
549 __tmp.v = bswap_16(__tmp.v); \
550 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
555 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
556 if (_byte_order != BYTE_ORDER) \
557 __tmp.v = bswap_32(__tmp.v); \
558 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
563 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
564 if (_byte_order != BYTE_ORDER) \
565 __tmp.v = bswap_64(__tmp.v); \
566 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
572 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
574 __stack_data += sizeof(int64_t);
577 #define _ctf_float(_type, _item, _src, _nowrite) \
579 double __ctf_tmp_double = (double) (_type) (_src); \
580 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
581 __stack_data += sizeof(double); \
584 #undef _ctf_array_encoded
585 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
586 _encoding, _nowrite, _elem_type_base) \
588 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
589 const void *__ctf_tmp_ptr = (_src); \
590 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
591 __stack_data += sizeof(unsigned long); \
592 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
593 __stack_data += sizeof(void *); \
596 #undef _ctf_sequence_encoded
597 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
598 _src_length, _encoding, _nowrite, _elem_type_base) \
600 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
601 const void *__ctf_tmp_ptr = (_src); \
602 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
603 __stack_data += sizeof(unsigned long); \
604 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
605 __stack_data += sizeof(void *); \
609 #define _ctf_string(_item, _src, _nowrite) \
611 const void *__ctf_tmp_ptr = \
612 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
613 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
614 __stack_data += sizeof(void *); \
618 #define _ctf_unused(_src) \
623 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
624 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
626 #undef LTTNG_UST_TP_ARGS
627 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
629 #undef LTTNG_UST_TP_FIELDS
630 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
632 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
633 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
635 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
636 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
639 (void) __tp_data; /* don't warn if unused */ \
640 (void) __stack_data; /* don't warn if unused */ \
646 #include TRACEPOINT_INCLUDE
649 * Stage 4 of tracepoint event generation.
651 * Create static inline function that calculates event payload alignment.
654 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
655 #include <lttng/ust-tracepoint-event-reset.h>
656 #include <lttng/ust-tracepoint-event-write.h>
658 #undef _ctf_integer_ext
659 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
661 (void) (_src); /* Unused */ \
662 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
665 #define _ctf_float(_type, _item, _src, _nowrite) \
667 (void) (_src); /* Unused */ \
668 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
670 #undef _ctf_array_encoded
671 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
672 _encoding, _nowrite, _elem_type_base) \
674 (void) (_src); /* Unused */ \
675 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
677 #undef _ctf_sequence_encoded
678 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
679 _src_length, _encoding, _nowrite, _elem_type_base) \
681 (void) (_src); /* Unused */ \
683 (void) (_src_length); /* Unused */ \
684 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \
685 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
688 #define _ctf_string(_item, _src, _nowrite) \
690 (void) (_src); /* Unused */
693 #define _ctf_unused(_src) \
695 (void) (_src); /* Unused */
698 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
699 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
701 #undef LTTNG_UST_TP_ARGS
702 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
704 #undef LTTNG_UST_TP_FIELDS
705 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
707 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
708 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
710 size_t __event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
713 size_t __event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
715 size_t __event_align = 1; \
717 return __event_align; \
720 #include TRACEPOINT_INCLUDE
724 * Stage 5 of tracepoint event generation.
726 * Create the probe function. This function calls event size calculation
727 * and writes event data into the buffer.
730 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
731 #include <lttng/ust-tracepoint-event-reset.h>
732 #include <lttng/ust-tracepoint-event-write.h>
734 #undef _ctf_integer_ext
735 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
737 _type __tmp = (_src); \
738 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
742 #define _ctf_float(_type, _item, _src, _nowrite) \
744 _type __tmp = (_src); \
745 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
748 #undef _ctf_array_encoded
749 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
750 _encoding, _nowrite, _elem_type_base) \
751 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
752 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
754 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
756 #undef _ctf_sequence_encoded
757 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
758 _src_length, _encoding, _nowrite, _elem_type_base) \
760 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
761 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
763 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
764 __chan->ops->event_write(&__ctx, _src, \
765 sizeof(_type) * __get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
767 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), __get_dynamic_len(dest)); \
770 #define _ctf_string(_item, _src, _nowrite) \
772 const char *__ctf_tmp_string = \
773 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
774 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
775 __get_dynamic_len(dest)); \
779 #define _ctf_unused(_src)
782 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
783 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
785 /* Beware: this get len actually consumes the len value */
786 #undef __get_dynamic_len
787 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
789 #undef LTTNG_UST_TP_ARGS
790 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
792 #undef LTTNG_UST_TP_FIELDS
793 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
796 * For state dump, check that "session" argument (mandatory) matches the
797 * session this event belongs to. Ensures that we write state dump data only
798 * into the started session, not into all sessions.
800 #undef _TP_SESSION_CHECK
801 #ifdef TP_SESSION_CHECK
802 #define _TP_SESSION_CHECK(session, csession) (session == csession)
803 #else /* TP_SESSION_CHECK */
804 #define _TP_SESSION_CHECK(session, csession) 1
805 #endif /* TP_SESSION_CHECK */
808 * Use of __builtin_return_address(0) sometimes seems to cause stack
809 * corruption on 32-bit PowerPC. Disable this feature on that
810 * architecture for now by always using the NULL value for the ip
815 #define _TP_IP_PARAM(x) (x)
816 #else /* TP_IP_PARAM */
818 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
819 #define _TP_IP_PARAM(x) NULL
821 #define _TP_IP_PARAM(x) __builtin_return_address(0)
824 #endif /* TP_IP_PARAM */
827 * Using twice size for filter stack data to hold size and pointer for
828 * each field (worse case). For integers, max size required is 64-bit.
829 * Same for double-precision floats. Those fit within
830 * 2*sizeof(unsigned long) for all supported architectures.
831 * Perform UNION (||) of filter runtime list.
833 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
834 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
836 void __event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
839 void __event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
841 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
842 size_t __dynamic_len_idx = 0; \
843 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
845 size_t __dynamic_len[__num_fields]; \
846 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
849 bool __interpreter_stack_prepared = false; \
852 (void) __dynamic_len_idx; /* don't warn if unused */ \
853 switch (__event->type) { \
854 case LTTNG_UST_EVENT_TYPE_RECORDER: \
856 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
857 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
858 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
860 if (!_TP_SESSION_CHECK(session, __chan_common->session)) \
862 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
864 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
868 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
871 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
873 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
875 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
876 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
877 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
878 __interpreter_stack_prepared = true; \
879 if (caa_likely(__event->run_filter(__event, \
880 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
883 switch (__event->type) { \
884 case LTTNG_UST_EVENT_TYPE_RECORDER: \
886 size_t __event_len, __event_align; \
887 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
888 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
889 struct lttng_ust_ring_buffer_ctx __ctx; \
891 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
892 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
893 __event_align = __event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
894 lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
895 _TP_IP_PARAM(TP_IP_PARAM)); \
896 __ret = __chan->ops->event_reserve(&__ctx); \
900 __chan->ops->event_commit(&__ctx); \
903 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
905 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
906 struct lttng_ust_notification_ctx __notif_ctx; \
908 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
909 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
911 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
912 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
913 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
915 __event_notifier->notification_send(__event_notifier, \
916 __stackvar.__interpreter_stack_data, \
923 #include TRACEPOINT_INCLUDE
925 #undef __get_dynamic_len
928 * Stage 5.1 of tracepoint event generation.
930 * Create probe signature
933 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
934 #include <lttng/ust-tracepoint-event-reset.h>
936 #undef LTTNG_UST_TP_ARGS
937 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
939 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
941 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
942 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
943 static const char __tp_event_signature___##_provider##___##_name[] = \
944 _TP_EXTRACT_STRING2(_args);
946 #include TRACEPOINT_INCLUDE
948 #undef _TP_EXTRACT_STRING2
951 * Stage 6 of tracepoint event generation.
953 * Tracepoint loglevel mapping definition generation. We generate a
954 * symbol for each mapping for a provider/event to ensure at most a 1 to
955 * 1 mapping between events and loglevels. If the symbol is repeated,
956 * the compiler will complain.
959 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
960 #include <lttng/ust-tracepoint-event-reset.h>
963 * Declare _loglevel___##__provider##___##__name as non-static, with
964 * hidden visibility for c++ handling of weakref. We do a weakref to the
965 * symbol in a later stage, which requires that the symbol is not
969 #define LTTNG_UST_TP_EXTERN_C extern "C"
971 #define LTTNG_UST_TP_EXTERN_C
974 #undef TRACEPOINT_LOGLEVEL
975 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
976 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
977 LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
978 __attribute__((visibility("hidden"))) = \
979 &_loglevel_value___##__provider##___##__name;
981 #include TRACEPOINT_INCLUDE
983 #undef LTTNG_UST_TP_EXTERN_C
986 * Stage 6.1 of tracepoint event generation.
988 * Tracepoint UML URI info.
991 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
992 #include <lttng/ust-tracepoint-event-reset.h>
995 * Declare _model_emf_uri___##__provider##___##__name as non-static,
996 * with hidden visibility for c++ handling of weakref. We do a weakref
997 * to the symbol in a later stage, which requires that the symbol is not
1001 #define LTTNG_UST_TP_EXTERN_C extern "C"
1003 #define LTTNG_UST_TP_EXTERN_C
1006 #undef TRACEPOINT_MODEL_EMF_URI
1007 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1008 LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
1009 __attribute__((visibility("hidden"))) = __uri; \
1011 #include TRACEPOINT_INCLUDE
1013 #undef LTTNG_UST_TP_EXTERN_C
1016 * Stage 7.0 of tracepoint event generation.
1018 * Declare toplevel descriptor for the whole probe.
1019 * Unlike C, C++ does not allow tentative definitions. Therefore, we
1020 * need to explicitly declare the variable with "extern", using hidden
1021 * visibility to keep this symbol from being exported to the global
1025 extern const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
)
1026 __attribute__((visibility("hidden")));
1029 * Stage 7.1 of tracepoint event generation.
1031 * Create events description structures. We use a weakref because
1032 * loglevels are optional. If not declared, the event will point to
1033 * a loglevel that contains NULL.
1035 * C++ requires that const objects have a user-declared default
1036 * constructor. However, in both C++ and C, weakref cannot be
1037 * initialized because it causes the weakref attribute to be ignored.
1038 * Therefore, the loglevel and model_emf_uri pointers are not const
1039 * to ensure C++ compilers default-initialize them.
1042 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1043 #include <lttng/ust-tracepoint-event-reset.h>
1045 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1046 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1047 static const int * \
1048 __ref_loglevel___##_provider##___##_name \
1049 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1050 static const char * \
1051 __ref_model_emf_uri___##_provider##___##_name \
1052 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1053 static const struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \
1054 .struct_size = sizeof(struct lttng_ust_event_desc), \
1055 .event_name = #_name, \
1056 .probe_desc = &__probe_desc___##_provider, \
1057 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \
1058 .fields = __event_fields___##_provider##___##_template, \
1059 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1060 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1061 .signature = __tp_event_signature___##_provider##___##_template, \
1062 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1065 #include TRACEPOINT_INCLUDE
1068 * Stage 7.2 of tracepoint event generation.
1070 * Create array of events.
1073 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1074 #include <lttng/ust-tracepoint-event-reset.h>
1076 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1077 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1078 &__event_desc___##_provider##_##_name,
1080 static const struct lttng_ust_event_desc
* const LTTNG_UST__TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1081 #include TRACEPOINT_INCLUDE
1082 NULL
, /* Dummy, C99 forbids 0-len array. */
1087 * Stage 8 of tracepoint event generation.
1089 * Create a toplevel descriptor for the whole probe.
1092 const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1093 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1094 .provider_name
= __tp_stringify(TRACEPOINT_PROVIDER
),
1095 .event_desc
= LTTNG_UST__TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1096 .nr_events
= _TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1097 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1098 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1101 static int LTTNG_UST__TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1102 static struct lttng_ust_registered_probe
*LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
);
1105 * Stage 9 of tracepoint event generation.
1107 * Register/unregister probes at module load/unload.
1109 * Generate the constructor as an externally visible symbol for use when
1110 * linking the probe statically.
1112 * Register refcount is protected by libc dynamic loader mutex.
1115 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1116 #include <lttng/ust-tracepoint-event-reset.h>
1118 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_init__
, TRACEPOINT_PROVIDER
)(void)
1119 lttng_ust_notrace
__attribute__((constructor
));
1121 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_init__
, TRACEPOINT_PROVIDER
)(void)
1123 struct lttng_ust_registered_probe
*reg_probe
;
1125 if (LTTNG_UST__TP_COMBINE_TOKENS(__probe_register_refcount___
,
1126 TRACEPOINT_PROVIDER
)++) {
1130 * lttng_ust_tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1131 * static inline function that ensures every probe PROVIDER
1132 * argument match the provider within which they appear. It
1133 * calls empty static inline functions, and therefore has no
1134 * runtime effect. However, if it detects an error, a linker
1135 * error will appear.
1137 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1138 assert(!LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
));
1139 reg_probe
= lttng_ust_probe_register(<TNG_UST__TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1141 fprintf(stderr
, "LTTng-UST: Error while registering tracepoint probe.\n");
1144 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
) = reg_probe
;
1148 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1149 lttng_ust_notrace
__attribute__((destructor
));
1151 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1153 if (--LTTNG_UST__TP_COMBINE_TOKENS(__probe_register_refcount___
,
1154 TRACEPOINT_PROVIDER
)) {
1157 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
));
1158 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___
, TRACEPOINT_PROVIDER
) = NULL
;
1161 int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1162 __attribute__((visibility("default")));