422f959018c47c2d05d5c91bb2e328797854cf4a
1 #include <linux/debugfs.h>
3 #include "lttng-types.h"
4 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
5 #include "../wrapper/ringbuffer/frontend_types.h"
6 #include "../ltt-events.h"
7 #include "../ltt-tracer-core.h"
10 * Macro declarations used for all stages.
14 * DECLARE_EVENT_CLASS can be used to add a generic function
15 * handlers for events. That is, if all events have the same
16 * parameters and just have distinct trace points.
17 * Each tracepoint can be defined with DEFINE_EVENT and that
18 * will map the DECLARE_EVENT_CLASS to the tracepoint.
20 * TRACE_EVENT is a one to one mapping between tracepoint and template.
24 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
25 DECLARE_EVENT_CLASS(name, \
31 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
33 #undef DEFINE_EVENT_PRINT
34 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
35 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
37 /* Callbacks are meaningless to LTTng. */
39 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
40 assign, print, reg, unreg) \
41 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
42 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
45 * Stage 1 of the trace events.
47 * Create dummy trace calls for each events, verifying that the LTTng module
48 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
52 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
55 #define TP_PROTO(args...) args
58 #define TP_ARGS(args...) args
61 #define DEFINE_EVENT(_template, _name, _proto, _args) \
62 void trace_##_name(_proto);
64 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
67 * Stage 2 of the trace events.
69 * Create event field type metadata section.
70 * Each event produce an array of fields.
73 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
75 /* Named field types must be defined in lttng-types.h */
78 #define __field(_type, _item) \
81 .type = __type_integer(_type, __BYTE_ORDER, 10), \
85 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
87 #undef __field_network
88 #define __field_network(_type, _item) \
91 .type = __type_integer(_type, __BIG_ENDIAN, 10), \
95 #define __array(_type, _item, _length) \
100 .atype = atype_array, \
104 .elem_type = __type_integer(_type, __BYTE_ORDER, 10), \
109 #undef __dynamic_array
110 #define __dynamic_array(_type, _item, _length) \
115 .atype = atype_sequence, \
118 .length_type = __type_integer(u32, __BYTE_ORDER, 10), \
119 .elem_type = __type_integer(_type, __BYTE_ORDER, 10), \
125 #define __string(_item, _src) \
130 .atype = atype_string, \
131 .u.basic.string.encoding = lttng_encode_UTF8, \
135 #undef TP_STRUCT__entry
136 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
138 #undef DECLARE_EVENT_CLASS
139 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
140 static const struct lttng_event_field __event_fields___##_name[] = { \
144 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
146 #undef __type_integer
149 * Stage 3 of the trace events.
151 * Create probe callback prototypes.
154 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
157 #define TP_PROTO(args...) args
159 #undef DECLARE_EVENT_CLASS
160 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
161 static void __event_probe__##_name(void *__data, _proto);
163 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
166 * Stage 4 of the trace events.
168 * Create an array of events.
171 /* Named field types must be defined in lttng-types.h */
173 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
176 #define DEFINE_EVENT(_template, _name, _proto, _args) \
178 .fields = __event_fields___##_template, \
180 .probe_callback = (void *) &__event_probe__##_template,\
181 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
184 #define TP_ID1(_token, _system) _token##_system
185 #define TP_ID(_token, _system) TP_ID1(_token, _system)
187 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
188 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
196 * Stage 5 of the trace events.
198 * Create a toplevel descriptor for the whole probe.
201 #define TP_ID1(_token, _system) _token##_system
202 #define TP_ID(_token, _system) TP_ID1(_token, _system)
204 /* non-const because list head will be modified when registered. */
205 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
206 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
207 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
214 * Stage 6 of the trace events.
216 * Create static inline function that calculates event size.
219 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
221 /* Named field types must be defined in lttng-types.h */
224 #define __field(_type, _item) \
225 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
226 __event_len += sizeof(_type);
229 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
232 #define __array(_type, _item, _length) \
233 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
234 __event_len += sizeof(_type) * (_length);
236 #undef __dynamic_array
237 #define __dynamic_array(_type, _item, _length) \
238 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \
239 __event_len += sizeof(u32); \
240 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
241 __event_len += sizeof(_type) * (_length);
244 #define __string(_item, _src) \
245 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
248 #define TP_PROTO(args...) args
250 #undef TP_STRUCT__entry
251 #define TP_STRUCT__entry(args...) args
253 #undef DECLARE_EVENT_CLASS
254 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
255 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
257 size_t __event_len = 0; \
258 unsigned int __dynamic_len_idx = 0; \
261 (void) __dynamic_len_idx; /* don't warn if unused */ \
263 return __event_len; \
266 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
269 * Stage 7 of the trace events.
271 * Create static inline function that calculates event payload alignment.
274 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
276 /* Named field types must be defined in lttng-types.h */
279 #define __field(_type, _item) \
280 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
283 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
286 #define __array(_type, _item, _length) \
287 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
289 #undef __dynamic_array
290 #define __dynamic_array(_type, _item, _length) \
291 __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \
292 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
295 #define __string(_item, _src)
298 #define TP_PROTO(args...) args
300 #undef TP_STRUCT__entry
301 #define TP_STRUCT__entry(args...) args
303 #undef DECLARE_EVENT_CLASS
304 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
305 static inline size_t __event_get_align__##_name(_proto) \
307 size_t __event_align = 1; \
309 return __event_align; \
312 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
316 * Stage 8 of the trace events.
318 * Create structure declaration that allows the "assign" macros to access the
322 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
324 /* Named field types must be defined in lttng-types.h */
327 #define __field(_type, _item) _type _item;
330 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
333 #define __array(_type, _item, _length) _type _item;
335 #undef __dynamic_array
336 #define __dynamic_array(_type, _item, _length) _type _item;
339 #define __string(_item, _src) char _item;
341 #undef TP_STRUCT__entry
342 #define TP_STRUCT__entry(args...) args
344 #undef DECLARE_EVENT_CLASS
345 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
346 struct __event_typemap__##_name { \
350 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
354 * Stage 9 of the trace events.
356 * Create the probe function : call even size calculation and write event data
359 * We use both the field and assignment macros to write the fields in the order
360 * defined in the field declaration. The field declarations control the
361 * execution order, jumping to the appropriate assignment block.
364 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
367 #define __field(_type, _item) \
368 goto __assign_##_item; \
372 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
375 #define __array(_type, _item, _length) \
376 goto __assign_##_item; \
379 #undef __dynamic_array
380 #define __dynamic_array(_type, _item, _length) \
381 goto __assign_##_item##_1; \
382 __end_field_##_item##_1: \
383 goto __assign_##_item##_2; \
384 __end_field_##_item##_2:
387 #define __string(_item, _src) \
388 goto __assign_##_item; \
392 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
396 #define tp_assign(dest, src) \
399 __typeof__(__typemap.dest) __tmp = (src); \
400 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \
401 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
403 goto __end_field_##dest;
406 #define tp_memcpy(dest, src, len) \
409 (void) __typemap.dest; \
410 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__typemap.dest)); \
411 __chan->ops->event_write(&ctx, src, len); \
412 goto __end_field_##dest;
415 #define tp_memcpy_dyn(dest, src, len) \
416 __assign_##dest##_1: \
418 u32 __tmpl = (len); \
419 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(u32)); \
420 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
422 goto __end_field_##dest##_1; \
423 __assign_##dest##_2: \
424 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__typemap.dest)); \
425 __chan->ops->event_write(&ctx, src, len); \
426 goto __end_field_##dest##_2;
429 #define tp_strcpy(dest, src) \
430 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
432 /* Named field types must be defined in lttng-types.h */
435 #define __get_str(field) field
437 #undef __get_dynamic_array
438 #define __get_dynamic_array(field) field
440 /* Beware: this get len actually consumes the len value */
441 #undef __get_dynamic_array_len
442 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
445 #define TP_PROTO(args...) args
448 #define TP_ARGS(args...) args
450 #undef TP_STRUCT__entry
451 #define TP_STRUCT__entry(args...) args
453 #undef TP_fast_assign
454 #define TP_fast_assign(args...) args
456 #undef DECLARE_EVENT_CLASS
457 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
458 static void __event_probe__##_name(void *__data, _proto) \
460 struct ltt_event *__event = __data; \
461 struct ltt_channel *__chan = __event->chan; \
462 struct lib_ring_buffer_ctx ctx; \
463 size_t __event_len, __event_align; \
464 size_t __dynamic_len_idx = 0; \
465 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
466 struct __event_typemap__##_name __typemap; \
470 (void) __dynamic_len_idx; /* don't warn if unused */ \
471 if (!ACCESS_ONCE(__chan->session->active)) \
473 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
474 __event_align = __event_get_align__##_name(_args); \
475 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
476 __event_align, -1); \
477 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
480 /* Control code (field ordering) */ \
482 __chan->ops->event_commit(&ctx); \
484 /* Copy code, steered by control code */ \
488 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
491 * Stage 10 of the trace events.
493 * Register/unregister probes at module load/unload.
496 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
498 #define TP_ID1(_token, _system) _token##_system
499 #define TP_ID(_token, _system) TP_ID1(_token, _system)
500 #define module_init_eval1(_token, _system) module_init(_token##_system)
501 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
502 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
503 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
505 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
507 wrapper_vmalloc_sync_all();
508 return ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
511 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
513 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
515 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
518 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
520 #undef module_init_eval
521 #undef module_exit_eval
This page took 0.053588 seconds and 4 git commands to generate.