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 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
425 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
432 * Stage 6 of the trace events.
434 * Create static inline function that calculates event size.
437 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
439 /* Named field types must be defined in lttng-types.h */
442 #define __field_full(_type, _item, _order, _base) \
443 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
444 __event_len += sizeof(_type);
446 #undef __array_enc_ext
447 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
448 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
449 __event_len += sizeof(_type) * (_length);
451 #undef __dynamic_array_enc_ext
452 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
453 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
454 __event_len += sizeof(u32); \
455 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
456 __dynamic_len[__dynamic_len_idx] = (_length); \
457 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
460 #undef __dynamic_array_enc_ext_2
461 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
462 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
463 __event_len += sizeof(u32); \
464 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
465 __dynamic_len[__dynamic_len_idx] = (_length1); \
466 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
467 __dynamic_len_idx++; \
468 __dynamic_len[__dynamic_len_idx] = (_length2); \
469 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
473 #define __string(_item, _src) \
474 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
477 * strlen_user includes \0. If returns 0, it faulted, so we set size to
480 #undef __string_from_user
481 #define __string_from_user(_item, _src) \
482 __event_len += __dynamic_len[__dynamic_len_idx++] = \
483 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
486 #define TP_PROTO(args...) args
488 #undef TP_STRUCT__entry
489 #define TP_STRUCT__entry(args...) args
492 #define TP_locvar(...) __VA_ARGS__
494 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
495 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
496 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
497 void *__tp_locvar, _proto) \
499 size_t __event_len = 0; \
500 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
501 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
504 return __event_len; \
507 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
508 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
509 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
512 size_t __event_len = 0; \
513 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
514 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
517 return __event_len; \
520 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
523 * Stage 7 of the trace events.
525 * Create static inline function that calculates event payload alignment.
528 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
530 /* Named field types must be defined in lttng-types.h */
533 #define __field_full(_type, _item, _order, _base) \
534 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
536 #undef __array_enc_ext
537 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
538 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
540 #undef __dynamic_array_enc_ext
541 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
542 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
543 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
545 #undef __dynamic_array_enc_ext_2
546 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
547 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
550 #define __string(_item, _src)
552 #undef __string_from_user
553 #define __string_from_user(_item, _src)
556 #define TP_PROTO(args...) args
558 #undef TP_STRUCT__entry
559 #define TP_STRUCT__entry(args...) args
562 #define TP_locvar(...) __VA_ARGS__
564 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
565 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
566 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
568 size_t __event_align = 1; \
569 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
572 return __event_align; \
575 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
576 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
577 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
579 size_t __event_align = 1; \
580 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
583 return __event_align; \
586 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
589 * Stage 8 of the trace events.
591 * Create structure declaration that allows the "assign" macros to access the
595 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
597 /* Named field types must be defined in lttng-types.h */
600 #define __field_full(_type, _item, _order, _base) _type _item;
602 #undef __array_enc_ext
603 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
606 #undef __dynamic_array_enc_ext
607 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
610 #undef __dynamic_array_enc_ext_2
611 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
612 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
615 #define __string(_item, _src) char _item;
617 #undef __string_from_user
618 #define __string_from_user(_item, _src) \
619 __string(_item, _src)
621 #undef TP_STRUCT__entry
622 #define TP_STRUCT__entry(args...) args
624 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
625 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
626 struct __event_typemap__##_name { \
630 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
631 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
632 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
634 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
638 * Stage 9 of the trace events.
640 * Create the probe function : call even size calculation and write event data
643 * We use both the field and assignment macros to write the fields in the order
644 * defined in the field declaration. The field declarations control the
645 * execution order, jumping to the appropriate assignment block.
648 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
651 #define __field_full(_type, _item, _order, _base) \
652 goto __assign_##_item; \
655 #undef __array_enc_ext
656 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
657 goto __assign_##_item; \
660 #undef __dynamic_array_enc_ext
661 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
662 goto __assign_##_item##_1; \
663 __end_field_##_item##_1: \
664 goto __assign_##_item##_2; \
665 __end_field_##_item##_2:
667 #undef __dynamic_array_enc_ext_2
668 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
669 goto __assign_##_item##_1; \
670 __end_field_##_item##_1: \
671 goto __assign_##_item##_2; \
672 __end_field_##_item##_2: \
673 goto __assign_##_item##_3; \
674 __end_field_##_item##_3:
677 #define __string(_item, _src) \
678 goto __assign_##_item; \
681 #undef __string_from_user
682 #define __string_from_user(_item, _src) \
683 __string(_item, _src)
686 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
690 #define tp_assign(dest, src) \
693 __typeof__(__typemap.dest) __tmp = (src); \
694 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
695 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
697 goto __end_field_##dest;
699 /* fixed length array memcpy */
701 #define tp_memcpy_gen(write_ops, dest, src, len) \
704 (void) __typemap.dest; \
705 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
706 __chan->ops->write_ops(&__ctx, src, len); \
707 goto __end_field_##dest;
710 #define tp_memcpy(dest, src, len) \
711 tp_memcpy_gen(event_write, dest, src, len)
713 #undef tp_memcpy_from_user
714 #define tp_memcpy_from_user(dest, src, len) \
715 tp_memcpy_gen(event_write_from_user, dest, src, len)
717 /* variable length sequence memcpy */
718 #undef tp_memcpy_dyn_gen
719 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
720 __assign_##dest##_1: \
722 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
723 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
724 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
726 goto __end_field_##dest##_1; \
727 __assign_##dest##_2: \
728 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
729 __chan->ops->write_ops(&__ctx, src, \
730 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
731 goto __end_field_##dest##_2;
733 #undef tp_memcpy_dyn_gen_2
734 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
735 __assign_##dest##_1: \
737 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
738 + __dynamic_len[__dynamic_len_idx + 1]; \
739 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
740 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
742 goto __end_field_##dest##_1; \
743 __assign_##dest##_2: \
744 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
745 __chan->ops->write_ops(&__ctx, src1, \
746 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
747 goto __end_field_##dest##_2; \
748 __assign_##dest##_3: \
749 __chan->ops->write_ops(&__ctx, src2, \
750 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
751 goto __end_field_##dest##_3;
754 #define tp_memcpy_dyn(dest, src) \
755 tp_memcpy_dyn_gen(event_write, dest, src)
757 #undef tp_memcpy_dyn_2
758 #define tp_memcpy_dyn_2(dest, src1, src2) \
759 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
761 #undef tp_memcpy_dyn_from_user
762 #define tp_memcpy_dyn_from_user(dest, src) \
763 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
766 * The string length including the final \0.
768 #undef tp_copy_string_from_user
769 #define tp_copy_string_from_user(dest, src) \
772 (void) __typemap.dest; \
773 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
774 __chan->ops->event_strcpy_from_user(&__ctx, src, \
775 __get_dynamic_array_len(dest)); \
776 goto __end_field_##dest;
779 #define tp_strcpy(dest, src) \
782 (void) __typemap.dest; \
783 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
784 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
785 goto __end_field_##dest;
787 /* Named field types must be defined in lttng-types.h */
790 #define __get_str(field) field
792 #undef __get_dynamic_array
793 #define __get_dynamic_array(field) field
795 /* Beware: this get len actually consumes the len value */
796 #undef __get_dynamic_array_len
797 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
800 #define TP_PROTO(args...) args
803 #define TP_ARGS(args...) args
805 #undef TP_STRUCT__entry
806 #define TP_STRUCT__entry(args...) args
808 #undef TP_fast_assign
809 #define TP_fast_assign(args...) args
812 #define TP_locvar(...) __VA_ARGS__
815 #define TP_code(...) __VA_ARGS__
818 * For state dump, check that "session" argument (mandatory) matches the
819 * session this event belongs to. Ensures that we write state dump data only
820 * into the started session, not into all sessions.
822 #ifdef TP_SESSION_CHECK
823 #define _TP_SESSION_CHECK(session, csession) (session == csession)
824 #else /* TP_SESSION_CHECK */
825 #define _TP_SESSION_CHECK(session, csession) 1
826 #endif /* TP_SESSION_CHECK */
829 * __dynamic_len array length is twice the number of fields due to
830 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
831 * worse case, needing 2 entries per field.
833 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
834 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
835 static void __event_probe__##_name(void *__data, _proto) \
837 struct probe_local_vars { _locvar }; \
838 struct lttng_event *__event = __data; \
839 struct lttng_channel *__chan = __event->chan; \
840 struct lib_ring_buffer_ctx __ctx; \
841 size_t __event_len, __event_align; \
842 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
843 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
844 struct __event_typemap__##_name __typemap __attribute__((unused)); \
846 struct probe_local_vars __tp_locvar; \
847 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
850 if (!_TP_SESSION_CHECK(session, __chan->session)) \
852 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
854 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
856 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
859 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
861 __event_align = __event_get_align__##_name(tp_locvar, _args); \
862 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
863 __event_align, -1); \
864 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
867 /* Control code (field ordering) */ \
869 __chan->ops->event_commit(&__ctx); \
871 /* Copy code, steered by control code */ \
875 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
876 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
877 static void __event_probe__##_name(void *__data) \
879 struct probe_local_vars { _locvar }; \
880 struct lttng_event *__event = __data; \
881 struct lttng_channel *__chan = __event->chan; \
882 struct lib_ring_buffer_ctx __ctx; \
883 size_t __event_len, __event_align; \
884 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
885 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
886 struct __event_typemap__##_name __typemap __attribute__((unused)); \
888 struct probe_local_vars __tp_locvar; \
889 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
892 if (!_TP_SESSION_CHECK(session, __chan->session)) \
894 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
896 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
898 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
901 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
902 __event_align = __event_get_align__##_name(tp_locvar); \
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 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
919 * Stage 10 of the trace events.
921 * Register/unregister probes at module load/unload.
924 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
926 #define TP_ID1(_token, _system) _token##_system
927 #define TP_ID(_token, _system) TP_ID1(_token, _system)
928 #define module_init_eval1(_token, _system) module_init(_token##_system)
929 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
930 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
931 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
933 #ifndef TP_MODULE_NOINIT
934 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
936 wrapper_vmalloc_sync_all();
937 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
940 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
942 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
945 #ifndef TP_MODULE_NOAUTOLOAD
946 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
947 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
952 #undef module_init_eval
953 #undef module_exit_eval
This page took 0.0477 seconds and 4 git commands to generate.