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"
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, fields) \
59 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
65 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
67 #undef LTTNG_TRACEPOINT_EVENT_CODE
68 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
69 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
77 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
78 * handlers for events. That is, if all events have the same parameters
79 * and just have distinct trace points. Each tracepoint can be defined
80 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
81 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
83 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
87 #undef LTTNG_TRACEPOINT_EVENT
88 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
89 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
94 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
95 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
96 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
98 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
99 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
100 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
102 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
103 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
104 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
106 #undef LTTNG_TRACEPOINT_EVENT_CLASS
107 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
108 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
111 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
112 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
113 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
117 * Stage 1 of the trace events.
119 * Create dummy trace calls for each events, verifying that the LTTng module
120 * instrumentation headers match the kernel arguments. Will be optimized
121 * out by the compiler.
124 /* Reset all macros within TRACEPOINT_EVENT */
125 #include "lttng-events-reset.h"
128 #define TP_PROTO(...) __VA_ARGS__
131 #define TP_ARGS(...) __VA_ARGS__
133 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
134 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
135 void trace_##_name(_proto);
137 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
138 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
139 void trace_##_name(void);
141 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
144 * Stage 1.1 of the trace events.
146 * Create dummy trace prototypes for each event class, and for each used
147 * template. This will allow checking whether the prototypes from the
148 * class and the instance using the class actually match.
151 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
154 #define TP_PROTO(...) __VA_ARGS__
157 #define TP_ARGS(...) __VA_ARGS__
159 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
160 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
161 void __event_template_proto___##_template(_proto);
163 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
164 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
165 void __event_template_proto___##_template(void);
167 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
168 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
169 void __event_template_proto___##_name(_proto);
171 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
172 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
173 void __event_template_proto___##_name(void);
175 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
178 * Stage 2 of the trace events.
180 * Create event field type metadata section.
181 * Each event produce an array of fields.
184 /* Reset all macros within TRACEPOINT_EVENT */
185 #include "lttng-events-reset.h"
186 #include "lttng-events-write.h"
187 #include "lttng-events-nowrite.h"
189 #undef _ctf_integer_ext
190 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
193 .type = __type_integer(_type, _byte_order, _base, none),\
194 .nowrite = _nowrite, \
198 #undef _ctf_array_encoded
199 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
204 .atype = atype_array, \
209 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
214 .nowrite = _nowrite, \
218 #undef _ctf_sequence_encoded
219 #define _ctf_sequence_encoded(_type, _item, _src, \
220 _length_type, _src_length, _encoding, \
221 _byte_order, _base, _user, _nowrite) \
226 .atype = atype_sequence, \
231 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
232 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
236 .nowrite = _nowrite, \
241 #define _ctf_string(_item, _src, _user, _nowrite) \
246 .atype = atype_string, \
249 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
252 .nowrite = _nowrite, \
257 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
259 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
260 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
261 static const struct lttng_event_field __event_fields___##_name[] = { \
265 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
266 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
267 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
269 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
272 * Stage 3 of the trace events.
274 * Create probe callback prototypes.
277 /* Reset all macros within TRACEPOINT_EVENT */
278 #include "lttng-events-reset.h"
281 #define TP_PROTO(...) __VA_ARGS__
283 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
284 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
285 static void __event_probe__##_name(void *__data, _proto);
287 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
288 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
289 static void __event_probe__##_name(void *__data);
291 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
294 * Stage 4 of the trace events.
296 * Create static inline function that calculates event size.
299 /* Reset all macros within TRACEPOINT_EVENT */
300 #include "lttng-events-reset.h"
301 #include "lttng-events-write.h"
303 #undef _ctf_integer_ext
304 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
305 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
306 __event_len += sizeof(_type);
308 #undef _ctf_array_encoded
309 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
310 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
311 __event_len += sizeof(_type) * (_length);
313 #undef _ctf_sequence_encoded
314 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
315 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
316 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
317 __event_len += sizeof(_length_type); \
318 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
319 __dynamic_len[__dynamic_len_idx] = (_src_length); \
320 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
324 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
328 #define _ctf_string(_item, _src, _user, _nowrite) \
330 __event_len += __dynamic_len[__dynamic_len_idx++] = \
331 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
333 __event_len += __dynamic_len[__dynamic_len_idx++] = \
337 #define TP_PROTO(...) __VA_ARGS__
340 #define TP_FIELDS(...) __VA_ARGS__
343 #define TP_locvar(...) __VA_ARGS__
345 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
346 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
347 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
348 void *__tp_locvar, _proto) \
350 size_t __event_len = 0; \
351 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
352 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
355 return __event_len; \
358 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
359 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
360 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
363 size_t __event_len = 0; \
364 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
365 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
368 return __event_len; \
371 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
375 * Stage 4.1 of tracepoint event generation.
377 * Create static inline function that layout the filter stack data.
378 * We make both write and nowrite data available to the filter.
381 /* Reset all macros within TRACEPOINT_EVENT */
382 #include "lttng-events-reset.h"
383 #include "lttng-events-write.h"
384 #include "lttng-events-nowrite.h"
386 #undef _ctf_integer_ext_fetched
387 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
388 if (lttng_is_signed_type(_type)) { \
389 int64_t __ctf_tmp_int64; \
390 switch (sizeof(_type)) { \
393 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
394 __ctf_tmp_int64 = (int64_t) __tmp.v; \
399 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
400 __ctf_tmp_int64 = (int64_t) __tmp.v; \
405 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
406 __ctf_tmp_int64 = (int64_t) __tmp.v; \
411 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
412 __ctf_tmp_int64 = (int64_t) __tmp.v; \
418 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
420 uint64_t __ctf_tmp_uint64; \
421 switch (sizeof(_type)) { \
424 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
425 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
430 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
431 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
436 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
437 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
442 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
443 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
449 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
451 __stack_data += sizeof(int64_t);
453 #undef _ctf_integer_ext_isuser0
454 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
455 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
457 #undef _ctf_integer_ext_isuser1
458 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
461 char __array[sizeof(_user_src)]; \
462 __typeof__(_user_src) __v; \
464 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
465 &(_user_src), sizeof(_user_src))) \
466 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
467 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
470 #undef _ctf_integer_ext
471 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
472 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
474 #undef _ctf_array_encoded
475 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
477 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
478 const void *__ctf_tmp_ptr = (_src); \
479 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
480 __stack_data += sizeof(unsigned long); \
481 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
482 __stack_data += sizeof(void *); \
485 #undef _ctf_sequence_encoded
486 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
487 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
489 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
490 const void *__ctf_tmp_ptr = (_src); \
491 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
492 __stack_data += sizeof(unsigned long); \
493 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
494 __stack_data += sizeof(void *); \
498 #define _ctf_string(_item, _src, _user, _nowrite) \
500 const void *__ctf_tmp_ptr = (_src); \
501 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
502 __stack_data += sizeof(void *); \
506 #define TP_PROTO(...) __VA_ARGS__
509 #define TP_FIELDS(...) __VA_ARGS__
512 #define TP_locvar(...) __VA_ARGS__
514 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
515 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
517 void __event_prepare_filter_stack__##_name(char *__stack_data, \
520 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
525 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
526 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
528 void __event_prepare_filter_stack__##_name(char *__stack_data, \
529 void *__tp_locvar, _proto) \
531 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
536 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
539 * Stage 5 of the trace events.
541 * Create static inline function that calculates event payload alignment.
544 /* Reset all macros within TRACEPOINT_EVENT */
545 #include "lttng-events-reset.h"
546 #include "lttng-events-write.h"
548 #undef _ctf_integer_ext
549 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
550 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
552 #undef _ctf_array_encoded
553 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
554 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
556 #undef _ctf_sequence_encoded
557 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
558 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
559 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
560 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
563 #define _ctf_string(_item, _src, _user, _nowrite)
566 #define TP_PROTO(...) __VA_ARGS__
569 #define TP_FIELDS(...) __VA_ARGS__
572 #define TP_locvar(...) __VA_ARGS__
574 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
575 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
576 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
578 size_t __event_align = 1; \
579 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
582 return __event_align; \
585 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
586 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
587 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
589 size_t __event_align = 1; \
590 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
593 return __event_align; \
596 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
599 * Stage 6 of tracepoint event generation.
601 * Create the probe function. This function calls event size calculation
602 * and writes event data into the buffer.
605 /* Reset all macros within TRACEPOINT_EVENT */
606 #include "lttng-events-reset.h"
607 #include "lttng-events-write.h"
609 #undef _ctf_integer_ext_fetched
610 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
612 _type __tmp = _src; \
613 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
614 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
617 #undef _ctf_integer_ext_isuser0
618 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
619 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
621 #undef _ctf_integer_ext_isuser1
622 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
625 char __array[sizeof(_user_src)]; \
626 __typeof__(_user_src) __v; \
628 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
629 &(_user_src), sizeof(_user_src))) \
630 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
631 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
634 #undef _ctf_integer_ext
635 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
636 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
638 #undef _ctf_array_encoded
639 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
640 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
642 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
644 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
647 #undef _ctf_sequence_encoded
648 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
649 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
651 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
652 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
653 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
655 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
657 __chan->ops->event_write_from_user(&__ctx, _src, \
658 sizeof(_type) * __get_dynamic_len(dest)); \
660 __chan->ops->event_write(&__ctx, _src, \
661 sizeof(_type) * __get_dynamic_len(dest)); \
665 #define _ctf_string(_item, _src, _user, _nowrite) \
666 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
668 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
669 __get_dynamic_len(dest)); \
671 __chan->ops->event_strcpy(&__ctx, _src, \
672 __get_dynamic_len(dest)); \
675 /* Beware: this get len actually consumes the len value */
676 #undef __get_dynamic_len
677 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
680 #define TP_PROTO(...) __VA_ARGS__
683 #define TP_ARGS(...) __VA_ARGS__
686 #define TP_FIELDS(...) __VA_ARGS__
689 #define TP_locvar(...) __VA_ARGS__
692 #define TP_code(...) __VA_ARGS__
695 * For state dump, check that "session" argument (mandatory) matches the
696 * session this event belongs to. Ensures that we write state dump data only
697 * into the started session, not into all sessions.
699 #ifdef TP_SESSION_CHECK
700 #define _TP_SESSION_CHECK(session, csession) (session == csession)
701 #else /* TP_SESSION_CHECK */
702 #define _TP_SESSION_CHECK(session, csession) 1
703 #endif /* TP_SESSION_CHECK */
706 * Using twice size for filter stack data to hold size and pointer for
707 * each field (worse case). For integers, max size required is 64-bit.
708 * Same for double-precision floats. Those fit within
709 * 2*sizeof(unsigned long) for all supported architectures.
710 * Perform UNION (||) of filter runtime list.
712 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
713 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
714 static void __event_probe__##_name(void *__data, _proto) \
716 struct probe_local_vars { _locvar }; \
717 struct lttng_event *__event = __data; \
718 struct lttng_channel *__chan = __event->chan; \
719 struct lttng_session *__session = __chan->session; \
720 struct lib_ring_buffer_ctx __ctx; \
721 size_t __event_len, __event_align; \
722 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
724 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
725 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
728 struct probe_local_vars __tp_locvar; \
729 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
731 struct lttng_pid_tracker *__lpf; \
733 if (!_TP_SESSION_CHECK(session, __session)) \
735 if (unlikely(!ACCESS_ONCE(__session->active))) \
737 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
739 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
741 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
742 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
745 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
746 struct lttng_bytecode_runtime *bc_runtime; \
747 int __filter_record = __event->has_enablers_without_bytecode; \
749 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
751 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
752 if (unlikely(bc_runtime->filter(bc_runtime, \
753 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
754 __filter_record = 1; \
756 if (likely(!__filter_record)) \
759 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
761 __event_align = __event_get_align__##_name(tp_locvar, _args); \
762 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
763 __event_align, -1); \
764 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
768 __chan->ops->event_commit(&__ctx); \
771 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
772 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
773 static void __event_probe__##_name(void *__data) \
775 struct probe_local_vars { _locvar }; \
776 struct lttng_event *__event = __data; \
777 struct lttng_channel *__chan = __event->chan; \
778 struct lttng_session *__session = __chan->session; \
779 struct lib_ring_buffer_ctx __ctx; \
780 size_t __event_len, __event_align; \
781 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
783 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
784 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
787 struct probe_local_vars __tp_locvar; \
788 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
790 struct lttng_pid_tracker *__lpf; \
792 if (!_TP_SESSION_CHECK(session, __session)) \
794 if (unlikely(!ACCESS_ONCE(__session->active))) \
796 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
798 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
800 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
801 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
804 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
805 struct lttng_bytecode_runtime *bc_runtime; \
806 int __filter_record = __event->has_enablers_without_bytecode; \
808 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
810 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
811 if (unlikely(bc_runtime->filter(bc_runtime, \
812 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
813 __filter_record = 1; \
815 if (likely(!__filter_record)) \
818 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
819 __event_align = __event_get_align__##_name(tp_locvar); \
820 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
821 __event_align, -1); \
822 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
826 __chan->ops->event_commit(&__ctx); \
829 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
831 #undef __get_dynamic_len
834 * Stage 7 of the trace events.
836 * Create event descriptions.
839 /* Named field types must be defined in lttng-types.h */
841 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
844 #define TP_PROBE_CB(_template) &__event_probe__##_template
847 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
848 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
849 static const struct lttng_event_desc __event_desc___##_map = { \
850 .fields = __event_fields___##_template, \
853 .probe_callback = (void *) TP_PROBE_CB(_template), \
854 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
855 .owner = THIS_MODULE, \
858 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
859 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
860 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
862 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
865 * Stage 8 of the trace events.
867 * Create an array of event description pointers.
870 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
872 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
873 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
874 &__event_desc___##_map,
876 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
877 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
878 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
880 #define TP_ID1(_token, _system) _token##_system
881 #define TP_ID(_token, _system) TP_ID1(_token, _system)
883 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
884 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
891 * Stage 9 of the trace events.
893 * Create a toplevel descriptor for the whole probe.
896 #define TP_ID1(_token, _system) _token##_system
897 #define TP_ID(_token, _system) TP_ID1(_token, _system)
899 /* non-const because list head will be modified when registered. */
900 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
901 .provider
= __stringify(TRACE_SYSTEM
),
902 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
903 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
904 .head
= { NULL
, NULL
},
905 .lazy_init_head
= { NULL
, NULL
},
913 * Stage 10 of the trace events.
915 * Register/unregister probes at module load/unload.
918 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
920 #define TP_ID1(_token, _system) _token##_system
921 #define TP_ID(_token, _system) TP_ID1(_token, _system)
922 #define module_init_eval1(_token, _system) module_init(_token##_system)
923 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
924 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
925 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
927 #ifndef TP_MODULE_NOINIT
928 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
930 wrapper_vmalloc_sync_all();
931 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
934 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
936 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
939 #ifndef TP_MODULE_NOAUTOLOAD
940 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
941 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
946 #undef module_init_eval
947 #undef module_exit_eval
This page took 0.061139 seconds and 5 git commands to generate.