4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
5 * Copyright (C) 2009-2012 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
21 #include <linux/uaccess.h>
22 #include <linux/debugfs.h>
24 #include "lttng-types.h"
25 #include "lttng-probe-user.h"
26 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
27 #include "../wrapper/ringbuffer/frontend_types.h"
28 #include "../lttng-events.h"
29 #include "../lttng-tracer-core.h"
31 #define __LTTNG_NULL_STRING "(null)"
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, tstruct, assign, print) \
43 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, tstruct, assign, print) \
53 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
57 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
59 #undef LTTNG_TRACEPOINT_EVENT_CODE
60 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, tstruct, assign, print) \
61 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(name, \
69 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(name, name, name, PARAMS(proto), PARAMS(args))
72 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP
73 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP(template, name, map, proto, args, print) \
74 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, map, PARAMS(proto), PARAMS(args))
76 /* Callbacks are meaningless to LTTng. */
77 #undef LTTNG_TRACEPOINT_EVENT_FN_MAP
78 #define LTTNG_TRACEPOINT_EVENT_FN_MAP(name, map, proto, args, tstruct, \
79 assign, print, reg, unreg) \
80 LTTNG_TRACEPOINT_EVENT_MAP(name, map, PARAMS(proto), PARAMS(args), \
81 PARAMS(tstruct), PARAMS(assign), PARAMS(print))
83 #undef LTTNG_TRACEPOINT_EVENT_CONDITION_MAP
84 #define LTTNG_TRACEPOINT_EVENT_CONDITION_MAP(name, map, proto, args, cond, tstruct, assign, print) \
85 LTTNG_TRACEPOINT_EVENT_MAP(name, map, \
92 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION_MAP
93 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION_MAP(template, name, map, proto, args, cond) \
94 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, map, PARAMS(proto), PARAMS(args))
97 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
98 * handlers for events. That is, if all events have the same parameters
99 * and just have distinct trace points. Each tracepoint can be defined
100 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
101 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
103 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
107 #undef LTTNG_TRACEPOINT_EVENT
108 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, tstruct, assign, print) \
109 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
116 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
117 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, tstruct, assign, print) \
118 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, \
123 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT
124 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT(template, name, proto, args, print) \
125 LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP(template, name, name, \
126 PARAMS(proto), PARAMS(args), PARAMS(print_))
128 #undef LTTNG_TRACEPOINT_EVENT_FN
129 #define LTTNG_TRACEPOINT_EVENT_FN(name, proto, args, tstruct, \
130 assign, print, reg, unreg) \
131 LTTNG_TRACEPOINT_EVENT_FN_MAP(name, name, PARAMS(proto), PARAMS(args), \
132 PARAMS(tstruct), PARAMS(assign), PARAMS(print), \
133 PARAMS(reg), PARAMS(unreg)) \
135 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
136 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
137 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
139 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
140 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
141 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
143 #undef LTTNG_TRACEPOINT_EVENT_CONDITION
144 #define LTTNG_TRACEPOINT_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
145 LTTNG_TRACEPOINT_EVENT_CONDITION_MAP(name, name, \
153 #undef LTTNG_TRACEPOINT_EVENT_CLASS
154 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
155 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
156 PARAMS(_tstruct), PARAMS(_assign), PARAMS(_print))
158 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
159 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
160 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_tstruct), \
161 PARAMS(_assign), PARAMS(_print))
165 * Stage 1 of the trace events.
167 * Create dummy trace calls for each events, verifying that the LTTng module
168 * instrumentation headers match the kernel arguments. Will be optimized
169 * out by the compiler.
172 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
175 #define TP_PROTO(args...) args
178 #define TP_ARGS(args...) args
180 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
181 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
182 void trace_##_name(_proto);
184 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
185 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
186 void trace_##_name(void);
188 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
191 * Stage 1.1 of the trace events.
193 * Create dummy trace prototypes for each event class, and for each used
194 * template. This will allow checking whether the prototypes from the
195 * class and the instance using the class actually match.
198 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
201 #define TP_PROTO(args...) args
204 #define TP_ARGS(args...) args
206 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
207 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
208 void __event_template_proto___##_template(_proto);
210 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
211 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
212 void __event_template_proto___##_template(void);
214 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
215 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
216 void __event_template_proto___##_name(_proto);
218 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
219 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
220 void __event_template_proto___##_name(void);
222 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
225 * Stage 2 of the trace events.
227 * Create event field type metadata section.
228 * Each event produce an array of fields.
231 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
233 /* Named field types must be defined in lttng-types.h */
236 #define __field_full(_type, _item, _order, _base) \
239 .type = __type_integer(_type, _order, _base, none), \
243 #define __field(_type, _item) \
244 __field_full(_type, _item, __BYTE_ORDER, 10)
247 #define __field_ext(_type, _item, _filter_type) \
248 __field(_type, _item)
251 #define __field_hex(_type, _item) \
252 __field_full(_type, _item, __BYTE_ORDER, 16)
255 #define __field_oct(_type, _item) \
256 __field_full(_type, _item, __BYTE_ORDER, 8)
258 #undef __field_network
259 #define __field_network(_type, _item) \
260 __field_full(_type, _item, __BIG_ENDIAN, 10)
262 #undef __field_network_hex
263 #define __field_network_hex(_type, _item) \
264 __field_full(_type, _item, __BIG_ENDIAN, 16)
266 #undef __array_enc_ext
267 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
272 .atype = atype_array, \
276 .elem_type = __type_integer(_type, _order, _base, _encoding), \
282 #define __array(_type, _item, _length) \
283 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
286 #define __array_text(_type, _item, _length) \
287 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
290 #define __array_hex(_type, _item, _length) \
291 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
293 #undef __dynamic_array_enc_ext
294 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
299 .atype = atype_sequence, \
302 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
303 .elem_type = __type_integer(_type, _order, _base, _encoding), \
308 #undef __dynamic_array_enc_ext_2
309 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
310 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
312 #undef __dynamic_array
313 #define __dynamic_array(_type, _item, _length) \
314 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
316 #undef __dynamic_array_text
317 #define __dynamic_array_text(_type, _item, _length) \
318 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
320 #undef __dynamic_array_hex
321 #define __dynamic_array_hex(_type, _item, _length) \
322 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
324 #undef __dynamic_array_network_hex
325 #define __dynamic_array_network_hex(_type, _item, _length) \
326 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
328 #undef __dynamic_array_network
329 #define __dynamic_array_network(_type, _item, _length) \
330 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
332 #undef __dynamic_array_text_2
333 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
334 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
337 #define __string(_item, _src) \
342 .atype = atype_string, \
343 .u.basic.string.encoding = lttng_encode_UTF8, \
347 #undef __string_from_user
348 #define __string_from_user(_item, _src) \
349 __string(_item, _src)
351 #undef TP_STRUCT__entry
352 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
354 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
355 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
356 static const struct lttng_event_field __event_fields___##_name[] = { \
360 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
361 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
362 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
365 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
368 * Stage 3 of the trace events.
370 * Create probe callback prototypes.
373 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
376 #define TP_PROTO(args...) args
378 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
379 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
380 static void __event_probe__##_name(void *__data, _proto);
382 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
383 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
384 static void __event_probe__##_name(void *__data);
386 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
389 * Stage 3.9 of the trace events.
391 * Create event descriptions.
394 /* Named field types must be defined in lttng-types.h */
396 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
399 #define TP_PROBE_CB(_template) &__event_probe__##_template
402 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
403 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
404 static const struct lttng_event_desc __event_desc___##_map = { \
405 .fields = __event_fields___##_template, \
408 .probe_callback = (void *) TP_PROBE_CB(_template), \
409 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
410 .owner = THIS_MODULE, \
413 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
414 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
415 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
417 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
421 * Stage 4 of the trace events.
423 * Create an array of event description pointers.
426 /* Named field types must be defined in lttng-types.h */
428 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
430 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
431 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
432 &__event_desc___##_map,
434 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
435 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
436 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
438 #define TP_ID1(_token, _system) _token##_system
439 #define TP_ID(_token, _system) TP_ID1(_token, _system)
441 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
442 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
450 * Stage 5 of the trace events.
452 * Create a toplevel descriptor for the whole probe.
455 #define TP_ID1(_token, _system) _token##_system
456 #define TP_ID(_token, _system) TP_ID1(_token, _system)
458 /* non-const because list head will be modified when registered. */
459 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
460 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
461 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
468 * Stage 6 of the trace events.
470 * Create static inline function that calculates event size.
473 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
475 /* Named field types must be defined in lttng-types.h */
478 #define __field_full(_type, _item, _order, _base) \
479 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
480 __event_len += sizeof(_type);
482 #undef __array_enc_ext
483 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
484 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
485 __event_len += sizeof(_type) * (_length);
487 #undef __dynamic_array_enc_ext
488 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
489 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
490 __event_len += sizeof(u32); \
491 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
492 __dynamic_len[__dynamic_len_idx] = (_length); \
493 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
496 #undef __dynamic_array_enc_ext_2
497 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
498 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
499 __event_len += sizeof(u32); \
500 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
501 __dynamic_len[__dynamic_len_idx] = (_length1); \
502 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
503 __dynamic_len_idx++; \
504 __dynamic_len[__dynamic_len_idx] = (_length2); \
505 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
509 #define __string(_item, _src) \
510 __event_len += __dynamic_len[__dynamic_len_idx++] = \
511 strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1;
514 * strlen_user includes \0. If returns 0, it faulted, so we set size to
517 #undef __string_from_user
518 #define __string_from_user(_item, _src) \
519 __event_len += __dynamic_len[__dynamic_len_idx++] = \
520 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
523 #define TP_PROTO(args...) args
525 #undef TP_STRUCT__entry
526 #define TP_STRUCT__entry(args...) args
529 #define TP_locvar(...) __VA_ARGS__
531 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
532 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
533 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
534 void *__tp_locvar, _proto) \
536 size_t __event_len = 0; \
537 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
538 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
541 return __event_len; \
544 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
545 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
546 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
549 size_t __event_len = 0; \
550 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
551 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
554 return __event_len; \
557 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
560 * Stage 7 of the trace events.
562 * Create static inline function that calculates event payload alignment.
565 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
567 /* Named field types must be defined in lttng-types.h */
570 #define __field_full(_type, _item, _order, _base) \
571 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
573 #undef __array_enc_ext
574 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
575 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
577 #undef __dynamic_array_enc_ext
578 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
579 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
580 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
582 #undef __dynamic_array_enc_ext_2
583 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
584 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
587 #define __string(_item, _src)
589 #undef __string_from_user
590 #define __string_from_user(_item, _src)
593 #define TP_PROTO(args...) args
595 #undef TP_STRUCT__entry
596 #define TP_STRUCT__entry(args...) args
599 #define TP_locvar(...) __VA_ARGS__
601 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
602 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
603 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
605 size_t __event_align = 1; \
606 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
609 return __event_align; \
612 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
613 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
614 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
616 size_t __event_align = 1; \
617 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
620 return __event_align; \
623 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
626 * Stage 8 of the trace events.
628 * Create structure declaration that allows the "assign" macros to access the
632 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
634 /* Named field types must be defined in lttng-types.h */
637 #define __field_full(_type, _item, _order, _base) _type _item;
639 #undef __array_enc_ext
640 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
643 #undef __dynamic_array_enc_ext
644 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
647 #undef __dynamic_array_enc_ext_2
648 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
649 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
652 #define __string(_item, _src) char _item;
654 #undef __string_from_user
655 #define __string_from_user(_item, _src) \
656 __string(_item, _src)
658 #undef TP_STRUCT__entry
659 #define TP_STRUCT__entry(args...) args
661 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
662 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
663 struct __event_typemap__##_name { \
667 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
668 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
669 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
671 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
675 * Stage 9 of the trace events.
677 * Create the probe function : call even size calculation and write event data
680 * We use both the field and assignment macros to write the fields in the order
681 * defined in the field declaration. The field declarations control the
682 * execution order, jumping to the appropriate assignment block.
685 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
688 #define __field_full(_type, _item, _order, _base) \
689 goto __assign_##_item; \
692 #undef __array_enc_ext
693 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
694 goto __assign_##_item; \
697 #undef __dynamic_array_enc_ext
698 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
699 goto __assign_##_item##_1; \
700 __end_field_##_item##_1: \
701 goto __assign_##_item##_2; \
702 __end_field_##_item##_2:
704 #undef __dynamic_array_enc_ext_2
705 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
706 goto __assign_##_item##_1; \
707 __end_field_##_item##_1: \
708 goto __assign_##_item##_2; \
709 __end_field_##_item##_2: \
710 goto __assign_##_item##_3; \
711 __end_field_##_item##_3:
714 #define __string(_item, _src) \
715 goto __assign_##_item; \
718 #undef __string_from_user
719 #define __string_from_user(_item, _src) \
720 __string(_item, _src)
723 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
727 #define tp_assign(dest, src) \
730 __typeof__(__typemap.dest) __tmp = (src); \
731 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
732 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
734 goto __end_field_##dest;
736 /* fixed length array memcpy */
738 #define tp_memcpy_gen(write_ops, dest, src, len) \
741 (void) __typemap.dest; \
742 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
743 __chan->ops->write_ops(&__ctx, src, len); \
744 goto __end_field_##dest;
747 #define tp_memcpy(dest, src, len) \
748 tp_memcpy_gen(event_write, dest, src, len)
750 #undef tp_memcpy_from_user
751 #define tp_memcpy_from_user(dest, src, len) \
752 tp_memcpy_gen(event_write_from_user, dest, src, len)
754 /* variable length sequence memcpy */
755 #undef tp_memcpy_dyn_gen
756 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
757 __assign_##dest##_1: \
759 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
760 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
761 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
763 goto __end_field_##dest##_1; \
764 __assign_##dest##_2: \
765 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
766 __chan->ops->write_ops(&__ctx, src, \
767 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
768 goto __end_field_##dest##_2;
770 #undef tp_memcpy_dyn_gen_2
771 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
772 __assign_##dest##_1: \
774 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
775 + __dynamic_len[__dynamic_len_idx + 1]; \
776 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
777 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
779 goto __end_field_##dest##_1; \
780 __assign_##dest##_2: \
781 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
782 __chan->ops->write_ops(&__ctx, src1, \
783 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
784 goto __end_field_##dest##_2; \
785 __assign_##dest##_3: \
786 __chan->ops->write_ops(&__ctx, src2, \
787 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
788 goto __end_field_##dest##_3;
791 #define tp_memcpy_dyn(dest, src) \
792 tp_memcpy_dyn_gen(event_write, dest, src)
794 #undef tp_memcpy_dyn_2
795 #define tp_memcpy_dyn_2(dest, src1, src2) \
796 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
798 #undef tp_memcpy_dyn_from_user
799 #define tp_memcpy_dyn_from_user(dest, src) \
800 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
803 * The string length including the final \0.
805 #undef tp_copy_string_from_user
806 #define tp_copy_string_from_user(dest, src) \
809 (void) __typemap.dest; \
810 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
811 __chan->ops->event_strcpy_from_user(&__ctx, src, \
812 __get_dynamic_array_len(dest)); \
813 goto __end_field_##dest;
816 #define tp_strcpy(dest, src) \
819 (void) __typemap.dest; \
821 const char *__ctf_tmp_string = \
822 ((src) ? (src) : __LTTNG_NULL_STRING); \
823 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
824 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, __get_dynamic_array_len(dest)); \
826 goto __end_field_##dest;
828 /* Named field types must be defined in lttng-types.h */
831 #define __get_str(field) field
833 #undef __get_dynamic_array
834 #define __get_dynamic_array(field) field
836 /* Beware: this get len actually consumes the len value */
837 #undef __get_dynamic_array_len
838 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
841 #define TP_PROTO(args...) args
844 #define TP_ARGS(args...) args
846 #undef TP_STRUCT__entry
847 #define TP_STRUCT__entry(args...) args
849 #undef TP_fast_assign
850 #define TP_fast_assign(args...) args
853 #define TP_locvar(...) __VA_ARGS__
856 #define TP_code(...) __VA_ARGS__
859 * For state dump, check that "session" argument (mandatory) matches the
860 * session this event belongs to. Ensures that we write state dump data only
861 * into the started session, not into all sessions.
863 #ifdef TP_SESSION_CHECK
864 #define _TP_SESSION_CHECK(session, csession) (session == csession)
865 #else /* TP_SESSION_CHECK */
866 #define _TP_SESSION_CHECK(session, csession) 1
867 #endif /* TP_SESSION_CHECK */
870 * __dynamic_len array length is twice the number of fields due to
871 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
872 * worse case, needing 2 entries per field.
874 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
875 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
876 static void __event_probe__##_name(void *__data, _proto) \
878 struct probe_local_vars { _locvar }; \
879 struct lttng_event *__event = __data; \
880 struct lttng_channel *__chan = __event->chan; \
881 struct lib_ring_buffer_ctx __ctx; \
882 size_t __event_len, __event_align; \
883 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
884 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
885 struct __event_typemap__##_name __typemap __attribute__((unused)); \
887 struct probe_local_vars __tp_locvar; \
888 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
891 if (!_TP_SESSION_CHECK(session, __chan->session)) \
893 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
895 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
897 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
900 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
902 __event_align = __event_get_align__##_name(tp_locvar, _args); \
903 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
904 __event_align, -1); \
905 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
908 /* Control code (field ordering) */ \
910 __chan->ops->event_commit(&__ctx); \
912 /* Copy code, steered by control code */ \
916 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
917 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
918 static void __event_probe__##_name(void *__data) \
920 struct probe_local_vars { _locvar }; \
921 struct lttng_event *__event = __data; \
922 struct lttng_channel *__chan = __event->chan; \
923 struct lib_ring_buffer_ctx __ctx; \
924 size_t __event_len, __event_align; \
925 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
926 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
927 struct __event_typemap__##_name __typemap __attribute__((unused)); \
929 struct probe_local_vars __tp_locvar; \
930 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
933 if (!_TP_SESSION_CHECK(session, __chan->session)) \
935 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
937 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
939 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
942 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
943 __event_align = __event_get_align__##_name(tp_locvar); \
944 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
945 __event_align, -1); \
946 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
949 /* Control code (field ordering) */ \
951 __chan->ops->event_commit(&__ctx); \
953 /* Copy code, steered by control code */ \
957 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
960 * Stage 10 of the trace events.
962 * Register/unregister probes at module load/unload.
965 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
967 #define TP_ID1(_token, _system) _token##_system
968 #define TP_ID(_token, _system) TP_ID1(_token, _system)
969 #define module_init_eval1(_token, _system) module_init(_token##_system)
970 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
971 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
972 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
974 #ifndef TP_MODULE_NOINIT
975 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
977 wrapper_vmalloc_sync_all();
978 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
981 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
983 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
986 #ifndef TP_MODULE_NOAUTOLOAD
987 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
988 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
993 #undef module_init_eval
994 #undef module_exit_eval
This page took 0.04861 seconds and 4 git commands to generate.