2 * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include <urcu/compiler.h>
26 #include <urcu/rculist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/ringbuffer-config.h>
29 #include <lttng/ust-compiler.h>
30 #include <lttng/tracepoint.h>
34 #define __LTTNG_UST_NULL_STRING "(null)"
36 #undef tp_list_for_each_entry_rcu
37 #define tp_list_for_each_entry_rcu(pos, head, member) \
38 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
39 &pos->member != (head); \
40 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
43 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
44 * same arguments and having the same field layout.
46 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
47 * its own provider and name. It refers to a class (template).
49 * TRACEPOINT_EVENT declared both a class and an instance and does a
50 * direct mapping from the instance to the class.
53 #undef TRACEPOINT_EVENT
54 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
55 TRACEPOINT_EVENT_CLASS(_provider, _name, \
57 _TP_PARAMS(_fields)) \
58 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
62 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
64 #define _tp_max_t(type, x, y) \
68 __max1 > __max2 ? __max1: __max2; \
72 * Stage 0 of tracepoint event generation.
74 * Check that each TRACEPOINT_EVENT provider argument match the
75 * TRACEPOINT_PROVIDER by creating dummy callbacks.
78 /* Reset all macros within TRACEPOINT_EVENT */
79 #include <lttng/ust-tracepoint-event-reset.h>
81 static inline lttng_ust_notrace
82 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
84 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
88 #undef TRACEPOINT_EVENT_CLASS
89 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
90 __tracepoint_provider_mismatch_##_provider();
92 #undef TRACEPOINT_EVENT_INSTANCE
93 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
94 __tracepoint_provider_mismatch_##_provider();
96 static inline lttng_ust_notrace
97 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
99 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
101 #include TRACEPOINT_INCLUDE
105 * Stage 0.1 of tracepoint event generation.
107 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
108 * tracepoint name length limit.
111 /* Reset all macros within TRACEPOINT_EVENT */
112 #include <lttng/ust-tracepoint-event-reset.h>
114 #undef TRACEPOINT_EVENT_INSTANCE
115 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
117 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
118 __attribute__((unused)) = \
119 #_provider ":" #_name;
121 #include TRACEPOINT_INCLUDE
124 * Stage 0.9 of tracepoint event generation
126 * Unfolding the enums
128 #include <lttng/ust-tracepoint-event-reset.h>
130 /* Enumeration entry (single value) */
131 #undef ctf_enum_value
132 #define ctf_enum_value(_string, _value) \
135 .value = lttng_is_signed_type(__typeof__(_value)) ? \
136 (long long) (_value) : (_value), \
137 .signedness = lttng_is_signed_type(__typeof__(_value)), \
140 .value = lttng_is_signed_type(__typeof__(_value)) ? \
141 (long long) (_value) : (_value), \
142 .signedness = lttng_is_signed_type(__typeof__(_value)), \
144 .string = (_string), \
147 /* Enumeration entry (range) */
148 #undef ctf_enum_range
149 #define ctf_enum_range(_string, _range_start, _range_end) \
152 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
153 (long long) (_range_start) : (_range_start), \
154 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
157 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
158 (long long) (_range_end) : (_range_end), \
159 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
161 .string = (_string), \
164 /* Enumeration entry (automatic value; follows the rules of CTF) */
166 #define ctf_enum_auto(_string) \
176 .string = (_string), \
179 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
184 #undef TP_ENUM_VALUES
185 #define TP_ENUM_VALUES(...) \
188 #undef TRACEPOINT_ENUM
189 #define TRACEPOINT_ENUM(_provider, _name, _values) \
190 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
192 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
195 #include TRACEPOINT_INCLUDE
198 * Stage 1 of tracepoint event generation.
200 * Create event field type metadata section.
201 * Each event produce an array of fields.
204 /* Reset all macros within TRACEPOINT_EVENT */
205 #include <lttng/ust-tracepoint-event-reset.h>
206 #include <lttng/ust-tracepoint-event-write.h>
207 #include <lttng/ust-tracepoint-event-nowrite.h>
209 #undef _ctf_integer_ext
210 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
213 .type = __type_integer(_type, _byte_order, _base, none),\
214 .nowrite = _nowrite, \
218 #define _ctf_float(_type, _item, _src, _nowrite) \
221 .type = __type_float(_type), \
222 .nowrite = _nowrite, \
225 #undef _ctf_array_encoded
226 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
227 _length, _encoding, _nowrite, \
233 .atype = atype_array, \
238 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
243 .nowrite = _nowrite, \
246 #undef _ctf_sequence_encoded
247 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
248 _length_type, _src_length, _encoding, _nowrite, \
254 .atype = atype_sequence, \
259 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
260 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
264 .nowrite = _nowrite, \
268 #define _ctf_string(_item, _src, _nowrite) \
273 .atype = atype_string, \
276 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
279 .nowrite = _nowrite, \
283 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
287 .atype = atype_enum, \
291 .desc = &__enum_##_provider##_##_name, \
292 .container_type = { \
293 .size = sizeof(_type) * CHAR_BIT, \
294 .alignment = lttng_alignof(_type) * CHAR_BIT, \
295 .signedness = lttng_is_signed_type(_type), \
296 .reverse_byte_order = 0, \
298 .encoding = lttng_encode_none, \
304 .nowrite = _nowrite, \
308 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
310 #undef TRACEPOINT_EVENT_CLASS
311 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
312 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
314 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
317 #undef TRACEPOINT_ENUM
318 #define TRACEPOINT_ENUM(_provider, _name, _values) \
319 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
320 .name = #_provider "_" #_name, \
321 .entries = __enum_values__##_provider##_##_name, \
322 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
325 #include TRACEPOINT_INCLUDE
328 * Stage 2 of tracepoint event generation.
330 * Create probe callback prototypes.
333 /* Reset all macros within TRACEPOINT_EVENT */
334 #include <lttng/ust-tracepoint-event-reset.h>
337 #define TP_ARGS(...) __VA_ARGS__
339 #undef TRACEPOINT_EVENT_CLASS
340 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
341 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
343 #include TRACEPOINT_INCLUDE
346 * Stage 3.0 of tracepoint event generation.
348 * Create static inline function that calculates event size.
351 /* Reset all macros within TRACEPOINT_EVENT */
352 #include <lttng/ust-tracepoint-event-reset.h>
353 #include <lttng/ust-tracepoint-event-write.h>
355 #undef _ctf_integer_ext
356 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
357 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
358 __event_len += sizeof(_type);
361 #define _ctf_float(_type, _item, _src, _nowrite) \
362 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
363 __event_len += sizeof(_type);
365 #undef _ctf_array_encoded
366 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
367 _nowrite, _elem_type_base) \
368 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
369 __event_len += sizeof(_type) * (_length);
371 #undef _ctf_sequence_encoded
372 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
373 _src_length, _encoding, _nowrite, _elem_type_base) \
374 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
375 __event_len += sizeof(_length_type); \
376 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
377 __dynamic_len[__dynamic_len_idx] = (_src_length); \
378 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
382 #define _ctf_string(_item, _src, _nowrite) \
383 __event_len += __dynamic_len[__dynamic_len_idx++] = \
384 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
387 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
388 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
391 #define TP_ARGS(...) __VA_ARGS__
394 #define TP_FIELDS(...) __VA_ARGS__
396 #undef TRACEPOINT_EVENT_CLASS
397 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
398 static inline lttng_ust_notrace \
399 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
401 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
403 size_t __event_len = 0; \
404 unsigned int __dynamic_len_idx = 0; \
407 (void) __dynamic_len_idx; /* don't warn if unused */ \
409 return __event_len; \
412 #include TRACEPOINT_INCLUDE
415 * Stage 3.1 of tracepoint event generation.
417 * Create static inline function that layout the filter stack data.
418 * We make both write and nowrite data available to the filter.
421 /* Reset all macros within TRACEPOINT_EVENT */
422 #include <lttng/ust-tracepoint-event-reset.h>
423 #include <lttng/ust-tracepoint-event-write.h>
424 #include <lttng/ust-tracepoint-event-nowrite.h>
426 #undef _ctf_integer_ext
427 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
428 if (lttng_is_signed_type(_type)) { \
429 int64_t __ctf_tmp_int64; \
430 switch (sizeof(_type)) { \
433 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
434 __ctf_tmp_int64 = (int64_t) __tmp.v; \
439 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
440 if (_byte_order != BYTE_ORDER) \
441 __tmp.v = bswap_16(__tmp.v); \
442 __ctf_tmp_int64 = (int64_t) __tmp.v; \
447 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
448 if (_byte_order != BYTE_ORDER) \
449 __tmp.v = bswap_32(__tmp.v); \
450 __ctf_tmp_int64 = (int64_t) __tmp.v; \
455 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
456 if (_byte_order != BYTE_ORDER) \
457 __tmp.v = bswap_64(__tmp.v); \
458 __ctf_tmp_int64 = (int64_t) __tmp.v; \
464 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
466 uint64_t __ctf_tmp_uint64; \
467 switch (sizeof(_type)) { \
470 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
471 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
476 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
477 if (_byte_order != BYTE_ORDER) \
478 __tmp.v = bswap_16(__tmp.v); \
479 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
484 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
485 if (_byte_order != BYTE_ORDER) \
486 __tmp.v = bswap_32(__tmp.v); \
487 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
492 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
493 if (_byte_order != BYTE_ORDER) \
494 __tmp.v = bswap_64(__tmp.v); \
495 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
501 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
503 __stack_data += sizeof(int64_t);
506 #define _ctf_float(_type, _item, _src, _nowrite) \
508 double __ctf_tmp_double = (double) (_type) (_src); \
509 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
510 __stack_data += sizeof(double); \
513 #undef _ctf_array_encoded
514 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
515 _encoding, _nowrite, _elem_type_base) \
517 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
518 const void *__ctf_tmp_ptr = (_src); \
519 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
520 __stack_data += sizeof(unsigned long); \
521 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
522 __stack_data += sizeof(void *); \
525 #undef _ctf_sequence_encoded
526 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
527 _src_length, _encoding, _nowrite, _elem_type_base) \
529 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
530 const void *__ctf_tmp_ptr = (_src); \
531 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
532 __stack_data += sizeof(unsigned long); \
533 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
534 __stack_data += sizeof(void *); \
538 #define _ctf_string(_item, _src, _nowrite) \
540 const void *__ctf_tmp_ptr = \
541 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
542 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
543 __stack_data += sizeof(void *); \
547 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
548 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
551 #define TP_ARGS(...) __VA_ARGS__
554 #define TP_FIELDS(...) __VA_ARGS__
556 #undef TRACEPOINT_EVENT_CLASS
557 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
559 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
560 _TP_ARGS_DATA_PROTO(_args)) \
565 #include TRACEPOINT_INCLUDE
568 * Stage 4 of tracepoint event generation.
570 * Create static inline function that calculates event payload alignment.
573 /* Reset all macros within TRACEPOINT_EVENT */
574 #include <lttng/ust-tracepoint-event-reset.h>
575 #include <lttng/ust-tracepoint-event-write.h>
577 #undef _ctf_integer_ext
578 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
579 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
582 #define _ctf_float(_type, _item, _src, _nowrite) \
583 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
585 #undef _ctf_array_encoded
586 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
587 _encoding, _nowrite, _elem_type_base) \
588 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
590 #undef _ctf_sequence_encoded
591 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
592 _src_length, _encoding, _nowrite, _elem_type_base) \
593 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
594 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
597 #define _ctf_string(_item, _src, _nowrite)
600 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
601 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
604 #define TP_ARGS(...) __VA_ARGS__
607 #define TP_FIELDS(...) __VA_ARGS__
609 #undef TRACEPOINT_EVENT_CLASS
610 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
611 static inline lttng_ust_notrace \
612 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
614 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
616 size_t __event_align = 1; \
618 return __event_align; \
621 #include TRACEPOINT_INCLUDE
625 * Stage 5 of tracepoint event generation.
627 * Create the probe function. This function calls event size calculation
628 * and writes event data into the buffer.
631 /* Reset all macros within TRACEPOINT_EVENT */
632 #include <lttng/ust-tracepoint-event-reset.h>
633 #include <lttng/ust-tracepoint-event-write.h>
635 #undef _ctf_integer_ext
636 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
638 _type __tmp = (_src); \
639 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
640 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
644 #define _ctf_float(_type, _item, _src, _nowrite) \
646 _type __tmp = (_src); \
647 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
648 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
651 #undef _ctf_array_encoded
652 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
653 _encoding, _nowrite, _elem_type_base) \
654 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
655 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
657 #undef _ctf_sequence_encoded
658 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
659 _src_length, _encoding, _nowrite, _elem_type_base) \
661 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
662 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
663 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
665 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
666 __chan->ops->event_write(&__ctx, _src, \
667 sizeof(_type) * __get_dynamic_len(dest));
670 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
671 * tracepoint provider ABI implements event_strcpy. This dynamic check
672 * can be removed when the tracepoint provider ABI moves to 2.
674 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
675 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
679 #define _ctf_string(_item, _src, _nowrite) \
681 const char *__ctf_tmp_string = \
682 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
683 lib_ring_buffer_align_ctx(&__ctx, \
684 lttng_alignof(*__ctf_tmp_string)); \
685 if (__chan->ops->u.has_strcpy) \
686 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
687 __get_dynamic_len(dest)); \
689 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
690 __get_dynamic_len(dest)); \
695 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
696 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
698 /* Beware: this get len actually consumes the len value */
699 #undef __get_dynamic_len
700 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
703 #define TP_ARGS(...) __VA_ARGS__
706 #define TP_FIELDS(...) __VA_ARGS__
709 * For state dump, check that "session" argument (mandatory) matches the
710 * session this event belongs to. Ensures that we write state dump data only
711 * into the started session, not into all sessions.
713 #undef _TP_SESSION_CHECK
714 #ifdef TP_SESSION_CHECK
715 #define _TP_SESSION_CHECK(session, csession) (session == csession)
716 #else /* TP_SESSION_CHECK */
717 #define _TP_SESSION_CHECK(session, csession) 1
718 #endif /* TP_SESSION_CHECK */
721 * Use of __builtin_return_address(0) sometimes seems to cause stack
722 * corruption on 32-bit PowerPC. Disable this feature on that
723 * architecture for now by always using the NULL value for the ip
728 #define _TP_IP_PARAM(x) (x)
729 #else /* TP_IP_PARAM */
731 #if defined(__PPC__) && !defined(__PPC64__)
732 #define _TP_IP_PARAM(x) NULL
733 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
734 #define _TP_IP_PARAM(x) __builtin_return_address(0)
735 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
737 #endif /* TP_IP_PARAM */
740 * Using twice size for filter stack data to hold size and pointer for
741 * each field (worse case). For integers, max size required is 64-bit.
742 * Same for double-precision floats. Those fit within
743 * 2*sizeof(unsigned long) for all supported architectures.
744 * Perform UNION (||) of filter runtime list.
746 #undef TRACEPOINT_EVENT_CLASS
747 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
748 static lttng_ust_notrace \
749 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
751 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
753 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
754 struct lttng_channel *__chan = __event->chan; \
755 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
756 struct lttng_stack_ctx __lttng_ctx; \
757 size_t __event_len, __event_align; \
758 size_t __dynamic_len_idx = 0; \
760 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
761 char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
766 (void) __dynamic_len_idx; /* don't warn if unused */ \
767 if (!_TP_SESSION_CHECK(session, __chan->session)) \
769 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
771 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
773 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
775 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
777 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
778 struct lttng_bytecode_runtime *bc_runtime; \
779 int __filter_record = __event->has_enablers_without_bytecode; \
781 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
782 _TP_ARGS_DATA_VAR(_args)); \
783 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
784 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
785 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
786 __filter_record = 1; \
788 if (caa_likely(!__filter_record)) \
791 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
792 _TP_ARGS_DATA_VAR(_args)); \
793 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
794 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
795 __lttng_ctx.event = __event; \
796 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
797 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
798 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
799 __event_align, -1, __chan->handle, &__lttng_ctx); \
800 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
801 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
805 __chan->ops->event_commit(&__ctx); \
808 #include TRACEPOINT_INCLUDE
810 #undef __get_dynamic_len
813 * Stage 5.1 of tracepoint event generation.
815 * Create probe signature
818 /* Reset all macros within TRACEPOINT_EVENT */
819 #include <lttng/ust-tracepoint-event-reset.h>
822 #define TP_ARGS(...) __VA_ARGS__
824 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
826 #undef TRACEPOINT_EVENT_CLASS
827 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
828 static const char __tp_event_signature___##_provider##___##_name[] = \
829 _TP_EXTRACT_STRING2(_args);
831 #include TRACEPOINT_INCLUDE
833 #undef _TP_EXTRACT_STRING2
836 * Stage 6 of tracepoint event generation.
838 * Tracepoint loglevel mapping definition generation. We generate a
839 * symbol for each mapping for a provider/event to ensure at most a 1 to
840 * 1 mapping between events and loglevels. If the symbol is repeated,
841 * the compiler will complain.
844 /* Reset all macros within TRACEPOINT_EVENT */
845 #include <lttng/ust-tracepoint-event-reset.h>
848 * Declare _loglevel___##__provider##___##__name as non-static, with
849 * hidden visibility for c++ handling of weakref. We do a weakref to the
850 * symbol in a later stage, which requires that the symbol is not
854 #define LTTNG_TP_EXTERN_C extern "C"
856 #define LTTNG_TP_EXTERN_C
859 #undef TRACEPOINT_LOGLEVEL
860 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
861 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
862 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
863 __attribute__((visibility("hidden"))) = \
864 &_loglevel_value___##__provider##___##__name;
866 #include TRACEPOINT_INCLUDE
868 #undef LTTNG_TP_EXTERN_C
871 * Stage 6.1 of tracepoint event generation.
873 * Tracepoint UML URI info.
876 /* Reset all macros within TRACEPOINT_EVENT */
877 #include <lttng/ust-tracepoint-event-reset.h>
880 * Declare _model_emf_uri___##__provider##___##__name as non-static,
881 * with hidden visibility for c++ handling of weakref. We do a weakref
882 * to the symbol in a later stage, which requires that the symbol is not
886 #define LTTNG_TP_EXTERN_C extern "C"
888 #define LTTNG_TP_EXTERN_C
891 #undef TRACEPOINT_MODEL_EMF_URI
892 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
893 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
894 __attribute__((visibility("hidden"))) = __uri; \
896 #include TRACEPOINT_INCLUDE
898 #undef LTTNG_TP_EXTERN_C
901 * Stage 7.1 of tracepoint event generation.
903 * Create events description structures. We use a weakref because
904 * loglevels are optional. If not declared, the event will point to the
905 * a loglevel that contains NULL.
908 /* Reset all macros within TRACEPOINT_EVENT */
909 #include <lttng/ust-tracepoint-event-reset.h>
911 #undef TRACEPOINT_EVENT_INSTANCE
912 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
914 __ref_loglevel___##_provider##___##_name \
915 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
916 static const char * \
917 __ref_model_emf_uri___##_provider##___##_name \
918 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
919 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
920 .name = #_provider ":" #_name, \
921 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
923 .fields = __event_fields___##_provider##___##_template, \
924 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
925 .loglevel = &__ref_loglevel___##_provider##___##_name, \
926 .signature = __tp_event_signature___##_provider##___##_template, \
929 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
934 #include TRACEPOINT_INCLUDE
937 * Stage 7.2 of tracepoint event generation.
939 * Create array of events.
942 /* Reset all macros within TRACEPOINT_EVENT */
943 #include <lttng/ust-tracepoint-event-reset.h>
945 #undef TRACEPOINT_EVENT_INSTANCE
946 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
947 &__event_desc___##_provider##_##_name,
949 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
950 #include TRACEPOINT_INCLUDE
951 NULL
, /* Dummy, C99 forbids 0-len array. */
956 * Stage 8 of tracepoint event generation.
958 * Create a toplevel descriptor for the whole probe.
961 /* non-const because list head will be modified when registered. */
962 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
963 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
964 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
965 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
966 .head
= { NULL
, NULL
},
967 .lazy_init_head
= { NULL
, NULL
},
969 .major
= LTTNG_UST_PROVIDER_MAJOR
,
970 .minor
= LTTNG_UST_PROVIDER_MINOR
,
973 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
976 * Stage 9 of tracepoint event generation.
978 * Register/unregister probes at module load/unload.
980 * Generate the constructor as an externally visible symbol for use when
981 * linking the probe statically.
983 * Register refcount is protected by libc dynamic loader mutex.
986 /* Reset all macros within TRACEPOINT_EVENT */
987 #include <lttng/ust-tracepoint-event-reset.h>
988 static void lttng_ust_notrace
__attribute__((constructor
))
989 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
991 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
995 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
996 TRACEPOINT_PROVIDER
)++) {
1000 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1001 * static inline function that ensures every probe PROVIDER
1002 * argument match the provider within which they appear. It
1003 * calls empty static inline functions, and therefore has no
1004 * runtime effect. However, if it detects an error, a linker
1005 * error will appear.
1007 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1008 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1010 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
1015 static void lttng_ust_notrace
__attribute__((destructor
))
1016 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1018 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1020 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1021 TRACEPOINT_PROVIDER
)) {
1024 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1027 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);