084666d56514520f7db875e6026bf538eef0cfbd
4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
5 * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * Dual LGPL v2.1/GPL v2 license.
10 #include <linux/debugfs.h>
12 #include "lttng-types.h"
13 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
14 #include "../wrapper/ringbuffer/frontend_types.h"
15 #include "../ltt-events.h"
16 #include "../ltt-tracer-core.h"
19 * Macro declarations used for all stages.
23 * DECLARE_EVENT_CLASS can be used to add a generic function
24 * handlers for events. That is, if all events have the same
25 * parameters and just have distinct trace points.
26 * Each tracepoint can be defined with DEFINE_EVENT and that
27 * will map the DECLARE_EVENT_CLASS to the tracepoint.
29 * TRACE_EVENT is a one to one mapping between tracepoint and template.
33 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
34 DECLARE_EVENT_CLASS(name, \
40 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
42 #undef TRACE_EVENT_NOARGS
43 #define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \
44 DECLARE_EVENT_CLASS_NOARGS(name, \
48 DEFINE_EVENT_NOARGS(name, name)
51 #undef DEFINE_EVENT_PRINT
52 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
53 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
55 /* Callbacks are meaningless to LTTng. */
57 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
58 assign, print, reg, unreg) \
59 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
60 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
63 * Stage 1 of the trace events.
65 * Create dummy trace calls for each events, verifying that the LTTng module
66 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
70 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
73 #define TP_PROTO(args...) args
76 #define TP_ARGS(args...) args
79 #define DEFINE_EVENT(_template, _name, _proto, _args) \
80 void trace_##_name(_proto);
82 #undef DEFINE_EVENT_NOARGS
83 #define DEFINE_EVENT_NOARGS(_template, _name) \
84 void trace_##_name(void *__data);
86 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
89 * Stage 2 of the trace events.
91 * Create event field type metadata section.
92 * Each event produce an array of fields.
95 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
97 /* Named field types must be defined in lttng-types.h */
100 #define __field_full(_type, _item, _order, _base) \
103 .type = __type_integer(_type, _order, _base, none), \
107 #define __field(_type, _item) \
108 __field_full(_type, _item, __BYTE_ORDER, 10)
111 #define __field_ext(_type, _item, _filter_type) \
112 __field(_type, _item)
115 #define __field_hex(_type, _item) \
116 __field_full(_type, _item, __BYTE_ORDER, 16)
118 #undef __field_network
119 #define __field_network(_type, _item) \
120 __field_full(_type, _item, __BIG_ENDIAN, 10)
122 #undef __field_network_hex
123 #define __field_network_hex(_type, _item) \
124 __field_full(_type, _item, __BIG_ENDIAN, 16)
126 #undef __array_enc_ext
127 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
132 .atype = atype_array, \
136 .elem_type = __type_integer(_type, _order, _base, _encoding), \
142 #define __array(_type, _item, _length) \
143 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
146 #define __array_text(_type, _item, _length) \
147 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
150 #define __array_hex(_type, _item, _length) \
151 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
153 #undef __dynamic_array_enc_ext
154 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
159 .atype = atype_sequence, \
162 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
163 .elem_type = __type_integer(_type, _order, _base, _encoding), \
168 #undef __dynamic_array
169 #define __dynamic_array(_type, _item, _length) \
170 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
172 #undef __dynamic_array_text
173 #define __dynamic_array_text(_type, _item, _length) \
174 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
176 #undef __dynamic_array_hex
177 #define __dynamic_array_hex(_type, _item, _length) \
178 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
181 #define __string(_item, _src) \
186 .atype = atype_string, \
187 .u.basic.string.encoding = lttng_encode_UTF8, \
191 #undef TP_STRUCT__entry
192 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
194 #undef DECLARE_EVENT_CLASS_NOARGS
195 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
196 static const struct lttng_event_field __event_fields___##_name[] = { \
200 #undef DECLARE_EVENT_CLASS
201 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
202 DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \
205 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
208 * Stage 3 of the trace events.
210 * Create probe callback prototypes.
213 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
216 #define TP_PROTO(args...) args
218 #undef DECLARE_EVENT_CLASS
219 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
220 static void __event_probe__##_name(void *__data, _proto);
222 #undef DECLARE_EVENT_CLASS_NOARGS
223 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
224 static void __event_probe__##_name(void *__data);
226 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
229 * Stage 3.9 of the trace events.
231 * Create event descriptions.
234 /* Named field types must be defined in lttng-types.h */
236 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
239 #define TP_PROBE_CB(_template) &__event_probe__##_template
242 #undef DEFINE_EVENT_NOARGS
243 #define DEFINE_EVENT_NOARGS(_template, _name) \
244 static const struct lttng_event_desc __event_desc___##_name = { \
245 .fields = __event_fields___##_template, \
247 .probe_callback = (void *) TP_PROBE_CB(_template), \
248 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
249 .owner = THIS_MODULE, \
253 #define DEFINE_EVENT(_template, _name, _proto, _args) \
254 DEFINE_EVENT_NOARGS(_template, _name)
256 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
260 * Stage 4 of the trace events.
262 * Create an array of event description pointers.
265 /* Named field types must be defined in lttng-types.h */
267 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
269 #undef DEFINE_EVENT_NOARGS
270 #define DEFINE_EVENT_NOARGS(_template, _name) \
271 &__event_desc___##_name,
274 #define DEFINE_EVENT(_template, _name, _proto, _args) \
275 DEFINE_EVENT_NOARGS(_template, _name)
277 #define TP_ID1(_token, _system) _token##_system
278 #define TP_ID(_token, _system) TP_ID1(_token, _system)
280 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
281 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
289 * Stage 5 of the trace events.
291 * Create a toplevel descriptor for the whole probe.
294 #define TP_ID1(_token, _system) _token##_system
295 #define TP_ID(_token, _system) TP_ID1(_token, _system)
297 /* non-const because list head will be modified when registered. */
298 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
299 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
300 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
307 * Stage 6 of the trace events.
309 * Create static inline function that calculates event size.
312 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
314 /* Named field types must be defined in lttng-types.h */
317 #define __field_full(_type, _item, _order, _base) \
318 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
319 __event_len += sizeof(_type);
321 #undef __array_enc_ext
322 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
323 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
324 __event_len += sizeof(_type) * (_length);
326 #undef __dynamic_array_enc_ext
327 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
328 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \
329 __event_len += sizeof(u32); \
330 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
331 __dynamic_len[__dynamic_len_idx] = (_length); \
332 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
336 #define __string(_item, _src) \
337 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
340 #define TP_PROTO(args...) args
342 #undef TP_STRUCT__entry
343 #define TP_STRUCT__entry(args...) args
345 #undef DECLARE_EVENT_CLASS
346 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
347 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
349 size_t __event_len = 0; \
350 unsigned int __dynamic_len_idx = 0; \
353 (void) __dynamic_len_idx; /* don't warn if unused */ \
355 return __event_len; \
358 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
361 * Stage 7 of the trace events.
363 * Create static inline function that calculates event payload alignment.
366 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
368 /* Named field types must be defined in lttng-types.h */
371 #define __field_full(_type, _item, _order, _base) \
372 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
374 #undef __array_enc_ext
375 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
376 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
378 #undef __dynamic_array_enc_ext
379 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
380 __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \
381 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
384 #define __string(_item, _src)
387 #define TP_PROTO(args...) args
389 #undef TP_STRUCT__entry
390 #define TP_STRUCT__entry(args...) args
392 #undef DECLARE_EVENT_CLASS
393 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
394 static inline size_t __event_get_align__##_name(_proto) \
396 size_t __event_align = 1; \
398 return __event_align; \
401 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
405 * Stage 8 of the trace events.
407 * Create structure declaration that allows the "assign" macros to access the
411 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
413 /* Named field types must be defined in lttng-types.h */
416 #define __field_full(_type, _item, _order, _base) _type _item;
418 #undef __array_enc_ext
419 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
422 #undef __dynamic_array_enc_ext
423 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
427 #define __string(_item, _src) char _item;
429 #undef TP_STRUCT__entry
430 #define TP_STRUCT__entry(args...) args
432 #undef DECLARE_EVENT_CLASS
433 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
434 struct __event_typemap__##_name { \
438 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
442 * Stage 9 of the trace events.
444 * Create the probe function : call even size calculation and write event data
447 * We use both the field and assignment macros to write the fields in the order
448 * defined in the field declaration. The field declarations control the
449 * execution order, jumping to the appropriate assignment block.
452 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
455 #define __field_full(_type, _item, _order, _base) \
456 goto __assign_##_item; \
459 #undef __array_enc_ext
460 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
461 goto __assign_##_item; \
464 #undef __dynamic_array_enc_ext
465 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
466 goto __assign_##_item##_1; \
467 __end_field_##_item##_1: \
468 goto __assign_##_item##_2; \
469 __end_field_##_item##_2:
472 #define __string(_item, _src) \
473 goto __assign_##_item; \
477 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
481 #define tp_assign(dest, src) \
484 __typeof__(__typemap.dest) __tmp = (src); \
485 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__tmp)); \
486 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
488 goto __end_field_##dest;
491 #define tp_memcpy(dest, src, len) \
494 (void) __typemap.dest; \
495 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
496 __chan->ops->event_write(&__ctx, src, len); \
497 goto __end_field_##dest;
500 #define tp_memcpy_dyn(dest, src) \
501 __assign_##dest##_1: \
503 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
504 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(u32)); \
505 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
507 goto __end_field_##dest##_1; \
508 __assign_##dest##_2: \
509 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
510 __chan->ops->event_write(&__ctx, src, \
511 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
512 goto __end_field_##dest##_2;
513 #undef tp_memcpy_from_user
514 #define tp_memcpy_from_user(dest, src, len) \
517 (void) __typemap.dest; \
518 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
519 __chan->ops->event_write_from_user(&__ctx, src, len); \
520 goto __end_field_##dest;
522 * tp_copy_string_from_user "len" parameter is the length of the string
523 * excluding the final \0.
525 #undef tp_copy_string_from_user
526 #define tp_copy_string_from_user(dest, src, len) \
529 (void) __typemap.dest; \
530 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
531 __chan->ops->event_write_from_user(&__ctx, src, len); \
532 __chan->ops->event_memset(&__ctx, 0, 1); \
533 goto __end_field_##dest;
536 #define tp_strcpy(dest, src) \
537 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
539 /* Named field types must be defined in lttng-types.h */
542 #define __get_str(field) field
544 #undef __get_dynamic_array
545 #define __get_dynamic_array(field) field
547 /* Beware: this get len actually consumes the len value */
548 #undef __get_dynamic_array_len
549 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
552 #define TP_PROTO(args...) args
555 #define TP_ARGS(args...) args
557 #undef TP_STRUCT__entry
558 #define TP_STRUCT__entry(args...) args
560 #undef TP_fast_assign
561 #define TP_fast_assign(args...) args
563 #undef DECLARE_EVENT_CLASS
564 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
565 static void __event_probe__##_name(void *__data, _proto) \
567 struct ltt_event *__event = __data; \
568 struct ltt_channel *__chan = __event->chan; \
569 struct lib_ring_buffer_ctx __ctx; \
570 size_t __event_len, __event_align; \
571 size_t __dynamic_len_idx = 0; \
572 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
573 struct __event_typemap__##_name __typemap; \
577 (void) __dynamic_len_idx; /* don't warn if unused */ \
578 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
580 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
582 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
584 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
585 __event_align = __event_get_align__##_name(_args); \
586 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
587 __event_align, -1); \
588 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
591 /* Control code (field ordering) */ \
593 __chan->ops->event_commit(&__ctx); \
595 /* Copy code, steered by control code */ \
599 #undef DECLARE_EVENT_CLASS_NOARGS
600 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
601 static void __event_probe__##_name(void *__data) \
603 struct ltt_event *__event = __data; \
604 struct ltt_channel *__chan = __event->chan; \
605 struct lib_ring_buffer_ctx __ctx; \
606 size_t __event_len, __event_align; \
609 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
611 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
613 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
617 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
618 __event_align, -1); \
619 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
622 /* Control code (field ordering) */ \
624 __chan->ops->event_commit(&__ctx); \
626 /* Copy code, steered by control code */ \
630 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
633 * Stage 10 of the trace events.
635 * Register/unregister probes at module load/unload.
638 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
640 #define TP_ID1(_token, _system) _token##_system
641 #define TP_ID(_token, _system) TP_ID1(_token, _system)
642 #define module_init_eval1(_token, _system) module_init(_token##_system)
643 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
644 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
645 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
647 #ifndef TP_MODULE_OVERRIDE
648 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
650 wrapper_vmalloc_sync_all();
651 return ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
654 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
656 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
658 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
661 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
664 #undef module_init_eval
665 #undef module_exit_eval
671 #undef TRACE_EVENT_FLAGS
This page took 0.046031 seconds and 4 git commands to generate.