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>
33 #define __LTTNG_UST_NULL_STRING "(null)"
35 #undef tp_list_for_each_entry_rcu
36 #define tp_list_for_each_entry_rcu(pos, head, member) \
37 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
38 &pos->member != (head); \
39 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
42 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
43 * same arguments and having the same field layout.
45 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
46 * its own provider and name. It refers to a class (template).
48 * TRACEPOINT_EVENT declared both a class and an instance and does a
49 * direct mapping from the instance to the class.
52 #undef TRACEPOINT_EVENT
53 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
54 TRACEPOINT_EVENT_CLASS(_provider, _name, \
56 _TP_PARAMS(_fields)) \
57 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
61 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
63 #define _tp_max_t(type, x, y) \
67 __max1 > __max2 ? __max1: __max2; \
71 * Stage 0 of tracepoint event generation.
73 * Check that each TRACEPOINT_EVENT provider argument match the
74 * TRACEPOINT_PROVIDER by creating dummy callbacks.
77 /* Reset all macros within TRACEPOINT_EVENT */
78 #include <lttng/ust-tracepoint-event-reset.h>
80 static inline lttng_ust_notrace
81 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
83 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
87 #undef TRACEPOINT_EVENT_CLASS
88 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
89 __tracepoint_provider_mismatch_##_provider();
91 #undef TRACEPOINT_EVENT_INSTANCE
92 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
93 __tracepoint_provider_mismatch_##_provider();
95 static inline lttng_ust_notrace
96 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
98 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
100 #include TRACEPOINT_INCLUDE
104 * Stage 0.1 of tracepoint event generation.
106 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
107 * tracepoint name length limit.
110 /* Reset all macros within TRACEPOINT_EVENT */
111 #include <lttng/ust-tracepoint-event-reset.h>
113 #undef TRACEPOINT_EVENT_INSTANCE
114 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
116 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
117 __attribute__((unused)) = \
118 #_provider ":" #_name;
120 #include TRACEPOINT_INCLUDE
123 * Stage 0.9 of tracepoint event generation
125 * Unfolding the enums
127 #include <lttng/ust-tracepoint-event-reset.h>
129 /* Enumeration entry (single value) */
130 #undef ctf_enum_value
131 #define ctf_enum_value(_string, _value) \
132 { _value, _value, _string },
134 /* Enumeration entry (range) */
135 #undef ctf_enum_range
136 #define ctf_enum_range(_string, _range_start, _range_end) \
137 { _range_start, _range_end, _string },
139 #undef TP_ENUM_VALUES
140 #define TP_ENUM_VALUES(...) \
143 #undef TRACEPOINT_ENUM
144 #define TRACEPOINT_ENUM(_provider, _name, _values) \
145 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
149 #include TRACEPOINT_INCLUDE
152 * Stage 1 of tracepoint event generation.
154 * Create event field type metadata section.
155 * Each event produce an array of fields.
158 /* Reset all macros within TRACEPOINT_EVENT */
159 #include <lttng/ust-tracepoint-event-reset.h>
160 #include <lttng/ust-tracepoint-event-write.h>
161 #include <lttng/ust-tracepoint-event-nowrite.h>
163 #undef _ctf_integer_ext
164 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
167 .type = __type_integer(_type, _byte_order, _base, none),\
168 .nowrite = _nowrite, \
172 #define _ctf_float(_type, _item, _src, _nowrite) \
175 .type = __type_float(_type), \
176 .nowrite = _nowrite, \
179 #undef _ctf_array_encoded
180 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
185 .atype = atype_array, \
190 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
195 .nowrite = _nowrite, \
198 #undef _ctf_sequence_encoded
199 #define _ctf_sequence_encoded(_type, _item, _src, \
200 _length_type, _src_length, _encoding, _nowrite, \
206 .atype = atype_sequence, \
211 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
212 .elem_type = __type_integer(_type, BYTE_ORDER, _elem_type_base, _encoding), \
216 .nowrite = _nowrite, \
220 #define _ctf_string(_item, _src, _nowrite) \
225 .atype = atype_string, \
228 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
231 .nowrite = _nowrite, \
235 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
239 .atype = atype_enum, \
243 .desc = &__enum_##_provider##_##_name, \
244 .container_type = { \
245 .size = sizeof(_type) * CHAR_BIT, \
246 .alignment = lttng_alignof(_type) * CHAR_BIT, \
247 .signedness = lttng_is_signed_type(_type), \
248 .reverse_byte_order = 0, \
250 .encoding = lttng_encode_none, \
256 .nowrite = _nowrite, \
260 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
262 #undef TRACEPOINT_EVENT_CLASS
263 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
264 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
268 #undef TRACEPOINT_ENUM
269 #define TRACEPOINT_ENUM(_provider, _name, _values) \
270 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
271 .name = #_provider "_" #_name, \
272 .entries = __enum_values__##_provider##_##_name, \
273 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name), \
276 #include TRACEPOINT_INCLUDE
279 * Stage 2 of tracepoint event generation.
281 * Create probe callback prototypes.
284 /* Reset all macros within TRACEPOINT_EVENT */
285 #include <lttng/ust-tracepoint-event-reset.h>
288 #define TP_ARGS(...) __VA_ARGS__
290 #undef TRACEPOINT_EVENT_CLASS
291 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
292 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
294 #include TRACEPOINT_INCLUDE
297 * Stage 3.0 of tracepoint event generation.
299 * Create static inline function that calculates event size.
302 /* Reset all macros within TRACEPOINT_EVENT */
303 #include <lttng/ust-tracepoint-event-reset.h>
304 #include <lttng/ust-tracepoint-event-write.h>
306 #undef _ctf_integer_ext
307 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
308 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
309 __event_len += sizeof(_type);
312 #define _ctf_float(_type, _item, _src, _nowrite) \
313 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
314 __event_len += sizeof(_type);
316 #undef _ctf_array_encoded
317 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
318 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
319 __event_len += sizeof(_type) * (_length);
321 #undef _ctf_sequence_encoded
322 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
323 _src_length, _encoding, _nowrite, _elem_type_base) \
324 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
325 __event_len += sizeof(_length_type); \
326 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
327 __dynamic_len[__dynamic_len_idx] = (_src_length); \
328 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
332 #define _ctf_string(_item, _src, _nowrite) \
333 __event_len += __dynamic_len[__dynamic_len_idx++] = \
334 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
337 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
338 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
341 #define TP_ARGS(...) __VA_ARGS__
344 #define TP_FIELDS(...) __VA_ARGS__
346 #undef TRACEPOINT_EVENT_CLASS
347 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
348 static inline lttng_ust_notrace \
349 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
351 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
353 size_t __event_len = 0; \
354 unsigned int __dynamic_len_idx = 0; \
357 (void) __dynamic_len_idx; /* don't warn if unused */ \
359 return __event_len; \
362 #include TRACEPOINT_INCLUDE
365 * Stage 3.1 of tracepoint event generation.
367 * Create static inline function that layout the filter stack data.
368 * We make both write and nowrite data available to the filter.
371 /* Reset all macros within TRACEPOINT_EVENT */
372 #include <lttng/ust-tracepoint-event-reset.h>
373 #include <lttng/ust-tracepoint-event-write.h>
374 #include <lttng/ust-tracepoint-event-nowrite.h>
376 #undef _ctf_integer_ext
377 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
378 if (lttng_is_signed_type(_type)) { \
379 int64_t __ctf_tmp_int64; \
380 switch (sizeof(_type)) { \
383 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
384 __ctf_tmp_int64 = (int64_t) __tmp.v; \
389 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
390 __ctf_tmp_int64 = (int64_t) __tmp.v; \
395 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
396 __ctf_tmp_int64 = (int64_t) __tmp.v; \
401 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
402 __ctf_tmp_int64 = (int64_t) __tmp.v; \
408 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
410 uint64_t __ctf_tmp_uint64; \
411 switch (sizeof(_type)) { \
414 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
415 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
420 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
421 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
426 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
427 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
432 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
433 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
439 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
441 __stack_data += sizeof(int64_t);
444 #define _ctf_float(_type, _item, _src, _nowrite) \
446 double __ctf_tmp_double = (double) (_type) (_src); \
447 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
448 __stack_data += sizeof(double); \
451 #undef _ctf_array_encoded
452 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
454 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
455 const void *__ctf_tmp_ptr = (_src); \
456 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
457 __stack_data += sizeof(unsigned long); \
458 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
459 __stack_data += sizeof(void *); \
462 #undef _ctf_sequence_encoded
463 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
464 _src_length, _encoding, _nowrite, _elem_type_base) \
466 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
467 const void *__ctf_tmp_ptr = (_src); \
468 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
469 __stack_data += sizeof(unsigned long); \
470 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
471 __stack_data += sizeof(void *); \
475 #define _ctf_string(_item, _src, _nowrite) \
477 const void *__ctf_tmp_ptr = \
478 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
479 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
480 __stack_data += sizeof(void *); \
484 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
485 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
488 #define TP_ARGS(...) __VA_ARGS__
491 #define TP_FIELDS(...) __VA_ARGS__
493 #undef TRACEPOINT_EVENT_CLASS
494 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
496 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
497 _TP_ARGS_DATA_PROTO(_args)) \
502 #include TRACEPOINT_INCLUDE
505 * Stage 4 of tracepoint event generation.
507 * Create static inline function that calculates event payload alignment.
510 /* Reset all macros within TRACEPOINT_EVENT */
511 #include <lttng/ust-tracepoint-event-reset.h>
512 #include <lttng/ust-tracepoint-event-write.h>
514 #undef _ctf_integer_ext
515 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
516 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
519 #define _ctf_float(_type, _item, _src, _nowrite) \
520 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
522 #undef _ctf_array_encoded
523 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
524 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
526 #undef _ctf_sequence_encoded
527 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
528 _src_length, _encoding, _nowrite, _elem_type_base) \
529 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
530 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
533 #define _ctf_string(_item, _src, _nowrite)
536 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
537 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
540 #define TP_ARGS(...) __VA_ARGS__
543 #define TP_FIELDS(...) __VA_ARGS__
545 #undef TRACEPOINT_EVENT_CLASS
546 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
547 static inline lttng_ust_notrace \
548 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
550 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
552 size_t __event_align = 1; \
554 return __event_align; \
557 #include TRACEPOINT_INCLUDE
561 * Stage 5 of tracepoint event generation.
563 * Create the probe function. This function calls event size calculation
564 * and writes event data into the buffer.
567 /* Reset all macros within TRACEPOINT_EVENT */
568 #include <lttng/ust-tracepoint-event-reset.h>
569 #include <lttng/ust-tracepoint-event-write.h>
571 #undef _ctf_integer_ext
572 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
574 _type __tmp = (_src); \
575 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
576 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
580 #define _ctf_float(_type, _item, _src, _nowrite) \
582 _type __tmp = (_src); \
583 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
584 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
587 #undef _ctf_array_encoded
588 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
589 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
590 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
592 #undef _ctf_sequence_encoded
593 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
594 _src_length, _encoding, _nowrite, _elem_type_base) \
596 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
597 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
598 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
600 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
601 __chan->ops->event_write(&__ctx, _src, \
602 sizeof(_type) * __get_dynamic_len(dest));
605 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
606 * tracepoint provider ABI implements event_strcpy. This dynamic check
607 * can be removed when the tracepoint provider ABI moves to 2.
609 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
610 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
614 #define _ctf_string(_item, _src, _nowrite) \
616 const char *__ctf_tmp_string = \
617 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
618 lib_ring_buffer_align_ctx(&__ctx, \
619 lttng_alignof(*__ctf_tmp_string)); \
620 if (__chan->ops->u.has_strcpy) \
621 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
622 __get_dynamic_len(dest)); \
624 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
625 __get_dynamic_len(dest)); \
630 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
631 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
633 /* Beware: this get len actually consumes the len value */
634 #undef __get_dynamic_len
635 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
638 #define TP_ARGS(...) __VA_ARGS__
641 #define TP_FIELDS(...) __VA_ARGS__
644 * For state dump, check that "session" argument (mandatory) matches the
645 * session this event belongs to. Ensures that we write state dump data only
646 * into the started session, not into all sessions.
648 #undef _TP_SESSION_CHECK
649 #ifdef TP_SESSION_CHECK
650 #define _TP_SESSION_CHECK(session, csession) (session == csession)
651 #else /* TP_SESSION_CHECK */
652 #define _TP_SESSION_CHECK(session, csession) 1
653 #endif /* TP_SESSION_CHECK */
656 * Use of __builtin_return_address(0) sometimes seems to cause stack
657 * corruption on 32-bit PowerPC. Disable this feature on that
658 * architecture for now by always using the NULL value for the ip
663 #define _TP_IP_PARAM(x) (x)
664 #else /* TP_IP_PARAM */
666 #if defined(__PPC__) && !defined(__PPC64__)
667 #define _TP_IP_PARAM(x) NULL
668 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
669 #define _TP_IP_PARAM(x) __builtin_return_address(0)
670 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
672 #endif /* TP_IP_PARAM */
675 * Using twice size for filter stack data to hold size and pointer for
676 * each field (worse case). For integers, max size required is 64-bit.
677 * Same for double-precision floats. Those fit within
678 * 2*sizeof(unsigned long) for all supported architectures.
679 * Perform UNION (||) of filter runtime list.
681 #undef TRACEPOINT_EVENT_CLASS
682 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
683 static lttng_ust_notrace \
684 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
686 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
688 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
689 struct lttng_channel *__chan = __event->chan; \
690 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
691 struct lttng_stack_ctx __lttng_ctx; \
692 size_t __event_len, __event_align; \
693 size_t __dynamic_len_idx = 0; \
695 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
696 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
701 (void) __dynamic_len_idx; /* don't warn if unused */ \
702 if (!_TP_SESSION_CHECK(session, __chan->session)) \
704 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
706 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
708 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
710 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
712 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
713 struct lttng_bytecode_runtime *bc_runtime; \
714 int __filter_record = __event->has_enablers_without_bytecode; \
716 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
717 _TP_ARGS_DATA_VAR(_args)); \
718 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
719 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
720 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
721 __filter_record = 1; \
723 if (caa_likely(!__filter_record)) \
726 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
727 _TP_ARGS_DATA_VAR(_args)); \
728 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
729 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
730 __lttng_ctx.event = __event; \
731 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
732 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
733 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
734 __event_align, -1, __chan->handle, &__lttng_ctx); \
735 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
736 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
740 __chan->ops->event_commit(&__ctx); \
743 #include TRACEPOINT_INCLUDE
745 #undef __get_dynamic_len
748 * Stage 5.1 of tracepoint event generation.
750 * Create probe signature
753 /* Reset all macros within TRACEPOINT_EVENT */
754 #include <lttng/ust-tracepoint-event-reset.h>
757 #define TP_ARGS(...) __VA_ARGS__
759 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
761 #undef TRACEPOINT_EVENT_CLASS
762 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
763 const char __tp_event_signature___##_provider##___##_name[] = \
764 _TP_EXTRACT_STRING2(_args);
766 #include TRACEPOINT_INCLUDE
768 #undef _TP_EXTRACT_STRING2
771 * Stage 6 of tracepoint event generation.
773 * Tracepoint loglevel mapping definition generation. We generate a
774 * symbol for each mapping for a provider/event to ensure at most a 1 to
775 * 1 mapping between events and loglevels. If the symbol is repeated,
776 * the compiler will complain.
779 /* Reset all macros within TRACEPOINT_EVENT */
780 #include <lttng/ust-tracepoint-event-reset.h>
782 #undef TRACEPOINT_LOGLEVEL
783 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
784 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
785 static const int *_loglevel___##__provider##___##__name = \
786 &_loglevel_value___##__provider##___##__name;
788 #include TRACEPOINT_INCLUDE
791 * Stage 6.1 of tracepoint event generation.
793 * Tracepoint UML URI info.
796 /* Reset all macros within TRACEPOINT_EVENT */
797 #include <lttng/ust-tracepoint-event-reset.h>
799 #undef TRACEPOINT_MODEL_EMF_URI
800 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
801 static const char *_model_emf_uri___##__provider##___##__name = __uri;
803 #include TRACEPOINT_INCLUDE
806 * Stage 7.1 of tracepoint event generation.
808 * Create events description structures. We use a weakref because
809 * loglevels are optional. If not declared, the event will point to the
810 * a loglevel that contains NULL.
813 /* Reset all macros within TRACEPOINT_EVENT */
814 #include <lttng/ust-tracepoint-event-reset.h>
816 #undef TRACEPOINT_EVENT_INSTANCE
817 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
819 __ref_loglevel___##_provider##___##_name \
820 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
821 static const char * \
822 __ref_model_emf_uri___##_provider##___##_name \
823 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
824 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
825 .name = #_provider ":" #_name, \
826 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
828 .fields = __event_fields___##_provider##___##_template, \
829 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
830 .loglevel = &__ref_loglevel___##_provider##___##_name, \
831 .signature = __tp_event_signature___##_provider##___##_template, \
834 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
839 #include TRACEPOINT_INCLUDE
842 * Stage 7.2 of tracepoint event generation.
844 * Create array of events.
847 /* Reset all macros within TRACEPOINT_EVENT */
848 #include <lttng/ust-tracepoint-event-reset.h>
850 #undef TRACEPOINT_EVENT_INSTANCE
851 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
852 &__event_desc___##_provider##_##_name,
854 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
855 #include TRACEPOINT_INCLUDE
860 * Stage 8 of tracepoint event generation.
862 * Create a toplevel descriptor for the whole probe.
865 /* non-const because list head will be modified when registered. */
866 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
867 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
868 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
869 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
870 .head
= { NULL
, NULL
},
871 .lazy_init_head
= { NULL
, NULL
},
873 .major
= LTTNG_UST_PROVIDER_MAJOR
,
874 .minor
= LTTNG_UST_PROVIDER_MINOR
,
877 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
880 * Stage 9 of tracepoint event generation.
882 * Register/unregister probes at module load/unload.
884 * Generate the constructor as an externally visible symbol for use when
885 * linking the probe statically.
887 * Register refcount is protected by libc dynamic loader mutex.
890 /* Reset all macros within TRACEPOINT_EVENT */
891 #include <lttng/ust-tracepoint-event-reset.h>
892 static void lttng_ust_notrace
__attribute__((constructor
))
893 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
895 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
899 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
900 TRACEPOINT_PROVIDER
)++) {
904 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
905 * static inline function that ensures every probe PROVIDER
906 * argument match the provider within which they appear. It
907 * calls empty static inline functions, and therefore has no
908 * runtime effect. However, if it detects an error, a linker
911 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
912 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
914 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
919 static void lttng_ust_notrace
__attribute__((destructor
))
920 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
922 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
924 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
925 TRACEPOINT_PROVIDER
)) {
928 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
931 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);