2 * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include <urcu/compiler.h>
26 #include <urcu/rculist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/ringbuffer-config.h>
29 #include <lttng/ust-compiler.h>
30 #include <lttng/tracepoint.h>
33 #undef tp_list_for_each_entry_rcu
34 #define tp_list_for_each_entry_rcu(pos, head, member) \
35 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
36 &pos->member != (head); \
37 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
40 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
41 * same arguments and having the same field layout.
43 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
44 * its own provider and name. It refers to a class (template).
46 * TRACEPOINT_EVENT declared both a class and an instance and does a
47 * direct mapping from the instance to the class.
50 #undef TRACEPOINT_EVENT
51 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
52 TRACEPOINT_EVENT_CLASS(_provider, _name, \
54 _TP_PARAMS(_fields)) \
55 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
59 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
61 #define _tp_max_t(type, x, y) \
65 __max1 > __max2 ? __max1: __max2; \
69 * Stage 0 of tracepoint event generation.
71 * Check that each TRACEPOINT_EVENT provider argument match the
72 * TRACEPOINT_PROVIDER by creating dummy callbacks.
75 /* Reset all macros within TRACEPOINT_EVENT */
76 #include <lttng/ust-tracepoint-event-reset.h>
78 static inline lttng_ust_notrace
79 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void);
81 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
85 #undef TRACEPOINT_EVENT_CLASS
86 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
87 __tracepoint_provider_mismatch_##_provider();
89 #undef TRACEPOINT_EVENT_INSTANCE
90 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
91 __tracepoint_provider_mismatch_##_provider();
93 static inline lttng_ust_notrace
94 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void);
96 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
98 #include TRACEPOINT_INCLUDE
102 * Stage 0.1 of tracepoint event generation.
104 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
105 * tracepoint name length limit.
108 /* Reset all macros within TRACEPOINT_EVENT */
109 #include <lttng/ust-tracepoint-event-reset.h>
111 #undef TRACEPOINT_EVENT_INSTANCE
112 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
114 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
115 __attribute__((unused)) = \
116 #_provider ":" #_name;
118 #include TRACEPOINT_INCLUDE
121 * Stage 1 of tracepoint event generation.
123 * Create event field type metadata section.
124 * Each event produce an array of fields.
127 /* Reset all macros within TRACEPOINT_EVENT */
128 #include <lttng/ust-tracepoint-event-reset.h>
129 #include <lttng/ust-tracepoint-event-write.h>
130 #include <lttng/ust-tracepoint-event-nowrite.h>
132 #undef _ctf_integer_ext
133 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
136 .type = __type_integer(_type, _byte_order, _base, none),\
137 .nowrite = _nowrite, \
141 #define _ctf_float(_type, _item, _src, _nowrite) \
144 .type = __type_float(_type), \
145 .nowrite = _nowrite, \
148 #undef _ctf_array_encoded
149 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
154 .atype = atype_array, \
159 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
164 .nowrite = _nowrite, \
167 #undef _ctf_sequence_encoded
168 #define _ctf_sequence_encoded(_type, _item, _src, \
169 _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, _elem_type_base, _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, _elem_type_base) \
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 __ctf_tmp_int64 = (int64_t) __tmp.v; \
326 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
327 __ctf_tmp_int64 = (int64_t) __tmp.v; \
332 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
333 __ctf_tmp_int64 = (int64_t) __tmp.v; \
339 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
341 uint64_t __ctf_tmp_uint64; \
342 switch (sizeof(_type)) { \
345 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
346 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
351 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
352 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
357 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
358 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
363 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
364 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
370 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
372 __stack_data += sizeof(int64_t);
375 #define _ctf_float(_type, _item, _src, _nowrite) \
377 double __ctf_tmp_double = (double) (_type) (_src); \
378 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
379 __stack_data += sizeof(double); \
382 #undef _ctf_array_encoded
383 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
385 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
386 const void *__ctf_tmp_ptr = (_src); \
387 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
388 __stack_data += sizeof(unsigned long); \
389 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
390 __stack_data += sizeof(void *); \
393 #undef _ctf_sequence_encoded
394 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
395 _src_length, _encoding, _nowrite, _elem_type_base) \
397 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_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 *); \
406 #define _ctf_string(_item, _src, _nowrite) \
408 const void *__ctf_tmp_ptr = (_src); \
409 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
410 __stack_data += sizeof(void *); \
414 #define TP_ARGS(...) __VA_ARGS__
417 #define TP_FIELDS(...) __VA_ARGS__
419 #undef TRACEPOINT_EVENT_CLASS
420 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
422 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
423 _TP_ARGS_DATA_PROTO(_args)) \
428 #include TRACEPOINT_INCLUDE
433 * Stage 4 of tracepoint event generation.
435 * Create static inline function that calculates event payload alignment.
438 /* Reset all macros within TRACEPOINT_EVENT */
439 #include <lttng/ust-tracepoint-event-reset.h>
440 #include <lttng/ust-tracepoint-event-write.h>
442 #undef _ctf_integer_ext
443 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
444 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
447 #define _ctf_float(_type, _item, _src, _nowrite) \
448 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
450 #undef _ctf_array_encoded
451 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
452 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
454 #undef _ctf_sequence_encoded
455 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
456 _src_length, _encoding, _nowrite, _elem_type_base) \
457 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
458 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
461 #define _ctf_string(_item, _src, _nowrite)
464 #define TP_ARGS(...) __VA_ARGS__
467 #define TP_FIELDS(...) __VA_ARGS__
469 #undef TRACEPOINT_EVENT_CLASS
470 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
471 static inline lttng_ust_notrace \
472 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
474 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
476 size_t __event_align = 1; \
478 return __event_align; \
481 #include TRACEPOINT_INCLUDE
485 * Stage 5 of tracepoint event generation.
487 * Create the probe function. This function calls event size calculation
488 * and writes event data into the buffer.
491 /* Reset all macros within TRACEPOINT_EVENT */
492 #include <lttng/ust-tracepoint-event-reset.h>
493 #include <lttng/ust-tracepoint-event-write.h>
495 #undef _ctf_integer_ext
496 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
498 _type __tmp = (_src); \
499 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
500 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
504 #define _ctf_float(_type, _item, _src, _nowrite) \
506 _type __tmp = (_src); \
507 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
508 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
511 #undef _ctf_array_encoded
512 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
513 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
514 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
516 #undef _ctf_sequence_encoded
517 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
518 _src_length, _encoding, _nowrite, _elem_type_base) \
520 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
521 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
522 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
524 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
525 __chan->ops->event_write(&__ctx, _src, \
526 sizeof(_type) * __get_dynamic_len(dest));
529 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
530 * tracepoint provider ABI implements event_strcpy. This dynamic check
531 * can be removed when the tracepoint provider ABI moves to 2.
533 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
534 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
538 #define _ctf_string(_item, _src, _nowrite) \
539 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
540 if (__chan->ops->u.has_strcpy) \
541 __chan->ops->event_strcpy(&__ctx, _src, \
542 __get_dynamic_len(dest)); \
544 __chan->ops->event_write(&__ctx, _src, \
545 __get_dynamic_len(dest));
547 /* Beware: this get len actually consumes the len value */
548 #undef __get_dynamic_len
549 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
552 #define TP_ARGS(...) __VA_ARGS__
555 #define TP_FIELDS(...) __VA_ARGS__
558 * For state dump, check that "session" argument (mandatory) matches the
559 * session this event belongs to. Ensures that we write state dump data only
560 * into the started session, not into all sessions.
562 #undef _TP_SESSION_CHECK
563 #ifdef TP_SESSION_CHECK
564 #define _TP_SESSION_CHECK(session, csession) (session == csession)
565 #else /* TP_SESSION_CHECK */
566 #define _TP_SESSION_CHECK(session, csession) 1
567 #endif /* TP_SESSION_CHECK */
571 #define _TP_IP_PARAM(x) (x)
572 #else /* TP_IP_PARAM */
573 #define _TP_IP_PARAM(x) __builtin_return_address(0)
574 #endif /* TP_IP_PARAM */
577 * Using twice size for filter stack data to hold size and pointer for
578 * each field (worse case). For integers, max size required is 64-bit.
579 * Same for double-precision floats. Those fit within
580 * 2*sizeof(unsigned long) for all supported architectures.
581 * Perform UNION (||) of filter runtime list.
583 #undef TRACEPOINT_EVENT_CLASS
584 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
585 static lttng_ust_notrace \
586 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
588 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
590 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
591 struct lttng_channel *__chan = __event->chan; \
592 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
593 size_t __event_len, __event_align; \
594 size_t __dynamic_len_idx = 0; \
596 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
597 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
602 (void) __dynamic_len_idx; /* don't warn if unused */ \
603 if (!_TP_SESSION_CHECK(session, __chan->session)) \
605 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
607 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
609 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
611 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
613 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
614 struct lttng_bytecode_runtime *bc_runtime; \
615 int __filter_record = __event->has_enablers_without_bytecode; \
617 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
618 _TP_ARGS_DATA_VAR(_args)); \
619 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
620 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
621 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
622 __filter_record = 1; \
624 if (caa_likely(!__filter_record)) \
627 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
628 _TP_ARGS_DATA_VAR(_args)); \
629 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
630 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
631 __event_align, -1, __chan->handle); \
632 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
633 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
637 __chan->ops->event_commit(&__ctx); \
640 #include TRACEPOINT_INCLUDE
642 #undef __get_dynamic_len
645 * Stage 5.1 of tracepoint event generation.
647 * Create probe signature
650 /* Reset all macros within TRACEPOINT_EVENT */
651 #include <lttng/ust-tracepoint-event-reset.h>
654 #define TP_ARGS(...) __VA_ARGS__
656 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
658 #undef TRACEPOINT_EVENT_CLASS
659 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
660 const char __tp_event_signature___##_provider##___##_name[] = \
661 _TP_EXTRACT_STRING2(_args);
663 #include TRACEPOINT_INCLUDE
665 #undef _TP_EXTRACT_STRING2
668 * Stage 6 of tracepoint event generation.
670 * Tracepoint loglevel mapping definition generation. We generate a
671 * symbol for each mapping for a provider/event to ensure at most a 1 to
672 * 1 mapping between events and loglevels. If the symbol is repeated,
673 * the compiler will complain.
676 /* Reset all macros within TRACEPOINT_EVENT */
677 #include <lttng/ust-tracepoint-event-reset.h>
679 #undef TRACEPOINT_LOGLEVEL
680 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
681 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
682 static const int *_loglevel___##__provider##___##__name = \
683 &_loglevel_value___##__provider##___##__name;
685 #include TRACEPOINT_INCLUDE
688 * Stage 6.1 of tracepoint event generation.
690 * Tracepoint UML URI info.
693 /* Reset all macros within TRACEPOINT_EVENT */
694 #include <lttng/ust-tracepoint-event-reset.h>
696 #undef TRACEPOINT_MODEL_EMF_URI
697 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
698 static const char *_model_emf_uri___##__provider##___##__name = __uri;
700 #include TRACEPOINT_INCLUDE
703 * Stage 7.1 of tracepoint event generation.
705 * Create events description structures. We use a weakref because
706 * loglevels are optional. If not declared, the event will point to the
707 * a loglevel that contains NULL.
710 /* Reset all macros within TRACEPOINT_EVENT */
711 #include <lttng/ust-tracepoint-event-reset.h>
713 #undef TRACEPOINT_EVENT_INSTANCE
714 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
716 __ref_loglevel___##_provider##___##_name \
717 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
718 static const char * \
719 __ref_model_emf_uri___##_provider##___##_name \
720 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
721 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
722 .name = #_provider ":" #_name, \
723 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
725 .fields = __event_fields___##_provider##___##_template, \
726 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
727 .loglevel = &__ref_loglevel___##_provider##___##_name, \
728 .signature = __tp_event_signature___##_provider##___##_template, \
729 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
732 #include TRACEPOINT_INCLUDE
735 * Stage 7.2 of tracepoint event generation.
737 * Create array of events.
740 /* Reset all macros within TRACEPOINT_EVENT */
741 #include <lttng/ust-tracepoint-event-reset.h>
743 #undef TRACEPOINT_EVENT_INSTANCE
744 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
745 &__event_desc___##_provider##_##_name,
747 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
748 #include TRACEPOINT_INCLUDE
753 * Stage 8 of tracepoint event generation.
755 * Create a toplevel descriptor for the whole probe.
758 /* non-const because list head will be modified when registered. */
759 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
760 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
761 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
762 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
763 .head
= { NULL
, NULL
},
764 .lazy_init_head
= { NULL
, NULL
},
766 .major
= LTTNG_UST_PROVIDER_MAJOR
,
767 .minor
= LTTNG_UST_PROVIDER_MINOR
,
770 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
773 * Stage 9 of tracepoint event generation.
775 * Register/unregister probes at module load/unload.
777 * Generate the constructor as an externally visible symbol for use when
778 * linking the probe statically.
780 * Register refcount is protected by libc dynamic loader mutex.
783 /* Reset all macros within TRACEPOINT_EVENT */
784 #include <lttng/ust-tracepoint-event-reset.h>
785 static void lttng_ust_notrace
__attribute__((constructor
))
786 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
788 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
792 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
793 TRACEPOINT_PROVIDER
)++) {
797 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
798 * static inline function that ensures every probe PROVIDER
799 * argument match the provider within which they appear. It
800 * calls empty static inline functions, and therefore has no
801 * runtime effect. However, if it detects an error, a linker
804 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
805 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
807 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
812 static void lttng_ust_notrace
__attribute__((destructor
))
813 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
815 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
817 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
818 TRACEPOINT_PROVIDER
)) {
821 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
824 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);