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>
26 #include "lttng-types.h"
27 #include "lttng-probe-user.h"
28 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
29 #include "../wrapper/ringbuffer/frontend_types.h"
30 #include "../wrapper/ringbuffer/backend.h"
31 #include "../wrapper/rcu.h"
32 #include "../lttng-events.h"
33 #include "../lttng-tracer-core.h"
34 #include <asm/byteorder.h>
35 #include <linux/swab.h>
38 * Macro declarations used for all stages.
42 * LTTng name mapping macros. LTTng remaps some of the kernel events to
43 * enforce name-spacing.
45 #undef LTTNG_TRACEPOINT_EVENT_MAP
46 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
47 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
51 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
53 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
54 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
55 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
57 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
59 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
60 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields) \
61 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
67 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
69 #undef LTTNG_TRACEPOINT_EVENT_CODE
70 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
71 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, _fields) \
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, _fields) \
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, _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, __BYTE_ORDER, 10, _encoding), \
216 .nowrite = _nowrite, \
220 #undef _ctf_sequence_encoded
221 #define _ctf_sequence_encoded(_type, _item, _src, \
222 _length_type, _src_length, _encoding, \
223 _byte_order, _base, _user, _nowrite) \
228 .atype = atype_sequence, \
233 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
234 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
238 .nowrite = _nowrite, \
243 #define _ctf_string(_item, _src, _user, _nowrite) \
248 .atype = atype_string, \
251 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
254 .nowrite = _nowrite, \
259 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
261 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
262 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
263 static const struct lttng_event_field __event_fields___##_name[] = { \
267 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
268 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
269 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
271 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
274 * Stage 3 of the trace events.
276 * Create probe callback prototypes.
279 /* Reset all macros within TRACEPOINT_EVENT */
280 #include "lttng-events-reset.h"
283 #define TP_PROTO(...) __VA_ARGS__
285 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
286 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
287 static void __event_probe__##_name(void *__data, _proto);
289 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
290 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
291 static void __event_probe__##_name(void *__data);
293 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
296 * Stage 4 of the trace events.
298 * Create static inline function that calculates event size.
301 /* Reset all macros within TRACEPOINT_EVENT */
302 #include "lttng-events-reset.h"
303 #include "lttng-events-write.h"
305 #undef _ctf_integer_ext
306 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
307 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
308 __event_len += sizeof(_type);
310 #undef _ctf_array_encoded
311 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
312 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
313 __event_len += sizeof(_type) * (_length);
315 #undef _ctf_sequence_encoded
316 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
317 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
318 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
319 __event_len += sizeof(_length_type); \
320 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
321 __dynamic_len[__dynamic_len_idx] = (_src_length); \
322 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
326 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
330 #define _ctf_string(_item, _src, _user, _nowrite) \
332 __event_len += __dynamic_len[__dynamic_len_idx++] = \
333 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
335 __event_len += __dynamic_len[__dynamic_len_idx++] = \
339 #define TP_PROTO(...) __VA_ARGS__
342 #define TP_FIELDS(...) __VA_ARGS__
345 #define TP_locvar(...) __VA_ARGS__
347 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
348 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
349 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
350 void *__tp_locvar, _proto) \
352 size_t __event_len = 0; \
353 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
354 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
357 return __event_len; \
360 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
361 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
362 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
365 size_t __event_len = 0; \
366 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
367 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
370 return __event_len; \
373 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
377 * Stage 4.1 of tracepoint event generation.
379 * Create static inline function that layout the filter stack data.
380 * We make both write and nowrite data available to the filter.
383 /* Reset all macros within TRACEPOINT_EVENT */
384 #include "lttng-events-reset.h"
385 #include "lttng-events-write.h"
386 #include "lttng-events-nowrite.h"
388 #undef _ctf_integer_ext_fetched
389 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
390 if (lttng_is_signed_type(_type)) { \
391 int64_t __ctf_tmp_int64; \
392 switch (sizeof(_type)) { \
395 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
396 __ctf_tmp_int64 = (int64_t) __tmp.v; \
401 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
402 if (_byte_order != __BYTE_ORDER) \
403 __swab16s(&__tmp.v); \
404 __ctf_tmp_int64 = (int64_t) __tmp.v; \
409 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
410 if (_byte_order != __BYTE_ORDER) \
411 __swab32s(&__tmp.v); \
412 __ctf_tmp_int64 = (int64_t) __tmp.v; \
417 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
418 if (_byte_order != __BYTE_ORDER) \
419 __swab64s(&__tmp.v); \
420 __ctf_tmp_int64 = (int64_t) __tmp.v; \
426 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
428 uint64_t __ctf_tmp_uint64; \
429 switch (sizeof(_type)) { \
432 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
433 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
438 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
439 if (_byte_order != __BYTE_ORDER) \
440 __swab16s(&__tmp.v); \
441 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
446 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
447 if (_byte_order != __BYTE_ORDER) \
448 __swab32s(&__tmp.v); \
449 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
454 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
455 if (_byte_order != __BYTE_ORDER) \
456 __swab64s(&__tmp.v); \
457 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
463 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
465 __stack_data += sizeof(int64_t);
467 #undef _ctf_integer_ext_isuser0
468 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
469 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
471 #undef _ctf_integer_ext_isuser1
472 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
475 char __array[sizeof(_user_src)]; \
476 __typeof__(_user_src) __v; \
478 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
479 &(_user_src), sizeof(_user_src))) \
480 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
481 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
484 #undef _ctf_integer_ext
485 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
486 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
488 #undef _ctf_array_encoded
489 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
491 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
492 const void *__ctf_tmp_ptr = (_src); \
493 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
494 __stack_data += sizeof(unsigned long); \
495 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
496 __stack_data += sizeof(void *); \
499 #undef _ctf_sequence_encoded
500 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
501 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
503 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
504 const void *__ctf_tmp_ptr = (_src); \
505 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
506 __stack_data += sizeof(unsigned long); \
507 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
508 __stack_data += sizeof(void *); \
512 #define _ctf_string(_item, _src, _user, _nowrite) \
514 const void *__ctf_tmp_ptr = (_src); \
515 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
516 __stack_data += sizeof(void *); \
520 #define TP_PROTO(...) __VA_ARGS__
523 #define TP_FIELDS(...) __VA_ARGS__
526 #define TP_locvar(...) __VA_ARGS__
528 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
529 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
531 void __event_prepare_filter_stack__##_name(char *__stack_data, \
534 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
539 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
540 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
542 void __event_prepare_filter_stack__##_name(char *__stack_data, \
543 void *__tp_locvar, _proto) \
545 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
550 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
553 * Stage 5 of the trace events.
555 * Create static inline function that calculates event payload alignment.
558 /* Reset all macros within TRACEPOINT_EVENT */
559 #include "lttng-events-reset.h"
560 #include "lttng-events-write.h"
562 #undef _ctf_integer_ext
563 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
564 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
566 #undef _ctf_array_encoded
567 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
568 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
570 #undef _ctf_sequence_encoded
571 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
572 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
573 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
574 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
577 #define _ctf_string(_item, _src, _user, _nowrite)
580 #define TP_PROTO(...) __VA_ARGS__
583 #define TP_FIELDS(...) __VA_ARGS__
586 #define TP_locvar(...) __VA_ARGS__
588 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
589 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
590 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
592 size_t __event_align = 1; \
593 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
596 return __event_align; \
599 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
600 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
601 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
603 size_t __event_align = 1; \
604 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
607 return __event_align; \
610 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
613 * Stage 6 of tracepoint event generation.
615 * Create the probe function. This function calls event size calculation
616 * and writes event data into the buffer.
619 /* Reset all macros within TRACEPOINT_EVENT */
620 #include "lttng-events-reset.h"
621 #include "lttng-events-write.h"
623 #undef _ctf_integer_ext_fetched
624 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
626 _type __tmp = _src; \
627 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
628 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
631 #undef _ctf_integer_ext_isuser0
632 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
633 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
635 #undef _ctf_integer_ext_isuser1
636 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
639 char __array[sizeof(_user_src)]; \
640 __typeof__(_user_src) __v; \
642 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
643 &(_user_src), sizeof(_user_src))) \
644 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
645 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
648 #undef _ctf_integer_ext
649 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
650 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
652 #undef _ctf_array_encoded
653 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
654 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
656 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
658 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
661 #undef _ctf_sequence_encoded
662 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
663 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
665 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
666 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
667 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
669 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
671 __chan->ops->event_write_from_user(&__ctx, _src, \
672 sizeof(_type) * __get_dynamic_len(dest)); \
674 __chan->ops->event_write(&__ctx, _src, \
675 sizeof(_type) * __get_dynamic_len(dest)); \
679 #define _ctf_string(_item, _src, _user, _nowrite) \
680 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
682 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
683 __get_dynamic_len(dest)); \
685 __chan->ops->event_strcpy(&__ctx, _src, \
686 __get_dynamic_len(dest)); \
689 /* Beware: this get len actually consumes the len value */
690 #undef __get_dynamic_len
691 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
694 #define TP_PROTO(...) __VA_ARGS__
697 #define TP_ARGS(...) __VA_ARGS__
700 #define TP_FIELDS(...) __VA_ARGS__
703 #define TP_locvar(...) __VA_ARGS__
706 #define TP_code(...) __VA_ARGS__
709 * For state dump, check that "session" argument (mandatory) matches the
710 * session this event belongs to. Ensures that we write state dump data only
711 * into the started session, not into all sessions.
713 #ifdef TP_SESSION_CHECK
714 #define _TP_SESSION_CHECK(session, csession) (session == csession)
715 #else /* TP_SESSION_CHECK */
716 #define _TP_SESSION_CHECK(session, csession) 1
717 #endif /* TP_SESSION_CHECK */
720 * Using twice size for filter stack data to hold size and pointer for
721 * each field (worse case). For integers, max size required is 64-bit.
722 * Same for double-precision floats. Those fit within
723 * 2*sizeof(unsigned long) for all supported architectures.
724 * Perform UNION (||) of filter runtime list.
726 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
727 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
728 static void __event_probe__##_name(void *__data, _proto) \
730 struct probe_local_vars { _locvar }; \
731 struct lttng_event *__event = __data; \
732 struct lttng_channel *__chan = __event->chan; \
733 struct lttng_session *__session = __chan->session; \
734 struct lib_ring_buffer_ctx __ctx; \
735 size_t __event_len, __event_align; \
736 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
738 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
739 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
742 struct probe_local_vars __tp_locvar; \
743 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
745 struct lttng_pid_tracker *__lpf; \
747 if (!_TP_SESSION_CHECK(session, __session)) \
749 if (unlikely(!ACCESS_ONCE(__session->active))) \
751 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
753 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
755 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
756 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
759 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
760 struct lttng_bytecode_runtime *bc_runtime; \
761 int __filter_record = __event->has_enablers_without_bytecode; \
763 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
765 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
766 if (unlikely(bc_runtime->filter(bc_runtime, \
767 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
768 __filter_record = 1; \
770 if (likely(!__filter_record)) \
773 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
775 __event_align = __event_get_align__##_name(tp_locvar, _args); \
776 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
777 __event_align, -1); \
778 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
782 __chan->ops->event_commit(&__ctx); \
785 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
786 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
787 static void __event_probe__##_name(void *__data) \
789 struct probe_local_vars { _locvar }; \
790 struct lttng_event *__event = __data; \
791 struct lttng_channel *__chan = __event->chan; \
792 struct lttng_session *__session = __chan->session; \
793 struct lib_ring_buffer_ctx __ctx; \
794 size_t __event_len, __event_align; \
795 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
797 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
798 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
801 struct probe_local_vars __tp_locvar; \
802 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
804 struct lttng_pid_tracker *__lpf; \
806 if (!_TP_SESSION_CHECK(session, __session)) \
808 if (unlikely(!ACCESS_ONCE(__session->active))) \
810 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
812 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
814 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
815 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
818 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
819 struct lttng_bytecode_runtime *bc_runtime; \
820 int __filter_record = __event->has_enablers_without_bytecode; \
822 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
824 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
825 if (unlikely(bc_runtime->filter(bc_runtime, \
826 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
827 __filter_record = 1; \
829 if (likely(!__filter_record)) \
832 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
833 __event_align = __event_get_align__##_name(tp_locvar); \
834 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
835 __event_align, -1); \
836 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
840 __chan->ops->event_commit(&__ctx); \
843 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
845 #undef __get_dynamic_len
848 * Stage 7 of the trace events.
850 * Create event descriptions.
853 /* Named field types must be defined in lttng-types.h */
855 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
858 #define TP_PROBE_CB(_template) &__event_probe__##_template
861 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
862 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
863 static const struct lttng_event_desc __event_desc___##_map = { \
864 .fields = __event_fields___##_template, \
867 .probe_callback = (void *) TP_PROBE_CB(_template), \
868 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
869 .owner = THIS_MODULE, \
872 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
873 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
874 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
876 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
879 * Stage 8 of the trace events.
881 * Create an array of event description pointers.
884 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
886 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
887 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
888 &__event_desc___##_map,
890 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
891 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
892 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
894 #define TP_ID1(_token, _system) _token##_system
895 #define TP_ID(_token, _system) TP_ID1(_token, _system)
897 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
898 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
905 * Stage 9 of the trace events.
907 * Create a toplevel descriptor for the whole probe.
910 #define TP_ID1(_token, _system) _token##_system
911 #define TP_ID(_token, _system) TP_ID1(_token, _system)
913 /* non-const because list head will be modified when registered. */
914 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
915 .provider
= __stringify(TRACE_SYSTEM
),
916 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
917 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
918 .head
= { NULL
, NULL
},
919 .lazy_init_head
= { NULL
, NULL
},
927 * Stage 10 of the trace events.
929 * Register/unregister probes at module load/unload.
932 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
934 #define TP_ID1(_token, _system) _token##_system
935 #define TP_ID(_token, _system) TP_ID1(_token, _system)
936 #define module_init_eval1(_token, _system) module_init(_token##_system)
937 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
938 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
939 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
941 #ifndef TP_MODULE_NOINIT
942 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
944 wrapper_vmalloc_sync_all();
945 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
948 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
950 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
953 #ifndef TP_MODULE_NOAUTOLOAD
954 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
955 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
960 #undef module_init_eval
961 #undef module_exit_eval
This page took 0.055827 seconds and 5 git commands to generate.