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 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
309 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
310 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
311 static const struct lttng_event_field __event_fields___##_name[] = { \
315 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
316 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
317 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
319 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
322 * Stage 3 of the trace events.
324 * Create probe callback prototypes.
327 /* Reset all macros within TRACEPOINT_EVENT */
328 #include <probes/lttng-events-reset.h>
331 #define TP_PROTO(...) __VA_ARGS__
333 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
334 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
335 static void __event_probe__##_name(void *__data, _proto);
337 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
338 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
339 static void __event_probe__##_name(void *__data);
341 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
344 * Stage 4 of the trace events.
346 * Create static inline function that calculates event size.
349 /* Reset all macros within TRACEPOINT_EVENT */
350 #include <probes/lttng-events-reset.h>
351 #include <probes/lttng-events-write.h>
353 #undef _ctf_integer_ext
354 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
355 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
356 __event_len += sizeof(_type);
358 #undef _ctf_array_encoded
359 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
360 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
361 __event_len += sizeof(_type) * (_length);
363 #undef _ctf_array_bitfield
364 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
365 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
367 #undef _ctf_sequence_encoded
368 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
369 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
370 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
371 __event_len += sizeof(_length_type); \
372 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
374 size_t __seqlen = (_src_length); \
376 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
378 barrier(); /* reserve before use. */ \
379 this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = __seqlen; \
380 __event_len += sizeof(_type) * __seqlen; \
383 #undef _ctf_sequence_bitfield
384 #define _ctf_sequence_bitfield(_type, _item, _src, \
385 _length_type, _src_length, \
387 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
388 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
391 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
395 #define _ctf_string(_item, _src, _user, _nowrite) \
396 if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
398 barrier(); /* reserve before use. */ \
400 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
401 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
403 __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \
408 #define TP_PROTO(...) __VA_ARGS__
411 #define TP_FIELDS(...) __VA_ARGS__
414 #define TP_locvar(...) __VA_ARGS__
416 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
417 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
418 static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \
420 size_t __event_len = 0; \
421 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
422 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
425 return __event_len; \
428 __attribute__((unused)); \
432 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
433 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
434 static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \
436 size_t __event_len = 0; \
437 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
438 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
441 return __event_len; \
444 __attribute__((unused)); \
448 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
452 * Stage 4.1 of tracepoint event generation.
454 * Create static inline function that layout the filter stack data.
455 * We make both write and nowrite data available to the filter.
458 /* Reset all macros within TRACEPOINT_EVENT */
459 #include <probes/lttng-events-reset.h>
460 #include <probes/lttng-events-write.h>
461 #include <probes/lttng-events-nowrite.h>
463 #undef _ctf_integer_ext_fetched
464 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
465 if (lttng_is_signed_type(_type)) { \
466 int64_t __ctf_tmp_int64; \
467 switch (sizeof(_type)) { \
470 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
471 __ctf_tmp_int64 = (int64_t) __tmp.v; \
476 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
477 if (_byte_order != __BYTE_ORDER) \
478 __swab16s(&__tmp.v); \
479 __ctf_tmp_int64 = (int64_t) __tmp.v; \
484 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
485 if (_byte_order != __BYTE_ORDER) \
486 __swab32s(&__tmp.v); \
487 __ctf_tmp_int64 = (int64_t) __tmp.v; \
492 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
493 if (_byte_order != __BYTE_ORDER) \
494 __swab64s(&__tmp.v); \
495 __ctf_tmp_int64 = (int64_t) __tmp.v; \
501 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
503 uint64_t __ctf_tmp_uint64; \
504 switch (sizeof(_type)) { \
507 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
508 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
513 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
514 if (_byte_order != __BYTE_ORDER) \
515 __swab16s(&__tmp.v); \
516 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
521 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
522 if (_byte_order != __BYTE_ORDER) \
523 __swab32s(&__tmp.v); \
524 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
529 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
530 if (_byte_order != __BYTE_ORDER) \
531 __swab64s(&__tmp.v); \
532 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
538 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
540 __stack_data += sizeof(int64_t);
542 #undef _ctf_integer_ext_isuser0
543 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
544 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
546 #undef _ctf_integer_ext_isuser1
547 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
550 char __array[sizeof(_user_src)]; \
551 __typeof__(_user_src) __v; \
553 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
554 &(_user_src), sizeof(_user_src))) \
555 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
556 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
559 #undef _ctf_integer_ext
560 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
561 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
563 #undef _ctf_array_encoded
564 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
566 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
567 const void *__ctf_tmp_ptr = (_src); \
568 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
569 __stack_data += sizeof(unsigned long); \
570 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
571 __stack_data += sizeof(void *); \
574 #undef _ctf_array_bitfield
575 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
576 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
578 #undef _ctf_sequence_encoded
579 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
580 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
582 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
583 const void *__ctf_tmp_ptr = (_src); \
584 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
585 __stack_data += sizeof(unsigned long); \
586 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
587 __stack_data += sizeof(void *); \
590 #undef _ctf_sequence_bitfield
591 #define _ctf_sequence_bitfield(_type, _item, _src, \
592 _length_type, _src_length, \
594 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
595 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
598 #define _ctf_string(_item, _src, _user, _nowrite) \
600 const void *__ctf_tmp_ptr = (_src); \
601 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
602 __stack_data += sizeof(void *); \
606 #define TP_PROTO(...) __VA_ARGS__
609 #define TP_FIELDS(...) __VA_ARGS__
612 #define TP_locvar(...) __VA_ARGS__
614 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
615 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
617 void __event_prepare_filter_stack__##_name(char *__stack_data, \
620 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
625 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
626 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
628 void __event_prepare_filter_stack__##_name(char *__stack_data, \
629 void *__tp_locvar, _proto) \
631 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
636 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
639 * Stage 5 of the trace events.
641 * Create static inline function that calculates event payload alignment.
644 /* Reset all macros within TRACEPOINT_EVENT */
645 #include <probes/lttng-events-reset.h>
646 #include <probes/lttng-events-write.h>
648 #undef _ctf_integer_ext
649 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
650 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
652 #undef _ctf_array_encoded
653 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
654 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
656 #undef _ctf_array_bitfield
657 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
658 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
660 #undef _ctf_sequence_encoded
661 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
662 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
663 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
664 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
666 #undef _ctf_sequence_bitfield
667 #define _ctf_sequence_bitfield(_type, _item, _src, \
668 _length_type, _src_length, \
670 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
671 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
674 #define _ctf_string(_item, _src, _user, _nowrite)
677 #define TP_PROTO(...) __VA_ARGS__
680 #define TP_FIELDS(...) __VA_ARGS__
683 #define TP_locvar(...) __VA_ARGS__
685 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
686 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
687 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
689 size_t __event_align = 1; \
690 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
693 return __event_align; \
696 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
697 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
698 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
700 size_t __event_align = 1; \
701 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
704 return __event_align; \
707 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
710 * Stage 6 of tracepoint event generation.
712 * Create the probe function. This function calls event size calculation
713 * and writes event data into the buffer.
716 /* Reset all macros within TRACEPOINT_EVENT */
717 #include <probes/lttng-events-reset.h>
718 #include <probes/lttng-events-write.h>
720 #undef _ctf_integer_ext_fetched
721 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
723 _type __tmp = _src; \
724 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
725 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
728 #undef _ctf_integer_ext_isuser0
729 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
730 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
732 #undef _ctf_integer_ext_isuser1
733 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
736 char __array[sizeof(_user_src)]; \
737 __typeof__(_user_src) __v; \
739 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
740 &(_user_src), sizeof(_user_src))) \
741 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
742 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
745 #undef _ctf_integer_ext
746 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
747 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
749 #undef _ctf_array_encoded
750 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
751 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
753 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
755 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
758 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
759 #undef _ctf_array_bitfield
760 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
761 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
763 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
765 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
767 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
769 * For big endian, we need to byteswap into little endian.
771 #undef _ctf_array_bitfield
772 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
773 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
777 for (_i = 0; _i < (_length); _i++) { \
781 if (get_user(_tmp, (_type *) _src + _i)) \
784 _tmp = ((_type *) _src)[_i]; \
786 switch (sizeof(_type)) { \
790 _tmp = cpu_to_le16(_tmp); \
793 _tmp = cpu_to_le32(_tmp); \
796 _tmp = cpu_to_le64(_tmp); \
801 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
804 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
806 #undef _ctf_sequence_encoded
807 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
808 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
810 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx]; \
811 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
812 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
814 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
816 __chan->ops->event_write_from_user(&__ctx, _src, \
817 sizeof(_type) * __get_dynamic_len(dest)); \
819 __chan->ops->event_write(&__ctx, _src, \
820 sizeof(_type) * __get_dynamic_len(dest)); \
823 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
824 #undef _ctf_sequence_bitfield
825 #define _ctf_sequence_bitfield(_type, _item, _src, \
826 _length_type, _src_length, \
829 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
830 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
831 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
833 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
835 __chan->ops->event_write_from_user(&__ctx, _src, \
836 sizeof(_type) * __get_dynamic_len(dest)); \
838 __chan->ops->event_write(&__ctx, _src, \
839 sizeof(_type) * __get_dynamic_len(dest)); \
841 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
843 * For big endian, we need to byteswap into little endian.
845 #undef _ctf_sequence_bitfield
846 #define _ctf_sequence_bitfield(_type, _item, _src, \
847 _length_type, _src_length, \
850 _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
851 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
852 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
854 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
856 size_t _i, _length; \
858 _length = __get_dynamic_len(dest); \
859 for (_i = 0; _i < _length; _i++) { \
863 if (get_user(_tmp, (_type *) _src + _i)) \
866 _tmp = ((_type *) _src)[_i]; \
868 switch (sizeof(_type)) { \
872 _tmp = cpu_to_le16(_tmp); \
875 _tmp = cpu_to_le32(_tmp); \
878 _tmp = cpu_to_le64(_tmp); \
883 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
886 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
889 #define _ctf_string(_item, _src, _user, _nowrite) \
890 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
892 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
893 __get_dynamic_len(dest)); \
895 __chan->ops->event_strcpy(&__ctx, _src, \
896 __get_dynamic_len(dest)); \
899 /* Beware: this get len actually consumes the len value */
900 #undef __get_dynamic_len
901 #define __get_dynamic_len(field) this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx++]
904 #define TP_PROTO(...) __VA_ARGS__
907 #define TP_ARGS(...) __VA_ARGS__
910 #define TP_FIELDS(...) __VA_ARGS__
913 #define TP_locvar(...) __VA_ARGS__
916 #define TP_code_pre(...) __VA_ARGS__
919 #define TP_code_post(...) __VA_ARGS__
922 * For state dump, check that "session" argument (mandatory) matches the
923 * session this event belongs to. Ensures that we write state dump data only
924 * into the started session, not into all sessions.
926 #ifdef TP_SESSION_CHECK
927 #define _TP_SESSION_CHECK(session, csession) (session == csession)
928 #else /* TP_SESSION_CHECK */
929 #define _TP_SESSION_CHECK(session, csession) 1
930 #endif /* TP_SESSION_CHECK */
933 * Using twice size for filter stack data to hold size and pointer for
934 * each field (worse case). For integers, max size required is 64-bit.
935 * Same for double-precision floats. Those fit within
936 * 2*sizeof(unsigned long) for all supported architectures.
937 * Perform UNION (||) of filter runtime list.
939 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
940 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
941 static void __event_probe__##_name(void *__data, _proto) \
943 struct probe_local_vars { _locvar }; \
944 struct lttng_event *__event = __data; \
945 struct lttng_probe_ctx __lttng_probe_ctx = { \
947 .interruptible = !irqs_disabled(), \
949 struct lttng_channel *__chan = __event->chan; \
950 struct lttng_session *__session = __chan->session; \
951 struct lib_ring_buffer_ctx __ctx; \
952 ssize_t __event_len; \
953 size_t __event_align; \
954 size_t __orig_dynamic_len_offset, __dynamic_len_idx; \
956 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
957 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
960 struct probe_local_vars __tp_locvar; \
961 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
963 struct lttng_pid_tracker *__lpf; \
965 if (!_TP_SESSION_CHECK(session, __session)) \
967 if (unlikely(!ACCESS_ONCE(__session->active))) \
969 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
971 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
973 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
974 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
976 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
977 __dynamic_len_idx = __orig_dynamic_len_offset; \
979 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
980 struct lttng_bytecode_runtime *bc_runtime; \
981 int __filter_record = __event->has_enablers_without_bytecode; \
983 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
985 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
986 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
987 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
988 __filter_record = 1; \
990 if (likely(!__filter_record)) \
993 __event_len = __event_get_size__##_name(tp_locvar, _args); \
994 if (unlikely(__event_len < 0)) { \
995 lib_ring_buffer_lost_event_too_big(__chan->chan); \
998 __event_align = __event_get_align__##_name(tp_locvar, _args); \
999 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1000 __event_align, -1); \
1001 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1005 __chan->ops->event_commit(&__ctx); \
1008 barrier(); /* use before un-reserve. */ \
1009 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1013 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1014 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1015 static void __event_probe__##_name(void *__data) \
1017 struct probe_local_vars { _locvar }; \
1018 struct lttng_event *__event = __data; \
1019 struct lttng_probe_ctx __lttng_probe_ctx = { \
1021 .interruptible = !irqs_disabled(), \
1023 struct lttng_channel *__chan = __event->chan; \
1024 struct lttng_session *__session = __chan->session; \
1025 struct lib_ring_buffer_ctx __ctx; \
1026 ssize_t __event_len; \
1027 size_t __event_align; \
1028 size_t __orig_dynamic_len_offset, __dynamic_len_idx; \
1030 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1031 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1034 struct probe_local_vars __tp_locvar; \
1035 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1037 struct lttng_pid_tracker *__lpf; \
1039 if (!_TP_SESSION_CHECK(session, __session)) \
1041 if (unlikely(!ACCESS_ONCE(__session->active))) \
1043 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
1045 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
1047 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
1048 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
1050 __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \
1051 __dynamic_len_idx = __orig_dynamic_len_offset; \
1053 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1054 struct lttng_bytecode_runtime *bc_runtime; \
1055 int __filter_record = __event->has_enablers_without_bytecode; \
1057 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1059 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1060 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1061 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1062 __filter_record = 1; \
1064 if (likely(!__filter_record)) \
1067 __event_len = __event_get_size__##_name(tp_locvar); \
1068 if (unlikely(__event_len < 0)) { \
1069 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1072 __event_align = __event_get_align__##_name(tp_locvar); \
1073 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1074 __event_align, -1); \
1075 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1079 __chan->ops->event_commit(&__ctx); \
1082 barrier(); /* use before un-reserve. */ \
1083 this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1087 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1089 #undef __get_dynamic_len
1092 * Stage 7 of the trace events.
1094 * Create event descriptions.
1097 /* Named field types must be defined in lttng-types.h */
1099 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1102 #define TP_PROBE_CB(_template) &__event_probe__##_template
1105 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1106 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1107 static const struct lttng_event_desc __event_desc___##_map = { \
1108 .fields = __event_fields___##_template, \
1111 .probe_callback = (void *) TP_PROBE_CB(_template), \
1112 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1113 .owner = THIS_MODULE, \
1116 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1117 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1118 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1120 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1123 * Stage 8 of the trace events.
1125 * Create an array of event description pointers.
1128 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1130 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1131 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1132 &__event_desc___##_map,
1134 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1135 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1136 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1138 #define TP_ID1(_token, _system) _token##_system
1139 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1141 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
1142 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1149 * Stage 9 of the trace events.
1151 * Create a toplevel descriptor for the whole probe.
1154 #define TP_ID1(_token, _system) _token##_system
1155 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1157 /* non-const because list head will be modified when registered. */
1158 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
1159 .provider
= __stringify(TRACE_SYSTEM
),
1160 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
1161 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
1162 .head
= { NULL
, NULL
},
1163 .lazy_init_head
= { NULL
, NULL
},
1171 * Stage 10 of the trace events.
1173 * Register/unregister probes at module load/unload.
1176 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1178 #define TP_ID1(_token, _system) _token##_system
1179 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1180 #define module_init_eval1(_token, _system) module_init(_token##_system)
1181 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1182 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1183 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1185 #ifndef TP_MODULE_NOINIT
1186 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
1188 wrapper_vmalloc_sync_all();
1189 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1192 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
1194 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1197 #ifndef TP_MODULE_NOAUTOLOAD
1198 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
1199 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
1204 #undef module_init_eval
1205 #undef module_exit_eval
This page took 0.055611 seconds and 6 git commands to generate.