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 .signedness = lttng_is_signed_type(__typeof__(_value)), \
136 .value = lttng_is_signed_type(__typeof__(_value)) ? \
137 (long long) (_value) : (_value), \
140 .signedness = lttng_is_signed_type(__typeof__(_value)), \
141 .value = lttng_is_signed_type(__typeof__(_value)) ? \
142 (long long) (_value) : (_value), \
144 .string = (_string), \
147 /* Enumeration entry (range) */
148 #undef ctf_enum_range
149 #define ctf_enum_range(_string, _range_start, _range_end) \
152 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
153 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
154 (long long) (_range_start) : (_range_start), \
157 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
158 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
159 (long long) (_range_end) : (_range_end), \
161 .string = (_string), \
164 #undef TP_ENUM_VALUES
165 #define TP_ENUM_VALUES(...) \
168 #undef TRACEPOINT_ENUM
169 #define TRACEPOINT_ENUM(_provider, _name, _values) \
170 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
174 #include TRACEPOINT_INCLUDE
177 * Stage 1 of tracepoint event generation.
179 * Create event field type metadata section.
180 * Each event produce an array of fields.
183 /* Reset all macros within TRACEPOINT_EVENT */
184 #include <lttng/ust-tracepoint-event-reset.h>
185 #include <lttng/ust-tracepoint-event-write.h>
186 #include <lttng/ust-tracepoint-event-nowrite.h>
188 #undef _ctf_integer_ext
189 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
192 .type = __type_integer(_type, _byte_order, _base, none),\
193 .nowrite = _nowrite, \
197 #define _ctf_float(_type, _item, _src, _nowrite) \
200 .type = __type_float(_type), \
201 .nowrite = _nowrite, \
204 #undef _ctf_array_encoded
205 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
206 _length, _encoding, _nowrite, \
212 .atype = atype_array, \
217 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
222 .nowrite = _nowrite, \
225 #undef _ctf_sequence_encoded
226 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
227 _length_type, _src_length, _encoding, _nowrite, \
233 .atype = atype_sequence, \
238 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
239 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
243 .nowrite = _nowrite, \
247 #define _ctf_string(_item, _src, _nowrite) \
252 .atype = atype_string, \
255 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
258 .nowrite = _nowrite, \
262 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
266 .atype = atype_enum, \
270 .desc = &__enum_##_provider##_##_name, \
271 .container_type = { \
272 .size = sizeof(_type) * CHAR_BIT, \
273 .alignment = lttng_alignof(_type) * CHAR_BIT, \
274 .signedness = lttng_is_signed_type(_type), \
275 .reverse_byte_order = 0, \
277 .encoding = lttng_encode_none, \
283 .nowrite = _nowrite, \
287 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
289 #undef TRACEPOINT_EVENT_CLASS
290 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
291 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
295 #undef TRACEPOINT_ENUM
296 #define TRACEPOINT_ENUM(_provider, _name, _values) \
297 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
298 .name = #_provider "_" #_name, \
299 .entries = __enum_values__##_provider##_##_name, \
300 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name), \
303 #include TRACEPOINT_INCLUDE
306 * Stage 2 of tracepoint event generation.
308 * Create probe callback prototypes.
311 /* Reset all macros within TRACEPOINT_EVENT */
312 #include <lttng/ust-tracepoint-event-reset.h>
315 #define TP_ARGS(...) __VA_ARGS__
317 #undef TRACEPOINT_EVENT_CLASS
318 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
319 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
321 #include TRACEPOINT_INCLUDE
324 * Stage 3.0 of tracepoint event generation.
326 * Create static inline function that calculates event size.
329 /* Reset all macros within TRACEPOINT_EVENT */
330 #include <lttng/ust-tracepoint-event-reset.h>
331 #include <lttng/ust-tracepoint-event-write.h>
333 #undef _ctf_integer_ext
334 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
335 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
336 __event_len += sizeof(_type);
339 #define _ctf_float(_type, _item, _src, _nowrite) \
340 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
341 __event_len += sizeof(_type);
343 #undef _ctf_array_encoded
344 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
345 _nowrite, _elem_type_base) \
346 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
347 __event_len += sizeof(_type) * (_length);
349 #undef _ctf_sequence_encoded
350 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
351 _src_length, _encoding, _nowrite, _elem_type_base) \
352 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
353 __event_len += sizeof(_length_type); \
354 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
355 __dynamic_len[__dynamic_len_idx] = (_src_length); \
356 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
360 #define _ctf_string(_item, _src, _nowrite) \
361 __event_len += __dynamic_len[__dynamic_len_idx++] = \
362 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
365 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
366 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
369 #define TP_ARGS(...) __VA_ARGS__
372 #define TP_FIELDS(...) __VA_ARGS__
374 #undef TRACEPOINT_EVENT_CLASS
375 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
376 static inline lttng_ust_notrace \
377 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
379 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
381 size_t __event_len = 0; \
382 unsigned int __dynamic_len_idx = 0; \
385 (void) __dynamic_len_idx; /* don't warn if unused */ \
387 return __event_len; \
390 #include TRACEPOINT_INCLUDE
393 * Stage 3.1 of tracepoint event generation.
395 * Create static inline function that layout the filter stack data.
396 * We make both write and nowrite data available to the filter.
399 /* Reset all macros within TRACEPOINT_EVENT */
400 #include <lttng/ust-tracepoint-event-reset.h>
401 #include <lttng/ust-tracepoint-event-write.h>
402 #include <lttng/ust-tracepoint-event-nowrite.h>
404 #undef _ctf_integer_ext
405 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
406 if (lttng_is_signed_type(_type)) { \
407 int64_t __ctf_tmp_int64; \
408 switch (sizeof(_type)) { \
411 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
412 __ctf_tmp_int64 = (int64_t) __tmp.v; \
417 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
418 if (_byte_order != BYTE_ORDER) \
419 __tmp.v = bswap_16(__tmp.v); \
420 __ctf_tmp_int64 = (int64_t) __tmp.v; \
425 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
426 if (_byte_order != BYTE_ORDER) \
427 __tmp.v = bswap_32(__tmp.v); \
428 __ctf_tmp_int64 = (int64_t) __tmp.v; \
433 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
434 if (_byte_order != BYTE_ORDER) \
435 __tmp.v = bswap_64(__tmp.v); \
436 __ctf_tmp_int64 = (int64_t) __tmp.v; \
442 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
444 uint64_t __ctf_tmp_uint64; \
445 switch (sizeof(_type)) { \
448 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
449 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
454 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
455 if (_byte_order != BYTE_ORDER) \
456 __tmp.v = bswap_16(__tmp.v); \
457 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
462 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
463 if (_byte_order != BYTE_ORDER) \
464 __tmp.v = bswap_32(__tmp.v); \
465 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
470 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
471 if (_byte_order != BYTE_ORDER) \
472 __tmp.v = bswap_64(__tmp.v); \
473 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
479 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
481 __stack_data += sizeof(int64_t);
484 #define _ctf_float(_type, _item, _src, _nowrite) \
486 double __ctf_tmp_double = (double) (_type) (_src); \
487 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
488 __stack_data += sizeof(double); \
491 #undef _ctf_array_encoded
492 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
493 _encoding, _nowrite, _elem_type_base) \
495 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
496 const void *__ctf_tmp_ptr = (_src); \
497 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
498 __stack_data += sizeof(unsigned long); \
499 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
500 __stack_data += sizeof(void *); \
503 #undef _ctf_sequence_encoded
504 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
505 _src_length, _encoding, _nowrite, _elem_type_base) \
507 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
508 const void *__ctf_tmp_ptr = (_src); \
509 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
510 __stack_data += sizeof(unsigned long); \
511 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
512 __stack_data += sizeof(void *); \
516 #define _ctf_string(_item, _src, _nowrite) \
518 const void *__ctf_tmp_ptr = \
519 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
520 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
521 __stack_data += sizeof(void *); \
525 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
526 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
529 #define TP_ARGS(...) __VA_ARGS__
532 #define TP_FIELDS(...) __VA_ARGS__
534 #undef TRACEPOINT_EVENT_CLASS
535 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
537 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
538 _TP_ARGS_DATA_PROTO(_args)) \
543 #include TRACEPOINT_INCLUDE
546 * Stage 4 of tracepoint event generation.
548 * Create static inline function that calculates event payload alignment.
551 /* Reset all macros within TRACEPOINT_EVENT */
552 #include <lttng/ust-tracepoint-event-reset.h>
553 #include <lttng/ust-tracepoint-event-write.h>
555 #undef _ctf_integer_ext
556 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
557 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
560 #define _ctf_float(_type, _item, _src, _nowrite) \
561 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
563 #undef _ctf_array_encoded
564 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
565 _encoding, _nowrite, _elem_type_base) \
566 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
568 #undef _ctf_sequence_encoded
569 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
570 _src_length, _encoding, _nowrite, _elem_type_base) \
571 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
572 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
575 #define _ctf_string(_item, _src, _nowrite)
578 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
579 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
582 #define TP_ARGS(...) __VA_ARGS__
585 #define TP_FIELDS(...) __VA_ARGS__
587 #undef TRACEPOINT_EVENT_CLASS
588 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
589 static inline lttng_ust_notrace \
590 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
592 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
594 size_t __event_align = 1; \
596 return __event_align; \
599 #include TRACEPOINT_INCLUDE
603 * Stage 5 of tracepoint event generation.
605 * Create the probe function. This function calls event size calculation
606 * and writes event data into the buffer.
609 /* Reset all macros within TRACEPOINT_EVENT */
610 #include <lttng/ust-tracepoint-event-reset.h>
611 #include <lttng/ust-tracepoint-event-write.h>
613 #undef _ctf_integer_ext
614 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
616 _type __tmp = (_src); \
617 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
618 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
622 #define _ctf_float(_type, _item, _src, _nowrite) \
624 _type __tmp = (_src); \
625 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
626 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
629 #undef _ctf_array_encoded
630 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
631 _encoding, _nowrite, _elem_type_base) \
632 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
633 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
635 #undef _ctf_sequence_encoded
636 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
637 _src_length, _encoding, _nowrite, _elem_type_base) \
639 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
640 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
641 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
643 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
644 __chan->ops->event_write(&__ctx, _src, \
645 sizeof(_type) * __get_dynamic_len(dest));
648 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
649 * tracepoint provider ABI implements event_strcpy. This dynamic check
650 * can be removed when the tracepoint provider ABI moves to 2.
652 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
653 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
657 #define _ctf_string(_item, _src, _nowrite) \
659 const char *__ctf_tmp_string = \
660 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
661 lib_ring_buffer_align_ctx(&__ctx, \
662 lttng_alignof(*__ctf_tmp_string)); \
663 if (__chan->ops->u.has_strcpy) \
664 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
665 __get_dynamic_len(dest)); \
667 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
668 __get_dynamic_len(dest)); \
673 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
674 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
676 /* Beware: this get len actually consumes the len value */
677 #undef __get_dynamic_len
678 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
681 #define TP_ARGS(...) __VA_ARGS__
684 #define TP_FIELDS(...) __VA_ARGS__
687 * For state dump, check that "session" argument (mandatory) matches the
688 * session this event belongs to. Ensures that we write state dump data only
689 * into the started session, not into all sessions.
691 #undef _TP_SESSION_CHECK
692 #ifdef TP_SESSION_CHECK
693 #define _TP_SESSION_CHECK(session, csession) (session == csession)
694 #else /* TP_SESSION_CHECK */
695 #define _TP_SESSION_CHECK(session, csession) 1
696 #endif /* TP_SESSION_CHECK */
699 * Use of __builtin_return_address(0) sometimes seems to cause stack
700 * corruption on 32-bit PowerPC. Disable this feature on that
701 * architecture for now by always using the NULL value for the ip
706 #define _TP_IP_PARAM(x) (x)
707 #else /* TP_IP_PARAM */
709 #if defined(__PPC__) && !defined(__PPC64__)
710 #define _TP_IP_PARAM(x) NULL
711 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
712 #define _TP_IP_PARAM(x) __builtin_return_address(0)
713 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
715 #endif /* TP_IP_PARAM */
718 * Using twice size for filter stack data to hold size and pointer for
719 * each field (worse case). For integers, max size required is 64-bit.
720 * Same for double-precision floats. Those fit within
721 * 2*sizeof(unsigned long) for all supported architectures.
722 * Perform UNION (||) of filter runtime list.
724 #undef TRACEPOINT_EVENT_CLASS
725 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
726 static lttng_ust_notrace \
727 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
729 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
731 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
732 struct lttng_channel *__chan = __event->chan; \
733 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
734 struct lttng_stack_ctx __lttng_ctx; \
735 size_t __event_len, __event_align; \
736 size_t __dynamic_len_idx = 0; \
738 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
739 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
744 (void) __dynamic_len_idx; /* don't warn if unused */ \
745 if (!_TP_SESSION_CHECK(session, __chan->session)) \
747 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
749 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
751 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
753 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
755 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
756 struct lttng_bytecode_runtime *bc_runtime; \
757 int __filter_record = __event->has_enablers_without_bytecode; \
759 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
760 _TP_ARGS_DATA_VAR(_args)); \
761 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
762 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
763 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
764 __filter_record = 1; \
766 if (caa_likely(!__filter_record)) \
769 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
770 _TP_ARGS_DATA_VAR(_args)); \
771 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
772 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
773 __lttng_ctx.event = __event; \
774 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
775 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
776 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
777 __event_align, -1, __chan->handle, &__lttng_ctx); \
778 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
779 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
783 __chan->ops->event_commit(&__ctx); \
786 #include TRACEPOINT_INCLUDE
788 #undef __get_dynamic_len
791 * Stage 5.1 of tracepoint event generation.
793 * Create probe signature
796 /* Reset all macros within TRACEPOINT_EVENT */
797 #include <lttng/ust-tracepoint-event-reset.h>
800 #define TP_ARGS(...) __VA_ARGS__
802 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
804 #undef TRACEPOINT_EVENT_CLASS
805 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
806 static const char __tp_event_signature___##_provider##___##_name[] = \
807 _TP_EXTRACT_STRING2(_args);
809 #include TRACEPOINT_INCLUDE
811 #undef _TP_EXTRACT_STRING2
814 * Stage 6 of tracepoint event generation.
816 * Tracepoint loglevel mapping definition generation. We generate a
817 * symbol for each mapping for a provider/event to ensure at most a 1 to
818 * 1 mapping between events and loglevels. If the symbol is repeated,
819 * the compiler will complain.
822 /* Reset all macros within TRACEPOINT_EVENT */
823 #include <lttng/ust-tracepoint-event-reset.h>
825 #undef TRACEPOINT_LOGLEVEL
826 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
827 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
828 static const int *_loglevel___##__provider##___##__name = \
829 &_loglevel_value___##__provider##___##__name;
831 #include TRACEPOINT_INCLUDE
834 * Stage 6.1 of tracepoint event generation.
836 * Tracepoint UML URI info.
839 /* Reset all macros within TRACEPOINT_EVENT */
840 #include <lttng/ust-tracepoint-event-reset.h>
842 #undef TRACEPOINT_MODEL_EMF_URI
843 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
844 static const char *_model_emf_uri___##__provider##___##__name = __uri;
846 #include TRACEPOINT_INCLUDE
849 * Stage 7.1 of tracepoint event generation.
851 * Create events description structures. We use a weakref because
852 * loglevels are optional. If not declared, the event will point to the
853 * a loglevel that contains NULL.
856 /* Reset all macros within TRACEPOINT_EVENT */
857 #include <lttng/ust-tracepoint-event-reset.h>
859 #undef TRACEPOINT_EVENT_INSTANCE
860 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
862 __ref_loglevel___##_provider##___##_name \
863 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
864 static const char * \
865 __ref_model_emf_uri___##_provider##___##_name \
866 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
867 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
868 .name = #_provider ":" #_name, \
869 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
871 .fields = __event_fields___##_provider##___##_template, \
872 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
873 .loglevel = &__ref_loglevel___##_provider##___##_name, \
874 .signature = __tp_event_signature___##_provider##___##_template, \
877 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
882 #include TRACEPOINT_INCLUDE
885 * Stage 7.2 of tracepoint event generation.
887 * Create array of events.
890 /* Reset all macros within TRACEPOINT_EVENT */
891 #include <lttng/ust-tracepoint-event-reset.h>
893 #undef TRACEPOINT_EVENT_INSTANCE
894 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
895 &__event_desc___##_provider##_##_name,
897 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
898 #include TRACEPOINT_INCLUDE
903 * Stage 8 of tracepoint event generation.
905 * Create a toplevel descriptor for the whole probe.
908 /* non-const because list head will be modified when registered. */
909 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
910 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
911 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
912 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
913 .head
= { NULL
, NULL
},
914 .lazy_init_head
= { NULL
, NULL
},
916 .major
= LTTNG_UST_PROVIDER_MAJOR
,
917 .minor
= LTTNG_UST_PROVIDER_MINOR
,
920 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
923 * Stage 9 of tracepoint event generation.
925 * Register/unregister probes at module load/unload.
927 * Generate the constructor as an externally visible symbol for use when
928 * linking the probe statically.
930 * Register refcount is protected by libc dynamic loader mutex.
933 /* Reset all macros within TRACEPOINT_EVENT */
934 #include <lttng/ust-tracepoint-event-reset.h>
935 static void lttng_ust_notrace
__attribute__((constructor
))
936 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
938 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
942 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
943 TRACEPOINT_PROVIDER
)++) {
947 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
948 * static inline function that ensures every probe PROVIDER
949 * argument match the provider within which they appear. It
950 * calls empty static inline functions, and therefore has no
951 * runtime effect. However, if it detects an error, a linker
954 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
955 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
957 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
962 static void lttng_ust_notrace
__attribute__((destructor
))
963 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
965 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
967 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
968 TRACEPOINT_PROVIDER
)) {
971 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
974 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);