libertas: fix cmdpendingq locking
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / trace / ftrace.h
blob1ca49902094c86015e5db33b235c4643836c0d74
1 /*
2 * Stage 1 of the trace events.
4 * Override the macros in <trace/trace_events.h> to include the following:
6 * struct ftrace_raw_<call> {
7 * struct trace_entry ent;
8 * <type> <item>;
9 * <type2> <item2>[<len>];
10 * [...]
11 * };
13 * The <type> <item> is created by the __field(type, item) macro or
14 * the __array(type2, item2, len) macro.
15 * We simply do "type item;", and that will create the fields
16 * in the structure.
19 #include <linux/ftrace_event.h>
22 * DECLARE_EVENT_CLASS can be used to add a generic function
23 * handlers for events. That is, if all events have the same
24 * parameters and just have distinct trace points.
25 * Each tracepoint can be defined with DEFINE_EVENT and that
26 * will map the DECLARE_EVENT_CLASS to the tracepoint.
28 * TRACE_EVENT is a one to one mapping between tracepoint and template.
30 #undef TRACE_EVENT
31 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
32 DECLARE_EVENT_CLASS(name, \
33 PARAMS(proto), \
34 PARAMS(args), \
35 PARAMS(tstruct), \
36 PARAMS(assign), \
37 PARAMS(print)); \
38 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
41 #undef __field
42 #define __field(type, item) type item;
44 #undef __field_ext
45 #define __field_ext(type, item, filter_type) type item;
47 #undef __array
48 #define __array(type, item, len) type item[len];
50 #undef __dynamic_array
51 #define __dynamic_array(type, item, len) u32 __data_loc_##item;
53 #undef __string
54 #define __string(item, src) __dynamic_array(char, item, -1)
56 #undef TP_STRUCT__entry
57 #define TP_STRUCT__entry(args...) args
59 #undef DECLARE_EVENT_CLASS
60 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
61 struct ftrace_raw_##name { \
62 struct trace_entry ent; \
63 tstruct \
64 char __data[0]; \
66 #undef DEFINE_EVENT
67 #define DEFINE_EVENT(template, name, proto, args) \
68 static struct ftrace_event_call \
69 __attribute__((__aligned__(4))) event_##name
71 #undef DEFINE_EVENT_PRINT
72 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
73 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
75 #undef __cpparg
76 #define __cpparg(arg...) arg
78 /* Callbacks are meaningless to ftrace. */
79 #undef TRACE_EVENT_FN
80 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
81 assign, print, reg, unreg) \
82 TRACE_EVENT(name, __cpparg(proto), __cpparg(args), \
83 __cpparg(tstruct), __cpparg(assign), __cpparg(print)) \
85 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
89 * Stage 2 of the trace events.
91 * Include the following:
93 * struct ftrace_data_offsets_<call> {
94 * u32 <item1>;
95 * u32 <item2>;
96 * [...]
97 * };
99 * The __dynamic_array() macro will create each u32 <item>, this is
100 * to keep the offset of each array from the beginning of the event.
101 * The size of an array is also encoded, in the higher 16 bits of <item>.
104 #undef __field
105 #define __field(type, item)
107 #undef __field_ext
108 #define __field_ext(type, item, filter_type)
110 #undef __array
111 #define __array(type, item, len)
113 #undef __dynamic_array
114 #define __dynamic_array(type, item, len) u32 item;
116 #undef __string
117 #define __string(item, src) __dynamic_array(char, item, -1)
119 #undef DECLARE_EVENT_CLASS
120 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
121 struct ftrace_data_offsets_##call { \
122 tstruct; \
125 #undef DEFINE_EVENT
126 #define DEFINE_EVENT(template, name, proto, args)
128 #undef DEFINE_EVENT_PRINT
129 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
130 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
132 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
135 * Setup the showing format of trace point.
137 * int
138 * ftrace_format_##call(struct trace_seq *s)
140 * struct ftrace_raw_##call field;
141 * int ret;
143 * ret = trace_seq_printf(s, #type " " #item ";"
144 * " offset:%u; size:%u;\n",
145 * offsetof(struct ftrace_raw_##call, item),
146 * sizeof(field.type));
151 #undef TP_STRUCT__entry
152 #define TP_STRUCT__entry(args...) args
154 #undef __field
155 #define __field(type, item) \
156 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
157 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
158 (unsigned int)offsetof(typeof(field), item), \
159 (unsigned int)sizeof(field.item), \
160 (unsigned int)is_signed_type(type)); \
161 if (!ret) \
162 return 0;
164 #undef __field_ext
165 #define __field_ext(type, item, filter_type) __field(type, item)
167 #undef __array
168 #define __array(type, item, len) \
169 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
170 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
171 (unsigned int)offsetof(typeof(field), item), \
172 (unsigned int)sizeof(field.item), \
173 (unsigned int)is_signed_type(type)); \
174 if (!ret) \
175 return 0;
177 #undef __dynamic_array
178 #define __dynamic_array(type, item, len) \
179 ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
180 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
181 (unsigned int)offsetof(typeof(field), \
182 __data_loc_##item), \
183 (unsigned int)sizeof(field.__data_loc_##item), \
184 (unsigned int)is_signed_type(type)); \
185 if (!ret) \
186 return 0;
188 #undef __string
189 #define __string(item, src) __dynamic_array(char, item, -1)
191 #undef __entry
192 #define __entry REC
194 #undef __print_symbolic
195 #undef __get_dynamic_array
196 #undef __get_str
198 #undef TP_printk
199 #define TP_printk(fmt, args...) "\"%s\", %s\n", fmt, __stringify(args)
201 #undef TP_fast_assign
202 #define TP_fast_assign(args...) args
204 #undef TP_perf_assign
205 #define TP_perf_assign(args...)
207 #undef DECLARE_EVENT_CLASS
208 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
209 static int \
210 ftrace_format_setup_##call(struct ftrace_event_call *unused, \
211 struct trace_seq *s) \
213 struct ftrace_raw_##call field __attribute__((unused)); \
214 int ret = 0; \
216 tstruct; \
218 return ret; \
221 static int \
222 ftrace_format_##call(struct ftrace_event_call *unused, \
223 struct trace_seq *s) \
225 int ret = 0; \
227 ret = ftrace_format_setup_##call(unused, s); \
228 if (!ret) \
229 return ret; \
231 ret = trace_seq_printf(s, "\nprint fmt: " print); \
233 return ret; \
236 #undef DEFINE_EVENT
237 #define DEFINE_EVENT(template, name, proto, args)
239 #undef DEFINE_EVENT_PRINT
240 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
241 static int \
242 ftrace_format_##name(struct ftrace_event_call *unused, \
243 struct trace_seq *s) \
245 int ret = 0; \
247 ret = ftrace_format_setup_##template(unused, s); \
248 if (!ret) \
249 return ret; \
251 trace_seq_printf(s, "\nprint fmt: " print); \
253 return ret; \
256 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
259 * Stage 3 of the trace events.
261 * Override the macros in <trace/trace_events.h> to include the following:
263 * enum print_line_t
264 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
266 * struct trace_seq *s = &iter->seq;
267 * struct ftrace_raw_<call> *field; <-- defined in stage 1
268 * struct trace_entry *entry;
269 * struct trace_seq *p;
270 * int ret;
272 * entry = iter->ent;
274 * if (entry->type != event_<call>.id) {
275 * WARN_ON_ONCE(1);
276 * return TRACE_TYPE_UNHANDLED;
279 * field = (typeof(field))entry;
281 * p = get_cpu_var(ftrace_event_seq);
282 * trace_seq_init(p);
283 * ret = trace_seq_printf(s, <TP_printk> "\n");
284 * put_cpu();
285 * if (!ret)
286 * return TRACE_TYPE_PARTIAL_LINE;
288 * return TRACE_TYPE_HANDLED;
291 * This is the method used to print the raw event to the trace
292 * output format. Note, this is not needed if the data is read
293 * in binary.
296 #undef __entry
297 #define __entry field
299 #undef TP_printk
300 #define TP_printk(fmt, args...) fmt "\n", args
302 #undef __get_dynamic_array
303 #define __get_dynamic_array(field) \
304 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
306 #undef __get_str
307 #define __get_str(field) (char *)__get_dynamic_array(field)
309 #undef __print_flags
310 #define __print_flags(flag, delim, flag_array...) \
311 ({ \
312 static const struct trace_print_flags __flags[] = \
313 { flag_array, { -1, NULL }}; \
314 ftrace_print_flags_seq(p, delim, flag, __flags); \
317 #undef __print_symbolic
318 #define __print_symbolic(value, symbol_array...) \
319 ({ \
320 static const struct trace_print_flags symbols[] = \
321 { symbol_array, { -1, NULL }}; \
322 ftrace_print_symbols_seq(p, value, symbols); \
325 #undef DECLARE_EVENT_CLASS
326 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
327 static enum print_line_t \
328 ftrace_raw_output_id_##call(int event_id, const char *name, \
329 struct trace_iterator *iter, int flags) \
331 struct trace_seq *s = &iter->seq; \
332 struct ftrace_raw_##call *field; \
333 struct trace_entry *entry; \
334 struct trace_seq *p; \
335 int ret; \
337 entry = iter->ent; \
339 if (entry->type != event_id) { \
340 WARN_ON_ONCE(1); \
341 return TRACE_TYPE_UNHANDLED; \
344 field = (typeof(field))entry; \
346 p = &get_cpu_var(ftrace_event_seq); \
347 trace_seq_init(p); \
348 ret = trace_seq_printf(s, "%s: ", name); \
349 if (ret) \
350 ret = trace_seq_printf(s, print); \
351 put_cpu(); \
352 if (!ret) \
353 return TRACE_TYPE_PARTIAL_LINE; \
355 return TRACE_TYPE_HANDLED; \
358 #undef DEFINE_EVENT
359 #define DEFINE_EVENT(template, name, proto, args) \
360 static enum print_line_t \
361 ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
363 return ftrace_raw_output_id_##template(event_##name.id, \
364 #name, iter, flags); \
367 #undef DEFINE_EVENT_PRINT
368 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
369 static enum print_line_t \
370 ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
372 struct trace_seq *s = &iter->seq; \
373 struct ftrace_raw_##template *field; \
374 struct trace_entry *entry; \
375 struct trace_seq *p; \
376 int ret; \
378 entry = iter->ent; \
380 if (entry->type != event_##call.id) { \
381 WARN_ON_ONCE(1); \
382 return TRACE_TYPE_UNHANDLED; \
385 field = (typeof(field))entry; \
387 p = &get_cpu_var(ftrace_event_seq); \
388 trace_seq_init(p); \
389 ret = trace_seq_printf(s, "%s: ", #call); \
390 if (ret) \
391 ret = trace_seq_printf(s, print); \
392 put_cpu(); \
393 if (!ret) \
394 return TRACE_TYPE_PARTIAL_LINE; \
396 return TRACE_TYPE_HANDLED; \
399 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
401 #undef __field_ext
402 #define __field_ext(type, item, filter_type) \
403 ret = trace_define_field(event_call, #type, #item, \
404 offsetof(typeof(field), item), \
405 sizeof(field.item), \
406 is_signed_type(type), filter_type); \
407 if (ret) \
408 return ret;
410 #undef __field
411 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
413 #undef __array
414 #define __array(type, item, len) \
415 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
416 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
417 offsetof(typeof(field), item), \
418 sizeof(field.item), \
419 is_signed_type(type), FILTER_OTHER); \
420 if (ret) \
421 return ret;
423 #undef __dynamic_array
424 #define __dynamic_array(type, item, len) \
425 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
426 offsetof(typeof(field), __data_loc_##item), \
427 sizeof(field.__data_loc_##item), \
428 is_signed_type(type), FILTER_OTHER);
430 #undef __string
431 #define __string(item, src) __dynamic_array(char, item, -1)
433 #undef DECLARE_EVENT_CLASS
434 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
435 static int \
436 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
438 struct ftrace_raw_##call field; \
439 int ret; \
441 tstruct; \
443 return ret; \
446 #undef DEFINE_EVENT
447 #define DEFINE_EVENT(template, name, proto, args)
449 #undef DEFINE_EVENT_PRINT
450 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
451 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
453 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
456 * remember the offset of each array from the beginning of the event.
459 #undef __entry
460 #define __entry entry
462 #undef __field
463 #define __field(type, item)
465 #undef __field_ext
466 #define __field_ext(type, item, filter_type)
468 #undef __array
469 #define __array(type, item, len)
471 #undef __dynamic_array
472 #define __dynamic_array(type, item, len) \
473 __data_offsets->item = __data_size + \
474 offsetof(typeof(*entry), __data); \
475 __data_offsets->item |= (len * sizeof(type)) << 16; \
476 __data_size += (len) * sizeof(type);
478 #undef __string
479 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
481 #undef DECLARE_EVENT_CLASS
482 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
483 static inline int ftrace_get_offsets_##call( \
484 struct ftrace_data_offsets_##call *__data_offsets, proto) \
486 int __data_size = 0; \
487 struct ftrace_raw_##call __maybe_unused *entry; \
489 tstruct; \
491 return __data_size; \
494 #undef DEFINE_EVENT
495 #define DEFINE_EVENT(template, name, proto, args)
497 #undef DEFINE_EVENT_PRINT
498 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
499 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
501 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
503 #ifdef CONFIG_EVENT_PROFILE
506 * Generate the functions needed for tracepoint perf_event support.
508 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
510 * static int ftrace_profile_enable_<call>(void)
512 * return register_trace_<call>(ftrace_profile_<call>);
515 * static void ftrace_profile_disable_<call>(void)
517 * unregister_trace_<call>(ftrace_profile_<call>);
522 #undef DECLARE_EVENT_CLASS
523 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
525 #undef DEFINE_EVENT
526 #define DEFINE_EVENT(template, name, proto, args) \
528 static void ftrace_profile_##name(proto); \
530 static int ftrace_profile_enable_##name(struct ftrace_event_call *unused)\
532 return register_trace_##name(ftrace_profile_##name); \
535 static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\
537 unregister_trace_##name(ftrace_profile_##name); \
540 #undef DEFINE_EVENT_PRINT
541 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
542 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
544 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
546 #endif
549 * Stage 4 of the trace events.
551 * Override the macros in <trace/trace_events.h> to include the following:
553 * static void ftrace_event_<call>(proto)
555 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
558 * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused)
560 * return register_trace_<call>(ftrace_event_<call>);
563 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
565 * unregister_trace_<call>(ftrace_event_<call>);
569 * For those macros defined with TRACE_EVENT:
571 * static struct ftrace_event_call event_<call>;
573 * static void ftrace_raw_event_<call>(proto)
575 * struct ring_buffer_event *event;
576 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
577 * struct ring_buffer *buffer;
578 * unsigned long irq_flags;
579 * int pc;
581 * local_save_flags(irq_flags);
582 * pc = preempt_count();
584 * event = trace_current_buffer_lock_reserve(&buffer,
585 * event_<call>.id,
586 * sizeof(struct ftrace_raw_<call>),
587 * irq_flags, pc);
588 * if (!event)
589 * return;
590 * entry = ring_buffer_event_data(event);
592 * <assign>; <-- Here we assign the entries by the __field and
593 * __array macros.
595 * trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc);
598 * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
600 * int ret;
602 * ret = register_trace_<call>(ftrace_raw_event_<call>);
603 * if (!ret)
604 * pr_info("event trace: Could not activate trace point "
605 * "probe to <call>");
606 * return ret;
609 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
611 * unregister_trace_<call>(ftrace_raw_event_<call>);
614 * static struct trace_event ftrace_event_type_<call> = {
615 * .trace = ftrace_raw_output_<call>, <-- stage 2
616 * };
618 * static struct ftrace_event_call __used
619 * __attribute__((__aligned__(4)))
620 * __attribute__((section("_ftrace_events"))) event_<call> = {
621 * .name = "<call>",
622 * .system = "<system>",
623 * .raw_init = trace_event_raw_init,
624 * .regfunc = ftrace_reg_event_<call>,
625 * .unregfunc = ftrace_unreg_event_<call>,
626 * .show_format = ftrace_format_<call>,
631 #ifdef CONFIG_EVENT_PROFILE
633 #define _TRACE_PROFILE_INIT(call) \
634 .profile_enable = ftrace_profile_enable_##call, \
635 .profile_disable = ftrace_profile_disable_##call,
637 #else
638 #define _TRACE_PROFILE_INIT(call)
639 #endif
641 #undef __entry
642 #define __entry entry
644 #undef __field
645 #define __field(type, item)
647 #undef __array
648 #define __array(type, item, len)
650 #undef __dynamic_array
651 #define __dynamic_array(type, item, len) \
652 __entry->__data_loc_##item = __data_offsets.item;
654 #undef __string
655 #define __string(item, src) __dynamic_array(char, item, -1) \
657 #undef __assign_str
658 #define __assign_str(dst, src) \
659 strcpy(__get_str(dst), src);
661 #undef DECLARE_EVENT_CLASS
662 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
664 static void ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
665 proto) \
667 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
668 struct ring_buffer_event *event; \
669 struct ftrace_raw_##call *entry; \
670 struct ring_buffer *buffer; \
671 unsigned long irq_flags; \
672 int __data_size; \
673 int pc; \
675 local_save_flags(irq_flags); \
676 pc = preempt_count(); \
678 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
680 event = trace_current_buffer_lock_reserve(&buffer, \
681 event_call->id, \
682 sizeof(*entry) + __data_size, \
683 irq_flags, pc); \
684 if (!event) \
685 return; \
686 entry = ring_buffer_event_data(event); \
689 tstruct \
691 { assign; } \
693 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
694 trace_nowake_buffer_unlock_commit(buffer, \
695 event, irq_flags, pc); \
698 #undef DEFINE_EVENT
699 #define DEFINE_EVENT(template, call, proto, args) \
701 static void ftrace_raw_event_##call(proto) \
703 ftrace_raw_event_id_##template(&event_##call, args); \
706 static int ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)\
708 return register_trace_##call(ftrace_raw_event_##call); \
711 static void ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused)\
713 unregister_trace_##call(ftrace_raw_event_##call); \
716 static struct trace_event ftrace_event_type_##call = { \
717 .trace = ftrace_raw_output_##call, \
720 #undef DEFINE_EVENT_PRINT
721 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
722 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
724 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
726 #undef DECLARE_EVENT_CLASS
727 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
729 #undef DEFINE_EVENT
730 #define DEFINE_EVENT(template, call, proto, args) \
732 static struct ftrace_event_call __used \
733 __attribute__((__aligned__(4))) \
734 __attribute__((section("_ftrace_events"))) event_##call = { \
735 .name = #call, \
736 .system = __stringify(TRACE_SYSTEM), \
737 .event = &ftrace_event_type_##call, \
738 .raw_init = trace_event_raw_init, \
739 .regfunc = ftrace_raw_reg_event_##call, \
740 .unregfunc = ftrace_raw_unreg_event_##call, \
741 .show_format = ftrace_format_##template, \
742 .define_fields = ftrace_define_fields_##template, \
743 _TRACE_PROFILE_INIT(call) \
746 #undef DEFINE_EVENT_PRINT
747 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
749 static struct ftrace_event_call __used \
750 __attribute__((__aligned__(4))) \
751 __attribute__((section("_ftrace_events"))) event_##call = { \
752 .name = #call, \
753 .system = __stringify(TRACE_SYSTEM), \
754 .event = &ftrace_event_type_##call, \
755 .raw_init = trace_event_raw_init, \
756 .regfunc = ftrace_raw_reg_event_##call, \
757 .unregfunc = ftrace_raw_unreg_event_##call, \
758 .show_format = ftrace_format_##call, \
759 .define_fields = ftrace_define_fields_##template, \
760 _TRACE_PROFILE_INIT(call) \
763 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
766 * Define the insertion callback to profile events
768 * The job is very similar to ftrace_raw_event_<call> except that we don't
769 * insert in the ring buffer but in a perf counter.
771 * static void ftrace_profile_<call>(proto)
773 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
774 * struct ftrace_event_call *event_call = &event_<call>;
775 * extern void perf_tp_event(int, u64, u64, void *, int);
776 * struct ftrace_raw_##call *entry;
777 * struct perf_trace_buf *trace_buf;
778 * u64 __addr = 0, __count = 1;
779 * unsigned long irq_flags;
780 * struct trace_entry *ent;
781 * int __entry_size;
782 * int __data_size;
783 * int __cpu
784 * int pc;
786 * pc = preempt_count();
788 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
790 * // Below we want to get the aligned size by taking into account
791 * // the u32 field that will later store the buffer size
792 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
793 * sizeof(u64));
794 * __entry_size -= sizeof(u32);
796 * // Protect the non nmi buffer
797 * // This also protects the rcu read side
798 * local_irq_save(irq_flags);
799 * __cpu = smp_processor_id();
801 * if (in_nmi())
802 * trace_buf = rcu_dereference(perf_trace_buf_nmi);
803 * else
804 * trace_buf = rcu_dereference(perf_trace_buf);
806 * if (!trace_buf)
807 * goto end;
809 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
811 * // Avoid recursion from perf that could mess up the buffer
812 * if (trace_buf->recursion++)
813 * goto end_recursion;
815 * raw_data = trace_buf->buf;
817 * // Make recursion update visible before entering perf_tp_event
818 * // so that we protect from perf recursions.
820 * barrier();
822 * //zero dead bytes from alignment to avoid stack leak to userspace:
823 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
824 * entry = (struct ftrace_raw_<call> *)raw_data;
825 * ent = &entry->ent;
826 * tracing_generic_entry_update(ent, irq_flags, pc);
827 * ent->type = event_call->id;
829 * <tstruct> <- do some jobs with dynamic arrays
831 * <assign> <- affect our values
833 * perf_tp_event(event_call->id, __addr, __count, entry,
834 * __entry_size); <- submit them to perf counter
839 #ifdef CONFIG_EVENT_PROFILE
841 #undef __perf_addr
842 #define __perf_addr(a) __addr = (a)
844 #undef __perf_count
845 #define __perf_count(c) __count = (c)
847 #undef DECLARE_EVENT_CLASS
848 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
849 static void \
850 ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
851 proto) \
853 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
854 extern int perf_swevent_get_recursion_context(void); \
855 extern void perf_swevent_put_recursion_context(int rctx); \
856 extern void perf_tp_event(int, u64, u64, void *, int); \
857 struct ftrace_raw_##call *entry; \
858 u64 __addr = 0, __count = 1; \
859 unsigned long irq_flags; \
860 struct trace_entry *ent; \
861 int __entry_size; \
862 int __data_size; \
863 char *trace_buf; \
864 char *raw_data; \
865 int __cpu; \
866 int rctx; \
867 int pc; \
869 pc = preempt_count(); \
871 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
872 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
873 sizeof(u64)); \
874 __entry_size -= sizeof(u32); \
876 if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE, \
877 "profile buffer not large enough")) \
878 return; \
880 local_irq_save(irq_flags); \
882 rctx = perf_swevent_get_recursion_context(); \
883 if (rctx < 0) \
884 goto end_recursion; \
886 __cpu = smp_processor_id(); \
888 if (in_nmi()) \
889 trace_buf = rcu_dereference(perf_trace_buf_nmi); \
890 else \
891 trace_buf = rcu_dereference(perf_trace_buf); \
893 if (!trace_buf) \
894 goto end; \
896 raw_data = per_cpu_ptr(trace_buf, __cpu); \
898 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
899 entry = (struct ftrace_raw_##call *)raw_data; \
900 ent = &entry->ent; \
901 tracing_generic_entry_update(ent, irq_flags, pc); \
902 ent->type = event_call->id; \
904 tstruct \
906 { assign; } \
908 perf_tp_event(event_call->id, __addr, __count, entry, \
909 __entry_size); \
911 end: \
912 perf_swevent_put_recursion_context(rctx); \
913 end_recursion: \
914 local_irq_restore(irq_flags); \
917 #undef DEFINE_EVENT
918 #define DEFINE_EVENT(template, call, proto, args) \
919 static void ftrace_profile_##call(proto) \
921 struct ftrace_event_call *event_call = &event_##call; \
923 ftrace_profile_templ_##template(event_call, args); \
926 #undef DEFINE_EVENT_PRINT
927 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
928 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
930 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
931 #endif /* CONFIG_EVENT_PROFILE */
933 #undef _TRACE_PROFILE_INIT