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
258 #if defined(__cplusplus)
262 * Verifying array and sequence elements are of an integer or pointer
265 * This compile-time check is only enabled in C++, because the C
266 * implementation of lttng_ust_is_pointer_type does not support opaque
270 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
271 #include <lttng/ust-tracepoint-event-reset.h>
272 #include <lttng/ust-tracepoint-event-write.h>
273 #include <lttng/ust-tracepoint-event-nowrite.h>
275 #undef lttng_ust__field_array_encoded
276 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
277 _length, _encoding, _nowrite, \
279 lttng_ust_field_array_element_type_is_supported(_type, _item);
281 #undef lttng_ust__field_sequence_encoded
282 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
283 _length_type, _src_length, _encoding, _nowrite, \
285 lttng_ust_field_array_element_type_is_supported(_type, _item);
287 #undef LTTNG_UST_TP_FIELDS
288 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
290 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
291 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
294 #include LTTNG_UST_TRACEPOINT_INCLUDE
299 * Stage 0.9.2 of tracepoint event generation.
301 * Create probe signature
304 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
305 #include <lttng/ust-tracepoint-event-reset.h>
307 #undef LTTNG_UST_TP_ARGS
308 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
310 #define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__
312 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
313 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
314 static const char __tp_event_signature___##_provider##___##_name[] = \
315 LTTNG_UST__TP_EXTRACT_STRING2(_args);
317 #include LTTNG_UST_TRACEPOINT_INCLUDE
319 #undef LTTNG_UST__TP_EXTRACT_STRING2
322 * Stage 1 of tracepoint event generation.
324 * Create probe callback prototypes.
327 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
328 #include <lttng/ust-tracepoint-event-reset.h>
330 #undef LTTNG_UST_TP_ARGS
331 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
333 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
334 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
335 static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
337 #include LTTNG_UST_TRACEPOINT_INCLUDE
340 * Stage 1.1 of tracepoint event generation.
342 * Declare toplevel descriptor for the whole probe.
343 * Unlike C, C++ does not allow tentative definitions. Therefore, we
344 * need to explicitly declare the variable with "extern", using hidden
345 * visibility to keep this symbol from being exported to the global
349 extern const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)
350 __attribute__((visibility("hidden")));
353 * Stage 2 of tracepoint event generation.
355 * Create event field type metadata section.
356 * Each event produce an array of fields.
359 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
360 #include <lttng/ust-tracepoint-event-reset.h>
361 #include <lttng/ust-tracepoint-event-write.h>
362 #include <lttng/ust-tracepoint-event-nowrite.h>
364 #undef lttng_ust__field_integer_ext
365 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
366 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
367 .struct_size = sizeof(struct lttng_ust_event_field), \
369 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
370 .nowrite = _nowrite, \
374 #undef lttng_ust__field_float
375 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
376 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
377 .struct_size = sizeof(struct lttng_ust_event_field), \
379 .type = lttng_ust_type_float_define(_type), \
380 .nowrite = _nowrite, \
384 #undef lttng_ust__field_array_encoded
385 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
386 _length, _encoding, _nowrite, \
388 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
389 .struct_size = sizeof(struct lttng_ust_event_field), \
391 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
393 .type = lttng_ust_type_array, \
395 .struct_size = sizeof(struct lttng_ust_type_array), \
396 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
399 .encoding = lttng_ust_string_encoding_##_encoding, \
401 .nowrite = _nowrite, \
405 #undef lttng_ust__field_sequence_encoded
406 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
407 _length_type, _src_length, _encoding, _nowrite, \
409 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
410 .struct_size = sizeof(struct lttng_ust_event_field), \
411 .name = "_" #_item "_length", \
412 .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \
413 .nowrite = _nowrite, \
416 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
417 .struct_size = sizeof(struct lttng_ust_event_field), \
419 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \
421 .type = lttng_ust_type_sequence, \
423 .struct_size = sizeof(struct lttng_ust_type_sequence), \
424 .length_name = NULL, /* Use previous field. */ \
425 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
427 .encoding = lttng_ust_string_encoding_##_encoding, \
429 .nowrite = _nowrite, \
433 #undef lttng_ust__field_string
434 #define lttng_ust__field_string(_item, _src, _nowrite) \
435 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
436 .struct_size = sizeof(struct lttng_ust_event_field), \
438 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \
440 .type = lttng_ust_type_string, \
442 .struct_size = sizeof(struct lttng_ust_type_string), \
443 .encoding = lttng_ust_string_encoding_UTF8, \
445 .nowrite = _nowrite, \
449 #undef lttng_ust__field_unused
450 #define lttng_ust__field_unused(_src)
452 #undef lttng_ust__field_enum
453 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
454 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
455 .struct_size = sizeof(struct lttng_ust_event_field), \
457 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \
459 .type = lttng_ust_type_enum, \
461 .struct_size = sizeof(struct lttng_ust_type_enum), \
462 .desc = &__enum_##_provider##_##_name, \
463 .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \
465 .nowrite = _nowrite, \
469 #undef LTTNG_UST_TP_FIELDS
470 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
472 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
473 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
474 static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \
476 lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
478 static const struct lttng_ust_tracepoint_class lttng_ust__event_class___##_provider##___##_name = { \
479 .struct_size = sizeof(struct lttng_ust_tracepoint_class), \
480 .fields = lttng_ust__event_fields___##_provider##___##_name, \
481 .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1, \
482 .probe_callback = (void (*)(void)) <tng_ust__event_probe__##_provider##___##_name, \
483 .signature = __tp_event_signature___##_provider##___##_name, \
484 .probe_desc = <tng_ust__probe_desc___##_provider, \
487 #undef LTTNG_UST_TRACEPOINT_ENUM
488 #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
489 static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
490 .struct_size = sizeof(struct lttng_ust_enum_desc), \
491 .name = #_provider "_" #_name, \
492 .entries = __enum_values__##_provider##_##_name, \
493 .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
494 .probe_desc = <tng_ust__probe_desc___##_provider, \
497 #include LTTNG_UST_TRACEPOINT_INCLUDE
500 * Stage 3.0 of tracepoint event generation.
502 * Create static inline function that calculates event size.
505 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
506 #include <lttng/ust-tracepoint-event-reset.h>
507 #include <lttng/ust-tracepoint-event-write.h>
509 #undef lttng_ust__field_integer_ext
510 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
512 (void) (_src); /* Unused */ \
513 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
514 __event_len += sizeof(_type);
516 #undef lttng_ust__field_float
517 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
519 (void) (_src); /* Unused */ \
520 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
521 __event_len += sizeof(_type);
523 #undef lttng_ust__field_array_encoded
524 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
525 _nowrite, _elem_type_base) \
527 (void) (_src); /* Unused */ \
528 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
529 __event_len += sizeof(_type) * (_length);
531 #undef lttng_ust__field_sequence_encoded
532 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
533 _src_length, _encoding, _nowrite, _elem_type_base) \
535 (void) (_src); /* Unused */ \
536 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
537 __event_len += sizeof(_length_type); \
538 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
539 __dynamic_len[__dynamic_len_idx] = (_src_length); \
540 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
543 #undef lttng_ust__field_string
544 #define lttng_ust__field_string(_item, _src, _nowrite) \
545 __event_len += __dynamic_len[__dynamic_len_idx++] = \
546 strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1;
548 #undef lttng_ust__field_unused
549 #define lttng_ust__field_unused(_src) \
551 (void) (_src); /* Unused */
553 #undef lttng_ust__field_enum
554 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
555 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
557 #undef LTTNG_UST_TP_ARGS
558 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
560 #undef LTTNG_UST_TP_FIELDS
561 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
563 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
564 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
566 size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
569 size_t lttng_ust__event_get_size__##_provider##___##_name( \
570 size_t *__dynamic_len __attribute__((__unused__)), \
571 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
573 size_t __event_len = 0; \
574 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
577 (void) __tp_data; /* don't warn if unused */ \
580 return __event_len; \
583 #include LTTNG_UST_TRACEPOINT_INCLUDE
586 * Stage 3.1 of tracepoint event generation.
588 * Create static inline function that layout the filter stack data.
589 * We make both write and nowrite data available to the filter.
592 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
593 #include <lttng/ust-tracepoint-event-reset.h>
594 #include <lttng/ust-tracepoint-event-write.h>
595 #include <lttng/ust-tracepoint-event-nowrite.h>
597 #undef lttng_ust__field_integer_ext
598 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
599 if (lttng_ust_is_signed_type(_type)) { \
600 int64_t __ctf_tmp_int64; \
601 switch (sizeof(_type)) { \
604 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
605 __ctf_tmp_int64 = (int64_t) __tmp.v; \
610 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
611 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
612 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
613 __ctf_tmp_int64 = (int64_t) __tmp.v; \
618 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
619 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
620 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
621 __ctf_tmp_int64 = (int64_t) __tmp.v; \
626 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
627 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
628 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
629 __ctf_tmp_int64 = (int64_t) __tmp.v; \
635 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
637 uint64_t __ctf_tmp_uint64; \
638 switch (sizeof(_type)) { \
641 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
642 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
647 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
648 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
649 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
650 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
655 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
656 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
657 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
658 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
663 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
664 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
665 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
666 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
672 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
674 __stack_data += sizeof(int64_t);
676 #undef lttng_ust__field_float
677 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
679 double __ctf_tmp_double = (double) (_type) (_src); \
680 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
681 __stack_data += sizeof(double); \
684 #undef lttng_ust__field_array_encoded
685 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
686 _encoding, _nowrite, _elem_type_base) \
688 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
689 const void *__ctf_tmp_ptr = (_src); \
690 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
691 __stack_data += sizeof(unsigned long); \
692 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
693 __stack_data += sizeof(void *); \
696 #undef lttng_ust__field_sequence_encoded
697 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
698 _src_length, _encoding, _nowrite, _elem_type_base) \
700 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
701 const void *__ctf_tmp_ptr = (_src); \
702 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
703 __stack_data += sizeof(unsigned long); \
704 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
705 __stack_data += sizeof(void *); \
708 #undef lttng_ust__field_string
709 #define lttng_ust__field_string(_item, _src, _nowrite) \
711 const void *__ctf_tmp_ptr = \
712 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
713 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
714 __stack_data += sizeof(void *); \
717 #undef lttng_ust__field_unused
718 #define lttng_ust__field_unused(_src) \
722 #undef lttng_ust__field_enum
723 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
724 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
726 #undef LTTNG_UST_TP_ARGS
727 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
729 #undef LTTNG_UST_TP_FIELDS
730 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
732 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
733 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
735 void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
736 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
739 (void) __tp_data; /* don't warn if unused */ \
740 (void) __stack_data; /* don't warn if unused */ \
746 #include LTTNG_UST_TRACEPOINT_INCLUDE
749 * Stage 4 of tracepoint event generation.
751 * Create static inline function that calculates event payload alignment.
754 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
755 #include <lttng/ust-tracepoint-event-reset.h>
756 #include <lttng/ust-tracepoint-event-write.h>
758 #undef lttng_ust__field_integer_ext
759 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
761 (void) (_src); /* Unused */ \
762 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
764 #undef lttng_ust__field_float
765 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
767 (void) (_src); /* Unused */ \
768 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
770 #undef lttng_ust__field_array_encoded
771 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
772 _encoding, _nowrite, _elem_type_base) \
774 (void) (_src); /* Unused */ \
775 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
777 #undef lttng_ust__field_sequence_encoded
778 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
779 _src_length, _encoding, _nowrite, _elem_type_base) \
781 (void) (_src); /* Unused */ \
783 (void) (_src_length); /* Unused */ \
784 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \
785 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
787 #undef lttng_ust__field_string
788 #define lttng_ust__field_string(_item, _src, _nowrite) \
790 (void) (_src); /* Unused */
792 #undef lttng_ust__field_unused
793 #define lttng_ust__field_unused(_src) \
795 (void) (_src); /* Unused */
797 #undef lttng_ust__field_enum
798 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
799 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
801 #undef LTTNG_UST_TP_ARGS
802 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
804 #undef LTTNG_UST_TP_FIELDS
805 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
807 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
808 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
810 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
813 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
815 size_t __event_align = 1; \
817 return __event_align; \
820 #include LTTNG_UST_TRACEPOINT_INCLUDE
824 * Stage 5 of tracepoint event generation.
826 * Create the probe function. This function calls event size calculation
827 * and writes event data into the buffer.
830 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
831 #include <lttng/ust-tracepoint-event-reset.h>
832 #include <lttng/ust-tracepoint-event-write.h>
834 #undef lttng_ust__field_integer_ext
835 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
837 _type __tmp = (_src); \
838 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
841 #undef lttng_ust__field_float
842 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
844 _type __tmp = (_src); \
845 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
848 #undef lttng_ust__field_array_encoded
849 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
850 _encoding, _nowrite, _elem_type_base) \
851 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
852 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
854 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length);
856 #undef lttng_ust__field_sequence_encoded
857 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
858 _src_length, _encoding, _nowrite, _elem_type_base) \
860 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
861 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
863 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
864 __chan->ops->event_write(&__ctx, _src, \
865 sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
867 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \
869 #undef lttng_ust__field_string
870 #define lttng_ust__field_string(_item, _src, _nowrite) \
872 const char *__ctf_tmp_string = \
873 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
874 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
875 lttng_ust__get_dynamic_len(dest)); \
878 #undef lttng_ust__field_unused
879 #define lttng_ust__field_unused(_src)
881 #undef lttng_ust__field_enum
882 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
883 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
885 /* Beware: this get len actually consumes the len value */
886 #undef lttng_ust__get_dynamic_len
887 #define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
889 #undef LTTNG_UST_TP_ARGS
890 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
892 #undef LTTNG_UST_TP_FIELDS
893 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
896 * For state dump, check that "session" argument (mandatory) matches the
897 * session this event belongs to. Ensures that we write state dump data only
898 * into the started session, not into all sessions.
900 #undef LTTNG_UST__TP_SESSION_CHECK
901 #ifdef LTTNG_UST_TP_SESSION_CHECK
902 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession)
903 #else /* TP_SESSION_CHECK */
904 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1
905 #endif /* TP_SESSION_CHECK */
908 * Use of __builtin_return_address(0) sometimes seems to cause stack
909 * corruption on 32-bit PowerPC. Disable this feature on that
910 * architecture for now by always using the NULL value for the ip
913 #undef LTTNG_UST__TP_IP_PARAM
915 #ifdef LTTNG_UST_TP_IP_PARAM
916 #define LTTNG_UST__TP_IP_PARAM(x) (x)
917 #else /* TP_IP_PARAM */
919 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
920 #define LTTNG_UST__TP_IP_PARAM(x) NULL
922 #define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0)
925 #endif /* TP_IP_PARAM */
928 * Using twice size for filter stack data to hold size and pointer for
929 * each field (worse case). For integers, max size required is 64-bit.
930 * Same for double-precision floats. Those fit within
931 * 2*sizeof(unsigned long) for all supported architectures.
932 * Perform UNION (||) of filter runtime list.
934 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
935 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
937 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
940 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
942 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
943 size_t __dynamic_len_idx = 0; \
944 const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \
945 struct lttng_ust_probe_ctx __probe_ctx; \
947 size_t __dynamic_len[__num_fields]; \
948 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
951 bool __interpreter_stack_prepared = false; \
954 (void) __dynamic_len_idx; /* don't warn if unused */ \
955 switch (__event->type) { \
956 case LTTNG_UST_EVENT_TYPE_RECORDER: \
958 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
959 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
960 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
962 if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \
964 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
966 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
970 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
973 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
975 if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
977 __probe_ctx.struct_size = sizeof(struct lttng_ust_probe_ctx); \
978 __probe_ctx.ip = LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM); \
979 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
980 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
981 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
982 __interpreter_stack_prepared = true; \
983 if (caa_likely(__event->run_filter(__event, \
984 __stackvar.__interpreter_stack_data, &__probe_ctx, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
987 switch (__event->type) { \
988 case LTTNG_UST_EVENT_TYPE_RECORDER: \
990 size_t __event_len, __event_align; \
991 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
992 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
993 struct lttng_ust_ring_buffer_ctx __ctx; \
995 __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
996 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
997 __event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
998 lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
1000 __ret = __chan->ops->event_reserve(&__ctx); \
1004 __chan->ops->event_commit(&__ctx); \
1007 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
1009 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
1010 struct lttng_ust_notification_ctx __notif_ctx; \
1012 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
1013 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
1015 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
1016 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
1017 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
1019 __event_notifier->notification_send(__event_notifier, \
1020 __stackvar.__interpreter_stack_data, \
1028 #include LTTNG_UST_TRACEPOINT_INCLUDE
1030 #undef lttng_ust__get_dynamic_len
1033 * Stage 6 of tracepoint event generation.
1035 * Tracepoint loglevel mapping definition generation. We generate a
1036 * symbol for each mapping for a provider/event to ensure at most a 1 to
1037 * 1 mapping between events and loglevels. If the symbol is repeated,
1038 * the compiler will complain.
1041 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1042 #include <lttng/ust-tracepoint-event-reset.h>
1045 * Declare _loglevel___##__provider##___##__name as non-static, with
1046 * hidden visibility for c++ handling of weakref. We do a weakref to the
1047 * symbol in a later stage, which requires that the symbol is not
1051 #define LTTNG_UST_TP_EXTERN_C extern "C"
1053 #define LTTNG_UST_TP_EXTERN_C
1056 #undef LTTNG_UST_TRACEPOINT_LOGLEVEL
1057 #define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
1058 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
1059 LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
1060 __attribute__((visibility("hidden"))) = \
1061 &_loglevel_value___##__provider##___##__name;
1063 #include LTTNG_UST_TRACEPOINT_INCLUDE
1065 #undef LTTNG_UST_TP_EXTERN_C
1068 * Stage 6.1 of tracepoint event generation.
1070 * Tracepoint UML URI info.
1073 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1074 #include <lttng/ust-tracepoint-event-reset.h>
1077 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1078 * with hidden visibility for c++ handling of weakref. We do a weakref
1079 * to the symbol in a later stage, which requires that the symbol is not
1083 #define LTTNG_UST_TP_EXTERN_C extern "C"
1085 #define LTTNG_UST_TP_EXTERN_C
1088 #undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI
1089 #define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1090 LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
1091 __attribute__((visibility("hidden"))) = __uri; \
1093 #include LTTNG_UST_TRACEPOINT_INCLUDE
1095 #undef LTTNG_UST_TP_EXTERN_C
1098 * Stage 7.0 of tracepoint event generation.
1100 * Create events description structures. We use a weakref because
1101 * loglevels are optional. If not declared, the event will point to
1102 * a loglevel that contains NULL.
1104 * C++ requires that const objects have a user-declared default
1105 * constructor. However, in both C++ and C, weakref cannot be
1106 * initialized because it causes the weakref attribute to be ignored.
1107 * Therefore, the loglevel and model_emf_uri pointers are not const
1108 * to ensure C++ compilers default-initialize them.
1111 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1112 #include <lttng/ust-tracepoint-event-reset.h>
1114 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1115 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
1116 static const int * \
1117 __ref_loglevel___##_provider##___##_name \
1118 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1119 static const char * \
1120 __ref_model_emf_uri___##_provider##___##_name \
1121 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1122 static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \
1123 .struct_size = sizeof(struct lttng_ust_event_desc), \
1124 .event_name = #_name, \
1125 .probe_desc = <tng_ust__probe_desc___##_provider, \
1126 .tp_class = <tng_ust__event_class___##_template_provider##___##_template_name, \
1127 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1128 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1131 #include LTTNG_UST_TRACEPOINT_INCLUDE
1134 * Stage 7.1 of tracepoint event generation.
1136 * Create array of events.
1139 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1140 #include <lttng/ust-tracepoint-event-reset.h>
1142 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1143 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
1144 <tng_ust__event_desc___##_provider##_##_name,
1146 static const struct lttng_ust_event_desc
* const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)[] = {
1147 #include LTTNG_UST_TRACEPOINT_INCLUDE
1148 NULL
, /* Dummy, C99 forbids 0-len array. */
1153 * Stage 8 of tracepoint event generation.
1155 * Create a toplevel descriptor for the whole probe.
1158 const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = {
1159 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1160 .provider_name
= lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER
),
1161 .event_desc
= LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
),
1162 .nr_events
= LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)) - 1,
1163 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1164 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1167 static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
, LTTNG_UST_TRACEPOINT_PROVIDER
);
1168 static struct lttng_ust_registered_probe
*LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
);
1171 * Stage 9 of tracepoint event generation.
1173 * Register/unregister probes at module load/unload.
1175 * Generate the constructor as an externally visible symbol for use when
1176 * linking the probe statically.
1178 * Register refcount is protected by libc dynamic loader mutex.
1180 * Note that when building this code as C++, the definition of constructors
1181 * and destructors invoking the registration and unregistration functions
1182 * must be performed _after_ the initialization of the probes.
1184 * This is because we rely on the order of initialization of static variables
1185 * and anonymous namespaces (their order of declaration) to ensure probes are
1186 * fully initialized, see
1187 * https://en.cppreference.com/w/cpp/language/initialization. This is especially
1188 * important when LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP is defined as
1189 * compound literals are then dynamically initialized.
1192 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1193 #include <lttng/ust-tracepoint-event-reset.h>
1196 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void) lttng_ust_notrace
;
1198 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1200 struct lttng_ust_registered_probe
*reg_probe
;
1202 if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
,
1203 LTTNG_UST_TRACEPOINT_PROVIDER
)++) {
1207 * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a
1208 * static inline function that ensures every probe PROVIDER
1209 * argument match the provider within which they appear. It
1210 * calls empty static inline functions, and therefore has no
1211 * runtime effect. However, if it detects an error, a linker
1212 * error will appear.
1214 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, LTTNG_UST_TRACEPOINT_PROVIDER
)();
1215 assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1216 reg_probe
= lttng_ust_probe_register(<TNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1218 fprintf(stderr
, "LTTng-UST: Error while registering tracepoint probe.\n");
1221 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = reg_probe
;
1225 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void) lttng_ust_notrace
;
1227 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1229 if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
,
1230 LTTNG_UST_TRACEPOINT_PROVIDER
)) {
1233 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1234 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = NULL
;
1237 LTTNG_UST_DECLARE_CONSTRUCTOR_DESTRUCTOR(
1238 LTTNG_UST_TRACEPOINT_PROVIDER
,
1239 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
),
1240 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
),
1244 * LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before
1245 * including a tracepoint instrumentation header to hide symbols
1246 * associated with the tracepoint provider. This is useful if the
1247 * tracepoint definition (including the header after defining
1248 * LTTNG_UST_TRACEPOINT_DEFINE) is in the same module as the provider
1249 * (including the header after defining
1250 * LTTNG_UST_TRACEPOINT_CREATE_PROBES).
1252 #undef LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY
1253 #ifdef LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
1254 #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("hidden")))
1256 #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("default")))
1259 int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_
, LTTNG_UST_TRACEPOINT_PROVIDER
)
1260 LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY
;