b0152829966f8d290264acb94b0ee8706513c225
4 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
7 #define tp_assign(dest, src) \
8 lib_ring_buffer_align_ctx(config, &ctx, sizeof(src)); \
9 lib_ring_buffer_write(config, &ctx, &src, sizeof(src));
11 #define tp_memcpy(dest, src, len) \
12 lib_ring_buffer_align_ctx(config, &ctx, sizeof(*(src))); \
13 lib_ring_buffer_write(config, &ctx, &src, len);
16 #define tp_strcpy(dest, src) __assign_str(dest, src)
19 * Stage 1 of the trace events.
21 * Create event field type metadata section.
25 * DECLARE_EVENT_CLASS can be used to add a generic function
26 * handlers for events. That is, if all events have the same
27 * parameters and just have distinct trace points.
28 * Each tracepoint can be defined with DEFINE_EVENT and that
29 * will map the DECLARE_EVENT_CLASS to the tracepoint.
31 * TRACE_EVENT is a one to one mapping between tracepoint and template.
34 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
35 DECLARE_EVENT_CLASS(name, \
41 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
43 /* Field types must be defined in lttng-types.h */
46 #define __field(type, item) type item;
49 #define __field_ext(type, item, filter_type) type item;
52 #define __array(type, item, len) \
53 type { parent = array; length = len; elem_type = type; } item;
57 #undef __dynamic_array
58 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
61 #define __string(item, src) __dynamic_array(char, item, -1)
63 #undef TP_STRUCT__entry
64 #define TP_STRUCT__entry(args...) args
66 #undef DECLARE_EVENT_CLASS
67 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
68 struct ftrace_raw_##name { \
69 struct trace_entry ent; \
74 static struct ftrace_event_class event_class_##name;
77 #define DEFINE_EVENT(template, name, proto, args) \
78 static struct ftrace_event_call __used \
79 __attribute__((__aligned__(4))) event_##name
81 #undef DEFINE_EVENT_PRINT
82 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
83 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
85 /* Callbacks are meaningless to ftrace. */
87 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
88 assign, print, reg, unreg) \
89 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
90 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
95 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
98 * Stage 2 of the trace events.
100 * Create static inline function that calculates event size.
105 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
108 * Stage 3 of the trace events.
110 * Create the probe function : call even size calculation and write event data
116 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
121 #include <linux/ftrace_event.h>
124 * DECLARE_EVENT_CLASS can be used to add a generic function
125 * handlers for events. That is, if all events have the same
126 * parameters and just have distinct trace points.
127 * Each tracepoint can be defined with DEFINE_EVENT and that
128 * will map the DECLARE_EVENT_CLASS to the tracepoint.
130 * TRACE_EVENT is a one to one mapping between tracepoint and template.
133 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
134 DECLARE_EVENT_CLASS(name, \
140 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
144 #define __field(type, item) type item;
147 #define __field_ext(type, item, filter_type) type item;
150 #define __array(type, item, len) type item[len];
152 #undef __dynamic_array
153 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
156 #define __string(item, src) __dynamic_array(char, item, -1)
158 #undef TP_STRUCT__entry
159 #define TP_STRUCT__entry(args...) args
161 #undef DECLARE_EVENT_CLASS
162 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
163 struct ftrace_raw_##name { \
164 struct trace_entry ent; \
169 static struct ftrace_event_class event_class_##name;
172 #define DEFINE_EVENT(template, name, proto, args) \
173 static struct ftrace_event_call __used \
174 __attribute__((__aligned__(4))) event_##name
176 #undef DEFINE_EVENT_PRINT
177 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
178 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
180 /* Callbacks are meaningless to ftrace. */
181 #undef TRACE_EVENT_FN
182 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
183 assign, print, reg, unreg) \
184 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
185 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
187 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
191 * Stage 2 of the trace events.
193 * Create static inline function that calculates event size.
197 #define __field(type, item)
200 #define __field_ext(type, item, filter_type)
203 #define __array(type, item, len)
205 #undef __dynamic_array
206 #define __dynamic_array(type, item, len) u32 item;
209 #define __string(item, src) __dynamic_array(char, item, -1)
211 #undef DECLARE_EVENT_CLASS
212 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
213 struct ftrace_data_offsets_##call { \
218 #define DEFINE_EVENT(template, name, proto, args)
220 #undef DEFINE_EVENT_PRINT
221 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
222 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
224 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
227 * Stage 3 of the trace events.
229 * Create the probe function : call even size calculation and write event data
234 #define __entry field
237 #define TP_printk(fmt, args...) fmt "\n", args
239 #undef __get_dynamic_array
240 #define __get_dynamic_array(field) \
241 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
244 #define __get_str(field) (char *)__get_dynamic_array(field)
247 #define __print_flags(flag, delim, flag_array...) \
249 static const struct trace_print_flags __flags[] = \
250 { flag_array, { -1, NULL }}; \
251 ftrace_print_flags_seq(p, delim, flag, __flags); \
254 #undef __print_symbolic
255 #define __print_symbolic(value, symbol_array...) \
257 static const struct trace_print_flags symbols[] = \
258 { symbol_array, { -1, NULL }}; \
259 ftrace_print_symbols_seq(p, value, symbols); \
263 #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
265 #undef DECLARE_EVENT_CLASS
266 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
267 static notrace enum print_line_t \
268 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
269 struct trace_event *trace_event) \
271 struct ftrace_event_call *event; \
272 struct trace_seq *s = &iter->seq; \
273 struct ftrace_raw_##call *field; \
274 struct trace_entry *entry; \
275 struct trace_seq *p = &iter->tmp_seq; \
278 event = container_of(trace_event, struct ftrace_event_call, \
283 if (entry->type != event->event.type) { \
285 return TRACE_TYPE_UNHANDLED; \
288 field = (typeof(field))entry; \
291 ret = trace_seq_printf(s, "%s: ", event->name); \
293 ret = trace_seq_printf(s, print); \
295 return TRACE_TYPE_PARTIAL_LINE; \
297 return TRACE_TYPE_HANDLED; \
299 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
300 .trace = ftrace_raw_output_##call, \
303 #undef DEFINE_EVENT_PRINT
304 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
305 static notrace enum print_line_t \
306 ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
307 struct trace_event *event) \
309 struct trace_seq *s = &iter->seq; \
310 struct ftrace_raw_##template *field; \
311 struct trace_entry *entry; \
312 struct trace_seq *p = &iter->tmp_seq; \
317 if (entry->type != event_##call.event.type) { \
319 return TRACE_TYPE_UNHANDLED; \
322 field = (typeof(field))entry; \
325 ret = trace_seq_printf(s, "%s: ", #call); \
327 ret = trace_seq_printf(s, print); \
329 return TRACE_TYPE_PARTIAL_LINE; \
331 return TRACE_TYPE_HANDLED; \
333 static struct trace_event_functions ftrace_event_type_funcs_##call = { \
334 .trace = ftrace_raw_output_##call, \
337 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
340 #define __field_ext(type, item, filter_type) \
341 ret = trace_define_field(event_call, #type, #item, \
342 offsetof(typeof(field), item), \
343 sizeof(field.item), \
344 is_signed_type(type), filter_type); \
349 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
352 #define __array(type, item, len) \
353 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
354 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
355 offsetof(typeof(field), item), \
356 sizeof(field.item), \
357 is_signed_type(type), FILTER_OTHER); \
361 #undef __dynamic_array
362 #define __dynamic_array(type, item, len) \
363 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
364 offsetof(typeof(field), __data_loc_##item), \
365 sizeof(field.__data_loc_##item), \
366 is_signed_type(type), FILTER_OTHER);
369 #define __string(item, src) __dynamic_array(char, item, -1)
371 #undef DECLARE_EVENT_CLASS
372 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
374 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
376 struct ftrace_raw_##call field; \
385 #define DEFINE_EVENT(template, name, proto, args)
387 #undef DEFINE_EVENT_PRINT
388 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
389 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
391 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
394 * remember the offset of each array from the beginning of the event.
398 #define __entry entry
401 #define __field(type, item)
404 #define __field_ext(type, item, filter_type)
407 #define __array(type, item, len)
409 #undef __dynamic_array
410 #define __dynamic_array(type, item, len) \
411 __data_offsets->item = __data_size + \
412 offsetof(typeof(*entry), __data); \
413 __data_offsets->item |= (len * sizeof(type)) << 16; \
414 __data_size += (len) * sizeof(type);
417 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
419 #undef DECLARE_EVENT_CLASS
420 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
421 static inline notrace int ftrace_get_offsets_##call( \
422 struct ftrace_data_offsets_##call *__data_offsets, proto) \
424 int __data_size = 0; \
425 struct ftrace_raw_##call __maybe_unused *entry; \
429 return __data_size; \
433 #define DEFINE_EVENT(template, name, proto, args)
435 #undef DEFINE_EVENT_PRINT
436 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
437 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
439 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
442 * Stage 4 of the trace events.
444 * Override the macros in <trace/trace_events.h> to include the following:
446 * For those macros defined with TRACE_EVENT:
448 * static struct ftrace_event_call event_<call>;
450 * static void ftrace_raw_event_<call>(void *__data, proto)
452 * struct ftrace_event_call *event_call = __data;
453 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
454 * struct ring_buffer_event *event;
455 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
456 * struct ring_buffer *buffer;
457 * unsigned long irq_flags;
461 * local_save_flags(irq_flags);
462 * pc = preempt_count();
464 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
466 * event = trace_current_buffer_lock_reserve(&buffer,
467 * event_<call>->event.type,
468 * sizeof(*entry) + __data_size,
472 * entry = ring_buffer_event_data(event);
474 * { <assign>; } <-- Here we assign the entries by the __field and
477 * if (!filter_current_check_discard(buffer, event_call, entry, event))
478 * trace_current_buffer_unlock_commit(buffer,
479 * event, irq_flags, pc);
482 * static struct trace_event ftrace_event_type_<call> = {
483 * .trace = ftrace_raw_output_<call>, <-- stage 2
486 * static const char print_fmt_<call>[] = <TP_printk>;
488 * static struct ftrace_event_class __used event_class_<template> = {
489 * .system = "<system>",
490 * .define_fields = ftrace_define_fields_<call>,
491 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
492 * .raw_init = trace_event_raw_init,
493 * .probe = ftrace_raw_event_##call,
494 * .reg = ftrace_event_reg,
497 * static struct ftrace_event_call __used
498 * __attribute__((__aligned__(4)))
499 * __attribute__((section("_ftrace_events"))) event_<call> = {
501 * .class = event_class_<template>,
502 * .event = &ftrace_event_type_<call>,
503 * .print_fmt = print_fmt_<call>,
508 #ifdef CONFIG_PERF_EVENTS
510 #define _TRACE_PERF_PROTO(call, proto) \
511 static notrace void \
512 perf_trace_##call(void *__data, proto);
514 #define _TRACE_PERF_INIT(call) \
515 .perf_probe = perf_trace_##call,
518 #define _TRACE_PERF_PROTO(call, proto)
519 #define _TRACE_PERF_INIT(call)
520 #endif /* CONFIG_PERF_EVENTS */
523 #define __entry entry
526 #define __field(type, item)
529 #define __array(type, item, len)
531 #undef __dynamic_array
532 #define __dynamic_array(type, item, len) \
533 __entry->__data_loc_##item = __data_offsets.item;
536 #define __string(item, src) __dynamic_array(char, item, -1) \
539 #define __assign_str(dst, src) \
540 strcpy(__get_str(dst), src);
542 #undef TP_fast_assign
543 #define TP_fast_assign(args...) args
545 #undef TP_perf_assign
546 #define TP_perf_assign(args...)
548 #undef DECLARE_EVENT_CLASS
549 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
551 static notrace void \
552 ftrace_raw_event_##call(void *__data, proto) \
554 struct ftrace_event_call *event_call = __data; \
555 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
556 struct ring_buffer_event *event; \
557 struct ftrace_raw_##call *entry; \
558 struct ring_buffer *buffer; \
559 unsigned long irq_flags; \
563 local_save_flags(irq_flags); \
564 pc = preempt_count(); \
566 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
568 event = trace_current_buffer_lock_reserve(&buffer, \
569 event_call->event.type, \
570 sizeof(*entry) + __data_size, \
574 entry = ring_buffer_event_data(event); \
580 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
581 trace_nowake_buffer_unlock_commit(buffer, \
582 event, irq_flags, pc); \
585 * The ftrace_test_probe is compiled out, it is only here as a build time check
586 * to make sure that if the tracepoint handling changes, the ftrace probe will
587 * fail to compile unless it too is updated.
591 #define DEFINE_EVENT(template, call, proto, args) \
592 static inline void ftrace_test_probe_##call(void) \
594 check_trace_callback_type_##call(ftrace_raw_event_##template); \
597 #undef DEFINE_EVENT_PRINT
598 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
600 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
606 #undef __print_symbolic
607 #undef __get_dynamic_array
611 #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
613 #undef DECLARE_EVENT_CLASS
614 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
615 _TRACE_PERF_PROTO(call, PARAMS(proto)); \
616 static const char print_fmt_##call[] = print; \
617 static struct ftrace_event_class __used event_class_##call = { \
618 .system = __stringify(TRACE_SYSTEM), \
619 .define_fields = ftrace_define_fields_##call, \
620 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
621 .raw_init = trace_event_raw_init, \
622 .probe = ftrace_raw_event_##call, \
623 .reg = ftrace_event_reg, \
624 _TRACE_PERF_INIT(call) \
628 #define DEFINE_EVENT(template, call, proto, args) \
630 static struct ftrace_event_call __used \
631 __attribute__((__aligned__(4))) \
632 __attribute__((section("_ftrace_events"))) event_##call = { \
634 .class = &event_class_##template, \
635 .event.funcs = &ftrace_event_type_funcs_##template, \
636 .print_fmt = print_fmt_##template, \
639 #undef DEFINE_EVENT_PRINT
640 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
642 static const char print_fmt_##call[] = print; \
644 static struct ftrace_event_call __used \
645 __attribute__((__aligned__(4))) \
646 __attribute__((section("_ftrace_events"))) event_##call = { \
648 .class = &event_class_##template, \
649 .event.funcs = &ftrace_event_type_funcs_##call, \
650 .print_fmt = print_fmt_##call, \
653 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
656 * Define the insertion callback to perf events
658 * The job is very similar to ftrace_raw_event_<call> except that we don't
659 * insert in the ring buffer but in a perf counter.
661 * static void ftrace_perf_<call>(proto)
663 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
664 * struct ftrace_event_call *event_call = &event_<call>;
665 * extern void perf_tp_event(int, u64, u64, void *, int);
666 * struct ftrace_raw_##call *entry;
667 * struct perf_trace_buf *trace_buf;
668 * u64 __addr = 0, __count = 1;
669 * unsigned long irq_flags;
670 * struct trace_entry *ent;
676 * pc = preempt_count();
678 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
680 * // Below we want to get the aligned size by taking into account
681 * // the u32 field that will later store the buffer size
682 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
684 * __entry_size -= sizeof(u32);
686 * // Protect the non nmi buffer
687 * // This also protects the rcu read side
688 * local_irq_save(irq_flags);
689 * __cpu = smp_processor_id();
692 * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
694 * trace_buf = rcu_dereference_sched(perf_trace_buf);
699 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
701 * // Avoid recursion from perf that could mess up the buffer
702 * if (trace_buf->recursion++)
703 * goto end_recursion;
705 * raw_data = trace_buf->buf;
707 * // Make recursion update visible before entering perf_tp_event
708 * // so that we protect from perf recursions.
712 * //zero dead bytes from alignment to avoid stack leak to userspace:
713 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
714 * entry = (struct ftrace_raw_<call> *)raw_data;
716 * tracing_generic_entry_update(ent, irq_flags, pc);
717 * ent->type = event_call->id;
719 * <tstruct> <- do some jobs with dynamic arrays
721 * <assign> <- affect our values
723 * perf_tp_event(event_call->id, __addr, __count, entry,
724 * __entry_size); <- submit them to perf counter
729 #ifdef CONFIG_PERF_EVENTS
732 #define __entry entry
734 #undef __get_dynamic_array
735 #define __get_dynamic_array(field) \
736 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
739 #define __get_str(field) (char *)__get_dynamic_array(field)
742 #define __perf_addr(a) __addr = (a)
745 #define __perf_count(c) __count = (c)
747 #undef DECLARE_EVENT_CLASS
748 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
749 static notrace void \
750 perf_trace_##call(void *__data, proto) \
752 struct ftrace_event_call *event_call = __data; \
753 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
754 struct ftrace_raw_##call *entry; \
755 struct pt_regs __regs; \
756 u64 __addr = 0, __count = 1; \
757 struct hlist_head *head; \
762 perf_fetch_caller_regs(&__regs); \
764 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
765 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
767 __entry_size -= sizeof(u32); \
769 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
770 "profile buffer not large enough")) \
773 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
774 __entry_size, event_call->event.type, &__regs, &rctx); \
782 head = this_cpu_ptr(event_call->perf_events); \
783 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
784 __count, &__regs, head); \
788 * This part is compiled out, it is only here as a build time check
789 * to make sure that if the tracepoint handling changes, the
790 * perf probe will fail to compile unless it too is updated.
793 #define DEFINE_EVENT(template, call, proto, args) \
794 static inline void perf_test_probe_##call(void) \
796 check_trace_callback_type_##call(perf_trace_##template); \
800 #undef DEFINE_EVENT_PRINT
801 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
802 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
804 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
805 #endif /* CONFIG_PERF_EVENTS */
807 #undef _TRACE_PROFILE_INIT
This page took 0.047518 seconds and 4 git commands to generate.