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 TRACE_EVENT_MAP
40 #define TRACE_EVENT_MAP(name, map, proto, args, tstruct, assign, print) \
41 DECLARE_EVENT_CLASS(map, \
47 DEFINE_EVENT_MAP(map, name, map, PARAMS(proto), PARAMS(args))
49 #undef TRACE_EVENT_MAP_NOARGS
50 #define TRACE_EVENT_MAP_NOARGS(name, map, tstruct, assign, print) \
51 DECLARE_EVENT_CLASS_NOARGS(map, \
55 DEFINE_EVENT_MAP_NOARGS(map, name, map)
57 #undef LTTNG_TRACE_EVENT
58 #define LTTNG_TRACE_EVENT(name, proto, args, _locvar, _code, tstruct, assign, print) \
59 LTTNG_DECLARE_EVENT_CLASS(name, \
67 DEFINE_EVENT_MAP(name, name, name, PARAMS(proto), PARAMS(args))
69 #undef DEFINE_EVENT_PRINT_MAP
70 #define DEFINE_EVENT_PRINT_MAP(template, name, map, proto, args, print) \
71 DEFINE_EVENT_MAP(template, name, map, PARAMS(proto), PARAMS(args))
73 /* Callbacks are meaningless to LTTng. */
74 #undef TRACE_EVENT_FN_MAP
75 #define TRACE_EVENT_FN_MAP(name, map, proto, args, tstruct, \
76 assign, print, reg, unreg) \
77 TRACE_EVENT_MAP(name, map, PARAMS(proto), PARAMS(args), \
78 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
80 #undef TRACE_EVENT_CONDITION_MAP
81 #define TRACE_EVENT_CONDITION_MAP(name, map, proto, args, cond, tstruct, assign, print) \
82 TRACE_EVENT_MAP(name, map, \
90 * DECLARE_EVENT_CLASS can be used to add a generic function
91 * handlers for events. That is, if all events have the same
92 * parameters and just have distinct trace points.
93 * Each tracepoint can be defined with DEFINE_EVENT and that
94 * will map the DECLARE_EVENT_CLASS to the tracepoint.
96 * TRACE_EVENT is a one to one mapping between tracepoint and template.
100 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
101 TRACE_EVENT_MAP(name, name, \
108 #undef TRACE_EVENT_NOARGS
109 #define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \
110 TRACE_EVENT_MAP_NOARGS(name, name, \
115 #undef DEFINE_EVENT_PRINT
116 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
117 DEFINE_EVENT_PRINT_MAP(template, name, name, \
118 PARAMS(proto), PARAMS(args), PARAMS(print_))
120 #undef TRACE_EVENT_FN
121 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
122 assign, print, reg, unreg) \
123 TRACE_EVENT_FN_MAP(name, name, PARAMS(proto), PARAMS(args), \
124 PARAMS(tstruct), PARAMS(assign), PARAMS(print), \
125 PARAMS(reg), PARAMS(unreg)) \
128 #define DEFINE_EVENT(template, name, proto, args) \
129 DEFINE_EVENT_MAP(template, name, name, PARAMS(proto), PARAMS(args))
131 #undef DEFINE_EVENT_NOARGS
132 #define DEFINE_EVENT_NOARGS(template, name) \
133 DEFINE_EVENT_MAP_NOARGS(template, name, name)
135 #undef TRACE_EVENT_CONDITION
136 #define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
137 TRACE_EVENT_CONDITION_MAP(name, name, \
145 #undef DECLARE_EVENT_CLASS
146 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
147 LTTNG_DECLARE_EVENT_CLASS(_name, PARAMS(_proto), PARAMS(_args), , , \
148 PARAMS(_tstruct), PARAMS(_assign), PARAMS(_print))
150 #undef DECLARE_EVENT_CLASS_NOARGS
151 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
152 LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, , , PARAMS(_tstruct), \
153 PARAMS(_assign), PARAMS(_print))
157 * Stage 1 of the trace events.
159 * Create dummy trace calls for each events, verifying that the LTTng module
160 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
164 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
167 #define TP_PROTO(args...) args
170 #define TP_ARGS(args...) args
172 #undef DEFINE_EVENT_MAP
173 #define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
174 void trace_##_name(_proto);
176 #undef DEFINE_EVENT_MAP_NOARGS
177 #define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
178 void trace_##_name(void *__data);
180 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
183 * Stage 2 of the trace events.
185 * Create event field type metadata section.
186 * Each event produce an array of fields.
189 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
191 /* Named field types must be defined in lttng-types.h */
194 #define __field_full(_type, _item, _order, _base) \
197 .type = __type_integer(_type, _order, _base, none), \
201 #define __field(_type, _item) \
202 __field_full(_type, _item, __BYTE_ORDER, 10)
205 #define __field_ext(_type, _item, _filter_type) \
206 __field(_type, _item)
209 #define __field_hex(_type, _item) \
210 __field_full(_type, _item, __BYTE_ORDER, 16)
213 #define __field_oct(_type, _item) \
214 __field_full(_type, _item, __BYTE_ORDER, 8)
216 #undef __field_network
217 #define __field_network(_type, _item) \
218 __field_full(_type, _item, __BIG_ENDIAN, 10)
220 #undef __field_network_hex
221 #define __field_network_hex(_type, _item) \
222 __field_full(_type, _item, __BIG_ENDIAN, 16)
224 #undef __array_enc_ext
225 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
230 .atype = atype_array, \
234 .elem_type = __type_integer(_type, _order, _base, _encoding), \
240 #define __array(_type, _item, _length) \
241 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
244 #define __array_text(_type, _item, _length) \
245 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
248 #define __array_hex(_type, _item, _length) \
249 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
251 #undef __dynamic_array_enc_ext
252 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
257 .atype = atype_sequence, \
260 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
261 .elem_type = __type_integer(_type, _order, _base, _encoding), \
266 #undef __dynamic_array_enc_ext_2
267 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
268 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
270 #undef __dynamic_array
271 #define __dynamic_array(_type, _item, _length) \
272 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
274 #undef __dynamic_array_text
275 #define __dynamic_array_text(_type, _item, _length) \
276 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
278 #undef __dynamic_array_hex
279 #define __dynamic_array_hex(_type, _item, _length) \
280 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
282 #undef __dynamic_array_network_hex
283 #define __dynamic_array_network_hex(_type, _item, _length) \
284 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
286 #undef __dynamic_array_network
287 #define __dynamic_array_network(_type, _item, _length) \
288 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
290 #undef __dynamic_array_text_2
291 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
292 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
295 #define __string(_item, _src) \
300 .atype = atype_string, \
301 .u.basic.string.encoding = lttng_encode_UTF8, \
305 #undef __string_from_user
306 #define __string_from_user(_item, _src) \
307 __string(_item, _src)
309 #undef TP_STRUCT__entry
310 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
312 #undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
313 #define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
314 static const struct lttng_event_field __event_fields___##_name[] = { \
318 #undef LTTNG_DECLARE_EVENT_CLASS
319 #define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
320 LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
323 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
326 * Stage 3 of the trace events.
328 * Create probe callback prototypes.
331 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
334 #define TP_PROTO(args...) args
336 #undef LTTNG_DECLARE_EVENT_CLASS
337 #define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
338 static void __event_probe__##_name(void *__data, _proto);
340 #undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
341 #define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
342 static void __event_probe__##_name(void *__data);
344 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
347 * Stage 3.9 of the trace events.
349 * Create event descriptions.
352 /* Named field types must be defined in lttng-types.h */
354 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
357 #define TP_PROBE_CB(_template) &__event_probe__##_template
360 #undef DEFINE_EVENT_MAP_NOARGS
361 #define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
362 static const struct lttng_event_desc __event_desc___##_map = { \
363 .fields = __event_fields___##_template, \
366 .probe_callback = (void *) TP_PROBE_CB(_template), \
367 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
368 .owner = THIS_MODULE, \
371 #undef DEFINE_EVENT_MAP
372 #define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
373 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
375 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
379 * Stage 4 of the trace events.
381 * Create an array of event description pointers.
384 /* Named field types must be defined in lttng-types.h */
386 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
388 #undef DEFINE_EVENT_MAP_NOARGS
389 #define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
390 &__event_desc___##_map,
392 #undef DEFINE_EVENT_MAP
393 #define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
394 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
396 #define TP_ID1(_token, _system) _token##_system
397 #define TP_ID(_token, _system) TP_ID1(_token, _system)
399 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
400 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
408 * Stage 5 of the trace events.
410 * Create a toplevel descriptor for the whole probe.
413 #define TP_ID1(_token, _system) _token##_system
414 #define TP_ID(_token, _system) TP_ID1(_token, _system)
416 /* non-const because list head will be modified when registered. */
417 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
418 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
419 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
426 * Stage 6 of the trace events.
428 * Create static inline function that calculates event size.
431 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
433 /* Named field types must be defined in lttng-types.h */
436 #define __field_full(_type, _item, _order, _base) \
437 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
438 __event_len += sizeof(_type);
440 #undef __array_enc_ext
441 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
442 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
443 __event_len += sizeof(_type) * (_length);
445 #undef __dynamic_array_enc_ext
446 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
447 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
448 __event_len += sizeof(u32); \
449 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
450 __dynamic_len[__dynamic_len_idx] = (_length); \
451 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
454 #undef __dynamic_array_enc_ext_2
455 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
456 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
457 __event_len += sizeof(u32); \
458 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
459 __dynamic_len[__dynamic_len_idx] = (_length1); \
460 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
461 __dynamic_len_idx++; \
462 __dynamic_len[__dynamic_len_idx] = (_length2); \
463 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
467 #define __string(_item, _src) \
468 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
471 * strlen_user includes \0. If returns 0, it faulted, so we set size to
474 #undef __string_from_user
475 #define __string_from_user(_item, _src) \
476 __event_len += __dynamic_len[__dynamic_len_idx++] = \
477 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
480 #define TP_PROTO(args...) args
482 #undef TP_STRUCT__entry
483 #define TP_STRUCT__entry(args...) args
486 #define TP_locvar(...) __VA_ARGS__
488 #undef LTTNG_DECLARE_EVENT_CLASS
489 #define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
490 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
491 void *__tp_locvar, _proto) \
493 size_t __event_len = 0; \
494 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
495 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
498 return __event_len; \
501 #undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
502 #define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
503 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
506 size_t __event_len = 0; \
507 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
508 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
511 return __event_len; \
514 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
517 * Stage 7 of the trace events.
519 * Create static inline function that calculates event payload alignment.
522 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
524 /* Named field types must be defined in lttng-types.h */
527 #define __field_full(_type, _item, _order, _base) \
528 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
530 #undef __array_enc_ext
531 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
532 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
534 #undef __dynamic_array_enc_ext
535 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
536 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
537 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
539 #undef __dynamic_array_enc_ext_2
540 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
541 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
544 #define __string(_item, _src)
546 #undef __string_from_user
547 #define __string_from_user(_item, _src)
550 #define TP_PROTO(args...) args
552 #undef TP_STRUCT__entry
553 #define TP_STRUCT__entry(args...) args
556 #define TP_locvar(...) __VA_ARGS__
558 #undef LTTNG_DECLARE_EVENT_CLASS
559 #define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
560 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
562 size_t __event_align = 1; \
563 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
566 return __event_align; \
569 #undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
570 #define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
571 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
573 size_t __event_align = 1; \
574 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
577 return __event_align; \
580 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
583 * Stage 8 of the trace events.
585 * Create structure declaration that allows the "assign" macros to access the
589 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
591 /* Named field types must be defined in lttng-types.h */
594 #define __field_full(_type, _item, _order, _base) _type _item;
596 #undef __array_enc_ext
597 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
600 #undef __dynamic_array_enc_ext
601 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
604 #undef __dynamic_array_enc_ext_2
605 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
606 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
609 #define __string(_item, _src) char _item;
611 #undef __string_from_user
612 #define __string_from_user(_item, _src) \
613 __string(_item, _src)
615 #undef TP_STRUCT__entry
616 #define TP_STRUCT__entry(args...) args
618 #undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
619 #define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
620 struct __event_typemap__##_name { \
624 #undef LTTNG_DECLARE_EVENT_CLASS
625 #define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
626 LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
628 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
632 * Stage 9 of the trace events.
634 * Create the probe function : call even size calculation and write event data
637 * We use both the field and assignment macros to write the fields in the order
638 * defined in the field declaration. The field declarations control the
639 * execution order, jumping to the appropriate assignment block.
642 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
645 #define __field_full(_type, _item, _order, _base) \
646 goto __assign_##_item; \
649 #undef __array_enc_ext
650 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
651 goto __assign_##_item; \
654 #undef __dynamic_array_enc_ext
655 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
656 goto __assign_##_item##_1; \
657 __end_field_##_item##_1: \
658 goto __assign_##_item##_2; \
659 __end_field_##_item##_2:
661 #undef __dynamic_array_enc_ext_2
662 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
663 goto __assign_##_item##_1; \
664 __end_field_##_item##_1: \
665 goto __assign_##_item##_2; \
666 __end_field_##_item##_2: \
667 goto __assign_##_item##_3; \
668 __end_field_##_item##_3:
671 #define __string(_item, _src) \
672 goto __assign_##_item; \
675 #undef __string_from_user
676 #define __string_from_user(_item, _src) \
677 __string(_item, _src)
680 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
684 #define tp_assign(dest, src) \
687 __typeof__(__typemap.dest) __tmp = (src); \
688 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
689 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
691 goto __end_field_##dest;
693 /* fixed length array memcpy */
695 #define tp_memcpy_gen(write_ops, dest, src, len) \
698 (void) __typemap.dest; \
699 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
700 __chan->ops->write_ops(&__ctx, src, len); \
701 goto __end_field_##dest;
704 #define tp_memcpy(dest, src, len) \
705 tp_memcpy_gen(event_write, dest, src, len)
707 #undef tp_memcpy_from_user
708 #define tp_memcpy_from_user(dest, src, len) \
709 tp_memcpy_gen(event_write_from_user, dest, src, len)
711 /* variable length sequence memcpy */
712 #undef tp_memcpy_dyn_gen
713 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
714 __assign_##dest##_1: \
716 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
717 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
718 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
720 goto __end_field_##dest##_1; \
721 __assign_##dest##_2: \
722 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
723 __chan->ops->write_ops(&__ctx, src, \
724 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
725 goto __end_field_##dest##_2;
727 #undef tp_memcpy_dyn_gen_2
728 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
729 __assign_##dest##_1: \
731 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
732 + __dynamic_len[__dynamic_len_idx + 1]; \
733 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
734 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
736 goto __end_field_##dest##_1; \
737 __assign_##dest##_2: \
738 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
739 __chan->ops->write_ops(&__ctx, src1, \
740 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
741 goto __end_field_##dest##_2; \
742 __assign_##dest##_3: \
743 __chan->ops->write_ops(&__ctx, src2, \
744 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
745 goto __end_field_##dest##_3;
748 #define tp_memcpy_dyn(dest, src) \
749 tp_memcpy_dyn_gen(event_write, dest, src)
751 #undef tp_memcpy_dyn_2
752 #define tp_memcpy_dyn_2(dest, src1, src2) \
753 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
755 #undef tp_memcpy_dyn_from_user
756 #define tp_memcpy_dyn_from_user(dest, src) \
757 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
760 * The string length including the final \0.
762 #undef tp_copy_string_from_user
763 #define tp_copy_string_from_user(dest, src) \
766 (void) __typemap.dest; \
767 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
768 __chan->ops->event_strcpy_from_user(&__ctx, src, \
769 __get_dynamic_array_len(dest)); \
770 goto __end_field_##dest;
773 #define tp_strcpy(dest, src) \
776 (void) __typemap.dest; \
777 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
778 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
779 goto __end_field_##dest;
781 /* Named field types must be defined in lttng-types.h */
784 #define __get_str(field) field
786 #undef __get_dynamic_array
787 #define __get_dynamic_array(field) field
789 /* Beware: this get len actually consumes the len value */
790 #undef __get_dynamic_array_len
791 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
794 #define TP_PROTO(args...) args
797 #define TP_ARGS(args...) args
799 #undef TP_STRUCT__entry
800 #define TP_STRUCT__entry(args...) args
802 #undef TP_fast_assign
803 #define TP_fast_assign(args...) args
806 #define TP_locvar(...) __VA_ARGS__
809 #define TP_code(...) __VA_ARGS__
812 * For state dump, check that "session" argument (mandatory) matches the
813 * session this event belongs to. Ensures that we write state dump data only
814 * into the started session, not into all sessions.
816 #ifdef TP_SESSION_CHECK
817 #define _TP_SESSION_CHECK(session, csession) (session == csession)
818 #else /* TP_SESSION_CHECK */
819 #define _TP_SESSION_CHECK(session, csession) 1
820 #endif /* TP_SESSION_CHECK */
823 * __dynamic_len array length is twice the number of fields due to
824 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
825 * worse case, needing 2 entries per field.
827 #undef LTTNG_DECLARE_EVENT_CLASS
828 #define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
829 static void __event_probe__##_name(void *__data, _proto) \
831 struct probe_local_vars { _locvar }; \
832 struct lttng_event *__event = __data; \
833 struct lttng_channel *__chan = __event->chan; \
834 struct lib_ring_buffer_ctx __ctx; \
835 size_t __event_len, __event_align; \
836 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
837 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
838 struct __event_typemap__##_name __typemap __attribute__((unused)); \
840 struct probe_local_vars __tp_locvar; \
841 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
844 if (!_TP_SESSION_CHECK(session, __chan->session)) \
846 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
848 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
850 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
853 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
855 __event_align = __event_get_align__##_name(tp_locvar, _args); \
856 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
857 __event_align, -1); \
858 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
861 /* Control code (field ordering) */ \
863 __chan->ops->event_commit(&__ctx); \
865 /* Copy code, steered by control code */ \
869 #undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
870 #define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
871 static void __event_probe__##_name(void *__data) \
873 struct probe_local_vars { _locvar }; \
874 struct lttng_event *__event = __data; \
875 struct lttng_channel *__chan = __event->chan; \
876 struct lib_ring_buffer_ctx __ctx; \
877 size_t __event_len, __event_align; \
878 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
879 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
880 struct __event_typemap__##_name __typemap __attribute__((unused)); \
882 struct probe_local_vars __tp_locvar; \
883 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
886 if (!_TP_SESSION_CHECK(session, __chan->session)) \
888 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
890 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
892 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
895 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
896 __event_align = __event_get_align__##_name(tp_locvar); \
897 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
898 __event_align, -1); \
899 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
902 /* Control code (field ordering) */ \
904 __chan->ops->event_commit(&__ctx); \
906 /* Copy code, steered by control code */ \
910 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
913 * Stage 10 of the trace events.
915 * Register/unregister probes at module load/unload.
918 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
920 #define TP_ID1(_token, _system) _token##_system
921 #define TP_ID(_token, _system) TP_ID1(_token, _system)
922 #define module_init_eval1(_token, _system) module_init(_token##_system)
923 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
924 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
925 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
927 #ifndef TP_MODULE_NOINIT
928 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
930 wrapper_vmalloc_sync_all();
931 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
934 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
936 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
939 #ifndef TP_MODULE_NOAUTOLOAD
940 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
941 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
946 #undef module_init_eval
947 #undef module_exit_eval
953 #undef TRACE_EVENT_FLAGS
This page took 0.049365 seconds and 4 git commands to generate.