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) \
134 .signedness = lttng_is_signed_type(__typeof__(_value)), \
135 .value = lttng_is_signed_type(__typeof__(_value)) ? \
136 (long long) (_value) : (_value), \
139 .signedness = lttng_is_signed_type(__typeof__(_value)), \
140 .value = lttng_is_signed_type(__typeof__(_value)) ? \
141 (long long) (_value) : (_value), \
143 .string = (_string), \
146 /* Enumeration entry (range) */
147 #undef ctf_enum_range
148 #define ctf_enum_range(_string, _range_start, _range_end) \
151 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
152 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
153 (long long) (_range_start) : (_range_start), \
156 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
157 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
158 (long long) (_range_end) : (_range_end), \
160 .string = (_string), \
163 #undef TP_ENUM_VALUES
164 #define TP_ENUM_VALUES(...) \
167 #undef TRACEPOINT_ENUM
168 #define TRACEPOINT_ENUM(_provider, _name, _values) \
169 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
173 #include TRACEPOINT_INCLUDE
176 * Stage 1 of tracepoint event generation.
178 * Create event field type metadata section.
179 * Each event produce an array of fields.
182 /* Reset all macros within TRACEPOINT_EVENT */
183 #include <lttng/ust-tracepoint-event-reset.h>
184 #include <lttng/ust-tracepoint-event-write.h>
185 #include <lttng/ust-tracepoint-event-nowrite.h>
187 #undef _ctf_integer_ext
188 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
191 .type = __type_integer(_type, _byte_order, _base, none),\
192 .nowrite = _nowrite, \
196 #define _ctf_float(_type, _item, _src, _nowrite) \
199 .type = __type_float(_type), \
200 .nowrite = _nowrite, \
203 #undef _ctf_array_encoded
204 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
209 .atype = atype_array, \
214 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
219 .nowrite = _nowrite, \
222 #undef _ctf_sequence_encoded
223 #define _ctf_sequence_encoded(_type, _item, _src, \
224 _length_type, _src_length, _encoding, _nowrite, \
230 .atype = atype_sequence, \
235 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
236 .elem_type = __type_integer(_type, BYTE_ORDER, _elem_type_base, _encoding), \
240 .nowrite = _nowrite, \
244 #define _ctf_string(_item, _src, _nowrite) \
249 .atype = atype_string, \
252 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
255 .nowrite = _nowrite, \
259 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
263 .atype = atype_enum, \
267 .desc = &__enum_##_provider##_##_name, \
268 .container_type = { \
269 .size = sizeof(_type) * CHAR_BIT, \
270 .alignment = lttng_alignof(_type) * CHAR_BIT, \
271 .signedness = lttng_is_signed_type(_type), \
272 .reverse_byte_order = 0, \
274 .encoding = lttng_encode_none, \
280 .nowrite = _nowrite, \
284 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
286 #undef TRACEPOINT_EVENT_CLASS
287 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
288 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
292 #undef TRACEPOINT_ENUM
293 #define TRACEPOINT_ENUM(_provider, _name, _values) \
294 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
295 .name = #_provider "_" #_name, \
296 .entries = __enum_values__##_provider##_##_name, \
297 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name), \
300 #include TRACEPOINT_INCLUDE
303 * Stage 2 of tracepoint event generation.
305 * Create probe callback prototypes.
308 /* Reset all macros within TRACEPOINT_EVENT */
309 #include <lttng/ust-tracepoint-event-reset.h>
312 #define TP_ARGS(...) __VA_ARGS__
314 #undef TRACEPOINT_EVENT_CLASS
315 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
316 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
318 #include TRACEPOINT_INCLUDE
321 * Stage 3.0 of tracepoint event generation.
323 * Create static inline function that calculates event size.
326 /* Reset all macros within TRACEPOINT_EVENT */
327 #include <lttng/ust-tracepoint-event-reset.h>
328 #include <lttng/ust-tracepoint-event-write.h>
330 #undef _ctf_integer_ext
331 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
332 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
333 __event_len += sizeof(_type);
336 #define _ctf_float(_type, _item, _src, _nowrite) \
337 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
338 __event_len += sizeof(_type);
340 #undef _ctf_array_encoded
341 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
342 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
343 __event_len += sizeof(_type) * (_length);
345 #undef _ctf_sequence_encoded
346 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
347 _src_length, _encoding, _nowrite, _elem_type_base) \
348 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
349 __event_len += sizeof(_length_type); \
350 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
351 __dynamic_len[__dynamic_len_idx] = (_src_length); \
352 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
356 #define _ctf_string(_item, _src, _nowrite) \
357 __event_len += __dynamic_len[__dynamic_len_idx++] = \
358 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
361 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
362 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
365 #define TP_ARGS(...) __VA_ARGS__
368 #define TP_FIELDS(...) __VA_ARGS__
370 #undef TRACEPOINT_EVENT_CLASS
371 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
372 static inline lttng_ust_notrace \
373 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
375 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
377 size_t __event_len = 0; \
378 unsigned int __dynamic_len_idx = 0; \
381 (void) __dynamic_len_idx; /* don't warn if unused */ \
383 return __event_len; \
386 #include TRACEPOINT_INCLUDE
389 * Stage 3.1 of tracepoint event generation.
391 * Create static inline function that layout the filter stack data.
392 * We make both write and nowrite data available to the filter.
395 /* Reset all macros within TRACEPOINT_EVENT */
396 #include <lttng/ust-tracepoint-event-reset.h>
397 #include <lttng/ust-tracepoint-event-write.h>
398 #include <lttng/ust-tracepoint-event-nowrite.h>
400 #undef _ctf_integer_ext
401 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
402 if (lttng_is_signed_type(_type)) { \
403 int64_t __ctf_tmp_int64; \
404 switch (sizeof(_type)) { \
407 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
408 __ctf_tmp_int64 = (int64_t) __tmp.v; \
413 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
414 __ctf_tmp_int64 = (int64_t) __tmp.v; \
419 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
420 __ctf_tmp_int64 = (int64_t) __tmp.v; \
425 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
426 __ctf_tmp_int64 = (int64_t) __tmp.v; \
432 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
434 uint64_t __ctf_tmp_uint64; \
435 switch (sizeof(_type)) { \
438 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
439 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
444 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
445 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
450 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
451 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
456 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
457 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
463 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
465 __stack_data += sizeof(int64_t);
468 #define _ctf_float(_type, _item, _src, _nowrite) \
470 double __ctf_tmp_double = (double) (_type) (_src); \
471 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
472 __stack_data += sizeof(double); \
475 #undef _ctf_array_encoded
476 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
478 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
479 const void *__ctf_tmp_ptr = (_src); \
480 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
481 __stack_data += sizeof(unsigned long); \
482 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
483 __stack_data += sizeof(void *); \
486 #undef _ctf_sequence_encoded
487 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
488 _src_length, _encoding, _nowrite, _elem_type_base) \
490 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
491 const void *__ctf_tmp_ptr = (_src); \
492 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
493 __stack_data += sizeof(unsigned long); \
494 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
495 __stack_data += sizeof(void *); \
499 #define _ctf_string(_item, _src, _nowrite) \
501 const void *__ctf_tmp_ptr = \
502 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
503 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
504 __stack_data += sizeof(void *); \
508 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
509 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
512 #define TP_ARGS(...) __VA_ARGS__
515 #define TP_FIELDS(...) __VA_ARGS__
517 #undef TRACEPOINT_EVENT_CLASS
518 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
520 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
521 _TP_ARGS_DATA_PROTO(_args)) \
526 #include TRACEPOINT_INCLUDE
529 * Stage 4 of tracepoint event generation.
531 * Create static inline function that calculates event payload alignment.
534 /* Reset all macros within TRACEPOINT_EVENT */
535 #include <lttng/ust-tracepoint-event-reset.h>
536 #include <lttng/ust-tracepoint-event-write.h>
538 #undef _ctf_integer_ext
539 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
540 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
543 #define _ctf_float(_type, _item, _src, _nowrite) \
544 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
546 #undef _ctf_array_encoded
547 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
548 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
550 #undef _ctf_sequence_encoded
551 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
552 _src_length, _encoding, _nowrite, _elem_type_base) \
553 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
554 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
557 #define _ctf_string(_item, _src, _nowrite)
560 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
561 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
564 #define TP_ARGS(...) __VA_ARGS__
567 #define TP_FIELDS(...) __VA_ARGS__
569 #undef TRACEPOINT_EVENT_CLASS
570 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
571 static inline lttng_ust_notrace \
572 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
574 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
576 size_t __event_align = 1; \
578 return __event_align; \
581 #include TRACEPOINT_INCLUDE
585 * Stage 5 of tracepoint event generation.
587 * Create the probe function. This function calls event size calculation
588 * and writes event data into the buffer.
591 /* Reset all macros within TRACEPOINT_EVENT */
592 #include <lttng/ust-tracepoint-event-reset.h>
593 #include <lttng/ust-tracepoint-event-write.h>
595 #undef _ctf_integer_ext
596 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
598 _type __tmp = (_src); \
599 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
600 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
604 #define _ctf_float(_type, _item, _src, _nowrite) \
606 _type __tmp = (_src); \
607 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
608 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
611 #undef _ctf_array_encoded
612 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
613 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
614 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
616 #undef _ctf_sequence_encoded
617 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
618 _src_length, _encoding, _nowrite, _elem_type_base) \
620 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
621 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
622 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
624 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
625 __chan->ops->event_write(&__ctx, _src, \
626 sizeof(_type) * __get_dynamic_len(dest));
629 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
630 * tracepoint provider ABI implements event_strcpy. This dynamic check
631 * can be removed when the tracepoint provider ABI moves to 2.
633 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
634 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
638 #define _ctf_string(_item, _src, _nowrite) \
640 const char *__ctf_tmp_string = \
641 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
642 lib_ring_buffer_align_ctx(&__ctx, \
643 lttng_alignof(*__ctf_tmp_string)); \
644 if (__chan->ops->u.has_strcpy) \
645 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
646 __get_dynamic_len(dest)); \
648 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
649 __get_dynamic_len(dest)); \
654 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
655 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
657 /* Beware: this get len actually consumes the len value */
658 #undef __get_dynamic_len
659 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
662 #define TP_ARGS(...) __VA_ARGS__
665 #define TP_FIELDS(...) __VA_ARGS__
668 * For state dump, check that "session" argument (mandatory) matches the
669 * session this event belongs to. Ensures that we write state dump data only
670 * into the started session, not into all sessions.
672 #undef _TP_SESSION_CHECK
673 #ifdef TP_SESSION_CHECK
674 #define _TP_SESSION_CHECK(session, csession) (session == csession)
675 #else /* TP_SESSION_CHECK */
676 #define _TP_SESSION_CHECK(session, csession) 1
677 #endif /* TP_SESSION_CHECK */
680 * Use of __builtin_return_address(0) sometimes seems to cause stack
681 * corruption on 32-bit PowerPC. Disable this feature on that
682 * architecture for now by always using the NULL value for the ip
687 #define _TP_IP_PARAM(x) (x)
688 #else /* TP_IP_PARAM */
690 #if defined(__PPC__) && !defined(__PPC64__)
691 #define _TP_IP_PARAM(x) NULL
692 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
693 #define _TP_IP_PARAM(x) __builtin_return_address(0)
694 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
696 #endif /* TP_IP_PARAM */
699 * Using twice size for filter stack data to hold size and pointer for
700 * each field (worse case). For integers, max size required is 64-bit.
701 * Same for double-precision floats. Those fit within
702 * 2*sizeof(unsigned long) for all supported architectures.
703 * Perform UNION (||) of filter runtime list.
705 #undef TRACEPOINT_EVENT_CLASS
706 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
707 static lttng_ust_notrace \
708 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
710 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
712 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
713 struct lttng_channel *__chan = __event->chan; \
714 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
715 struct lttng_stack_ctx __lttng_ctx; \
716 size_t __event_len, __event_align; \
717 size_t __dynamic_len_idx = 0; \
719 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
720 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
725 (void) __dynamic_len_idx; /* don't warn if unused */ \
726 if (!_TP_SESSION_CHECK(session, __chan->session)) \
728 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
730 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
732 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
734 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
736 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
737 struct lttng_bytecode_runtime *bc_runtime; \
738 int __filter_record = __event->has_enablers_without_bytecode; \
740 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
741 _TP_ARGS_DATA_VAR(_args)); \
742 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
743 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
744 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
745 __filter_record = 1; \
747 if (caa_likely(!__filter_record)) \
750 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
751 _TP_ARGS_DATA_VAR(_args)); \
752 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
753 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
754 __lttng_ctx.event = __event; \
755 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
756 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
757 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
758 __event_align, -1, __chan->handle, &__lttng_ctx); \
759 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
760 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
764 __chan->ops->event_commit(&__ctx); \
767 #include TRACEPOINT_INCLUDE
769 #undef __get_dynamic_len
772 * Stage 5.1 of tracepoint event generation.
774 * Create probe signature
777 /* Reset all macros within TRACEPOINT_EVENT */
778 #include <lttng/ust-tracepoint-event-reset.h>
781 #define TP_ARGS(...) __VA_ARGS__
783 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
785 #undef TRACEPOINT_EVENT_CLASS
786 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
787 const char __tp_event_signature___##_provider##___##_name[] = \
788 _TP_EXTRACT_STRING2(_args);
790 #include TRACEPOINT_INCLUDE
792 #undef _TP_EXTRACT_STRING2
795 * Stage 6 of tracepoint event generation.
797 * Tracepoint loglevel mapping definition generation. We generate a
798 * symbol for each mapping for a provider/event to ensure at most a 1 to
799 * 1 mapping between events and loglevels. If the symbol is repeated,
800 * the compiler will complain.
803 /* Reset all macros within TRACEPOINT_EVENT */
804 #include <lttng/ust-tracepoint-event-reset.h>
806 #undef TRACEPOINT_LOGLEVEL
807 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
808 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
809 static const int *_loglevel___##__provider##___##__name = \
810 &_loglevel_value___##__provider##___##__name;
812 #include TRACEPOINT_INCLUDE
815 * Stage 6.1 of tracepoint event generation.
817 * Tracepoint UML URI info.
820 /* Reset all macros within TRACEPOINT_EVENT */
821 #include <lttng/ust-tracepoint-event-reset.h>
823 #undef TRACEPOINT_MODEL_EMF_URI
824 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
825 static const char *_model_emf_uri___##__provider##___##__name = __uri;
827 #include TRACEPOINT_INCLUDE
830 * Stage 7.1 of tracepoint event generation.
832 * Create events description structures. We use a weakref because
833 * loglevels are optional. If not declared, the event will point to the
834 * a loglevel that contains NULL.
837 /* Reset all macros within TRACEPOINT_EVENT */
838 #include <lttng/ust-tracepoint-event-reset.h>
840 #undef TRACEPOINT_EVENT_INSTANCE
841 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
843 __ref_loglevel___##_provider##___##_name \
844 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
845 static const char * \
846 __ref_model_emf_uri___##_provider##___##_name \
847 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
848 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
849 .name = #_provider ":" #_name, \
850 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
852 .fields = __event_fields___##_provider##___##_template, \
853 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
854 .loglevel = &__ref_loglevel___##_provider##___##_name, \
855 .signature = __tp_event_signature___##_provider##___##_template, \
858 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
863 #include TRACEPOINT_INCLUDE
866 * Stage 7.2 of tracepoint event generation.
868 * Create array of events.
871 /* Reset all macros within TRACEPOINT_EVENT */
872 #include <lttng/ust-tracepoint-event-reset.h>
874 #undef TRACEPOINT_EVENT_INSTANCE
875 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
876 &__event_desc___##_provider##_##_name,
878 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
879 #include TRACEPOINT_INCLUDE
884 * Stage 8 of tracepoint event generation.
886 * Create a toplevel descriptor for the whole probe.
889 /* non-const because list head will be modified when registered. */
890 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
891 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
892 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
893 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
894 .head
= { NULL
, NULL
},
895 .lazy_init_head
= { NULL
, NULL
},
897 .major
= LTTNG_UST_PROVIDER_MAJOR
,
898 .minor
= LTTNG_UST_PROVIDER_MINOR
,
901 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
904 * Stage 9 of tracepoint event generation.
906 * Register/unregister probes at module load/unload.
908 * Generate the constructor as an externally visible symbol for use when
909 * linking the probe statically.
911 * Register refcount is protected by libc dynamic loader mutex.
914 /* Reset all macros within TRACEPOINT_EVENT */
915 #include <lttng/ust-tracepoint-event-reset.h>
916 static void lttng_ust_notrace
__attribute__((constructor
))
917 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
919 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
923 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
924 TRACEPOINT_PROVIDER
)++) {
928 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
929 * static inline function that ensures every probe PROVIDER
930 * argument match the provider within which they appear. It
931 * calls empty static inline functions, and therefore has no
932 * runtime effect. However, if it detects an error, a linker
935 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
936 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
938 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
943 static void lttng_ust_notrace
__attribute__((destructor
))
944 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
946 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
948 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
949 TRACEPOINT_PROVIDER
)) {
952 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
955 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);