ce4c3f125a43814251f9a3c26434973898e497a6
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 *__data);
139 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
142 * Stage 2 of the trace events.
144 * Create event field type metadata section.
145 * Each event produce an array of fields.
148 /* Reset all macros within TRACEPOINT_EVENT */
149 #include "lttng-events-reset.h"
150 #include "lttng-events-write.h"
151 #include "lttng-events-nowrite.h"
153 #undef _ctf_integer_ext
154 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
157 .type = __type_integer(_type, _byte_order, _base, none),\
158 .nowrite = _nowrite, \
162 #undef _ctf_array_encoded
163 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
168 .atype = atype_array, \
173 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
178 .nowrite = _nowrite, \
182 #undef _ctf_sequence_encoded
183 #define _ctf_sequence_encoded(_type, _item, _src, \
184 _length_type, _src_length, _encoding, \
185 _byte_order, _base, _user, _nowrite) \
190 .atype = atype_sequence, \
195 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
196 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
200 .nowrite = _nowrite, \
205 #define _ctf_string(_item, _src, _user, _nowrite) \
210 .atype = atype_string, \
213 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
216 .nowrite = _nowrite, \
221 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
223 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
224 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
225 static const struct lttng_event_field __event_fields___##_name[] = { \
229 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
230 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
231 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
233 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
236 * Stage 3 of the trace events.
238 * Create probe callback prototypes.
241 /* Reset all macros within TRACEPOINT_EVENT */
242 #include "lttng-events-reset.h"
245 #define TP_PROTO(...) __VA_ARGS__
247 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
248 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
249 static void __event_probe__##_name(void *__data, _proto);
251 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
252 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
253 static void __event_probe__##_name(void *__data);
255 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
258 * Stage 4 of the trace events.
260 * Create static inline function that calculates event size.
263 /* Reset all macros within TRACEPOINT_EVENT */
264 #include "lttng-events-reset.h"
265 #include "lttng-events-write.h"
267 #undef _ctf_integer_ext
268 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
269 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
270 __event_len += sizeof(_type);
272 #undef _ctf_array_encoded
273 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
274 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
275 __event_len += sizeof(_type) * (_length);
277 #undef _ctf_sequence_encoded
278 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
279 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
280 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
281 __event_len += sizeof(_length_type); \
282 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
283 __dynamic_len[__dynamic_len_idx] = (_src_length); \
284 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
288 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
292 #define _ctf_string(_item, _src, _user, _nowrite) \
294 __event_len += __dynamic_len[__dynamic_len_idx++] = \
297 __event_len += __dynamic_len[__dynamic_len_idx++] = \
298 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
301 #define TP_PROTO(...) __VA_ARGS__
304 #define TP_FIELDS(...) __VA_ARGS__
307 #define TP_locvar(...) __VA_ARGS__
309 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
310 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
311 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
312 void *__tp_locvar, _proto) \
314 size_t __event_len = 0; \
315 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
316 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
319 return __event_len; \
322 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
323 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
324 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
327 size_t __event_len = 0; \
328 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
329 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
332 return __event_len; \
335 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
339 * Stage 4.1 of tracepoint event generation.
341 * Create static inline function that layout the filter stack data.
342 * We make both write and nowrite data available to the filter.
345 /* Reset all macros within TRACEPOINT_EVENT */
346 #include "lttng-events-reset.h"
347 #include "lttng-events-write.h"
348 #include "lttng-events-nowrite.h"
350 #undef _ctf_integer_ext_fetched
351 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
352 if (lttng_is_signed_type(_type)) { \
353 int64_t __ctf_tmp_int64; \
354 switch (sizeof(_type)) { \
357 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
358 __ctf_tmp_int64 = (int64_t) __tmp.v; \
363 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
364 __ctf_tmp_int64 = (int64_t) __tmp.v; \
369 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
370 __ctf_tmp_int64 = (int64_t) __tmp.v; \
375 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
376 __ctf_tmp_int64 = (int64_t) __tmp.v; \
382 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
384 uint64_t __ctf_tmp_uint64; \
385 switch (sizeof(_type)) { \
388 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
389 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
394 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
395 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
400 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
401 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
406 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
407 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
413 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
415 __stack_data += sizeof(int64_t);
417 #undef _ctf_integer_ext_isuser0
418 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
419 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
421 #undef _ctf_integer_ext_isuser1
422 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
424 __typeof__(_user_src) _src; \
425 if (get_user(_src, &(_user_src))) \
427 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
430 #undef _ctf_integer_ext
431 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
432 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
434 #undef _ctf_array_encoded
435 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
437 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
438 const void *__ctf_tmp_ptr = (_src); \
439 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
440 __stack_data += sizeof(unsigned long); \
441 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
442 __stack_data += sizeof(void **); \
445 #undef _ctf_sequence_encoded
446 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
447 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
449 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
450 const void *__ctf_tmp_ptr = (_src); \
451 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
452 __stack_data += sizeof(unsigned long); \
453 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
454 __stack_data += sizeof(void **); \
458 #define _ctf_string(_item, _src, _user, _nowrite) \
460 const void *__ctf_tmp_ptr = (_src); \
461 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
462 __stack_data += sizeof(void **); \
466 #define TP_PROTO(...) __VA_ARGS__
469 #define TP_FIELDS(...) __VA_ARGS__
472 #define TP_locvar(...) __VA_ARGS__
474 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
475 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
477 void __event_prepare_filter_stack__##_name(char *__stack_data, \
480 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
485 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
486 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
488 void __event_prepare_filter_stack__##_name(char *__stack_data, \
489 void *__tp_locvar, _proto) \
491 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
496 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
499 * Stage 5 of the trace events.
501 * Create static inline function that calculates event payload alignment.
504 /* Reset all macros within TRACEPOINT_EVENT */
505 #include "lttng-events-reset.h"
506 #include "lttng-events-write.h"
508 #undef _ctf_integer_ext
509 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
510 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
512 #undef _ctf_array_encoded
513 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
514 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
516 #undef _ctf_sequence_encoded
517 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
518 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
519 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
520 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
523 #define _ctf_string(_item, _src, _user, _nowrite)
526 #define TP_PROTO(...) __VA_ARGS__
529 #define TP_FIELDS(...) __VA_ARGS__
532 #define TP_locvar(...) __VA_ARGS__
534 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
535 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
536 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
538 size_t __event_align = 1; \
539 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
542 return __event_align; \
545 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
546 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
547 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
549 size_t __event_align = 1; \
550 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
553 return __event_align; \
556 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
559 * Stage 6 of tracepoint event generation.
561 * Create the probe function. This function calls event size calculation
562 * and writes event data into the buffer.
565 /* Reset all macros within TRACEPOINT_EVENT */
566 #include "lttng-events-reset.h"
567 #include "lttng-events-write.h"
569 #undef _ctf_integer_ext_fetched
570 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
572 _type __tmp = _src; \
573 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
574 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
577 #undef _ctf_integer_ext_isuser0
578 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
579 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
581 #undef _ctf_integer_ext_isuser1
582 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
584 __typeof__(_user_src) _src; \
585 if (get_user(_src, &(_user_src))) \
587 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
590 #undef _ctf_integer_ext
591 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
592 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
594 #undef _ctf_array_encoded
595 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
596 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
598 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
600 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
603 #undef _ctf_sequence_encoded
604 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
605 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
607 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
608 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
609 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
611 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
613 __chan->ops->event_write_from_user(&__ctx, _src, \
614 sizeof(_type) * __get_dynamic_len(dest)); \
616 __chan->ops->event_write(&__ctx, _src, \
617 sizeof(_type) * __get_dynamic_len(dest)); \
621 #define _ctf_string(_item, _src, _user, _nowrite) \
622 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
624 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
625 __get_dynamic_len(dest)); \
627 __chan->ops->event_strcpy(&__ctx, _src, \
628 __get_dynamic_len(dest)); \
631 /* Beware: this get len actually consumes the len value */
632 #undef __get_dynamic_len
633 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
636 #define TP_PROTO(...) __VA_ARGS__
639 #define TP_ARGS(...) __VA_ARGS__
642 #define TP_FIELDS(...) __VA_ARGS__
645 #define TP_locvar(...) __VA_ARGS__
648 #define TP_code(...) __VA_ARGS__
651 * For state dump, check that "session" argument (mandatory) matches the
652 * session this event belongs to. Ensures that we write state dump data only
653 * into the started session, not into all sessions.
655 #ifdef TP_SESSION_CHECK
656 #define _TP_SESSION_CHECK(session, csession) (session == csession)
657 #else /* TP_SESSION_CHECK */
658 #define _TP_SESSION_CHECK(session, csession) 1
659 #endif /* TP_SESSION_CHECK */
662 * Using twice size for filter stack data to hold size and pointer for
663 * each field (worse case). For integers, max size required is 64-bit.
664 * Same for double-precision floats. Those fit within
665 * 2*sizeof(unsigned long) for all supported architectures.
666 * Perform UNION (||) of filter runtime list.
668 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
669 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
670 static void __event_probe__##_name(void *__data, _proto) \
672 struct probe_local_vars { _locvar }; \
673 struct lttng_event *__event = __data; \
674 struct lttng_channel *__chan = __event->chan; \
675 struct lttng_session *__session = __chan->session; \
676 struct lib_ring_buffer_ctx __ctx; \
677 size_t __event_len, __event_align; \
678 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
680 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
681 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
684 struct probe_local_vars __tp_locvar; \
685 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
687 struct lttng_pid_tracker *__lpf; \
689 if (!_TP_SESSION_CHECK(session, __session)) \
691 if (unlikely(!ACCESS_ONCE(__session->active))) \
693 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
695 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
697 __lpf = rcu_dereference(__session->pid_tracker); \
698 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
701 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
702 struct lttng_bytecode_runtime *bc_runtime; \
703 int __filter_record = __event->has_enablers_without_bytecode; \
705 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
707 list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
708 if (unlikely(bc_runtime->filter(bc_runtime, \
709 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
710 __filter_record = 1; \
712 if (likely(!__filter_record)) \
715 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
717 __event_align = __event_get_align__##_name(tp_locvar, _args); \
718 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
719 __event_align, -1); \
720 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
724 __chan->ops->event_commit(&__ctx); \
727 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
728 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
729 static void __event_probe__##_name(void *__data) \
731 struct probe_local_vars { _locvar }; \
732 struct lttng_event *__event = __data; \
733 struct lttng_channel *__chan = __event->chan; \
734 struct lttng_session *__session = __chan->session; \
735 struct lib_ring_buffer_ctx __ctx; \
736 size_t __event_len, __event_align; \
737 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
739 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
740 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
743 struct probe_local_vars __tp_locvar; \
744 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
746 struct lttng_pid_tracker *__lpf; \
748 if (!_TP_SESSION_CHECK(session, __session)) \
750 if (unlikely(!ACCESS_ONCE(__session->active))) \
752 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
754 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
756 __lpf = rcu_dereference(__session->pid_tracker); \
757 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
760 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
761 struct lttng_bytecode_runtime *bc_runtime; \
762 int __filter_record = __event->has_enablers_without_bytecode; \
764 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
766 list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
767 if (unlikely(bc_runtime->filter(bc_runtime, \
768 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
769 __filter_record = 1; \
771 if (likely(!__filter_record)) \
774 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
775 __event_align = __event_get_align__##_name(tp_locvar); \
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 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
787 #undef __get_dynamic_len
790 * Stage 7 of the trace events.
792 * Create event descriptions.
795 /* Named field types must be defined in lttng-types.h */
797 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
800 #define TP_PROBE_CB(_template) &__event_probe__##_template
803 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
804 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
805 static const struct lttng_event_desc __event_desc___##_map = { \
806 .fields = __event_fields___##_template, \
809 .probe_callback = (void *) TP_PROBE_CB(_template), \
810 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
811 .owner = THIS_MODULE, \
814 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
815 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
816 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
818 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
821 * Stage 8 of the trace events.
823 * Create an array of event description pointers.
826 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
828 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
829 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
830 &__event_desc___##_map,
832 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
833 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
834 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
836 #define TP_ID1(_token, _system) _token##_system
837 #define TP_ID(_token, _system) TP_ID1(_token, _system)
839 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
840 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
847 * Stage 9 of the trace events.
849 * Create a toplevel descriptor for the whole probe.
852 #define TP_ID1(_token, _system) _token##_system
853 #define TP_ID(_token, _system) TP_ID1(_token, _system)
855 /* non-const because list head will be modified when registered. */
856 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
857 .provider
= __stringify(TRACE_SYSTEM
),
858 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
859 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
860 .head
= { NULL
, NULL
},
861 .lazy_init_head
= { NULL
, NULL
},
869 * Stage 10 of the trace events.
871 * Register/unregister probes at module load/unload.
874 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
876 #define TP_ID1(_token, _system) _token##_system
877 #define TP_ID(_token, _system) TP_ID1(_token, _system)
878 #define module_init_eval1(_token, _system) module_init(_token##_system)
879 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
880 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
881 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
883 #ifndef TP_MODULE_NOINIT
884 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
886 wrapper_vmalloc_sync_all();
887 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
890 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
892 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
895 #ifndef TP_MODULE_NOAUTOLOAD
896 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
897 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
902 #undef module_init_eval
903 #undef module_exit_eval
This page took 0.056614 seconds and 4 git commands to generate.