tracing: Change event->profile_count to be int type
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / trace / ftrace.h
blob73523151a731f61598702d7ccd2ab51fefb39aa7
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 event_##name
70 #undef DEFINE_EVENT_PRINT
71 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
72 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
74 #undef __cpparg
75 #define __cpparg(arg...) arg
77 /* Callbacks are meaningless to ftrace. */
78 #undef TRACE_EVENT_FN
79 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
80 assign, print, reg, unreg) \
81 TRACE_EVENT(name, __cpparg(proto), __cpparg(args), \
82 __cpparg(tstruct), __cpparg(assign), __cpparg(print)) \
84 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
88 * Stage 2 of the trace events.
90 * Include the following:
92 * struct ftrace_data_offsets_<call> {
93 * u32 <item1>;
94 * u32 <item2>;
95 * [...]
96 * };
98 * The __dynamic_array() macro will create each u32 <item>, this is
99 * to keep the offset of each array from the beginning of the event.
100 * The size of an array is also encoded, in the higher 16 bits of <item>.
103 #undef __field
104 #define __field(type, item)
106 #undef __field_ext
107 #define __field_ext(type, item, filter_type)
109 #undef __array
110 #define __array(type, item, len)
112 #undef __dynamic_array
113 #define __dynamic_array(type, item, len) u32 item;
115 #undef __string
116 #define __string(item, src) __dynamic_array(char, item, -1)
118 #undef DECLARE_EVENT_CLASS
119 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
120 struct ftrace_data_offsets_##call { \
121 tstruct; \
124 #undef DEFINE_EVENT
125 #define DEFINE_EVENT(template, name, proto, args)
127 #undef DEFINE_EVENT_PRINT
128 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
129 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
131 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
134 * Setup the showing format of trace point.
136 * int
137 * ftrace_format_##call(struct trace_seq *s)
139 * struct ftrace_raw_##call field;
140 * int ret;
142 * ret = trace_seq_printf(s, #type " " #item ";"
143 * " offset:%u; size:%u;\n",
144 * offsetof(struct ftrace_raw_##call, item),
145 * sizeof(field.type));
150 #undef TP_STRUCT__entry
151 #define TP_STRUCT__entry(args...) args
153 #undef __field
154 #define __field(type, item) \
155 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
156 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
157 (unsigned int)offsetof(typeof(field), item), \
158 (unsigned int)sizeof(field.item), \
159 (unsigned int)is_signed_type(type)); \
160 if (!ret) \
161 return 0;
163 #undef __field_ext
164 #define __field_ext(type, item, filter_type) __field(type, item)
166 #undef __array
167 #define __array(type, item, len) \
168 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
169 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
170 (unsigned int)offsetof(typeof(field), item), \
171 (unsigned int)sizeof(field.item), \
172 (unsigned int)is_signed_type(type)); \
173 if (!ret) \
174 return 0;
176 #undef __dynamic_array
177 #define __dynamic_array(type, item, len) \
178 ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
179 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
180 (unsigned int)offsetof(typeof(field), \
181 __data_loc_##item), \
182 (unsigned int)sizeof(field.__data_loc_##item), \
183 (unsigned int)is_signed_type(type)); \
184 if (!ret) \
185 return 0;
187 #undef __string
188 #define __string(item, src) __dynamic_array(char, item, -1)
190 #undef __entry
191 #define __entry REC
193 #undef __print_symbolic
194 #undef __get_dynamic_array
195 #undef __get_str
197 #undef TP_printk
198 #define TP_printk(fmt, args...) "\"%s\", %s\n", fmt, __stringify(args)
200 #undef TP_fast_assign
201 #define TP_fast_assign(args...) args
203 #undef TP_perf_assign
204 #define TP_perf_assign(args...)
206 #undef DECLARE_EVENT_CLASS
207 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
208 static int \
209 ftrace_format_setup_##call(struct ftrace_event_call *unused, \
210 struct trace_seq *s) \
212 struct ftrace_raw_##call field __attribute__((unused)); \
213 int ret = 0; \
215 tstruct; \
217 return ret; \
220 static int \
221 ftrace_format_##call(struct ftrace_event_call *unused, \
222 struct trace_seq *s) \
224 int ret = 0; \
226 ret = ftrace_format_setup_##call(unused, s); \
227 if (!ret) \
228 return ret; \
230 ret = trace_seq_printf(s, "\nprint fmt: " print); \
232 return ret; \
235 #undef DEFINE_EVENT
236 #define DEFINE_EVENT(template, name, proto, args)
238 #undef DEFINE_EVENT_PRINT
239 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
240 static int \
241 ftrace_format_##name(struct ftrace_event_call *unused, \
242 struct trace_seq *s) \
244 int ret = 0; \
246 ret = ftrace_format_setup_##template(unused, s); \
247 if (!ret) \
248 return ret; \
250 trace_seq_printf(s, "\nprint fmt: " print); \
252 return ret; \
255 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
258 * Stage 3 of the trace events.
260 * Override the macros in <trace/trace_events.h> to include the following:
262 * enum print_line_t
263 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
265 * struct trace_seq *s = &iter->seq;
266 * struct ftrace_raw_<call> *field; <-- defined in stage 1
267 * struct trace_entry *entry;
268 * struct trace_seq *p;
269 * int ret;
271 * entry = iter->ent;
273 * if (entry->type != event_<call>.id) {
274 * WARN_ON_ONCE(1);
275 * return TRACE_TYPE_UNHANDLED;
278 * field = (typeof(field))entry;
280 * p = get_cpu_var(ftrace_event_seq);
281 * trace_seq_init(p);
282 * ret = trace_seq_printf(s, <TP_printk> "\n");
283 * put_cpu();
284 * if (!ret)
285 * return TRACE_TYPE_PARTIAL_LINE;
287 * return TRACE_TYPE_HANDLED;
290 * This is the method used to print the raw event to the trace
291 * output format. Note, this is not needed if the data is read
292 * in binary.
295 #undef __entry
296 #define __entry field
298 #undef TP_printk
299 #define TP_printk(fmt, args...) fmt "\n", args
301 #undef __get_dynamic_array
302 #define __get_dynamic_array(field) \
303 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
305 #undef __get_str
306 #define __get_str(field) (char *)__get_dynamic_array(field)
308 #undef __print_flags
309 #define __print_flags(flag, delim, flag_array...) \
310 ({ \
311 static const struct trace_print_flags __flags[] = \
312 { flag_array, { -1, NULL }}; \
313 ftrace_print_flags_seq(p, delim, flag, __flags); \
316 #undef __print_symbolic
317 #define __print_symbolic(value, symbol_array...) \
318 ({ \
319 static const struct trace_print_flags symbols[] = \
320 { symbol_array, { -1, NULL }}; \
321 ftrace_print_symbols_seq(p, value, symbols); \
324 #undef DECLARE_EVENT_CLASS
325 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
326 static enum print_line_t \
327 ftrace_raw_output_id_##call(int event_id, const char *name, \
328 struct trace_iterator *iter, int flags) \
330 struct trace_seq *s = &iter->seq; \
331 struct ftrace_raw_##call *field; \
332 struct trace_entry *entry; \
333 struct trace_seq *p; \
334 int ret; \
336 entry = iter->ent; \
338 if (entry->type != event_id) { \
339 WARN_ON_ONCE(1); \
340 return TRACE_TYPE_UNHANDLED; \
343 field = (typeof(field))entry; \
345 p = &get_cpu_var(ftrace_event_seq); \
346 trace_seq_init(p); \
347 ret = trace_seq_printf(s, "%s: ", name); \
348 if (ret) \
349 ret = trace_seq_printf(s, print); \
350 put_cpu(); \
351 if (!ret) \
352 return TRACE_TYPE_PARTIAL_LINE; \
354 return TRACE_TYPE_HANDLED; \
357 #undef DEFINE_EVENT
358 #define DEFINE_EVENT(template, name, proto, args) \
359 static enum print_line_t \
360 ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
362 return ftrace_raw_output_id_##template(event_##name.id, \
363 #name, iter, flags); \
366 #undef DEFINE_EVENT_PRINT
367 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
368 static enum print_line_t \
369 ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
371 struct trace_seq *s = &iter->seq; \
372 struct ftrace_raw_##template *field; \
373 struct trace_entry *entry; \
374 struct trace_seq *p; \
375 int ret; \
377 entry = iter->ent; \
379 if (entry->type != event_##call.id) { \
380 WARN_ON_ONCE(1); \
381 return TRACE_TYPE_UNHANDLED; \
384 field = (typeof(field))entry; \
386 p = &get_cpu_var(ftrace_event_seq); \
387 trace_seq_init(p); \
388 ret = trace_seq_printf(s, "%s: ", #call); \
389 if (ret) \
390 ret = trace_seq_printf(s, print); \
391 put_cpu(); \
392 if (!ret) \
393 return TRACE_TYPE_PARTIAL_LINE; \
395 return TRACE_TYPE_HANDLED; \
398 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
400 #undef __field_ext
401 #define __field_ext(type, item, filter_type) \
402 ret = trace_define_field(event_call, #type, #item, \
403 offsetof(typeof(field), item), \
404 sizeof(field.item), \
405 is_signed_type(type), filter_type); \
406 if (ret) \
407 return ret;
409 #undef __field
410 #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
412 #undef __array
413 #define __array(type, item, len) \
414 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
415 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
416 offsetof(typeof(field), item), \
417 sizeof(field.item), 0, FILTER_OTHER); \
418 if (ret) \
419 return ret;
421 #undef __dynamic_array
422 #define __dynamic_array(type, item, len) \
423 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
424 offsetof(typeof(field), __data_loc_##item), \
425 sizeof(field.__data_loc_##item), 0, \
426 FILTER_OTHER);
428 #undef __string
429 #define __string(item, src) __dynamic_array(char, item, -1)
431 #undef DECLARE_EVENT_CLASS
432 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
433 static int \
434 ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
436 struct ftrace_raw_##call field; \
437 int ret; \
439 tstruct; \
441 return ret; \
444 #undef DEFINE_EVENT
445 #define DEFINE_EVENT(template, name, proto, args)
447 #undef DEFINE_EVENT_PRINT
448 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
449 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
451 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
454 * remember the offset of each array from the beginning of the event.
457 #undef __entry
458 #define __entry entry
460 #undef __field
461 #define __field(type, item)
463 #undef __field_ext
464 #define __field_ext(type, item, filter_type)
466 #undef __array
467 #define __array(type, item, len)
469 #undef __dynamic_array
470 #define __dynamic_array(type, item, len) \
471 __data_offsets->item = __data_size + \
472 offsetof(typeof(*entry), __data); \
473 __data_offsets->item |= (len * sizeof(type)) << 16; \
474 __data_size += (len) * sizeof(type);
476 #undef __string
477 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
479 #undef DECLARE_EVENT_CLASS
480 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
481 static inline int ftrace_get_offsets_##call( \
482 struct ftrace_data_offsets_##call *__data_offsets, proto) \
484 int __data_size = 0; \
485 struct ftrace_raw_##call __maybe_unused *entry; \
487 tstruct; \
489 return __data_size; \
492 #undef DEFINE_EVENT
493 #define DEFINE_EVENT(template, name, proto, args)
495 #undef DEFINE_EVENT_PRINT
496 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
497 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
499 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
501 #ifdef CONFIG_EVENT_PROFILE
504 * Generate the functions needed for tracepoint perf_event support.
506 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
508 * static int ftrace_profile_enable_<call>(void)
510 * return register_trace_<call>(ftrace_profile_<call>);
513 * static void ftrace_profile_disable_<call>(void)
515 * unregister_trace_<call>(ftrace_profile_<call>);
520 #undef DECLARE_EVENT_CLASS
521 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
523 #undef DEFINE_EVENT
524 #define DEFINE_EVENT(template, name, proto, args) \
526 static void ftrace_profile_##name(proto); \
528 static int ftrace_profile_enable_##name(struct ftrace_event_call *unused)\
530 return register_trace_##name(ftrace_profile_##name); \
533 static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\
535 unregister_trace_##name(ftrace_profile_##name); \
538 #undef DEFINE_EVENT_PRINT
539 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
540 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
542 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
544 #endif
547 * Stage 4 of the trace events.
549 * Override the macros in <trace/trace_events.h> to include the following:
551 * static void ftrace_event_<call>(proto)
553 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
556 * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused)
558 * return register_trace_<call>(ftrace_event_<call>);
561 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
563 * unregister_trace_<call>(ftrace_event_<call>);
567 * For those macros defined with TRACE_EVENT:
569 * static struct ftrace_event_call event_<call>;
571 * static void ftrace_raw_event_<call>(proto)
573 * struct ring_buffer_event *event;
574 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
575 * struct ring_buffer *buffer;
576 * unsigned long irq_flags;
577 * int pc;
579 * local_save_flags(irq_flags);
580 * pc = preempt_count();
582 * event = trace_current_buffer_lock_reserve(&buffer,
583 * event_<call>.id,
584 * sizeof(struct ftrace_raw_<call>),
585 * irq_flags, pc);
586 * if (!event)
587 * return;
588 * entry = ring_buffer_event_data(event);
590 * <assign>; <-- Here we assign the entries by the __field and
591 * __array macros.
593 * trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc);
596 * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
598 * int ret;
600 * ret = register_trace_<call>(ftrace_raw_event_<call>);
601 * if (!ret)
602 * pr_info("event trace: Could not activate trace point "
603 * "probe to <call>");
604 * return ret;
607 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
609 * unregister_trace_<call>(ftrace_raw_event_<call>);
612 * static struct trace_event ftrace_event_type_<call> = {
613 * .trace = ftrace_raw_output_<call>, <-- stage 2
614 * };
616 * static struct ftrace_event_call __used
617 * __attribute__((__aligned__(4)))
618 * __attribute__((section("_ftrace_events"))) event_<call> = {
619 * .name = "<call>",
620 * .system = "<system>",
621 * .raw_init = trace_event_raw_init,
622 * .regfunc = ftrace_reg_event_<call>,
623 * .unregfunc = ftrace_unreg_event_<call>,
624 * .show_format = ftrace_format_<call>,
629 #ifdef CONFIG_EVENT_PROFILE
631 #define _TRACE_PROFILE_INIT(call) \
632 .profile_enable = ftrace_profile_enable_##call, \
633 .profile_disable = ftrace_profile_disable_##call,
635 #else
636 #define _TRACE_PROFILE_INIT(call)
637 #endif
639 #undef __entry
640 #define __entry entry
642 #undef __field
643 #define __field(type, item)
645 #undef __array
646 #define __array(type, item, len)
648 #undef __dynamic_array
649 #define __dynamic_array(type, item, len) \
650 __entry->__data_loc_##item = __data_offsets.item;
652 #undef __string
653 #define __string(item, src) __dynamic_array(char, item, -1) \
655 #undef __assign_str
656 #define __assign_str(dst, src) \
657 strcpy(__get_str(dst), src);
659 #undef DECLARE_EVENT_CLASS
660 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
662 static void ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
663 proto) \
665 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
666 struct ring_buffer_event *event; \
667 struct ftrace_raw_##call *entry; \
668 struct ring_buffer *buffer; \
669 unsigned long irq_flags; \
670 int __data_size; \
671 int pc; \
673 local_save_flags(irq_flags); \
674 pc = preempt_count(); \
676 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
678 event = trace_current_buffer_lock_reserve(&buffer, \
679 event_call->id, \
680 sizeof(*entry) + __data_size, \
681 irq_flags, pc); \
682 if (!event) \
683 return; \
684 entry = ring_buffer_event_data(event); \
687 tstruct \
689 { assign; } \
691 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
692 trace_nowake_buffer_unlock_commit(buffer, \
693 event, irq_flags, pc); \
696 #undef DEFINE_EVENT
697 #define DEFINE_EVENT(template, call, proto, args) \
699 static void ftrace_raw_event_##call(proto) \
701 ftrace_raw_event_id_##template(&event_##call, args); \
704 static int ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)\
706 return register_trace_##call(ftrace_raw_event_##call); \
709 static void ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused)\
711 unregister_trace_##call(ftrace_raw_event_##call); \
714 static struct trace_event ftrace_event_type_##call = { \
715 .trace = ftrace_raw_output_##call, \
718 #undef DEFINE_EVENT_PRINT
719 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
720 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
722 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
724 #undef DECLARE_EVENT_CLASS
725 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
727 #undef DEFINE_EVENT
728 #define DEFINE_EVENT(template, call, proto, args) \
730 static struct ftrace_event_call __used \
731 __attribute__((__aligned__(4))) \
732 __attribute__((section("_ftrace_events"))) event_##call = { \
733 .name = #call, \
734 .system = __stringify(TRACE_SYSTEM), \
735 .event = &ftrace_event_type_##call, \
736 .raw_init = trace_event_raw_init, \
737 .regfunc = ftrace_raw_reg_event_##call, \
738 .unregfunc = ftrace_raw_unreg_event_##call, \
739 .show_format = ftrace_format_##template, \
740 .define_fields = ftrace_define_fields_##template, \
741 _TRACE_PROFILE_INIT(call) \
744 #undef DEFINE_EVENT_PRINT
745 #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
747 static struct ftrace_event_call __used \
748 __attribute__((__aligned__(4))) \
749 __attribute__((section("_ftrace_events"))) event_##call = { \
750 .name = #call, \
751 .system = __stringify(TRACE_SYSTEM), \
752 .event = &ftrace_event_type_##call, \
753 .raw_init = trace_event_raw_init, \
754 .regfunc = ftrace_raw_reg_event_##call, \
755 .unregfunc = ftrace_raw_unreg_event_##call, \
756 .show_format = ftrace_format_##call, \
757 .define_fields = ftrace_define_fields_##template, \
758 _TRACE_PROFILE_INIT(call) \
761 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
764 * Define the insertion callback to profile events
766 * The job is very similar to ftrace_raw_event_<call> except that we don't
767 * insert in the ring buffer but in a perf counter.
769 * static void ftrace_profile_<call>(proto)
771 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
772 * struct ftrace_event_call *event_call = &event_<call>;
773 * extern void perf_tp_event(int, u64, u64, void *, int);
774 * struct ftrace_raw_##call *entry;
775 * struct perf_trace_buf *trace_buf;
776 * u64 __addr = 0, __count = 1;
777 * unsigned long irq_flags;
778 * struct trace_entry *ent;
779 * int __entry_size;
780 * int __data_size;
781 * int __cpu
782 * int pc;
784 * pc = preempt_count();
786 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
788 * // Below we want to get the aligned size by taking into account
789 * // the u32 field that will later store the buffer size
790 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
791 * sizeof(u64));
792 * __entry_size -= sizeof(u32);
794 * // Protect the non nmi buffer
795 * // This also protects the rcu read side
796 * local_irq_save(irq_flags);
797 * __cpu = smp_processor_id();
799 * if (in_nmi())
800 * trace_buf = rcu_dereference(perf_trace_buf_nmi);
801 * else
802 * trace_buf = rcu_dereference(perf_trace_buf);
804 * if (!trace_buf)
805 * goto end;
807 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
809 * // Avoid recursion from perf that could mess up the buffer
810 * if (trace_buf->recursion++)
811 * goto end_recursion;
813 * raw_data = trace_buf->buf;
815 * // Make recursion update visible before entering perf_tp_event
816 * // so that we protect from perf recursions.
818 * barrier();
820 * //zero dead bytes from alignment to avoid stack leak to userspace:
821 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
822 * entry = (struct ftrace_raw_<call> *)raw_data;
823 * ent = &entry->ent;
824 * tracing_generic_entry_update(ent, irq_flags, pc);
825 * ent->type = event_call->id;
827 * <tstruct> <- do some jobs with dynamic arrays
829 * <assign> <- affect our values
831 * perf_tp_event(event_call->id, __addr, __count, entry,
832 * __entry_size); <- submit them to perf counter
837 #ifdef CONFIG_EVENT_PROFILE
839 #undef __perf_addr
840 #define __perf_addr(a) __addr = (a)
842 #undef __perf_count
843 #define __perf_count(c) __count = (c)
845 #undef DECLARE_EVENT_CLASS
846 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
847 static void \
848 ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
849 proto) \
851 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
852 extern int perf_swevent_get_recursion_context(void); \
853 extern void perf_swevent_put_recursion_context(int rctx); \
854 extern void perf_tp_event(int, u64, u64, void *, int); \
855 struct ftrace_raw_##call *entry; \
856 u64 __addr = 0, __count = 1; \
857 unsigned long irq_flags; \
858 struct trace_entry *ent; \
859 int __entry_size; \
860 int __data_size; \
861 char *trace_buf; \
862 char *raw_data; \
863 int __cpu; \
864 int rctx; \
865 int pc; \
867 pc = preempt_count(); \
869 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
870 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
871 sizeof(u64)); \
872 __entry_size -= sizeof(u32); \
874 if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE, \
875 "profile buffer not large enough")) \
876 return; \
878 local_irq_save(irq_flags); \
880 rctx = perf_swevent_get_recursion_context(); \
881 if (rctx < 0) \
882 goto end_recursion; \
884 __cpu = smp_processor_id(); \
886 if (in_nmi()) \
887 trace_buf = rcu_dereference(perf_trace_buf_nmi); \
888 else \
889 trace_buf = rcu_dereference(perf_trace_buf); \
891 if (!trace_buf) \
892 goto end; \
894 raw_data = per_cpu_ptr(trace_buf, __cpu); \
896 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
897 entry = (struct ftrace_raw_##call *)raw_data; \
898 ent = &entry->ent; \
899 tracing_generic_entry_update(ent, irq_flags, pc); \
900 ent->type = event_call->id; \
902 tstruct \
904 { assign; } \
906 perf_tp_event(event_call->id, __addr, __count, entry, \
907 __entry_size); \
909 end: \
910 perf_swevent_put_recursion_context(rctx); \
911 end_recursion: \
912 local_irq_restore(irq_flags); \
915 #undef DEFINE_EVENT
916 #define DEFINE_EVENT(template, call, proto, args) \
917 static void ftrace_profile_##call(proto) \
919 struct ftrace_event_call *event_call = &event_##call; \
921 ftrace_profile_templ_##template(event_call, args); \
924 #undef DEFINE_EVENT_PRINT
925 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
926 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
928 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
929 #endif /* CONFIG_EVENT_PROFILE */
931 #undef _TRACE_PROFILE_INIT