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 <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
16 #include <ringbuffer/frontend_types.h>
17 #include <ringbuffer/backend.h>
18 #include <wrapper/rcu.h>
19 #include <wrapper/user_namespace.h>
20 #include <lttng/types.h>
21 #include <lttng/probe-user.h>
22 #include <lttng/events.h>
23 #include <lttng/tracer-core.h>
24 #include <lttng/tp-mempool.h>
26 #define __LTTNG_NULL_STRING "(null)"
29 #define PARAMS(args...) args
32 * Macro declarations used for all stages.
36 * LTTng name mapping macros. LTTng remaps some of the kernel events to
37 * enforce name-spacing.
39 #undef LTTNG_TRACEPOINT_EVENT_MAP
40 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
41 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
45 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
47 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
48 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
49 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
51 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
53 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
54 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
55 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
62 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
64 #undef LTTNG_TRACEPOINT_EVENT_CODE
65 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
66 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
75 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
76 * handlers for events. That is, if all events have the same parameters
77 * and just have distinct trace points. Each tracepoint can be defined
78 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
79 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
81 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
85 #undef LTTNG_TRACEPOINT_EVENT
86 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
87 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
92 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
93 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
94 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
96 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
97 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
98 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
100 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
101 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
102 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
104 #undef LTTNG_TRACEPOINT_EVENT_CLASS
105 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
106 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
109 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
110 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
111 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
115 * Stage 1 of the trace events.
117 * Create dummy trace calls for each events, verifying that the LTTng module
118 * instrumentation headers match the kernel arguments. Will be optimized
119 * out by the compiler.
122 /* Reset all macros within TRACEPOINT_EVENT */
123 #include <lttng/events-reset.h>
126 #define TP_PROTO(...) __VA_ARGS__
129 #define TP_ARGS(...) __VA_ARGS__
131 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
132 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
133 void trace_##_name(_proto);
135 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
136 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
137 void trace_##_name(void);
139 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
142 * Stage 1.1 of the trace events.
144 * Create dummy trace prototypes for each event class, and for each used
145 * template. This will allow checking whether the prototypes from the
146 * class and the instance using the class actually match.
149 #include <lttng/events-reset.h> /* Reset all macros within TRACE_EVENT */
152 #define TP_PROTO(...) __VA_ARGS__
155 #define TP_ARGS(...) __VA_ARGS__
157 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
158 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
159 void __event_template_proto___##_template(_proto);
161 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
162 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
163 void __event_template_proto___##_template(void);
165 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
166 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
167 void __event_template_proto___##_name(_proto);
169 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
170 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
171 void __event_template_proto___##_name(void);
173 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
176 * Stage 1.2 of the trace event_notifier.
178 * Create dummy trace prototypes for each event class, and for each used
179 * template. This will allow checking whether the prototypes from the
180 * class and the instance using the class actually match.
183 #include <lttng/events-reset.h> /* Reset all macros within TRACE_EVENT */
186 #define TP_PROTO(...) __VA_ARGS__
189 #define TP_ARGS(...) __VA_ARGS__
191 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
192 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
193 void __event_notifier_template_proto___##_template(_proto);
195 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
196 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
197 void __event_notifier_template_proto___##_template(void);
199 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
200 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
201 void __event_notifier_template_proto___##_name(_proto);
203 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
204 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
205 void __event_notifier_template_proto___##_name(void);
207 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
211 * Stage 1.2 of tracepoint event generation
213 * Unfolding the enums
215 #include <lttng/events-reset.h> /* Reset all macros within TRACE_EVENT */
217 /* Enumeration entry (single value) */
218 #undef ctf_enum_value
219 #define ctf_enum_value(_string, _value) \
222 .signedness = lttng_is_signed_type(__typeof__(_value)), \
223 .value = lttng_is_signed_type(__typeof__(_value)) ? \
224 (long long) (_value) : (_value), \
227 .signedness = lttng_is_signed_type(__typeof__(_value)), \
228 .value = lttng_is_signed_type(__typeof__(_value)) ? \
229 (long long) (_value) : (_value), \
231 .string = (_string), \
234 /* Enumeration entry (range) */
235 #undef ctf_enum_range
236 #define ctf_enum_range(_string, _range_start, _range_end) \
239 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
240 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
241 (long long) (_range_start) : (_range_start), \
244 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
245 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
246 (long long) (_range_end) : (_range_end), \
248 .string = (_string), \
251 /* Enumeration entry (automatic value; follows the rules of CTF) */
253 #define ctf_enum_auto(_string) \
263 .string = (_string), \
269 #undef TP_ENUM_VALUES
270 #define TP_ENUM_VALUES(...) \
273 #undef LTTNG_TRACEPOINT_ENUM
274 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
275 const struct lttng_enum_entry __enum_values__##_name[] = { \
279 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
282 * Stage 2 of the trace events.
284 * Create event field type metadata section.
285 * Each event produce an array of fields.
288 /* Reset all macros within TRACEPOINT_EVENT */
289 #include <lttng/events-reset.h>
290 #include <lttng/events-write.h>
291 #include <lttng/events-nowrite.h>
293 #undef _ctf_integer_ext
294 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
297 .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none), \
298 .nowrite = _nowrite, \
303 #undef _ctf_array_encoded
304 #define _ctf_array_encoded(_type, _item, _src, _length, \
305 _encoding, _byte_order, _elem_type_base, _user, _nowrite) \
310 .atype = atype_array_nestable, \
315 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
316 __type_integer(_type, 0, 0, -1, _byte_order, _elem_type_base, _encoding)), \
322 .nowrite = _nowrite, \
327 #undef _ctf_array_bitfield
328 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
333 .atype = atype_array_nestable, \
338 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
339 __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none)), \
340 .length = (_length) * sizeof(_type) * CHAR_BIT, \
341 .alignment = lttng_alignof(_type), \
345 .nowrite = _nowrite, \
351 #undef _ctf_sequence_encoded
352 #define _ctf_sequence_encoded(_type, _item, _src, \
353 _length_type, _src_length, _encoding, \
354 _byte_order, _elem_type_base, _user, _nowrite) \
356 .name = "_" #_item "_length", \
357 .type = __type_integer(_length_type, 0, 0, -1, __BYTE_ORDER, 10, none), \
358 .nowrite = _nowrite, \
365 .atype = atype_sequence_nestable, \
368 .sequence_nestable = \
370 .length_name = "_" #_item "_length", \
371 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
372 __type_integer(_type, 0, 0, -1, _byte_order, _elem_type_base, _encoding)), \
377 .nowrite = _nowrite, \
382 #undef _ctf_sequence_bitfield
383 #define _ctf_sequence_bitfield(_type, _item, _src, \
384 _length_type, _src_length, \
387 .name = "_" #_item "_length", \
388 .type = __type_integer(_length_type, 0, 0, -1, __BYTE_ORDER, 10, none), \
389 .nowrite = _nowrite, \
396 .atype = atype_sequence_nestable, \
399 .sequence_nestable = \
401 .length_name = "_" #_item "_length", \
402 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
403 __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none)), \
404 .alignment = lttng_alignof(_type), \
408 .nowrite = _nowrite, \
414 #define _ctf_string(_item, _src, _user, _nowrite) \
419 .atype = atype_string, \
422 .string = { .encoding = lttng_encode_UTF8 }, \
425 .nowrite = _nowrite, \
431 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
435 .atype = atype_enum_nestable, \
438 .desc = &__enum_##_name, \
439 .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
440 __type_integer(_type, 0, 0, -1, __BYTE_ORDER, 10, none)), \
444 .nowrite = _nowrite, \
449 #undef ctf_custom_field
450 #define ctf_custom_field(_type, _item, _code) \
459 #undef ctf_custom_type
460 #define ctf_custom_type(...) __VA_ARGS__
463 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
465 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
466 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
467 static const struct lttng_event_field __event_fields___##_name[] = { \
471 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
472 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
473 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
475 #undef LTTNG_TRACEPOINT_ENUM
476 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
477 static const struct lttng_enum_desc __enum_##_name = { \
479 .entries = __enum_values__##_name, \
480 .nr_entries = ARRAY_SIZE(__enum_values__##_name), \
483 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
486 * Stage 3 of the trace events.
488 * Create probe callback prototypes.
491 /* Reset all macros within TRACEPOINT_EVENT */
492 #include <lttng/events-reset.h>
495 #define TP_PROTO(...) __VA_ARGS__
497 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
498 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
499 static void __event_probe__##_name(void *__data, _proto);
501 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
502 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
503 static void __event_probe__##_name(void *__data);
505 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
508 * Stage 3.1 of the trace event_notifiers.
510 * Create event_notifier probe callback prototypes.
513 /* Reset all macros within TRACEPOINT_EVENT */
514 #include <lttng/events-reset.h>
517 #define TP_PROTO(...) __VA_ARGS__
519 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
520 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
521 static void __event_notifier_probe__##_name(void *__data, _proto);
523 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
524 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
525 static void __event_notifier_probe__##_name(void *__data);
527 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
530 * Stage 4 of the trace events.
532 * Create static inline function that calculates event size.
535 /* Reset all macros within TRACEPOINT_EVENT */
536 #include <lttng/events-reset.h>
537 #include <lttng/events-write.h>
539 #undef _ctf_integer_ext
540 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
541 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
542 __event_len += sizeof(_type);
544 #undef _ctf_array_encoded
545 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
546 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
547 __event_len += sizeof(_type) * (_length);
549 #undef _ctf_array_bitfield
550 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
551 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
553 #undef _ctf_sequence_encoded
554 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
555 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
556 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
557 __event_len += sizeof(_length_type); \
558 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
560 size_t __seqlen = (_src_length); \
562 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
564 barrier(); /* reserve before use. */ \
565 this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = __seqlen; \
566 __event_len += sizeof(_type) * __seqlen; \
569 #undef _ctf_sequence_bitfield
570 #define _ctf_sequence_bitfield(_type, _item, _src, \
571 _length_type, _src_length, \
573 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
574 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
577 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
581 #define _ctf_string(_item, _src, _user, _nowrite) \
582 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
584 barrier(); /* reserve before use. */ \
586 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
587 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
589 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
590 strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1; \
594 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
595 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
598 #define ctf_align(_type) \
599 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type));
601 #undef ctf_custom_field
602 #define ctf_custom_field(_type, _item, _code) \
607 #undef ctf_custom_code
608 #define ctf_custom_code(...) __VA_ARGS__
611 #define TP_PROTO(...) __VA_ARGS__
614 #define TP_FIELDS(...) __VA_ARGS__
617 #define TP_locvar(...) __VA_ARGS__
619 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
620 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
621 static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \
623 size_t __event_len = 0; \
624 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
625 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
628 return __event_len; \
631 __attribute__((unused)); \
635 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
636 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
637 static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \
639 size_t __event_len = 0; \
640 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
641 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
644 return __event_len; \
647 __attribute__((unused)); \
651 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
655 * Stage 4.1 of tracepoint event generation.
657 * Create static inline function that layout the filter stack data.
658 * We make both write and nowrite data available to the filter.
661 /* Reset all macros within TRACEPOINT_EVENT */
662 #include <lttng/events-reset.h>
663 #include <lttng/events-write.h>
664 #include <lttng/events-nowrite.h>
666 #undef _ctf_integer_ext_fetched
667 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
668 if (lttng_is_signed_type(_type)) { \
669 int64_t __ctf_tmp_int64; \
670 switch (sizeof(_type)) { \
673 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
674 __ctf_tmp_int64 = (int64_t) __tmp.v; \
679 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
680 if (_byte_order != __BYTE_ORDER) \
681 __swab16s(&__tmp.v); \
682 __ctf_tmp_int64 = (int64_t) __tmp.v; \
687 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
688 if (_byte_order != __BYTE_ORDER) \
689 __swab32s(&__tmp.v); \
690 __ctf_tmp_int64 = (int64_t) __tmp.v; \
695 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
696 if (_byte_order != __BYTE_ORDER) \
697 __swab64s(&__tmp.v); \
698 __ctf_tmp_int64 = (int64_t) __tmp.v; \
704 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
706 uint64_t __ctf_tmp_uint64; \
707 switch (sizeof(_type)) { \
710 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
711 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
716 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
717 if (_byte_order != __BYTE_ORDER) \
718 __swab16s(&__tmp.v); \
719 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
724 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
725 if (_byte_order != __BYTE_ORDER) \
726 __swab32s(&__tmp.v); \
727 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
732 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
733 if (_byte_order != __BYTE_ORDER) \
734 __swab64s(&__tmp.v); \
735 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
741 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
743 __stack_data += sizeof(int64_t);
745 #undef _ctf_integer_ext_isuser0
746 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
747 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
749 #undef _ctf_integer_ext_isuser1
750 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
753 char __array[sizeof(_user_src)]; \
754 __typeof__(_user_src) __v; \
756 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
757 &(_user_src), sizeof(_user_src))) \
758 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
759 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
762 #undef _ctf_integer_ext
763 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
764 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
766 #undef _ctf_array_encoded
767 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
769 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
770 const void *__ctf_tmp_ptr = (_src); \
771 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
772 __stack_data += sizeof(unsigned long); \
773 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
774 __stack_data += sizeof(void *); \
777 #undef _ctf_array_bitfield
778 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
779 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
781 #undef _ctf_sequence_encoded
782 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
783 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
785 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
786 const void *__ctf_tmp_ptr = (_src); \
787 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
788 __stack_data += sizeof(unsigned long); \
789 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
790 __stack_data += sizeof(void *); \
793 #undef _ctf_sequence_bitfield
794 #define _ctf_sequence_bitfield(_type, _item, _src, \
795 _length_type, _src_length, \
797 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
798 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
801 #define _ctf_string(_item, _src, _user, _nowrite) \
803 const void *__ctf_tmp_ptr = \
804 ((_src) ? (_src) : __LTTNG_NULL_STRING); \
805 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
806 __stack_data += sizeof(void *); \
810 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
811 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
814 #define TP_PROTO(...) __VA_ARGS__
817 #define TP_FIELDS(...) __VA_ARGS__
820 #define TP_locvar(...) __VA_ARGS__
822 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
823 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
825 void __event_prepare_filter_stack__##_name(char *__stack_data, \
828 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
833 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
834 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
836 void __event_prepare_filter_stack__##_name(char *__stack_data, \
837 void *__tp_locvar, _proto) \
839 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
844 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
847 * Stage 5 of the trace events.
849 * Create static inline function that calculates event payload alignment.
852 /* Reset all macros within TRACEPOINT_EVENT */
853 #include <lttng/events-reset.h>
854 #include <lttng/events-write.h>
856 #undef _ctf_integer_ext
857 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
858 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
860 #undef _ctf_array_encoded
861 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
862 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
864 #undef _ctf_array_bitfield
865 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
866 _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite)
868 #undef _ctf_sequence_encoded
869 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
870 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
871 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
872 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
874 #undef _ctf_sequence_bitfield
875 #define _ctf_sequence_bitfield(_type, _item, _src, \
876 _length_type, _src_length, \
878 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
879 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
882 #define _ctf_string(_item, _src, _user, _nowrite)
885 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
886 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
889 #define ctf_align(_type) \
890 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
893 #define TP_PROTO(...) __VA_ARGS__
896 #define TP_FIELDS(...) __VA_ARGS__
899 #define TP_locvar(...) __VA_ARGS__
901 #undef ctf_custom_field
902 #define ctf_custom_field(_type, _item, _code) _code
904 #undef ctf_custom_code
905 #define ctf_custom_code(...) \
910 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
911 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
912 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
914 size_t __event_align = 1; \
915 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
918 return __event_align; \
921 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
922 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
923 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
925 size_t __event_align = 1; \
926 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
929 return __event_align; \
932 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
935 * Stage 6 of tracepoint event generation.
937 * Create the probe function. This function calls event size calculation
938 * and writes event data into the buffer.
941 /* Reset all macros within TRACEPOINT_EVENT */
942 #include <lttng/events-reset.h>
943 #include <lttng/events-write.h>
945 #undef _ctf_integer_ext_fetched
946 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
948 _type __tmp = _src; \
949 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
950 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
953 #undef _ctf_integer_ext_isuser0
954 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
955 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
957 #undef _ctf_integer_ext_isuser1
958 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
961 char __array[sizeof(_user_src)]; \
962 __typeof__(_user_src) __v; \
964 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
965 &(_user_src), sizeof(_user_src))) \
966 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
967 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
970 #undef _ctf_integer_ext
971 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
972 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
974 #undef _ctf_array_encoded
975 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
976 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
978 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
980 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
983 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
984 #undef _ctf_array_bitfield
985 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
986 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
988 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
990 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
992 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
994 * For big endian, we need to byteswap into little endian.
996 #undef _ctf_array_bitfield
997 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
998 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
1002 for (_i = 0; _i < (_length); _i++) { \
1006 if (get_user(_tmp, (_type *) _src + _i)) \
1009 _tmp = ((_type *) _src)[_i]; \
1011 switch (sizeof(_type)) { \
1015 _tmp = cpu_to_le16(_tmp); \
1018 _tmp = cpu_to_le32(_tmp); \
1021 _tmp = cpu_to_le64(_tmp); \
1026 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
1029 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1031 #undef _ctf_sequence_encoded
1032 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
1033 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
1035 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx]; \
1036 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
1037 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
1039 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
1041 __chan->ops->event_write_from_user(&__ctx, _src, \
1042 sizeof(_type) * __get_dynamic_len(dest)); \
1044 __chan->ops->event_write(&__ctx, _src, \
1045 sizeof(_type) * __get_dynamic_len(dest)); \
1048 #if (__BYTE_ORDER == __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 __chan->ops->event_write_from_user(&__ctx, _src, \
1061 sizeof(_type) * __get_dynamic_len(dest)); \
1063 __chan->ops->event_write(&__ctx, _src, \
1064 sizeof(_type) * __get_dynamic_len(dest)); \
1066 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1068 * For big endian, we need to byteswap into little endian.
1070 #undef _ctf_sequence_bitfield
1071 #define _ctf_sequence_bitfield(_type, _item, _src, \
1072 _length_type, _src_length, \
1075 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
1076 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
1077 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
1079 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
1081 size_t _i, _length; \
1083 _length = __get_dynamic_len(dest); \
1084 for (_i = 0; _i < _length; _i++) { \
1088 if (get_user(_tmp, (_type *) _src + _i)) \
1091 _tmp = ((_type *) _src)[_i]; \
1093 switch (sizeof(_type)) { \
1097 _tmp = cpu_to_le16(_tmp); \
1100 _tmp = cpu_to_le32(_tmp); \
1103 _tmp = cpu_to_le64(_tmp); \
1108 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
1111 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1114 #define _ctf_string(_item, _src, _user, _nowrite) \
1116 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
1117 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
1118 __get_dynamic_len(dest)); \
1120 const char *__ctf_tmp_string = \
1121 ((_src) ? (_src) : __LTTNG_NULL_STRING); \
1122 lib_ring_buffer_align_ctx(&__ctx, \
1123 lttng_alignof(*__ctf_tmp_string)); \
1124 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
1125 __get_dynamic_len(dest)); \
1129 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
1130 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
1133 #define ctf_align(_type) \
1134 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type));
1136 #undef ctf_custom_field
1137 #define ctf_custom_field(_type, _item, _code) _code
1139 #undef ctf_custom_code
1140 #define ctf_custom_code(...) \
1145 /* Beware: this get len actually consumes the len value */
1146 #undef __get_dynamic_len
1147 #define __get_dynamic_len(field) this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx++]
1150 #define TP_PROTO(...) __VA_ARGS__
1153 #define TP_ARGS(...) __VA_ARGS__
1156 #define TP_FIELDS(...) __VA_ARGS__
1159 #define TP_locvar(...) __VA_ARGS__
1162 #define TP_code_pre(...) __VA_ARGS__
1165 #define TP_code_post(...) __VA_ARGS__
1168 * For state dump, check that "session" argument (mandatory) matches the
1169 * session this event belongs to. Ensures that we write state dump data only
1170 * into the started session, not into all sessions.
1172 #ifdef TP_SESSION_CHECK
1173 #define _TP_SESSION_CHECK(session, csession) (session == csession)
1174 #else /* TP_SESSION_CHECK */
1175 #define _TP_SESSION_CHECK(session, csession) 1
1176 #endif /* TP_SESSION_CHECK */
1179 * Using twice size for filter stack data to hold size and pointer for
1180 * each field (worse case). For integers, max size required is 64-bit.
1181 * Same for double-precision floats. Those fit within
1182 * 2*sizeof(unsigned long) for all supported architectures.
1183 * Perform UNION (||) of filter runtime list.
1185 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1186 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
1187 static void __event_probe__##_name(void *__data, _proto) \
1189 struct probe_local_vars { _locvar }; \
1190 struct lttng_event *__event = __data; \
1191 struct lttng_probe_ctx __lttng_probe_ctx = { \
1193 .event_notifier = NULL, \
1194 .interruptible = !irqs_disabled(), \
1196 struct lttng_channel *__chan = __event->chan; \
1197 struct lttng_session *__session = __chan->session; \
1198 struct lib_ring_buffer_ctx __ctx; \
1199 ssize_t __event_len; \
1200 size_t __event_align; \
1201 size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \
1203 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1204 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1207 struct probe_local_vars __tp_locvar; \
1208 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1210 struct lttng_id_tracker_rcu *__lf; \
1212 if (!_TP_SESSION_CHECK(session, __session)) \
1214 if (unlikely(!LTTNG_READ_ONCE(__session->active))) \
1216 if (unlikely(!LTTNG_READ_ONCE(__chan->enabled))) \
1218 if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \
1220 __lf = lttng_rcu_dereference(__session->pid_tracker.p); \
1221 if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \
1223 __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \
1224 if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
1226 __lf = lttng_rcu_dereference(__session->uid_tracker.p); \
1227 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1228 lttng_current_uid()))) \
1230 __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \
1231 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1232 lttng_current_vuid()))) \
1234 __lf = lttng_rcu_dereference(__session->gid_tracker.p); \
1235 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1236 lttng_current_gid()))) \
1238 __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \
1239 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1240 lttng_current_vgid()))) \
1242 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1243 __dynamic_len_idx = __orig_dynamic_len_offset; \
1245 if (unlikely(!list_empty(&__event->filter_bytecode_runtime_head))) { \
1246 struct lttng_bytecode_runtime *bc_runtime; \
1247 int __filter_record = __event->has_enablers_without_bytecode; \
1249 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1250 tp_locvar, _args); \
1251 lttng_list_for_each_entry_rcu(bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
1252 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1253 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \
1254 __filter_record = 1; \
1258 if (likely(!__filter_record)) \
1261 __event_len = __event_get_size__##_name(tp_locvar, _args); \
1262 if (unlikely(__event_len < 0)) { \
1263 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1266 __event_align = __event_get_align__##_name(tp_locvar, _args); \
1267 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1268 __event_align, -1); \
1269 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1273 __chan->ops->event_commit(&__ctx); \
1276 barrier(); /* use before un-reserve. */ \
1277 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1281 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1282 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1283 static void __event_probe__##_name(void *__data) \
1285 struct probe_local_vars { _locvar }; \
1286 struct lttng_event *__event = __data; \
1287 struct lttng_probe_ctx __lttng_probe_ctx = { \
1289 .event_notifier = NULL, \
1290 .interruptible = !irqs_disabled(), \
1292 struct lttng_channel *__chan = __event->chan; \
1293 struct lttng_session *__session = __chan->session; \
1294 struct lib_ring_buffer_ctx __ctx; \
1295 ssize_t __event_len; \
1296 size_t __event_align; \
1297 size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \
1299 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1300 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1303 struct probe_local_vars __tp_locvar; \
1304 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1306 struct lttng_id_tracker_rcu *__lf; \
1308 if (!_TP_SESSION_CHECK(session, __session)) \
1310 if (unlikely(!LTTNG_READ_ONCE(__session->active))) \
1312 if (unlikely(!LTTNG_READ_ONCE(__chan->enabled))) \
1314 if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \
1316 __lf = lttng_rcu_dereference(__session->pid_tracker.p); \
1317 if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \
1319 __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \
1320 if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
1322 __lf = lttng_rcu_dereference(__session->uid_tracker.p); \
1323 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1324 lttng_current_uid()))) \
1326 __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \
1327 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1328 lttng_current_vuid()))) \
1330 __lf = lttng_rcu_dereference(__session->gid_tracker.p); \
1331 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1332 lttng_current_gid()))) \
1334 __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \
1335 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1336 lttng_current_vgid()))) \
1338 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1339 __dynamic_len_idx = __orig_dynamic_len_offset; \
1341 if (unlikely(!list_empty(&__event->filter_bytecode_runtime_head))) { \
1342 struct lttng_bytecode_runtime *bc_runtime; \
1343 int __filter_record = __event->has_enablers_without_bytecode; \
1345 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1347 lttng_list_for_each_entry_rcu(bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
1348 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1349 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \
1350 __filter_record = 1; \
1354 if (likely(!__filter_record)) \
1357 __event_len = __event_get_size__##_name(tp_locvar); \
1358 if (unlikely(__event_len < 0)) { \
1359 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1362 __event_align = __event_get_align__##_name(tp_locvar); \
1363 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1364 __event_align, -1); \
1365 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1369 __chan->ops->event_commit(&__ctx); \
1372 barrier(); /* use before un-reserve. */ \
1373 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1377 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1379 #undef __get_dynamic_len
1382 * Stage 6.1 of tracepoint generation: generate event notifier probes
1384 * Create the probe function. This function evaluates the filter bytecode and
1385 * queue a notification to be sent to userspace.
1388 #include <lttng/events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1391 #define TP_PROTO(...) __VA_ARGS__
1394 #define TP_ARGS(...) __VA_ARGS__
1397 #define TP_FIELDS(...) __VA_ARGS__
1400 #define TP_locvar(...) __VA_ARGS__
1403 #define TP_code_pre(...) __VA_ARGS__
1406 #define TP_code_post(...) __VA_ARGS__
1409 * Using twice size for filter stack data to hold size and pointer for
1410 * each field (worse case). For integers, max size required is 64-bit.
1411 * Same for double-precision floats. Those fit within
1412 * 2*sizeof(unsigned long) for all supported architectures.
1413 * Perform UNION (||) of filter runtime list.
1415 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1416 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
1417 static void __event_notifier_probe__##_name(void *__data, _proto) \
1419 struct probe_local_vars { _locvar }; \
1420 struct lttng_event_notifier *__event_notifier = __data; \
1421 struct lttng_probe_ctx __lttng_probe_ctx = { \
1423 .event_notifier = __event_notifier, \
1424 .interruptible = !irqs_disabled(), \
1427 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1428 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1430 struct probe_local_vars __tp_locvar; \
1431 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1434 if (unlikely(!READ_ONCE(__event_notifier->enabled))) \
1437 if (unlikely(!list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \
1438 struct lttng_bytecode_runtime *bc_runtime; \
1439 int __filter_record = __event_notifier->has_enablers_without_bytecode; \
1441 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1442 tp_locvar, _args); \
1443 lttng_list_for_each_entry_rcu(bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \
1444 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1445 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1446 __filter_record = 1; \
1448 if (likely(!__filter_record)) \
1452 __event_notifier->send_notification(__event_notifier); \
1458 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1459 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1460 static void __event_notifier_probe__##_name(void *__data) \
1462 struct probe_local_vars { _locvar }; \
1463 struct lttng_event_notifier *__event_notifier = __data; \
1464 struct lttng_probe_ctx __lttng_probe_ctx = { \
1466 .event_notifier = __event_notifier, \
1467 .interruptible = !irqs_disabled(), \
1470 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1471 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1473 struct probe_local_vars __tp_locvar; \
1474 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1477 if (unlikely(!READ_ONCE(__event_notifier->enabled))) \
1480 if (unlikely(!list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \
1481 struct lttng_bytecode_runtime *bc_runtime; \
1482 int __filter_record = __event_notifier->has_enablers_without_bytecode; \
1484 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1486 lttng_list_for_each_entry_rcu(bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \
1487 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1488 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1489 __filter_record = 1; \
1491 if (likely(!__filter_record)) \
1495 __event_notifier->send_notification(__event_notifier); \
1501 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1503 * Stage 7 of the trace events.
1505 * Create event descriptions.
1508 /* Named field types must be defined in lttng-types.h */
1510 #include <lttng/events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1513 #define TP_PROBE_CB(_template) &__event_probe__##_template
1516 #ifndef TP_EVENT_NOTIFIER_PROBE_CB
1517 #define TP_EVENT_NOTIFIER_PROBE_CB(_template) &__event_notifier_probe__##_template
1520 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1521 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1522 static const struct lttng_event_desc __event_desc___##_map = { \
1523 .fields = __event_fields___##_template, \
1526 .probe_callback = (void *) TP_PROBE_CB(_template), \
1527 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1528 .owner = THIS_MODULE, \
1529 .event_notifier_callback = (void *) TP_EVENT_NOTIFIER_PROBE_CB(_template), \
1532 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1533 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1534 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1536 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1539 * Stage 8 of the trace events.
1541 * Create an array of event description pointers.
1544 #include <lttng/events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1546 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1547 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1548 &__event_desc___##_map,
1550 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1551 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1552 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1554 #define TP_ID1(_token, _system) _token##_system
1555 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1557 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
1558 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1565 * Stage 9 of the trace events.
1567 * Create a toplevel descriptor for the whole probe.
1570 #define TP_ID1(_token, _system) _token##_system
1571 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1573 /* non-const because list head will be modified when registered. */
1574 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
1575 .provider
= __stringify(TRACE_SYSTEM
),
1576 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
1577 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
1578 .head
= { NULL
, NULL
},
1579 .lazy_init_head
= { NULL
, NULL
},
1587 * Stage 10 of the trace events.
1589 * Register/unregister probes at module load/unload.
1592 #include <lttng/events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1594 #define TP_ID1(_token, _system) _token##_system
1595 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1596 #define module_init_eval1(_token, _system) module_init(_token##_system)
1597 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1598 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1599 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1601 #ifndef TP_MODULE_NOINIT
1602 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
1604 wrapper_vmalloc_sync_mappings();
1605 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1608 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
1610 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1613 #ifndef TP_MODULE_NOAUTOLOAD
1614 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
1615 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
1620 #undef module_init_eval
1621 #undef module_exit_eval
This page took 0.081348 seconds and 4 git commands to generate.