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
26 #include <urcu/compiler.h>
27 #include <urcu/rculist.h>
28 #include <lttng/ust-events.h>
29 #include <lttng/ringbuffer-config.h>
30 #include <lttng/ust-compiler.h>
31 #include <lttng/tracepoint.h>
35 #define __LTTNG_UST_NULL_STRING "(null)"
37 #undef tp_list_for_each_entry_rcu
38 #define tp_list_for_each_entry_rcu(pos, head, member) \
39 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
40 &pos->member != (head); \
41 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
44 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
45 * same arguments and having the same field layout.
47 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
48 * its own provider and name. It refers to a class (template).
50 * TRACEPOINT_EVENT declared both a class and an instance and does a
51 * direct mapping from the instance to the class.
54 #undef TRACEPOINT_EVENT
55 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
56 TRACEPOINT_EVENT_CLASS(_provider, _name, \
58 _TP_PARAMS(_fields)) \
59 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
63 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
65 #define _tp_max_t(type, x, y) \
69 __max1 > __max2 ? __max1: __max2; \
73 * Stage 0 of tracepoint event generation.
75 * Check that each TRACEPOINT_EVENT provider argument match the
76 * TRACEPOINT_PROVIDER by creating dummy callbacks.
79 /* Reset all macros within TRACEPOINT_EVENT */
80 #include <lttng/ust-tracepoint-event-reset.h>
82 static inline lttng_ust_notrace
83 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
85 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
89 #undef TRACEPOINT_EVENT_CLASS
90 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
91 __tracepoint_provider_mismatch_##_provider();
93 #undef TRACEPOINT_EVENT_INSTANCE
94 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
95 __tracepoint_provider_mismatch_##_provider();
97 static inline lttng_ust_notrace
98 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
100 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
102 #include TRACEPOINT_INCLUDE
106 * Stage 0.1 of tracepoint event generation.
108 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
109 * tracepoint name length limit.
112 /* Reset all macros within TRACEPOINT_EVENT */
113 #include <lttng/ust-tracepoint-event-reset.h>
115 #undef TRACEPOINT_EVENT_INSTANCE
116 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
118 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
119 __attribute__((unused)) = \
120 #_provider ":" #_name;
122 #include TRACEPOINT_INCLUDE
125 * Stage 0.2 of tracepoint event generation.
127 * Create dummy trace prototypes for each event class, and for each used
128 * template. This will allow checking whether the prototypes from the
129 * class and the instance using the class actually match.
132 /* Reset all macros within TRACEPOINT_EVENT */
133 #include <lttng/ust-tracepoint-event-reset.h>
136 #define TP_ARGS(...) __VA_ARGS__
138 #undef TRACEPOINT_EVENT_INSTANCE
139 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
140 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
142 #undef TRACEPOINT_EVENT_CLASS
143 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
144 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
146 #include TRACEPOINT_INCLUDE
149 * Stage 0.9 of tracepoint event generation
151 * Unfolding the enums
153 #include <lttng/ust-tracepoint-event-reset.h>
155 /* Enumeration entry (single value) */
156 #undef ctf_enum_value
157 #define ctf_enum_value(_string, _value) \
160 .value = lttng_is_signed_type(__typeof__(_value)) ? \
161 (long long) (_value) : (_value), \
162 .signedness = lttng_is_signed_type(__typeof__(_value)), \
165 .value = lttng_is_signed_type(__typeof__(_value)) ? \
166 (long long) (_value) : (_value), \
167 .signedness = lttng_is_signed_type(__typeof__(_value)), \
169 .string = (_string), \
172 /* Enumeration entry (range) */
173 #undef ctf_enum_range
174 #define ctf_enum_range(_string, _range_start, _range_end) \
177 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
178 (long long) (_range_start) : (_range_start), \
179 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
182 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
183 (long long) (_range_end) : (_range_end), \
184 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
186 .string = (_string), \
189 /* Enumeration entry (automatic value; follows the rules of CTF) */
191 #define ctf_enum_auto(_string) \
201 .string = (_string), \
204 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
209 #undef TP_ENUM_VALUES
210 #define TP_ENUM_VALUES(...) \
213 #undef TRACEPOINT_ENUM
214 #define TRACEPOINT_ENUM(_provider, _name, _values) \
215 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
217 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
220 #include TRACEPOINT_INCLUDE
223 * Stage 1 of tracepoint event generation.
225 * Create event field type metadata section.
226 * Each event produce an array of fields.
229 /* Reset all macros within TRACEPOINT_EVENT */
230 #include <lttng/ust-tracepoint-event-reset.h>
231 #include <lttng/ust-tracepoint-event-write.h>
232 #include <lttng/ust-tracepoint-event-nowrite.h>
234 #undef _ctf_integer_ext
235 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
238 .type = __type_integer(_type, _byte_order, _base, none),\
239 .nowrite = _nowrite, \
243 #define _ctf_float(_type, _item, _src, _nowrite) \
246 .type = __type_float(_type), \
247 .nowrite = _nowrite, \
250 #undef _ctf_array_encoded
251 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
252 _length, _encoding, _nowrite, \
258 .atype = atype_array, \
263 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
268 .nowrite = _nowrite, \
271 #undef _ctf_sequence_encoded
272 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
273 _length_type, _src_length, _encoding, _nowrite, \
279 .atype = atype_sequence, \
284 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
285 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
289 .nowrite = _nowrite, \
293 #define _ctf_string(_item, _src, _nowrite) \
298 .atype = atype_string, \
301 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
304 .nowrite = _nowrite, \
308 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
312 .atype = atype_enum, \
316 .desc = &__enum_##_provider##_##_name, \
317 .container_type = { \
318 .size = sizeof(_type) * CHAR_BIT, \
319 .alignment = lttng_alignof(_type) * CHAR_BIT, \
320 .signedness = lttng_is_signed_type(_type), \
321 .reverse_byte_order = 0, \
323 .encoding = lttng_encode_none, \
329 .nowrite = _nowrite, \
333 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
335 #undef TRACEPOINT_EVENT_CLASS
336 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
337 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
339 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
342 #undef TRACEPOINT_ENUM
343 #define TRACEPOINT_ENUM(_provider, _name, _values) \
344 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
345 .name = #_provider "_" #_name, \
346 .entries = __enum_values__##_provider##_##_name, \
347 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
350 #include TRACEPOINT_INCLUDE
353 * Stage 2 of tracepoint event generation.
355 * Create probe callback prototypes.
358 /* Reset all macros within TRACEPOINT_EVENT */
359 #include <lttng/ust-tracepoint-event-reset.h>
362 #define TP_ARGS(...) __VA_ARGS__
364 #undef TRACEPOINT_EVENT_CLASS
365 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
366 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
368 #include TRACEPOINT_INCLUDE
371 * Stage 3.0 of tracepoint event generation.
373 * Create static inline function that calculates event size.
376 /* Reset all macros within TRACEPOINT_EVENT */
377 #include <lttng/ust-tracepoint-event-reset.h>
378 #include <lttng/ust-tracepoint-event-write.h>
380 #undef _ctf_integer_ext
381 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
382 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
383 __event_len += sizeof(_type);
386 #define _ctf_float(_type, _item, _src, _nowrite) \
387 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
388 __event_len += sizeof(_type);
390 #undef _ctf_array_encoded
391 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
392 _nowrite, _elem_type_base) \
393 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
394 __event_len += sizeof(_type) * (_length);
396 #undef _ctf_sequence_encoded
397 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
398 _src_length, _encoding, _nowrite, _elem_type_base) \
399 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
400 __event_len += sizeof(_length_type); \
401 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
402 __dynamic_len[__dynamic_len_idx] = (_src_length); \
403 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
407 #define _ctf_string(_item, _src, _nowrite) \
408 __event_len += __dynamic_len[__dynamic_len_idx++] = \
409 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
412 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
413 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
416 #define TP_ARGS(...) __VA_ARGS__
419 #define TP_FIELDS(...) __VA_ARGS__
421 #undef TRACEPOINT_EVENT_CLASS
422 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
423 static inline lttng_ust_notrace \
424 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
426 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
428 size_t __event_len = 0; \
429 unsigned int __dynamic_len_idx = 0; \
432 (void) __dynamic_len_idx; /* don't warn if unused */ \
434 return __event_len; \
437 #include TRACEPOINT_INCLUDE
440 * Stage 3.1 of tracepoint event generation.
442 * Create static inline function that layout the filter stack data.
443 * We make both write and nowrite data available to the filter.
446 /* Reset all macros within TRACEPOINT_EVENT */
447 #include <lttng/ust-tracepoint-event-reset.h>
448 #include <lttng/ust-tracepoint-event-write.h>
449 #include <lttng/ust-tracepoint-event-nowrite.h>
451 #undef _ctf_integer_ext
452 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
453 if (lttng_is_signed_type(_type)) { \
454 int64_t __ctf_tmp_int64; \
455 switch (sizeof(_type)) { \
458 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
459 __ctf_tmp_int64 = (int64_t) __tmp.v; \
464 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
465 if (_byte_order != BYTE_ORDER) \
466 __tmp.v = bswap_16(__tmp.v); \
467 __ctf_tmp_int64 = (int64_t) __tmp.v; \
472 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
473 if (_byte_order != BYTE_ORDER) \
474 __tmp.v = bswap_32(__tmp.v); \
475 __ctf_tmp_int64 = (int64_t) __tmp.v; \
480 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
481 if (_byte_order != BYTE_ORDER) \
482 __tmp.v = bswap_64(__tmp.v); \
483 __ctf_tmp_int64 = (int64_t) __tmp.v; \
489 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
491 uint64_t __ctf_tmp_uint64; \
492 switch (sizeof(_type)) { \
495 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
496 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
501 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
502 if (_byte_order != BYTE_ORDER) \
503 __tmp.v = bswap_16(__tmp.v); \
504 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
509 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
510 if (_byte_order != BYTE_ORDER) \
511 __tmp.v = bswap_32(__tmp.v); \
512 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
517 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
518 if (_byte_order != BYTE_ORDER) \
519 __tmp.v = bswap_64(__tmp.v); \
520 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
526 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
528 __stack_data += sizeof(int64_t);
531 #define _ctf_float(_type, _item, _src, _nowrite) \
533 double __ctf_tmp_double = (double) (_type) (_src); \
534 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
535 __stack_data += sizeof(double); \
538 #undef _ctf_array_encoded
539 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
540 _encoding, _nowrite, _elem_type_base) \
542 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
543 const void *__ctf_tmp_ptr = (_src); \
544 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
545 __stack_data += sizeof(unsigned long); \
546 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
547 __stack_data += sizeof(void *); \
550 #undef _ctf_sequence_encoded
551 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
552 _src_length, _encoding, _nowrite, _elem_type_base) \
554 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
555 const void *__ctf_tmp_ptr = (_src); \
556 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
557 __stack_data += sizeof(unsigned long); \
558 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
559 __stack_data += sizeof(void *); \
563 #define _ctf_string(_item, _src, _nowrite) \
565 const void *__ctf_tmp_ptr = \
566 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
567 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
568 __stack_data += sizeof(void *); \
572 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
573 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
576 #define TP_ARGS(...) __VA_ARGS__
579 #define TP_FIELDS(...) __VA_ARGS__
581 #undef TRACEPOINT_EVENT_CLASS
582 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
584 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
585 _TP_ARGS_DATA_PROTO(_args)) \
590 #include TRACEPOINT_INCLUDE
593 * Stage 4 of tracepoint event generation.
595 * Create static inline function that calculates event payload alignment.
598 /* Reset all macros within TRACEPOINT_EVENT */
599 #include <lttng/ust-tracepoint-event-reset.h>
600 #include <lttng/ust-tracepoint-event-write.h>
602 #undef _ctf_integer_ext
603 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
604 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
607 #define _ctf_float(_type, _item, _src, _nowrite) \
608 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
610 #undef _ctf_array_encoded
611 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
612 _encoding, _nowrite, _elem_type_base) \
613 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
615 #undef _ctf_sequence_encoded
616 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
617 _src_length, _encoding, _nowrite, _elem_type_base) \
618 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
619 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
622 #define _ctf_string(_item, _src, _nowrite)
625 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
626 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
629 #define TP_ARGS(...) __VA_ARGS__
632 #define TP_FIELDS(...) __VA_ARGS__
634 #undef TRACEPOINT_EVENT_CLASS
635 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
636 static inline lttng_ust_notrace \
637 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
639 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
641 size_t __event_align = 1; \
643 return __event_align; \
646 #include TRACEPOINT_INCLUDE
650 * Stage 5 of tracepoint event generation.
652 * Create the probe function. This function calls event size calculation
653 * and writes event data into the buffer.
656 /* Reset all macros within TRACEPOINT_EVENT */
657 #include <lttng/ust-tracepoint-event-reset.h>
658 #include <lttng/ust-tracepoint-event-write.h>
660 #undef _ctf_integer_ext
661 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
663 _type __tmp = (_src); \
664 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
665 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
669 #define _ctf_float(_type, _item, _src, _nowrite) \
671 _type __tmp = (_src); \
672 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
673 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
676 #undef _ctf_array_encoded
677 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
678 _encoding, _nowrite, _elem_type_base) \
679 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
680 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
682 #undef _ctf_sequence_encoded
683 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
684 _src_length, _encoding, _nowrite, _elem_type_base) \
686 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
687 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
688 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
690 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
691 __chan->ops->event_write(&__ctx, _src, \
692 sizeof(_type) * __get_dynamic_len(dest));
695 #define _ctf_string(_item, _src, _nowrite) \
697 const char *__ctf_tmp_string = \
698 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
699 lib_ring_buffer_align_ctx(&__ctx, \
700 lttng_alignof(*__ctf_tmp_string)); \
701 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
702 __get_dynamic_len(dest)); \
707 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
708 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
710 /* Beware: this get len actually consumes the len value */
711 #undef __get_dynamic_len
712 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
715 #define TP_ARGS(...) __VA_ARGS__
718 #define TP_FIELDS(...) __VA_ARGS__
721 * For state dump, check that "session" argument (mandatory) matches the
722 * session this event belongs to. Ensures that we write state dump data only
723 * into the started session, not into all sessions.
725 #undef _TP_SESSION_CHECK
726 #ifdef TP_SESSION_CHECK
727 #define _TP_SESSION_CHECK(session, csession) (session == csession)
728 #else /* TP_SESSION_CHECK */
729 #define _TP_SESSION_CHECK(session, csession) 1
730 #endif /* TP_SESSION_CHECK */
733 * Use of __builtin_return_address(0) sometimes seems to cause stack
734 * corruption on 32-bit PowerPC. Disable this feature on that
735 * architecture for now by always using the NULL value for the ip
740 #define _TP_IP_PARAM(x) (x)
741 #else /* TP_IP_PARAM */
743 #if defined(__PPC__) && !defined(__PPC64__)
744 #define _TP_IP_PARAM(x) NULL
745 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
746 #define _TP_IP_PARAM(x) __builtin_return_address(0)
747 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
749 #endif /* TP_IP_PARAM */
752 * Using twice size for filter stack data to hold size and pointer for
753 * each field (worse case). For integers, max size required is 64-bit.
754 * Same for double-precision floats. Those fit within
755 * 2*sizeof(unsigned long) for all supported architectures.
756 * Perform UNION (||) of filter runtime list.
758 #undef TRACEPOINT_EVENT_CLASS
759 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
760 static lttng_ust_notrace \
761 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
763 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
765 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
766 struct lttng_channel *__chan = __event->chan; \
767 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
768 struct lttng_stack_ctx __lttng_ctx; \
769 size_t __event_len, __event_align; \
770 size_t __dynamic_len_idx = 0; \
771 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
773 size_t __dynamic_len[__num_fields]; \
774 char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
779 (void) __dynamic_len_idx; /* don't warn if unused */ \
780 if (!_TP_SESSION_CHECK(session, __chan->session)) \
782 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
784 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
786 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
788 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
790 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
791 struct lttng_bytecode_runtime *bc_runtime; \
792 int __filter_record = __event->has_enablers_without_bytecode; \
794 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
795 _TP_ARGS_DATA_VAR(_args)); \
796 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
797 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
798 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \
799 __filter_record = 1; \
803 if (caa_likely(!__filter_record)) \
806 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
807 _TP_ARGS_DATA_VAR(_args)); \
808 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
809 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
810 __lttng_ctx.event = __event; \
811 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
812 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
813 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
814 __event_align, -1, __chan->handle, &__lttng_ctx); \
815 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
816 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
820 __chan->ops->event_commit(&__ctx); \
823 #include TRACEPOINT_INCLUDE
825 #undef __get_dynamic_len
828 * Stage 5.1 of tracepoint event generation.
830 * Create probe signature
833 /* Reset all macros within TRACEPOINT_EVENT */
834 #include <lttng/ust-tracepoint-event-reset.h>
837 #define TP_ARGS(...) __VA_ARGS__
839 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
841 #undef TRACEPOINT_EVENT_CLASS
842 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
843 static const char __tp_event_signature___##_provider##___##_name[] = \
844 _TP_EXTRACT_STRING2(_args);
846 #include TRACEPOINT_INCLUDE
848 #undef _TP_EXTRACT_STRING2
851 * Stage 6 of tracepoint event generation.
853 * Tracepoint loglevel mapping definition generation. We generate a
854 * symbol for each mapping for a provider/event to ensure at most a 1 to
855 * 1 mapping between events and loglevels. If the symbol is repeated,
856 * the compiler will complain.
859 /* Reset all macros within TRACEPOINT_EVENT */
860 #include <lttng/ust-tracepoint-event-reset.h>
863 * Declare _loglevel___##__provider##___##__name as non-static, with
864 * hidden visibility for c++ handling of weakref. We do a weakref to the
865 * symbol in a later stage, which requires that the symbol is not
869 #define LTTNG_TP_EXTERN_C extern "C"
871 #define LTTNG_TP_EXTERN_C
874 #undef TRACEPOINT_LOGLEVEL
875 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
876 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
877 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
878 __attribute__((visibility("hidden"))) = \
879 &_loglevel_value___##__provider##___##__name;
881 #include TRACEPOINT_INCLUDE
883 #undef LTTNG_TP_EXTERN_C
886 * Stage 6.1 of tracepoint event generation.
888 * Tracepoint UML URI info.
891 /* Reset all macros within TRACEPOINT_EVENT */
892 #include <lttng/ust-tracepoint-event-reset.h>
895 * Declare _model_emf_uri___##__provider##___##__name as non-static,
896 * with hidden visibility for c++ handling of weakref. We do a weakref
897 * to the symbol in a later stage, which requires that the symbol is not
901 #define LTTNG_TP_EXTERN_C extern "C"
903 #define LTTNG_TP_EXTERN_C
906 #undef TRACEPOINT_MODEL_EMF_URI
907 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
908 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
909 __attribute__((visibility("hidden"))) = __uri; \
911 #include TRACEPOINT_INCLUDE
913 #undef LTTNG_TP_EXTERN_C
916 * Stage 7.1 of tracepoint event generation.
918 * Create events description structures. We use a weakref because
919 * loglevels are optional. If not declared, the event will point to the
920 * a loglevel that contains NULL.
923 /* Reset all macros within TRACEPOINT_EVENT */
924 #include <lttng/ust-tracepoint-event-reset.h>
926 #undef TRACEPOINT_EVENT_INSTANCE
927 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
929 __ref_loglevel___##_provider##___##_name \
930 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
931 static const char * \
932 __ref_model_emf_uri___##_provider##___##_name \
933 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
934 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
935 .name = #_provider ":" #_name, \
936 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
938 .fields = __event_fields___##_provider##___##_template, \
939 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
940 .loglevel = &__ref_loglevel___##_provider##___##_name, \
941 .signature = __tp_event_signature___##_provider##___##_template, \
944 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
949 #include TRACEPOINT_INCLUDE
952 * Stage 7.2 of tracepoint event generation.
954 * Create array of events.
957 /* Reset all macros within TRACEPOINT_EVENT */
958 #include <lttng/ust-tracepoint-event-reset.h>
960 #undef TRACEPOINT_EVENT_INSTANCE
961 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
962 &__event_desc___##_provider##_##_name,
964 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
965 #include TRACEPOINT_INCLUDE
966 NULL
, /* Dummy, C99 forbids 0-len array. */
971 * Stage 8 of tracepoint event generation.
973 * Create a toplevel descriptor for the whole probe.
976 /* non-const because list head will be modified when registered. */
977 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
978 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
979 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
980 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)) - 1,
981 .head
= { NULL
, NULL
},
982 .lazy_init_head
= { NULL
, NULL
},
984 .major
= LTTNG_UST_PROVIDER_MAJOR
,
985 .minor
= LTTNG_UST_PROVIDER_MINOR
,
988 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
991 * Stage 9 of tracepoint event generation.
993 * Register/unregister probes at module load/unload.
995 * Generate the constructor as an externally visible symbol for use when
996 * linking the probe statically.
998 * Register refcount is protected by libc dynamic loader mutex.
1001 /* Reset all macros within TRACEPOINT_EVENT */
1002 #include <lttng/ust-tracepoint-event-reset.h>
1003 static void lttng_ust_notrace
__attribute__((constructor
))
1004 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
1006 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
1010 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1011 TRACEPOINT_PROVIDER
)++) {
1015 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1016 * static inline function that ensures every probe PROVIDER
1017 * argument match the provider within which they appear. It
1018 * calls empty static inline functions, and therefore has no
1019 * runtime effect. However, if it detects an error, a linker
1020 * error will appear.
1022 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
1023 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1025 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret
);
1030 static void lttng_ust_notrace
__attribute__((destructor
))
1031 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
1033 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
1035 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
1036 TRACEPOINT_PROVIDER
)) {
1039 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
1042 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);