9262f5de21f8181ef81f52ee0527b04f7eef7473
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
22 #include <linux/debugfs.h>
24 #include "lttng-types.h"
25 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
26 #include "../wrapper/ringbuffer/frontend_types.h"
27 #include "../lttng-events.h"
28 #include "../lttng-tracer-core.h"
31 * Macro declarations used for all stages.
35 * DECLARE_EVENT_CLASS can be used to add a generic function
36 * handlers for events. That is, if all events have the same
37 * parameters and just have distinct trace points.
38 * Each tracepoint can be defined with DEFINE_EVENT and that
39 * will map the DECLARE_EVENT_CLASS to the tracepoint.
41 * TRACE_EVENT is a one to one mapping between tracepoint and template.
45 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
46 DECLARE_EVENT_CLASS(name, \
52 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
54 #undef TRACE_EVENT_NOARGS
55 #define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \
56 DECLARE_EVENT_CLASS_NOARGS(name, \
60 DEFINE_EVENT_NOARGS(name, name)
63 #undef DEFINE_EVENT_PRINT
64 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
65 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
67 /* Callbacks are meaningless to LTTng. */
69 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
70 assign, print, reg, unreg) \
71 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
72 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
75 * Stage 1 of the trace events.
77 * Create dummy trace calls for each events, verifying that the LTTng module
78 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
82 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
85 #define TP_PROTO(args...) args
88 #define TP_ARGS(args...) args
91 #define DEFINE_EVENT(_template, _name, _proto, _args) \
92 void trace_##_name(_proto);
94 #undef DEFINE_EVENT_NOARGS
95 #define DEFINE_EVENT_NOARGS(_template, _name) \
96 void trace_##_name(void *__data);
98 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
101 * Stage 2 of the trace events.
103 * Create event field type metadata section.
104 * Each event produce an array of fields.
107 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
109 /* Named field types must be defined in lttng-types.h */
112 #define __field_full(_type, _item, _order, _base) \
115 .type = __type_integer(_type, _order, _base, none), \
119 #define __field(_type, _item) \
120 __field_full(_type, _item, __BYTE_ORDER, 10)
123 #define __field_ext(_type, _item, _filter_type) \
124 __field(_type, _item)
127 #define __field_hex(_type, _item) \
128 __field_full(_type, _item, __BYTE_ORDER, 16)
130 #undef __field_network
131 #define __field_network(_type, _item) \
132 __field_full(_type, _item, __BIG_ENDIAN, 10)
134 #undef __field_network_hex
135 #define __field_network_hex(_type, _item) \
136 __field_full(_type, _item, __BIG_ENDIAN, 16)
138 #undef __array_enc_ext
139 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
144 .atype = atype_array, \
148 .elem_type = __type_integer(_type, _order, _base, _encoding), \
154 #define __array(_type, _item, _length) \
155 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
158 #define __array_text(_type, _item, _length) \
159 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
162 #define __array_hex(_type, _item, _length) \
163 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
165 #undef __dynamic_array_enc_ext
166 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
171 .atype = atype_sequence, \
174 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
175 .elem_type = __type_integer(_type, _order, _base, _encoding), \
180 #undef __dynamic_array
181 #define __dynamic_array(_type, _item, _length) \
182 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
184 #undef __dynamic_array_text
185 #define __dynamic_array_text(_type, _item, _length) \
186 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
188 #undef __dynamic_array_hex
189 #define __dynamic_array_hex(_type, _item, _length) \
190 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
193 #define __string(_item, _src) \
198 .atype = atype_string, \
199 .u.basic.string.encoding = lttng_encode_UTF8, \
203 #undef __string_from_user
204 #define __string_from_user(_item, _src) \
205 __string(_item, _src)
207 #undef TP_STRUCT__entry
208 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
210 #undef DECLARE_EVENT_CLASS_NOARGS
211 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
212 static const struct lttng_event_field __event_fields___##_name[] = { \
216 #undef DECLARE_EVENT_CLASS
217 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
218 DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \
221 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
224 * Stage 3 of the trace events.
226 * Create probe callback prototypes.
229 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
232 #define TP_PROTO(args...) args
234 #undef DECLARE_EVENT_CLASS
235 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
236 static void __event_probe__##_name(void *__data, _proto);
238 #undef DECLARE_EVENT_CLASS_NOARGS
239 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
240 static void __event_probe__##_name(void *__data);
242 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
245 * Stage 3.9 of the trace events.
247 * Create event descriptions.
250 /* Named field types must be defined in lttng-types.h */
252 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
255 #define TP_PROBE_CB(_template) &__event_probe__##_template
258 #undef DEFINE_EVENT_NOARGS
259 #define DEFINE_EVENT_NOARGS(_template, _name) \
260 static const struct lttng_event_desc __event_desc___##_name = { \
261 .fields = __event_fields___##_template, \
263 .probe_callback = (void *) TP_PROBE_CB(_template), \
264 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
265 .owner = THIS_MODULE, \
269 #define DEFINE_EVENT(_template, _name, _proto, _args) \
270 DEFINE_EVENT_NOARGS(_template, _name)
272 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
276 * Stage 4 of the trace events.
278 * Create an array of event description pointers.
281 /* Named field types must be defined in lttng-types.h */
283 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
285 #undef DEFINE_EVENT_NOARGS
286 #define DEFINE_EVENT_NOARGS(_template, _name) \
287 &__event_desc___##_name,
290 #define DEFINE_EVENT(_template, _name, _proto, _args) \
291 DEFINE_EVENT_NOARGS(_template, _name)
293 #define TP_ID1(_token, _system) _token##_system
294 #define TP_ID(_token, _system) TP_ID1(_token, _system)
296 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
297 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
305 * Stage 5 of the trace events.
307 * Create a toplevel descriptor for the whole probe.
310 #define TP_ID1(_token, _system) _token##_system
311 #define TP_ID(_token, _system) TP_ID1(_token, _system)
313 /* non-const because list head will be modified when registered. */
314 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
315 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
316 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
323 * Stage 6 of the trace events.
325 * Create static inline function that calculates event size.
328 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
330 /* Named field types must be defined in lttng-types.h */
333 #define __field_full(_type, _item, _order, _base) \
334 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
335 __event_len += sizeof(_type);
337 #undef __array_enc_ext
338 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
339 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
340 __event_len += sizeof(_type) * (_length);
342 #undef __dynamic_array_enc_ext
343 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
344 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
345 __event_len += sizeof(u32); \
346 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
347 __dynamic_len[__dynamic_len_idx] = (_length); \
348 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
352 #define __string(_item, _src) \
353 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
356 * strlen_user includes \0. If returns 0, it faulted, so we set size to
359 #undef __string_from_user
360 #define __string_from_user(_item, _src) \
361 __event_len += __dynamic_len[__dynamic_len_idx++] = \
362 max_t(size_t, strlen_user(_src), 1);
365 #define TP_PROTO(args...) args
367 #undef TP_STRUCT__entry
368 #define TP_STRUCT__entry(args...) args
370 #undef DECLARE_EVENT_CLASS
371 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
372 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
374 size_t __event_len = 0; \
375 unsigned int __dynamic_len_idx = 0; \
378 (void) __dynamic_len_idx; /* don't warn if unused */ \
380 return __event_len; \
383 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
386 * Stage 7 of the trace events.
388 * Create static inline function that calculates event payload alignment.
391 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
393 /* Named field types must be defined in lttng-types.h */
396 #define __field_full(_type, _item, _order, _base) \
397 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
399 #undef __array_enc_ext
400 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
401 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
403 #undef __dynamic_array_enc_ext
404 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
405 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
406 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
409 #define __string(_item, _src)
411 #undef __string_from_user
412 #define __string_from_user(_item, _src)
415 #define TP_PROTO(args...) args
417 #undef TP_STRUCT__entry
418 #define TP_STRUCT__entry(args...) args
420 #undef DECLARE_EVENT_CLASS
421 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
422 static inline size_t __event_get_align__##_name(_proto) \
424 size_t __event_align = 1; \
426 return __event_align; \
429 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
433 * Stage 8 of the trace events.
435 * Create structure declaration that allows the "assign" macros to access the
439 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
441 /* Named field types must be defined in lttng-types.h */
444 #define __field_full(_type, _item, _order, _base) _type _item;
446 #undef __array_enc_ext
447 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
450 #undef __dynamic_array_enc_ext
451 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
455 #define __string(_item, _src) char _item;
457 #undef __string_from_user
458 #define __string_from_user(_item, _src) \
459 __string(_item, _src)
461 #undef TP_STRUCT__entry
462 #define TP_STRUCT__entry(args...) args
464 #undef DECLARE_EVENT_CLASS
465 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
466 struct __event_typemap__##_name { \
470 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
474 * Stage 9 of the trace events.
476 * Create the probe function : call even size calculation and write event data
479 * We use both the field and assignment macros to write the fields in the order
480 * defined in the field declaration. The field declarations control the
481 * execution order, jumping to the appropriate assignment block.
484 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
487 #define __field_full(_type, _item, _order, _base) \
488 goto __assign_##_item; \
491 #undef __array_enc_ext
492 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
493 goto __assign_##_item; \
496 #undef __dynamic_array_enc_ext
497 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
498 goto __assign_##_item##_1; \
499 __end_field_##_item##_1: \
500 goto __assign_##_item##_2; \
501 __end_field_##_item##_2:
504 #define __string(_item, _src) \
505 goto __assign_##_item; \
508 #undef __string_from_user
509 #define __string_from_user(_item, _src) \
510 __string(_item, _src)
513 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
517 #define tp_assign(dest, src) \
520 __typeof__(__typemap.dest) __tmp = (src); \
521 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
522 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
524 goto __end_field_##dest;
527 #define tp_memcpy(dest, src, len) \
530 (void) __typemap.dest; \
531 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
532 __chan->ops->event_write(&__ctx, src, len); \
533 goto __end_field_##dest;
536 #define tp_memcpy_dyn(dest, src) \
537 __assign_##dest##_1: \
539 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
540 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
541 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
543 goto __end_field_##dest##_1; \
544 __assign_##dest##_2: \
545 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
546 __chan->ops->event_write(&__ctx, src, \
547 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
548 goto __end_field_##dest##_2;
550 #undef tp_memcpy_from_user
551 #define tp_memcpy_from_user(dest, src, len) \
554 (void) __typemap.dest; \
555 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
556 __chan->ops->event_write_from_user(&__ctx, src, len); \
557 goto __end_field_##dest;
560 * The string length including the final \0.
562 #undef tp_copy_string_from_user
563 #define tp_copy_string_from_user(dest, src) \
569 (void) __typemap.dest; \
570 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));\
571 __ustrlen = __get_dynamic_array_len(dest); \
572 if (likely(__ustrlen > 1)) { \
573 __chan->ops->event_write_from_user(&__ctx, src, \
576 __chan->ops->event_memset(&__ctx, 0, 1); \
578 goto __end_field_##dest;
580 #define tp_strcpy(dest, src) \
581 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
583 /* Named field types must be defined in lttng-types.h */
586 #define __get_str(field) field
588 #undef __get_dynamic_array
589 #define __get_dynamic_array(field) field
591 /* Beware: this get len actually consumes the len value */
592 #undef __get_dynamic_array_len
593 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
596 #define TP_PROTO(args...) args
599 #define TP_ARGS(args...) args
601 #undef TP_STRUCT__entry
602 #define TP_STRUCT__entry(args...) args
604 #undef TP_fast_assign
605 #define TP_fast_assign(args...) args
608 * For state dump, check that "session" argument (mandatory) matches the
609 * session this event belongs to. Ensures that we write state dump data only
610 * into the started session, not into all sessions.
612 #ifdef TP_SESSION_CHECK
613 #define _TP_SESSION_CHECK(session, csession) (session == csession)
614 #else /* TP_SESSION_CHECK */
615 #define _TP_SESSION_CHECK(session, csession) 1
616 #endif /* TP_SESSION_CHECK */
618 #undef DECLARE_EVENT_CLASS
619 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
620 static void __event_probe__##_name(void *__data, _proto) \
622 struct lttng_event *__event = __data; \
623 struct lttng_channel *__chan = __event->chan; \
624 struct lib_ring_buffer_ctx __ctx; \
625 size_t __event_len, __event_align; \
626 size_t __dynamic_len_idx = 0; \
627 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
628 struct __event_typemap__##_name __typemap; \
632 (void) __dynamic_len_idx; /* don't warn if unused */ \
633 (void) __typemap; /* don't warn if unused */ \
635 if (!_TP_SESSION_CHECK(session, __chan->session)) \
637 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
639 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
641 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
643 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
644 __event_align = __event_get_align__##_name(_args); \
645 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
646 __event_align, -1); \
647 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
650 /* Control code (field ordering) */ \
652 __chan->ops->event_commit(&__ctx); \
654 /* Copy code, steered by control code */ \
658 #undef DECLARE_EVENT_CLASS_NOARGS
659 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
660 static void __event_probe__##_name(void *__data) \
662 struct lttng_event *__event = __data; \
663 struct lttng_channel *__chan = __event->chan; \
664 struct lib_ring_buffer_ctx __ctx; \
665 size_t __event_len, __event_align; \
668 if (!_TP_SESSION_CHECK(session, __chan->session)) \
670 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
672 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
674 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
678 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
679 __event_align, -1); \
680 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
683 /* Control code (field ordering) */ \
685 __chan->ops->event_commit(&__ctx); \
687 /* Copy code, steered by control code */ \
691 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
694 * Stage 10 of the trace events.
696 * Register/unregister probes at module load/unload.
699 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
701 #define TP_ID1(_token, _system) _token##_system
702 #define TP_ID(_token, _system) TP_ID1(_token, _system)
703 #define module_init_eval1(_token, _system) module_init(_token##_system)
704 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
705 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
706 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
708 #ifndef TP_MODULE_OVERRIDE
709 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
711 wrapper_vmalloc_sync_all();
712 return lttng_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
715 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
717 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
719 lttng_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
722 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
725 #undef module_init_eval
726 #undef module_exit_eval
732 #undef TRACE_EVENT_FLAGS
This page took 0.044248 seconds and 4 git commands to generate.