2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <urcu/compiler.h>
11 #include <urcu/rculist.h>
12 #include <lttng/ust-events.h>
13 #include <lttng/ust-ringbuffer-context.h>
14 #include <lttng/ust-arch.h>
15 #include <lttng/ust-compiler.h>
16 #include <lttng/tracepoint.h>
17 #include <lttng/ust-endian.h>
18 #include <lttng/ust-api-compat.h>
20 #include <lttng/ust-api-compat.h>
22 #if LTTNG_UST_COMPAT_API(0)
23 #define TP_FIELDS LTTNG_UST_TP_FIELDS
25 #define ctf_integer lttng_ust_field_integer
26 #define ctf_integer_hex lttng_ust_field_integer_hex
27 #define ctf_integer_network lttng_ust_field_integer_network
28 #define ctf_integer_network_hex lttng_ust_field_integer_network_hex
29 #define ctf_integer_nowrite lttng_ust_field_integer_nowrite
31 #define ctf_float lttng_ust_field_float
32 #define ctf_float_nowrite lttng_ust_field_float_nowrite
34 #define ctf_array lttng_ust_field_array
35 #define ctf_array_hex lttng_ust_field_array_hex
36 #define ctf_array_network lttng_ust_field_array_network
37 #define ctf_array_network_hex lttng_ust_field_array_network_hex
38 #define ctf_array_text lttng_ust_field_array_text
39 #define ctf_array_nowrite lttng_ust_field_array_nowrite
40 #define ctf_array_nowrite_hex lttng_ust_field_array_nowrite_hex
41 #define ctf_array_network_nowrite lttng_ust_field_array_network_nowrite
42 #define ctf_array_network_nowrite_hex lttng_ust_field_array_network_nowrite_hex
43 #define ctf_array_text_nowrite lttng_ust_field_array_text_nowrite
45 #define ctf_sequence lttng_ust_field_sequence
46 #define ctf_sequence_hex lttng_ust_field_sequence_hex
47 #define ctf_sequence_network lttng_ust_field_sequence_network
48 #define ctf_sequence_network_hex lttng_ust_field_sequence_network_hex
49 #define ctf_sequence_text lttng_ust_field_sequence_text
50 #define ctf_sequence_nowrite lttng_ust_field_sequence_nowrite
51 #define ctf_sequence_nowrite_hex lttng_ust_field_sequence_nowrite_hex
52 #define ctf_sequence_network_nowrite lttng_ust_field_sequence_network_nowrite
53 #define ctf_sequence_network_nowrite_hex lttng_ust_field_sequence_network_nowrite_hex
54 #define ctf_sequence_text_nowrite lttng_ust_field_sequence_text_nowrite
56 #define ctf_string lttng_ust_field_string
57 #define ctf_string_nowrite lttng_ust_field_string_nowrite
59 #define ctf_unused lttng_ust_field_unused
60 #define ctf_unused_nowrite lttng_ust_field_unused_nowrite
62 #define ctf_enum lttng_ust_field_enum
63 #define ctf_enum_nowrite lttng_ust_field_enum_nowrite
64 #define ctf_enum_value lttng_ust_field_enum_value
65 #define ctf_enum_range lttng_ust_field_enum_range
66 #define ctf_enum_auto lttng_ust_field_enum_auto
67 #endif /* #if LTTNG_UST_COMPAT_API(0) */
69 #define LTTNG_UST__NULL_STRING "(null)"
72 * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
73 * same arguments and having the same field layout.
75 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
76 * its own provider and name. It refers to a class (template).
78 * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a
79 * direct mapping from the instance to the class.
82 #undef LTTNG_UST_TRACEPOINT_EVENT
83 #define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
84 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \
85 LTTNG_UST__TP_PARAMS(_args), \
86 LTTNG_UST__TP_PARAMS(_fields)) \
87 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _provider, _name, \
88 LTTNG_UST__TP_PARAMS(_args))
90 #undef LTTNG_UST_TRACEPOINT_EVENT_CLASS
91 #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
92 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields))
94 #undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
95 #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
96 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, LTTNG_UST__TP_PARAMS(_args))
99 #define LTTNG_UST__TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
101 #define lttng_ust__tp_max_t(type, x, y) \
103 type lttng_ust__max1 = (x); \
104 type lttng_ust__max2 = (y); \
105 lttng_ust__max1 > lttng_ust__max2 ? lttng_ust__max1: lttng_ust__max2; \
109 * Stage 0 of tracepoint event generation.
111 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider argument match the
112 * LTTNG_UST_TRACEPOINT_PROVIDER by creating dummy callbacks.
115 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
116 #include <lttng/ust-tracepoint-event-reset.h>
119 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
122 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
126 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
127 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
128 lttng_ust_tracepoint_provider_mismatch_##_provider();
130 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
131 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
132 lttng_ust_tracepoint_provider_mismatch_##_provider();
135 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
138 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
140 #include LTTNG_UST_TRACEPOINT_INCLUDE
144 * Stage 0.1 of tracepoint event generation.
146 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the
147 * tracepoint name length limit.
150 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
151 #include <lttng/ust-tracepoint-event-reset.h>
153 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
154 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
155 lttng_ust_tracepoint_validate_name_len(_provider, _name);
157 #include LTTNG_UST_TRACEPOINT_INCLUDE
160 * Stage 0.2 of tracepoint event generation.
162 * Create dummy trace prototypes for each event class, and for each used
163 * template. This will allow checking whether the prototypes from the
164 * class and the instance using the class actually match.
167 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
168 #include <lttng/ust-tracepoint-event-reset.h>
170 #undef LTTNG_UST_TP_ARGS
171 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
173 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
174 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
175 void lttng_ust__event_template_proto___##_template_provider##___##_template_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
177 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
178 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
179 void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
181 #include LTTNG_UST_TRACEPOINT_INCLUDE
184 * Stage 0.9 of tracepoint event generation
186 * Unfolding the enums
188 #include <lttng/ust-tracepoint-event-reset.h>
190 /* Enumeration entry (single value) */
191 #undef lttng_ust_field_enum_value
192 #define lttng_ust_field_enum_value(_string, _value) \
193 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
194 .struct_size = sizeof(struct lttng_ust_enum_entry), \
196 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
197 (long long) (_value) : (_value), \
198 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
201 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
202 (long long) (_value) : (_value), \
203 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
205 .string = (_string), \
208 /* Enumeration entry (range) */
209 #undef lttng_ust_field_enum_range
210 #define lttng_ust_field_enum_range(_string, _range_start, _range_end) \
211 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
212 .struct_size = sizeof(struct lttng_ust_enum_entry), \
214 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
215 (long long) (_range_start) : (_range_start), \
216 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
219 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
220 (long long) (_range_end) : (_range_end), \
221 .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \
223 .string = (_string), \
226 /* Enumeration entry (automatic value; follows the rules of CTF) */
227 #undef lttng_ust_field_enum_auto
228 #define lttng_ust_field_enum_auto(_string) \
229 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
230 .struct_size = sizeof(struct lttng_ust_enum_entry), \
239 .string = (_string), \
240 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
243 #undef LTTNG_UST_TP_ENUM_VALUES
244 #define LTTNG_UST_TP_ENUM_VALUES(...) \
247 #if LTTNG_UST_COMPAT_API(0)
248 # undef TP_ENUM_VALUES
249 # define TP_ENUM_VALUES LTTNG_UST_TP_ENUM_VALUES
250 #endif /* #if LTTNG_UST_COMPAT_API(0) */
252 #undef LTTNG_UST_TRACEPOINT_ENUM
253 #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
254 const struct lttng_ust_enum_entry * const __enum_values__##_provider##_##_name[] = { \
256 lttng_ust_field_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
258 #include LTTNG_UST_TRACEPOINT_INCLUDE
262 * Verifying array and sequence elements are of an integer type.
265 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
266 #include <lttng/ust-tracepoint-event-reset.h>
267 #include <lttng/ust-tracepoint-event-write.h>
268 #include <lttng/ust-tracepoint-event-nowrite.h>
270 #undef lttng_ust__field_array_encoded
271 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
272 _length, _encoding, _nowrite, \
274 lttng_ust_field_array_element_type_is_supported(_type, _item);
276 #undef lttng_ust__field_sequence_encoded
277 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
278 _length_type, _src_length, _encoding, _nowrite, \
280 lttng_ust_field_array_element_type_is_supported(_type, _item);
282 #undef LTTNG_UST_TP_FIELDS
283 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
285 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
286 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
289 #include LTTNG_UST_TRACEPOINT_INCLUDE
292 * Stage 0.9.2 of tracepoint event generation.
294 * Create probe signature
297 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
298 #include <lttng/ust-tracepoint-event-reset.h>
300 #undef LTTNG_UST_TP_ARGS
301 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
303 #define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__
305 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
306 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
307 static const char __tp_event_signature___##_provider##___##_name[] = \
308 LTTNG_UST__TP_EXTRACT_STRING2(_args);
310 #include LTTNG_UST_TRACEPOINT_INCLUDE
312 #undef LTTNG_UST__TP_EXTRACT_STRING2
315 * Stage 1 of tracepoint event generation.
317 * Create probe callback prototypes.
320 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
321 #include <lttng/ust-tracepoint-event-reset.h>
323 #undef LTTNG_UST_TP_ARGS
324 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
326 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
327 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
328 static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
330 #include LTTNG_UST_TRACEPOINT_INCLUDE
333 * Stage 1.1 of tracepoint event generation.
335 * Declare toplevel descriptor for the whole probe.
336 * Unlike C, C++ does not allow tentative definitions. Therefore, we
337 * need to explicitly declare the variable with "extern", using hidden
338 * visibility to keep this symbol from being exported to the global
342 extern const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)
343 __attribute__((visibility("hidden")));
346 * Stage 2 of tracepoint event generation.
348 * Create event field type metadata section.
349 * Each event produce an array of fields.
352 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
353 #include <lttng/ust-tracepoint-event-reset.h>
354 #include <lttng/ust-tracepoint-event-write.h>
355 #include <lttng/ust-tracepoint-event-nowrite.h>
357 #undef lttng_ust__field_integer_ext
358 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
359 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
360 .struct_size = sizeof(struct lttng_ust_event_field), \
362 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
363 .nowrite = _nowrite, \
367 #undef lttng_ust__field_float
368 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
369 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
370 .struct_size = sizeof(struct lttng_ust_event_field), \
372 .type = lttng_ust_type_float_define(_type), \
373 .nowrite = _nowrite, \
377 #undef lttng_ust__field_array_encoded
378 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
379 _length, _encoding, _nowrite, \
381 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
382 .struct_size = sizeof(struct lttng_ust_event_field), \
384 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
386 .type = lttng_ust_type_array, \
388 .struct_size = sizeof(struct lttng_ust_type_array), \
389 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
392 .encoding = lttng_ust_string_encoding_##_encoding, \
394 .nowrite = _nowrite, \
398 #undef lttng_ust__field_sequence_encoded
399 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
400 _length_type, _src_length, _encoding, _nowrite, \
402 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
403 .struct_size = sizeof(struct lttng_ust_event_field), \
404 .name = "_" #_item "_length", \
405 .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \
406 .nowrite = _nowrite, \
409 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
410 .struct_size = sizeof(struct lttng_ust_event_field), \
412 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \
414 .type = lttng_ust_type_sequence, \
416 .struct_size = sizeof(struct lttng_ust_type_sequence), \
417 .length_name = NULL, /* Use previous field. */ \
418 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
420 .encoding = lttng_ust_string_encoding_##_encoding, \
422 .nowrite = _nowrite, \
426 #undef lttng_ust__field_string
427 #define lttng_ust__field_string(_item, _src, _nowrite) \
428 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
429 .struct_size = sizeof(struct lttng_ust_event_field), \
431 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \
433 .type = lttng_ust_type_string, \
435 .struct_size = sizeof(struct lttng_ust_type_string), \
436 .encoding = lttng_ust_string_encoding_UTF8, \
438 .nowrite = _nowrite, \
442 #undef lttng_ust__field_unused
443 #define lttng_ust__field_unused(_src)
445 #undef lttng_ust__field_enum
446 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
447 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
448 .struct_size = sizeof(struct lttng_ust_event_field), \
450 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \
452 .type = lttng_ust_type_enum, \
454 .struct_size = sizeof(struct lttng_ust_type_enum), \
455 .desc = &__enum_##_provider##_##_name, \
456 .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \
458 .nowrite = _nowrite, \
462 #undef LTTNG_UST_TP_FIELDS
463 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
465 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
466 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
467 static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \
469 lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
471 static const struct lttng_ust_tracepoint_class lttng_ust__event_class___##_provider##___##_name = { \
472 .struct_size = sizeof(struct lttng_ust_tracepoint_class), \
473 .fields = lttng_ust__event_fields___##_provider##___##_name, \
474 .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1, \
475 .probe_callback = (void (*)(void)) <tng_ust__event_probe__##_provider##___##_name, \
476 .signature = __tp_event_signature___##_provider##___##_name, \
477 .probe_desc = <tng_ust__probe_desc___##_provider, \
480 #undef LTTNG_UST_TRACEPOINT_ENUM
481 #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
482 static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
483 .struct_size = sizeof(struct lttng_ust_enum_desc), \
484 .name = #_provider "_" #_name, \
485 .entries = __enum_values__##_provider##_##_name, \
486 .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
487 .probe_desc = <tng_ust__probe_desc___##_provider, \
490 #include LTTNG_UST_TRACEPOINT_INCLUDE
493 * Stage 3.0 of tracepoint event generation.
495 * Create static inline function that calculates event size.
498 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
499 #include <lttng/ust-tracepoint-event-reset.h>
500 #include <lttng/ust-tracepoint-event-write.h>
502 #undef lttng_ust__field_integer_ext
503 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
505 (void) (_src); /* Unused */ \
506 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
507 __event_len += sizeof(_type);
509 #undef lttng_ust__field_float
510 #define lttng_ust__field_float(_type, _item, _src, _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_array_encoded
517 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
518 _nowrite, _elem_type_base) \
520 (void) (_src); /* Unused */ \
521 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
522 __event_len += sizeof(_type) * (_length);
524 #undef lttng_ust__field_sequence_encoded
525 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
526 _src_length, _encoding, _nowrite, _elem_type_base) \
528 (void) (_src); /* Unused */ \
529 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
530 __event_len += sizeof(_length_type); \
531 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
532 __dynamic_len[__dynamic_len_idx] = (_src_length); \
533 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
536 #undef lttng_ust__field_string
537 #define lttng_ust__field_string(_item, _src, _nowrite) \
538 __event_len += __dynamic_len[__dynamic_len_idx++] = \
539 strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1;
541 #undef lttng_ust__field_unused
542 #define lttng_ust__field_unused(_src) \
544 (void) (_src); /* Unused */
546 #undef lttng_ust__field_enum
547 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
548 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
550 #undef LTTNG_UST_TP_ARGS
551 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
553 #undef LTTNG_UST_TP_FIELDS
554 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
556 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
557 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
559 size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
562 size_t lttng_ust__event_get_size__##_provider##___##_name( \
563 size_t *__dynamic_len __attribute__((__unused__)), \
564 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
566 size_t __event_len = 0; \
567 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
570 (void) __tp_data; /* don't warn if unused */ \
573 return __event_len; \
576 #include LTTNG_UST_TRACEPOINT_INCLUDE
579 * Stage 3.1 of tracepoint event generation.
581 * Create static inline function that layout the filter stack data.
582 * We make both write and nowrite data available to the filter.
585 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
586 #include <lttng/ust-tracepoint-event-reset.h>
587 #include <lttng/ust-tracepoint-event-write.h>
588 #include <lttng/ust-tracepoint-event-nowrite.h>
590 #undef lttng_ust__field_integer_ext
591 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
592 if (lttng_ust_is_signed_type(_type)) { \
593 int64_t __ctf_tmp_int64; \
594 switch (sizeof(_type)) { \
597 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
598 __ctf_tmp_int64 = (int64_t) __tmp.v; \
603 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
604 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
605 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
606 __ctf_tmp_int64 = (int64_t) __tmp.v; \
611 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
612 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
613 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
614 __ctf_tmp_int64 = (int64_t) __tmp.v; \
619 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
620 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
621 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
622 __ctf_tmp_int64 = (int64_t) __tmp.v; \
628 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
630 uint64_t __ctf_tmp_uint64; \
631 switch (sizeof(_type)) { \
634 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
635 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
640 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
641 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
642 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
643 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
648 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
649 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
650 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
651 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
656 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
657 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
658 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
659 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
665 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
667 __stack_data += sizeof(int64_t);
669 #undef lttng_ust__field_float
670 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
672 double __ctf_tmp_double = (double) (_type) (_src); \
673 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
674 __stack_data += sizeof(double); \
677 #undef lttng_ust__field_array_encoded
678 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
679 _encoding, _nowrite, _elem_type_base) \
681 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
682 const void *__ctf_tmp_ptr = (_src); \
683 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
684 __stack_data += sizeof(unsigned long); \
685 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
686 __stack_data += sizeof(void *); \
689 #undef lttng_ust__field_sequence_encoded
690 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
691 _src_length, _encoding, _nowrite, _elem_type_base) \
693 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
694 const void *__ctf_tmp_ptr = (_src); \
695 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
696 __stack_data += sizeof(unsigned long); \
697 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
698 __stack_data += sizeof(void *); \
701 #undef lttng_ust__field_string
702 #define lttng_ust__field_string(_item, _src, _nowrite) \
704 const void *__ctf_tmp_ptr = \
705 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
706 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
707 __stack_data += sizeof(void *); \
710 #undef lttng_ust__field_unused
711 #define lttng_ust__field_unused(_src) \
715 #undef lttng_ust__field_enum
716 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
717 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
719 #undef LTTNG_UST_TP_ARGS
720 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
722 #undef LTTNG_UST_TP_FIELDS
723 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
725 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
726 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
728 void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
729 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
732 (void) __tp_data; /* don't warn if unused */ \
733 (void) __stack_data; /* don't warn if unused */ \
739 #include LTTNG_UST_TRACEPOINT_INCLUDE
742 * Stage 4 of tracepoint event generation.
744 * Create static inline function that calculates event payload alignment.
747 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
748 #include <lttng/ust-tracepoint-event-reset.h>
749 #include <lttng/ust-tracepoint-event-write.h>
751 #undef lttng_ust__field_integer_ext
752 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
754 (void) (_src); /* Unused */ \
755 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
757 #undef lttng_ust__field_float
758 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
760 (void) (_src); /* Unused */ \
761 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
763 #undef lttng_ust__field_array_encoded
764 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
765 _encoding, _nowrite, _elem_type_base) \
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_sequence_encoded
771 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
772 _src_length, _encoding, _nowrite, _elem_type_base) \
774 (void) (_src); /* Unused */ \
776 (void) (_src_length); /* Unused */ \
777 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \
778 __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
780 #undef lttng_ust__field_string
781 #define lttng_ust__field_string(_item, _src, _nowrite) \
783 (void) (_src); /* Unused */
785 #undef lttng_ust__field_unused
786 #define lttng_ust__field_unused(_src) \
788 (void) (_src); /* Unused */
790 #undef lttng_ust__field_enum
791 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
792 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
794 #undef LTTNG_UST_TP_ARGS
795 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
797 #undef LTTNG_UST_TP_FIELDS
798 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
800 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
801 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
803 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
806 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
808 size_t __event_align = 1; \
810 return __event_align; \
813 #include LTTNG_UST_TRACEPOINT_INCLUDE
817 * Stage 5 of tracepoint event generation.
819 * Create the probe function. This function calls event size calculation
820 * and writes event data into the buffer.
823 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
824 #include <lttng/ust-tracepoint-event-reset.h>
825 #include <lttng/ust-tracepoint-event-write.h>
827 #undef lttng_ust__field_integer_ext
828 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
830 _type __tmp = (_src); \
831 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
834 #undef lttng_ust__field_float
835 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
837 _type __tmp = (_src); \
838 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
841 #undef lttng_ust__field_array_encoded
842 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
843 _encoding, _nowrite, _elem_type_base) \
844 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
845 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
847 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
849 #undef lttng_ust__field_sequence_encoded
850 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
851 _src_length, _encoding, _nowrite, _elem_type_base) \
853 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
854 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
856 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
857 __chan->ops->event_write(&__ctx, _src, \
858 sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
860 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \
862 #undef lttng_ust__field_string
863 #define lttng_ust__field_string(_item, _src, _nowrite) \
865 const char *__ctf_tmp_string = \
866 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
867 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
868 lttng_ust__get_dynamic_len(dest)); \
871 #undef lttng_ust__field_unused
872 #define lttng_ust__field_unused(_src)
874 #undef lttng_ust__field_enum
875 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
876 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
878 /* Beware: this get len actually consumes the len value */
879 #undef lttng_ust__get_dynamic_len
880 #define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
882 #undef LTTNG_UST_TP_ARGS
883 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
885 #undef LTTNG_UST_TP_FIELDS
886 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
889 * For state dump, check that "session" argument (mandatory) matches the
890 * session this event belongs to. Ensures that we write state dump data only
891 * into the started session, not into all sessions.
893 #undef LTTNG_UST__TP_SESSION_CHECK
894 #ifdef LTTNG_UST_TP_SESSION_CHECK
895 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession)
896 #else /* TP_SESSION_CHECK */
897 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1
898 #endif /* TP_SESSION_CHECK */
901 * Use of __builtin_return_address(0) sometimes seems to cause stack
902 * corruption on 32-bit PowerPC. Disable this feature on that
903 * architecture for now by always using the NULL value for the ip
906 #undef LTTNG_UST__TP_IP_PARAM
908 #ifdef LTTNG_UST_TP_IP_PARAM
909 #define LTTNG_UST__TP_IP_PARAM(x) (x)
910 #else /* TP_IP_PARAM */
912 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
913 #define LTTNG_UST__TP_IP_PARAM(x) NULL
915 #define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0)
918 #endif /* TP_IP_PARAM */
921 * Using twice size for filter stack data to hold size and pointer for
922 * each field (worse case). For integers, max size required is 64-bit.
923 * Same for double-precision floats. Those fit within
924 * 2*sizeof(unsigned long) for all supported architectures.
925 * Perform UNION (||) of filter runtime list.
927 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
928 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
930 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
933 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
935 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
936 size_t __dynamic_len_idx = 0; \
937 const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \
938 struct lttng_ust_probe_ctx __probe_ctx; \
940 size_t __dynamic_len[__num_fields]; \
941 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
944 bool __interpreter_stack_prepared = false; \
947 (void) __dynamic_len_idx; /* don't warn if unused */ \
948 switch (__event->type) { \
949 case LTTNG_UST_EVENT_TYPE_RECORDER: \
951 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
952 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
953 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
955 if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \
957 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
959 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
963 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
966 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
968 if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
970 __probe_ctx.struct_size = sizeof(struct lttng_ust_probe_ctx); \
971 __probe_ctx.ip = LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM); \
972 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
973 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
974 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
975 __interpreter_stack_prepared = true; \
976 if (caa_likely(__event->run_filter(__event, \
977 __stackvar.__interpreter_stack_data, &__probe_ctx, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
980 switch (__event->type) { \
981 case LTTNG_UST_EVENT_TYPE_RECORDER: \
983 size_t __event_len, __event_align; \
984 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
985 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
986 struct lttng_ust_ring_buffer_ctx __ctx; \
988 __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
989 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
990 __event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
991 lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
993 __ret = __chan->ops->event_reserve(&__ctx); \
997 __chan->ops->event_commit(&__ctx); \
1000 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
1002 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
1003 struct lttng_ust_notification_ctx __notif_ctx; \
1005 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
1006 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
1008 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
1009 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
1010 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
1012 __event_notifier->notification_send(__event_notifier, \
1013 __stackvar.__interpreter_stack_data, \
1021 #include LTTNG_UST_TRACEPOINT_INCLUDE
1023 #undef lttng_ust__get_dynamic_len
1026 * Stage 6 of tracepoint event generation.
1028 * Tracepoint loglevel mapping definition generation. We generate a
1029 * symbol for each mapping for a provider/event to ensure at most a 1 to
1030 * 1 mapping between events and loglevels. If the symbol is repeated,
1031 * the compiler will complain.
1034 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1035 #include <lttng/ust-tracepoint-event-reset.h>
1038 * Declare _loglevel___##__provider##___##__name as non-static, with
1039 * hidden visibility for c++ handling of weakref. We do a weakref to the
1040 * symbol in a later stage, which requires that the symbol is not
1044 #define LTTNG_UST_TP_EXTERN_C extern "C"
1046 #define LTTNG_UST_TP_EXTERN_C
1049 #undef LTTNG_UST_TRACEPOINT_LOGLEVEL
1050 #define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
1051 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
1052 LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
1053 __attribute__((visibility("hidden"))) = \
1054 &_loglevel_value___##__provider##___##__name;
1056 #include LTTNG_UST_TRACEPOINT_INCLUDE
1058 #undef LTTNG_UST_TP_EXTERN_C
1061 * Stage 6.1 of tracepoint event generation.
1063 * Tracepoint UML URI info.
1066 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1067 #include <lttng/ust-tracepoint-event-reset.h>
1070 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1071 * with hidden visibility for c++ handling of weakref. We do a weakref
1072 * to the symbol in a later stage, which requires that the symbol is not
1076 #define LTTNG_UST_TP_EXTERN_C extern "C"
1078 #define LTTNG_UST_TP_EXTERN_C
1081 #undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI
1082 #define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1083 LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
1084 __attribute__((visibility("hidden"))) = __uri; \
1086 #include LTTNG_UST_TRACEPOINT_INCLUDE
1088 #undef LTTNG_UST_TP_EXTERN_C
1091 * Stage 7.0 of tracepoint event generation.
1093 * Create events description structures. We use a weakref because
1094 * loglevels are optional. If not declared, the event will point to
1095 * a loglevel that contains NULL.
1097 * C++ requires that const objects have a user-declared default
1098 * constructor. However, in both C++ and C, weakref cannot be
1099 * initialized because it causes the weakref attribute to be ignored.
1100 * Therefore, the loglevel and model_emf_uri pointers are not const
1101 * to ensure C++ compilers default-initialize them.
1104 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1105 #include <lttng/ust-tracepoint-event-reset.h>
1107 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1108 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
1109 static const int * \
1110 __ref_loglevel___##_provider##___##_name \
1111 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1112 static const char * \
1113 __ref_model_emf_uri___##_provider##___##_name \
1114 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1115 static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \
1116 .struct_size = sizeof(struct lttng_ust_event_desc), \
1117 .event_name = #_name, \
1118 .probe_desc = <tng_ust__probe_desc___##_provider, \
1119 .tp_class = <tng_ust__event_class___##_template_provider##___##_template_name, \
1120 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1121 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1124 #include LTTNG_UST_TRACEPOINT_INCLUDE
1127 * Stage 7.1 of tracepoint event generation.
1129 * Create array of events.
1132 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1133 #include <lttng/ust-tracepoint-event-reset.h>
1135 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1136 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
1137 <tng_ust__event_desc___##_provider##_##_name,
1139 static const struct lttng_ust_event_desc
* const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)[] = {
1140 #include LTTNG_UST_TRACEPOINT_INCLUDE
1141 NULL
, /* Dummy, C99 forbids 0-len array. */
1146 * Stage 8 of tracepoint event generation.
1148 * Create a toplevel descriptor for the whole probe.
1151 const struct lttng_ust_probe_desc
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = {
1152 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1153 .provider_name
= lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER
),
1154 .event_desc
= LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
),
1155 .nr_events
= LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
)) - 1,
1156 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1157 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1160 static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
, LTTNG_UST_TRACEPOINT_PROVIDER
);
1161 static struct lttng_ust_registered_probe
*LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
);
1164 * Stage 9 of tracepoint event generation.
1166 * Register/unregister probes at module load/unload.
1168 * Generate the constructor as an externally visible symbol for use when
1169 * linking the probe statically.
1171 * Register refcount is protected by libc dynamic loader mutex.
1174 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1175 #include <lttng/ust-tracepoint-event-reset.h>
1177 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1178 lttng_ust_notrace
__attribute__((constructor
));
1180 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1182 struct lttng_ust_registered_probe
*reg_probe
;
1184 if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
,
1185 LTTNG_UST_TRACEPOINT_PROVIDER
)++) {
1189 * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a
1190 * static inline function that ensures every probe PROVIDER
1191 * argument match the provider within which they appear. It
1192 * calls empty static inline functions, and therefore has no
1193 * runtime effect. However, if it detects an error, a linker
1194 * error will appear.
1196 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_
, LTTNG_UST_TRACEPOINT_PROVIDER
)();
1197 assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1198 reg_probe
= lttng_ust_probe_register(<TNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1200 fprintf(stderr
, "LTTng-UST: Error while registering tracepoint probe.\n");
1203 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = reg_probe
;
1207 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1208 lttng_ust_notrace
__attribute__((destructor
));
1210 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__
, LTTNG_UST_TRACEPOINT_PROVIDER
)(void)
1212 if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___
,
1213 LTTNG_UST_TRACEPOINT_PROVIDER
)) {
1216 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
));
1217 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___
, LTTNG_UST_TRACEPOINT_PROVIDER
) = NULL
;
1221 * LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before
1222 * including a tracepoint instrumentation header to hide symbols
1223 * associated with the tracepoint provider. This is useful if the
1224 * tracepoint definition (including the header after defining
1225 * LTTNG_UST_TRACEPOINT_DEFINE) is in the same module as the provider
1226 * (including the header after defining
1227 * LTTNG_UST_TRACEPOINT_CREATE_PROBES).
1229 #undef LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY
1230 #ifdef LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
1231 #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("hidden")))
1233 #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("default")))
1236 int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_
, LTTNG_UST_TRACEPOINT_PROVIDER
)
1237 LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY
;