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 "../lttng-events.h"
31 #include "../lttng-tracer-core.h"
34 * Macro declarations used for all stages.
38 * LTTng name mapping macros. LTTng remaps some of the kernel events to
39 * enforce name-spacing.
41 #undef LTTNG_TRACEPOINT_EVENT_MAP
42 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
43 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
47 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
49 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
50 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
51 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
53 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
55 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
56 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields) \
57 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
63 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
65 #undef LTTNG_TRACEPOINT_EVENT_CODE
66 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
67 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
75 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
76 * handlers for events. That is, if all events have the same parameters
77 * and just have distinct trace points. Each tracepoint can be defined
78 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
79 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
81 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
85 #undef LTTNG_TRACEPOINT_EVENT
86 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
87 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
92 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
93 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
94 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
96 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
97 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
98 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
100 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
101 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
102 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
104 #undef LTTNG_TRACEPOINT_EVENT_CLASS
105 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
106 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
109 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
110 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
111 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
115 * Stage 1 of the trace events.
117 * Create dummy trace calls for each events, verifying that the LTTng module
118 * instrumentation headers match the kernel arguments. Will be optimized
119 * out by the compiler.
122 /* Reset all macros within TRACEPOINT_EVENT */
123 #include "lttng-events-reset.h"
126 #define TP_PROTO(...) __VA_ARGS__
129 #define TP_ARGS(...) __VA_ARGS__
131 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
132 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
133 void trace_##_name(_proto);
135 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
136 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
137 void trace_##_name(void);
139 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
142 * Stage 1.1 of the trace events.
144 * Create dummy trace prototypes for each event class, and for each used
145 * template. This will allow checking whether the prototypes from the
146 * class and the instance using the class actually match.
149 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
152 #define TP_PROTO(...) __VA_ARGS__
155 #define TP_ARGS(...) __VA_ARGS__
157 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
158 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
159 void __event_template_proto___##_template(_proto);
161 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
162 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
163 void __event_template_proto___##_template(void);
165 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
166 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
167 void __event_template_proto___##_name(_proto);
169 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
170 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
171 void __event_template_proto___##_name(void);
173 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
176 * Stage 2 of the trace events.
178 * Create event field type metadata section.
179 * Each event produce an array of fields.
182 /* Reset all macros within TRACEPOINT_EVENT */
183 #include "lttng-events-reset.h"
184 #include "lttng-events-write.h"
185 #include "lttng-events-nowrite.h"
187 #undef _ctf_integer_ext
188 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
191 .type = __type_integer(_type, _byte_order, _base, none),\
192 .nowrite = _nowrite, \
196 #undef _ctf_array_encoded
197 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
202 .atype = atype_array, \
207 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
212 .nowrite = _nowrite, \
216 #undef _ctf_sequence_encoded
217 #define _ctf_sequence_encoded(_type, _item, _src, \
218 _length_type, _src_length, _encoding, \
219 _byte_order, _base, _user, _nowrite) \
224 .atype = atype_sequence, \
229 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
230 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
234 .nowrite = _nowrite, \
239 #define _ctf_string(_item, _src, _user, _nowrite) \
244 .atype = atype_string, \
247 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
250 .nowrite = _nowrite, \
255 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
257 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
258 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
259 static const struct lttng_event_field __event_fields___##_name[] = { \
263 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
264 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
265 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
267 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
270 * Stage 3 of the trace events.
272 * Create probe callback prototypes.
275 /* Reset all macros within TRACEPOINT_EVENT */
276 #include "lttng-events-reset.h"
279 #define TP_PROTO(...) __VA_ARGS__
281 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
282 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
283 static void __event_probe__##_name(void *__data, _proto);
285 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
286 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
287 static void __event_probe__##_name(void *__data);
289 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
292 * Stage 4 of the trace events.
294 * Create static inline function that calculates event size.
297 /* Reset all macros within TRACEPOINT_EVENT */
298 #include "lttng-events-reset.h"
299 #include "lttng-events-write.h"
301 #undef _ctf_integer_ext
302 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
303 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
304 __event_len += sizeof(_type);
306 #undef _ctf_array_encoded
307 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
308 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
309 __event_len += sizeof(_type) * (_length);
311 #undef _ctf_sequence_encoded
312 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
313 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
314 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
315 __event_len += sizeof(_length_type); \
316 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
317 __dynamic_len[__dynamic_len_idx] = (_src_length); \
318 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
322 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
326 #define _ctf_string(_item, _src, _user, _nowrite) \
328 __event_len += __dynamic_len[__dynamic_len_idx++] = \
331 __event_len += __dynamic_len[__dynamic_len_idx++] = \
332 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
335 #define TP_PROTO(...) __VA_ARGS__
338 #define TP_FIELDS(...) __VA_ARGS__
341 #define TP_locvar(...) __VA_ARGS__
343 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
344 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
345 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
346 void *__tp_locvar, _proto) \
348 size_t __event_len = 0; \
349 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
350 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
353 return __event_len; \
356 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
357 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
358 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
361 size_t __event_len = 0; \
362 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
363 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
366 return __event_len; \
369 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
373 * Stage 4.1 of tracepoint event generation.
375 * Create static inline function that layout the filter stack data.
376 * We make both write and nowrite data available to the filter.
379 /* Reset all macros within TRACEPOINT_EVENT */
380 #include "lttng-events-reset.h"
381 #include "lttng-events-write.h"
382 #include "lttng-events-nowrite.h"
384 #undef _ctf_integer_ext_fetched
385 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
386 if (lttng_is_signed_type(_type)) { \
387 int64_t __ctf_tmp_int64; \
388 switch (sizeof(_type)) { \
391 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
392 __ctf_tmp_int64 = (int64_t) __tmp.v; \
397 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
398 __ctf_tmp_int64 = (int64_t) __tmp.v; \
403 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
404 __ctf_tmp_int64 = (int64_t) __tmp.v; \
409 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
410 __ctf_tmp_int64 = (int64_t) __tmp.v; \
416 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
418 uint64_t __ctf_tmp_uint64; \
419 switch (sizeof(_type)) { \
422 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
423 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
428 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
429 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
434 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
435 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
440 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
441 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
447 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
449 __stack_data += sizeof(int64_t);
451 #undef _ctf_integer_ext_isuser0
452 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
453 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
455 #undef _ctf_integer_ext_isuser1
456 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
458 __typeof__(_user_src) _src; \
459 if (get_user(_src, &(_user_src))) \
461 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
464 #undef _ctf_integer_ext
465 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
466 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
468 #undef _ctf_array_encoded
469 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
471 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
472 const void *__ctf_tmp_ptr = (_src); \
473 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
474 __stack_data += sizeof(unsigned long); \
475 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
476 __stack_data += sizeof(void *); \
479 #undef _ctf_sequence_encoded
480 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
481 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
483 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
484 const void *__ctf_tmp_ptr = (_src); \
485 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
486 __stack_data += sizeof(unsigned long); \
487 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
488 __stack_data += sizeof(void *); \
492 #define _ctf_string(_item, _src, _user, _nowrite) \
494 const void *__ctf_tmp_ptr = (_src); \
495 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
496 __stack_data += sizeof(void *); \
500 #define TP_PROTO(...) __VA_ARGS__
503 #define TP_FIELDS(...) __VA_ARGS__
506 #define TP_locvar(...) __VA_ARGS__
508 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
509 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
511 void __event_prepare_filter_stack__##_name(char *__stack_data, \
514 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
519 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
520 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
522 void __event_prepare_filter_stack__##_name(char *__stack_data, \
523 void *__tp_locvar, _proto) \
525 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
530 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
533 * Stage 5 of the trace events.
535 * Create static inline function that calculates event payload alignment.
538 /* Reset all macros within TRACEPOINT_EVENT */
539 #include "lttng-events-reset.h"
540 #include "lttng-events-write.h"
542 #undef _ctf_integer_ext
543 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
544 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
546 #undef _ctf_array_encoded
547 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
548 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
550 #undef _ctf_sequence_encoded
551 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
552 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
553 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
554 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
557 #define _ctf_string(_item, _src, _user, _nowrite)
560 #define TP_PROTO(...) __VA_ARGS__
563 #define TP_FIELDS(...) __VA_ARGS__
566 #define TP_locvar(...) __VA_ARGS__
568 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
569 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
570 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
572 size_t __event_align = 1; \
573 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
576 return __event_align; \
579 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
580 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
581 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
583 size_t __event_align = 1; \
584 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
587 return __event_align; \
590 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
593 * Stage 6 of tracepoint event generation.
595 * Create the probe function. This function calls event size calculation
596 * and writes event data into the buffer.
599 /* Reset all macros within TRACEPOINT_EVENT */
600 #include "lttng-events-reset.h"
601 #include "lttng-events-write.h"
603 #undef _ctf_integer_ext_fetched
604 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
606 _type __tmp = _src; \
607 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
608 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
611 #undef _ctf_integer_ext_isuser0
612 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
613 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
615 #undef _ctf_integer_ext_isuser1
616 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
618 __typeof__(_user_src) _src; \
619 if (get_user(_src, &(_user_src))) \
621 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
624 #undef _ctf_integer_ext
625 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
626 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
628 #undef _ctf_array_encoded
629 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
630 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
632 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
634 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
637 #undef _ctf_sequence_encoded
638 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
639 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
641 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
642 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
643 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
645 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
647 __chan->ops->event_write_from_user(&__ctx, _src, \
648 sizeof(_type) * __get_dynamic_len(dest)); \
650 __chan->ops->event_write(&__ctx, _src, \
651 sizeof(_type) * __get_dynamic_len(dest)); \
655 #define _ctf_string(_item, _src, _user, _nowrite) \
656 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
658 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
659 __get_dynamic_len(dest)); \
661 __chan->ops->event_strcpy(&__ctx, _src, \
662 __get_dynamic_len(dest)); \
665 /* Beware: this get len actually consumes the len value */
666 #undef __get_dynamic_len
667 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
670 #define TP_PROTO(...) __VA_ARGS__
673 #define TP_ARGS(...) __VA_ARGS__
676 #define TP_FIELDS(...) __VA_ARGS__
679 #define TP_locvar(...) __VA_ARGS__
682 #define TP_code(...) __VA_ARGS__
685 * For state dump, check that "session" argument (mandatory) matches the
686 * session this event belongs to. Ensures that we write state dump data only
687 * into the started session, not into all sessions.
689 #ifdef TP_SESSION_CHECK
690 #define _TP_SESSION_CHECK(session, csession) (session == csession)
691 #else /* TP_SESSION_CHECK */
692 #define _TP_SESSION_CHECK(session, csession) 1
693 #endif /* TP_SESSION_CHECK */
696 * Using twice size for filter stack data to hold size and pointer for
697 * each field (worse case). For integers, max size required is 64-bit.
698 * Same for double-precision floats. Those fit within
699 * 2*sizeof(unsigned long) for all supported architectures.
700 * Perform UNION (||) of filter runtime list.
702 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
703 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
704 static void __event_probe__##_name(void *__data, _proto) \
706 struct probe_local_vars { _locvar }; \
707 struct lttng_event *__event = __data; \
708 struct lttng_channel *__chan = __event->chan; \
709 struct lttng_session *__session = __chan->session; \
710 struct lib_ring_buffer_ctx __ctx; \
711 size_t __event_len, __event_align; \
712 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
714 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
715 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
718 struct probe_local_vars __tp_locvar; \
719 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
721 struct lttng_pid_tracker *__lpf; \
723 if (!_TP_SESSION_CHECK(session, __session)) \
725 if (unlikely(!ACCESS_ONCE(__session->active))) \
727 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
729 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
731 __lpf = rcu_dereference(__session->pid_tracker); \
732 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
735 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
736 struct lttng_bytecode_runtime *bc_runtime; \
737 int __filter_record = __event->has_enablers_without_bytecode; \
739 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
741 list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
742 if (unlikely(bc_runtime->filter(bc_runtime, \
743 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
744 __filter_record = 1; \
746 if (likely(!__filter_record)) \
749 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
751 __event_align = __event_get_align__##_name(tp_locvar, _args); \
752 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
753 __event_align, -1); \
754 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
758 __chan->ops->event_commit(&__ctx); \
761 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
762 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
763 static void __event_probe__##_name(void *__data) \
765 struct probe_local_vars { _locvar }; \
766 struct lttng_event *__event = __data; \
767 struct lttng_channel *__chan = __event->chan; \
768 struct lttng_session *__session = __chan->session; \
769 struct lib_ring_buffer_ctx __ctx; \
770 size_t __event_len, __event_align; \
771 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
773 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
774 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
777 struct probe_local_vars __tp_locvar; \
778 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
780 struct lttng_pid_tracker *__lpf; \
782 if (!_TP_SESSION_CHECK(session, __session)) \
784 if (unlikely(!ACCESS_ONCE(__session->active))) \
786 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
788 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
790 __lpf = rcu_dereference(__session->pid_tracker); \
791 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
794 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
795 struct lttng_bytecode_runtime *bc_runtime; \
796 int __filter_record = __event->has_enablers_without_bytecode; \
798 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
800 list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
801 if (unlikely(bc_runtime->filter(bc_runtime, \
802 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
803 __filter_record = 1; \
805 if (likely(!__filter_record)) \
808 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
809 __event_align = __event_get_align__##_name(tp_locvar); \
810 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
811 __event_align, -1); \
812 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
816 __chan->ops->event_commit(&__ctx); \
819 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
821 #undef __get_dynamic_len
824 * Stage 7 of the trace events.
826 * Create event descriptions.
829 /* Named field types must be defined in lttng-types.h */
831 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
834 #define TP_PROBE_CB(_template) &__event_probe__##_template
837 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
838 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
839 static const struct lttng_event_desc __event_desc___##_map = { \
840 .fields = __event_fields___##_template, \
843 .probe_callback = (void *) TP_PROBE_CB(_template), \
844 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
845 .owner = THIS_MODULE, \
848 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
849 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
850 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
852 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
855 * Stage 8 of the trace events.
857 * Create an array of event description pointers.
860 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
862 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
863 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
864 &__event_desc___##_map,
866 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
867 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
868 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
870 #define TP_ID1(_token, _system) _token##_system
871 #define TP_ID(_token, _system) TP_ID1(_token, _system)
873 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
874 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
881 * Stage 9 of the trace events.
883 * Create a toplevel descriptor for the whole probe.
886 #define TP_ID1(_token, _system) _token##_system
887 #define TP_ID(_token, _system) TP_ID1(_token, _system)
889 /* non-const because list head will be modified when registered. */
890 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
891 .provider
= __stringify(TRACE_SYSTEM
),
892 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
893 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
894 .head
= { NULL
, NULL
},
895 .lazy_init_head
= { NULL
, NULL
},
903 * Stage 10 of the trace events.
905 * Register/unregister probes at module load/unload.
908 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
910 #define TP_ID1(_token, _system) _token##_system
911 #define TP_ID(_token, _system) TP_ID1(_token, _system)
912 #define module_init_eval1(_token, _system) module_init(_token##_system)
913 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
914 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
915 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
917 #ifndef TP_MODULE_NOINIT
918 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
920 wrapper_vmalloc_sync_all();
921 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
924 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
926 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
929 #ifndef TP_MODULE_NOAUTOLOAD
930 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
931 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
936 #undef module_init_eval
937 #undef module_exit_eval
This page took 0.056911 seconds and 6 git commands to generate.