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, \
90 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION_MAP
91 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION_MAP(template, name, map, proto, args, cond) \
92 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, map, PARAMS(proto), PARAMS(args))
95 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
96 * handlers for events. That is, if all events have the same parameters
97 * and just have distinct trace points. Each tracepoint can be defined
98 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
99 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
101 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
105 #undef LTTNG_TRACEPOINT_EVENT
106 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, tstruct, assign, print) \
107 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
114 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
115 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, tstruct, assign, print) \
116 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, \
121 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT
122 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT(template, name, proto, args, print) \
123 LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP(template, name, name, \
124 PARAMS(proto), PARAMS(args), PARAMS(print_))
126 #undef LTTNG_TRACEPOINT_EVENT_FN
127 #define LTTNG_TRACEPOINT_EVENT_FN(name, proto, args, tstruct, \
128 assign, print, reg, unreg) \
129 LTTNG_TRACEPOINT_EVENT_FN_MAP(name, name, PARAMS(proto), PARAMS(args), \
130 PARAMS(tstruct), PARAMS(assign), PARAMS(print), \
131 PARAMS(reg), PARAMS(unreg)) \
133 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
134 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
135 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
137 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
138 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
139 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
141 #undef LTTNG_TRACEPOINT_EVENT_CONDITION
142 #define LTTNG_TRACEPOINT_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
143 LTTNG_TRACEPOINT_EVENT_CONDITION_MAP(name, name, \
151 #undef LTTNG_TRACEPOINT_EVENT_CLASS
152 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
153 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
154 PARAMS(_tstruct), PARAMS(_assign), PARAMS(_print))
156 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
157 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
158 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_tstruct), \
159 PARAMS(_assign), PARAMS(_print))
163 * Stage 1 of the trace events.
165 * Create dummy trace calls for each events, verifying that the LTTng module
166 * instrumentation headers match the kernel arguments. Will be optimized
167 * out by the compiler.
170 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
173 #define TP_PROTO(args...) args
176 #define TP_ARGS(args...) args
178 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
179 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
180 void trace_##_name(_proto);
182 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
183 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
184 void trace_##_name(void *__data);
186 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
189 * Stage 2 of the trace events.
191 * Create event field type metadata section.
192 * Each event produce an array of fields.
195 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
197 /* Named field types must be defined in lttng-types.h */
200 #define __field_full(_type, _item, _order, _base) \
203 .type = __type_integer(_type, _order, _base, none), \
207 #define __field(_type, _item) \
208 __field_full(_type, _item, __BYTE_ORDER, 10)
211 #define __field_ext(_type, _item, _filter_type) \
212 __field(_type, _item)
215 #define __field_hex(_type, _item) \
216 __field_full(_type, _item, __BYTE_ORDER, 16)
219 #define __field_oct(_type, _item) \
220 __field_full(_type, _item, __BYTE_ORDER, 8)
222 #undef __field_network
223 #define __field_network(_type, _item) \
224 __field_full(_type, _item, __BIG_ENDIAN, 10)
226 #undef __field_network_hex
227 #define __field_network_hex(_type, _item) \
228 __field_full(_type, _item, __BIG_ENDIAN, 16)
230 #undef __array_enc_ext
231 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
236 .atype = atype_array, \
240 .elem_type = __type_integer(_type, _order, _base, _encoding), \
246 #define __array(_type, _item, _length) \
247 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
250 #define __array_text(_type, _item, _length) \
251 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
254 #define __array_hex(_type, _item, _length) \
255 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
257 #undef __dynamic_array_enc_ext
258 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
263 .atype = atype_sequence, \
266 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
267 .elem_type = __type_integer(_type, _order, _base, _encoding), \
272 #undef __dynamic_array_enc_ext_2
273 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
274 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
276 #undef __dynamic_array
277 #define __dynamic_array(_type, _item, _length) \
278 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
280 #undef __dynamic_array_text
281 #define __dynamic_array_text(_type, _item, _length) \
282 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
284 #undef __dynamic_array_hex
285 #define __dynamic_array_hex(_type, _item, _length) \
286 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
288 #undef __dynamic_array_network_hex
289 #define __dynamic_array_network_hex(_type, _item, _length) \
290 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
292 #undef __dynamic_array_network
293 #define __dynamic_array_network(_type, _item, _length) \
294 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
296 #undef __dynamic_array_text_2
297 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
298 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
301 #define __string(_item, _src) \
306 .atype = atype_string, \
307 .u.basic.string.encoding = lttng_encode_UTF8, \
311 #undef __string_from_user
312 #define __string_from_user(_item, _src) \
313 __string(_item, _src)
315 #undef TP_STRUCT__entry
316 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
318 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
319 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
320 static const struct lttng_event_field __event_fields___##_name[] = { \
324 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
325 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
326 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
329 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
332 * Stage 3 of the trace events.
334 * Create probe callback prototypes.
337 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
340 #define TP_PROTO(args...) args
342 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
343 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
344 static void __event_probe__##_name(void *__data, _proto);
346 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
347 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
348 static void __event_probe__##_name(void *__data);
350 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
353 * Stage 3.9 of the trace events.
355 * Create event descriptions.
358 /* Named field types must be defined in lttng-types.h */
360 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
363 #define TP_PROBE_CB(_template) &__event_probe__##_template
366 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
367 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
368 static const struct lttng_event_desc __event_desc___##_map = { \
369 .fields = __event_fields___##_template, \
372 .probe_callback = (void *) TP_PROBE_CB(_template), \
373 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
374 .owner = THIS_MODULE, \
377 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
378 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
379 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
381 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
385 * Stage 4 of the trace events.
387 * Create an array of event description pointers.
390 /* Named field types must be defined in lttng-types.h */
392 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
394 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
395 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
396 &__event_desc___##_map,
398 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
399 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
400 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
402 #define TP_ID1(_token, _system) _token##_system
403 #define TP_ID(_token, _system) TP_ID1(_token, _system)
405 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
406 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
414 * Stage 5 of the trace events.
416 * Create a toplevel descriptor for the whole probe.
419 #define TP_ID1(_token, _system) _token##_system
420 #define TP_ID(_token, _system) TP_ID1(_token, _system)
422 /* non-const because list head will be modified when registered. */
423 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
424 .provider
= __stringify(TRACE_SYSTEM
),
425 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
426 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
427 .head
= { NULL
, NULL
},
428 .lazy_init_head
= { NULL
, NULL
},
436 * Stage 6 of the trace events.
438 * Create static inline function that calculates event size.
441 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
443 /* Named field types must be defined in lttng-types.h */
446 #define __field_full(_type, _item, _order, _base) \
447 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
448 __event_len += sizeof(_type);
450 #undef __array_enc_ext
451 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
452 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
453 __event_len += sizeof(_type) * (_length);
455 #undef __dynamic_array_enc_ext
456 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
457 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
458 __event_len += sizeof(u32); \
459 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
460 __dynamic_len[__dynamic_len_idx] = (_length); \
461 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
464 #undef __dynamic_array_enc_ext_2
465 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
466 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
467 __event_len += sizeof(u32); \
468 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
469 __dynamic_len[__dynamic_len_idx] = (_length1); \
470 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
471 __dynamic_len_idx++; \
472 __dynamic_len[__dynamic_len_idx] = (_length2); \
473 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
477 #define __string(_item, _src) \
478 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
481 * strlen_user includes \0. If returns 0, it faulted, so we set size to
484 #undef __string_from_user
485 #define __string_from_user(_item, _src) \
486 __event_len += __dynamic_len[__dynamic_len_idx++] = \
487 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
490 #define TP_PROTO(args...) args
492 #undef TP_STRUCT__entry
493 #define TP_STRUCT__entry(args...) args
496 #define TP_locvar(...) __VA_ARGS__
498 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
499 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
500 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
501 void *__tp_locvar, _proto) \
503 size_t __event_len = 0; \
504 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
505 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
508 return __event_len; \
511 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
512 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
513 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
516 size_t __event_len = 0; \
517 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
518 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
521 return __event_len; \
524 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
527 * Stage 7 of the trace events.
529 * Create static inline function that calculates event payload alignment.
532 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
534 /* Named field types must be defined in lttng-types.h */
537 #define __field_full(_type, _item, _order, _base) \
538 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
540 #undef __array_enc_ext
541 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
542 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
544 #undef __dynamic_array_enc_ext
545 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
546 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
547 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
549 #undef __dynamic_array_enc_ext_2
550 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
551 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
554 #define __string(_item, _src)
556 #undef __string_from_user
557 #define __string_from_user(_item, _src)
560 #define TP_PROTO(args...) args
562 #undef TP_STRUCT__entry
563 #define TP_STRUCT__entry(args...) args
566 #define TP_locvar(...) __VA_ARGS__
568 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
569 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
570 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
572 size_t __event_align = 1; \
573 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
576 return __event_align; \
579 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
580 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
581 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
583 size_t __event_align = 1; \
584 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
587 return __event_align; \
590 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
593 * Stage 8 of the trace events.
595 * Create structure declaration that allows the "assign" macros to access the
599 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
601 /* Named field types must be defined in lttng-types.h */
604 #define __field_full(_type, _item, _order, _base) _type _item;
606 #undef __array_enc_ext
607 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
610 #undef __dynamic_array_enc_ext
611 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
614 #undef __dynamic_array_enc_ext_2
615 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
616 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
619 #define __string(_item, _src) char _item;
621 #undef __string_from_user
622 #define __string_from_user(_item, _src) \
623 __string(_item, _src)
625 #undef TP_STRUCT__entry
626 #define TP_STRUCT__entry(args...) args
628 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
629 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
630 struct __event_typemap__##_name { \
634 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
635 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
636 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
638 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
642 * Stage 9 of the trace events.
644 * Create the probe function : call even size calculation and write event data
647 * We use both the field and assignment macros to write the fields in the order
648 * defined in the field declaration. The field declarations control the
649 * execution order, jumping to the appropriate assignment block.
652 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
655 #define __field_full(_type, _item, _order, _base) \
656 goto __assign_##_item; \
659 #undef __array_enc_ext
660 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
661 goto __assign_##_item; \
664 #undef __dynamic_array_enc_ext
665 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
666 goto __assign_##_item##_1; \
667 __end_field_##_item##_1: \
668 goto __assign_##_item##_2; \
669 __end_field_##_item##_2:
671 #undef __dynamic_array_enc_ext_2
672 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
673 goto __assign_##_item##_1; \
674 __end_field_##_item##_1: \
675 goto __assign_##_item##_2; \
676 __end_field_##_item##_2: \
677 goto __assign_##_item##_3; \
678 __end_field_##_item##_3:
681 #define __string(_item, _src) \
682 goto __assign_##_item; \
685 #undef __string_from_user
686 #define __string_from_user(_item, _src) \
687 __string(_item, _src)
690 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
694 #define tp_assign(dest, src) \
697 __typeof__(__typemap.dest) __tmp = (src); \
698 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
699 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
701 goto __end_field_##dest;
703 /* fixed length array memcpy */
705 #define tp_memcpy_gen(write_ops, dest, src, len) \
708 (void) __typemap.dest; \
709 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
710 __chan->ops->write_ops(&__ctx, src, len); \
711 goto __end_field_##dest;
714 #define tp_memcpy(dest, src, len) \
715 tp_memcpy_gen(event_write, dest, src, len)
717 #undef tp_memcpy_from_user
718 #define tp_memcpy_from_user(dest, src, len) \
719 tp_memcpy_gen(event_write_from_user, dest, src, len)
721 /* variable length sequence memcpy */
722 #undef tp_memcpy_dyn_gen
723 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
724 __assign_##dest##_1: \
726 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
727 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
728 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
730 goto __end_field_##dest##_1; \
731 __assign_##dest##_2: \
732 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
733 __chan->ops->write_ops(&__ctx, src, \
734 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
735 goto __end_field_##dest##_2;
737 #undef tp_memcpy_dyn_gen_2
738 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
739 __assign_##dest##_1: \
741 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
742 + __dynamic_len[__dynamic_len_idx + 1]; \
743 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
744 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
746 goto __end_field_##dest##_1; \
747 __assign_##dest##_2: \
748 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
749 __chan->ops->write_ops(&__ctx, src1, \
750 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
751 goto __end_field_##dest##_2; \
752 __assign_##dest##_3: \
753 __chan->ops->write_ops(&__ctx, src2, \
754 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
755 goto __end_field_##dest##_3;
758 #define tp_memcpy_dyn(dest, src) \
759 tp_memcpy_dyn_gen(event_write, dest, src)
761 #undef tp_memcpy_dyn_2
762 #define tp_memcpy_dyn_2(dest, src1, src2) \
763 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
765 #undef tp_memcpy_dyn_from_user
766 #define tp_memcpy_dyn_from_user(dest, src) \
767 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
770 * The string length including the final \0.
772 #undef tp_copy_string_from_user
773 #define tp_copy_string_from_user(dest, src) \
776 (void) __typemap.dest; \
777 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
778 __chan->ops->event_strcpy_from_user(&__ctx, src, \
779 __get_dynamic_array_len(dest)); \
780 goto __end_field_##dest;
783 #define tp_strcpy(dest, src) \
786 (void) __typemap.dest; \
787 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
788 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
789 goto __end_field_##dest;
791 /* Named field types must be defined in lttng-types.h */
794 #define __get_str(field) field
796 #undef __get_dynamic_array
797 #define __get_dynamic_array(field) field
799 /* Beware: this get len actually consumes the len value */
800 #undef __get_dynamic_array_len
801 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
804 #define TP_PROTO(args...) args
807 #define TP_ARGS(args...) args
809 #undef TP_STRUCT__entry
810 #define TP_STRUCT__entry(args...) args
812 #undef TP_fast_assign
813 #define TP_fast_assign(args...) args
816 #define TP_locvar(...) __VA_ARGS__
819 #define TP_code(...) __VA_ARGS__
822 * For state dump, check that "session" argument (mandatory) matches the
823 * session this event belongs to. Ensures that we write state dump data only
824 * into the started session, not into all sessions.
826 #ifdef TP_SESSION_CHECK
827 #define _TP_SESSION_CHECK(session, csession) (session == csession)
828 #else /* TP_SESSION_CHECK */
829 #define _TP_SESSION_CHECK(session, csession) 1
830 #endif /* TP_SESSION_CHECK */
833 * __dynamic_len array length is twice the number of fields due to
834 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
835 * worse case, needing 2 entries per field.
837 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
838 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
839 static void __event_probe__##_name(void *__data, _proto) \
841 struct probe_local_vars { _locvar }; \
842 struct lttng_event *__event = __data; \
843 struct lttng_channel *__chan = __event->chan; \
844 struct lttng_session *__session = __chan->session; \
845 struct lib_ring_buffer_ctx __ctx; \
846 size_t __event_len, __event_align; \
847 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
848 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
849 struct __event_typemap__##_name __typemap __attribute__((unused)); \
851 struct probe_local_vars __tp_locvar; \
852 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
854 struct lttng_pid_tracker *__lpf; \
856 if (!_TP_SESSION_CHECK(session, __session)) \
858 if (unlikely(!ACCESS_ONCE(__session->active))) \
860 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
862 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
864 __lpf = rcu_dereference(__session->pid_tracker); \
865 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
868 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
870 __event_align = __event_get_align__##_name(tp_locvar, _args); \
871 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
872 __event_align, -1); \
873 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
876 /* Control code (field ordering) */ \
878 __chan->ops->event_commit(&__ctx); \
880 /* Copy code, steered by control code */ \
884 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
885 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
886 static void __event_probe__##_name(void *__data) \
888 struct probe_local_vars { _locvar }; \
889 struct lttng_event *__event = __data; \
890 struct lttng_channel *__chan = __event->chan; \
891 struct lttng_session *__session = __chan->session; \
892 struct lib_ring_buffer_ctx __ctx; \
893 size_t __event_len, __event_align; \
894 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
895 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
896 struct __event_typemap__##_name __typemap __attribute__((unused)); \
898 struct probe_local_vars __tp_locvar; \
899 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
901 struct lttng_pid_tracker *__lpf; \
903 if (!_TP_SESSION_CHECK(session, __session)) \
905 if (unlikely(!ACCESS_ONCE(__session->active))) \
907 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
909 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
911 __lpf = rcu_dereference(__session->pid_tracker); \
912 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
915 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
916 __event_align = __event_get_align__##_name(tp_locvar); \
917 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
918 __event_align, -1); \
919 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
922 /* Control code (field ordering) */ \
924 __chan->ops->event_commit(&__ctx); \
926 /* Copy code, steered by control code */ \
930 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
933 * Stage 10 of the trace events.
935 * Register/unregister probes at module load/unload.
938 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
940 #define TP_ID1(_token, _system) _token##_system
941 #define TP_ID(_token, _system) TP_ID1(_token, _system)
942 #define module_init_eval1(_token, _system) module_init(_token##_system)
943 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
944 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
945 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
947 #ifndef TP_MODULE_NOINIT
948 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
950 wrapper_vmalloc_sync_all();
951 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
954 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
956 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
959 #ifndef TP_MODULE_NOAUTOLOAD
960 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
961 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
966 #undef module_init_eval
967 #undef module_exit_eval
This page took 0.085741 seconds and 5 git commands to generate.