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)); \
373 __dynamic_len[__dynamic_len_idx] = (_src_length); \
374 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
377 #undef _ctf_sequence_bitfield
378 #define _ctf_sequence_bitfield(_type, _item, _src, \
379 _length_type, _src_length, \
381 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
382 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
385 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
389 #define _ctf_string(_item, _src, _user, _nowrite) \
391 __event_len += __dynamic_len[__dynamic_len_idx++] = \
392 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
394 __event_len += __dynamic_len[__dynamic_len_idx++] = \
398 #define TP_PROTO(...) __VA_ARGS__
401 #define TP_FIELDS(...) __VA_ARGS__
404 #define TP_locvar(...) __VA_ARGS__
406 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
407 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
408 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
409 void *__tp_locvar, _proto) \
411 size_t __event_len = 0; \
412 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
413 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
416 return __event_len; \
419 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
420 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
421 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
424 size_t __event_len = 0; \
425 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
426 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
429 return __event_len; \
432 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
436 * Stage 4.1 of tracepoint event generation.
438 * Create static inline function that layout the filter stack data.
439 * We make both write and nowrite data available to the filter.
442 /* Reset all macros within TRACEPOINT_EVENT */
443 #include <probes/lttng-events-reset.h>
444 #include <probes/lttng-events-write.h>
445 #include <probes/lttng-events-nowrite.h>
447 #undef _ctf_integer_ext_fetched
448 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
449 if (lttng_is_signed_type(_type)) { \
450 int64_t __ctf_tmp_int64; \
451 switch (sizeof(_type)) { \
454 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
455 __ctf_tmp_int64 = (int64_t) __tmp.v; \
460 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
461 if (_byte_order != __BYTE_ORDER) \
462 __swab16s(&__tmp.v); \
463 __ctf_tmp_int64 = (int64_t) __tmp.v; \
468 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
469 if (_byte_order != __BYTE_ORDER) \
470 __swab32s(&__tmp.v); \
471 __ctf_tmp_int64 = (int64_t) __tmp.v; \
476 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
477 if (_byte_order != __BYTE_ORDER) \
478 __swab64s(&__tmp.v); \
479 __ctf_tmp_int64 = (int64_t) __tmp.v; \
485 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
487 uint64_t __ctf_tmp_uint64; \
488 switch (sizeof(_type)) { \
491 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
492 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
497 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
498 if (_byte_order != __BYTE_ORDER) \
499 __swab16s(&__tmp.v); \
500 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
505 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
506 if (_byte_order != __BYTE_ORDER) \
507 __swab32s(&__tmp.v); \
508 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
513 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
514 if (_byte_order != __BYTE_ORDER) \
515 __swab64s(&__tmp.v); \
516 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
522 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
524 __stack_data += sizeof(int64_t);
526 #undef _ctf_integer_ext_isuser0
527 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
528 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
530 #undef _ctf_integer_ext_isuser1
531 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
534 char __array[sizeof(_user_src)]; \
535 __typeof__(_user_src) __v; \
537 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
538 &(_user_src), sizeof(_user_src))) \
539 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
540 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
543 #undef _ctf_integer_ext
544 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
545 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
547 #undef _ctf_array_encoded
548 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
550 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
551 const void *__ctf_tmp_ptr = (_src); \
552 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
553 __stack_data += sizeof(unsigned long); \
554 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
555 __stack_data += sizeof(void *); \
558 #undef _ctf_array_bitfield
559 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
560 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
562 #undef _ctf_sequence_encoded
563 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
564 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
566 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_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_sequence_bitfield
575 #define _ctf_sequence_bitfield(_type, _item, _src, \
576 _length_type, _src_length, \
578 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
579 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
582 #define _ctf_string(_item, _src, _user, _nowrite) \
584 const void *__ctf_tmp_ptr = (_src); \
585 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
586 __stack_data += sizeof(void *); \
590 #define TP_PROTO(...) __VA_ARGS__
593 #define TP_FIELDS(...) __VA_ARGS__
596 #define TP_locvar(...) __VA_ARGS__
598 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
599 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
601 void __event_prepare_filter_stack__##_name(char *__stack_data, \
604 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
609 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
610 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
612 void __event_prepare_filter_stack__##_name(char *__stack_data, \
613 void *__tp_locvar, _proto) \
615 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
620 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
623 * Stage 5 of the trace events.
625 * Create static inline function that calculates event payload alignment.
628 /* Reset all macros within TRACEPOINT_EVENT */
629 #include <probes/lttng-events-reset.h>
630 #include <probes/lttng-events-write.h>
632 #undef _ctf_integer_ext
633 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
634 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
636 #undef _ctf_array_encoded
637 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
638 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
640 #undef _ctf_array_bitfield
641 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
642 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
644 #undef _ctf_sequence_encoded
645 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
646 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
647 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
648 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
650 #undef _ctf_sequence_bitfield
651 #define _ctf_sequence_bitfield(_type, _item, _src, \
652 _length_type, _src_length, \
654 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
655 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
658 #define _ctf_string(_item, _src, _user, _nowrite)
661 #define TP_PROTO(...) __VA_ARGS__
664 #define TP_FIELDS(...) __VA_ARGS__
667 #define TP_locvar(...) __VA_ARGS__
669 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
670 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
671 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
673 size_t __event_align = 1; \
674 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
677 return __event_align; \
680 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
681 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
682 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
684 size_t __event_align = 1; \
685 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
688 return __event_align; \
691 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
694 * Stage 6 of tracepoint event generation.
696 * Create the probe function. This function calls event size calculation
697 * and writes event data into the buffer.
700 /* Reset all macros within TRACEPOINT_EVENT */
701 #include <probes/lttng-events-reset.h>
702 #include <probes/lttng-events-write.h>
704 #undef _ctf_integer_ext_fetched
705 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
707 _type __tmp = _src; \
708 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
709 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
712 #undef _ctf_integer_ext_isuser0
713 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
714 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
716 #undef _ctf_integer_ext_isuser1
717 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
720 char __array[sizeof(_user_src)]; \
721 __typeof__(_user_src) __v; \
723 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
724 &(_user_src), sizeof(_user_src))) \
725 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
726 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
729 #undef _ctf_integer_ext
730 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
731 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
733 #undef _ctf_array_encoded
734 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
735 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
737 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
739 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
742 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
743 #undef _ctf_array_bitfield
744 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
745 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
747 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
749 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
751 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
753 * For big endian, we need to byteswap into little endian.
755 #undef _ctf_array_bitfield
756 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
757 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
761 for (_i = 0; _i < (_length); _i++) { \
765 if (get_user(_tmp, (_type *) _src + _i)) \
768 _tmp = ((_type *) _src)[_i]; \
770 switch (sizeof(_type)) { \
774 _tmp = cpu_to_le16(_tmp); \
777 _tmp = cpu_to_le32(_tmp); \
780 _tmp = cpu_to_le64(_tmp); \
785 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
788 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
790 #undef _ctf_sequence_encoded
791 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
792 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
794 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
795 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
796 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
798 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
800 __chan->ops->event_write_from_user(&__ctx, _src, \
801 sizeof(_type) * __get_dynamic_len(dest)); \
803 __chan->ops->event_write(&__ctx, _src, \
804 sizeof(_type) * __get_dynamic_len(dest)); \
807 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
808 #undef _ctf_sequence_bitfield
809 #define _ctf_sequence_bitfield(_type, _item, _src, \
810 _length_type, _src_length, \
813 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
814 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
815 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
817 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
819 __chan->ops->event_write_from_user(&__ctx, _src, \
820 sizeof(_type) * __get_dynamic_len(dest)); \
822 __chan->ops->event_write(&__ctx, _src, \
823 sizeof(_type) * __get_dynamic_len(dest)); \
825 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
827 * For big endian, we need to byteswap into little endian.
829 #undef _ctf_sequence_bitfield
830 #define _ctf_sequence_bitfield(_type, _item, _src, \
831 _length_type, _src_length, \
834 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
835 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
836 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
838 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
840 size_t _i, _length; \
842 _length = __get_dynamic_len(dest); \
843 for (_i = 0; _i < _length; _i++) { \
847 if (get_user(_tmp, (_type *) _src + _i)) \
850 _tmp = ((_type *) _src)[_i]; \
852 switch (sizeof(_type)) { \
856 _tmp = cpu_to_le16(_tmp); \
859 _tmp = cpu_to_le32(_tmp); \
862 _tmp = cpu_to_le64(_tmp); \
867 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
870 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
873 #define _ctf_string(_item, _src, _user, _nowrite) \
874 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
876 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
877 __get_dynamic_len(dest)); \
879 __chan->ops->event_strcpy(&__ctx, _src, \
880 __get_dynamic_len(dest)); \
883 /* Beware: this get len actually consumes the len value */
884 #undef __get_dynamic_len
885 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
888 #define TP_PROTO(...) __VA_ARGS__
891 #define TP_ARGS(...) __VA_ARGS__
894 #define TP_FIELDS(...) __VA_ARGS__
897 #define TP_locvar(...) __VA_ARGS__
900 #define TP_code_pre(...) __VA_ARGS__
903 #define TP_code_post(...) __VA_ARGS__
906 * For state dump, check that "session" argument (mandatory) matches the
907 * session this event belongs to. Ensures that we write state dump data only
908 * into the started session, not into all sessions.
910 #ifdef TP_SESSION_CHECK
911 #define _TP_SESSION_CHECK(session, csession) (session == csession)
912 #else /* TP_SESSION_CHECK */
913 #define _TP_SESSION_CHECK(session, csession) 1
914 #endif /* TP_SESSION_CHECK */
917 * Using twice size for filter stack data to hold size and pointer for
918 * each field (worse case). For integers, max size required is 64-bit.
919 * Same for double-precision floats. Those fit within
920 * 2*sizeof(unsigned long) for all supported architectures.
921 * Perform UNION (||) of filter runtime list.
923 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
924 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
925 static void __event_probe__##_name(void *__data, _proto) \
927 struct probe_local_vars { _locvar }; \
928 struct lttng_event *__event = __data; \
929 struct lttng_probe_ctx __lttng_probe_ctx = { \
931 .interruptible = !irqs_disabled(), \
933 struct lttng_channel *__chan = __event->chan; \
934 struct lttng_session *__session = __chan->session; \
935 struct lib_ring_buffer_ctx __ctx; \
936 size_t __event_len, __event_align; \
937 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
939 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
940 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
943 struct probe_local_vars __tp_locvar; \
944 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
946 struct lttng_pid_tracker *__lpf; \
948 if (!_TP_SESSION_CHECK(session, __session)) \
950 if (unlikely(!ACCESS_ONCE(__session->active))) \
952 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
954 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
956 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
957 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
960 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
961 struct lttng_bytecode_runtime *bc_runtime; \
962 int __filter_record = __event->has_enablers_without_bytecode; \
964 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
966 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
967 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
968 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
969 __filter_record = 1; \
971 if (likely(!__filter_record)) \
974 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
976 __event_align = __event_get_align__##_name(tp_locvar, _args); \
977 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
978 __event_align, -1); \
979 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
983 __chan->ops->event_commit(&__ctx); \
989 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
990 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
991 static void __event_probe__##_name(void *__data) \
993 struct probe_local_vars { _locvar }; \
994 struct lttng_event *__event = __data; \
995 struct lttng_probe_ctx __lttng_probe_ctx = { \
997 .interruptible = !irqs_disabled(), \
999 struct lttng_channel *__chan = __event->chan; \
1000 struct lttng_session *__session = __chan->session; \
1001 struct lib_ring_buffer_ctx __ctx; \
1002 size_t __event_len, __event_align; \
1003 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
1005 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
1006 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1009 struct probe_local_vars __tp_locvar; \
1010 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1012 struct lttng_pid_tracker *__lpf; \
1014 if (!_TP_SESSION_CHECK(session, __session)) \
1016 if (unlikely(!ACCESS_ONCE(__session->active))) \
1018 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
1020 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
1022 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
1023 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
1026 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1027 struct lttng_bytecode_runtime *bc_runtime; \
1028 int __filter_record = __event->has_enablers_without_bytecode; \
1030 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1032 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1033 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1034 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1035 __filter_record = 1; \
1037 if (likely(!__filter_record)) \
1040 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
1041 __event_align = __event_get_align__##_name(tp_locvar); \
1042 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1043 __event_align, -1); \
1044 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1048 __chan->ops->event_commit(&__ctx); \
1054 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1056 #undef __get_dynamic_len
1059 * Stage 7 of the trace events.
1061 * Create event descriptions.
1064 /* Named field types must be defined in lttng-types.h */
1066 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1069 #define TP_PROBE_CB(_template) &__event_probe__##_template
1072 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1073 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1074 static const struct lttng_event_desc __event_desc___##_map = { \
1075 .fields = __event_fields___##_template, \
1078 .probe_callback = (void *) TP_PROBE_CB(_template), \
1079 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1080 .owner = THIS_MODULE, \
1083 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1084 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1085 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1087 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1090 * Stage 8 of the trace events.
1092 * Create an array of event description pointers.
1095 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1097 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1098 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1099 &__event_desc___##_map,
1101 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1102 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1103 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1105 #define TP_ID1(_token, _system) _token##_system
1106 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1108 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
1109 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1116 * Stage 9 of the trace events.
1118 * Create a toplevel descriptor for the whole probe.
1121 #define TP_ID1(_token, _system) _token##_system
1122 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1124 /* non-const because list head will be modified when registered. */
1125 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
1126 .provider
= __stringify(TRACE_SYSTEM
),
1127 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
1128 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
1129 .head
= { NULL
, NULL
},
1130 .lazy_init_head
= { NULL
, NULL
},
1138 * Stage 10 of the trace events.
1140 * Register/unregister probes at module load/unload.
1143 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1145 #define TP_ID1(_token, _system) _token##_system
1146 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1147 #define module_init_eval1(_token, _system) module_init(_token##_system)
1148 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1149 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1150 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1152 #ifndef TP_MODULE_NOINIT
1153 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
1155 wrapper_vmalloc_sync_all();
1156 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1159 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
1161 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1164 #ifndef TP_MODULE_NOAUTOLOAD
1165 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
1166 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
1171 #undef module_init_eval
1172 #undef module_exit_eval
This page took 0.057584 seconds and 5 git commands to generate.