a739bbc8e20dce85b35fdaa3476ab0f591bc220e
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 0.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 1 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) \
79 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
82 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
85 #define __array(_type, _item, _length) \
89 .atype = atype_array, \
91 .u.array.elem_type = #_type, \
92 .u.array.length = _length, \
96 #undef __dynamic_array
97 #define __dynamic_array(_type, _item, _length) \
101 .atype = atype_sequence, \
103 .u.sequence.elem_type = #_type, \
104 .u.sequence.length_type = "u32", \
109 #define __string(_item, _src) \
113 .atype = atype_string, \
115 .u.string.encoding = lttng_encode_UTF8, \
119 #undef TP_STRUCT__entry
120 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
122 #undef DECLARE_EVENT_CLASS
123 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
124 static const struct lttng_event_field __event_fields___##_name[] = { \
128 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
131 * Stage 1.1 of the trace events.
133 * Create probe callback prototypes.
136 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
139 #define TP_PROTO(args...) args
141 #undef DECLARE_EVENT_CLASS
142 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
143 static void __event_probe__##_name(void *__data, _proto);
145 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
148 * Stage 2 of the trace events.
150 * Create an array of events.
153 /* Named field types must be defined in lttng-types.h */
155 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
158 #define DEFINE_EVENT(_template, _name, _proto, _args) \
160 .fields = __event_fields___##_template, \
162 .probe_callback = (void *) &__event_probe__##_template,\
163 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
166 #define TP_ID1(_token, _system) _token##_system
167 #define TP_ID(_token, _system) TP_ID1(_token, _system)
169 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
170 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
178 * Stage 2.1 of the trace events.
180 * Create a toplevel descriptor for the whole probe.
183 #define TP_ID1(_token, _system) _token##_system
184 #define TP_ID(_token, _system) TP_ID1(_token, _system)
186 /* non-const because list head will be modified when registered. */
187 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
188 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
189 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
196 * Stage 3 of the trace events.
198 * Create seq file metadata output.
201 #define TP_ID1(_token, _system) _token##_system
202 #define TP_ID(_token, _system) TP_ID1(_token, _system)
204 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
207 const struct lttng_event_desc
*desc
=
208 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
210 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
211 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
213 return (void *) desc
;
216 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
217 void *p
, loff_t
*ppos
)
219 const struct lttng_event_desc
*desc
=
220 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
222 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
223 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
225 return (void *) desc
;
228 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
233 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
236 const struct lttng_event_desc
*desc
= p
;
239 seq_printf(m
, "event {\n"
242 "\tstream = UNKNOWN;\n"
245 for (i
= 0; i
< desc
->nr_fields
; i
++) {
246 if (desc
->fields
[i
].type
.name
) /* Named type */
247 seq_printf(m
, "\t\t%s",
248 desc
->fields
[i
].type
.name
);
249 else /* Nameless type */
250 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
251 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
253 seq_printf(m
, "\t};\n");
254 seq_printf(m
, "};\n");
259 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
260 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
261 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
262 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
263 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
267 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
269 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
273 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
274 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
277 .release
= seq_release_private
,
280 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
282 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
286 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
287 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
289 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
290 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
291 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
292 printk(KERN_ERR
"Error creating LTTng type export file\n");
300 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
302 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
309 * Stage 4 of the trace events.
311 * Create static inline function that calculates event size.
314 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
316 /* Named field types must be defined in lttng-types.h */
319 #define __field(_type, _item) \
320 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
321 __event_len += sizeof(_type);
324 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
327 #define __array(_type, _item, _length) \
328 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
329 __event_len += sizeof(_type) * (_length);
331 #undef __dynamic_array
332 #define __dynamic_array(_type, _item, _length) \
333 __event_len += lib_ring_buffer_align(__event_len, __alignof__(u32)); \
334 __event_len += sizeof(u32); \
335 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
336 __event_len += sizeof(_type) * (_length);
339 #define __string(_item, _src) \
340 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
343 #define TP_PROTO(args...) args
345 #undef TP_STRUCT__entry
346 #define TP_STRUCT__entry(args...) args
348 #undef DECLARE_EVENT_CLASS
349 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
350 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
352 size_t __event_len = 0; \
353 unsigned int __dynamic_len_idx = 0; \
356 (void) __dynamic_len_idx; /* don't warn if unused */ \
358 return __event_len; \
361 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
366 * Stage 5 of the trace events.
368 * Create static inline function that calculates event payload alignment.
371 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
373 /* Named field types must be defined in lttng-types.h */
376 #define __field(_type, _item) \
377 __event_align = max_t(size_t, __event_align, __alignof__(_type));
380 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
383 #define __array(_type, _item, _length) \
384 __event_align = max_t(size_t, __event_align, __alignof__(_type));
386 #undef __dynamic_array
387 #define __dynamic_array(_type, _item, _length) \
388 __event_align = max_t(size_t, __event_align, __alignof__(u32)); \
389 __event_align = max_t(size_t, __event_align, __alignof__(_type));
392 #define __string(_item, _src)
395 #define TP_PROTO(args...) args
397 #undef TP_STRUCT__entry
398 #define TP_STRUCT__entry(args...) args
400 #undef DECLARE_EVENT_CLASS
401 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
402 static inline size_t __event_get_align__##_name(_proto) \
404 size_t __event_align = 1; \
406 return __event_align; \
409 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
413 * Stage 6 of the trace events.
415 * Create structure declaration that allows the "assign" macros to access the
419 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
421 /* Named field types must be defined in lttng-types.h */
424 #define __field(_type, _item) _type _item;
427 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
430 #define __array(_type, _item, _length) _type _item;
432 #undef __dynamic_array
433 #define __dynamic_array(_type, _item, _length) _type _item;
436 #define __string(_item, _src) char _item;
438 #undef TP_STRUCT__entry
439 #define TP_STRUCT__entry(args...) args
441 #undef DECLARE_EVENT_CLASS
442 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
443 struct __event_typemap__##_name { \
447 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
451 * Stage 7 of the trace events.
453 * Create the probe function : call even size calculation and write event data
456 * We use both the field and assignment macros to write the fields in the order
457 * defined in the field declaration. The field declarations control the
458 * execution order, jumping to the appropriate assignment block.
461 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
464 #define __field(_type, _item) \
465 goto __assign_##_item; \
469 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
472 #define __array(_type, _item, _length) \
473 goto __assign_##_item; \
476 #undef __dynamic_array
477 #define __dynamic_array(_type, _item, _length) \
478 goto __assign_##_item##_1; \
479 __end_field_##_item##_1: \
480 goto __assign_##_item##_2; \
481 __end_field_##_item##_2:
484 #define __string(_item, _src) \
485 goto __assign_##_item; \
489 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
493 #define tp_assign(dest, src) \
496 __typeof__(__typemap.dest) __tmp = (src); \
497 lib_ring_buffer_align_ctx(&ctx, __alignof__(__tmp)); \
498 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
500 goto __end_field_##dest;
503 #define tp_memcpy(dest, src, len) \
505 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
506 __chan->ops->event_write(&ctx, src, len); \
507 goto __end_field_##dest;
510 #define tp_memcpy_dyn(dest, src, len) \
511 __assign_##dest##_1: \
513 u32 __tmpl = (len); \
514 lib_ring_buffer_align_ctx(&ctx, __alignof__(u32)); \
515 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
517 goto __end_field_##dest##_1; \
518 __assign_##dest##_2: \
519 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
520 __chan->ops->event_write(&ctx, src, len); \
521 goto __end_field_##dest##_2;
524 #define tp_strcpy(dest, src) \
525 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
527 /* Named field types must be defined in lttng-types.h */
530 #define __get_str(field) field
532 #undef __get_dynamic_array
533 #define __get_dynamic_array(field) field
535 /* Beware: this get len actually consumes the len value */
536 #undef __get_dynamic_array_len
537 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
540 #define TP_PROTO(args...) args
543 #define TP_ARGS(args...) args
545 #undef TP_STRUCT__entry
546 #define TP_STRUCT__entry(args...) args
548 #undef TP_fast_assign
549 #define TP_fast_assign(args...) args
551 #undef DECLARE_EVENT_CLASS
552 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
553 static void __event_probe__##_name(void *__data, _proto) \
555 struct ltt_event *__event = __data; \
556 struct ltt_channel *__chan = __event->chan; \
557 struct lib_ring_buffer_ctx ctx; \
558 size_t __event_len, __event_align; \
559 size_t __dynamic_len_idx = 0; \
560 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
561 struct __event_typemap__##_name __typemap; \
565 (void) __dynamic_len_idx; /* don't warn if unused */ \
566 if (!ACCESS_ONCE(__chan->session->active)) \
568 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
569 __event_align = __event_get_align__##_name(_args); \
570 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
571 __event_align, -1); \
572 __ret = __chan->ops->event_reserve(&ctx); \
575 /* Control code (field ordering) */ \
577 __chan->ops->event_commit(&ctx); \
579 /* Copy code, steered by control code */ \
583 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
586 * Stage 8 of the trace events.
588 * Register/unregister probes at module load/unload.
591 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
593 #define TP_ID1(_token, _system) _token##_system
594 #define TP_ID(_token, _system) TP_ID1(_token, _system)
595 #define module_init_eval1(_token, _system) module_init(_token##_system)
596 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
597 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
598 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
600 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
604 wrapper_vmalloc_sync_all();
605 ret
= TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)();
608 return ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
611 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
613 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
615 TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)();
616 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
619 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
621 #undef module_init_eval
622 #undef module_exit_eval
This page took 0.045597 seconds and 4 git commands to generate.