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, \
176 .atype = atype_sequence, \
181 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
182 .elem_type = __type_integer(_type, BYTE_ORDER, _elem_type_base, _encoding), \
186 .nowrite = _nowrite, \
190 #define _ctf_string(_item, _src, _nowrite) \
195 .atype = atype_string, \
198 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
201 .nowrite = _nowrite, \
205 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
207 #undef TRACEPOINT_EVENT_CLASS
208 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
209 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
213 #include TRACEPOINT_INCLUDE
216 * Stage 2 of tracepoint event generation.
218 * Create probe callback prototypes.
221 /* Reset all macros within TRACEPOINT_EVENT */
222 #include <lttng/ust-tracepoint-event-reset.h>
225 #define TP_ARGS(...) __VA_ARGS__
227 #undef TRACEPOINT_EVENT_CLASS
228 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
229 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
231 #include TRACEPOINT_INCLUDE
234 * Stage 3 of tracepoint event generation.
236 * Create static inline function that calculates event size.
239 /* Reset all macros within TRACEPOINT_EVENT */
240 #include <lttng/ust-tracepoint-event-reset.h>
241 #include <lttng/ust-tracepoint-event-write.h>
243 #undef _ctf_integer_ext
244 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
245 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
246 __event_len += sizeof(_type);
249 #define _ctf_float(_type, _item, _src, _nowrite) \
250 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
251 __event_len += sizeof(_type);
253 #undef _ctf_array_encoded
254 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
255 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
256 __event_len += sizeof(_type) * (_length);
258 #undef _ctf_sequence_encoded
259 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
260 _src_length, _encoding, _nowrite, _elem_type_base) \
261 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
262 __event_len += sizeof(_length_type); \
263 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
264 __dynamic_len[__dynamic_len_idx] = (_src_length); \
265 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
269 #define _ctf_string(_item, _src, _nowrite) \
270 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
273 #define TP_ARGS(...) __VA_ARGS__
276 #define TP_FIELDS(...) __VA_ARGS__
278 #undef TRACEPOINT_EVENT_CLASS
279 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
280 static inline lttng_ust_notrace \
281 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
283 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
285 size_t __event_len = 0; \
286 unsigned int __dynamic_len_idx = 0; \
289 (void) __dynamic_len_idx; /* don't warn if unused */ \
291 return __event_len; \
294 #include TRACEPOINT_INCLUDE
297 * Stage 3.1 of tracepoint event generation.
299 * Create static inline function that layout the filter stack data.
300 * We make both write and nowrite data available to the filter.
303 /* Reset all macros within TRACEPOINT_EVENT */
304 #include <lttng/ust-tracepoint-event-reset.h>
305 #include <lttng/ust-tracepoint-event-write.h>
306 #include <lttng/ust-tracepoint-event-nowrite.h>
308 #undef _ctf_integer_ext
309 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
310 if (lttng_is_signed_type(_type)) { \
311 int64_t __ctf_tmp_int64; \
312 switch (sizeof(_type)) { \
315 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
316 __ctf_tmp_int64 = (int64_t) __tmp.v; \
321 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
322 if (_byte_order != BYTE_ORDER) \
323 __tmp.v = bswap_16(__tmp.v); \
324 __ctf_tmp_int64 = (int64_t) __tmp.v; \
329 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
330 if (_byte_order != BYTE_ORDER) \
331 __tmp.v = bswap_32(__tmp.v); \
332 __ctf_tmp_int64 = (int64_t) __tmp.v; \
337 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
338 if (_byte_order != BYTE_ORDER) \
339 __tmp.v = bswap_64(__tmp.v); \
340 __ctf_tmp_int64 = (int64_t) __tmp.v; \
346 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
348 uint64_t __ctf_tmp_uint64; \
349 switch (sizeof(_type)) { \
352 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
353 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
358 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
359 if (_byte_order != BYTE_ORDER) \
360 __tmp.v = bswap_16(__tmp.v); \
361 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
366 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
367 if (_byte_order != BYTE_ORDER) \
368 __tmp.v = bswap_32(__tmp.v); \
369 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
374 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
375 if (_byte_order != BYTE_ORDER) \
376 __tmp.v = bswap_64(__tmp.v); \
377 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
383 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
385 __stack_data += sizeof(int64_t);
388 #define _ctf_float(_type, _item, _src, _nowrite) \
390 double __ctf_tmp_double = (double) (_type) (_src); \
391 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
392 __stack_data += sizeof(double); \
395 #undef _ctf_array_encoded
396 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
398 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
399 const void *__ctf_tmp_ptr = (_src); \
400 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
401 __stack_data += sizeof(unsigned long); \
402 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
403 __stack_data += sizeof(void *); \
406 #undef _ctf_sequence_encoded
407 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
408 _src_length, _encoding, _nowrite, _elem_type_base) \
410 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
411 const void *__ctf_tmp_ptr = (_src); \
412 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
413 __stack_data += sizeof(unsigned long); \
414 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
415 __stack_data += sizeof(void *); \
419 #define _ctf_string(_item, _src, _nowrite) \
421 const void *__ctf_tmp_ptr = (_src); \
422 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
423 __stack_data += sizeof(void *); \
427 #define TP_ARGS(...) __VA_ARGS__
430 #define TP_FIELDS(...) __VA_ARGS__
432 #undef TRACEPOINT_EVENT_CLASS
433 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
435 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
436 _TP_ARGS_DATA_PROTO(_args)) \
441 #include TRACEPOINT_INCLUDE
446 * Stage 4 of tracepoint event generation.
448 * Create static inline function that calculates event payload alignment.
451 /* Reset all macros within TRACEPOINT_EVENT */
452 #include <lttng/ust-tracepoint-event-reset.h>
453 #include <lttng/ust-tracepoint-event-write.h>
455 #undef _ctf_integer_ext
456 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
457 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
460 #define _ctf_float(_type, _item, _src, _nowrite) \
461 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
463 #undef _ctf_array_encoded
464 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
465 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
467 #undef _ctf_sequence_encoded
468 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
469 _src_length, _encoding, _nowrite, _elem_type_base) \
470 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
471 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
474 #define _ctf_string(_item, _src, _nowrite)
477 #define TP_ARGS(...) __VA_ARGS__
480 #define TP_FIELDS(...) __VA_ARGS__
482 #undef TRACEPOINT_EVENT_CLASS
483 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
484 static inline lttng_ust_notrace \
485 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
487 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
489 size_t __event_align = 1; \
491 return __event_align; \
494 #include TRACEPOINT_INCLUDE
498 * Stage 5 of tracepoint event generation.
500 * Create the probe function. This function calls event size calculation
501 * and writes event data into the buffer.
504 /* Reset all macros within TRACEPOINT_EVENT */
505 #include <lttng/ust-tracepoint-event-reset.h>
506 #include <lttng/ust-tracepoint-event-write.h>
508 #undef _ctf_integer_ext
509 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
511 _type __tmp = (_src); \
512 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
513 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
517 #define _ctf_float(_type, _item, _src, _nowrite) \
519 _type __tmp = (_src); \
520 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
521 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
524 #undef _ctf_array_encoded
525 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
526 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
527 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
529 #undef _ctf_sequence_encoded
530 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
531 _src_length, _encoding, _nowrite, _elem_type_base) \
533 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
534 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
535 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
537 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
538 __chan->ops->event_write(&__ctx, _src, \
539 sizeof(_type) * __get_dynamic_len(dest));
542 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
543 * tracepoint provider ABI implements event_strcpy. This dynamic check
544 * can be removed when the tracepoint provider ABI moves to 2.
546 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
547 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
551 #define _ctf_string(_item, _src, _nowrite) \
552 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
553 if (__chan->ops->u.has_strcpy) \
554 __chan->ops->event_strcpy(&__ctx, _src, \
555 __get_dynamic_len(dest)); \
557 __chan->ops->event_write(&__ctx, _src, \
558 __get_dynamic_len(dest));
560 /* Beware: this get len actually consumes the len value */
561 #undef __get_dynamic_len
562 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
565 #define TP_ARGS(...) __VA_ARGS__
568 #define TP_FIELDS(...) __VA_ARGS__
571 * For state dump, check that "session" argument (mandatory) matches the
572 * session this event belongs to. Ensures that we write state dump data only
573 * into the started session, not into all sessions.
575 #undef _TP_SESSION_CHECK
576 #ifdef TP_SESSION_CHECK
577 #define _TP_SESSION_CHECK(session, csession) (session == csession)
578 #else /* TP_SESSION_CHECK */
579 #define _TP_SESSION_CHECK(session, csession) 1
580 #endif /* TP_SESSION_CHECK */
583 * Use of __builtin_return_address(0) sometimes seems to cause stack
584 * corruption on 32-bit PowerPC. Disable this feature on that
585 * architecture for now by always using the NULL value for the ip
590 #define _TP_IP_PARAM(x) (x)
591 #else /* TP_IP_PARAM */
593 #if defined(__PPC__) && !defined(__PPC64__)
594 #define _TP_IP_PARAM(x) NULL
595 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
596 #define _TP_IP_PARAM(x) __builtin_return_address(0)
597 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
599 #endif /* TP_IP_PARAM */
602 * Using twice size for filter stack data to hold size and pointer for
603 * each field (worse case). For integers, max size required is 64-bit.
604 * Same for double-precision floats. Those fit within
605 * 2*sizeof(unsigned long) for all supported architectures.
606 * Perform UNION (||) of filter runtime list.
608 #undef TRACEPOINT_EVENT_CLASS
609 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
610 static lttng_ust_notrace \
611 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
613 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
615 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
616 struct lttng_channel *__chan = __event->chan; \
617 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
618 size_t __event_len, __event_align; \
619 size_t __dynamic_len_idx = 0; \
621 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
622 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
627 (void) __dynamic_len_idx; /* don't warn if unused */ \
628 if (!_TP_SESSION_CHECK(session, __chan->session)) \
630 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
632 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
634 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
636 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
638 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
639 struct lttng_bytecode_runtime *bc_runtime; \
640 int __filter_record = __event->has_enablers_without_bytecode; \
642 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
643 _TP_ARGS_DATA_VAR(_args)); \
644 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
645 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
646 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
647 __filter_record = 1; \
649 if (caa_likely(!__filter_record)) \
652 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
653 _TP_ARGS_DATA_VAR(_args)); \
654 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
655 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
656 __event_align, -1, __chan->handle); \
657 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
658 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
662 __chan->ops->event_commit(&__ctx); \
665 #include TRACEPOINT_INCLUDE
667 #undef __get_dynamic_len
670 * Stage 5.1 of tracepoint event generation.
672 * Create probe signature
675 /* Reset all macros within TRACEPOINT_EVENT */
676 #include <lttng/ust-tracepoint-event-reset.h>
679 #define TP_ARGS(...) __VA_ARGS__
681 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
683 #undef TRACEPOINT_EVENT_CLASS
684 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
685 const char __tp_event_signature___##_provider##___##_name[] = \
686 _TP_EXTRACT_STRING2(_args);
688 #include TRACEPOINT_INCLUDE
690 #undef _TP_EXTRACT_STRING2
693 * Stage 6 of tracepoint event generation.
695 * Tracepoint loglevel mapping definition generation. We generate a
696 * symbol for each mapping for a provider/event to ensure at most a 1 to
697 * 1 mapping between events and loglevels. If the symbol is repeated,
698 * the compiler will complain.
701 /* Reset all macros within TRACEPOINT_EVENT */
702 #include <lttng/ust-tracepoint-event-reset.h>
704 #undef TRACEPOINT_LOGLEVEL
705 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
706 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
707 static const int *_loglevel___##__provider##___##__name = \
708 &_loglevel_value___##__provider##___##__name;
710 #include TRACEPOINT_INCLUDE
713 * Stage 6.1 of tracepoint event generation.
715 * Tracepoint UML URI info.
718 /* Reset all macros within TRACEPOINT_EVENT */
719 #include <lttng/ust-tracepoint-event-reset.h>
721 #undef TRACEPOINT_MODEL_EMF_URI
722 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
723 static const char *_model_emf_uri___##__provider##___##__name = __uri;
725 #include TRACEPOINT_INCLUDE
728 * Stage 7.1 of tracepoint event generation.
730 * Create events description structures. We use a weakref because
731 * loglevels are optional. If not declared, the event will point to the
732 * a loglevel that contains NULL.
735 /* Reset all macros within TRACEPOINT_EVENT */
736 #include <lttng/ust-tracepoint-event-reset.h>
738 #undef TRACEPOINT_EVENT_INSTANCE
739 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
741 __ref_loglevel___##_provider##___##_name \
742 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
743 static const char * \
744 __ref_model_emf_uri___##_provider##___##_name \
745 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
746 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
747 .name = #_provider ":" #_name, \
748 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
750 .fields = __event_fields___##_provider##___##_template, \
751 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
752 .loglevel = &__ref_loglevel___##_provider##___##_name, \
753 .signature = __tp_event_signature___##_provider##___##_template, \
754 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
757 #include TRACEPOINT_INCLUDE
760 * Stage 7.2 of tracepoint event generation.
762 * Create array of events.
765 /* Reset all macros within TRACEPOINT_EVENT */
766 #include <lttng/ust-tracepoint-event-reset.h>
768 #undef TRACEPOINT_EVENT_INSTANCE
769 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
770 &__event_desc___##_provider##_##_name,
772 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
773 #include TRACEPOINT_INCLUDE
778 * Stage 8 of tracepoint event generation.
780 * Create a toplevel descriptor for the whole probe.
783 /* non-const because list head will be modified when registered. */
784 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
785 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
786 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
787 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
788 .head
= { NULL
, NULL
},
789 .lazy_init_head
= { NULL
, NULL
},
791 .major
= LTTNG_UST_PROVIDER_MAJOR
,
792 .minor
= LTTNG_UST_PROVIDER_MINOR
,
795 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
798 * Stage 9 of tracepoint event generation.
800 * Register/unregister probes at module load/unload.
802 * Generate the constructor as an externally visible symbol for use when
803 * linking the probe statically.
805 * Register refcount is protected by libc dynamic loader mutex.
808 /* Reset all macros within TRACEPOINT_EVENT */
809 #include <lttng/ust-tracepoint-event-reset.h>
810 static void lttng_ust_notrace
__attribute__((constructor
))
811 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
813 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
817 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
818 TRACEPOINT_PROVIDER
)++) {
822 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
823 * static inline function that ensures every probe PROVIDER
824 * argument match the provider within which they appear. It
825 * calls empty static inline functions, and therefore has no
826 * runtime effect. However, if it detects an error, a linker
829 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
830 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
832 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
837 static void lttng_ust_notrace
__attribute__((destructor
))
838 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
840 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
842 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
843 TRACEPOINT_PROVIDER
)) {
846 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
849 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);