x86: Rename global percpu symbol dr7 to cpu_dr7
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / include / trace / ftrace.h
CommitLineData
f42c85e7
SR
1/*
2 * Stage 1 of the trace events.
3 *
4 * Override the macros in <trace/trace_events.h> to include the following:
5 *
6 * struct ftrace_raw_<call> {
7 * struct trace_entry ent;
8 * <type> <item>;
9 * <type2> <item2>[<len>];
10 * [...]
11 * };
12 *
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.
17 */
18
19#include <linux/ftrace_event.h>
20
ff038f5c
SR
21/*
22 * TRACE_EVENT_TEMPLATE 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 TRACE_EVENT_TEMPLATE to the tracepoint.
27 *
28 * TRACE_EVENT is a one to one mapping between tracepoint and template.
29 */
30#undef TRACE_EVENT
31#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
32 TRACE_EVENT_TEMPLATE(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));
39
40
7fcb7c47
LZ
41#undef __field
42#define __field(type, item) type item;
43
43b51ead
LZ
44#undef __field_ext
45#define __field_ext(type, item, filter_type) type item;
46
f42c85e7
SR
47#undef __array
48#define __array(type, item, len) type item[len];
49
7fcb7c47 50#undef __dynamic_array
7d536cb3 51#define __dynamic_array(type, item, len) u32 __data_loc_##item;
f42c85e7 52
9cbf1176 53#undef __string
7fcb7c47 54#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 55
f42c85e7
SR
56#undef TP_STRUCT__entry
57#define TP_STRUCT__entry(args...) args
58
ff038f5c
SR
59#undef TRACE_EVENT_TEMPLATE
60#define TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print) \
61 struct ftrace_raw_##name { \
62 struct trace_entry ent; \
63 tstruct \
64 char __data[0]; \
65 };
66#undef DEFINE_EVENT
67#define DEFINE_EVENT(template, name, proto, args) \
f42c85e7
SR
68 static struct ftrace_event_call event_##name
69
e5bc9721
SR
70#undef DEFINE_EVENT_PRINT
71#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
72 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
73
0dd7b747
FW
74#undef __cpparg
75#define __cpparg(arg...) arg
76
97419875
JS
77/* Callbacks are meaningless to ftrace. */
78#undef TRACE_EVENT_FN
0dd7b747
FW
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)) \
97419875 83
f42c85e7
SR
84#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
85
9cbf1176 86
f42c85e7
SR
87/*
88 * Stage 2 of the trace events.
89 *
9cbf1176
FW
90 * Include the following:
91 *
7fcb7c47 92 * struct ftrace_data_offsets_<call> {
7d536cb3
LZ
93 * u32 <item1>;
94 * u32 <item2>;
9cbf1176
FW
95 * [...]
96 * };
97 *
7d536cb3 98 * The __dynamic_array() macro will create each u32 <item>, this is
7fcb7c47 99 * to keep the offset of each array from the beginning of the event.
7d536cb3 100 * The size of an array is also encoded, in the higher 16 bits of <item>.
9cbf1176
FW
101 */
102
7fcb7c47 103#undef __field
43b51ead
LZ
104#define __field(type, item)
105
106#undef __field_ext
107#define __field_ext(type, item, filter_type)
7fcb7c47 108
9cbf1176
FW
109#undef __array
110#define __array(type, item, len)
111
7fcb7c47 112#undef __dynamic_array
7d536cb3 113#define __dynamic_array(type, item, len) u32 item;
9cbf1176
FW
114
115#undef __string
7fcb7c47 116#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 117
ff038f5c
SR
118#undef TRACE_EVENT_TEMPLATE
119#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
7fcb7c47 120 struct ftrace_data_offsets_##call { \
9cbf1176
FW
121 tstruct; \
122 };
123
ff038f5c
SR
124#undef DEFINE_EVENT
125#define DEFINE_EVENT(template, name, proto, args)
126
e5bc9721
SR
127#undef DEFINE_EVENT_PRINT
128#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
129 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
130
9cbf1176
FW
131#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
132
6ff9a64d
SR
133/*
134 * Setup the showing format of trace point.
135 *
136 * int
137 * ftrace_format_##call(struct trace_seq *s)
138 * {
139 * struct ftrace_raw_##call field;
140 * int ret;
141 *
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));
146 *
147 * }
148 */
149
150#undef TP_STRUCT__entry
151#define TP_STRUCT__entry(args...) args
152
153#undef __field
154#define __field(type, item) \
155 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
26a50744 156 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
6ff9a64d 157 (unsigned int)offsetof(typeof(field), item), \
26a50744
TZ
158 (unsigned int)sizeof(field.item), \
159 (unsigned int)is_signed_type(type)); \
6ff9a64d
SR
160 if (!ret) \
161 return 0;
162
43b51ead
LZ
163#undef __field_ext
164#define __field_ext(type, item, filter_type) __field(type, item)
165
6ff9a64d
SR
166#undef __array
167#define __array(type, item, len) \
168 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
26a50744 169 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
6ff9a64d 170 (unsigned int)offsetof(typeof(field), item), \
26a50744
TZ
171 (unsigned int)sizeof(field.item), \
172 (unsigned int)is_signed_type(type)); \
6ff9a64d
SR
173 if (!ret) \
174 return 0;
175
176#undef __dynamic_array
177#define __dynamic_array(type, item, len) \
68fd60a8 178 ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
26a50744 179 "offset:%u;\tsize:%u;\tsigned:%u;\n", \
6ff9a64d
SR
180 (unsigned int)offsetof(typeof(field), \
181 __data_loc_##item), \
26a50744
TZ
182 (unsigned int)sizeof(field.__data_loc_##item), \
183 (unsigned int)is_signed_type(type)); \
6ff9a64d
SR
184 if (!ret) \
185 return 0;
186
187#undef __string
188#define __string(item, src) __dynamic_array(char, item, -1)
189
190#undef __entry
191#define __entry REC
192
193#undef __print_symbolic
194#undef __get_dynamic_array
195#undef __get_str
196
197#undef TP_printk
198#define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
199
200#undef TP_fast_assign
201#define TP_fast_assign(args...) args
202
3a659305
PZ
203#undef TP_perf_assign
204#define TP_perf_assign(args...)
205
ff038f5c
SR
206#undef TRACE_EVENT_TEMPLATE
207#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, func, print) \
6ff9a64d 208static int \
e5bc9721
SR
209ftrace_format_setup_##call(struct ftrace_event_call *unused, \
210 struct trace_seq *s) \
6ff9a64d
SR
211{ \
212 struct ftrace_raw_##call field __attribute__((unused)); \
213 int ret = 0; \
214 \
215 tstruct; \
216 \
e5bc9721
SR
217 return ret; \
218} \
219 \
220static int \
221ftrace_format_##call(struct ftrace_event_call *unused, \
222 struct trace_seq *s) \
223{ \
224 int ret = 0; \
225 \
226 ret = ftrace_format_setup_##call(unused, s); \
227 if (!ret) \
228 return ret; \
229 \
230 ret = trace_seq_printf(s, "\nprint fmt: " print); \
6ff9a64d
SR
231 \
232 return ret; \
233}
234
ff038f5c
SR
235#undef DEFINE_EVENT
236#define DEFINE_EVENT(template, name, proto, args)
237
e5bc9721
SR
238#undef DEFINE_EVENT_PRINT
239#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
240static int \
241ftrace_format_##name(struct ftrace_event_call *unused, \
242 struct trace_seq *s) \
243{ \
244 int ret = 0; \
245 \
246 ret = ftrace_format_setup_##template(unused, s); \
247 if (!ret) \
248 return ret; \
249 \
250 trace_seq_printf(s, "\nprint fmt: " print); \
251 \
252 return ret; \
253}
254
6ff9a64d
SR
255#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
256
9cbf1176
FW
257/*
258 * Stage 3 of the trace events.
259 *
f42c85e7
SR
260 * Override the macros in <trace/trace_events.h> to include the following:
261 *
262 * enum print_line_t
263 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
264 * {
265 * struct trace_seq *s = &iter->seq;
266 * struct ftrace_raw_<call> *field; <-- defined in stage 1
267 * struct trace_entry *entry;
be74b73a 268 * struct trace_seq *p;
f42c85e7
SR
269 * int ret;
270 *
271 * entry = iter->ent;
272 *
273 * if (entry->type != event_<call>.id) {
274 * WARN_ON_ONCE(1);
275 * return TRACE_TYPE_UNHANDLED;
276 * }
277 *
278 * field = (typeof(field))entry;
279 *
be74b73a 280 * p = get_cpu_var(ftrace_event_seq);
56d8bd3f 281 * trace_seq_init(p);
f42c85e7 282 * ret = trace_seq_printf(s, <TP_printk> "\n");
be74b73a 283 * put_cpu();
f42c85e7
SR
284 * if (!ret)
285 * return TRACE_TYPE_PARTIAL_LINE;
286 *
287 * return TRACE_TYPE_HANDLED;
288 * }
289 *
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.
293 */
294
295#undef __entry
296#define __entry field
297
298#undef TP_printk
299#define TP_printk(fmt, args...) fmt "\n", args
300
7fcb7c47
LZ
301#undef __get_dynamic_array
302#define __get_dynamic_array(field) \
7d536cb3 303 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
7fcb7c47 304
9cbf1176 305#undef __get_str
7fcb7c47 306#define __get_str(field) (char *)__get_dynamic_array(field)
9cbf1176 307
be74b73a
SR
308#undef __print_flags
309#define __print_flags(flag, delim, flag_array...) \
310 ({ \
a48f494e 311 static const struct trace_print_flags __flags[] = \
be74b73a 312 { flag_array, { -1, NULL }}; \
a48f494e 313 ftrace_print_flags_seq(p, delim, flag, __flags); \
be74b73a
SR
314 })
315
0f4fc29d
SR
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); \
322 })
323
ff038f5c
SR
324#undef TRACE_EVENT_TEMPLATE
325#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
ec827c7e 326static enum print_line_t \
ff038f5c
SR
327ftrace_raw_output_id_##call(int event_id, const char *name, \
328 struct trace_iterator *iter, int flags) \
f42c85e7
SR
329{ \
330 struct trace_seq *s = &iter->seq; \
331 struct ftrace_raw_##call *field; \
332 struct trace_entry *entry; \
be74b73a 333 struct trace_seq *p; \
f42c85e7
SR
334 int ret; \
335 \
336 entry = iter->ent; \
337 \
ff038f5c 338 if (entry->type != event_id) { \
f42c85e7
SR
339 WARN_ON_ONCE(1); \
340 return TRACE_TYPE_UNHANDLED; \
341 } \
342 \
343 field = (typeof(field))entry; \
344 \
be74b73a 345 p = &get_cpu_var(ftrace_event_seq); \
56d8bd3f 346 trace_seq_init(p); \
ff038f5c
SR
347 ret = trace_seq_printf(s, "%s: ", name); \
348 if (ret) \
349 ret = trace_seq_printf(s, print); \
be74b73a 350 put_cpu(); \
f42c85e7
SR
351 if (!ret) \
352 return TRACE_TYPE_PARTIAL_LINE; \
353 \
354 return TRACE_TYPE_HANDLED; \
355}
ff038f5c
SR
356
357#undef DEFINE_EVENT
358#define DEFINE_EVENT(template, name, proto, args) \
359static enum print_line_t \
360ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
361{ \
362 return ftrace_raw_output_id_##template(event_##name.id, \
363 #name, iter, flags); \
364}
365
e5bc9721
SR
366#undef DEFINE_EVENT_PRINT
367#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
368static enum print_line_t \
369ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
370{ \
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; \
376 \
377 entry = iter->ent; \
378 \
379 if (entry->type != event_##call.id) { \
380 WARN_ON_ONCE(1); \
381 return TRACE_TYPE_UNHANDLED; \
382 } \
383 \
384 field = (typeof(field))entry; \
385 \
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; \
394 \
395 return TRACE_TYPE_HANDLED; \
396}
397
f42c85e7
SR
398#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
399
43b51ead
LZ
400#undef __field_ext
401#define __field_ext(type, item, filter_type) \
f42c85e7
SR
402 ret = trace_define_field(event_call, #type, #item, \
403 offsetof(typeof(field), item), \
43b51ead
LZ
404 sizeof(field.item), \
405 is_signed_type(type), filter_type); \
f42c85e7
SR
406 if (ret) \
407 return ret;
408
43b51ead
LZ
409#undef __field
410#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
411
f42c85e7
SR
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), \
43b51ead 417 sizeof(field.item), 0, FILTER_OTHER); \
f42c85e7
SR
418 if (ret) \
419 return ret;
420
7fcb7c47
LZ
421#undef __dynamic_array
422#define __dynamic_array(type, item, len) \
68fd60a8 423 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
43b51ead
LZ
424 offsetof(typeof(field), __data_loc_##item), \
425 sizeof(field.__data_loc_##item), 0, \
426 FILTER_OTHER);
7fcb7c47 427
9cbf1176 428#undef __string
7fcb7c47 429#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 430
ff038f5c
SR
431#undef TRACE_EVENT_TEMPLATE
432#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, func, print) \
ec827c7e 433static int \
14be96c9 434ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
f42c85e7
SR
435{ \
436 struct ftrace_raw_##call field; \
f42c85e7
SR
437 int ret; \
438 \
e647d6b3
LZ
439 ret = trace_define_common_fields(event_call); \
440 if (ret) \
441 return ret; \
f42c85e7
SR
442 \
443 tstruct; \
444 \
445 return ret; \
446}
447
ff038f5c
SR
448#undef DEFINE_EVENT
449#define DEFINE_EVENT(template, name, proto, args)
450
e5bc9721
SR
451#undef DEFINE_EVENT_PRINT
452#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
453 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
454
f42c85e7
SR
455#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
456
7fcb7c47
LZ
457/*
458 * remember the offset of each array from the beginning of the event.
459 */
460
461#undef __entry
462#define __entry entry
463
464#undef __field
465#define __field(type, item)
466
43b51ead
LZ
467#undef __field_ext
468#define __field_ext(type, item, filter_type)
469
7fcb7c47
LZ
470#undef __array
471#define __array(type, item, len)
472
473#undef __dynamic_array
474#define __dynamic_array(type, item, len) \
475 __data_offsets->item = __data_size + \
476 offsetof(typeof(*entry), __data); \
7d536cb3 477 __data_offsets->item |= (len * sizeof(type)) << 16; \
7fcb7c47
LZ
478 __data_size += (len) * sizeof(type);
479
480#undef __string
ff038f5c 481#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
7fcb7c47 482
ff038f5c
SR
483#undef TRACE_EVENT_TEMPLATE
484#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
7fcb7c47
LZ
485static inline int ftrace_get_offsets_##call( \
486 struct ftrace_data_offsets_##call *__data_offsets, proto) \
487{ \
488 int __data_size = 0; \
489 struct ftrace_raw_##call __maybe_unused *entry; \
490 \
491 tstruct; \
492 \
493 return __data_size; \
494}
495
ff038f5c
SR
496#undef DEFINE_EVENT
497#define DEFINE_EVENT(template, name, proto, args)
498
e5bc9721
SR
499#undef DEFINE_EVENT_PRINT
500#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
501 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
502
7fcb7c47
LZ
503#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
504
3a659305
PZ
505#ifdef CONFIG_EVENT_PROFILE
506
507/*
cdd6c482 508 * Generate the functions needed for tracepoint perf_event support.
3a659305 509 *
f413cdb8 510 * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
3a659305 511 *
e5e25cf4 512 * static int ftrace_profile_enable_<call>(void)
3a659305 513 * {
e5e25cf4 514 * return register_trace_<call>(ftrace_profile_<call>);
3a659305
PZ
515 * }
516 *
e5e25cf4 517 * static void ftrace_profile_disable_<call>(void)
3a659305 518 * {
e5e25cf4 519 * unregister_trace_<call>(ftrace_profile_<call>);
3a659305
PZ
520 * }
521 *
522 */
523
ff038f5c
SR
524#undef TRACE_EVENT_TEMPLATE
525#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print)
526
527#undef DEFINE_EVENT
528#define DEFINE_EVENT(template, name, proto, args) \
3a659305 529 \
ff038f5c 530static void ftrace_profile_##name(proto); \
3a659305 531 \
ff038f5c 532static int ftrace_profile_enable_##name(struct ftrace_event_call *unused)\
3a659305 533{ \
ff038f5c 534 return register_trace_##name(ftrace_profile_##name); \
3a659305
PZ
535} \
536 \
ff038f5c 537static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\
3a659305 538{ \
ff038f5c 539 unregister_trace_##name(ftrace_profile_##name); \
3a659305
PZ
540}
541
e5bc9721
SR
542#undef DEFINE_EVENT_PRINT
543#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
544 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
545
3a659305
PZ
546#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
547
3a659305
PZ
548#endif
549
c32e827b 550/*
9cbf1176 551 * Stage 4 of the trace events.
c32e827b 552 *
ea20d929 553 * Override the macros in <trace/trace_events.h> to include the following:
c32e827b
SR
554 *
555 * static void ftrace_event_<call>(proto)
556 * {
ef18012b 557 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
c32e827b
SR
558 * }
559 *
bd1a5c84 560 * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused)
c32e827b 561 * {
ef18012b 562 * int ret;
c32e827b 563 *
ef18012b
SR
564 * ret = register_trace_<call>(ftrace_event_<call>);
565 * if (!ret)
566 * pr_info("event trace: Could not activate trace point "
567 * "probe to <call>");
568 * return ret;
c32e827b
SR
569 * }
570 *
bd1a5c84 571 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
c32e827b 572 * {
ef18012b 573 * unregister_trace_<call>(ftrace_event_<call>);
c32e827b
SR
574 * }
575 *
c32e827b 576 *
157587d7 577 * For those macros defined with TRACE_EVENT:
c32e827b
SR
578 *
579 * static struct ftrace_event_call event_<call>;
580 *
581 * static void ftrace_raw_event_<call>(proto)
582 * {
ef18012b
SR
583 * struct ring_buffer_event *event;
584 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
e77405ad 585 * struct ring_buffer *buffer;
ef18012b
SR
586 * unsigned long irq_flags;
587 * int pc;
588 *
589 * local_save_flags(irq_flags);
590 * pc = preempt_count();
591 *
e77405ad
SR
592 * event = trace_current_buffer_lock_reserve(&buffer,
593 * event_<call>.id,
ef18012b
SR
594 * sizeof(struct ftrace_raw_<call>),
595 * irq_flags, pc);
596 * if (!event)
597 * return;
598 * entry = ring_buffer_event_data(event);
599 *
600 * <assign>; <-- Here we assign the entries by the __field and
0e3d0f05 601 * __array macros.
c32e827b 602 *
e77405ad 603 * trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc);
c32e827b
SR
604 * }
605 *
bd1a5c84 606 * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
c32e827b 607 * {
ef18012b 608 * int ret;
c32e827b 609 *
ef18012b
SR
610 * ret = register_trace_<call>(ftrace_raw_event_<call>);
611 * if (!ret)
612 * pr_info("event trace: Could not activate trace point "
613 * "probe to <call>");
614 * return ret;
c32e827b
SR
615 * }
616 *
bd1a5c84 617 * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
c32e827b 618 * {
ef18012b 619 * unregister_trace_<call>(ftrace_raw_event_<call>);
c32e827b
SR
620 * }
621 *
622 * static struct trace_event ftrace_event_type_<call> = {
ef18012b 623 * .trace = ftrace_raw_output_<call>, <-- stage 2
c32e827b
SR
624 * };
625 *
bd1a5c84 626 * static int ftrace_raw_init_event_<call>(struct ftrace_event_call *unused)
c32e827b 627 * {
ef18012b 628 * int id;
c32e827b 629 *
ef18012b
SR
630 * id = register_ftrace_event(&ftrace_event_type_<call>);
631 * if (!id)
632 * return -ENODEV;
633 * event_<call>.id = id;
634 * return 0;
c32e827b
SR
635 * }
636 *
637 * static struct ftrace_event_call __used
638 * __attribute__((__aligned__(4)))
639 * __attribute__((section("_ftrace_events"))) event_<call> = {
ef18012b 640 * .name = "<call>",
0e3d0f05 641 * .system = "<system>",
ef18012b
SR
642 * .raw_init = ftrace_raw_init_event_<call>,
643 * .regfunc = ftrace_reg_event_<call>,
644 * .unregfunc = ftrace_unreg_event_<call>,
981d081e 645 * .show_format = ftrace_format_<call>,
c32e827b
SR
646 * }
647 *
648 */
649
2939b046
SR
650#undef TP_FMT
651#define TP_FMT(fmt, args...) fmt "\n", ##args
c32e827b 652
ac199db0 653#ifdef CONFIG_EVENT_PROFILE
ac199db0
PZ
654
655#define _TRACE_PROFILE_INIT(call) \
656 .profile_count = ATOMIC_INIT(-1), \
657 .profile_enable = ftrace_profile_enable_##call, \
658 .profile_disable = ftrace_profile_disable_##call,
659
660#else
ac199db0
PZ
661#define _TRACE_PROFILE_INIT(call)
662#endif
663
da4d0302
SR
664#undef __entry
665#define __entry entry
d20e3b03 666
9cbf1176
FW
667#undef __field
668#define __field(type, item)
669
670#undef __array
671#define __array(type, item, len)
672
7fcb7c47
LZ
673#undef __dynamic_array
674#define __dynamic_array(type, item, len) \
675 __entry->__data_loc_##item = __data_offsets.item;
676
9cbf1176 677#undef __string
7fcb7c47 678#define __string(item, src) __dynamic_array(char, item, -1) \
9cbf1176
FW
679
680#undef __assign_str
681#define __assign_str(dst, src) \
9cbf1176
FW
682 strcpy(__get_str(dst), src);
683
ff038f5c
SR
684#undef TRACE_EVENT_TEMPLATE
685#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
c32e827b 686 \
ff038f5c
SR
687static void ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
688 proto) \
c32e827b 689{ \
7fcb7c47 690 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
c32e827b
SR
691 struct ring_buffer_event *event; \
692 struct ftrace_raw_##call *entry; \
e77405ad 693 struct ring_buffer *buffer; \
c32e827b 694 unsigned long irq_flags; \
7fcb7c47 695 int __data_size; \
c32e827b
SR
696 int pc; \
697 \
698 local_save_flags(irq_flags); \
699 pc = preempt_count(); \
700 \
7fcb7c47 701 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
9cbf1176 702 \
e77405ad 703 event = trace_current_buffer_lock_reserve(&buffer, \
ff038f5c 704 event_call->id, \
7fcb7c47 705 sizeof(*entry) + __data_size, \
9cbf1176 706 irq_flags, pc); \
c32e827b
SR
707 if (!event) \
708 return; \
709 entry = ring_buffer_event_data(event); \
710 \
7fcb7c47
LZ
711 \
712 tstruct \
713 \
a9c1c3ab 714 { assign; } \
c32e827b 715 \
e77405ad
SR
716 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
717 trace_nowake_buffer_unlock_commit(buffer, \
718 event, irq_flags, pc); \
ff038f5c
SR
719}
720
721#undef DEFINE_EVENT
722#define DEFINE_EVENT(template, call, proto, args) \
723 \
724static void ftrace_raw_event_##call(proto) \
725{ \
726 ftrace_raw_event_id_##template(&event_##call, args); \
c32e827b
SR
727} \
728 \
bd1a5c84 729static int ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)\
c32e827b
SR
730{ \
731 int ret; \
732 \
733 ret = register_trace_##call(ftrace_raw_event_##call); \
633ddaa7 734 if (ret) \
c32e827b 735 pr_info("event trace: Could not activate trace point " \
633ddaa7 736 "probe to " #call "\n"); \
c32e827b
SR
737 return ret; \
738} \
739 \
bd1a5c84 740static void ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused)\
c32e827b
SR
741{ \
742 unregister_trace_##call(ftrace_raw_event_##call); \
743} \
744 \
745static struct trace_event ftrace_event_type_##call = { \
746 .trace = ftrace_raw_output_##call, \
747}; \
748 \
bd1a5c84 749static int ftrace_raw_init_event_##call(struct ftrace_event_call *unused)\
c32e827b
SR
750{ \
751 int id; \
752 \
753 id = register_ftrace_event(&ftrace_event_type_##call); \
754 if (!id) \
755 return -ENODEV; \
756 event_##call.id = id; \
cf027f64 757 INIT_LIST_HEAD(&event_##call.fields); \
c32e827b 758 return 0; \
e5bc9721
SR
759}
760
761#undef DEFINE_EVENT_PRINT
762#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
763 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
764
765#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
766
767#undef TRACE_EVENT_TEMPLATE
768#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print)
769
770#undef DEFINE_EVENT
771#define DEFINE_EVENT(template, call, proto, args) \
c32e827b
SR
772 \
773static struct ftrace_event_call __used \
774__attribute__((__aligned__(4))) \
775__attribute__((section("_ftrace_events"))) event_##call = { \
ef18012b 776 .name = #call, \
9cc26a26 777 .system = __stringify(TRACE_SYSTEM), \
6d723736 778 .event = &ftrace_event_type_##call, \
c32e827b 779 .raw_init = ftrace_raw_init_event_##call, \
da4d0302
SR
780 .regfunc = ftrace_raw_reg_event_##call, \
781 .unregfunc = ftrace_raw_unreg_event_##call, \
ff038f5c
SR
782 .show_format = ftrace_format_##template, \
783 .define_fields = ftrace_define_fields_##template, \
ac199db0 784 _TRACE_PROFILE_INIT(call) \
c32e827b 785}
ac199db0 786
e5bc9721
SR
787#undef DEFINE_EVENT_PRINT
788#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
789 \
790static struct ftrace_event_call __used \
791__attribute__((__aligned__(4))) \
792__attribute__((section("_ftrace_events"))) event_##call = { \
793 .name = #call, \
794 .system = __stringify(TRACE_SYSTEM), \
795 .event = &ftrace_event_type_##call, \
796 .raw_init = ftrace_raw_init_event_##call, \
797 .regfunc = ftrace_raw_reg_event_##call, \
798 .unregfunc = ftrace_raw_unreg_event_##call, \
799 .show_format = ftrace_format_##call, \
800 .define_fields = ftrace_define_fields_##template, \
801 _TRACE_PROFILE_INIT(call) \
802}
803
f42c85e7 804#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
ac199db0 805
f413cdb8
FW
806/*
807 * Define the insertion callback to profile events
808 *
809 * The job is very similar to ftrace_raw_event_<call> except that we don't
810 * insert in the ring buffer but in a perf counter.
811 *
812 * static void ftrace_profile_<call>(proto)
813 * {
814 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
815 * struct ftrace_event_call *event_call = &event_<call>;
cdd6c482 816 * extern void perf_tp_event(int, u64, u64, void *, int);
f413cdb8 817 * struct ftrace_raw_##call *entry;
444a2a3b 818 * struct perf_trace_buf *trace_buf;
f413cdb8
FW
819 * u64 __addr = 0, __count = 1;
820 * unsigned long irq_flags;
20ab4425 821 * struct trace_entry *ent;
f413cdb8
FW
822 * int __entry_size;
823 * int __data_size;
20ab4425 824 * int __cpu
f413cdb8
FW
825 * int pc;
826 *
f413cdb8
FW
827 * pc = preempt_count();
828 *
829 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
304703ab
FW
830 *
831 * // Below we want to get the aligned size by taking into account
832 * // the u32 field that will later store the buffer size
833 * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
834 * sizeof(u64));
835 * __entry_size -= sizeof(u32);
f413cdb8 836 *
20ab4425
FW
837 * // Protect the non nmi buffer
838 * // This also protects the rcu read side
839 * local_irq_save(irq_flags);
840 * __cpu = smp_processor_id();
841 *
842 * if (in_nmi())
444a2a3b 843 * trace_buf = rcu_dereference(perf_trace_buf_nmi);
20ab4425 844 * else
444a2a3b 845 * trace_buf = rcu_dereference(perf_trace_buf);
20ab4425 846 *
444a2a3b 847 * if (!trace_buf)
20ab4425 848 * goto end;
f413cdb8 849 *
444a2a3b
FW
850 * trace_buf = per_cpu_ptr(trace_buf, __cpu);
851 *
852 * // Avoid recursion from perf that could mess up the buffer
853 * if (trace_buf->recursion++)
854 * goto end_recursion;
855 *
856 * raw_data = trace_buf->buf;
857 *
858 * // Make recursion update visible before entering perf_tp_event
859 * // so that we protect from perf recursions.
860 *
861 * barrier();
1853db0e 862 *
20ab4425
FW
863 * //zero dead bytes from alignment to avoid stack leak to userspace:
864 * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
865 * entry = (struct ftrace_raw_<call> *)raw_data;
866 * ent = &entry->ent;
867 * tracing_generic_entry_update(ent, irq_flags, pc);
868 * ent->type = event_call->id;
f413cdb8 869 *
20ab4425 870 * <tstruct> <- do some jobs with dynamic arrays
f413cdb8 871 *
20ab4425 872 * <assign> <- affect our values
f413cdb8 873 *
43c1266c 874 * perf_tp_event(event_call->id, __addr, __count, entry,
20ab4425 875 * __entry_size); <- submit them to perf counter
f413cdb8
FW
876 *
877 * }
878 */
879
880#ifdef CONFIG_EVENT_PROFILE
881
882#undef __perf_addr
883#define __perf_addr(a) __addr = (a)
884
885#undef __perf_count
886#define __perf_count(c) __count = (c)
887
ff038f5c
SR
888#undef TRACE_EVENT_TEMPLATE
889#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
890static void \
891ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
892 proto) \
f413cdb8
FW
893{ \
894 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
4ed7c92d
PZ
895 extern int perf_swevent_get_recursion_context(void); \
896 extern void perf_swevent_put_recursion_context(int rctx); \
444a2a3b 897 extern void perf_tp_event(int, u64, u64, void *, int); \
f413cdb8
FW
898 struct ftrace_raw_##call *entry; \
899 u64 __addr = 0, __count = 1; \
900 unsigned long irq_flags; \
20ab4425 901 struct trace_entry *ent; \
f413cdb8
FW
902 int __entry_size; \
903 int __data_size; \
ce71b9df 904 char *trace_buf; \
20ab4425
FW
905 char *raw_data; \
906 int __cpu; \
4ed7c92d 907 int rctx; \
f413cdb8
FW
908 int pc; \
909 \
f413cdb8
FW
910 pc = preempt_count(); \
911 \
912 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
a044560c
PZ
913 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
914 sizeof(u64)); \
304703ab 915 __entry_size -= sizeof(u32); \
f413cdb8 916 \
20ab4425
FW
917 if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE, \
918 "profile buffer not large enough")) \
919 return; \
920 \
921 local_irq_save(irq_flags); \
ce71b9df 922 \
4ed7c92d
PZ
923 rctx = perf_swevent_get_recursion_context(); \
924 if (rctx < 0) \
925 goto end_recursion; \
ce71b9df 926 \
20ab4425 927 __cpu = smp_processor_id(); \
f413cdb8 928 \
20ab4425 929 if (in_nmi()) \
444a2a3b 930 trace_buf = rcu_dereference(perf_trace_buf_nmi); \
20ab4425 931 else \
444a2a3b 932 trace_buf = rcu_dereference(perf_trace_buf); \
f413cdb8 933 \
444a2a3b 934 if (!trace_buf) \
20ab4425 935 goto end; \
f413cdb8 936 \
ce71b9df 937 raw_data = per_cpu_ptr(trace_buf, __cpu); \
f413cdb8 938 \
20ab4425
FW
939 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
940 entry = (struct ftrace_raw_##call *)raw_data; \
941 ent = &entry->ent; \
942 tracing_generic_entry_update(ent, irq_flags, pc); \
943 ent->type = event_call->id; \
944 \
945 tstruct \
946 \
947 { assign; } \
948 \
43c1266c 949 perf_tp_event(event_call->id, __addr, __count, entry, \
f413cdb8 950 __entry_size); \
20ab4425 951 \
4ed7c92d
PZ
952end: \
953 perf_swevent_put_recursion_context(rctx); \
954end_recursion: \
20ab4425 955 local_irq_restore(irq_flags); \
f413cdb8
FW
956 \
957}
958
ff038f5c
SR
959#undef DEFINE_EVENT
960#define DEFINE_EVENT(template, call, proto, args) \
961static void ftrace_profile_##call(proto) \
962{ \
963 struct ftrace_event_call *event_call = &event_##call; \
964 \
965 ftrace_profile_templ_##template(event_call, args); \
966}
967
e5bc9721
SR
968#undef DEFINE_EVENT_PRINT
969#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
970 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
971
f413cdb8
FW
972#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
973#endif /* CONFIG_EVENT_PROFILE */
974
ac199db0
PZ
975#undef _TRACE_PROFILE_INIT
976