2 * lttng-tracepoint-event-impl.h
4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
5 * Copyright (C) 2009-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; only
10 * version 2.1 of the License.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <linux/uaccess.h>
23 #include <linux/debugfs.h>
24 #include <linux/rculist.h>
25 #include <asm/byteorder.h>
26 #include <linux/swab.h>
28 #include <probes/lttng.h>
29 #include <probes/lttng-types.h>
30 #include <probes/lttng-probe-user.h>
31 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
32 #include <wrapper/ringbuffer/frontend_types.h>
33 #include <wrapper/ringbuffer/backend.h>
34 #include <wrapper/rcu.h>
35 #include <lttng-events.h>
36 #include <lttng-tracer-core.h>
39 * Macro declarations used for all stages.
43 * LTTng name mapping macros. LTTng remaps some of the kernel events to
44 * enforce name-spacing.
46 #undef LTTNG_TRACEPOINT_EVENT_MAP
47 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
48 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
52 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
54 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
55 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
56 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
58 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
60 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
61 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
62 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
69 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
71 #undef LTTNG_TRACEPOINT_EVENT_CODE
72 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
73 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
82 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
83 * handlers for events. That is, if all events have the same parameters
84 * and just have distinct trace points. Each tracepoint can be defined
85 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
86 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
88 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
92 #undef LTTNG_TRACEPOINT_EVENT
93 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
94 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
99 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
100 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
101 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
103 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
104 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
105 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
107 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
108 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
109 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
111 #undef LTTNG_TRACEPOINT_EVENT_CLASS
112 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
113 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
116 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
117 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
118 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
122 * Stage 1 of the trace events.
124 * Create dummy trace calls for each events, verifying that the LTTng module
125 * instrumentation headers match the kernel arguments. Will be optimized
126 * out by the compiler.
129 /* Reset all macros within TRACEPOINT_EVENT */
130 #include <probes/lttng-events-reset.h>
133 #define TP_PROTO(...) __VA_ARGS__
136 #define TP_ARGS(...) __VA_ARGS__
138 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
139 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
140 void trace_##_name(_proto);
142 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
143 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
144 void trace_##_name(void);
146 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
149 * Stage 1.1 of the trace events.
151 * Create dummy trace prototypes for each event class, and for each used
152 * template. This will allow checking whether the prototypes from the
153 * class and the instance using the class actually match.
156 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
159 #define TP_PROTO(...) __VA_ARGS__
162 #define TP_ARGS(...) __VA_ARGS__
164 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
165 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
166 void __event_template_proto___##_template(_proto);
168 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
169 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
170 void __event_template_proto___##_template(void);
172 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
173 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
174 void __event_template_proto___##_name(_proto);
176 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
177 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
178 void __event_template_proto___##_name(void);
180 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
183 * Stage 2 of the trace events.
185 * Create event field type metadata section.
186 * Each event produce an array of fields.
189 /* Reset all macros within TRACEPOINT_EVENT */
190 #include <probes/lttng-events-reset.h>
191 #include <probes/lttng-events-write.h>
192 #include <probes/lttng-events-nowrite.h>
194 #undef _ctf_integer_ext
195 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
198 .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none),\
199 .nowrite = _nowrite, \
203 #undef _ctf_array_encoded
204 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
209 .atype = atype_array, \
214 .elem_type = __type_integer(_type, 0, 0, 0, __BYTE_ORDER, 10, _encoding), \
219 .nowrite = _nowrite, \
223 #undef _ctf_array_bitfield
224 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
229 .atype = atype_array, \
234 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
235 .length = (_length) * sizeof(_type) * CHAR_BIT, \
236 .elem_alignment = lttng_alignof(_type), \
240 .nowrite = _nowrite, \
245 #undef _ctf_sequence_encoded
246 #define _ctf_sequence_encoded(_type, _item, _src, \
247 _length_type, _src_length, _encoding, \
248 _byte_order, _base, _user, _nowrite) \
253 .atype = atype_sequence, \
258 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
259 .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _base, _encoding), \
263 .nowrite = _nowrite, \
267 #undef _ctf_sequence_bitfield
268 #define _ctf_sequence_bitfield(_type, _item, _src, \
269 _length_type, _src_length, \
275 .atype = atype_sequence, \
280 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
281 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
282 .elem_alignment = lttng_alignof(_type), \
286 .nowrite = _nowrite, \
291 #define _ctf_string(_item, _src, _user, _nowrite) \
296 .atype = atype_string, \
299 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
302 .nowrite = _nowrite, \
307 #undef ctf_custom_field
308 #define ctf_custom_field(_type, _item, _code) \
316 #undef ctf_custom_type
317 #define ctf_custom_type(...) __VA_ARGS__
320 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
322 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
323 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
324 static const struct lttng_event_field __event_fields___##_name[] = { \
328 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
329 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
330 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
332 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
335 * Stage 3 of the trace events.
337 * Create probe callback prototypes.
340 /* Reset all macros within TRACEPOINT_EVENT */
341 #include <probes/lttng-events-reset.h>
344 #define TP_PROTO(...) __VA_ARGS__
346 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
347 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
348 static void __event_probe__##_name(void *__data, _proto);
350 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
351 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
352 static void __event_probe__##_name(void *__data);
354 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
357 * Stage 4 of the trace events.
359 * Create static inline function that calculates event size.
362 /* Reset all macros within TRACEPOINT_EVENT */
363 #include <probes/lttng-events-reset.h>
364 #include <probes/lttng-events-write.h>
366 #undef _ctf_integer_ext
367 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
368 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
369 __event_len += sizeof(_type);
371 #undef _ctf_array_encoded
372 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
373 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
374 __event_len += sizeof(_type) * (_length);
376 #undef _ctf_array_bitfield
377 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
378 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
380 #undef _ctf_sequence_encoded
381 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
382 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
383 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
384 __event_len += sizeof(_length_type); \
385 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
387 size_t __seqlen = (_src_length); \
389 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
391 barrier(); /* reserve before use. */ \
392 this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = __seqlen; \
393 __event_len += sizeof(_type) * __seqlen; \
396 #undef _ctf_sequence_bitfield
397 #define _ctf_sequence_bitfield(_type, _item, _src, \
398 _length_type, _src_length, \
400 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
401 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
404 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
408 #define _ctf_string(_item, _src, _user, _nowrite) \
409 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
411 barrier(); /* reserve before use. */ \
413 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
414 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
416 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
421 #define ctf_align(_type) \
422 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type));
424 #undef ctf_custom_field
425 #define ctf_custom_field(_type, _item, _code) \
430 #undef ctf_custom_code
431 #define ctf_custom_code(...) __VA_ARGS__
434 #define TP_PROTO(...) __VA_ARGS__
437 #define TP_FIELDS(...) __VA_ARGS__
440 #define TP_locvar(...) __VA_ARGS__
442 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
443 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
444 static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \
446 size_t __event_len = 0; \
447 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
448 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
451 return __event_len; \
454 __attribute__((unused)); \
458 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
459 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
460 static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \
462 size_t __event_len = 0; \
463 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
464 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
467 return __event_len; \
470 __attribute__((unused)); \
474 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
478 * Stage 4.1 of tracepoint event generation.
480 * Create static inline function that layout the filter stack data.
481 * We make both write and nowrite data available to the filter.
484 /* Reset all macros within TRACEPOINT_EVENT */
485 #include <probes/lttng-events-reset.h>
486 #include <probes/lttng-events-write.h>
487 #include <probes/lttng-events-nowrite.h>
489 #undef _ctf_integer_ext_fetched
490 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
491 if (lttng_is_signed_type(_type)) { \
492 int64_t __ctf_tmp_int64; \
493 switch (sizeof(_type)) { \
496 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
497 __ctf_tmp_int64 = (int64_t) __tmp.v; \
502 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
503 if (_byte_order != __BYTE_ORDER) \
504 __swab16s(&__tmp.v); \
505 __ctf_tmp_int64 = (int64_t) __tmp.v; \
510 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
511 if (_byte_order != __BYTE_ORDER) \
512 __swab32s(&__tmp.v); \
513 __ctf_tmp_int64 = (int64_t) __tmp.v; \
518 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
519 if (_byte_order != __BYTE_ORDER) \
520 __swab64s(&__tmp.v); \
521 __ctf_tmp_int64 = (int64_t) __tmp.v; \
527 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
529 uint64_t __ctf_tmp_uint64; \
530 switch (sizeof(_type)) { \
533 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
534 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
539 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
540 if (_byte_order != __BYTE_ORDER) \
541 __swab16s(&__tmp.v); \
542 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
547 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
548 if (_byte_order != __BYTE_ORDER) \
549 __swab32s(&__tmp.v); \
550 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
555 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
556 if (_byte_order != __BYTE_ORDER) \
557 __swab64s(&__tmp.v); \
558 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
564 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
566 __stack_data += sizeof(int64_t);
568 #undef _ctf_integer_ext_isuser0
569 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
570 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
572 #undef _ctf_integer_ext_isuser1
573 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
576 char __array[sizeof(_user_src)]; \
577 __typeof__(_user_src) __v; \
579 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
580 &(_user_src), sizeof(_user_src))) \
581 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
582 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
585 #undef _ctf_integer_ext
586 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
587 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
589 #undef _ctf_array_encoded
590 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
592 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
593 const void *__ctf_tmp_ptr = (_src); \
594 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
595 __stack_data += sizeof(unsigned long); \
596 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
597 __stack_data += sizeof(void *); \
600 #undef _ctf_array_bitfield
601 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
602 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
604 #undef _ctf_sequence_encoded
605 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
606 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
608 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
609 const void *__ctf_tmp_ptr = (_src); \
610 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
611 __stack_data += sizeof(unsigned long); \
612 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
613 __stack_data += sizeof(void *); \
616 #undef _ctf_sequence_bitfield
617 #define _ctf_sequence_bitfield(_type, _item, _src, \
618 _length_type, _src_length, \
620 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
621 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
624 #define _ctf_string(_item, _src, _user, _nowrite) \
626 const void *__ctf_tmp_ptr = (_src); \
627 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
628 __stack_data += sizeof(void *); \
632 #define TP_PROTO(...) __VA_ARGS__
635 #define TP_FIELDS(...) __VA_ARGS__
638 #define TP_locvar(...) __VA_ARGS__
640 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
641 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
643 void __event_prepare_filter_stack__##_name(char *__stack_data, \
646 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
651 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
652 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
654 void __event_prepare_filter_stack__##_name(char *__stack_data, \
655 void *__tp_locvar, _proto) \
657 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
662 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
665 * Stage 5 of the trace events.
667 * Create static inline function that calculates event payload alignment.
670 /* Reset all macros within TRACEPOINT_EVENT */
671 #include <probes/lttng-events-reset.h>
672 #include <probes/lttng-events-write.h>
674 #undef _ctf_integer_ext
675 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
676 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
678 #undef _ctf_array_encoded
679 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
680 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
682 #undef _ctf_array_bitfield
683 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
684 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
686 #undef _ctf_sequence_encoded
687 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
688 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
689 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
690 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
692 #undef _ctf_sequence_bitfield
693 #define _ctf_sequence_bitfield(_type, _item, _src, \
694 _length_type, _src_length, \
696 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
697 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
700 #define _ctf_string(_item, _src, _user, _nowrite)
703 #define ctf_align(_type) \
704 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
707 #define TP_PROTO(...) __VA_ARGS__
710 #define TP_FIELDS(...) __VA_ARGS__
713 #define TP_locvar(...) __VA_ARGS__
715 #undef ctf_custom_field
716 #define ctf_custom_field(_type, _item, _code) _code
718 #undef ctf_custom_code
719 #define ctf_custom_code(...) \
724 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
725 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
726 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
728 size_t __event_align = 1; \
729 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
732 return __event_align; \
735 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
736 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
737 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
739 size_t __event_align = 1; \
740 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
743 return __event_align; \
746 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
749 * Stage 6 of tracepoint event generation.
751 * Create the probe function. This function calls event size calculation
752 * and writes event data into the buffer.
755 /* Reset all macros within TRACEPOINT_EVENT */
756 #include <probes/lttng-events-reset.h>
757 #include <probes/lttng-events-write.h>
759 #undef _ctf_integer_ext_fetched
760 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
762 _type __tmp = _src; \
763 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
764 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
767 #undef _ctf_integer_ext_isuser0
768 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
769 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
771 #undef _ctf_integer_ext_isuser1
772 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
775 char __array[sizeof(_user_src)]; \
776 __typeof__(_user_src) __v; \
778 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
779 &(_user_src), sizeof(_user_src))) \
780 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
781 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
784 #undef _ctf_integer_ext
785 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
786 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
788 #undef _ctf_array_encoded
789 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
790 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
792 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
794 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
797 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
798 #undef _ctf_array_bitfield
799 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
800 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
802 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
804 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
806 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
808 * For big endian, we need to byteswap into little endian.
810 #undef _ctf_array_bitfield
811 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
812 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
816 for (_i = 0; _i < (_length); _i++) { \
820 if (get_user(_tmp, (_type *) _src + _i)) \
823 _tmp = ((_type *) _src)[_i]; \
825 switch (sizeof(_type)) { \
829 _tmp = cpu_to_le16(_tmp); \
832 _tmp = cpu_to_le32(_tmp); \
835 _tmp = cpu_to_le64(_tmp); \
840 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
843 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
845 #undef _ctf_sequence_encoded
846 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
847 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
849 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx]; \
850 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
851 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
853 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
855 __chan->ops->event_write_from_user(&__ctx, _src, \
856 sizeof(_type) * __get_dynamic_len(dest)); \
858 __chan->ops->event_write(&__ctx, _src, \
859 sizeof(_type) * __get_dynamic_len(dest)); \
862 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
863 #undef _ctf_sequence_bitfield
864 #define _ctf_sequence_bitfield(_type, _item, _src, \
865 _length_type, _src_length, \
868 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
869 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
870 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
872 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
874 __chan->ops->event_write_from_user(&__ctx, _src, \
875 sizeof(_type) * __get_dynamic_len(dest)); \
877 __chan->ops->event_write(&__ctx, _src, \
878 sizeof(_type) * __get_dynamic_len(dest)); \
880 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
882 * For big endian, we need to byteswap into little endian.
884 #undef _ctf_sequence_bitfield
885 #define _ctf_sequence_bitfield(_type, _item, _src, \
886 _length_type, _src_length, \
889 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
890 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
891 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
893 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
895 size_t _i, _length; \
897 _length = __get_dynamic_len(dest); \
898 for (_i = 0; _i < _length; _i++) { \
902 if (get_user(_tmp, (_type *) _src + _i)) \
905 _tmp = ((_type *) _src)[_i]; \
907 switch (sizeof(_type)) { \
911 _tmp = cpu_to_le16(_tmp); \
914 _tmp = cpu_to_le32(_tmp); \
917 _tmp = cpu_to_le64(_tmp); \
922 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
925 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
928 #define _ctf_string(_item, _src, _user, _nowrite) \
929 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
931 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
932 __get_dynamic_len(dest)); \
934 __chan->ops->event_strcpy(&__ctx, _src, \
935 __get_dynamic_len(dest)); \
940 #define ctf_align(_type) \
941 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type));
943 #undef ctf_custom_field
944 #define ctf_custom_field(_type, _item, _code) _code
946 #undef ctf_custom_code
947 #define ctf_custom_code(...) \
952 /* Beware: this get len actually consumes the len value */
953 #undef __get_dynamic_len
954 #define __get_dynamic_len(field) this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx++]
957 #define TP_PROTO(...) __VA_ARGS__
960 #define TP_ARGS(...) __VA_ARGS__
963 #define TP_FIELDS(...) __VA_ARGS__
966 #define TP_locvar(...) __VA_ARGS__
969 #define TP_code_pre(...) __VA_ARGS__
972 #define TP_code_post(...) __VA_ARGS__
975 * For state dump, check that "session" argument (mandatory) matches the
976 * session this event belongs to. Ensures that we write state dump data only
977 * into the started session, not into all sessions.
979 #ifdef TP_SESSION_CHECK
980 #define _TP_SESSION_CHECK(session, csession) (session == csession)
981 #else /* TP_SESSION_CHECK */
982 #define _TP_SESSION_CHECK(session, csession) 1
983 #endif /* TP_SESSION_CHECK */
986 * Using twice size for filter stack data to hold size and pointer for
987 * each field (worse case). For integers, max size required is 64-bit.
988 * Same for double-precision floats. Those fit within
989 * 2*sizeof(unsigned long) for all supported architectures.
990 * Perform UNION (||) of filter runtime list.
992 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
993 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
994 static void __event_probe__##_name(void *__data, _proto) \
996 struct probe_local_vars { _locvar }; \
997 struct lttng_event *__event = __data; \
998 struct lttng_probe_ctx __lttng_probe_ctx = { \
1000 .interruptible = !irqs_disabled(), \
1002 struct lttng_channel *__chan = __event->chan; \
1003 struct lttng_session *__session = __chan->session; \
1004 struct lib_ring_buffer_ctx __ctx; \
1005 ssize_t __event_len; \
1006 size_t __event_align; \
1007 size_t __orig_dynamic_len_offset, __dynamic_len_idx; \
1009 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1010 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1013 struct probe_local_vars __tp_locvar; \
1014 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1016 struct lttng_pid_tracker *__lpf; \
1018 if (!_TP_SESSION_CHECK(session, __session)) \
1020 if (unlikely(!ACCESS_ONCE(__session->active))) \
1022 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
1024 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
1026 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
1027 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
1029 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1030 __dynamic_len_idx = __orig_dynamic_len_offset; \
1032 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1033 struct lttng_bytecode_runtime *bc_runtime; \
1034 int __filter_record = __event->has_enablers_without_bytecode; \
1036 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1037 tp_locvar, _args); \
1038 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1039 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1040 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1041 __filter_record = 1; \
1043 if (likely(!__filter_record)) \
1046 __event_len = __event_get_size__##_name(tp_locvar, _args); \
1047 if (unlikely(__event_len < 0)) { \
1048 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1051 __event_align = __event_get_align__##_name(tp_locvar, _args); \
1052 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1053 __event_align, -1); \
1054 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1058 __chan->ops->event_commit(&__ctx); \
1061 barrier(); /* use before un-reserve. */ \
1062 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1066 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1067 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1068 static void __event_probe__##_name(void *__data) \
1070 struct probe_local_vars { _locvar }; \
1071 struct lttng_event *__event = __data; \
1072 struct lttng_probe_ctx __lttng_probe_ctx = { \
1074 .interruptible = !irqs_disabled(), \
1076 struct lttng_channel *__chan = __event->chan; \
1077 struct lttng_session *__session = __chan->session; \
1078 struct lib_ring_buffer_ctx __ctx; \
1079 ssize_t __event_len; \
1080 size_t __event_align; \
1081 size_t __orig_dynamic_len_offset, __dynamic_len_idx; \
1083 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1084 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1087 struct probe_local_vars __tp_locvar; \
1088 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1090 struct lttng_pid_tracker *__lpf; \
1092 if (!_TP_SESSION_CHECK(session, __session)) \
1094 if (unlikely(!ACCESS_ONCE(__session->active))) \
1096 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
1098 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
1100 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
1101 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
1103 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1104 __dynamic_len_idx = __orig_dynamic_len_offset; \
1106 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1107 struct lttng_bytecode_runtime *bc_runtime; \
1108 int __filter_record = __event->has_enablers_without_bytecode; \
1110 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1112 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1113 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1114 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1115 __filter_record = 1; \
1117 if (likely(!__filter_record)) \
1120 __event_len = __event_get_size__##_name(tp_locvar); \
1121 if (unlikely(__event_len < 0)) { \
1122 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1125 __event_align = __event_get_align__##_name(tp_locvar); \
1126 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1127 __event_align, -1); \
1128 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1132 __chan->ops->event_commit(&__ctx); \
1135 barrier(); /* use before un-reserve. */ \
1136 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1140 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1142 #undef __get_dynamic_len
1145 * Stage 7 of the trace events.
1147 * Create event descriptions.
1150 /* Named field types must be defined in lttng-types.h */
1152 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1155 #define TP_PROBE_CB(_template) &__event_probe__##_template
1158 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1159 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1160 static const struct lttng_event_desc __event_desc___##_map = { \
1161 .fields = __event_fields___##_template, \
1164 .probe_callback = (void *) TP_PROBE_CB(_template), \
1165 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1166 .owner = THIS_MODULE, \
1169 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1170 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1171 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1173 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1176 * Stage 8 of the trace events.
1178 * Create an array of event description pointers.
1181 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1183 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1184 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1185 &__event_desc___##_map,
1187 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1188 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1189 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1191 #define TP_ID1(_token, _system) _token##_system
1192 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1194 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
1195 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1202 * Stage 9 of the trace events.
1204 * Create a toplevel descriptor for the whole probe.
1207 #define TP_ID1(_token, _system) _token##_system
1208 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1210 /* non-const because list head will be modified when registered. */
1211 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
1212 .provider
= __stringify(TRACE_SYSTEM
),
1213 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
1214 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
1215 .head
= { NULL
, NULL
},
1216 .lazy_init_head
= { NULL
, NULL
},
1224 * Stage 10 of the trace events.
1226 * Register/unregister probes at module load/unload.
1229 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1231 #define TP_ID1(_token, _system) _token##_system
1232 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1233 #define module_init_eval1(_token, _system) module_init(_token##_system)
1234 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1235 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1236 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1238 #ifndef TP_MODULE_NOINIT
1239 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
1241 wrapper_vmalloc_sync_all();
1242 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1245 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
1247 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1250 #ifndef TP_MODULE_NOAUTOLOAD
1251 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
1252 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
1257 #undef module_init_eval
1258 #undef module_exit_eval
This page took 0.085631 seconds and 4 git commands to generate.