1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
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 <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
19 #include <wrapper/ringbuffer/frontend_types.h>
20 #include <wrapper/ringbuffer/backend.h>
21 #include <wrapper/rcu.h>
22 #include <wrapper/user_namespace.h>
23 #include <lttng-events.h>
24 #include <lttng-tracer-core.h>
25 #include <lttng-tp-mempool.h>
27 #define __LTTNG_NULL_STRING "(null)"
30 * Macro declarations used for all stages.
34 * LTTng name mapping macros. LTTng remaps some of the kernel events to
35 * enforce name-spacing.
37 #undef LTTNG_TRACEPOINT_EVENT_MAP
38 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
39 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
43 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
45 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
46 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
47 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
49 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
51 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
52 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
53 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
60 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
62 #undef LTTNG_TRACEPOINT_EVENT_CODE
63 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
64 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
73 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
74 * handlers for events. That is, if all events have the same parameters
75 * and just have distinct trace points. Each tracepoint can be defined
76 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
77 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
79 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
83 #undef LTTNG_TRACEPOINT_EVENT
84 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
85 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
90 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
91 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
92 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
94 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
95 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
96 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
98 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
99 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
100 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
102 #undef LTTNG_TRACEPOINT_EVENT_CLASS
103 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
104 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
107 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
108 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
109 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
113 * Stage 1 of the trace events.
115 * Create dummy trace calls for each events, verifying that the LTTng module
116 * instrumentation headers match the kernel arguments. Will be optimized
117 * out by the compiler.
120 /* Reset all macros within TRACEPOINT_EVENT */
121 #include <probes/lttng-events-reset.h>
124 #define TP_PROTO(...) __VA_ARGS__
127 #define TP_ARGS(...) __VA_ARGS__
129 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
130 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
131 void trace_##_name(_proto);
133 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
134 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
135 void trace_##_name(void);
137 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
140 * Stage 1.1 of the trace events.
142 * Create dummy trace prototypes for each event class, and for each used
143 * template. This will allow checking whether the prototypes from the
144 * class and the instance using the class actually match.
147 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
150 #define TP_PROTO(...) __VA_ARGS__
153 #define TP_ARGS(...) __VA_ARGS__
155 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
156 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
157 void __event_template_proto___##_template(_proto);
159 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
160 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
161 void __event_template_proto___##_template(void);
163 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
164 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
165 void __event_template_proto___##_name(_proto);
167 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
168 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
169 void __event_template_proto___##_name(void);
171 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
174 * Stage 1.2 of the trace trigger.
176 * Create dummy trace prototypes for each event class, and for each used
177 * template. This will allow checking whether the prototypes from the
178 * class and the instance using the class actually match.
181 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
184 #define TP_PROTO(...) __VA_ARGS__
187 #define TP_ARGS(...) __VA_ARGS__
189 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
190 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
191 void __trigger_template_proto___##_template(_proto);
193 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
194 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
195 void __trigger_template_proto___##_template(void);
197 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
198 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
199 void __trigger_template_proto___##_name(_proto);
201 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
202 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
203 void __trigger_template_proto___##_name(void);
205 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
209 * Stage 1.2 of tracepoint event generation
211 * Unfolding the enums
213 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
215 /* Enumeration entry (single value) */
216 #undef ctf_enum_value
217 #define ctf_enum_value(_string, _value) \
220 .signedness = lttng_is_signed_type(__typeof__(_value)), \
221 .value = lttng_is_signed_type(__typeof__(_value)) ? \
222 (long long) (_value) : (_value), \
225 .signedness = lttng_is_signed_type(__typeof__(_value)), \
226 .value = lttng_is_signed_type(__typeof__(_value)) ? \
227 (long long) (_value) : (_value), \
229 .string = (_string), \
232 /* Enumeration entry (range) */
233 #undef ctf_enum_range
234 #define ctf_enum_range(_string, _range_start, _range_end) \
237 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
238 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
239 (long long) (_range_start) : (_range_start), \
242 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
243 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
244 (long long) (_range_end) : (_range_end), \
246 .string = (_string), \
249 /* Enumeration entry (automatic value; follows the rules of CTF) */
251 #define ctf_enum_auto(_string) \
261 .string = (_string), \
267 #undef TP_ENUM_VALUES
268 #define TP_ENUM_VALUES(...) \
271 #undef LTTNG_TRACEPOINT_ENUM
272 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
273 const struct lttng_enum_entry __enum_values__##_name[] = { \
277 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
280 * Stage 2 of the trace events.
282 * Create event field type metadata section.
283 * Each event produce an array of fields.
286 /* Reset all macros within TRACEPOINT_EVENT */
287 #include <probes/lttng-events-reset.h>
288 #include <probes/lttng-events-write.h>
289 #include <probes/lttng-events-nowrite.h>
291 #undef _ctf_integer_ext
292 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
295 .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none),\
296 .nowrite = _nowrite, \
300 #undef _ctf_array_encoded
301 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
306 .atype = atype_array, \
311 .elem_type = __type_integer(_type, 0, 0, 0, _byte_order, _base, _encoding), \
316 .nowrite = _nowrite, \
320 #undef _ctf_array_bitfield
321 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
326 .atype = atype_array_bitfield, \
331 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
332 .length = (_length) * sizeof(_type) * CHAR_BIT, \
333 .elem_alignment = lttng_alignof(_type), \
337 .nowrite = _nowrite, \
342 #undef _ctf_sequence_encoded
343 #define _ctf_sequence_encoded(_type, _item, _src, \
344 _length_type, _src_length, _encoding, \
345 _byte_order, _base, _user, _nowrite) \
350 .atype = atype_sequence, \
355 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
356 .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _base, _encoding), \
360 .nowrite = _nowrite, \
364 #undef _ctf_sequence_bitfield
365 #define _ctf_sequence_bitfield(_type, _item, _src, \
366 _length_type, _src_length, \
372 .atype = atype_sequence_bitfield, \
377 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
378 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
379 .elem_alignment = lttng_alignof(_type), \
383 .nowrite = _nowrite, \
388 #define _ctf_string(_item, _src, _user, _nowrite) \
393 .atype = atype_string, \
396 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
399 .nowrite = _nowrite, \
404 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
408 .atype = atype_enum, \
412 .desc = &__enum_##_name, \
413 .container_type = { \
414 .size = sizeof(_type) * CHAR_BIT, \
415 .alignment = lttng_alignof(_type) * CHAR_BIT, \
416 .signedness = lttng_is_signed_type(_type), \
417 .reverse_byte_order = 0, \
419 .encoding = lttng_encode_none, \
425 .nowrite = _nowrite, \
429 #undef ctf_custom_field
430 #define ctf_custom_field(_type, _item, _code) \
438 #undef ctf_custom_type
439 #define ctf_custom_type(...) __VA_ARGS__
442 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
444 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
445 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
446 static const struct lttng_event_field __event_fields___##_name[] = { \
450 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
451 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
452 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
454 #undef LTTNG_TRACEPOINT_ENUM
455 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
456 static const struct lttng_enum_desc __enum_##_name = { \
458 .entries = __enum_values__##_name, \
459 .nr_entries = ARRAY_SIZE(__enum_values__##_name), \
462 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
465 * Stage 3 of the trace events.
467 * Create probe callback prototypes.
470 /* Reset all macros within TRACEPOINT_EVENT */
471 #include <probes/lttng-events-reset.h>
474 #define TP_PROTO(...) __VA_ARGS__
476 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
477 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
478 static void __event_probe__##_name(void *__data, _proto);
480 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
481 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
482 static void __event_probe__##_name(void *__data);
484 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
487 * Stage 3.1 of the trace triggers.
489 * Create trigger probe callback prototypes.
492 /* Reset all macros within TRACEPOINT_EVENT */
493 #include <probes/lttng-events-reset.h>
496 #define TP_PROTO(...) __VA_ARGS__
498 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
499 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
500 static void __trigger_probe__##_name(void *__data, _proto);
502 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
503 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
504 static void __trigger_probe__##_name(void *__data);
506 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
509 * Stage 4 of the trace events.
511 * Create static inline function that calculates event size.
514 /* Reset all macros within TRACEPOINT_EVENT */
515 #include <probes/lttng-events-reset.h>
516 #include <probes/lttng-events-write.h>
518 #undef _ctf_integer_ext
519 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
520 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
521 __event_len += sizeof(_type);
523 #undef _ctf_array_encoded
524 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
525 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
526 __event_len += sizeof(_type) * (_length);
528 #undef _ctf_array_bitfield
529 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
530 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
532 #undef _ctf_sequence_encoded
533 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
534 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
535 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
536 __event_len += sizeof(_length_type); \
537 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
539 size_t __seqlen = (_src_length); \
541 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
543 barrier(); /* reserve before use. */ \
544 this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = __seqlen; \
545 __event_len += sizeof(_type) * __seqlen; \
548 #undef _ctf_sequence_bitfield
549 #define _ctf_sequence_bitfield(_type, _item, _src, \
550 _length_type, _src_length, \
552 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
553 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
556 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
560 #define _ctf_string(_item, _src, _user, _nowrite) \
561 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
563 barrier(); /* reserve before use. */ \
565 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
566 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
568 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
569 strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1; \
573 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
574 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
577 #define ctf_align(_type) \
578 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type));
580 #undef ctf_custom_field
581 #define ctf_custom_field(_type, _item, _code) \
586 #undef ctf_custom_code
587 #define ctf_custom_code(...) __VA_ARGS__
590 #define TP_PROTO(...) __VA_ARGS__
593 #define TP_FIELDS(...) __VA_ARGS__
596 #define TP_locvar(...) __VA_ARGS__
598 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
599 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
600 static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \
602 size_t __event_len = 0; \
603 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
604 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
607 return __event_len; \
610 __attribute__((unused)); \
614 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
615 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
616 static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \
618 size_t __event_len = 0; \
619 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
620 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
623 return __event_len; \
626 __attribute__((unused)); \
630 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
634 * Stage 4.1 of tracepoint event generation.
636 * Create static inline function that layout the filter stack data.
637 * We make both write and nowrite data available to the filter.
640 /* Reset all macros within TRACEPOINT_EVENT */
641 #include <probes/lttng-events-reset.h>
642 #include <probes/lttng-events-write.h>
643 #include <probes/lttng-events-nowrite.h>
645 #undef _ctf_integer_ext_fetched
646 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
647 if (lttng_is_signed_type(_type)) { \
648 int64_t __ctf_tmp_int64; \
649 switch (sizeof(_type)) { \
652 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
653 __ctf_tmp_int64 = (int64_t) __tmp.v; \
658 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
659 if (_byte_order != __BYTE_ORDER) \
660 __swab16s(&__tmp.v); \
661 __ctf_tmp_int64 = (int64_t) __tmp.v; \
666 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
667 if (_byte_order != __BYTE_ORDER) \
668 __swab32s(&__tmp.v); \
669 __ctf_tmp_int64 = (int64_t) __tmp.v; \
674 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
675 if (_byte_order != __BYTE_ORDER) \
676 __swab64s(&__tmp.v); \
677 __ctf_tmp_int64 = (int64_t) __tmp.v; \
683 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
685 uint64_t __ctf_tmp_uint64; \
686 switch (sizeof(_type)) { \
689 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
690 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
695 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
696 if (_byte_order != __BYTE_ORDER) \
697 __swab16s(&__tmp.v); \
698 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
703 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
704 if (_byte_order != __BYTE_ORDER) \
705 __swab32s(&__tmp.v); \
706 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
711 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
712 if (_byte_order != __BYTE_ORDER) \
713 __swab64s(&__tmp.v); \
714 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
720 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
722 __stack_data += sizeof(int64_t);
724 #undef _ctf_integer_ext_isuser0
725 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
726 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
728 #undef _ctf_integer_ext_isuser1
729 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
732 char __array[sizeof(_user_src)]; \
733 __typeof__(_user_src) __v; \
735 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
736 &(_user_src), sizeof(_user_src))) \
737 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
738 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
741 #undef _ctf_integer_ext
742 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
743 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
745 #undef _ctf_array_encoded
746 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
748 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
749 const void *__ctf_tmp_ptr = (_src); \
750 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
751 __stack_data += sizeof(unsigned long); \
752 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
753 __stack_data += sizeof(void *); \
756 #undef _ctf_array_bitfield
757 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
758 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
760 #undef _ctf_sequence_encoded
761 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
762 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
764 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
765 const void *__ctf_tmp_ptr = (_src); \
766 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
767 __stack_data += sizeof(unsigned long); \
768 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
769 __stack_data += sizeof(void *); \
772 #undef _ctf_sequence_bitfield
773 #define _ctf_sequence_bitfield(_type, _item, _src, \
774 _length_type, _src_length, \
776 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
777 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
780 #define _ctf_string(_item, _src, _user, _nowrite) \
782 const void *__ctf_tmp_ptr = \
783 ((_src) ? (_src) : __LTTNG_NULL_STRING); \
784 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
785 __stack_data += sizeof(void *); \
789 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
790 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
793 #define TP_PROTO(...) __VA_ARGS__
796 #define TP_FIELDS(...) __VA_ARGS__
799 #define TP_locvar(...) __VA_ARGS__
801 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
802 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
804 void __event_prepare_filter_stack__##_name(char *__stack_data, \
807 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
812 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
813 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
815 void __event_prepare_filter_stack__##_name(char *__stack_data, \
816 void *__tp_locvar, _proto) \
818 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
823 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
826 * Stage 5 of the trace events.
828 * Create static inline function that calculates event payload alignment.
831 /* Reset all macros within TRACEPOINT_EVENT */
832 #include <probes/lttng-events-reset.h>
833 #include <probes/lttng-events-write.h>
835 #undef _ctf_integer_ext
836 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
837 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
839 #undef _ctf_array_encoded
840 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
841 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
843 #undef _ctf_array_bitfield
844 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
845 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
847 #undef _ctf_sequence_encoded
848 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
849 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
850 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
851 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
853 #undef _ctf_sequence_bitfield
854 #define _ctf_sequence_bitfield(_type, _item, _src, \
855 _length_type, _src_length, \
857 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
858 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
861 #define _ctf_string(_item, _src, _user, _nowrite)
864 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
865 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
868 #define ctf_align(_type) \
869 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
872 #define TP_PROTO(...) __VA_ARGS__
875 #define TP_FIELDS(...) __VA_ARGS__
878 #define TP_locvar(...) __VA_ARGS__
880 #undef ctf_custom_field
881 #define ctf_custom_field(_type, _item, _code) _code
883 #undef ctf_custom_code
884 #define ctf_custom_code(...) \
889 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
890 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
891 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
893 size_t __event_align = 1; \
894 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
897 return __event_align; \
900 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
901 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
902 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
904 size_t __event_align = 1; \
905 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
908 return __event_align; \
911 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
914 * Stage 6 of tracepoint event generation.
916 * Create the probe function. This function calls event size calculation
917 * and writes event data into the buffer.
920 /* Reset all macros within TRACEPOINT_EVENT */
921 #include <probes/lttng-events-reset.h>
922 #include <probes/lttng-events-write.h>
924 #undef _ctf_integer_ext_fetched
925 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
927 _type __tmp = _src; \
928 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
929 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
932 #undef _ctf_integer_ext_isuser0
933 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
934 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
936 #undef _ctf_integer_ext_isuser1
937 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
940 char __array[sizeof(_user_src)]; \
941 __typeof__(_user_src) __v; \
943 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
944 &(_user_src), sizeof(_user_src))) \
945 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
946 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
949 #undef _ctf_integer_ext
950 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
951 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
953 #undef _ctf_array_encoded
954 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
955 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
957 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
959 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
962 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
963 #undef _ctf_array_bitfield
964 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
965 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
967 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
969 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
971 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
973 * For big endian, we need to byteswap into little endian.
975 #undef _ctf_array_bitfield
976 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
977 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
981 for (_i = 0; _i < (_length); _i++) { \
985 if (get_user(_tmp, (_type *) _src + _i)) \
988 _tmp = ((_type *) _src)[_i]; \
990 switch (sizeof(_type)) { \
994 _tmp = cpu_to_le16(_tmp); \
997 _tmp = cpu_to_le32(_tmp); \
1000 _tmp = cpu_to_le64(_tmp); \
1005 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
1008 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1010 #undef _ctf_sequence_encoded
1011 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
1012 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
1014 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx]; \
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 __chan->ops->event_write_from_user(&__ctx, _src, \
1021 sizeof(_type) * __get_dynamic_len(dest)); \
1023 __chan->ops->event_write(&__ctx, _src, \
1024 sizeof(_type) * __get_dynamic_len(dest)); \
1027 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
1028 #undef _ctf_sequence_bitfield
1029 #define _ctf_sequence_bitfield(_type, _item, _src, \
1030 _length_type, _src_length, \
1033 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
1034 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
1035 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
1037 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
1039 __chan->ops->event_write_from_user(&__ctx, _src, \
1040 sizeof(_type) * __get_dynamic_len(dest)); \
1042 __chan->ops->event_write(&__ctx, _src, \
1043 sizeof(_type) * __get_dynamic_len(dest)); \
1045 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1047 * For big endian, we need to byteswap into little endian.
1049 #undef _ctf_sequence_bitfield
1050 #define _ctf_sequence_bitfield(_type, _item, _src, \
1051 _length_type, _src_length, \
1054 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
1055 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
1056 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
1058 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
1060 size_t _i, _length; \
1062 _length = __get_dynamic_len(dest); \
1063 for (_i = 0; _i < _length; _i++) { \
1067 if (get_user(_tmp, (_type *) _src + _i)) \
1070 _tmp = ((_type *) _src)[_i]; \
1072 switch (sizeof(_type)) { \
1076 _tmp = cpu_to_le16(_tmp); \
1079 _tmp = cpu_to_le32(_tmp); \
1082 _tmp = cpu_to_le64(_tmp); \
1087 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
1090 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1093 #define _ctf_string(_item, _src, _user, _nowrite) \
1095 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
1096 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
1097 __get_dynamic_len(dest)); \
1099 const char *__ctf_tmp_string = \
1100 ((_src) ? (_src) : __LTTNG_NULL_STRING); \
1101 lib_ring_buffer_align_ctx(&__ctx, \
1102 lttng_alignof(*__ctf_tmp_string)); \
1103 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
1104 __get_dynamic_len(dest)); \
1108 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
1109 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
1112 #define ctf_align(_type) \
1113 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type));
1115 #undef ctf_custom_field
1116 #define ctf_custom_field(_type, _item, _code) _code
1118 #undef ctf_custom_code
1119 #define ctf_custom_code(...) \
1124 /* Beware: this get len actually consumes the len value */
1125 #undef __get_dynamic_len
1126 #define __get_dynamic_len(field) this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx++]
1129 #define TP_PROTO(...) __VA_ARGS__
1132 #define TP_ARGS(...) __VA_ARGS__
1135 #define TP_FIELDS(...) __VA_ARGS__
1138 #define TP_locvar(...) __VA_ARGS__
1141 #define TP_code_pre(...) __VA_ARGS__
1144 #define TP_code_post(...) __VA_ARGS__
1147 * For state dump, check that "session" argument (mandatory) matches the
1148 * session this event belongs to. Ensures that we write state dump data only
1149 * into the started session, not into all sessions.
1151 #ifdef TP_SESSION_CHECK
1152 #define _TP_SESSION_CHECK(session, csession) (session == csession)
1153 #else /* TP_SESSION_CHECK */
1154 #define _TP_SESSION_CHECK(session, csession) 1
1155 #endif /* TP_SESSION_CHECK */
1158 * Using twice size for filter stack data to hold size and pointer for
1159 * each field (worse case). For integers, max size required is 64-bit.
1160 * Same for double-precision floats. Those fit within
1161 * 2*sizeof(unsigned long) for all supported architectures.
1162 * Perform UNION (||) of filter runtime list.
1164 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1165 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
1166 static void __event_probe__##_name(void *__data, _proto) \
1168 struct probe_local_vars { _locvar }; \
1169 struct lttng_event *__event = __data; \
1170 struct lttng_probe_ctx __lttng_probe_ctx = { \
1173 .interruptible = !irqs_disabled(), \
1175 struct lttng_channel *__chan = __event->chan; \
1176 struct lttng_session *__session = __chan->session; \
1177 struct lib_ring_buffer_ctx __ctx; \
1178 ssize_t __event_len; \
1179 size_t __event_align; \
1180 size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \
1182 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1183 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1186 struct probe_local_vars __tp_locvar; \
1187 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1189 struct lttng_id_tracker_rcu *__lf; \
1191 if (!_TP_SESSION_CHECK(session, __session)) \
1193 if (unlikely(!READ_ONCE(__session->active))) \
1195 if (unlikely(!READ_ONCE(__chan->enabled))) \
1197 if (unlikely(!READ_ONCE(__event->enabled))) \
1199 __lf = lttng_rcu_dereference(__session->pid_tracker.p); \
1200 if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \
1202 __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \
1203 if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
1205 __lf = lttng_rcu_dereference(__session->uid_tracker.p); \
1206 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1207 lttng_current_uid()))) \
1209 __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \
1210 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1211 lttng_current_vuid()))) \
1213 __lf = lttng_rcu_dereference(__session->gid_tracker.p); \
1214 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1215 lttng_current_gid()))) \
1217 __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \
1218 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1219 lttng_current_vgid()))) \
1221 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1222 __dynamic_len_idx = __orig_dynamic_len_offset; \
1224 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1225 struct lttng_bytecode_runtime *bc_runtime; \
1226 int __filter_record = __event->has_enablers_without_bytecode; \
1228 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1229 tp_locvar, _args); \
1230 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1231 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1232 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1233 __filter_record = 1; \
1235 if (likely(!__filter_record)) \
1238 __event_len = __event_get_size__##_name(tp_locvar, _args); \
1239 if (unlikely(__event_len < 0)) { \
1240 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1243 __event_align = __event_get_align__##_name(tp_locvar, _args); \
1244 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1245 __event_align, -1); \
1246 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1250 __chan->ops->event_commit(&__ctx); \
1253 barrier(); /* use before un-reserve. */ \
1254 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1258 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1259 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1260 static void __event_probe__##_name(void *__data) \
1262 struct probe_local_vars { _locvar }; \
1263 struct lttng_event *__event = __data; \
1264 struct lttng_probe_ctx __lttng_probe_ctx = { \
1267 .interruptible = !irqs_disabled(), \
1269 struct lttng_channel *__chan = __event->chan; \
1270 struct lttng_session *__session = __chan->session; \
1271 struct lib_ring_buffer_ctx __ctx; \
1272 ssize_t __event_len; \
1273 size_t __event_align; \
1274 size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \
1276 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1277 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1280 struct probe_local_vars __tp_locvar; \
1281 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1283 struct lttng_id_tracker_rcu *__lf; \
1285 if (!_TP_SESSION_CHECK(session, __session)) \
1287 if (unlikely(!READ_ONCE(__session->active))) \
1289 if (unlikely(!READ_ONCE(__chan->enabled))) \
1291 if (unlikely(!READ_ONCE(__event->enabled))) \
1293 __lf = lttng_rcu_dereference(__session->pid_tracker.p); \
1294 if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \
1296 __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \
1297 if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
1299 __lf = lttng_rcu_dereference(__session->uid_tracker.p); \
1300 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1301 lttng_current_uid()))) \
1303 __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \
1304 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1305 lttng_current_vuid()))) \
1307 __lf = lttng_rcu_dereference(__session->gid_tracker.p); \
1308 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1309 lttng_current_gid()))) \
1311 __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \
1312 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1313 lttng_current_vgid()))) \
1315 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1316 __dynamic_len_idx = __orig_dynamic_len_offset; \
1318 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1319 struct lttng_bytecode_runtime *bc_runtime; \
1320 int __filter_record = __event->has_enablers_without_bytecode; \
1322 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1324 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1325 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1326 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1327 __filter_record = 1; \
1329 if (likely(!__filter_record)) \
1332 __event_len = __event_get_size__##_name(tp_locvar); \
1333 if (unlikely(__event_len < 0)) { \
1334 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1337 __event_align = __event_get_align__##_name(tp_locvar); \
1338 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1339 __event_align, -1); \
1340 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1344 __chan->ops->event_commit(&__ctx); \
1347 barrier(); /* use before un-reserve. */ \
1348 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1352 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1354 #undef __get_dynamic_len
1360 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1363 #define TP_PROTO(...) __VA_ARGS__
1366 #define TP_ARGS(...) __VA_ARGS__
1369 #define TP_FIELDS(...) __VA_ARGS__
1372 #define TP_locvar(...) __VA_ARGS__
1375 #define TP_code_pre(...) __VA_ARGS__
1378 #define TP_code_post(...) __VA_ARGS__
1381 * Using twice size for filter stack data to hold size and pointer for
1382 * each field (worse case). For integers, max size required is 64-bit.
1383 * Same for double-precision floats. Those fit within
1384 * 2*sizeof(unsigned long) for all supported architectures.
1385 * Perform UNION (||) of filter runtime list.
1387 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1388 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
1389 static void __trigger_probe__##_name(void *__data, _proto) \
1391 struct probe_local_vars { _locvar }; \
1392 struct lttng_trigger *__trigger = __data; \
1393 struct lttng_probe_ctx __lttng_probe_ctx = { \
1395 .trigger = __trigger, \
1396 .interruptible = !irqs_disabled(), \
1399 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1400 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1402 struct probe_local_vars __tp_locvar; \
1403 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1406 if (unlikely(!READ_ONCE(__trigger->enabled))) \
1409 if (unlikely(!list_empty(&__trigger->bytecode_runtime_head))) { \
1410 struct lttng_bytecode_runtime *bc_runtime; \
1411 int __filter_record = __trigger->has_enablers_without_bytecode; \
1413 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1414 tp_locvar, _args); \
1415 lttng_list_for_each_entry_rcu(bc_runtime, &__trigger->bytecode_runtime_head, node) { \
1416 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1417 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1418 __filter_record = 1; \
1420 if (likely(!__filter_record)) \
1424 __trigger->send_notification(__trigger); \
1430 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1431 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1432 static void __trigger_probe__##_name(void *__data) \
1434 struct probe_local_vars { _locvar }; \
1435 struct lttng_trigger *__trigger = __data; \
1436 struct lttng_probe_ctx __lttng_probe_ctx = { \
1438 .trigger = __trigger, \
1439 .interruptible = !irqs_disabled(), \
1442 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1443 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1445 struct probe_local_vars __tp_locvar; \
1446 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1449 if (unlikely(!READ_ONCE(__trigger->enabled))) \
1452 if (unlikely(!list_empty(&__trigger->bytecode_runtime_head))) { \
1453 struct lttng_bytecode_runtime *bc_runtime; \
1454 int __filter_record = __trigger->has_enablers_without_bytecode; \
1456 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1458 lttng_list_for_each_entry_rcu(bc_runtime, &__trigger->bytecode_runtime_head, node) { \
1459 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1460 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1461 __filter_record = 1; \
1463 if (likely(!__filter_record)) \
1467 __trigger->send_notification(__trigger); \
1473 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1475 * Stage 7 of the trace events.
1477 * Create event descriptions.
1480 /* Named field types must be defined in lttng-types.h */
1482 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1485 #define TP_PROBE_CB(_template) &__event_probe__##_template
1488 #ifndef TP_TRIGGER_PROBE_CB
1489 #define TP_TRIGGER_PROBE_CB(_template) &__trigger_probe__##_template
1492 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1493 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1494 static const struct lttng_event_desc __event_desc___##_map = { \
1495 .fields = __event_fields___##_template, \
1498 .probe_callback = (void *) TP_PROBE_CB(_template), \
1499 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1500 .owner = THIS_MODULE, \
1501 .trigger_callback = (void *) TP_TRIGGER_PROBE_CB(_template), \
1504 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1505 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1506 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1508 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1511 * Stage 8 of the trace events.
1513 * Create an array of event description pointers.
1516 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1518 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1519 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1520 &__event_desc___##_map,
1522 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1523 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1524 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1526 #define TP_ID1(_token, _system) _token##_system
1527 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1529 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
1530 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1537 * Stage 9 of the trace events.
1539 * Create a toplevel descriptor for the whole probe.
1542 #define TP_ID1(_token, _system) _token##_system
1543 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1545 /* non-const because list head will be modified when registered. */
1546 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
1547 .provider
= __stringify(TRACE_SYSTEM
),
1548 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
1549 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
1550 .head
= { NULL
, NULL
},
1551 .lazy_init_head
= { NULL
, NULL
},
1559 * Stage 10 of the trace events.
1561 * Register/unregister probes at module load/unload.
1564 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1566 #define TP_ID1(_token, _system) _token##_system
1567 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1568 #define module_init_eval1(_token, _system) module_init(_token##_system)
1569 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1570 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1571 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1573 #ifndef TP_MODULE_NOINIT
1574 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
1576 wrapper_vmalloc_sync_all();
1577 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1580 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
1582 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1585 #ifndef TP_MODULE_NOAUTOLOAD
1586 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
1587 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
1592 #undef module_init_eval
1593 #undef module_exit_eval
This page took 0.061816 seconds and 6 git commands to generate.