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 #undef tp_list_for_each_entry_rcu
35 #define tp_list_for_each_entry_rcu(pos, head, member) \
36 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
37 &pos->member != (head); \
38 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
41 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
42 * same arguments and having the same field layout.
44 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
45 * its own provider and name. It refers to a class (template).
47 * TRACEPOINT_EVENT declared both a class and an instance and does a
48 * direct mapping from the instance to the class.
51 #undef TRACEPOINT_EVENT
52 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
53 TRACEPOINT_EVENT_CLASS(_provider, _name, \
55 _TP_PARAMS(_fields)) \
56 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
60 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
62 #define _tp_max_t(type, x, y) \
66 __max1 > __max2 ? __max1: __max2; \
70 * Stage 0 of tracepoint event generation.
72 * Check that each TRACEPOINT_EVENT provider argument match the
73 * TRACEPOINT_PROVIDER by creating dummy callbacks.
76 /* Reset all macros within TRACEPOINT_EVENT */
77 #include <lttng/ust-tracepoint-event-reset.h>
79 static inline lttng_ust_notrace
80 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
82 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
86 #undef TRACEPOINT_EVENT_CLASS
87 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
88 __tracepoint_provider_mismatch_##_provider();
90 #undef TRACEPOINT_EVENT_INSTANCE
91 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
92 __tracepoint_provider_mismatch_##_provider();
94 static inline lttng_ust_notrace
95 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
97 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
99 #include TRACEPOINT_INCLUDE
103 * Stage 0.1 of tracepoint event generation.
105 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
106 * tracepoint name length limit.
109 /* Reset all macros within TRACEPOINT_EVENT */
110 #include <lttng/ust-tracepoint-event-reset.h>
112 #undef TRACEPOINT_EVENT_INSTANCE
113 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
115 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
116 __attribute__((unused)) = \
117 #_provider ":" #_name;
119 #include TRACEPOINT_INCLUDE
122 * Stage 1 of tracepoint event generation.
124 * Create event field type metadata section.
125 * Each event produce an array of fields.
128 /* Reset all macros within TRACEPOINT_EVENT */
129 #include <lttng/ust-tracepoint-event-reset.h>
130 #include <lttng/ust-tracepoint-event-write.h>
131 #include <lttng/ust-tracepoint-event-nowrite.h>
133 #undef _ctf_integer_ext
134 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
137 .type = __type_integer(_type, _byte_order, _base, none),\
138 .nowrite = _nowrite, \
142 #define _ctf_float(_type, _item, _src, _nowrite) \
145 .type = __type_float(_type), \
146 .nowrite = _nowrite, \
149 #undef _ctf_array_encoded
150 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
155 .atype = atype_array, \
160 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
165 .nowrite = _nowrite, \
168 #undef _ctf_sequence_encoded
169 #define _ctf_sequence_encoded(_type, _item, _src, \
170 _length_type, _src_length, _encoding, _nowrite) \
175 .atype = atype_sequence, \
180 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
181 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
185 .nowrite = _nowrite, \
189 #define _ctf_string(_item, _src, _nowrite) \
194 .atype = atype_string, \
197 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
200 .nowrite = _nowrite, \
204 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
206 #undef TRACEPOINT_EVENT_CLASS
207 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
208 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
212 #include TRACEPOINT_INCLUDE
215 * Stage 2 of tracepoint event generation.
217 * Create probe callback prototypes.
220 /* Reset all macros within TRACEPOINT_EVENT */
221 #include <lttng/ust-tracepoint-event-reset.h>
224 #define TP_ARGS(...) __VA_ARGS__
226 #undef TRACEPOINT_EVENT_CLASS
227 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
228 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
230 #include TRACEPOINT_INCLUDE
233 * Stage 3 of tracepoint event generation.
235 * Create static inline function that calculates event size.
238 /* Reset all macros within TRACEPOINT_EVENT */
239 #include <lttng/ust-tracepoint-event-reset.h>
240 #include <lttng/ust-tracepoint-event-write.h>
242 #undef _ctf_integer_ext
243 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
244 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
245 __event_len += sizeof(_type);
248 #define _ctf_float(_type, _item, _src, _nowrite) \
249 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
250 __event_len += sizeof(_type);
252 #undef _ctf_array_encoded
253 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
254 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
255 __event_len += sizeof(_type) * (_length);
257 #undef _ctf_sequence_encoded
258 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
259 _src_length, _encoding, _nowrite) \
260 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
261 __event_len += sizeof(_length_type); \
262 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
263 __dynamic_len[__dynamic_len_idx] = (_src_length); \
264 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
268 #define _ctf_string(_item, _src, _nowrite) \
269 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
272 #define TP_ARGS(...) __VA_ARGS__
275 #define TP_FIELDS(...) __VA_ARGS__
277 #undef TRACEPOINT_EVENT_CLASS
278 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
279 static inline lttng_ust_notrace \
280 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
282 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
284 size_t __event_len = 0; \
285 unsigned int __dynamic_len_idx = 0; \
288 (void) __dynamic_len_idx; /* don't warn if unused */ \
290 return __event_len; \
293 #include TRACEPOINT_INCLUDE
296 * Stage 3.1 of tracepoint event generation.
298 * Create static inline function that layout the filter stack data.
299 * We make both write and nowrite data available to the filter.
302 /* Reset all macros within TRACEPOINT_EVENT */
303 #include <lttng/ust-tracepoint-event-reset.h>
304 #include <lttng/ust-tracepoint-event-write.h>
305 #include <lttng/ust-tracepoint-event-nowrite.h>
307 #undef _ctf_integer_ext
308 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
309 if (lttng_is_signed_type(_type)) { \
310 int64_t __ctf_tmp_int64; \
311 switch (sizeof(_type)) { \
314 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
315 __ctf_tmp_int64 = (int64_t) __tmp.v; \
320 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
321 if (_byte_order != BYTE_ORDER) \
322 __tmp.v = bswap_16(__tmp.v); \
323 __ctf_tmp_int64 = (int64_t) __tmp.v; \
328 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
329 if (_byte_order != BYTE_ORDER) \
330 __tmp.v = bswap_32(__tmp.v); \
331 __ctf_tmp_int64 = (int64_t) __tmp.v; \
336 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
337 if (_byte_order != BYTE_ORDER) \
338 __tmp.v = bswap_64(__tmp.v); \
339 __ctf_tmp_int64 = (int64_t) __tmp.v; \
345 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
347 uint64_t __ctf_tmp_uint64; \
348 switch (sizeof(_type)) { \
351 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
352 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
357 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
358 if (_byte_order != BYTE_ORDER) \
359 __tmp.v = bswap_16(__tmp.v); \
360 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
365 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
366 if (_byte_order != BYTE_ORDER) \
367 __tmp.v = bswap_32(__tmp.v); \
368 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
373 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
374 if (_byte_order != BYTE_ORDER) \
375 __tmp.v = bswap_64(__tmp.v); \
376 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
382 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
384 __stack_data += sizeof(int64_t);
387 #define _ctf_float(_type, _item, _src, _nowrite) \
389 double __ctf_tmp_double = (double) (_type) (_src); \
390 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
391 __stack_data += sizeof(double); \
394 #undef _ctf_array_encoded
395 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
397 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
398 const void *__ctf_tmp_ptr = (_src); \
399 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
400 __stack_data += sizeof(unsigned long); \
401 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
402 __stack_data += sizeof(void *); \
405 #undef _ctf_sequence_encoded
406 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
407 _src_length, _encoding, _nowrite) \
409 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
410 const void *__ctf_tmp_ptr = (_src); \
411 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
412 __stack_data += sizeof(unsigned long); \
413 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
414 __stack_data += sizeof(void *); \
418 #define _ctf_string(_item, _src, _nowrite) \
420 const void *__ctf_tmp_ptr = (_src); \
421 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
422 __stack_data += sizeof(void *); \
426 #define TP_ARGS(...) __VA_ARGS__
429 #define TP_FIELDS(...) __VA_ARGS__
431 #undef TRACEPOINT_EVENT_CLASS
432 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
434 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
435 _TP_ARGS_DATA_PROTO(_args)) \
440 #include TRACEPOINT_INCLUDE
445 * Stage 4 of tracepoint event generation.
447 * Create static inline function that calculates event payload alignment.
450 /* Reset all macros within TRACEPOINT_EVENT */
451 #include <lttng/ust-tracepoint-event-reset.h>
452 #include <lttng/ust-tracepoint-event-write.h>
454 #undef _ctf_integer_ext
455 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
456 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
459 #define _ctf_float(_type, _item, _src, _nowrite) \
460 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
462 #undef _ctf_array_encoded
463 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
464 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
466 #undef _ctf_sequence_encoded
467 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
468 _src_length, _encoding, _nowrite) \
469 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
470 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
473 #define _ctf_string(_item, _src, _nowrite)
476 #define TP_ARGS(...) __VA_ARGS__
479 #define TP_FIELDS(...) __VA_ARGS__
481 #undef TRACEPOINT_EVENT_CLASS
482 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
483 static inline lttng_ust_notrace \
484 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
486 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
488 size_t __event_align = 1; \
490 return __event_align; \
493 #include TRACEPOINT_INCLUDE
497 * Stage 5 of tracepoint event generation.
499 * Create the probe function. This function calls event size calculation
500 * and writes event data into the buffer.
503 /* Reset all macros within TRACEPOINT_EVENT */
504 #include <lttng/ust-tracepoint-event-reset.h>
505 #include <lttng/ust-tracepoint-event-write.h>
507 #undef _ctf_integer_ext
508 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
510 _type __tmp = (_src); \
511 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
512 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
516 #define _ctf_float(_type, _item, _src, _nowrite) \
518 _type __tmp = (_src); \
519 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
520 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
523 #undef _ctf_array_encoded
524 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
525 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
526 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
528 #undef _ctf_sequence_encoded
529 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
530 _src_length, _encoding, _nowrite) \
532 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
533 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
534 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
536 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
537 __chan->ops->event_write(&__ctx, _src, \
538 sizeof(_type) * __get_dynamic_len(dest));
541 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
542 * tracepoint provider ABI implements event_strcpy. This dynamic check
543 * can be removed when the tracepoint provider ABI moves to 2.
545 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
546 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
550 #define _ctf_string(_item, _src, _nowrite) \
551 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
552 if (__chan->ops->u.has_strcpy) \
553 __chan->ops->event_strcpy(&__ctx, _src, \
554 __get_dynamic_len(dest)); \
556 __chan->ops->event_write(&__ctx, _src, \
557 __get_dynamic_len(dest));
559 /* Beware: this get len actually consumes the len value */
560 #undef __get_dynamic_len
561 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
564 #define TP_ARGS(...) __VA_ARGS__
567 #define TP_FIELDS(...) __VA_ARGS__
570 * For state dump, check that "session" argument (mandatory) matches the
571 * session this event belongs to. Ensures that we write state dump data only
572 * into the started session, not into all sessions.
574 #undef _TP_SESSION_CHECK
575 #ifdef TP_SESSION_CHECK
576 #define _TP_SESSION_CHECK(session, csession) (session == csession)
577 #else /* TP_SESSION_CHECK */
578 #define _TP_SESSION_CHECK(session, csession) 1
579 #endif /* TP_SESSION_CHECK */
582 * Use of __builtin_return_address(0) sometimes seems to cause stack
583 * corruption on 32-bit PowerPC. Disable this feature on that
584 * architecture for now by always using the NULL value for the ip
589 #define _TP_IP_PARAM(x) (x)
590 #else /* TP_IP_PARAM */
592 #if defined(__PPC__) && !defined(__PPC64__)
593 #define _TP_IP_PARAM(x) NULL
594 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
595 #define _TP_IP_PARAM(x) __builtin_return_address(0)
596 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
598 #endif /* TP_IP_PARAM */
601 * Using twice size for filter stack data to hold size and pointer for
602 * each field (worse case). For integers, max size required is 64-bit.
603 * Same for double-precision floats. Those fit within
604 * 2*sizeof(unsigned long) for all supported architectures.
605 * Perform UNION (||) of filter runtime list.
607 #undef TRACEPOINT_EVENT_CLASS
608 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
609 static lttng_ust_notrace \
610 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
612 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
614 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
615 struct lttng_channel *__chan = __event->chan; \
616 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
617 size_t __event_len, __event_align; \
618 size_t __dynamic_len_idx = 0; \
620 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
621 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
626 (void) __dynamic_len_idx; /* don't warn if unused */ \
627 if (!_TP_SESSION_CHECK(session, __chan->session)) \
629 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
631 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
633 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
635 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
637 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
638 struct lttng_bytecode_runtime *bc_runtime; \
639 int __filter_record = __event->has_enablers_without_bytecode; \
641 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
642 _TP_ARGS_DATA_VAR(_args)); \
643 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
644 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
645 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
646 __filter_record = 1; \
648 if (caa_likely(!__filter_record)) \
651 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
652 _TP_ARGS_DATA_VAR(_args)); \
653 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
654 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
655 __event_align, -1, __chan->handle); \
656 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
657 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
661 __chan->ops->event_commit(&__ctx); \
664 #include TRACEPOINT_INCLUDE
666 #undef __get_dynamic_len
669 * Stage 5.1 of tracepoint event generation.
671 * Create probe signature
674 /* Reset all macros within TRACEPOINT_EVENT */
675 #include <lttng/ust-tracepoint-event-reset.h>
678 #define TP_ARGS(...) __VA_ARGS__
680 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
682 #undef TRACEPOINT_EVENT_CLASS
683 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
684 const char __tp_event_signature___##_provider##___##_name[] = \
685 _TP_EXTRACT_STRING2(_args);
687 #include TRACEPOINT_INCLUDE
689 #undef _TP_EXTRACT_STRING2
692 * Stage 6 of tracepoint event generation.
694 * Tracepoint loglevel mapping definition generation. We generate a
695 * symbol for each mapping for a provider/event to ensure at most a 1 to
696 * 1 mapping between events and loglevels. If the symbol is repeated,
697 * the compiler will complain.
700 /* Reset all macros within TRACEPOINT_EVENT */
701 #include <lttng/ust-tracepoint-event-reset.h>
703 #undef TRACEPOINT_LOGLEVEL
704 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
705 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
706 static const int *_loglevel___##__provider##___##__name = \
707 &_loglevel_value___##__provider##___##__name;
709 #include TRACEPOINT_INCLUDE
712 * Stage 6.1 of tracepoint event generation.
714 * Tracepoint UML URI info.
717 /* Reset all macros within TRACEPOINT_EVENT */
718 #include <lttng/ust-tracepoint-event-reset.h>
720 #undef TRACEPOINT_MODEL_EMF_URI
721 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
722 static const char *_model_emf_uri___##__provider##___##__name = __uri;
724 #include TRACEPOINT_INCLUDE
727 * Stage 7.1 of tracepoint event generation.
729 * Create events description structures. We use a weakref because
730 * loglevels are optional. If not declared, the event will point to the
731 * a loglevel that contains NULL.
734 /* Reset all macros within TRACEPOINT_EVENT */
735 #include <lttng/ust-tracepoint-event-reset.h>
737 #undef TRACEPOINT_EVENT_INSTANCE
738 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
740 __ref_loglevel___##_provider##___##_name \
741 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
742 static const char * \
743 __ref_model_emf_uri___##_provider##___##_name \
744 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
745 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
746 .name = #_provider ":" #_name, \
747 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
749 .fields = __event_fields___##_provider##___##_template, \
750 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
751 .loglevel = &__ref_loglevel___##_provider##___##_name, \
752 .signature = __tp_event_signature___##_provider##___##_template, \
753 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
756 #include TRACEPOINT_INCLUDE
759 * Stage 7.2 of tracepoint event generation.
761 * Create array of events.
764 /* Reset all macros within TRACEPOINT_EVENT */
765 #include <lttng/ust-tracepoint-event-reset.h>
767 #undef TRACEPOINT_EVENT_INSTANCE
768 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
769 &__event_desc___##_provider##_##_name,
771 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
772 #include TRACEPOINT_INCLUDE
777 * Stage 8 of tracepoint event generation.
779 * Create a toplevel descriptor for the whole probe.
782 /* non-const because list head will be modified when registered. */
783 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
784 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
785 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
786 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
787 .head
= { NULL
, NULL
},
788 .lazy_init_head
= { NULL
, NULL
},
790 .major
= LTTNG_UST_PROVIDER_MAJOR
,
791 .minor
= LTTNG_UST_PROVIDER_MINOR
,
794 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
797 * Stage 9 of tracepoint event generation.
799 * Register/unregister probes at module load/unload.
801 * Generate the constructor as an externally visible symbol for use when
802 * linking the probe statically.
804 * Register refcount is protected by libc dynamic loader mutex.
807 /* Reset all macros within TRACEPOINT_EVENT */
808 #include <lttng/ust-tracepoint-event-reset.h>
809 static void lttng_ust_notrace
__attribute__((constructor
))
810 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
812 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
816 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
817 TRACEPOINT_PROVIDER
)++) {
821 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
822 * static inline function that ensures every probe PROVIDER
823 * argument match the provider within which they appear. It
824 * calls empty static inline functions, and therefore has no
825 * runtime effect. However, if it detects an error, a linker
828 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
829 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
831 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
836 static void lttng_ust_notrace
__attribute__((destructor
))
837 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
839 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
841 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
842 TRACEPOINT_PROVIDER
)) {
845 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
848 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);