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/ringbuffer-context.h>
14 #include <lttng/ust-arch.h>
15 #include <lttng/ust-compiler.h>
16 #include <lttng/tracepoint.h>
17 #include <lttng/ust-endian.h>
20 #define __LTTNG_UST_NULL_STRING "(null)"
22 #undef tp_list_for_each_entry_rcu
23 #define tp_list_for_each_entry_rcu(pos, head, member) \
24 for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \
25 &pos->member != (head); \
26 pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member))
29 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
30 * same arguments and having the same field layout.
32 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
33 * its own provider and name. It refers to a class (template).
35 * TRACEPOINT_EVENT declared both a class and an instance and does a
36 * direct mapping from the instance to the class.
39 #undef TRACEPOINT_EVENT
40 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
41 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
43 _TP_PARAMS(_fields)) \
44 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
47 #undef TRACEPOINT_EVENT_CLASS
48 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
49 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
51 #undef TRACEPOINT_EVENT_INSTANCE
52 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
53 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
56 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
58 #define _tp_max_t(type, x, y) \
62 __max1 > __max2 ? __max1: __max2; \
66 * Stage 0 of tracepoint event generation.
68 * Check that each TRACEPOINT_EVENT provider argument match the
69 * TRACEPOINT_PROVIDER by creating dummy callbacks.
72 /* Reset all macros within TRACEPOINT_EVENT */
73 #include <lttng/ust-tracepoint-event-reset.h>
75 static inline lttng_ust_notrace
76 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
78 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
82 #undef _TRACEPOINT_EVENT_CLASS
83 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
84 __tracepoint_provider_mismatch_##_provider();
86 #undef _TRACEPOINT_EVENT_INSTANCE
87 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
88 __tracepoint_provider_mismatch_##_provider();
90 static inline lttng_ust_notrace
91 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
93 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
95 #include TRACEPOINT_INCLUDE
99 * Stage 0.1 of tracepoint event generation.
101 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
102 * tracepoint name length limit.
105 /* Reset all macros within TRACEPOINT_EVENT */
106 #include <lttng/ust-tracepoint-event-reset.h>
108 #undef _TRACEPOINT_EVENT_INSTANCE
109 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
111 __tp_name_len_check##_provider##___##_name[LTTNG_UST_ABI_SYM_NAME_LEN] \
112 __attribute__((unused)) = \
113 #_provider ":" #_name;
115 #include TRACEPOINT_INCLUDE
118 * Stage 0.2 of tracepoint event generation.
120 * Create dummy trace prototypes for each event class, and for each used
121 * template. This will allow checking whether the prototypes from the
122 * class and the instance using the class actually match.
125 /* Reset all macros within TRACEPOINT_EVENT */
126 #include <lttng/ust-tracepoint-event-reset.h>
129 #define TP_ARGS(...) __VA_ARGS__
131 #undef _TRACEPOINT_EVENT_INSTANCE
132 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
133 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
135 #undef _TRACEPOINT_EVENT_CLASS
136 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
137 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
139 #include TRACEPOINT_INCLUDE
142 * Stage 0.9 of tracepoint event generation
144 * Unfolding the enums
146 #include <lttng/ust-tracepoint-event-reset.h>
148 /* Enumeration entry (single value) */
149 #undef ctf_enum_value
150 #define ctf_enum_value(_string, _value) \
151 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
152 .struct_size = sizeof(struct lttng_ust_enum_entry), \
154 .value = lttng_is_signed_type(__typeof__(_value)) ? \
155 (long long) (_value) : (_value), \
156 .signedness = lttng_is_signed_type(__typeof__(_value)), \
159 .value = lttng_is_signed_type(__typeof__(_value)) ? \
160 (long long) (_value) : (_value), \
161 .signedness = lttng_is_signed_type(__typeof__(_value)), \
163 .string = (_string), \
166 /* Enumeration entry (range) */
167 #undef ctf_enum_range
168 #define ctf_enum_range(_string, _range_start, _range_end) \
169 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
170 .struct_size = sizeof(struct lttng_ust_enum_entry), \
172 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
173 (long long) (_range_start) : (_range_start), \
174 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
177 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
178 (long long) (_range_end) : (_range_end), \
179 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
181 .string = (_string), \
184 /* Enumeration entry (automatic value; follows the rules of CTF) */
186 #define ctf_enum_auto(_string) \
187 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
188 .struct_size = sizeof(struct lttng_ust_enum_entry), \
197 .string = (_string), \
198 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
201 #undef TP_ENUM_VALUES
202 #define TP_ENUM_VALUES(...) \
205 #undef TRACEPOINT_ENUM
206 #define TRACEPOINT_ENUM(_provider, _name, _values) \
207 struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \
209 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
211 #include TRACEPOINT_INCLUDE
215 * Verifying array and sequence elements are of an integer type.
218 /* Reset all macros within TRACEPOINT_EVENT */
219 #include <lttng/ust-tracepoint-event-reset.h>
220 #include <lttng/ust-tracepoint-event-write.h>
221 #include <lttng/ust-tracepoint-event-nowrite.h>
223 #undef _ctf_array_encoded
224 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
225 _length, _encoding, _nowrite, \
227 _lttng_array_element_type_is_supported(_type, _item)
229 #undef _ctf_sequence_encoded
230 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
231 _length_type, _src_length, _encoding, _nowrite, \
233 _lttng_array_element_type_is_supported(_type, _item)
236 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
238 #undef _TRACEPOINT_EVENT_CLASS
239 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
242 #include TRACEPOINT_INCLUDE
245 * Stage 1 of tracepoint event generation.
247 * Create event field type metadata section.
248 * Each event produce an array of fields.
251 /* Reset all macros within TRACEPOINT_EVENT */
252 #include <lttng/ust-tracepoint-event-reset.h>
253 #include <lttng/ust-tracepoint-event-write.h>
254 #include <lttng/ust-tracepoint-event-nowrite.h>
256 #undef _ctf_integer_ext
257 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
258 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
259 .struct_size = sizeof(struct lttng_ust_event_field), \
261 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
262 .nowrite = _nowrite, \
267 #define _ctf_float(_type, _item, _src, _nowrite) \
268 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
269 .struct_size = sizeof(struct lttng_ust_event_field), \
271 .type = lttng_ust_type_float_define(_type), \
272 .nowrite = _nowrite, \
276 #undef _ctf_array_encoded
277 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
278 _length, _encoding, _nowrite, \
280 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
281 .struct_size = sizeof(struct lttng_ust_event_field), \
283 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_array, { \
285 .type = lttng_ust_type_array, \
287 .struct_size = sizeof(struct lttng_ust_type_array), \
288 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
291 .encoding = lttng_ust_string_encoding_##_encoding, \
293 .nowrite = _nowrite, \
297 #undef _ctf_sequence_encoded
298 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
299 _length_type, _src_length, _encoding, _nowrite, \
301 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
302 .struct_size = sizeof(struct lttng_ust_event_field), \
303 .name = "_" #_item "_length", \
304 .type = lttng_ust_type_integer_define(_length_type, BYTE_ORDER, 10), \
305 .nowrite = _nowrite, \
308 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
309 .struct_size = sizeof(struct lttng_ust_event_field), \
311 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_sequence, { \
313 .type = lttng_ust_type_sequence, \
315 .struct_size = sizeof(struct lttng_ust_type_sequence), \
316 .length_name = "_" #_item "_length", \
317 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
319 .encoding = lttng_ust_string_encoding_##_encoding, \
321 .nowrite = _nowrite, \
326 #define _ctf_string(_item, _src, _nowrite) \
327 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
328 .struct_size = sizeof(struct lttng_ust_event_field), \
330 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_string, { \
332 .type = lttng_ust_type_string, \
334 .struct_size = sizeof(struct lttng_ust_type_string), \
335 .encoding = lttng_ust_string_encoding_UTF8, \
337 .nowrite = _nowrite, \
342 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
343 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
344 .struct_size = sizeof(struct lttng_ust_event_field), \
346 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_enum, { \
348 .type = lttng_ust_type_enum, \
350 .struct_size = sizeof(struct lttng_ust_type_enum), \
351 .desc = &__enum_##_provider##_##_name, \
352 .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \
354 .nowrite = _nowrite, \
359 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
361 #undef _TRACEPOINT_EVENT_CLASS
362 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
363 static struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \
365 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
368 #undef TRACEPOINT_ENUM
369 #define TRACEPOINT_ENUM(_provider, _name, _values) \
370 static struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
371 .struct_size = sizeof(struct lttng_ust_enum_desc), \
372 .name = #_provider "_" #_name, \
373 .entries = __enum_values__##_provider##_##_name, \
374 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
377 #include TRACEPOINT_INCLUDE
380 * Stage 2 of tracepoint event generation.
382 * Create probe callback prototypes.
385 /* Reset all macros within TRACEPOINT_EVENT */
386 #include <lttng/ust-tracepoint-event-reset.h>
389 #define TP_ARGS(...) __VA_ARGS__
391 #undef _TRACEPOINT_EVENT_CLASS
392 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
393 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
395 #include TRACEPOINT_INCLUDE
398 * Stage 3.0 of tracepoint event generation.
400 * Create static inline function that calculates event size.
403 /* Reset all macros within TRACEPOINT_EVENT */
404 #include <lttng/ust-tracepoint-event-reset.h>
405 #include <lttng/ust-tracepoint-event-write.h>
407 #undef _ctf_integer_ext
408 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
409 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
410 __event_len += sizeof(_type);
413 #define _ctf_float(_type, _item, _src, _nowrite) \
414 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
415 __event_len += sizeof(_type);
417 #undef _ctf_array_encoded
418 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
419 _nowrite, _elem_type_base) \
420 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
421 __event_len += sizeof(_type) * (_length);
423 #undef _ctf_sequence_encoded
424 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
425 _src_length, _encoding, _nowrite, _elem_type_base) \
426 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
427 __event_len += sizeof(_length_type); \
428 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
429 __dynamic_len[__dynamic_len_idx] = (_src_length); \
430 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
434 #define _ctf_string(_item, _src, _nowrite) \
435 __event_len += __dynamic_len[__dynamic_len_idx++] = \
436 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
439 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
440 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
443 #define TP_ARGS(...) __VA_ARGS__
446 #define TP_FIELDS(...) __VA_ARGS__
448 #undef _TRACEPOINT_EVENT_CLASS
449 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
450 static inline lttng_ust_notrace \
451 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
453 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
455 size_t __event_len = 0; \
456 unsigned int __dynamic_len_idx = 0; \
459 (void) __dynamic_len_idx; /* don't warn if unused */ \
461 return __event_len; \
464 #include TRACEPOINT_INCLUDE
467 * Stage 3.1 of tracepoint event generation.
469 * Create static inline function that layout the filter stack data.
470 * We make both write and nowrite data available to the filter.
473 /* Reset all macros within TRACEPOINT_EVENT */
474 #include <lttng/ust-tracepoint-event-reset.h>
475 #include <lttng/ust-tracepoint-event-write.h>
476 #include <lttng/ust-tracepoint-event-nowrite.h>
478 #undef _ctf_integer_ext
479 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
480 if (lttng_is_signed_type(_type)) { \
481 int64_t __ctf_tmp_int64; \
482 switch (sizeof(_type)) { \
485 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
486 __ctf_tmp_int64 = (int64_t) __tmp.v; \
491 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
492 if (_byte_order != BYTE_ORDER) \
493 __tmp.v = bswap_16(__tmp.v); \
494 __ctf_tmp_int64 = (int64_t) __tmp.v; \
499 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
500 if (_byte_order != BYTE_ORDER) \
501 __tmp.v = bswap_32(__tmp.v); \
502 __ctf_tmp_int64 = (int64_t) __tmp.v; \
507 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
508 if (_byte_order != BYTE_ORDER) \
509 __tmp.v = bswap_64(__tmp.v); \
510 __ctf_tmp_int64 = (int64_t) __tmp.v; \
516 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
518 uint64_t __ctf_tmp_uint64; \
519 switch (sizeof(_type)) { \
522 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
523 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
528 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
529 if (_byte_order != BYTE_ORDER) \
530 __tmp.v = bswap_16(__tmp.v); \
531 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
536 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
537 if (_byte_order != BYTE_ORDER) \
538 __tmp.v = bswap_32(__tmp.v); \
539 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
544 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
545 if (_byte_order != BYTE_ORDER) \
546 __tmp.v = bswap_64(__tmp.v); \
547 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
553 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
555 __stack_data += sizeof(int64_t);
558 #define _ctf_float(_type, _item, _src, _nowrite) \
560 double __ctf_tmp_double = (double) (_type) (_src); \
561 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
562 __stack_data += sizeof(double); \
565 #undef _ctf_array_encoded
566 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
567 _encoding, _nowrite, _elem_type_base) \
569 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
570 const void *__ctf_tmp_ptr = (_src); \
571 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
572 __stack_data += sizeof(unsigned long); \
573 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
574 __stack_data += sizeof(void *); \
577 #undef _ctf_sequence_encoded
578 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
579 _src_length, _encoding, _nowrite, _elem_type_base) \
581 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
582 const void *__ctf_tmp_ptr = (_src); \
583 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
584 __stack_data += sizeof(unsigned long); \
585 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
586 __stack_data += sizeof(void *); \
590 #define _ctf_string(_item, _src, _nowrite) \
592 const void *__ctf_tmp_ptr = \
593 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
594 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
595 __stack_data += sizeof(void *); \
599 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
600 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
603 #define TP_ARGS(...) __VA_ARGS__
606 #define TP_FIELDS(...) __VA_ARGS__
608 #undef _TRACEPOINT_EVENT_CLASS
609 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
611 void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
612 _TP_ARGS_DATA_PROTO(_args)) \
617 #include TRACEPOINT_INCLUDE
620 * Stage 4 of tracepoint event generation.
622 * Create static inline function that calculates event payload alignment.
625 /* Reset all macros within TRACEPOINT_EVENT */
626 #include <lttng/ust-tracepoint-event-reset.h>
627 #include <lttng/ust-tracepoint-event-write.h>
629 #undef _ctf_integer_ext
630 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
631 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
634 #define _ctf_float(_type, _item, _src, _nowrite) \
635 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
637 #undef _ctf_array_encoded
638 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
639 _encoding, _nowrite, _elem_type_base) \
640 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
642 #undef _ctf_sequence_encoded
643 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
644 _src_length, _encoding, _nowrite, _elem_type_base) \
645 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
646 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
649 #define _ctf_string(_item, _src, _nowrite)
652 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
653 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
656 #define TP_ARGS(...) __VA_ARGS__
659 #define TP_FIELDS(...) __VA_ARGS__
661 #undef _TRACEPOINT_EVENT_CLASS
662 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
663 static inline lttng_ust_notrace \
664 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
666 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
668 size_t __event_align = 1; \
670 return __event_align; \
673 #include TRACEPOINT_INCLUDE
677 * Stage 5 of tracepoint event generation.
679 * Create the probe function. This function calls event size calculation
680 * and writes event data into the buffer.
683 /* Reset all macros within TRACEPOINT_EVENT */
684 #include <lttng/ust-tracepoint-event-reset.h>
685 #include <lttng/ust-tracepoint-event-write.h>
687 #undef _ctf_integer_ext
688 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
690 _type __tmp = (_src); \
691 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
692 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
696 #define _ctf_float(_type, _item, _src, _nowrite) \
698 _type __tmp = (_src); \
699 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
700 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
703 #undef _ctf_array_encoded
704 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
705 _encoding, _nowrite, _elem_type_base) \
706 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
707 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
709 #undef _ctf_sequence_encoded
710 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
711 _src_length, _encoding, _nowrite, _elem_type_base) \
713 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
714 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
715 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
717 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
718 __chan->ops->event_write(&__ctx, _src, \
719 sizeof(_type) * __get_dynamic_len(dest));
722 #define _ctf_string(_item, _src, _nowrite) \
724 const char *__ctf_tmp_string = \
725 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
726 lib_ring_buffer_align_ctx(&__ctx, \
727 lttng_alignof(*__ctf_tmp_string)); \
728 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
729 __get_dynamic_len(dest)); \
734 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
735 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
737 /* Beware: this get len actually consumes the len value */
738 #undef __get_dynamic_len
739 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
742 #define TP_ARGS(...) __VA_ARGS__
745 #define TP_FIELDS(...) __VA_ARGS__
748 * For state dump, check that "session" argument (mandatory) matches the
749 * session this event belongs to. Ensures that we write state dump data only
750 * into the started session, not into all sessions.
752 #undef _TP_SESSION_CHECK
753 #ifdef TP_SESSION_CHECK
754 #define _TP_SESSION_CHECK(session, csession) (session == csession)
755 #else /* TP_SESSION_CHECK */
756 #define _TP_SESSION_CHECK(session, csession) 1
757 #endif /* TP_SESSION_CHECK */
760 * Use of __builtin_return_address(0) sometimes seems to cause stack
761 * corruption on 32-bit PowerPC. Disable this feature on that
762 * architecture for now by always using the NULL value for the ip
767 #define _TP_IP_PARAM(x) (x)
768 #else /* TP_IP_PARAM */
770 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
771 #define _TP_IP_PARAM(x) NULL
773 #define _TP_IP_PARAM(x) __builtin_return_address(0)
776 #endif /* TP_IP_PARAM */
779 * Using twice size for filter stack data to hold size and pointer for
780 * each field (worse case). For integers, max size required is 64-bit.
781 * Same for double-precision floats. Those fit within
782 * 2*sizeof(unsigned long) for all supported architectures.
783 * Perform UNION (||) of filter runtime list.
785 #undef _TRACEPOINT_EVENT_CLASS
786 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
787 static lttng_ust_notrace \
788 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
790 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
792 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
793 size_t __dynamic_len_idx = 0; \
794 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
796 size_t __dynamic_len[__num_fields]; \
797 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
800 bool __interpreter_stack_prepared = false; \
803 (void) __dynamic_len_idx; /* don't warn if unused */ \
804 switch (__event->type) { \
805 case LTTNG_UST_EVENT_TYPE_RECORDER: \
807 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
808 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
809 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
811 if (!_TP_SESSION_CHECK(session, __chan_common->session)) \
813 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
815 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
819 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
822 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
824 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
826 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
827 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
828 _TP_ARGS_DATA_VAR(_args)); \
829 __interpreter_stack_prepared = true; \
830 if (caa_likely(__event->run_filter(__event, \
831 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
834 switch (__event->type) { \
835 case LTTNG_UST_EVENT_TYPE_RECORDER: \
837 size_t __event_len, __event_align; \
838 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
839 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
840 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
841 struct lttng_ust_stack_ctx __lttng_ctx; \
843 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
844 _TP_ARGS_DATA_VAR(_args)); \
845 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
846 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
847 __lttng_ctx.struct_size = sizeof(struct lttng_ust_stack_ctx); \
848 __lttng_ctx.event_recorder = __event_recorder; \
849 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_ctx, __event_len, \
850 __event_align, -1, __chan->handle); \
851 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
852 __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \
856 __chan->ops->event_commit(&__ctx); \
859 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
861 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
862 struct lttng_ust_notification_ctx __notif_ctx; \
864 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
865 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
867 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
868 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
869 _TP_ARGS_DATA_VAR(_args)); \
871 __event_notifier->notification_send(__event_notifier, \
872 __stackvar.__interpreter_stack_data, \
879 #include TRACEPOINT_INCLUDE
881 #undef __get_dynamic_len
884 * Stage 5.1 of tracepoint event generation.
886 * Create probe signature
889 /* Reset all macros within TRACEPOINT_EVENT */
890 #include <lttng/ust-tracepoint-event-reset.h>
893 #define TP_ARGS(...) __VA_ARGS__
895 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
897 #undef _TRACEPOINT_EVENT_CLASS
898 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
899 static const char __tp_event_signature___##_provider##___##_name[] = \
900 _TP_EXTRACT_STRING2(_args);
902 #include TRACEPOINT_INCLUDE
904 #undef _TP_EXTRACT_STRING2
907 * Stage 6 of tracepoint event generation.
909 * Tracepoint loglevel mapping definition generation. We generate a
910 * symbol for each mapping for a provider/event to ensure at most a 1 to
911 * 1 mapping between events and loglevels. If the symbol is repeated,
912 * the compiler will complain.
915 /* Reset all macros within TRACEPOINT_EVENT */
916 #include <lttng/ust-tracepoint-event-reset.h>
919 * Declare _loglevel___##__provider##___##__name as non-static, with
920 * hidden visibility for c++ handling of weakref. We do a weakref to the
921 * symbol in a later stage, which requires that the symbol is not
925 #define LTTNG_TP_EXTERN_C extern "C"
927 #define LTTNG_TP_EXTERN_C
930 #undef TRACEPOINT_LOGLEVEL
931 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
932 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
933 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
934 __attribute__((visibility("hidden"))) = \
935 &_loglevel_value___##__provider##___##__name;
937 #include TRACEPOINT_INCLUDE
939 #undef LTTNG_TP_EXTERN_C
942 * Stage 6.1 of tracepoint event generation.
944 * Tracepoint UML URI info.
947 /* Reset all macros within TRACEPOINT_EVENT */
948 #include <lttng/ust-tracepoint-event-reset.h>
951 * Declare _model_emf_uri___##__provider##___##__name as non-static,
952 * with hidden visibility for c++ handling of weakref. We do a weakref
953 * to the symbol in a later stage, which requires that the symbol is not
957 #define LTTNG_TP_EXTERN_C extern "C"
959 #define LTTNG_TP_EXTERN_C
962 #undef TRACEPOINT_MODEL_EMF_URI
963 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
964 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
965 __attribute__((visibility("hidden"))) = __uri; \
967 #include TRACEPOINT_INCLUDE
969 #undef LTTNG_TP_EXTERN_C
972 * Stage 7.1 of tracepoint event generation.
974 * Create events description structures. We use a weakref because
975 * loglevels are optional. If not declared, the event will point to the
976 * a loglevel that contains NULL.
979 /* Reset all macros within TRACEPOINT_EVENT */
980 #include <lttng/ust-tracepoint-event-reset.h>
982 #undef _TRACEPOINT_EVENT_INSTANCE
983 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
985 __ref_loglevel___##_provider##___##_name \
986 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
987 static const char * \
988 __ref_model_emf_uri___##_provider##___##_name \
989 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
990 static struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \
991 .struct_size = sizeof(struct lttng_ust_event_desc), \
992 .name = #_provider ":" #_name, \
993 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \
995 .fields = __event_fields___##_provider##___##_template, \
996 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
997 .loglevel = &__ref_loglevel___##_provider##___##_name, \
998 .signature = __tp_event_signature___##_provider##___##_template, \
999 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1002 #include TRACEPOINT_INCLUDE
1005 * Stage 7.2 of tracepoint event generation.
1007 * Create array of events.
1010 /* Reset all macros within TRACEPOINT_EVENT */
1011 #include <lttng/ust-tracepoint-event-reset.h>
1013 #undef _TRACEPOINT_EVENT_INSTANCE
1014 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1015 &__event_desc___##_provider##_##_name,
1017 static struct lttng_ust_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
1018 #include TRACEPOINT_INCLUDE
1019 NULL
, /* Dummy, C99 forbids 0-len array. */
1024 * Stage 8 of tracepoint event generation.
1026 * Create a toplevel descriptor for the whole probe.
1029 /* non-const because list head will be modified when registered. */
1030 static struct lttng_ust_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
1031 .struct_size
= sizeof(struct lttng_ust_probe_desc
),
1032 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
1033 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
1034 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
1035 .head
= { NULL
, NULL
},
1036 .lazy_init_head
= { NULL
, NULL
},
1038 .major
= LTTNG_UST_PROVIDER_MAJOR
,
1039 .minor
= LTTNG_UST_PROVIDER_MINOR
,
1042 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
1045 * Stage 9 of tracepoint event generation.
1047 * Register/unregister probes at module load/unload.
1049 * Generate the constructor as an externally visible symbol for use when
1050 * linking the probe statically.
1052 * Register refcount is protected by libc dynamic loader mutex.
1055 /* Reset all macros within TRACEPOINT_EVENT */
1056 #include <lttng/ust-tracepoint-event-reset.h>
1057 static void lttng_ust_notrace
__attribute__((constructor
))
1058 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1060 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1064 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1065 TRACEPOINT_PROVIDER
)++) {
1069 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1070 * static inline function that ensures every probe PROVIDER
1071 * argument match the provider within which they appear. It
1072 * calls empty static inline functions, and therefore has no
1073 * runtime effect. However, if it detects an error, a linker
1074 * error will appear.
1076 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1077 ret
= lttng_ust_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1079 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1084 static void lttng_ust_notrace
__attribute__((destructor
))
1085 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1087 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1089 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1090 TRACEPOINT_PROVIDER
)) {
1093 lttng_ust_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1096 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
)
1097 __attribute__((visibility("default")));