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>
79 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_
, TRACEPOINT_PROVIDER
)(void)
83 #undef TRACEPOINT_EVENT_CLASS
84 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
85 __tracepoint_provider_mismatch_##_provider();
87 #undef TRACEPOINT_EVENT_INSTANCE
88 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
89 __tracepoint_provider_mismatch_##_provider();
92 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)(void)
94 #include TRACEPOINT_INCLUDE
98 * Stage 0.1 of tracepoint event generation.
100 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
101 * tracepoint name length limit.
104 /* Reset all macros within TRACEPOINT_EVENT */
105 #include <lttng/ust-tracepoint-event-reset.h>
107 #undef TRACEPOINT_EVENT_INSTANCE
108 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
110 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
111 __attribute__((unused)) = \
112 #_provider ":" #_name;
114 #include TRACEPOINT_INCLUDE
117 * Stage 1 of tracepoint event generation.
119 * Create event field type metadata section.
120 * Each event produce an array of fields.
123 /* Reset all macros within TRACEPOINT_EVENT */
124 #include <lttng/ust-tracepoint-event-reset.h>
125 #include <lttng/ust-tracepoint-event-write.h>
126 #include <lttng/ust-tracepoint-event-nowrite.h>
128 #undef _ctf_integer_ext
129 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
132 .type = __type_integer(_type, _byte_order, _base, none),\
133 .nowrite = _nowrite, \
137 #define _ctf_float(_type, _item, _src, _nowrite) \
140 .type = __type_float(_type), \
141 .nowrite = _nowrite, \
144 #undef _ctf_array_encoded
145 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
150 .atype = atype_array, \
155 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
160 .nowrite = _nowrite, \
163 #undef _ctf_sequence_encoded
164 #define _ctf_sequence_encoded(_type, _item, _src, \
165 _length_type, _src_length, _encoding, _nowrite) \
170 .atype = atype_sequence, \
175 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
176 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
180 .nowrite = _nowrite, \
184 #define _ctf_string(_item, _src, _nowrite) \
189 .atype = atype_string, \
192 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
195 .nowrite = _nowrite, \
199 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
201 #undef TRACEPOINT_EVENT_CLASS
202 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
203 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
207 #include TRACEPOINT_INCLUDE
210 * Stage 2 of tracepoint event generation.
212 * Create probe callback prototypes.
215 /* Reset all macros within TRACEPOINT_EVENT */
216 #include <lttng/ust-tracepoint-event-reset.h>
219 #define TP_ARGS(...) __VA_ARGS__
221 #undef TRACEPOINT_EVENT_CLASS
222 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
223 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
225 #include TRACEPOINT_INCLUDE
228 * Stage 3 of tracepoint event generation.
230 * Create static inline function that calculates event size.
233 /* Reset all macros within TRACEPOINT_EVENT */
234 #include <lttng/ust-tracepoint-event-reset.h>
235 #include <lttng/ust-tracepoint-event-write.h>
237 #undef _ctf_integer_ext
238 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
239 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
240 __event_len += sizeof(_type);
243 #define _ctf_float(_type, _item, _src, _nowrite) \
244 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
245 __event_len += sizeof(_type);
247 #undef _ctf_array_encoded
248 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
249 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
250 __event_len += sizeof(_type) * (_length);
252 #undef _ctf_sequence_encoded
253 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
254 _src_length, _encoding, _nowrite) \
255 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
256 __event_len += sizeof(_length_type); \
257 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
258 __dynamic_len[__dynamic_len_idx] = (_src_length); \
259 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
263 #define _ctf_string(_item, _src, _nowrite) \
264 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
267 #define TP_ARGS(...) __VA_ARGS__
270 #define TP_FIELDS(...) __VA_ARGS__
272 #undef TRACEPOINT_EVENT_CLASS
273 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
274 static inline lttng_ust_notrace \
275 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
277 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
279 size_t __event_len = 0; \
280 unsigned int __dynamic_len_idx = 0; \
283 (void) __dynamic_len_idx; /* don't warn if unused */ \
285 return __event_len; \
288 #include TRACEPOINT_INCLUDE
291 * Stage 3.1 of tracepoint event generation.
293 * Create static inline function that layout the filter stack data.
294 * We make both write and nowrite data available to the filter.
297 /* Reset all macros within TRACEPOINT_EVENT */
298 #include <lttng/ust-tracepoint-event-reset.h>
299 #include <lttng/ust-tracepoint-event-write.h>
300 #include <lttng/ust-tracepoint-event-nowrite.h>
302 #undef _ctf_integer_ext
303 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
304 if (lttng_is_signed_type(_type)) { \
305 int64_t __ctf_tmp_int64; \
306 switch (sizeof(_type)) { \
309 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
310 __ctf_tmp_int64 = (int64_t) __tmp.v; \
315 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
316 __ctf_tmp_int64 = (int64_t) __tmp.v; \
321 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
322 __ctf_tmp_int64 = (int64_t) __tmp.v; \
327 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
328 __ctf_tmp_int64 = (int64_t) __tmp.v; \
334 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
336 uint64_t __ctf_tmp_uint64; \
337 switch (sizeof(_type)) { \
340 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
341 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
346 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
347 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
352 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
353 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
358 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
359 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
365 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
367 __stack_data += sizeof(int64_t);
370 #define _ctf_float(_type, _item, _src, _nowrite) \
372 double __ctf_tmp_double = (double) (_type) (_src); \
373 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
374 __stack_data += sizeof(double); \
377 #undef _ctf_array_encoded
378 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
380 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
381 const void *__ctf_tmp_ptr = (_src); \
382 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
383 __stack_data += sizeof(unsigned long); \
384 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
385 __stack_data += sizeof(void **); \
388 #undef _ctf_sequence_encoded
389 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
390 _src_length, _encoding, _nowrite) \
392 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
393 const void *__ctf_tmp_ptr = (_src); \
394 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
395 __stack_data += sizeof(unsigned long); \
396 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
397 __stack_data += sizeof(void **); \
401 #define _ctf_string(_item, _src, _nowrite) \
403 const void *__ctf_tmp_ptr = (_src); \
404 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
405 __stack_data += sizeof(void **); \
409 #define TP_ARGS(...) __VA_ARGS__
412 #define TP_FIELDS(...) __VA_ARGS__
414 #undef TRACEPOINT_EVENT_CLASS
415 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
417 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
418 _TP_ARGS_DATA_PROTO(_args)) \
423 #include TRACEPOINT_INCLUDE
428 * Stage 4 of tracepoint event generation.
430 * Create static inline function that calculates event payload alignment.
433 /* Reset all macros within TRACEPOINT_EVENT */
434 #include <lttng/ust-tracepoint-event-reset.h>
435 #include <lttng/ust-tracepoint-event-write.h>
437 #undef _ctf_integer_ext
438 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
439 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
442 #define _ctf_float(_type, _item, _src, _nowrite) \
443 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
445 #undef _ctf_array_encoded
446 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
447 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
449 #undef _ctf_sequence_encoded
450 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
451 _src_length, _encoding, _nowrite) \
452 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
453 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
456 #define _ctf_string(_item, _src, _nowrite)
459 #define TP_ARGS(...) __VA_ARGS__
462 #define TP_FIELDS(...) __VA_ARGS__
464 #undef TRACEPOINT_EVENT_CLASS
465 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
466 static inline lttng_ust_notrace \
467 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
469 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
471 size_t __event_align = 1; \
473 return __event_align; \
476 #include TRACEPOINT_INCLUDE
480 * Stage 5 of tracepoint event generation.
482 * Create the probe function. This function calls event size calculation
483 * and writes event data into the buffer.
486 /* Reset all macros within TRACEPOINT_EVENT */
487 #include <lttng/ust-tracepoint-event-reset.h>
488 #include <lttng/ust-tracepoint-event-write.h>
490 #undef _ctf_integer_ext
491 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
493 _type __tmp = (_src); \
494 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
495 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
499 #define _ctf_float(_type, _item, _src, _nowrite) \
501 _type __tmp = (_src); \
502 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
503 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
506 #undef _ctf_array_encoded
507 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
508 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
509 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
511 #undef _ctf_sequence_encoded
512 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
513 _src_length, _encoding, _nowrite) \
515 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
516 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
517 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
519 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
520 __chan->ops->event_write(&__ctx, _src, \
521 sizeof(_type) * __get_dynamic_len(dest));
524 #define _ctf_string(_item, _src, _nowrite) \
525 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
526 __chan->ops->event_write(&__ctx, _src, __get_dynamic_len(dest));
528 /* Beware: this get len actually consumes the len value */
529 #undef __get_dynamic_len
530 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
533 #define TP_ARGS(...) __VA_ARGS__
536 #define TP_FIELDS(...) __VA_ARGS__
539 * For state dump, check that "session" argument (mandatory) matches the
540 * session this event belongs to. Ensures that we write state dump data only
541 * into the started session, not into all sessions.
543 #undef _TP_SESSION_CHECK
544 #ifdef TP_SESSION_CHECK
545 #define _TP_SESSION_CHECK(session, csession) (session == csession)
546 #else /* TP_SESSION_CHECK */
547 #define _TP_SESSION_CHECK(session, csession) 1
548 #endif /* TP_SESSION_CHECK */
551 * Using twice size for filter stack data to hold size and pointer for
552 * each field (worse case). For integers, max size required is 64-bit.
553 * Same for double-precision floats. Those fit within
554 * 2*sizeof(unsigned long) for all supported architectures.
555 * Perform UNION (||) of filter runtime list.
557 #undef TRACEPOINT_EVENT_CLASS
558 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
559 static lttng_ust_notrace \
560 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
562 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
564 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
565 struct lttng_channel *__chan = __event->chan; \
566 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
567 size_t __event_len, __event_align; \
568 size_t __dynamic_len_idx = 0; \
570 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
571 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
576 (void) __dynamic_len_idx; /* don't warn if unused */ \
577 if (!_TP_SESSION_CHECK(session, __chan->session)) \
579 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
581 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
583 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
585 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
587 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
588 struct lttng_bytecode_runtime *bc_runtime; \
589 int __filter_record = __event->has_enablers_without_bytecode; \
591 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
592 _TP_ARGS_DATA_VAR(_args)); \
593 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
594 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
595 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
596 __filter_record = 1; \
598 if (caa_likely(!__filter_record)) \
601 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
602 _TP_ARGS_DATA_VAR(_args)); \
603 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
604 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
605 __event_align, -1, __chan->handle); \
606 __ctx.ip = __builtin_return_address(0); \
607 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
611 __chan->ops->event_commit(&__ctx); \
614 #include TRACEPOINT_INCLUDE
616 #undef __get_dynamic_len
619 * Stage 5.1 of tracepoint event generation.
621 * Create probe signature
624 /* Reset all macros within TRACEPOINT_EVENT */
625 #include <lttng/ust-tracepoint-event-reset.h>
628 #define TP_ARGS(...) __VA_ARGS__
630 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
632 #undef TRACEPOINT_EVENT_CLASS
633 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
634 const char __tp_event_signature___##_provider##___##_name[] = \
635 _TP_EXTRACT_STRING2(_args);
637 #include TRACEPOINT_INCLUDE
639 #undef _TP_EXTRACT_STRING2
642 * Stage 6 of tracepoint event generation.
644 * Tracepoint loglevel mapping definition generation. We generate a
645 * symbol for each mapping for a provider/event to ensure at most a 1 to
646 * 1 mapping between events and loglevels. If the symbol is repeated,
647 * the compiler will complain.
650 /* Reset all macros within TRACEPOINT_EVENT */
651 #include <lttng/ust-tracepoint-event-reset.h>
653 #undef TRACEPOINT_LOGLEVEL
654 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
655 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
656 static const int *_loglevel___##__provider##___##__name = \
657 &_loglevel_value___##__provider##___##__name;
659 #include TRACEPOINT_INCLUDE
662 * Stage 6.1 of tracepoint event generation.
664 * Tracepoint UML URI info.
667 /* Reset all macros within TRACEPOINT_EVENT */
668 #include <lttng/ust-tracepoint-event-reset.h>
670 #undef TRACEPOINT_MODEL_EMF_URI
671 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
672 static const char *_model_emf_uri___##__provider##___##__name = __uri;
674 #include TRACEPOINT_INCLUDE
677 * Stage 7.1 of tracepoint event generation.
679 * Create events description structures. We use a weakref because
680 * loglevels are optional. If not declared, the event will point to the
681 * a loglevel that contains NULL.
684 /* Reset all macros within TRACEPOINT_EVENT */
685 #include <lttng/ust-tracepoint-event-reset.h>
687 #undef TRACEPOINT_EVENT_INSTANCE
688 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
690 __ref_loglevel___##_provider##___##_name \
691 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
692 static const char * \
693 __ref_model_emf_uri___##_provider##___##_name \
694 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
695 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
696 .name = #_provider ":" #_name, \
697 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
699 .fields = __event_fields___##_provider##___##_template, \
700 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
701 .loglevel = &__ref_loglevel___##_provider##___##_name, \
702 .signature = __tp_event_signature___##_provider##___##_template, \
703 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
706 #include TRACEPOINT_INCLUDE
709 * Stage 7.2 of tracepoint event generation.
711 * Create array of events.
714 /* Reset all macros within TRACEPOINT_EVENT */
715 #include <lttng/ust-tracepoint-event-reset.h>
717 #undef TRACEPOINT_EVENT_INSTANCE
718 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
719 &__event_desc___##_provider##_##_name,
721 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
722 #include TRACEPOINT_INCLUDE
727 * Stage 8 of tracepoint event generation.
729 * Create a toplevel descriptor for the whole probe.
732 /* non-const because list head will be modified when registered. */
733 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
734 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
735 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
736 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
737 .head
= { NULL
, NULL
},
738 .lazy_init_head
= { NULL
, NULL
},
740 .major
= LTTNG_UST_PROVIDER_MAJOR
,
741 .minor
= LTTNG_UST_PROVIDER_MINOR
,
744 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
747 * Stage 9 of tracepoint event generation.
749 * Register/unregister probes at module load/unload.
751 * Generate the constructor as an externally visible symbol for use when
752 * linking the probe statically.
754 * Register refcount is protected by libc dynamic loader mutex.
757 /* Reset all macros within TRACEPOINT_EVENT */
758 #include <lttng/ust-tracepoint-event-reset.h>
759 static void lttng_ust_notrace
__attribute__((constructor
))
760 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
762 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
766 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
767 TRACEPOINT_PROVIDER
)++) {
771 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
772 * static inline function that ensures every probe PROVIDER
773 * argument match the provider within which they appear. It
774 * calls empty static inline functions, and therefore has no
775 * runtime effect. However, if it detects an error, a linker
778 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
779 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
781 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
786 static void lttng_ust_notrace
__attribute__((destructor
))
787 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
789 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
791 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
792 TRACEPOINT_PROVIDER
)) {
795 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
798 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);