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/rcu.h"
31 #include "../lttng-events.h"
32 #include "../lttng-tracer-core.h"
35 * Macro declarations used for all stages.
39 * LTTng name mapping macros. LTTng remaps some of the kernel events to
40 * enforce name-spacing.
42 #undef LTTNG_TRACEPOINT_EVENT_MAP
43 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
44 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
48 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
50 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
51 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
52 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
54 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
56 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
57 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields) \
58 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
64 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
66 #undef LTTNG_TRACEPOINT_EVENT_CODE
67 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
68 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
76 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
77 * handlers for events. That is, if all events have the same parameters
78 * and just have distinct trace points. Each tracepoint can be defined
79 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
80 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
82 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
86 #undef LTTNG_TRACEPOINT_EVENT
87 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
88 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
93 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
94 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
95 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
97 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
98 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
99 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
101 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
102 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
103 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
105 #undef LTTNG_TRACEPOINT_EVENT_CLASS
106 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
107 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
110 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
111 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
112 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
116 * Stage 1 of the trace events.
118 * Create dummy trace calls for each events, verifying that the LTTng module
119 * instrumentation headers match the kernel arguments. Will be optimized
120 * out by the compiler.
123 /* Reset all macros within TRACEPOINT_EVENT */
124 #include "lttng-events-reset.h"
127 #define TP_PROTO(...) __VA_ARGS__
130 #define TP_ARGS(...) __VA_ARGS__
132 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
133 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
134 void trace_##_name(_proto);
136 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
137 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
138 void trace_##_name(void);
140 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
143 * Stage 1.1 of the trace events.
145 * Create dummy trace prototypes for each event class, and for each used
146 * template. This will allow checking whether the prototypes from the
147 * class and the instance using the class actually match.
150 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
153 #define TP_PROTO(...) __VA_ARGS__
156 #define TP_ARGS(...) __VA_ARGS__
158 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
159 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
160 void __event_template_proto___##_template(_proto);
162 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
163 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
164 void __event_template_proto___##_template(void);
166 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
167 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
168 void __event_template_proto___##_name(_proto);
170 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
171 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
172 void __event_template_proto___##_name(void);
174 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
177 * Stage 2 of the trace events.
179 * Create event field type metadata section.
180 * Each event produce an array of fields.
183 /* Reset all macros within TRACEPOINT_EVENT */
184 #include "lttng-events-reset.h"
185 #include "lttng-events-write.h"
186 #include "lttng-events-nowrite.h"
188 #undef _ctf_integer_ext
189 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
192 .type = __type_integer(_type, _byte_order, _base, none),\
193 .nowrite = _nowrite, \
197 #undef _ctf_array_encoded
198 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
203 .atype = atype_array, \
208 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
213 .nowrite = _nowrite, \
217 #undef _ctf_sequence_encoded
218 #define _ctf_sequence_encoded(_type, _item, _src, \
219 _length_type, _src_length, _encoding, \
220 _byte_order, _base, _user, _nowrite) \
225 .atype = atype_sequence, \
230 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
231 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
235 .nowrite = _nowrite, \
240 #define _ctf_string(_item, _src, _user, _nowrite) \
245 .atype = atype_string, \
248 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
251 .nowrite = _nowrite, \
256 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
258 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
259 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
260 static const struct lttng_event_field __event_fields___##_name[] = { \
264 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
266 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
268 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
271 * Stage 3 of the trace events.
273 * Create probe callback prototypes.
276 /* Reset all macros within TRACEPOINT_EVENT */
277 #include "lttng-events-reset.h"
280 #define TP_PROTO(...) __VA_ARGS__
282 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
283 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
284 static void __event_probe__##_name(void *__data, _proto);
286 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
287 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
288 static void __event_probe__##_name(void *__data);
290 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
293 * Stage 4 of the trace events.
295 * Create static inline function that calculates event size.
298 /* Reset all macros within TRACEPOINT_EVENT */
299 #include "lttng-events-reset.h"
300 #include "lttng-events-write.h"
302 #undef _ctf_integer_ext
303 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
304 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
305 __event_len += sizeof(_type);
307 #undef _ctf_array_encoded
308 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
309 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
310 __event_len += sizeof(_type) * (_length);
312 #undef _ctf_sequence_encoded
313 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
314 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
315 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
316 __event_len += sizeof(_length_type); \
317 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
318 __dynamic_len[__dynamic_len_idx] = (_src_length); \
319 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
323 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
327 #define _ctf_string(_item, _src, _user, _nowrite) \
329 __event_len += __dynamic_len[__dynamic_len_idx++] = \
330 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
332 __event_len += __dynamic_len[__dynamic_len_idx++] = \
336 #define TP_PROTO(...) __VA_ARGS__
339 #define TP_FIELDS(...) __VA_ARGS__
342 #define TP_locvar(...) __VA_ARGS__
344 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
345 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
346 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
347 void *__tp_locvar, _proto) \
349 size_t __event_len = 0; \
350 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
351 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
354 return __event_len; \
357 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
358 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
359 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
362 size_t __event_len = 0; \
363 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
364 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
367 return __event_len; \
370 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
374 * Stage 4.1 of tracepoint event generation.
376 * Create static inline function that layout the filter stack data.
377 * We make both write and nowrite data available to the filter.
380 /* Reset all macros within TRACEPOINT_EVENT */
381 #include "lttng-events-reset.h"
382 #include "lttng-events-write.h"
383 #include "lttng-events-nowrite.h"
385 #undef _ctf_integer_ext_fetched
386 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
387 if (lttng_is_signed_type(_type)) { \
388 int64_t __ctf_tmp_int64; \
389 switch (sizeof(_type)) { \
392 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
393 __ctf_tmp_int64 = (int64_t) __tmp.v; \
398 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
399 __ctf_tmp_int64 = (int64_t) __tmp.v; \
404 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
405 __ctf_tmp_int64 = (int64_t) __tmp.v; \
410 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
411 __ctf_tmp_int64 = (int64_t) __tmp.v; \
417 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
419 uint64_t __ctf_tmp_uint64; \
420 switch (sizeof(_type)) { \
423 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
424 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
429 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
430 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
435 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
436 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
441 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
442 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
448 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
450 __stack_data += sizeof(int64_t);
452 #undef _ctf_integer_ext_isuser0
453 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
454 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
456 #undef _ctf_integer_ext_isuser1
457 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
459 __typeof__(_user_src) _src; \
460 if (get_user(_src, &(_user_src))) \
462 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
465 #undef _ctf_integer_ext
466 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
467 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
469 #undef _ctf_array_encoded
470 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
472 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
473 const void *__ctf_tmp_ptr = (_src); \
474 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
475 __stack_data += sizeof(unsigned long); \
476 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
477 __stack_data += sizeof(void *); \
480 #undef _ctf_sequence_encoded
481 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
482 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
484 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
485 const void *__ctf_tmp_ptr = (_src); \
486 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
487 __stack_data += sizeof(unsigned long); \
488 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
489 __stack_data += sizeof(void *); \
493 #define _ctf_string(_item, _src, _user, _nowrite) \
495 const void *__ctf_tmp_ptr = (_src); \
496 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
497 __stack_data += sizeof(void *); \
501 #define TP_PROTO(...) __VA_ARGS__
504 #define TP_FIELDS(...) __VA_ARGS__
507 #define TP_locvar(...) __VA_ARGS__
509 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
510 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
512 void __event_prepare_filter_stack__##_name(char *__stack_data, \
515 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
520 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
521 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
523 void __event_prepare_filter_stack__##_name(char *__stack_data, \
524 void *__tp_locvar, _proto) \
526 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
531 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
534 * Stage 5 of the trace events.
536 * Create static inline function that calculates event payload alignment.
539 /* Reset all macros within TRACEPOINT_EVENT */
540 #include "lttng-events-reset.h"
541 #include "lttng-events-write.h"
543 #undef _ctf_integer_ext
544 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
545 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
547 #undef _ctf_array_encoded
548 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
549 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
551 #undef _ctf_sequence_encoded
552 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
553 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
554 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
555 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
558 #define _ctf_string(_item, _src, _user, _nowrite)
561 #define TP_PROTO(...) __VA_ARGS__
564 #define TP_FIELDS(...) __VA_ARGS__
567 #define TP_locvar(...) __VA_ARGS__
569 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
570 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
571 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
573 size_t __event_align = 1; \
574 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
577 return __event_align; \
580 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
581 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
582 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
584 size_t __event_align = 1; \
585 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
588 return __event_align; \
591 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
594 * Stage 6 of tracepoint event generation.
596 * Create the probe function. This function calls event size calculation
597 * and writes event data into the buffer.
600 /* Reset all macros within TRACEPOINT_EVENT */
601 #include "lttng-events-reset.h"
602 #include "lttng-events-write.h"
604 #undef _ctf_integer_ext_fetched
605 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
607 _type __tmp = _src; \
608 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
609 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
612 #undef _ctf_integer_ext_isuser0
613 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
614 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
616 #undef _ctf_integer_ext_isuser1
617 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
619 __typeof__(_user_src) _src; \
620 if (get_user(_src, &(_user_src))) \
622 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
625 #undef _ctf_integer_ext
626 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
627 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
629 #undef _ctf_array_encoded
630 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
631 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
633 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
635 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
638 #undef _ctf_sequence_encoded
639 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
640 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
642 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
643 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
644 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
646 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
648 __chan->ops->event_write_from_user(&__ctx, _src, \
649 sizeof(_type) * __get_dynamic_len(dest)); \
651 __chan->ops->event_write(&__ctx, _src, \
652 sizeof(_type) * __get_dynamic_len(dest)); \
656 #define _ctf_string(_item, _src, _user, _nowrite) \
657 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
659 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
660 __get_dynamic_len(dest)); \
662 __chan->ops->event_strcpy(&__ctx, _src, \
663 __get_dynamic_len(dest)); \
666 /* Beware: this get len actually consumes the len value */
667 #undef __get_dynamic_len
668 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
671 #define TP_PROTO(...) __VA_ARGS__
674 #define TP_ARGS(...) __VA_ARGS__
677 #define TP_FIELDS(...) __VA_ARGS__
680 #define TP_locvar(...) __VA_ARGS__
683 #define TP_code(...) __VA_ARGS__
686 * For state dump, check that "session" argument (mandatory) matches the
687 * session this event belongs to. Ensures that we write state dump data only
688 * into the started session, not into all sessions.
690 #ifdef TP_SESSION_CHECK
691 #define _TP_SESSION_CHECK(session, csession) (session == csession)
692 #else /* TP_SESSION_CHECK */
693 #define _TP_SESSION_CHECK(session, csession) 1
694 #endif /* TP_SESSION_CHECK */
697 * Using twice size for filter stack data to hold size and pointer for
698 * each field (worse case). For integers, max size required is 64-bit.
699 * Same for double-precision floats. Those fit within
700 * 2*sizeof(unsigned long) for all supported architectures.
701 * Perform UNION (||) of filter runtime list.
703 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
704 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
705 static void __event_probe__##_name(void *__data, _proto) \
707 struct probe_local_vars { _locvar }; \
708 struct lttng_event *__event = __data; \
709 struct lttng_channel *__chan = __event->chan; \
710 struct lttng_session *__session = __chan->session; \
711 struct lib_ring_buffer_ctx __ctx; \
712 size_t __event_len, __event_align; \
713 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
715 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
716 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
719 struct probe_local_vars __tp_locvar; \
720 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
722 struct lttng_pid_tracker *__lpf; \
724 if (!_TP_SESSION_CHECK(session, __session)) \
726 if (unlikely(!ACCESS_ONCE(__session->active))) \
728 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
730 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
732 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
733 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
736 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
737 struct lttng_bytecode_runtime *bc_runtime; \
738 int __filter_record = __event->has_enablers_without_bytecode; \
740 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
742 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
743 if (unlikely(bc_runtime->filter(bc_runtime, \
744 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
745 __filter_record = 1; \
747 if (likely(!__filter_record)) \
750 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
752 __event_align = __event_get_align__##_name(tp_locvar, _args); \
753 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
754 __event_align, -1); \
755 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
759 __chan->ops->event_commit(&__ctx); \
762 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
763 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
764 static void __event_probe__##_name(void *__data) \
766 struct probe_local_vars { _locvar }; \
767 struct lttng_event *__event = __data; \
768 struct lttng_channel *__chan = __event->chan; \
769 struct lttng_session *__session = __chan->session; \
770 struct lib_ring_buffer_ctx __ctx; \
771 size_t __event_len, __event_align; \
772 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
774 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
775 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
778 struct probe_local_vars __tp_locvar; \
779 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
781 struct lttng_pid_tracker *__lpf; \
783 if (!_TP_SESSION_CHECK(session, __session)) \
785 if (unlikely(!ACCESS_ONCE(__session->active))) \
787 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
789 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
791 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
792 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
795 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
796 struct lttng_bytecode_runtime *bc_runtime; \
797 int __filter_record = __event->has_enablers_without_bytecode; \
799 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
801 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
802 if (unlikely(bc_runtime->filter(bc_runtime, \
803 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
804 __filter_record = 1; \
806 if (likely(!__filter_record)) \
809 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
810 __event_align = __event_get_align__##_name(tp_locvar); \
811 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
812 __event_align, -1); \
813 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
817 __chan->ops->event_commit(&__ctx); \
820 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
822 #undef __get_dynamic_len
825 * Stage 7 of the trace events.
827 * Create event descriptions.
830 /* Named field types must be defined in lttng-types.h */
832 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
835 #define TP_PROBE_CB(_template) &__event_probe__##_template
838 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
839 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
840 static const struct lttng_event_desc __event_desc___##_map = { \
841 .fields = __event_fields___##_template, \
844 .probe_callback = (void *) TP_PROBE_CB(_template), \
845 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
846 .owner = THIS_MODULE, \
849 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
850 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
851 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
853 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
856 * Stage 8 of the trace events.
858 * Create an array of event description pointers.
861 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
863 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
864 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
865 &__event_desc___##_map,
867 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
868 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
869 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
871 #define TP_ID1(_token, _system) _token##_system
872 #define TP_ID(_token, _system) TP_ID1(_token, _system)
874 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
875 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
882 * Stage 9 of the trace events.
884 * Create a toplevel descriptor for the whole probe.
887 #define TP_ID1(_token, _system) _token##_system
888 #define TP_ID(_token, _system) TP_ID1(_token, _system)
890 /* non-const because list head will be modified when registered. */
891 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
892 .provider
= __stringify(TRACE_SYSTEM
),
893 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
894 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
895 .head
= { NULL
, NULL
},
896 .lazy_init_head
= { NULL
, NULL
},
904 * Stage 10 of the trace events.
906 * Register/unregister probes at module load/unload.
909 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
911 #define TP_ID1(_token, _system) _token##_system
912 #define TP_ID(_token, _system) TP_ID1(_token, _system)
913 #define module_init_eval1(_token, _system) module_init(_token##_system)
914 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
915 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
916 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
918 #ifndef TP_MODULE_NOINIT
919 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
921 wrapper_vmalloc_sync_all();
922 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
925 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
927 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
930 #ifndef TP_MODULE_NOAUTOLOAD
931 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
932 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
937 #undef module_init_eval
938 #undef module_exit_eval
This page took 0.049007 seconds and 4 git commands to generate.