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) \
174 .atype = atype_sequence, \
179 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
180 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
184 .nowrite = _nowrite, \
188 #define _ctf_string(_item, _src, _nowrite) \
193 .atype = atype_string, \
196 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
199 .nowrite = _nowrite, \
203 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
205 #undef TRACEPOINT_EVENT_CLASS
206 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
207 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
211 #include TRACEPOINT_INCLUDE
214 * Stage 2 of tracepoint event generation.
216 * Create probe callback prototypes.
219 /* Reset all macros within TRACEPOINT_EVENT */
220 #include <lttng/ust-tracepoint-event-reset.h>
223 #define TP_ARGS(...) __VA_ARGS__
225 #undef TRACEPOINT_EVENT_CLASS
226 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
227 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
229 #include TRACEPOINT_INCLUDE
232 * Stage 3 of tracepoint event generation.
234 * Create static inline function that calculates event size.
237 /* Reset all macros within TRACEPOINT_EVENT */
238 #include <lttng/ust-tracepoint-event-reset.h>
239 #include <lttng/ust-tracepoint-event-write.h>
241 #undef _ctf_integer_ext
242 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
243 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
244 __event_len += sizeof(_type);
247 #define _ctf_float(_type, _item, _src, _nowrite) \
248 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
249 __event_len += sizeof(_type);
251 #undef _ctf_array_encoded
252 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
253 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
254 __event_len += sizeof(_type) * (_length);
256 #undef _ctf_sequence_encoded
257 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
258 _src_length, _encoding, _nowrite) \
259 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
260 __event_len += sizeof(_length_type); \
261 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
262 __dynamic_len[__dynamic_len_idx] = (_src_length); \
263 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
267 #define _ctf_string(_item, _src, _nowrite) \
268 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
271 #define TP_ARGS(...) __VA_ARGS__
274 #define TP_FIELDS(...) __VA_ARGS__
276 #undef TRACEPOINT_EVENT_CLASS
277 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
278 static inline lttng_ust_notrace \
279 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
281 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
283 size_t __event_len = 0; \
284 unsigned int __dynamic_len_idx = 0; \
287 (void) __dynamic_len_idx; /* don't warn if unused */ \
289 return __event_len; \
292 #include TRACEPOINT_INCLUDE
295 * Stage 3.1 of tracepoint event generation.
297 * Create static inline function that layout the filter stack data.
298 * We make both write and nowrite data available to the filter.
301 /* Reset all macros within TRACEPOINT_EVENT */
302 #include <lttng/ust-tracepoint-event-reset.h>
303 #include <lttng/ust-tracepoint-event-write.h>
304 #include <lttng/ust-tracepoint-event-nowrite.h>
306 #undef _ctf_integer_ext
307 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
308 if (lttng_is_signed_type(_type)) { \
309 int64_t __ctf_tmp_int64; \
310 switch (sizeof(_type)) { \
313 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
314 __ctf_tmp_int64 = (int64_t) __tmp.v; \
319 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
320 __ctf_tmp_int64 = (int64_t) __tmp.v; \
325 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
326 __ctf_tmp_int64 = (int64_t) __tmp.v; \
331 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
332 __ctf_tmp_int64 = (int64_t) __tmp.v; \
338 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
340 uint64_t __ctf_tmp_uint64; \
341 switch (sizeof(_type)) { \
344 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
345 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
350 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
351 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
356 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
357 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
362 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
363 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
369 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
371 __stack_data += sizeof(int64_t);
374 #define _ctf_float(_type, _item, _src, _nowrite) \
376 double __ctf_tmp_double = (double) (_type) (_src); \
377 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
378 __stack_data += sizeof(double); \
381 #undef _ctf_array_encoded
382 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
384 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
385 const void *__ctf_tmp_ptr = (_src); \
386 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
387 __stack_data += sizeof(unsigned long); \
388 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
389 __stack_data += sizeof(void *); \
392 #undef _ctf_sequence_encoded
393 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
394 _src_length, _encoding, _nowrite) \
396 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
397 const void *__ctf_tmp_ptr = (_src); \
398 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
399 __stack_data += sizeof(unsigned long); \
400 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
401 __stack_data += sizeof(void *); \
405 #define _ctf_string(_item, _src, _nowrite) \
407 const void *__ctf_tmp_ptr = (_src); \
408 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
409 __stack_data += sizeof(void *); \
413 #define TP_ARGS(...) __VA_ARGS__
416 #define TP_FIELDS(...) __VA_ARGS__
418 #undef TRACEPOINT_EVENT_CLASS
419 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
421 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
422 _TP_ARGS_DATA_PROTO(_args)) \
427 #include TRACEPOINT_INCLUDE
432 * Stage 4 of tracepoint event generation.
434 * Create static inline function that calculates event payload alignment.
437 /* Reset all macros within TRACEPOINT_EVENT */
438 #include <lttng/ust-tracepoint-event-reset.h>
439 #include <lttng/ust-tracepoint-event-write.h>
441 #undef _ctf_integer_ext
442 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
443 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
446 #define _ctf_float(_type, _item, _src, _nowrite) \
447 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
449 #undef _ctf_array_encoded
450 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
451 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
453 #undef _ctf_sequence_encoded
454 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
455 _src_length, _encoding, _nowrite) \
456 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
457 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
460 #define _ctf_string(_item, _src, _nowrite)
463 #define TP_ARGS(...) __VA_ARGS__
466 #define TP_FIELDS(...) __VA_ARGS__
468 #undef TRACEPOINT_EVENT_CLASS
469 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
470 static inline lttng_ust_notrace \
471 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
473 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
475 size_t __event_align = 1; \
477 return __event_align; \
480 #include TRACEPOINT_INCLUDE
484 * Stage 5 of tracepoint event generation.
486 * Create the probe function. This function calls event size calculation
487 * and writes event data into the buffer.
490 /* Reset all macros within TRACEPOINT_EVENT */
491 #include <lttng/ust-tracepoint-event-reset.h>
492 #include <lttng/ust-tracepoint-event-write.h>
494 #undef _ctf_integer_ext
495 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
497 _type __tmp = (_src); \
498 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
499 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
503 #define _ctf_float(_type, _item, _src, _nowrite) \
505 _type __tmp = (_src); \
506 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
507 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
510 #undef _ctf_array_encoded
511 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
512 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
513 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
515 #undef _ctf_sequence_encoded
516 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
517 _src_length, _encoding, _nowrite) \
519 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
520 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
521 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
523 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
524 __chan->ops->event_write(&__ctx, _src, \
525 sizeof(_type) * __get_dynamic_len(dest));
528 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
529 * tracepoint provider ABI implements event_strcpy. This dynamic check
530 * can be removed when the tracepoint provider ABI moves to 2.
532 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
533 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
537 #define _ctf_string(_item, _src, _nowrite) \
538 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
539 if (__chan->ops->u.has_strcpy) \
540 __chan->ops->event_strcpy(&__ctx, _src, \
541 __get_dynamic_len(dest)); \
543 __chan->ops->event_write(&__ctx, _src, \
544 __get_dynamic_len(dest));
546 /* Beware: this get len actually consumes the len value */
547 #undef __get_dynamic_len
548 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
551 #define TP_ARGS(...) __VA_ARGS__
554 #define TP_FIELDS(...) __VA_ARGS__
557 * For state dump, check that "session" argument (mandatory) matches the
558 * session this event belongs to. Ensures that we write state dump data only
559 * into the started session, not into all sessions.
561 #undef _TP_SESSION_CHECK
562 #ifdef TP_SESSION_CHECK
563 #define _TP_SESSION_CHECK(session, csession) (session == csession)
564 #else /* TP_SESSION_CHECK */
565 #define _TP_SESSION_CHECK(session, csession) 1
566 #endif /* TP_SESSION_CHECK */
570 #define _TP_IP_PARAM() ip
571 #else /* TP_IP_PARAM */
572 #define _TP_IP_PARAM() __builtin_return_address(0)
573 #endif /* TP_IP_PARAM */
576 * Using twice size for filter stack data to hold size and pointer for
577 * each field (worse case). For integers, max size required is 64-bit.
578 * Same for double-precision floats. Those fit within
579 * 2*sizeof(unsigned long) for all supported architectures.
580 * Perform UNION (||) of filter runtime list.
582 #undef TRACEPOINT_EVENT_CLASS
583 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
584 static lttng_ust_notrace \
585 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
587 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
589 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
590 struct lttng_channel *__chan = __event->chan; \
591 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
592 size_t __event_len, __event_align; \
593 size_t __dynamic_len_idx = 0; \
595 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
596 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
601 (void) __dynamic_len_idx; /* don't warn if unused */ \
602 if (!_TP_SESSION_CHECK(session, __chan->session)) \
604 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
606 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
608 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
610 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
612 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
613 struct lttng_bytecode_runtime *bc_runtime; \
614 int __filter_record = __event->has_enablers_without_bytecode; \
616 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
617 _TP_ARGS_DATA_VAR(_args)); \
618 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
619 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
620 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
621 __filter_record = 1; \
623 if (caa_likely(!__filter_record)) \
626 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
627 _TP_ARGS_DATA_VAR(_args)); \
628 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
629 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
630 __event_align, -1, __chan->handle); \
631 __ctx.ip = _TP_IP_PARAM(); \
632 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
636 __chan->ops->event_commit(&__ctx); \
639 #include TRACEPOINT_INCLUDE
641 #undef __get_dynamic_len
644 * Stage 5.1 of tracepoint event generation.
646 * Create probe signature
649 /* Reset all macros within TRACEPOINT_EVENT */
650 #include <lttng/ust-tracepoint-event-reset.h>
653 #define TP_ARGS(...) __VA_ARGS__
655 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
657 #undef TRACEPOINT_EVENT_CLASS
658 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
659 const char __tp_event_signature___##_provider##___##_name[] = \
660 _TP_EXTRACT_STRING2(_args);
662 #include TRACEPOINT_INCLUDE
664 #undef _TP_EXTRACT_STRING2
667 * Stage 6 of tracepoint event generation.
669 * Tracepoint loglevel mapping definition generation. We generate a
670 * symbol for each mapping for a provider/event to ensure at most a 1 to
671 * 1 mapping between events and loglevels. If the symbol is repeated,
672 * the compiler will complain.
675 /* Reset all macros within TRACEPOINT_EVENT */
676 #include <lttng/ust-tracepoint-event-reset.h>
678 #undef TRACEPOINT_LOGLEVEL
679 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
680 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
681 static const int *_loglevel___##__provider##___##__name = \
682 &_loglevel_value___##__provider##___##__name;
684 #include TRACEPOINT_INCLUDE
687 * Stage 6.1 of tracepoint event generation.
689 * Tracepoint UML URI info.
692 /* Reset all macros within TRACEPOINT_EVENT */
693 #include <lttng/ust-tracepoint-event-reset.h>
695 #undef TRACEPOINT_MODEL_EMF_URI
696 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
697 static const char *_model_emf_uri___##__provider##___##__name = __uri;
699 #include TRACEPOINT_INCLUDE
702 * Stage 7.1 of tracepoint event generation.
704 * Create events description structures. We use a weakref because
705 * loglevels are optional. If not declared, the event will point to the
706 * a loglevel that contains NULL.
709 /* Reset all macros within TRACEPOINT_EVENT */
710 #include <lttng/ust-tracepoint-event-reset.h>
712 #undef TRACEPOINT_EVENT_INSTANCE
713 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
715 __ref_loglevel___##_provider##___##_name \
716 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
717 static const char * \
718 __ref_model_emf_uri___##_provider##___##_name \
719 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
720 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
721 .name = #_provider ":" #_name, \
722 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
724 .fields = __event_fields___##_provider##___##_template, \
725 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
726 .loglevel = &__ref_loglevel___##_provider##___##_name, \
727 .signature = __tp_event_signature___##_provider##___##_template, \
728 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
731 #include TRACEPOINT_INCLUDE
734 * Stage 7.2 of tracepoint event generation.
736 * Create array of events.
739 /* Reset all macros within TRACEPOINT_EVENT */
740 #include <lttng/ust-tracepoint-event-reset.h>
742 #undef TRACEPOINT_EVENT_INSTANCE
743 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
744 &__event_desc___##_provider##_##_name,
746 static const struct lttng_event_desc
*_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)[] = {
747 #include TRACEPOINT_INCLUDE
752 * Stage 8 of tracepoint event generation.
754 * Create a toplevel descriptor for the whole probe.
757 /* non-const because list head will be modified when registered. */
758 static struct lttng_probe_desc
_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
) = {
759 .provider
= __tp_stringify(TRACEPOINT_PROVIDER
),
760 .event_desc
= _TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
),
761 .nr_events
= _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___
, TRACEPOINT_PROVIDER
)),
762 .head
= { NULL
, NULL
},
763 .lazy_init_head
= { NULL
, NULL
},
765 .major
= LTTNG_UST_PROVIDER_MAJOR
,
766 .minor
= LTTNG_UST_PROVIDER_MINOR
,
769 static int _TP_COMBINE_TOKENS(__probe_register_refcount___
, TRACEPOINT_PROVIDER
);
772 * Stage 9 of tracepoint event generation.
774 * Register/unregister probes at module load/unload.
776 * Generate the constructor as an externally visible symbol for use when
777 * linking the probe statically.
779 * Register refcount is protected by libc dynamic loader mutex.
782 /* Reset all macros within TRACEPOINT_EVENT */
783 #include <lttng/ust-tracepoint-event-reset.h>
784 static void lttng_ust_notrace
__attribute__((constructor
))
785 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void);
787 _TP_COMBINE_TOKENS(__lttng_events_init__
, TRACEPOINT_PROVIDER
)(void)
791 if (_TP_COMBINE_TOKENS(__probe_register_refcount___
,
792 TRACEPOINT_PROVIDER
)++) {
796 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
797 * static inline function that ensures every probe PROVIDER
798 * argument match the provider within which they appear. It
799 * calls empty static inline functions, and therefore has no
800 * runtime effect. However, if it detects an error, a linker
803 _TP_COMBINE_TOKENS(__tracepoint_provider_check_
, TRACEPOINT_PROVIDER
)();
804 ret
= lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
806 fprintf(stderr
, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret
);
811 static void lttng_ust_notrace
__attribute__((destructor
))
812 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void);
814 _TP_COMBINE_TOKENS(__lttng_events_exit__
, TRACEPOINT_PROVIDER
)(void)
816 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___
,
817 TRACEPOINT_PROVIDER
)) {
820 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___
, TRACEPOINT_PROVIDER
));
823 int _TP_COMBINE_TOKENS(__tracepoint_provider_
, TRACEPOINT_PROVIDER
);