1 // SPDX-FileCopyrightText: 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: MIT
8 #include <urcu/compiler.h>
9 #include <urcu/rculist.h>
10 #include <lttng/ust-events.h>
11 #include <lttng/ust-ringbuffer-context.h>
12 #include <lttng/ust-arch.h>
13 #include <lttng/ust-compiler.h>
14 #include <lttng/tracepoint.h>
15 #include <lttng/ust-endian.h>
16 #include <lttng/ust-api-compat.h>
18 #include <lttng/ust-api-compat.h>
20 #if LTTNG_UST_COMPAT_API(0)
21 #define TP_FIELDS LTTNG_UST_TP_FIELDS
23 #define ctf_integer lttng_ust_field_integer
24 #define ctf_integer_hex lttng_ust_field_integer_hex
25 #define ctf_integer_network lttng_ust_field_integer_network
26 #define ctf_integer_network_hex lttng_ust_field_integer_network_hex
27 #define ctf_integer_nowrite lttng_ust_field_integer_nowrite
29 #define ctf_float lttng_ust_field_float
30 #define ctf_float_nowrite lttng_ust_field_float_nowrite
32 #define ctf_array lttng_ust_field_array
33 #define ctf_array_hex lttng_ust_field_array_hex
34 #define ctf_array_network lttng_ust_field_array_network
35 #define ctf_array_network_hex lttng_ust_field_array_network_hex
36 #define ctf_array_text lttng_ust_field_array_text
37 #define ctf_array_nowrite lttng_ust_field_array_nowrite
38 #define ctf_array_nowrite_hex lttng_ust_field_array_nowrite_hex
39 #define ctf_array_network_nowrite lttng_ust_field_array_network_nowrite
40 #define ctf_array_network_nowrite_hex lttng_ust_field_array_network_nowrite_hex
41 #define ctf_array_text_nowrite lttng_ust_field_array_text_nowrite
43 #define ctf_sequence lttng_ust_field_sequence
44 #define ctf_sequence_hex lttng_ust_field_sequence_hex
45 #define ctf_sequence_network lttng_ust_field_sequence_network
46 #define ctf_sequence_network_hex lttng_ust_field_sequence_network_hex
47 #define ctf_sequence_text lttng_ust_field_sequence_text
48 #define ctf_sequence_nowrite lttng_ust_field_sequence_nowrite
49 #define ctf_sequence_nowrite_hex lttng_ust_field_sequence_nowrite_hex
50 #define ctf_sequence_network_nowrite lttng_ust_field_sequence_network_nowrite
51 #define ctf_sequence_network_nowrite_hex lttng_ust_field_sequence_network_nowrite_hex
52 #define ctf_sequence_text_nowrite lttng_ust_field_sequence_text_nowrite
54 #define ctf_string lttng_ust_field_string
55 #define ctf_string_nowrite lttng_ust_field_string_nowrite
57 #define ctf_unused lttng_ust_field_unused
58 #define ctf_unused_nowrite lttng_ust_field_unused_nowrite
60 #define ctf_enum lttng_ust_field_enum
61 #define ctf_enum_nowrite lttng_ust_field_enum_nowrite
62 #define ctf_enum_value lttng_ust_field_enum_value
63 #define ctf_enum_range lttng_ust_field_enum_range
64 #define ctf_enum_auto lttng_ust_field_enum_auto
65 #endif /* #if LTTNG_UST_COMPAT_API(0) */
67 #define LTTNG_UST__NULL_STRING "(null)"
70 * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
71 * same arguments and having the same field layout.
73 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
74 * its own provider and name. It refers to a class (template).
76 * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a
77 * direct mapping from the instance to the class.
80 #undef LTTNG_UST_TRACEPOINT_EVENT
81 #define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
82 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \
83 LTTNG_UST__TP_PARAMS(_args), \
84 LTTNG_UST__TP_PARAMS(_fields)) \
85 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _provider, _name, \
86 LTTNG_UST__TP_PARAMS(_args))
88 #undef LTTNG_UST_TRACEPOINT_EVENT_CLASS
89 #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
90 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields))
92 #undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
93 #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
94 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, LTTNG_UST__TP_PARAMS(_args))
97 #define LTTNG_UST__TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
99 #define lttng_ust__tp_max_t(type, x, y) \
101 type lttng_ust__max1 = (x); \
102 type lttng_ust__max2 = (y); \
103 lttng_ust__max1 > lttng_ust__max2 ? lttng_ust__max1: lttng_ust__max2; \
107 * Stage 0 of tracepoint event generation.
109 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider argument match the
110 * LTTNG_UST_TRACEPOINT_PROVIDER by creating dummy callbacks.
113 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
114 #include <lttng/ust-tracepoint-event-reset.h>
117 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
120 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
124 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
125 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
126 lttng_ust_tracepoint_provider_mismatch_##_provider();
128 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
129 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
130 lttng_ust_tracepoint_provider_mismatch_##_provider();
133 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
136 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
138 #include LTTNG_UST_TRACEPOINT_INCLUDE
142 * Stage 0.1 of tracepoint event generation.
144 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the
145 * tracepoint name length limit.
148 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
149 #include <lttng/ust-tracepoint-event-reset.h>
151 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
152 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
153 lttng_ust_tracepoint_validate_name_len(_provider, _name);
155 #include LTTNG_UST_TRACEPOINT_INCLUDE
158 * Stage 0.2 of tracepoint event generation.
160 * Create dummy trace prototypes for each event class, and for each used
161 * template. This will allow checking whether the prototypes from the
162 * class and the instance using the class actually match.
165 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
166 #include <lttng/ust-tracepoint-event-reset.h>
168 #undef LTTNG_UST_TP_ARGS
169 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
171 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
172 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
173 void lttng_ust__event_template_proto___##_template_provider##___##_template_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
175 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
176 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
177 void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
179 #include LTTNG_UST_TRACEPOINT_INCLUDE
182 * Stage 0.9 of tracepoint event generation
184 * Unfolding the enums
186 #include <lttng/ust-tracepoint-event-reset.h>
188 /* Enumeration entry (single value) */
189 #undef lttng_ust_field_enum_value
190 #define lttng_ust_field_enum_value(_string, _value) \
191 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
192 .struct_size = sizeof(struct lttng_ust_enum_entry), \
194 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
195 (long long) (_value) : (_value), \
196 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
199 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
200 (long long) (_value) : (_value), \
201 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
203 .string = (_string), \
206 /* Enumeration entry (range) */
207 #undef lttng_ust_field_enum_range
208 #define lttng_ust_field_enum_range(_string, _range_start, _range_end) \
209 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
210 .struct_size = sizeof(struct lttng_ust_enum_entry), \
212 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
213 (long long) (_range_start) : (_range_start), \
214 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
217 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
218 (long long) (_range_end) : (_range_end), \
219 .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \
221 .string = (_string), \
224 /* Enumeration entry (automatic value; follows the rules of CTF) */
225 #undef lttng_ust_field_enum_auto
226 #define lttng_ust_field_enum_auto(_string) \
227 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
228 .struct_size = sizeof(struct lttng_ust_enum_entry), \
237 .string = (_string), \
238 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
241 #undef LTTNG_UST_TP_ENUM_VALUES
242 #define LTTNG_UST_TP_ENUM_VALUES(...) \
245 #if LTTNG_UST_COMPAT_API(0)
246 # undef TP_ENUM_VALUES
247 # define TP_ENUM_VALUES LTTNG_UST_TP_ENUM_VALUES
248 #endif /* #if LTTNG_UST_COMPAT_API(0) */
250 #undef LTTNG_UST_TRACEPOINT_ENUM
251 #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
252 const struct lttng_ust_enum_entry * const __enum_values__##_provider##_##_name[] = { \
254 lttng_ust_field_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
256 #include LTTNG_UST_TRACEPOINT_INCLUDE
261 * Verifying sequence length types are of an unsigned type.
264 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
265 #include <lttng/ust-tracepoint-event-reset.h>
266 #include <lttng/ust-tracepoint-event-write.h>
267 #include <lttng/ust-tracepoint-event-nowrite.h>
270 * Note that it is not possible to encode the length type as a C identifier,
271 * since it can be multiple tokens.
273 #undef lttng_ust__field_sequence_encoded
274 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
275 _length_type, _src_length, _encoding, _nowrite, \
277 lttng_ust_static_assert(!lttng_ust_is_signed_type(_length_type), \
278 "Length type " #_length_type " is not a unsigned integer type", \
279 Length_type_is_not_a_unsigned_integer_type);
281 #undef LTTNG_UST_TP_FIELDS
282 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
284 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
285 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
288 #include LTTNG_UST_TRACEPOINT_INCLUDE
290 #if defined(__cplusplus)
294 * Verifying array and sequence elements are of an integer or pointer
297 * This compile-time check is only enabled in C++, because the C
298 * implementation of lttng_ust_is_pointer_type does not support opaque
302 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
303 #include <lttng/ust-tracepoint-event-reset.h>
304 #include <lttng/ust-tracepoint-event-write.h>
305 #include <lttng/ust-tracepoint-event-nowrite.h>
307 #undef lttng_ust__field_array_encoded
308 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
309 _length, _encoding, _nowrite, \
311 lttng_ust_field_array_element_type_is_supported(_type, _item);
313 #undef lttng_ust__field_sequence_encoded
314 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
315 _length_type, _src_length, _encoding, _nowrite, \
317 lttng_ust_field_array_element_type_is_supported(_type, _item);
319 #undef LTTNG_UST_TP_FIELDS
320 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
322 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
323 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
326 #include LTTNG_UST_TRACEPOINT_INCLUDE
331 * Stage 0.9.2 of tracepoint event generation.
333 * Create probe signature
336 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
337 #include <lttng/ust-tracepoint-event-reset.h>
339 #undef LTTNG_UST_TP_ARGS
340 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
342 #define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__
344 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
345 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
346 static const char __tp_event_signature___##_provider##___##_name[] = \
347 LTTNG_UST__TP_EXTRACT_STRING2(_args);
349 #include LTTNG_UST_TRACEPOINT_INCLUDE
351 #undef LTTNG_UST__TP_EXTRACT_STRING2
354 * Stage 1 of tracepoint event generation.
356 * Create probe callback prototypes.
359 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
360 #include <lttng/ust-tracepoint-event-reset.h>
362 #undef LTTNG_UST_TP_ARGS
363 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
365 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
366 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
367 static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
369 #include LTTNG_UST_TRACEPOINT_INCLUDE
372 * Stage 1.1 of tracepoint event generation.
374 * Declare toplevel descriptor for the whole probe.
375 * Unlike C, C++ does not allow tentative definitions. Therefore, we
376 * need to explicitly declare the variable with "extern", using hidden
377 * visibility to keep this symbol from being exported to the global
381 extern const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)
382 __attribute__((visibility("hidden")));
385 * Stage 2 of tracepoint event generation.
387 * Create event field type metadata section.
388 * Each event produce an array of fields.
391 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
392 #include <lttng/ust-tracepoint-event-reset.h>
393 #include <lttng/ust-tracepoint-event-write.h>
394 #include <lttng/ust-tracepoint-event-nowrite.h>
396 #undef lttng_ust__field_integer_ext
397 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
398 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
399 .struct_size = sizeof(struct lttng_ust_event_field), \
401 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
402 .nowrite = _nowrite, \
406 #undef lttng_ust__field_float
407 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
408 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
409 .struct_size = sizeof(struct lttng_ust_event_field), \
411 .type = lttng_ust_type_float_define(_type), \
412 .nowrite = _nowrite, \
416 #undef lttng_ust__field_array_encoded
417 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
418 _length, _encoding, _nowrite, \
420 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
421 .struct_size = sizeof(struct lttng_ust_event_field), \
423 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
425 .type = lttng_ust_type_array, \
427 .struct_size = sizeof(struct lttng_ust_type_array), \
428 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
431 .encoding = lttng_ust_string_encoding_##_encoding, \
433 .nowrite = _nowrite, \
437 #undef lttng_ust__field_sequence_encoded
438 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
439 _length_type, _src_length, _encoding, _nowrite, \
441 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
442 .struct_size = sizeof(struct lttng_ust_event_field), \
443 .name = "_" #_item "_length", \
444 .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \
445 .nowrite = _nowrite, \
448 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
449 .struct_size = sizeof(struct lttng_ust_event_field), \
451 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \
453 .type = lttng_ust_type_sequence, \
455 .struct_size = sizeof(struct lttng_ust_type_sequence), \
456 .length_name = NULL, /* Use previous field. */ \
457 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
459 .encoding = lttng_ust_string_encoding_##_encoding, \
461 .nowrite = _nowrite, \
465 #undef lttng_ust__field_string
466 #define lttng_ust__field_string(_item, _src, _nowrite) \
467 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
468 .struct_size = sizeof(struct lttng_ust_event_field), \
470 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \
472 .type = lttng_ust_type_string, \
474 .struct_size = sizeof(struct lttng_ust_type_string), \
475 .encoding = lttng_ust_string_encoding_UTF8, \
477 .nowrite = _nowrite, \
481 #undef lttng_ust__field_unused
482 #define lttng_ust__field_unused(_src)
484 #undef lttng_ust__field_enum
485 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
486 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
487 .struct_size = sizeof(struct lttng_ust_event_field), \
489 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \
491 .type = lttng_ust_type_enum, \
493 .struct_size = sizeof(struct lttng_ust_type_enum), \
494 .desc = &__enum_##_provider##_##_name, \
495 .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \
497 .nowrite = _nowrite, \
501 #undef LTTNG_UST_TP_FIELDS
502 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
504 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
505 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
506 static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \
508 lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
510 static const struct lttng_ust_tracepoint_class lttng_ust__event_class___##_provider##___##_name = { \
511 .struct_size = sizeof(struct lttng_ust_tracepoint_class), \
512 .fields = lttng_ust__event_fields___##_provider##___##_name, \
513 .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1, \
514 .probe_callback = (void (*)(void)) <tng_ust__event_probe__##_provider##___##_name, \
515 .signature = __tp_event_signature___##_provider##___##_name, \
516 .probe_desc = <tng_ust__probe_desc___##_provider, \
519 #undef LTTNG_UST_TRACEPOINT_ENUM
520 #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
521 static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
522 .struct_size = sizeof(struct lttng_ust_enum_desc), \
523 .name = #_provider "_" #_name, \
524 .entries = __enum_values__##_provider##_##_name, \
525 .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
526 .probe_desc = <tng_ust__probe_desc___##_provider, \
529 #include LTTNG_UST_TRACEPOINT_INCLUDE
532 * Stage 3.0 of tracepoint event generation.
534 * Create static inline function that calculates event size.
537 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
538 #include <lttng/ust-tracepoint-event-reset.h>
539 #include <lttng/ust-tracepoint-event-write.h>
541 #undef lttng_ust__field_integer_ext
542 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
544 (void) (_src); /* Unused */ \
545 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
546 __event_len += sizeof(_type);
548 #undef lttng_ust__field_float
549 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
551 (void) (_src); /* Unused */ \
552 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
553 __event_len += sizeof(_type);
555 #undef lttng_ust__field_array_encoded
556 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
557 _nowrite, _elem_type_base) \
559 (void) (_src); /* Unused */ \
560 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
561 __event_len += sizeof(_type) * (_length);
563 #undef lttng_ust__field_sequence_encoded
564 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
565 _src_length, _encoding, _nowrite, _elem_type_base) \
567 (void) (_src); /* Unused */ \
568 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
569 __event_len += sizeof(_length_type); \
570 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
571 __dynamic_len[__dynamic_len_idx] = (_src_length); \
572 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
575 #undef lttng_ust__field_string
576 #define lttng_ust__field_string(_item, _src, _nowrite) \
577 __event_len += __dynamic_len[__dynamic_len_idx++] = \
578 strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1;
580 #undef lttng_ust__field_unused
581 #define lttng_ust__field_unused(_src) \
583 (void) (_src); /* Unused */
585 #undef lttng_ust__field_enum
586 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
587 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
589 #undef LTTNG_UST_TP_ARGS
590 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
592 #undef LTTNG_UST_TP_FIELDS
593 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
595 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
596 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
598 size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
601 size_t lttng_ust__event_get_size__##_provider##___##_name( \
602 size_t *__dynamic_len __attribute__((__unused__)), \
603 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
605 size_t __event_len = 0; \
606 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
609 (void) __tp_data; /* don't warn if unused */ \
612 return __event_len; \
615 #include LTTNG_UST_TRACEPOINT_INCLUDE
618 * Stage 3.1 of tracepoint event generation.
620 * Create static inline function that layout the filter stack data.
621 * We make both write and nowrite data available to the filter.
624 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
625 #include <lttng/ust-tracepoint-event-reset.h>
626 #include <lttng/ust-tracepoint-event-write.h>
627 #include <lttng/ust-tracepoint-event-nowrite.h>
629 #undef lttng_ust__field_integer_ext
630 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
631 if (lttng_ust_is_signed_type(_type)) { \
632 int64_t __ctf_tmp_int64; \
633 switch (sizeof(_type)) { \
636 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
637 __ctf_tmp_int64 = (int64_t) __tmp.v; \
642 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
643 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
644 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
645 __ctf_tmp_int64 = (int64_t) __tmp.v; \
650 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
651 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
652 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
653 __ctf_tmp_int64 = (int64_t) __tmp.v; \
658 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
659 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
660 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
661 __ctf_tmp_int64 = (int64_t) __tmp.v; \
667 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
669 uint64_t __ctf_tmp_uint64; \
670 switch (sizeof(_type)) { \
673 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
674 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
679 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
680 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
681 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
682 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
687 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
688 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
689 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
690 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
695 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
696 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
697 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
698 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
704 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
706 __stack_data += sizeof(int64_t);
708 #undef lttng_ust__field_float
709 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
711 double __ctf_tmp_double = (double) (_type) (_src); \
712 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
713 __stack_data += sizeof(double); \
716 #undef lttng_ust__field_array_encoded
717 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
718 _encoding, _nowrite, _elem_type_base) \
720 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
721 const void *__ctf_tmp_ptr = (_src); \
722 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
723 __stack_data += sizeof(unsigned long); \
724 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
725 __stack_data += sizeof(void *); \
728 #undef lttng_ust__field_sequence_encoded
729 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
730 _src_length, _encoding, _nowrite, _elem_type_base) \
732 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
733 const void *__ctf_tmp_ptr = (_src); \
734 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
735 __stack_data += sizeof(unsigned long); \
736 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
737 __stack_data += sizeof(void *); \
740 #undef lttng_ust__field_string
741 #define lttng_ust__field_string(_item, _src, _nowrite) \
743 const void *__ctf_tmp_ptr = \
744 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
745 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
746 __stack_data += sizeof(void *); \
749 #undef lttng_ust__field_unused
750 #define lttng_ust__field_unused(_src) \
754 #undef lttng_ust__field_enum
755 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
756 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
758 #undef LTTNG_UST_TP_ARGS
759 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
761 #undef LTTNG_UST_TP_FIELDS
762 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
764 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
765 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
767 void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
768 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
771 (void) __tp_data; /* don't warn if unused */ \
772 (void) __stack_data; /* don't warn if unused */ \
778 #include LTTNG_UST_TRACEPOINT_INCLUDE
781 * Stage 4 of tracepoint event generation.
783 * Create static inline function that calculates event payload alignment.
786 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
787 #include <lttng/ust-tracepoint-event-reset.h>
788 #include <lttng/ust-tracepoint-event-write.h>
790 #undef lttng_ust__field_integer_ext
791 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
793 (void) (_src); /* Unused */ \
794 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
796 #undef lttng_ust__field_float
797 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
799 (void) (_src); /* Unused */ \
800 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
802 #undef lttng_ust__field_array_encoded
803 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
804 _encoding, _nowrite, _elem_type_base) \
806 (void) (_src); /* Unused */ \
807 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
809 #undef lttng_ust__field_sequence_encoded
810 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
811 _src_length, _encoding, _nowrite, _elem_type_base) \
813 (void) (_src); /* Unused */ \
815 (void) (_src_length); /* Unused */ \
816 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \
817 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
819 #undef lttng_ust__field_string
820 #define lttng_ust__field_string(_item, _src, _nowrite) \
822 (void) (_src); /* Unused */
824 #undef lttng_ust__field_unused
825 #define lttng_ust__field_unused(_src) \
827 (void) (_src); /* Unused */
829 #undef lttng_ust__field_enum
830 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
831 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
833 #undef LTTNG_UST_TP_ARGS
834 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
836 #undef LTTNG_UST_TP_FIELDS
837 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
839 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
840 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
842 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
845 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
847 size_t __event_align = 1; \
849 return __event_align; \
852 #include LTTNG_UST_TRACEPOINT_INCLUDE
856 * Stage 5 of tracepoint event generation.
858 * Create the probe function. This function calls event size calculation
859 * and writes event data into the buffer.
862 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
863 #include <lttng/ust-tracepoint-event-reset.h>
864 #include <lttng/ust-tracepoint-event-write.h>
866 #undef lttng_ust__field_integer_ext
867 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
869 _type __tmp = (_src); \
870 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
873 #undef lttng_ust__field_float
874 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
876 _type __tmp = (_src); \
877 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
880 #undef lttng_ust__field_array_encoded
881 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
882 _encoding, _nowrite, _elem_type_base) \
883 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
884 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
886 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length);
888 #undef lttng_ust__field_sequence_encoded
889 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
890 _src_length, _encoding, _nowrite, _elem_type_base) \
892 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
893 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
895 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
896 __chan->ops->event_write(&__ctx, _src, \
897 sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
899 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \
901 #undef lttng_ust__field_string
902 #define lttng_ust__field_string(_item, _src, _nowrite) \
904 const char *__ctf_tmp_string = \
905 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
906 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
907 lttng_ust__get_dynamic_len(dest)); \
910 #undef lttng_ust__field_unused
911 #define lttng_ust__field_unused(_src)
913 #undef lttng_ust__field_enum
914 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
915 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
917 /* Beware: this get len actually consumes the len value */
918 #undef lttng_ust__get_dynamic_len
919 #define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
921 #undef LTTNG_UST_TP_ARGS
922 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
924 #undef LTTNG_UST_TP_FIELDS
925 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
928 * For state dump, check that "session" argument (mandatory) matches the
929 * session this event belongs to. Ensures that we write state dump data only
930 * into the started session, not into all sessions.
932 #undef LTTNG_UST__TP_SESSION_CHECK
933 #ifdef LTTNG_UST_TP_SESSION_CHECK
934 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession)
935 #else /* TP_SESSION_CHECK */
936 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1
937 #endif /* TP_SESSION_CHECK */
940 * Use of __builtin_return_address(0) sometimes seems to cause stack
941 * corruption on 32-bit PowerPC. Disable this feature on that
942 * architecture for now by always using the NULL value for the ip
945 #undef LTTNG_UST__TP_IP_PARAM
947 #ifdef LTTNG_UST_TP_IP_PARAM
948 #define LTTNG_UST__TP_IP_PARAM(x) (x)
949 #else /* TP_IP_PARAM */
951 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
952 #define LTTNG_UST__TP_IP_PARAM(x) NULL
954 #define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0)
957 #endif /* TP_IP_PARAM */
960 * Using twice size for filter stack data to hold size and pointer for
961 * each field (worse case). For integers, max size required is 64-bit.
962 * Same for double-precision floats. Those fit within
963 * 2*sizeof(unsigned long) for all supported architectures.
964 * Perform UNION (||) of filter runtime list.
966 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
967 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
969 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
972 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
974 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
975 struct lttng_ust_channel_common *__chan_common; \
976 size_t __dynamic_len_idx = 0; \
977 const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \
978 struct lttng_ust_probe_ctx __probe_ctx; \
980 size_t __dynamic_len[__num_fields]; \
981 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
984 bool __interpreter_stack_prepared = false; \
987 (void) __dynamic_len_idx; /* don't warn if unused */ \
988 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
990 if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
992 __chan_common = lttng_ust_get_chan_common_from_event_common(__event); \
993 if (__chan_common) { \
994 if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \
996 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
998 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
1001 __probe_ctx.struct_size = sizeof(struct lttng_ust_probe_ctx); \
1002 __probe_ctx.ip = LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM); \
1003 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
1004 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
1005 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
1006 __interpreter_stack_prepared = true; \
1007 if (caa_likely(__event->run_filter(__event, \
1008 __stackvar.__interpreter_stack_data, &__probe_ctx, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
1011 switch (__event->type) { \
1012 case LTTNG_UST_EVENT_TYPE_RECORDER: \
1014 size_t __event_len, __event_align; \
1015 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
1016 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
1017 struct lttng_ust_ring_buffer_ctx __ctx; \
1019 __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
1020 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
1021 __event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
1022 lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
1024 __ret = __chan->ops->event_reserve(&__ctx); \
1028 __chan->ops->event_commit(&__ctx); \
1031 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
1033 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
1034 struct lttng_ust_notification_ctx __notif_ctx; \
1036 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
1037 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
1039 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
1040 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
1041 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
1043 __event_notifier->notification_send(__event_notifier, \
1044 __stackvar.__interpreter_stack_data, \
1049 case LTTNG_UST_EVENT_TYPE_COUNTER: \
1051 struct lttng_ust_event_counter *__event_counter = (struct lttng_ust_event_counter *) __event->child; \
1052 struct lttng_ust_event_counter_ctx __event_counter_ctx; \
1054 __event_counter_ctx.struct_size = sizeof(struct lttng_ust_event_counter_ctx); \
1055 __event_counter_ctx.args_available = CMM_ACCESS_ONCE(__event_counter->use_args); \
1057 if (caa_unlikely(!__interpreter_stack_prepared && __event_counter_ctx.args_available)) \
1058 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
1059 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
1061 (void) __event_counter->chan->ops->counter_hit(__event_counter, \
1062 __stackvar.__interpreter_stack_data, \
1064 &__event_counter_ctx); \
1070 #include LTTNG_UST_TRACEPOINT_INCLUDE
1072 #undef lttng_ust__get_dynamic_len
1075 * Stage 6 of tracepoint event generation.
1077 * Tracepoint loglevel mapping definition generation. We generate a
1078 * symbol for each mapping for a provider/event to ensure at most a 1 to
1079 * 1 mapping between events and loglevels. If the symbol is repeated,
1080 * the compiler will complain.
1083 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1084 #include <lttng/ust-tracepoint-event-reset.h>
1087 * Declare _loglevel___##__provider##___##__name as non-static, with
1088 * hidden visibility for c++ handling of weakref. We do a weakref to the
1089 * symbol in a later stage, which requires that the symbol is not
1093 #define LTTNG_UST_TP_EXTERN_C extern "C"
1095 #define LTTNG_UST_TP_EXTERN_C
1098 #undef LTTNG_UST_TRACEPOINT_LOGLEVEL
1099 #define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
1100 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
1101 LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
1102 __attribute__((visibility("hidden"))) = \
1103 &_loglevel_value___##__provider##___##__name;
1105 #include LTTNG_UST_TRACEPOINT_INCLUDE
1107 #undef LTTNG_UST_TP_EXTERN_C
1110 * Stage 6.1 of tracepoint event generation.
1112 * Tracepoint UML URI info.
1115 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1116 #include <lttng/ust-tracepoint-event-reset.h>
1119 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1120 * with hidden visibility for c++ handling of weakref. We do a weakref
1121 * to the symbol in a later stage, which requires that the symbol is not
1125 #define LTTNG_UST_TP_EXTERN_C extern "C"
1127 #define LTTNG_UST_TP_EXTERN_C
1130 #undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI
1131 #define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1132 LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
1133 __attribute__((visibility("hidden"))) = __uri; \
1135 #include LTTNG_UST_TRACEPOINT_INCLUDE
1137 #undef LTTNG_UST_TP_EXTERN_C
1140 * Stage 7.0 of tracepoint event generation.
1142 * Create events description structures. We use a weakref because
1143 * loglevels are optional. If not declared, the event will point to
1144 * a loglevel that contains NULL.
1146 * C++ requires that const objects have a user-declared default
1147 * constructor. However, in both C++ and C, weakref cannot be
1148 * initialized because it causes the weakref attribute to be ignored.
1149 * Therefore, the loglevel and model_emf_uri pointers are not const
1150 * to ensure C++ compilers default-initialize them.
1153 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1154 #include <lttng/ust-tracepoint-event-reset.h>
1156 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1157 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
1158 static const int * \
1159 __ref_loglevel___##_provider##___##_name \
1160 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1161 static const char * \
1162 __ref_model_emf_uri___##_provider##___##_name \
1163 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1164 static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \
1165 .struct_size = sizeof(struct lttng_ust_event_desc), \
1166 .event_name = #_name, \
1167 .probe_desc = <tng_ust__probe_desc___##_provider, \
1168 .tp_class = <tng_ust__event_class___##_template_provider##___##_template_name, \
1169 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1170 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1173 #include LTTNG_UST_TRACEPOINT_INCLUDE
1176 * Stage 7.1 of tracepoint event generation.
1178 * Create array of events.
1181 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1182 #include <lttng/ust-tracepoint-event-reset.h>
1184 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1185 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
1186 <tng_ust__event_desc___##_provider##_##_name,
1188 static const struct lttng_ust_event_desc
* const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)[] = {
1189 #include LTTNG_UST_TRACEPOINT_INCLUDE
1190 NULL
, /* Dummy, C99 forbids 0-len array. */
1195 * Stage 8 of tracepoint event generation.
1197 * Create a toplevel descriptor for the whole probe.
1200 const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = {
1201 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1202 .provider_name
= lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER
),
1203 .event_desc
= LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
),
1204 .nr_events
= LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)) - 1,
1205 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1206 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1209 static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
, LTTNG_UST_TRACEPOINT_PROVIDER
);
1210 static struct lttng_ust_registered_probe
*LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
);
1213 * Stage 9 of tracepoint event generation.
1215 * Register/unregister probes at module load/unload.
1217 * Generate the constructor as an externally visible symbol for use when
1218 * linking the probe statically.
1220 * Register refcount is protected by libc dynamic loader mutex.
1222 * Note that when building this code as C++, the definition of constructors
1223 * and destructors invoking the registration and unregistration functions
1224 * must be performed _after_ the initialization of the probes.
1226 * This is because we rely on the order of initialization of static variables
1227 * and anonymous namespaces (their order of declaration) to ensure probes are
1228 * fully initialized, see
1229 * https://en.cppreference.com/w/cpp/language/initialization. This is especially
1230 * important when LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP is defined as
1231 * compound literals are then dynamically initialized.
1234 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1235 #include <lttng/ust-tracepoint-event-reset.h>
1238 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void) lttng_ust_notrace
;
1240 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1242 struct lttng_ust_registered_probe
*reg_probe
;
1244 if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
,
1245 LTTNG_UST_TRACEPOINT_PROVIDER
)++) {
1249 * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a
1250 * static inline function that ensures every probe PROVIDER
1251 * argument match the provider within which they appear. It
1252 * calls empty static inline functions, and therefore has no
1253 * runtime effect. However, if it detects an error, a linker
1254 * error will appear.
1256 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, LTTNG_UST_TRACEPOINT_PROVIDER
)();
1257 assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1258 reg_probe
= lttng_ust_probe_register(<TNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1260 fprintf(stderr
, "LTTng-UST: Error while registering tracepoint probe.\n");
1263 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = reg_probe
;
1267 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void) lttng_ust_notrace
;
1269 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1271 if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
,
1272 LTTNG_UST_TRACEPOINT_PROVIDER
)) {
1275 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1276 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = NULL
;
1279 LTTNG_UST_DECLARE_CONSTRUCTOR_DESTRUCTOR(
1280 LTTNG_UST_TRACEPOINT_PROVIDER
,
1281 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
),
1282 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
),
1286 * LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before
1287 * including a tracepoint instrumentation header to hide symbols
1288 * associated with the tracepoint provider. This is useful if the
1289 * tracepoint definition (including the header after defining
1290 * LTTNG_UST_TRACEPOINT_DEFINE) is in the same module as the provider
1291 * (including the header after defining
1292 * LTTNG_UST_TRACEPOINT_CREATE_PROBES).
1294 #undef LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY
1295 #ifdef LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
1296 #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("hidden")))
1298 #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("default")))
1301 int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_
, LTTNG_UST_TRACEPOINT_PROVIDER
)
1302 LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY
;