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>
27 #include "lttng-types.h"
28 #include "lttng-probe-user.h"
29 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
30 #include "../wrapper/ringbuffer/frontend_types.h"
31 #include "../wrapper/rcu.h"
32 #include "../lttng-events.h"
33 #include "../lttng-tracer-core.h"
36 * Macro declarations used for all stages.
40 * LTTng name mapping macros. LTTng remaps some of the kernel events to
41 * enforce name-spacing.
43 #undef LTTNG_TRACEPOINT_EVENT_MAP
44 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
45 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
49 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
51 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
52 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
53 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
55 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
57 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
58 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
59 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
66 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
68 #undef LTTNG_TRACEPOINT_EVENT_CODE
69 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
70 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
79 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
80 * handlers for events. That is, if all events have the same parameters
81 * and just have distinct trace points. Each tracepoint can be defined
82 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
83 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
85 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
89 #undef LTTNG_TRACEPOINT_EVENT
90 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
91 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
96 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
97 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
98 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
100 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
101 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
102 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
104 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
105 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
106 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
108 #undef LTTNG_TRACEPOINT_EVENT_CLASS
109 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
110 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
113 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
114 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
115 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
119 * Stage 1 of the trace events.
121 * Create dummy trace calls for each events, verifying that the LTTng module
122 * instrumentation headers match the kernel arguments. Will be optimized
123 * out by the compiler.
126 /* Reset all macros within TRACEPOINT_EVENT */
127 #include "lttng-events-reset.h"
130 #define TP_PROTO(...) __VA_ARGS__
133 #define TP_ARGS(...) __VA_ARGS__
135 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
136 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
137 void trace_##_name(_proto);
139 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
140 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
141 void trace_##_name(void);
143 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
146 * Stage 1.1 of the trace events.
148 * Create dummy trace prototypes for each event class, and for each used
149 * template. This will allow checking whether the prototypes from the
150 * class and the instance using the class actually match.
153 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
156 #define TP_PROTO(...) __VA_ARGS__
159 #define TP_ARGS(...) __VA_ARGS__
161 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
162 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
163 void __event_template_proto___##_template(_proto);
165 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
166 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
167 void __event_template_proto___##_template(void);
169 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
170 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
171 void __event_template_proto___##_name(_proto);
173 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
174 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
175 void __event_template_proto___##_name(void);
177 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
180 * Stage 2 of the trace events.
182 * Create event field type metadata section.
183 * Each event produce an array of fields.
186 /* Reset all macros within TRACEPOINT_EVENT */
187 #include "lttng-events-reset.h"
188 #include "lttng-events-write.h"
189 #include "lttng-events-nowrite.h"
191 #undef _ctf_integer_ext
192 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
195 .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none),\
196 .nowrite = _nowrite, \
200 #undef _ctf_array_encoded
201 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
206 .atype = atype_array, \
211 .elem_type = __type_integer(_type, 0, 0, 0, __BYTE_ORDER, 10, _encoding), \
216 .nowrite = _nowrite, \
220 #undef _ctf_array_bitfield
221 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
226 .atype = atype_array, \
231 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
232 .length = (_length) * sizeof(_type) * CHAR_BIT, \
233 .elem_alignment = lttng_alignof(_type), \
237 .nowrite = _nowrite, \
242 #undef _ctf_sequence_encoded
243 #define _ctf_sequence_encoded(_type, _item, _src, \
244 _length_type, _src_length, _encoding, \
245 _byte_order, _base, _user, _nowrite) \
250 .atype = atype_sequence, \
255 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
256 .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _base, _encoding), \
260 .nowrite = _nowrite, \
264 #undef _ctf_sequence_bitfield
265 #define _ctf_sequence_bitfield(_type, _item, _src, \
266 _length_type, _src_length, \
272 .atype = atype_sequence, \
277 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
278 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
279 .elem_alignment = lttng_alignof(_type), \
283 .nowrite = _nowrite, \
288 #define _ctf_string(_item, _src, _user, _nowrite) \
293 .atype = atype_string, \
296 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
299 .nowrite = _nowrite, \
304 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
306 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
307 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
308 static const struct lttng_event_field __event_fields___##_name[] = { \
312 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
313 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
314 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
316 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
319 * Stage 3 of the trace events.
321 * Create probe callback prototypes.
324 /* Reset all macros within TRACEPOINT_EVENT */
325 #include "lttng-events-reset.h"
328 #define TP_PROTO(...) __VA_ARGS__
330 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
331 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
332 static void __event_probe__##_name(void *__data, _proto);
334 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
335 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
336 static void __event_probe__##_name(void *__data);
338 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
341 * Stage 4 of the trace events.
343 * Create static inline function that calculates event size.
346 /* Reset all macros within TRACEPOINT_EVENT */
347 #include "lttng-events-reset.h"
348 #include "lttng-events-write.h"
350 #undef _ctf_integer_ext
351 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
352 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
353 __event_len += sizeof(_type);
355 #undef _ctf_array_encoded
356 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
357 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
358 __event_len += sizeof(_type) * (_length);
360 #undef _ctf_array_bitfield
361 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
362 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
364 #undef _ctf_sequence_encoded
365 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
366 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
367 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
368 __event_len += sizeof(_length_type); \
369 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
370 __dynamic_len[__dynamic_len_idx] = (_src_length); \
371 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
374 #undef _ctf_sequence_bitfield
375 #define _ctf_sequence_bitfield(_type, _item, _src, \
376 _length_type, _src_length, \
378 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
379 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
382 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
386 #define _ctf_string(_item, _src, _user, _nowrite) \
388 __event_len += __dynamic_len[__dynamic_len_idx++] = \
389 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
391 __event_len += __dynamic_len[__dynamic_len_idx++] = \
395 #define TP_PROTO(...) __VA_ARGS__
398 #define TP_FIELDS(...) __VA_ARGS__
401 #define TP_locvar(...) __VA_ARGS__
403 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
404 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
405 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
406 void *__tp_locvar, _proto) \
408 size_t __event_len = 0; \
409 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
410 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
413 return __event_len; \
416 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
417 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
418 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
421 size_t __event_len = 0; \
422 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
423 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
426 return __event_len; \
429 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
433 * Stage 4.1 of tracepoint event generation.
435 * Create static inline function that layout the filter stack data.
436 * We make both write and nowrite data available to the filter.
439 /* Reset all macros within TRACEPOINT_EVENT */
440 #include "lttng-events-reset.h"
441 #include "lttng-events-write.h"
442 #include "lttng-events-nowrite.h"
444 #undef _ctf_integer_ext_fetched
445 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
446 if (lttng_is_signed_type(_type)) { \
447 int64_t __ctf_tmp_int64; \
448 switch (sizeof(_type)) { \
451 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
452 __ctf_tmp_int64 = (int64_t) __tmp.v; \
457 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
458 __ctf_tmp_int64 = (int64_t) __tmp.v; \
463 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
464 __ctf_tmp_int64 = (int64_t) __tmp.v; \
469 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
470 __ctf_tmp_int64 = (int64_t) __tmp.v; \
476 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
478 uint64_t __ctf_tmp_uint64; \
479 switch (sizeof(_type)) { \
482 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
483 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
488 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
489 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
494 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
495 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
500 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
501 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
507 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
509 __stack_data += sizeof(int64_t);
511 #undef _ctf_integer_ext_isuser0
512 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
513 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
515 #undef _ctf_integer_ext_isuser1
516 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
518 __typeof__(_user_src) _src; \
519 if (get_user(_src, &(_user_src))) \
521 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
524 #undef _ctf_integer_ext
525 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
526 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
528 #undef _ctf_array_encoded
529 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
531 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
532 const void *__ctf_tmp_ptr = (_src); \
533 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
534 __stack_data += sizeof(unsigned long); \
535 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
536 __stack_data += sizeof(void *); \
539 #undef _ctf_array_bitfield
540 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
541 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
543 #undef _ctf_sequence_encoded
544 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
545 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
547 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
548 const void *__ctf_tmp_ptr = (_src); \
549 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
550 __stack_data += sizeof(unsigned long); \
551 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
552 __stack_data += sizeof(void *); \
555 #undef _ctf_sequence_bitfield
556 #define _ctf_sequence_bitfield(_type, _item, _src, \
557 _length_type, _src_length, \
559 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
560 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
563 #define _ctf_string(_item, _src, _user, _nowrite) \
565 const void *__ctf_tmp_ptr = (_src); \
566 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
567 __stack_data += sizeof(void *); \
571 #define TP_PROTO(...) __VA_ARGS__
574 #define TP_FIELDS(...) __VA_ARGS__
577 #define TP_locvar(...) __VA_ARGS__
579 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
580 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
582 void __event_prepare_filter_stack__##_name(char *__stack_data, \
585 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
590 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
591 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
593 void __event_prepare_filter_stack__##_name(char *__stack_data, \
594 void *__tp_locvar, _proto) \
596 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
601 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
604 * Stage 5 of the trace events.
606 * Create static inline function that calculates event payload alignment.
609 /* Reset all macros within TRACEPOINT_EVENT */
610 #include "lttng-events-reset.h"
611 #include "lttng-events-write.h"
613 #undef _ctf_integer_ext
614 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
615 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
617 #undef _ctf_array_encoded
618 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
619 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
621 #undef _ctf_array_bitfield
622 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
623 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
625 #undef _ctf_sequence_encoded
626 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
627 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
628 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
629 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
631 #undef _ctf_sequence_bitfield
632 #define _ctf_sequence_bitfield(_type, _item, _src, \
633 _length_type, _src_length, \
635 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
636 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
639 #define _ctf_string(_item, _src, _user, _nowrite)
642 #define TP_PROTO(...) __VA_ARGS__
645 #define TP_FIELDS(...) __VA_ARGS__
648 #define TP_locvar(...) __VA_ARGS__
650 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
651 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
652 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
654 size_t __event_align = 1; \
655 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
658 return __event_align; \
661 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
662 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
663 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
665 size_t __event_align = 1; \
666 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
669 return __event_align; \
672 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
675 * Stage 6 of tracepoint event generation.
677 * Create the probe function. This function calls event size calculation
678 * and writes event data into the buffer.
681 /* Reset all macros within TRACEPOINT_EVENT */
682 #include "lttng-events-reset.h"
683 #include "lttng-events-write.h"
685 #undef _ctf_integer_ext_fetched
686 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
688 _type __tmp = _src; \
689 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
690 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
693 #undef _ctf_integer_ext_isuser0
694 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
695 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
697 #undef _ctf_integer_ext_isuser1
698 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
700 __typeof__(_user_src) _src; \
701 if (get_user(_src, &(_user_src))) \
703 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
706 #undef _ctf_integer_ext
707 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
708 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
710 #undef _ctf_array_encoded
711 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
712 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
714 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
716 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
719 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
720 #undef _ctf_array_bitfield
721 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
722 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
724 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
726 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
728 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
730 * For big endian, we need to byteswap into little endian.
732 #undef _ctf_array_bitfield
733 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
734 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
738 for (_i = 0; _i < (_length); _i++) { \
742 if (get_user(_tmp, (_type *) _src + _i)) \
745 _tmp = ((_type *) _src)[_i]; \
747 switch (sizeof(_type)) { \
751 _tmp = cpu_to_le16(_tmp); \
754 _tmp = cpu_to_le32(_tmp); \
757 _tmp = cpu_to_le64(_tmp); \
762 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
765 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
767 #undef _ctf_sequence_encoded
768 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
769 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
771 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
772 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
773 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
775 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
777 __chan->ops->event_write_from_user(&__ctx, _src, \
778 sizeof(_type) * __get_dynamic_len(dest)); \
780 __chan->ops->event_write(&__ctx, _src, \
781 sizeof(_type) * __get_dynamic_len(dest)); \
784 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
785 #undef _ctf_sequence_bitfield
786 #define _ctf_sequence_bitfield(_type, _item, _src, \
787 _length_type, _src_length, \
790 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
791 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
792 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
794 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
796 __chan->ops->event_write_from_user(&__ctx, _src, \
797 sizeof(_type) * __get_dynamic_len(dest)); \
799 __chan->ops->event_write(&__ctx, _src, \
800 sizeof(_type) * __get_dynamic_len(dest)); \
802 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
804 * For big endian, we need to byteswap into little endian.
806 #undef _ctf_sequence_bitfield
807 #define _ctf_sequence_bitfield(_type, _item, _src, \
808 _length_type, _src_length, \
811 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
812 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
813 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
815 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
817 size_t _i, _length; \
819 _length = __get_dynamic_len(dest); \
820 for (_i = 0; _i < _length; _i++) { \
824 if (get_user(_tmp, (_type *) _src + _i)) \
827 _tmp = ((_type *) _src)[_i]; \
829 switch (sizeof(_type)) { \
833 _tmp = cpu_to_le16(_tmp); \
836 _tmp = cpu_to_le32(_tmp); \
839 _tmp = cpu_to_le64(_tmp); \
844 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
847 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
850 #define _ctf_string(_item, _src, _user, _nowrite) \
851 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
853 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
854 __get_dynamic_len(dest)); \
856 __chan->ops->event_strcpy(&__ctx, _src, \
857 __get_dynamic_len(dest)); \
860 /* Beware: this get len actually consumes the len value */
861 #undef __get_dynamic_len
862 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
865 #define TP_PROTO(...) __VA_ARGS__
868 #define TP_ARGS(...) __VA_ARGS__
871 #define TP_FIELDS(...) __VA_ARGS__
874 #define TP_locvar(...) __VA_ARGS__
877 #define TP_code_pre(...) __VA_ARGS__
880 #define TP_code_post(...) __VA_ARGS__
883 * For state dump, check that "session" argument (mandatory) matches the
884 * session this event belongs to. Ensures that we write state dump data only
885 * into the started session, not into all sessions.
887 #ifdef TP_SESSION_CHECK
888 #define _TP_SESSION_CHECK(session, csession) (session == csession)
889 #else /* TP_SESSION_CHECK */
890 #define _TP_SESSION_CHECK(session, csession) 1
891 #endif /* TP_SESSION_CHECK */
894 * Using twice size for filter stack data to hold size and pointer for
895 * each field (worse case). For integers, max size required is 64-bit.
896 * Same for double-precision floats. Those fit within
897 * 2*sizeof(unsigned long) for all supported architectures.
898 * Perform UNION (||) of filter runtime list.
900 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
901 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
902 static void __event_probe__##_name(void *__data, _proto) \
904 struct probe_local_vars { _locvar }; \
905 struct lttng_event *__event = __data; \
906 struct lttng_channel *__chan = __event->chan; \
907 struct lttng_session *__session = __chan->session; \
908 struct lib_ring_buffer_ctx __ctx; \
909 size_t __event_len, __event_align; \
910 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
912 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
913 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
916 struct probe_local_vars __tp_locvar; \
917 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
919 struct lttng_pid_tracker *__lpf; \
921 if (!_TP_SESSION_CHECK(session, __session)) \
923 if (unlikely(!ACCESS_ONCE(__session->active))) \
925 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
927 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
929 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
930 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
933 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
934 struct lttng_bytecode_runtime *bc_runtime; \
935 int __filter_record = __event->has_enablers_without_bytecode; \
937 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
939 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
940 if (unlikely(bc_runtime->filter(bc_runtime, \
941 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
942 __filter_record = 1; \
944 if (likely(!__filter_record)) \
947 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
949 __event_align = __event_get_align__##_name(tp_locvar, _args); \
950 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
951 __event_align, -1); \
952 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
956 __chan->ops->event_commit(&__ctx); \
962 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
963 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
964 static void __event_probe__##_name(void *__data) \
966 struct probe_local_vars { _locvar }; \
967 struct lttng_event *__event = __data; \
968 struct lttng_channel *__chan = __event->chan; \
969 struct lttng_session *__session = __chan->session; \
970 struct lib_ring_buffer_ctx __ctx; \
971 size_t __event_len, __event_align; \
972 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
974 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
975 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
978 struct probe_local_vars __tp_locvar; \
979 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
981 struct lttng_pid_tracker *__lpf; \
983 if (!_TP_SESSION_CHECK(session, __session)) \
985 if (unlikely(!ACCESS_ONCE(__session->active))) \
987 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
989 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
991 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
992 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
995 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
996 struct lttng_bytecode_runtime *bc_runtime; \
997 int __filter_record = __event->has_enablers_without_bytecode; \
999 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1001 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1002 if (unlikely(bc_runtime->filter(bc_runtime, \
1003 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1004 __filter_record = 1; \
1006 if (likely(!__filter_record)) \
1009 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
1010 __event_align = __event_get_align__##_name(tp_locvar); \
1011 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
1012 __event_align, -1); \
1013 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1017 __chan->ops->event_commit(&__ctx); \
1023 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1025 #undef __get_dynamic_len
1028 * Stage 7 of the trace events.
1030 * Create event descriptions.
1033 /* Named field types must be defined in lttng-types.h */
1035 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1038 #define TP_PROBE_CB(_template) &__event_probe__##_template
1041 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1042 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1043 static const struct lttng_event_desc __event_desc___##_map = { \
1044 .fields = __event_fields___##_template, \
1047 .probe_callback = (void *) TP_PROBE_CB(_template), \
1048 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1049 .owner = THIS_MODULE, \
1052 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1053 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1054 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1056 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1059 * Stage 8 of the trace events.
1061 * Create an array of event description pointers.
1064 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1066 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1067 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1068 &__event_desc___##_map,
1070 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1071 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1072 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1074 #define TP_ID1(_token, _system) _token##_system
1075 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1077 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
1078 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1085 * Stage 9 of the trace events.
1087 * Create a toplevel descriptor for the whole probe.
1090 #define TP_ID1(_token, _system) _token##_system
1091 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1093 /* non-const because list head will be modified when registered. */
1094 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
1095 .provider
= __stringify(TRACE_SYSTEM
),
1096 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
1097 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
1098 .head
= { NULL
, NULL
},
1099 .lazy_init_head
= { NULL
, NULL
},
1107 * Stage 10 of the trace events.
1109 * Register/unregister probes at module load/unload.
1112 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1114 #define TP_ID1(_token, _system) _token##_system
1115 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1116 #define module_init_eval1(_token, _system) module_init(_token##_system)
1117 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1118 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1119 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1121 #ifndef TP_MODULE_NOINIT
1122 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
1124 wrapper_vmalloc_sync_all();
1125 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1128 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
1130 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
1133 #ifndef TP_MODULE_NOAUTOLOAD
1134 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
1135 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
1140 #undef module_init_eval
1141 #undef module_exit_eval
This page took 0.086848 seconds and 4 git commands to generate.