54a451e53388eda82d279d3ec1a98e6a398314f0
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 __string_from_user
192 #define __string_from_user(_item, _src) \
193 __string(_item, _src)
195 #undef TP_STRUCT__entry
196 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
198 #undef DECLARE_EVENT_CLASS_NOARGS
199 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
200 static const struct lttng_event_field __event_fields___##_name[] = { \
204 #undef DECLARE_EVENT_CLASS
205 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
206 DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \
209 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
212 * Stage 3 of the trace events.
214 * Create probe callback prototypes.
217 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
220 #define TP_PROTO(args...) args
222 #undef DECLARE_EVENT_CLASS
223 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
224 static void __event_probe__##_name(void *__data, _proto);
226 #undef DECLARE_EVENT_CLASS_NOARGS
227 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
228 static void __event_probe__##_name(void *__data);
230 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
233 * Stage 3.9 of the trace events.
235 * Create event descriptions.
238 /* Named field types must be defined in lttng-types.h */
240 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
243 #define TP_PROBE_CB(_template) &__event_probe__##_template
246 #undef DEFINE_EVENT_NOARGS
247 #define DEFINE_EVENT_NOARGS(_template, _name) \
248 static const struct lttng_event_desc __event_desc___##_name = { \
249 .fields = __event_fields___##_template, \
251 .probe_callback = (void *) TP_PROBE_CB(_template), \
252 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
253 .owner = THIS_MODULE, \
257 #define DEFINE_EVENT(_template, _name, _proto, _args) \
258 DEFINE_EVENT_NOARGS(_template, _name)
260 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
264 * Stage 4 of the trace events.
266 * Create an array of event description pointers.
269 /* Named field types must be defined in lttng-types.h */
271 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
273 #undef DEFINE_EVENT_NOARGS
274 #define DEFINE_EVENT_NOARGS(_template, _name) \
275 &__event_desc___##_name,
278 #define DEFINE_EVENT(_template, _name, _proto, _args) \
279 DEFINE_EVENT_NOARGS(_template, _name)
281 #define TP_ID1(_token, _system) _token##_system
282 #define TP_ID(_token, _system) TP_ID1(_token, _system)
284 static const struct lttng_event_desc
*TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
285 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
293 * Stage 5 of the trace events.
295 * Create a toplevel descriptor for the whole probe.
298 #define TP_ID1(_token, _system) _token##_system
299 #define TP_ID(_token, _system) TP_ID1(_token, _system)
301 /* non-const because list head will be modified when registered. */
302 static __used
struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
303 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
304 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
311 * Stage 6 of the trace events.
313 * Create static inline function that calculates event size.
316 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
318 /* Named field types must be defined in lttng-types.h */
321 #define __field_full(_type, _item, _order, _base) \
322 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
323 __event_len += sizeof(_type);
325 #undef __array_enc_ext
326 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
327 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
328 __event_len += sizeof(_type) * (_length);
330 #undef __dynamic_array_enc_ext
331 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
332 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \
333 __event_len += sizeof(u32); \
334 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
335 __dynamic_len[__dynamic_len_idx] = (_length); \
336 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
340 #define __string(_item, _src) \
341 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
344 * strlen_user includes \0. If returns 0, it faulted.
346 #undef __string_from_user
347 #define __string_from_user(_item, _src) \
348 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen_user(_src);
351 #define TP_PROTO(args...) args
353 #undef TP_STRUCT__entry
354 #define TP_STRUCT__entry(args...) args
356 #undef DECLARE_EVENT_CLASS
357 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
358 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
360 size_t __event_len = 0; \
361 unsigned int __dynamic_len_idx = 0; \
364 (void) __dynamic_len_idx; /* don't warn if unused */ \
366 return __event_len; \
369 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
372 * Stage 7 of the trace events.
374 * Create static inline function that calculates event payload alignment.
377 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
379 /* Named field types must be defined in lttng-types.h */
382 #define __field_full(_type, _item, _order, _base) \
383 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
385 #undef __array_enc_ext
386 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
387 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
389 #undef __dynamic_array_enc_ext
390 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
391 __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \
392 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
395 #define __string(_item, _src)
397 #undef __string_from_user
398 #define __string_from_user(_item, _src)
401 #define TP_PROTO(args...) args
403 #undef TP_STRUCT__entry
404 #define TP_STRUCT__entry(args...) args
406 #undef DECLARE_EVENT_CLASS
407 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
408 static inline size_t __event_get_align__##_name(_proto) \
410 size_t __event_align = 1; \
412 return __event_align; \
415 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
419 * Stage 8 of the trace events.
421 * Create structure declaration that allows the "assign" macros to access the
425 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
427 /* Named field types must be defined in lttng-types.h */
430 #define __field_full(_type, _item, _order, _base) _type _item;
432 #undef __array_enc_ext
433 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
436 #undef __dynamic_array_enc_ext
437 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
441 #define __string(_item, _src) char _item;
443 #undef __string_from_user
444 #define __string_from_user(_item, _src) \
445 __string(_item, _src)
447 #undef TP_STRUCT__entry
448 #define TP_STRUCT__entry(args...) args
450 #undef DECLARE_EVENT_CLASS
451 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
452 struct __event_typemap__##_name { \
456 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
460 * Stage 9 of the trace events.
462 * Create the probe function : call even size calculation and write event data
465 * We use both the field and assignment macros to write the fields in the order
466 * defined in the field declaration. The field declarations control the
467 * execution order, jumping to the appropriate assignment block.
470 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
473 #define __field_full(_type, _item, _order, _base) \
474 goto __assign_##_item; \
477 #undef __array_enc_ext
478 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
479 goto __assign_##_item; \
482 #undef __dynamic_array_enc_ext
483 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
484 goto __assign_##_item##_1; \
485 __end_field_##_item##_1: \
486 goto __assign_##_item##_2; \
487 __end_field_##_item##_2:
490 #define __string(_item, _src) \
491 goto __assign_##_item; \
494 #undef __string_from_user
495 #define __string_from_user(_item, _src) \
496 __string(_item, _src)
499 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
503 #define tp_assign(dest, src) \
506 __typeof__(__typemap.dest) __tmp = (src); \
507 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__tmp)); \
508 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
510 goto __end_field_##dest;
513 #define tp_memcpy(dest, src, len) \
516 (void) __typemap.dest; \
517 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
518 __chan->ops->event_write(&__ctx, src, len); \
519 goto __end_field_##dest;
522 #define tp_memcpy_dyn(dest, src) \
523 __assign_##dest##_1: \
525 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
526 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(u32)); \
527 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
529 goto __end_field_##dest##_1; \
530 __assign_##dest##_2: \
531 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
532 __chan->ops->event_write(&__ctx, src, \
533 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
534 goto __end_field_##dest##_2;
536 #undef tp_memcpy_from_user
537 #define tp_memcpy_from_user(dest, src, len) \
540 (void) __typemap.dest; \
541 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
542 __chan->ops->event_write_from_user(&__ctx, src, len); \
543 goto __end_field_##dest;
546 * If string length is zero, this means reading the string faulted, so
547 * we simply put a \0. If string length is larger than 0, it is the
548 * string length including the final \0.
550 #undef tp_copy_string_from_user
551 #define tp_copy_string_from_user(dest, src) \
557 (void) __typemap.dest; \
558 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest));\
559 __ustrlen = __get_dynamic_array_len(dest); \
560 if (likely(__ustrlen) > 1) { \
561 __chan->ops->event_write_from_user(&__ctx, src, \
564 __chan->ops->event_memset(&__ctx, 0, 1); \
566 goto __end_field_##dest;
568 #define tp_strcpy(dest, src) \
569 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
571 /* Named field types must be defined in lttng-types.h */
574 #define __get_str(field) field
576 #undef __get_dynamic_array
577 #define __get_dynamic_array(field) field
579 /* Beware: this get len actually consumes the len value */
580 #undef __get_dynamic_array_len
581 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
584 #define TP_PROTO(args...) args
587 #define TP_ARGS(args...) args
589 #undef TP_STRUCT__entry
590 #define TP_STRUCT__entry(args...) args
592 #undef TP_fast_assign
593 #define TP_fast_assign(args...) args
595 #undef DECLARE_EVENT_CLASS
596 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
597 static void __event_probe__##_name(void *__data, _proto) \
599 struct ltt_event *__event = __data; \
600 struct ltt_channel *__chan = __event->chan; \
601 struct lib_ring_buffer_ctx __ctx; \
602 size_t __event_len, __event_align; \
603 size_t __dynamic_len_idx = 0; \
604 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
605 struct __event_typemap__##_name __typemap; \
609 (void) __dynamic_len_idx; /* don't warn if unused */ \
610 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
612 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
614 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
616 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
617 __event_align = __event_get_align__##_name(_args); \
618 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
619 __event_align, -1); \
620 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
623 /* Control code (field ordering) */ \
625 __chan->ops->event_commit(&__ctx); \
627 /* Copy code, steered by control code */ \
631 #undef DECLARE_EVENT_CLASS_NOARGS
632 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
633 static void __event_probe__##_name(void *__data) \
635 struct ltt_event *__event = __data; \
636 struct ltt_channel *__chan = __event->chan; \
637 struct lib_ring_buffer_ctx __ctx; \
638 size_t __event_len, __event_align; \
641 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
643 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
645 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
649 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
650 __event_align, -1); \
651 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
654 /* Control code (field ordering) */ \
656 __chan->ops->event_commit(&__ctx); \
658 /* Copy code, steered by control code */ \
662 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
665 * Stage 10 of the trace events.
667 * Register/unregister probes at module load/unload.
670 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
672 #define TP_ID1(_token, _system) _token##_system
673 #define TP_ID(_token, _system) TP_ID1(_token, _system)
674 #define module_init_eval1(_token, _system) module_init(_token##_system)
675 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
676 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
677 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
679 #ifndef TP_MODULE_OVERRIDE
680 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
682 wrapper_vmalloc_sync_all();
683 return ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
686 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
688 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
690 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
693 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
696 #undef module_init_eval
697 #undef module_exit_eval
703 #undef TRACE_EVENT_FLAGS
This page took 0.043033 seconds and 4 git commands to generate.