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);
187 * Stage 1.1 of the trace events.
189 * Create dummy trace prototypes for each event class, and for each used
190 * template. This will allow checking whether the prototypes from the
191 * class and the instance using the class actually match.
194 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
197 #define TP_PROTO(args...) args
200 #define TP_ARGS(args...) args
202 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
203 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
204 void __event_template_proto___##_template(_proto);
206 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
207 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
208 void __event_template_proto___##_template(void);
210 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
211 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
212 void __event_template_proto___##_name(_proto);
214 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
215 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
216 void __event_template_proto___##_name(void);
218 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
221 * Stage 2 of the trace events.
223 * Create event field type metadata section.
224 * Each event produce an array of fields.
227 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
229 /* Named field types must be defined in lttng-types.h */
232 #define __field_full(_type, _item, _order, _base) \
235 .type = __type_integer(_type, _order, _base, none), \
239 #define __field(_type, _item) \
240 __field_full(_type, _item, __BYTE_ORDER, 10)
243 #define __field_ext(_type, _item, _filter_type) \
244 __field(_type, _item)
247 #define __field_hex(_type, _item) \
248 __field_full(_type, _item, __BYTE_ORDER, 16)
251 #define __field_oct(_type, _item) \
252 __field_full(_type, _item, __BYTE_ORDER, 8)
254 #undef __field_network
255 #define __field_network(_type, _item) \
256 __field_full(_type, _item, __BIG_ENDIAN, 10)
258 #undef __field_network_hex
259 #define __field_network_hex(_type, _item) \
260 __field_full(_type, _item, __BIG_ENDIAN, 16)
262 #undef __array_enc_ext
263 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
268 .atype = atype_array, \
272 .elem_type = __type_integer(_type, _order, _base, _encoding), \
278 #define __array(_type, _item, _length) \
279 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
282 #define __array_text(_type, _item, _length) \
283 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
286 #define __array_hex(_type, _item, _length) \
287 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
289 #undef __dynamic_array_enc_ext
290 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
295 .atype = atype_sequence, \
298 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
299 .elem_type = __type_integer(_type, _order, _base, _encoding), \
304 #undef __dynamic_array_enc_ext_2
305 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
306 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
308 #undef __dynamic_array
309 #define __dynamic_array(_type, _item, _length) \
310 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
312 #undef __dynamic_array_text
313 #define __dynamic_array_text(_type, _item, _length) \
314 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
316 #undef __dynamic_array_hex
317 #define __dynamic_array_hex(_type, _item, _length) \
318 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
320 #undef __dynamic_array_network_hex
321 #define __dynamic_array_network_hex(_type, _item, _length) \
322 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
324 #undef __dynamic_array_network
325 #define __dynamic_array_network(_type, _item, _length) \
326 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
328 #undef __dynamic_array_text_2
329 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
330 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
333 #define __string(_item, _src) \
338 .atype = atype_string, \
339 .u.basic.string.encoding = lttng_encode_UTF8, \
343 #undef __string_from_user
344 #define __string_from_user(_item, _src) \
345 __string(_item, _src)
347 #undef TP_STRUCT__entry
348 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
350 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
351 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
352 static const struct lttng_event_field __event_fields___##_name[] = { \
356 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
357 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
358 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
361 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
364 * Stage 3 of the trace events.
366 * Create probe callback prototypes.
369 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
372 #define TP_PROTO(args...) args
374 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
375 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
376 static void __event_probe__##_name(void *__data, _proto);
378 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
379 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
380 static void __event_probe__##_name(void *__data);
382 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
385 * Stage 3.9 of the trace events.
387 * Create event descriptions.
390 /* Named field types must be defined in lttng-types.h */
392 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
395 #define TP_PROBE_CB(_template) &__event_probe__##_template
398 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
399 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
400 static const struct lttng_event_desc __event_desc___##_map = { \
401 .fields = __event_fields___##_template, \
404 .probe_callback = (void *) TP_PROBE_CB(_template), \
405 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
406 .owner = THIS_MODULE, \
409 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
410 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
411 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
413 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
417 * Stage 4 of the trace events.
419 * Create an array of event description pointers.
422 /* Named field types must be defined in lttng-types.h */
424 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
426 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
427 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
428 &__event_desc___##_map,
430 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
431 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
432 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
434 #define TP_ID1(_token, _system) _token##_system
435 #define TP_ID(_token, _system) TP_ID1(_token, _system)
437 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
438 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
446 * Stage 5 of the trace events.
448 * Create a toplevel descriptor for the whole probe.
451 #define TP_ID1(_token, _system) _token##_system
452 #define TP_ID(_token, _system) TP_ID1(_token, _system)
454 /* non-const because list head will be modified when registered. */
455 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
456 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
457 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
464 * Stage 6 of the trace events.
466 * Create static inline function that calculates event size.
469 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
471 /* Named field types must be defined in lttng-types.h */
474 #define __field_full(_type, _item, _order, _base) \
475 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
476 __event_len += sizeof(_type);
478 #undef __array_enc_ext
479 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
480 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
481 __event_len += sizeof(_type) * (_length);
483 #undef __dynamic_array_enc_ext
484 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
485 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
486 __event_len += sizeof(u32); \
487 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
488 __dynamic_len[__dynamic_len_idx] = (_length); \
489 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
492 #undef __dynamic_array_enc_ext_2
493 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
494 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
495 __event_len += sizeof(u32); \
496 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
497 __dynamic_len[__dynamic_len_idx] = (_length1); \
498 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
499 __dynamic_len_idx++; \
500 __dynamic_len[__dynamic_len_idx] = (_length2); \
501 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
505 #define __string(_item, _src) \
506 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
509 * strlen_user includes \0. If returns 0, it faulted, so we set size to
512 #undef __string_from_user
513 #define __string_from_user(_item, _src) \
514 __event_len += __dynamic_len[__dynamic_len_idx++] = \
515 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
518 #define TP_PROTO(args...) args
520 #undef TP_STRUCT__entry
521 #define TP_STRUCT__entry(args...) args
524 #define TP_locvar(...) __VA_ARGS__
526 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
527 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
528 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
529 void *__tp_locvar, _proto) \
531 size_t __event_len = 0; \
532 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
533 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
536 return __event_len; \
539 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
540 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
541 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
544 size_t __event_len = 0; \
545 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
546 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
549 return __event_len; \
552 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
555 * Stage 7 of the trace events.
557 * Create static inline function that calculates event payload alignment.
560 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
562 /* Named field types must be defined in lttng-types.h */
565 #define __field_full(_type, _item, _order, _base) \
566 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
568 #undef __array_enc_ext
569 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
570 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
572 #undef __dynamic_array_enc_ext
573 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
574 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
575 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
577 #undef __dynamic_array_enc_ext_2
578 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
579 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
582 #define __string(_item, _src)
584 #undef __string_from_user
585 #define __string_from_user(_item, _src)
588 #define TP_PROTO(args...) args
590 #undef TP_STRUCT__entry
591 #define TP_STRUCT__entry(args...) args
594 #define TP_locvar(...) __VA_ARGS__
596 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
597 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
598 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
600 size_t __event_align = 1; \
601 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
604 return __event_align; \
607 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
608 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
609 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
611 size_t __event_align = 1; \
612 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
615 return __event_align; \
618 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
621 * Stage 8 of the trace events.
623 * Create structure declaration that allows the "assign" macros to access the
627 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
629 /* Named field types must be defined in lttng-types.h */
632 #define __field_full(_type, _item, _order, _base) _type _item;
634 #undef __array_enc_ext
635 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
638 #undef __dynamic_array_enc_ext
639 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
642 #undef __dynamic_array_enc_ext_2
643 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
644 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
647 #define __string(_item, _src) char _item;
649 #undef __string_from_user
650 #define __string_from_user(_item, _src) \
651 __string(_item, _src)
653 #undef TP_STRUCT__entry
654 #define TP_STRUCT__entry(args...) args
656 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
657 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
658 struct __event_typemap__##_name { \
662 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
663 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
664 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
666 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
670 * Stage 9 of the trace events.
672 * Create the probe function : call even size calculation and write event data
675 * We use both the field and assignment macros to write the fields in the order
676 * defined in the field declaration. The field declarations control the
677 * execution order, jumping to the appropriate assignment block.
680 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
683 #define __field_full(_type, _item, _order, _base) \
684 goto __assign_##_item; \
687 #undef __array_enc_ext
688 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
689 goto __assign_##_item; \
692 #undef __dynamic_array_enc_ext
693 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
694 goto __assign_##_item##_1; \
695 __end_field_##_item##_1: \
696 goto __assign_##_item##_2; \
697 __end_field_##_item##_2:
699 #undef __dynamic_array_enc_ext_2
700 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
701 goto __assign_##_item##_1; \
702 __end_field_##_item##_1: \
703 goto __assign_##_item##_2; \
704 __end_field_##_item##_2: \
705 goto __assign_##_item##_3; \
706 __end_field_##_item##_3:
709 #define __string(_item, _src) \
710 goto __assign_##_item; \
713 #undef __string_from_user
714 #define __string_from_user(_item, _src) \
715 __string(_item, _src)
718 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
722 #define tp_assign(dest, src) \
725 __typeof__(__typemap.dest) __tmp = (src); \
726 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
727 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
729 goto __end_field_##dest;
731 /* fixed length array memcpy */
733 #define tp_memcpy_gen(write_ops, dest, src, len) \
736 (void) __typemap.dest; \
737 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
738 __chan->ops->write_ops(&__ctx, src, len); \
739 goto __end_field_##dest;
742 #define tp_memcpy(dest, src, len) \
743 tp_memcpy_gen(event_write, dest, src, len)
745 #undef tp_memcpy_from_user
746 #define tp_memcpy_from_user(dest, src, len) \
747 tp_memcpy_gen(event_write_from_user, dest, src, len)
749 /* variable length sequence memcpy */
750 #undef tp_memcpy_dyn_gen
751 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
752 __assign_##dest##_1: \
754 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
755 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
756 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
758 goto __end_field_##dest##_1; \
759 __assign_##dest##_2: \
760 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
761 __chan->ops->write_ops(&__ctx, src, \
762 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
763 goto __end_field_##dest##_2;
765 #undef tp_memcpy_dyn_gen_2
766 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
767 __assign_##dest##_1: \
769 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
770 + __dynamic_len[__dynamic_len_idx + 1]; \
771 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
772 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
774 goto __end_field_##dest##_1; \
775 __assign_##dest##_2: \
776 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
777 __chan->ops->write_ops(&__ctx, src1, \
778 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
779 goto __end_field_##dest##_2; \
780 __assign_##dest##_3: \
781 __chan->ops->write_ops(&__ctx, src2, \
782 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
783 goto __end_field_##dest##_3;
786 #define tp_memcpy_dyn(dest, src) \
787 tp_memcpy_dyn_gen(event_write, dest, src)
789 #undef tp_memcpy_dyn_2
790 #define tp_memcpy_dyn_2(dest, src1, src2) \
791 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
793 #undef tp_memcpy_dyn_from_user
794 #define tp_memcpy_dyn_from_user(dest, src) \
795 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
798 * The string length including the final \0.
800 #undef tp_copy_string_from_user
801 #define tp_copy_string_from_user(dest, src) \
804 (void) __typemap.dest; \
805 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
806 __chan->ops->event_strcpy_from_user(&__ctx, src, \
807 __get_dynamic_array_len(dest)); \
808 goto __end_field_##dest;
811 #define tp_strcpy(dest, src) \
814 (void) __typemap.dest; \
815 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
816 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
817 goto __end_field_##dest;
819 /* Named field types must be defined in lttng-types.h */
822 #define __get_str(field) field
824 #undef __get_dynamic_array
825 #define __get_dynamic_array(field) field
827 /* Beware: this get len actually consumes the len value */
828 #undef __get_dynamic_array_len
829 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
832 #define TP_PROTO(args...) args
835 #define TP_ARGS(args...) args
837 #undef TP_STRUCT__entry
838 #define TP_STRUCT__entry(args...) args
840 #undef TP_fast_assign
841 #define TP_fast_assign(args...) args
844 #define TP_locvar(...) __VA_ARGS__
847 #define TP_code(...) __VA_ARGS__
850 * For state dump, check that "session" argument (mandatory) matches the
851 * session this event belongs to. Ensures that we write state dump data only
852 * into the started session, not into all sessions.
854 #ifdef TP_SESSION_CHECK
855 #define _TP_SESSION_CHECK(session, csession) (session == csession)
856 #else /* TP_SESSION_CHECK */
857 #define _TP_SESSION_CHECK(session, csession) 1
858 #endif /* TP_SESSION_CHECK */
861 * __dynamic_len array length is twice the number of fields due to
862 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
863 * worse case, needing 2 entries per field.
865 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
866 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
867 static void __event_probe__##_name(void *__data, _proto) \
869 struct probe_local_vars { _locvar }; \
870 struct lttng_event *__event = __data; \
871 struct lttng_channel *__chan = __event->chan; \
872 struct lib_ring_buffer_ctx __ctx; \
873 size_t __event_len, __event_align; \
874 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
875 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
876 struct __event_typemap__##_name __typemap __attribute__((unused)); \
878 struct probe_local_vars __tp_locvar; \
879 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
882 if (!_TP_SESSION_CHECK(session, __chan->session)) \
884 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
886 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
888 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
891 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
893 __event_align = __event_get_align__##_name(tp_locvar, _args); \
894 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
895 __event_align, -1); \
896 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
899 /* Control code (field ordering) */ \
901 __chan->ops->event_commit(&__ctx); \
903 /* Copy code, steered by control code */ \
907 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
908 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
909 static void __event_probe__##_name(void *__data) \
911 struct probe_local_vars { _locvar }; \
912 struct lttng_event *__event = __data; \
913 struct lttng_channel *__chan = __event->chan; \
914 struct lib_ring_buffer_ctx __ctx; \
915 size_t __event_len, __event_align; \
916 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
917 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
918 struct __event_typemap__##_name __typemap __attribute__((unused)); \
920 struct probe_local_vars __tp_locvar; \
921 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
924 if (!_TP_SESSION_CHECK(session, __chan->session)) \
926 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
928 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
930 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
933 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
934 __event_align = __event_get_align__##_name(tp_locvar); \
935 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
936 __event_align, -1); \
937 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
940 /* Control code (field ordering) */ \
942 __chan->ops->event_commit(&__ctx); \
944 /* Copy code, steered by control code */ \
948 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
951 * Stage 10 of the trace events.
953 * Register/unregister probes at module load/unload.
956 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
958 #define TP_ID1(_token, _system) _token##_system
959 #define TP_ID(_token, _system) TP_ID1(_token, _system)
960 #define module_init_eval1(_token, _system) module_init(_token##_system)
961 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
962 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
963 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
965 #ifndef TP_MODULE_NOINIT
966 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
968 wrapper_vmalloc_sync_all();
969 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
972 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
974 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
977 #ifndef TP_MODULE_NOAUTOLOAD
978 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
979 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
984 #undef module_init_eval
985 #undef module_exit_eval
This page took 0.071754 seconds and 4 git commands to generate.