1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
3 * lttng-tracepoint-event-impl.h
5 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
6 * Copyright (C) 2009-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 #include <linux/uaccess.h>
10 #include <linux/debugfs.h>
11 #include <linux/rculist.h>
12 #include <asm/byteorder.h>
13 #include <linux/swab.h>
15 #include <probes/lttng.h>
16 #include <probes/lttng-types.h>
17 #include <probes/lttng-probe-user.h>
18 #include <include/ringbuffer/frontend_types.h>
19 #include <include/ringbuffer/backend.h>
20 #include <wrapper/user_namespace.h>
21 #include <lttng-events.h>
22 #include <lttng-tracer-core.h>
23 #include <lttng-tp-mempool.h>
25 #define __LTTNG_NULL_STRING "(null)"
28 * Macro declarations used for all stages.
32 * LTTng name mapping macros. LTTng remaps some of the kernel events to
33 * enforce name-spacing.
35 #undef LTTNG_TRACEPOINT_EVENT_MAP
36 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
37 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
41 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
43 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
44 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
45 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
47 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
49 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
50 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
51 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
58 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
60 #undef LTTNG_TRACEPOINT_EVENT_CODE
61 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
62 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
71 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
72 * handlers for events. That is, if all events have the same parameters
73 * and just have distinct trace points. Each tracepoint can be defined
74 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
75 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
77 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
81 #undef LTTNG_TRACEPOINT_EVENT
82 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
83 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
88 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
89 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
90 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
92 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
93 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
94 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
96 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
97 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
98 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
100 #undef LTTNG_TRACEPOINT_EVENT_CLASS
101 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
102 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
105 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
106 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
107 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
111 * Stage 1 of the trace events.
113 * Create dummy trace calls for each events, verifying that the LTTng module
114 * instrumentation headers match the kernel arguments. Will be optimized
115 * out by the compiler.
118 /* Reset all macros within TRACEPOINT_EVENT */
119 #include <probes/lttng-events-reset.h>
122 #define TP_PROTO(...) __VA_ARGS__
125 #define TP_ARGS(...) __VA_ARGS__
127 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
128 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
129 void trace_##_name(_proto);
131 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
132 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
133 void trace_##_name(void);
135 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
138 * Stage 1.1 of the trace events.
140 * Create dummy trace prototypes for each event class, and for each used
141 * template. This will allow checking whether the prototypes from the
142 * class and the instance using the class actually match.
145 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
148 #define TP_PROTO(...) __VA_ARGS__
151 #define TP_ARGS(...) __VA_ARGS__
153 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
154 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
155 void __event_template_proto___##_template(_proto);
157 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
158 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
159 void __event_template_proto___##_template(void);
161 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
162 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
163 void __event_template_proto___##_name(_proto);
165 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
166 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
167 void __event_template_proto___##_name(void);
169 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
172 * Stage 1.2 of tracepoint event generation
174 * Unfolding the enums
176 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
178 /* Enumeration entry (single value) */
179 #undef ctf_enum_value
180 #define ctf_enum_value(_string, _value) \
183 .signedness = lttng_is_signed_type(__typeof__(_value)), \
184 .value = lttng_is_signed_type(__typeof__(_value)) ? \
185 (long long) (_value) : (_value), \
188 .signedness = lttng_is_signed_type(__typeof__(_value)), \
189 .value = lttng_is_signed_type(__typeof__(_value)) ? \
190 (long long) (_value) : (_value), \
192 .string = (_string), \
195 /* Enumeration entry (range) */
196 #undef ctf_enum_range
197 #define ctf_enum_range(_string, _range_start, _range_end) \
200 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
201 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
202 (long long) (_range_start) : (_range_start), \
205 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
206 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
207 (long long) (_range_end) : (_range_end), \
209 .string = (_string), \
212 /* Enumeration entry (automatic value; follows the rules of CTF) */
214 #define ctf_enum_auto(_string) \
224 .string = (_string), \
230 #undef TP_ENUM_VALUES
231 #define TP_ENUM_VALUES(...) \
234 #undef LTTNG_TRACEPOINT_ENUM
235 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
236 const struct lttng_enum_entry __enum_values__##_name[] = { \
240 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
243 * Stage 2 of the trace events.
245 * Create event field type metadata section.
246 * Each event produce an array of fields.
249 /* Reset all macros within TRACEPOINT_EVENT */
250 #include <probes/lttng-events-reset.h>
251 #include <probes/lttng-events-write.h>
252 #include <probes/lttng-events-nowrite.h>
254 #undef _ctf_integer_ext
255 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
258 .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none), \
259 .nowrite = _nowrite, \
264 #undef _ctf_array_encoded
265 #define _ctf_array_encoded(_type, _item, _src, _length, \
266 _encoding, _byte_order, _elem_type_base, _user, _nowrite) \
271 .atype = atype_array_nestable, \
276 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
277 __type_integer(_type, 0, 0, -1, _byte_order, _elem_type_base, _encoding)), \
283 .nowrite = _nowrite, \
288 #undef _ctf_array_bitfield
289 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
294 .atype = atype_array_nestable, \
299 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
300 __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none)), \
301 .length = (_length) * sizeof(_type) * CHAR_BIT, \
302 .alignment = lttng_alignof(_type), \
306 .nowrite = _nowrite, \
312 #undef _ctf_sequence_encoded
313 #define _ctf_sequence_encoded(_type, _item, _src, \
314 _length_type, _src_length, _encoding, \
315 _byte_order, _elem_type_base, _user, _nowrite) \
317 .name = "_" #_item "_length", \
318 .type = __type_integer(_length_type, 0, 0, -1, __BYTE_ORDER, 10, none), \
319 .nowrite = _nowrite, \
326 .atype = atype_sequence_nestable, \
329 .sequence_nestable = \
331 .length_name = "_" #_item "_length", \
332 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
333 __type_integer(_type, 0, 0, -1, _byte_order, _elem_type_base, _encoding)), \
338 .nowrite = _nowrite, \
343 #undef _ctf_sequence_bitfield
344 #define _ctf_sequence_bitfield(_type, _item, _src, \
345 _length_type, _src_length, \
348 .name = "_" #_item "_length", \
349 .type = __type_integer(_length_type, 0, 0, -1, __BYTE_ORDER, 10, none), \
350 .nowrite = _nowrite, \
357 .atype = atype_sequence_nestable, \
360 .sequence_nestable = \
362 .length_name = "_" #_item "_length", \
363 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
364 __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none)), \
365 .alignment = lttng_alignof(_type), \
369 .nowrite = _nowrite, \
375 #define _ctf_string(_item, _src, _user, _nowrite) \
380 .atype = atype_string, \
383 .string = { .encoding = lttng_encode_UTF8 }, \
386 .nowrite = _nowrite, \
392 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
396 .atype = atype_enum_nestable, \
399 .desc = &__enum_##_name, \
400 .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
401 __type_integer(_type, 0, 0, -1, __BYTE_ORDER, 10, none)), \
405 .nowrite = _nowrite, \
410 #undef ctf_custom_field
411 #define ctf_custom_field(_type, _item, _code) \
420 #undef ctf_custom_type
421 #define ctf_custom_type(...) __VA_ARGS__
424 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
426 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
427 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
428 static const struct lttng_event_field __event_fields___##_name[] = { \
432 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
433 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
434 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
436 #undef LTTNG_TRACEPOINT_ENUM
437 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
438 static const struct lttng_enum_desc __enum_##_name = { \
440 .entries = __enum_values__##_name, \
441 .nr_entries = ARRAY_SIZE(__enum_values__##_name), \
444 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
447 * Stage 3 of the trace events.
449 * Create probe callback prototypes.
452 /* Reset all macros within TRACEPOINT_EVENT */
453 #include <probes/lttng-events-reset.h>
456 #define TP_PROTO(...) __VA_ARGS__
458 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
459 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
460 static void __event_probe__##_name(void *__data, _proto);
462 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
463 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
464 static void __event_probe__##_name(void *__data);
466 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
469 * Stage 4 of the trace events.
471 * Create static inline function that calculates event size.
474 /* Reset all macros within TRACEPOINT_EVENT */
475 #include <probes/lttng-events-reset.h>
476 #include <probes/lttng-events-write.h>
478 #undef _ctf_integer_ext
479 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
480 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
481 __event_len += sizeof(_type);
483 #undef _ctf_array_encoded
484 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
485 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
486 __event_len += sizeof(_type) * (_length);
488 #undef _ctf_array_bitfield
489 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
490 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
492 #undef _ctf_sequence_encoded
493 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
494 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
495 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
496 __event_len += sizeof(_length_type); \
497 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
499 size_t __seqlen = (_src_length); \
501 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
503 barrier(); /* reserve before use. */ \
504 this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = __seqlen; \
505 __event_len += sizeof(_type) * __seqlen; \
508 #undef _ctf_sequence_bitfield
509 #define _ctf_sequence_bitfield(_type, _item, _src, \
510 _length_type, _src_length, \
512 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
513 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
516 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
520 #define _ctf_string(_item, _src, _user, _nowrite) \
521 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
523 barrier(); /* reserve before use. */ \
525 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
526 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
528 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
529 strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1; \
533 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
534 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
537 #define ctf_align(_type) \
538 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type));
540 #undef ctf_custom_field
541 #define ctf_custom_field(_type, _item, _code) \
546 #undef ctf_custom_code
547 #define ctf_custom_code(...) __VA_ARGS__
550 #define TP_PROTO(...) __VA_ARGS__
553 #define TP_FIELDS(...) __VA_ARGS__
556 #define TP_locvar(...) __VA_ARGS__
558 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
559 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
560 static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \
562 size_t __event_len = 0; \
563 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
564 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
567 return __event_len; \
570 __attribute__((unused)); \
574 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
575 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
576 static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \
578 size_t __event_len = 0; \
579 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
580 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
583 return __event_len; \
586 __attribute__((unused)); \
590 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
594 * Stage 4.1 of tracepoint event generation.
596 * Create static inline function that layout the filter stack data.
597 * We make both write and nowrite data available to the filter.
600 /* Reset all macros within TRACEPOINT_EVENT */
601 #include <probes/lttng-events-reset.h>
602 #include <probes/lttng-events-write.h>
603 #include <probes/lttng-events-nowrite.h>
605 #undef _ctf_integer_ext_fetched
606 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
607 if (lttng_is_signed_type(_type)) { \
608 int64_t __ctf_tmp_int64; \
609 switch (sizeof(_type)) { \
612 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
613 __ctf_tmp_int64 = (int64_t) __tmp.v; \
618 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
619 if (_byte_order != __BYTE_ORDER) \
620 __swab16s(&__tmp.v); \
621 __ctf_tmp_int64 = (int64_t) __tmp.v; \
626 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
627 if (_byte_order != __BYTE_ORDER) \
628 __swab32s(&__tmp.v); \
629 __ctf_tmp_int64 = (int64_t) __tmp.v; \
634 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
635 if (_byte_order != __BYTE_ORDER) \
636 __swab64s(&__tmp.v); \
637 __ctf_tmp_int64 = (int64_t) __tmp.v; \
643 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
645 uint64_t __ctf_tmp_uint64; \
646 switch (sizeof(_type)) { \
649 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
650 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
655 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
656 if (_byte_order != __BYTE_ORDER) \
657 __swab16s(&__tmp.v); \
658 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
663 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
664 if (_byte_order != __BYTE_ORDER) \
665 __swab32s(&__tmp.v); \
666 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
671 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
672 if (_byte_order != __BYTE_ORDER) \
673 __swab64s(&__tmp.v); \
674 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
680 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
682 __stack_data += sizeof(int64_t);
684 #undef _ctf_integer_ext_isuser0
685 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
686 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
688 #undef _ctf_integer_ext_isuser1
689 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
692 char __array[sizeof(_user_src)]; \
693 __typeof__(_user_src) __v; \
695 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
696 &(_user_src), sizeof(_user_src))) \
697 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
698 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
701 #undef _ctf_integer_ext
702 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
703 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
705 #undef _ctf_array_encoded
706 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
708 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
709 const void *__ctf_tmp_ptr = (_src); \
710 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
711 __stack_data += sizeof(unsigned long); \
712 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
713 __stack_data += sizeof(void *); \
716 #undef _ctf_array_bitfield
717 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
718 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
720 #undef _ctf_sequence_encoded
721 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
722 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
724 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
725 const void *__ctf_tmp_ptr = (_src); \
726 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
727 __stack_data += sizeof(unsigned long); \
728 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
729 __stack_data += sizeof(void *); \
732 #undef _ctf_sequence_bitfield
733 #define _ctf_sequence_bitfield(_type, _item, _src, \
734 _length_type, _src_length, \
736 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
737 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
740 #define _ctf_string(_item, _src, _user, _nowrite) \
742 const void *__ctf_tmp_ptr = \
743 ((_src) ? (_src) : __LTTNG_NULL_STRING); \
744 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
745 __stack_data += sizeof(void *); \
749 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
750 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
753 #define TP_PROTO(...) __VA_ARGS__
756 #define TP_FIELDS(...) __VA_ARGS__
759 #define TP_locvar(...) __VA_ARGS__
761 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
762 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
764 void __event_prepare_filter_stack__##_name(char *__stack_data, \
767 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
772 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
773 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
775 void __event_prepare_filter_stack__##_name(char *__stack_data, \
776 void *__tp_locvar, _proto) \
778 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
783 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
786 * Stage 5 of the trace events.
788 * Create static inline function that calculates event payload alignment.
791 /* Reset all macros within TRACEPOINT_EVENT */
792 #include <probes/lttng-events-reset.h>
793 #include <probes/lttng-events-write.h>
795 #undef _ctf_integer_ext
796 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
797 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
799 #undef _ctf_array_encoded
800 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
801 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
803 #undef _ctf_array_bitfield
804 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
805 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
807 #undef _ctf_sequence_encoded
808 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
809 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
810 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
811 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
813 #undef _ctf_sequence_bitfield
814 #define _ctf_sequence_bitfield(_type, _item, _src, \
815 _length_type, _src_length, \
817 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
818 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
821 #define _ctf_string(_item, _src, _user, _nowrite)
824 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
825 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
828 #define ctf_align(_type) \
829 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
832 #define TP_PROTO(...) __VA_ARGS__
835 #define TP_FIELDS(...) __VA_ARGS__
838 #define TP_locvar(...) __VA_ARGS__
840 #undef ctf_custom_field
841 #define ctf_custom_field(_type, _item, _code) _code
843 #undef ctf_custom_code
844 #define ctf_custom_code(...) \
849 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
850 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
851 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
853 size_t __event_align = 1; \
854 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
857 return __event_align; \
860 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
861 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
862 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
864 size_t __event_align = 1; \
865 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
868 return __event_align; \
871 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
874 * Stage 6 of tracepoint event generation.
876 * Create the probe function. This function calls event size calculation
877 * and writes event data into the buffer.
880 /* Reset all macros within TRACEPOINT_EVENT */
881 #include <probes/lttng-events-reset.h>
882 #include <probes/lttng-events-write.h>
884 #undef _ctf_integer_ext_fetched
885 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
887 _type __tmp = _src; \
888 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
889 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
892 #undef _ctf_integer_ext_isuser0
893 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
894 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
896 #undef _ctf_integer_ext_isuser1
897 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
900 char __array[sizeof(_user_src)]; \
901 __typeof__(_user_src) __v; \
903 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
904 &(_user_src), sizeof(_user_src))) \
905 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
906 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
909 #undef _ctf_integer_ext
910 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
911 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
913 #undef _ctf_array_encoded
914 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
915 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
917 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
919 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
922 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
923 #undef _ctf_array_bitfield
924 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
925 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
927 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
929 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
931 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
933 * For big endian, we need to byteswap into little endian.
935 #undef _ctf_array_bitfield
936 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
937 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
941 for (_i = 0; _i < (_length); _i++) { \
945 if (get_user(_tmp, (_type *) _src + _i)) \
948 _tmp = ((_type *) _src)[_i]; \
950 switch (sizeof(_type)) { \
954 _tmp = cpu_to_le16(_tmp); \
957 _tmp = cpu_to_le32(_tmp); \
960 _tmp = cpu_to_le64(_tmp); \
965 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
968 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
970 #undef _ctf_sequence_encoded
971 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
972 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
974 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx]; \
975 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
976 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
978 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
980 __chan->ops->event_write_from_user(&__ctx, _src, \
981 sizeof(_type) * __get_dynamic_len(dest)); \
983 __chan->ops->event_write(&__ctx, _src, \
984 sizeof(_type) * __get_dynamic_len(dest)); \
987 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
988 #undef _ctf_sequence_bitfield
989 #define _ctf_sequence_bitfield(_type, _item, _src, \
990 _length_type, _src_length, \
993 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
994 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
995 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
997 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
999 __chan->ops->event_write_from_user(&__ctx, _src, \
1000 sizeof(_type) * __get_dynamic_len(dest)); \
1002 __chan->ops->event_write(&__ctx, _src, \
1003 sizeof(_type) * __get_dynamic_len(dest)); \
1005 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1007 * For big endian, we need to byteswap into little endian.
1009 #undef _ctf_sequence_bitfield
1010 #define _ctf_sequence_bitfield(_type, _item, _src, \
1011 _length_type, _src_length, \
1014 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
1015 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
1016 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
1018 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
1020 size_t _i, _length; \
1022 _length = __get_dynamic_len(dest); \
1023 for (_i = 0; _i < _length; _i++) { \
1027 if (get_user(_tmp, (_type *) _src + _i)) \
1030 _tmp = ((_type *) _src)[_i]; \
1032 switch (sizeof(_type)) { \
1036 _tmp = cpu_to_le16(_tmp); \
1039 _tmp = cpu_to_le32(_tmp); \
1042 _tmp = cpu_to_le64(_tmp); \
1047 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
1050 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1053 #define _ctf_string(_item, _src, _user, _nowrite) \
1055 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
1056 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
1057 __get_dynamic_len(dest)); \
1059 const char *__ctf_tmp_string = \
1060 ((_src) ? (_src) : __LTTNG_NULL_STRING); \
1061 lib_ring_buffer_align_ctx(&__ctx, \
1062 lttng_alignof(*__ctf_tmp_string)); \
1063 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
1064 __get_dynamic_len(dest)); \
1068 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
1069 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
1072 #define ctf_align(_type) \
1073 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type));
1075 #undef ctf_custom_field
1076 #define ctf_custom_field(_type, _item, _code) _code
1078 #undef ctf_custom_code
1079 #define ctf_custom_code(...) \
1084 /* Beware: this get len actually consumes the len value */
1085 #undef __get_dynamic_len
1086 #define __get_dynamic_len(field) this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx++]
1089 #define TP_PROTO(...) __VA_ARGS__
1092 #define TP_ARGS(...) __VA_ARGS__
1095 #define TP_FIELDS(...) __VA_ARGS__
1098 #define TP_locvar(...) __VA_ARGS__
1101 #define TP_code_pre(...) __VA_ARGS__
1104 #define TP_code_post(...) __VA_ARGS__
1107 * For state dump, check that "session" argument (mandatory) matches the
1108 * session this event belongs to. Ensures that we write state dump data only
1109 * into the started session, not into all sessions.
1111 #ifdef TP_SESSION_CHECK
1112 #define _TP_SESSION_CHECK(session, csession) (session == csession)
1113 #else /* TP_SESSION_CHECK */
1114 #define _TP_SESSION_CHECK(session, csession) 1
1115 #endif /* TP_SESSION_CHECK */
1118 * Using twice size for filter stack data to hold size and pointer for
1119 * each field (worse case). For integers, max size required is 64-bit.
1120 * Same for double-precision floats. Those fit within
1121 * 2*sizeof(unsigned long) for all supported architectures.
1122 * Perform UNION (||) of filter runtime list.
1124 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1125 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
1126 static void __event_probe__##_name(void *__data, _proto) \
1128 struct probe_local_vars { _locvar }; \
1129 struct lttng_event *__event = __data; \
1130 struct lttng_probe_ctx __lttng_probe_ctx = { \
1132 .interruptible = !irqs_disabled(), \
1134 struct lttng_channel *__chan = __event->chan; \
1135 struct lttng_session *__session = __chan->session; \
1136 struct lib_ring_buffer_ctx __ctx; \
1137 ssize_t __event_len; \
1138 size_t __event_align; \
1139 size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \
1141 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1142 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1145 struct probe_local_vars __tp_locvar; \
1146 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1148 struct lttng_id_tracker_rcu *__lf; \
1150 if (!_TP_SESSION_CHECK(session, __session)) \
1152 if (unlikely(!READ_ONCE(__session->active))) \
1154 if (unlikely(!READ_ONCE(__chan->enabled))) \
1156 if (unlikely(!READ_ONCE(__event->enabled))) \
1158 __lf = rcu_dereference_raw_check(__session->pid_tracker.p); \
1159 if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \
1161 __lf = rcu_dereference_raw_check(__session->vpid_tracker.p); \
1162 if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
1164 __lf = rcu_dereference_raw_check(__session->uid_tracker.p); \
1165 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1166 lttng_current_uid()))) \
1168 __lf = rcu_dereference_raw_check(__session->vuid_tracker.p); \
1169 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1170 lttng_current_vuid()))) \
1172 __lf = rcu_dereference_raw_check(__session->gid_tracker.p); \
1173 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1174 lttng_current_gid()))) \
1176 __lf = rcu_dereference_raw_check(__session->vgid_tracker.p); \
1177 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1178 lttng_current_vgid()))) \
1180 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1181 __dynamic_len_idx = __orig_dynamic_len_offset; \
1183 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1184 struct lttng_bytecode_runtime *bc_runtime; \
1185 int __filter_record = __event->has_enablers_without_bytecode; \
1187 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1188 tp_locvar, _args); \
1189 list_for_each_entry_rcu_notrace(bc_runtime, &__event->bytecode_runtime_head, node) { \
1190 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1191 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \
1192 __filter_record = 1; \
1196 if (likely(!__filter_record)) \
1199 __event_len = __event_get_size__##_name(tp_locvar, _args); \
1200 if (unlikely(__event_len < 0)) { \
1201 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1204 __event_align = __event_get_align__##_name(tp_locvar, _args); \
1205 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1206 __event_align, -1); \
1207 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1211 __chan->ops->event_commit(&__ctx); \
1214 barrier(); /* use before un-reserve. */ \
1215 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1219 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1220 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1221 static void __event_probe__##_name(void *__data) \
1223 struct probe_local_vars { _locvar }; \
1224 struct lttng_event *__event = __data; \
1225 struct lttng_probe_ctx __lttng_probe_ctx = { \
1227 .interruptible = !irqs_disabled(), \
1229 struct lttng_channel *__chan = __event->chan; \
1230 struct lttng_session *__session = __chan->session; \
1231 struct lib_ring_buffer_ctx __ctx; \
1232 ssize_t __event_len; \
1233 size_t __event_align; \
1234 size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \
1236 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1237 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1240 struct probe_local_vars __tp_locvar; \
1241 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1243 struct lttng_id_tracker_rcu *__lf; \
1245 if (!_TP_SESSION_CHECK(session, __session)) \
1247 if (unlikely(!READ_ONCE(__session->active))) \
1249 if (unlikely(!READ_ONCE(__chan->enabled))) \
1251 if (unlikely(!READ_ONCE(__event->enabled))) \
1253 __lf = rcu_dereference_raw_check(__session->pid_tracker.p); \
1254 if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \
1256 __lf = rcu_dereference_raw_check(__session->vpid_tracker.p); \
1257 if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
1259 __lf = rcu_dereference_raw_check(__session->uid_tracker.p); \
1260 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1261 lttng_current_uid()))) \
1263 __lf = rcu_dereference_raw_check(__session->vuid_tracker.p); \
1264 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1265 lttng_current_vuid()))) \
1267 __lf = rcu_dereference_raw_check(__session->gid_tracker.p); \
1268 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1269 lttng_current_gid()))) \
1271 __lf = rcu_dereference_raw_check(__session->vgid_tracker.p); \
1272 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1273 lttng_current_vgid()))) \
1275 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1276 __dynamic_len_idx = __orig_dynamic_len_offset; \
1278 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1279 struct lttng_bytecode_runtime *bc_runtime; \
1280 int __filter_record = __event->has_enablers_without_bytecode; \
1282 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1284 list_for_each_entry_rcu_notrace(bc_runtime, &__event->bytecode_runtime_head, node) { \
1285 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1286 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \
1287 __filter_record = 1; \
1291 if (likely(!__filter_record)) \
1294 __event_len = __event_get_size__##_name(tp_locvar); \
1295 if (unlikely(__event_len < 0)) { \
1296 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1299 __event_align = __event_get_align__##_name(tp_locvar); \
1300 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1301 __event_align, -1); \
1302 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1306 __chan->ops->event_commit(&__ctx); \
1309 barrier(); /* use before un-reserve. */ \
1310 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1314 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1316 #undef __get_dynamic_len
1319 * Stage 7 of the trace events.
1321 * Create event descriptions.
1324 /* Named field types must be defined in lttng-types.h */
1326 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1329 #define TP_PROBE_CB(_template) &__event_probe__##_template
1332 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1333 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1334 static const struct lttng_event_desc __event_desc___##_map = { \
1335 .fields = __event_fields___##_template, \
1338 .probe_callback = (void *) TP_PROBE_CB(_template), \
1339 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1340 .owner = THIS_MODULE, \
1343 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1344 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1345 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1347 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1350 * Stage 8 of the trace events.
1352 * Create an array of event description pointers.
1355 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1357 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1358 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1359 &__event_desc___##_map,
1361 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1362 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1363 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1365 #define TP_ID1(_token, _system) _token##_system
1366 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1368 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
1369 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1376 * Stage 9 of the trace events.
1378 * Create a toplevel descriptor for the whole probe.
1381 #define TP_ID1(_token, _system) _token##_system
1382 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1384 /* non-const because list head will be modified when registered. */
1385 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
1386 .provider
= __stringify(TRACE_SYSTEM
),
1387 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
1388 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
1389 .head
= { NULL
, NULL
},
1390 .lazy_init_head
= { NULL
, NULL
},
1398 * Stage 10 of the trace events.
1400 * Register/unregister probes at module load/unload.
1403 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1405 #define TP_ID1(_token, _system) _token##_system
1406 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1407 #define module_init_eval1(_token, _system) module_init(_token##_system)
1408 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1409 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1410 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1412 #ifndef TP_MODULE_NOINIT
1413 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
1415 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1418 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
1420 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1423 #ifndef TP_MODULE_NOAUTOLOAD
1424 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
1425 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
1430 #undef module_init_eval
1431 #undef module_exit_eval
This page took 0.088465 seconds and 4 git commands to generate.