616850f4d680e1f2e90771e6e45a656a6ee6c344
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"
32 * Macro declarations used for all stages.
36 * LTTng name mapping macros. LTTng remaps some of the kernel events to
37 * enforce name-spacing.
39 #undef LTTNG_TRACEPOINT_EVENT_MAP
40 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, tstruct, assign, print) \
41 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, tstruct, assign, print) \
51 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
55 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
57 #undef LTTNG_TRACEPOINT_EVENT_CODE
58 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, tstruct, assign, print) \
59 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(name, \
67 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(name, name, name, PARAMS(proto), PARAMS(args))
70 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP
71 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP(template, name, map, proto, args, print) \
72 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, map, PARAMS(proto), PARAMS(args))
74 /* Callbacks are meaningless to LTTng. */
75 #undef LTTNG_TRACEPOINT_EVENT_FN_MAP
76 #define LTTNG_TRACEPOINT_EVENT_FN_MAP(name, map, proto, args, tstruct, \
77 assign, print, reg, unreg) \
78 LTTNG_TRACEPOINT_EVENT_MAP(name, map, PARAMS(proto), PARAMS(args), \
79 PARAMS(tstruct), PARAMS(assign), PARAMS(print))
81 #undef LTTNG_TRACEPOINT_EVENT_CONDITION_MAP
82 #define LTTNG_TRACEPOINT_EVENT_CONDITION_MAP(name, map, proto, args, cond, tstruct, assign, print) \
83 LTTNG_TRACEPOINT_EVENT_MAP(name, map, \
91 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
92 * handlers for events. That is, if all events have the same parameters
93 * and just have distinct trace points. Each tracepoint can be defined
94 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
95 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
97 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
101 #undef LTTNG_TRACEPOINT_EVENT
102 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, tstruct, assign, print) \
103 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
110 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
111 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, tstruct, assign, print) \
112 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, \
117 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT
118 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT(template, name, proto, args, print) \
119 LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP(template, name, name, \
120 PARAMS(proto), PARAMS(args), PARAMS(print_))
122 #undef LTTNG_TRACEPOINT_EVENT_FN
123 #define LTTNG_TRACEPOINT_EVENT_FN(name, proto, args, tstruct, \
124 assign, print, reg, unreg) \
125 LTTNG_TRACEPOINT_EVENT_FN_MAP(name, name, PARAMS(proto), PARAMS(args), \
126 PARAMS(tstruct), PARAMS(assign), PARAMS(print), \
127 PARAMS(reg), PARAMS(unreg)) \
129 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
130 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
131 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
133 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
134 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
135 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
137 #undef LTTNG_TRACEPOINT_EVENT_CONDITION
138 #define LTTNG_TRACEPOINT_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
139 LTTNG_TRACEPOINT_EVENT_CONDITION_MAP(name, name, \
147 #undef LTTNG_TRACEPOINT_EVENT_CLASS
148 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
149 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
150 PARAMS(_tstruct), PARAMS(_assign), PARAMS(_print))
152 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
153 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
154 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_tstruct), \
155 PARAMS(_assign), PARAMS(_print))
159 * Stage 1 of the trace events.
161 * Create dummy trace calls for each events, verifying that the LTTng module
162 * instrumentation headers match the kernel arguments. Will be optimized
163 * out by the compiler.
166 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
169 #define TP_PROTO(args...) args
172 #define TP_ARGS(args...) args
174 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
175 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
176 void trace_##_name(_proto);
178 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
179 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
180 void trace_##_name(void *__data);
182 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
185 * Stage 2 of the trace events.
187 * Create event field type metadata section.
188 * Each event produce an array of fields.
191 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
193 /* Named field types must be defined in lttng-types.h */
196 #define __field_full(_type, _item, _order, _base) \
199 .type = __type_integer(_type, _order, _base, none), \
203 #define __field(_type, _item) \
204 __field_full(_type, _item, __BYTE_ORDER, 10)
207 #define __field_ext(_type, _item, _filter_type) \
208 __field(_type, _item)
211 #define __field_hex(_type, _item) \
212 __field_full(_type, _item, __BYTE_ORDER, 16)
215 #define __field_oct(_type, _item) \
216 __field_full(_type, _item, __BYTE_ORDER, 8)
218 #undef __field_network
219 #define __field_network(_type, _item) \
220 __field_full(_type, _item, __BIG_ENDIAN, 10)
222 #undef __field_network_hex
223 #define __field_network_hex(_type, _item) \
224 __field_full(_type, _item, __BIG_ENDIAN, 16)
226 #undef __array_enc_ext
227 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
232 .atype = atype_array, \
236 .elem_type = __type_integer(_type, _order, _base, _encoding), \
242 #define __array(_type, _item, _length) \
243 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
246 #define __array_text(_type, _item, _length) \
247 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
250 #define __array_hex(_type, _item, _length) \
251 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
253 #undef __dynamic_array_enc_ext
254 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
259 .atype = atype_sequence, \
262 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
263 .elem_type = __type_integer(_type, _order, _base, _encoding), \
268 #undef __dynamic_array_enc_ext_2
269 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
270 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
272 #undef __dynamic_array
273 #define __dynamic_array(_type, _item, _length) \
274 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
276 #undef __dynamic_array_text
277 #define __dynamic_array_text(_type, _item, _length) \
278 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
280 #undef __dynamic_array_hex
281 #define __dynamic_array_hex(_type, _item, _length) \
282 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
284 #undef __dynamic_array_network_hex
285 #define __dynamic_array_network_hex(_type, _item, _length) \
286 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
288 #undef __dynamic_array_network
289 #define __dynamic_array_network(_type, _item, _length) \
290 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
292 #undef __dynamic_array_text_2
293 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
294 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
297 #define __string(_item, _src) \
302 .atype = atype_string, \
303 .u.basic.string.encoding = lttng_encode_UTF8, \
307 #undef __string_from_user
308 #define __string_from_user(_item, _src) \
309 __string(_item, _src)
311 #undef TP_STRUCT__entry
312 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
314 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
315 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
316 static const struct lttng_event_field __event_fields___##_name[] = { \
320 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
321 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
322 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
325 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
328 * Stage 3 of the trace events.
330 * Create probe callback prototypes.
333 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
336 #define TP_PROTO(args...) args
338 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
339 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
340 static void __event_probe__##_name(void *__data, _proto);
342 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
343 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
344 static void __event_probe__##_name(void *__data);
346 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
349 * Stage 3.9 of the trace events.
351 * Create event descriptions.
354 /* Named field types must be defined in lttng-types.h */
356 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
359 #define TP_PROBE_CB(_template) &__event_probe__##_template
362 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
363 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
364 static const struct lttng_event_desc __event_desc___##_map = { \
365 .fields = __event_fields___##_template, \
368 .probe_callback = (void *) TP_PROBE_CB(_template), \
369 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
370 .owner = THIS_MODULE, \
373 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
374 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
375 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
377 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
381 * Stage 4 of the trace events.
383 * Create an array of event description pointers.
386 /* Named field types must be defined in lttng-types.h */
388 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
390 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
391 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
392 &__event_desc___##_map,
394 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
395 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
396 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
398 #define TP_ID1(_token, _system) _token##_system
399 #define TP_ID(_token, _system) TP_ID1(_token, _system)
401 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
402 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
410 * Stage 5 of the trace events.
412 * Create a toplevel descriptor for the whole probe.
415 #define TP_ID1(_token, _system) _token##_system
416 #define TP_ID(_token, _system) TP_ID1(_token, _system)
418 /* non-const because list head will be modified when registered. */
419 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
420 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
421 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
428 * Stage 6 of the trace events.
430 * Create static inline function that calculates event size.
433 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
435 /* Named field types must be defined in lttng-types.h */
438 #define __field_full(_type, _item, _order, _base) \
439 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
440 __event_len += sizeof(_type);
442 #undef __array_enc_ext
443 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
444 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
445 __event_len += sizeof(_type) * (_length);
447 #undef __dynamic_array_enc_ext
448 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
449 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
450 __event_len += sizeof(u32); \
451 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
452 __dynamic_len[__dynamic_len_idx] = (_length); \
453 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
456 #undef __dynamic_array_enc_ext_2
457 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
458 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
459 __event_len += sizeof(u32); \
460 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
461 __dynamic_len[__dynamic_len_idx] = (_length1); \
462 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
463 __dynamic_len_idx++; \
464 __dynamic_len[__dynamic_len_idx] = (_length2); \
465 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
469 #define __string(_item, _src) \
470 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
473 * strlen_user includes \0. If returns 0, it faulted, so we set size to
476 #undef __string_from_user
477 #define __string_from_user(_item, _src) \
478 __event_len += __dynamic_len[__dynamic_len_idx++] = \
479 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
482 #define TP_PROTO(args...) args
484 #undef TP_STRUCT__entry
485 #define TP_STRUCT__entry(args...) args
488 #define TP_locvar(...) __VA_ARGS__
490 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
491 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
492 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
493 void *__tp_locvar, _proto) \
495 size_t __event_len = 0; \
496 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
497 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
500 return __event_len; \
503 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
504 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
505 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
508 size_t __event_len = 0; \
509 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
510 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
513 return __event_len; \
516 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
519 * Stage 7 of the trace events.
521 * Create static inline function that calculates event payload alignment.
524 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
526 /* Named field types must be defined in lttng-types.h */
529 #define __field_full(_type, _item, _order, _base) \
530 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
532 #undef __array_enc_ext
533 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
534 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
536 #undef __dynamic_array_enc_ext
537 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
538 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
539 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
541 #undef __dynamic_array_enc_ext_2
542 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
543 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
546 #define __string(_item, _src)
548 #undef __string_from_user
549 #define __string_from_user(_item, _src)
552 #define TP_PROTO(args...) args
554 #undef TP_STRUCT__entry
555 #define TP_STRUCT__entry(args...) args
558 #define TP_locvar(...) __VA_ARGS__
560 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
561 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
562 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
564 size_t __event_align = 1; \
565 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
568 return __event_align; \
571 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
572 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
573 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
575 size_t __event_align = 1; \
576 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
579 return __event_align; \
582 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
585 * Stage 8 of the trace events.
587 * Create structure declaration that allows the "assign" macros to access the
591 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
593 /* Named field types must be defined in lttng-types.h */
596 #define __field_full(_type, _item, _order, _base) _type _item;
598 #undef __array_enc_ext
599 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
602 #undef __dynamic_array_enc_ext
603 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
606 #undef __dynamic_array_enc_ext_2
607 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
608 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
611 #define __string(_item, _src) char _item;
613 #undef __string_from_user
614 #define __string_from_user(_item, _src) \
615 __string(_item, _src)
617 #undef TP_STRUCT__entry
618 #define TP_STRUCT__entry(args...) args
620 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
621 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
622 struct __event_typemap__##_name { \
626 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
627 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
628 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
630 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
634 * Stage 9 of the trace events.
636 * Create the probe function : call even size calculation and write event data
639 * We use both the field and assignment macros to write the fields in the order
640 * defined in the field declaration. The field declarations control the
641 * execution order, jumping to the appropriate assignment block.
644 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
647 #define __field_full(_type, _item, _order, _base) \
648 goto __assign_##_item; \
651 #undef __array_enc_ext
652 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
653 goto __assign_##_item; \
656 #undef __dynamic_array_enc_ext
657 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
658 goto __assign_##_item##_1; \
659 __end_field_##_item##_1: \
660 goto __assign_##_item##_2; \
661 __end_field_##_item##_2:
663 #undef __dynamic_array_enc_ext_2
664 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
665 goto __assign_##_item##_1; \
666 __end_field_##_item##_1: \
667 goto __assign_##_item##_2; \
668 __end_field_##_item##_2: \
669 goto __assign_##_item##_3; \
670 __end_field_##_item##_3:
673 #define __string(_item, _src) \
674 goto __assign_##_item; \
677 #undef __string_from_user
678 #define __string_from_user(_item, _src) \
679 __string(_item, _src)
682 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
686 #define tp_assign(dest, src) \
689 __typeof__(__typemap.dest) __tmp = (src); \
690 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
691 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
693 goto __end_field_##dest;
695 /* fixed length array memcpy */
697 #define tp_memcpy_gen(write_ops, dest, src, len) \
700 (void) __typemap.dest; \
701 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
702 __chan->ops->write_ops(&__ctx, src, len); \
703 goto __end_field_##dest;
706 #define tp_memcpy(dest, src, len) \
707 tp_memcpy_gen(event_write, dest, src, len)
709 #undef tp_memcpy_from_user
710 #define tp_memcpy_from_user(dest, src, len) \
711 tp_memcpy_gen(event_write_from_user, dest, src, len)
713 /* variable length sequence memcpy */
714 #undef tp_memcpy_dyn_gen
715 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
716 __assign_##dest##_1: \
718 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
719 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
720 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
722 goto __end_field_##dest##_1; \
723 __assign_##dest##_2: \
724 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
725 __chan->ops->write_ops(&__ctx, src, \
726 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
727 goto __end_field_##dest##_2;
729 #undef tp_memcpy_dyn_gen_2
730 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
731 __assign_##dest##_1: \
733 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
734 + __dynamic_len[__dynamic_len_idx + 1]; \
735 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
736 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
738 goto __end_field_##dest##_1; \
739 __assign_##dest##_2: \
740 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
741 __chan->ops->write_ops(&__ctx, src1, \
742 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
743 goto __end_field_##dest##_2; \
744 __assign_##dest##_3: \
745 __chan->ops->write_ops(&__ctx, src2, \
746 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
747 goto __end_field_##dest##_3;
750 #define tp_memcpy_dyn(dest, src) \
751 tp_memcpy_dyn_gen(event_write, dest, src)
753 #undef tp_memcpy_dyn_2
754 #define tp_memcpy_dyn_2(dest, src1, src2) \
755 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
757 #undef tp_memcpy_dyn_from_user
758 #define tp_memcpy_dyn_from_user(dest, src) \
759 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
762 * The string length including the final \0.
764 #undef tp_copy_string_from_user
765 #define tp_copy_string_from_user(dest, src) \
768 (void) __typemap.dest; \
769 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
770 __chan->ops->event_strcpy_from_user(&__ctx, src, \
771 __get_dynamic_array_len(dest)); \
772 goto __end_field_##dest;
775 #define tp_strcpy(dest, src) \
778 (void) __typemap.dest; \
779 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
780 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
781 goto __end_field_##dest;
783 /* Named field types must be defined in lttng-types.h */
786 #define __get_str(field) field
788 #undef __get_dynamic_array
789 #define __get_dynamic_array(field) field
791 /* Beware: this get len actually consumes the len value */
792 #undef __get_dynamic_array_len
793 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
796 #define TP_PROTO(args...) args
799 #define TP_ARGS(args...) args
801 #undef TP_STRUCT__entry
802 #define TP_STRUCT__entry(args...) args
804 #undef TP_fast_assign
805 #define TP_fast_assign(args...) args
808 #define TP_locvar(...) __VA_ARGS__
811 #define TP_code(...) __VA_ARGS__
814 * For state dump, check that "session" argument (mandatory) matches the
815 * session this event belongs to. Ensures that we write state dump data only
816 * into the started session, not into all sessions.
818 #ifdef TP_SESSION_CHECK
819 #define _TP_SESSION_CHECK(session, csession) (session == csession)
820 #else /* TP_SESSION_CHECK */
821 #define _TP_SESSION_CHECK(session, csession) 1
822 #endif /* TP_SESSION_CHECK */
825 * __dynamic_len array length is twice the number of fields due to
826 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
827 * worse case, needing 2 entries per field.
829 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
830 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
831 static void __event_probe__##_name(void *__data, _proto) \
833 struct probe_local_vars { _locvar }; \
834 struct lttng_event *__event = __data; \
835 struct lttng_channel *__chan = __event->chan; \
836 struct lib_ring_buffer_ctx __ctx; \
837 size_t __event_len, __event_align; \
838 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
839 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
840 struct __event_typemap__##_name __typemap __attribute__((unused)); \
842 struct probe_local_vars __tp_locvar; \
843 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
846 if (!_TP_SESSION_CHECK(session, __chan->session)) \
848 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
850 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
852 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
855 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
857 __event_align = __event_get_align__##_name(tp_locvar, _args); \
858 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
859 __event_align, -1); \
860 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
863 /* Control code (field ordering) */ \
865 __chan->ops->event_commit(&__ctx); \
867 /* Copy code, steered by control code */ \
871 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
872 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
873 static void __event_probe__##_name(void *__data) \
875 struct probe_local_vars { _locvar }; \
876 struct lttng_event *__event = __data; \
877 struct lttng_channel *__chan = __event->chan; \
878 struct lib_ring_buffer_ctx __ctx; \
879 size_t __event_len, __event_align; \
880 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
881 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
882 struct __event_typemap__##_name __typemap __attribute__((unused)); \
884 struct probe_local_vars __tp_locvar; \
885 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
888 if (!_TP_SESSION_CHECK(session, __chan->session)) \
890 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
892 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
894 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
897 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
898 __event_align = __event_get_align__##_name(tp_locvar); \
899 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
900 __event_align, -1); \
901 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
904 /* Control code (field ordering) */ \
906 __chan->ops->event_commit(&__ctx); \
908 /* Copy code, steered by control code */ \
912 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
915 * Stage 10 of the trace events.
917 * Register/unregister probes at module load/unload.
920 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
922 #define TP_ID1(_token, _system) _token##_system
923 #define TP_ID(_token, _system) TP_ID1(_token, _system)
924 #define module_init_eval1(_token, _system) module_init(_token##_system)
925 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
926 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
927 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
929 #ifndef TP_MODULE_NOINIT
930 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
932 wrapper_vmalloc_sync_all();
933 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
936 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
938 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
941 #ifndef TP_MODULE_NOAUTOLOAD
942 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
943 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
948 #undef module_init_eval
949 #undef module_exit_eval
This page took 0.051957 seconds and 4 git commands to generate.