]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/trace/ftrace.h
tracing/ring-buffer: Move poll wake ups into ring buffer code
[mirror_ubuntu-bionic-kernel.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 21/*
091ad365 22 * DECLARE_EVENT_CLASS can be used to add a generic function
ff038f5c
SR
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
091ad365 26 * will map the DECLARE_EVENT_CLASS to the tracepoint.
ff038f5c
SR
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) \
091ad365 32 DECLARE_EVENT_CLASS(name, \
ff038f5c
SR
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
091ad365
IM
59#undef DECLARE_EVENT_CLASS
60#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
ff038f5c
SR
61 struct ftrace_raw_##name { \
62 struct trace_entry ent; \
63 tstruct \
64 char __data[0]; \
8f082018
SR
65 }; \
66 \
67 static struct ftrace_event_class event_class_##name;
68
ff038f5c
SR
69#undef DEFINE_EVENT
70#define DEFINE_EVENT(template, name, proto, args) \
49c17746 71 static struct ftrace_event_call __used \
86c38a31 72 __attribute__((__aligned__(4))) event_##name
f42c85e7 73
e5bc9721
SR
74#undef DEFINE_EVENT_PRINT
75#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
76 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
77
97419875
JS
78/* Callbacks are meaningless to ftrace. */
79#undef TRACE_EVENT_FN
0dd7b747
FW
80#define TRACE_EVENT_FN(name, proto, args, tstruct, \
81 assign, print, reg, unreg) \
819ce45a
FW
82 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
83 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
97419875 84
1ed0c597
FW
85#undef TRACE_EVENT_FLAGS
86#define TRACE_EVENT_FLAGS(name, value) \
53cf810b 87 __TRACE_EVENT_FLAGS(name, value)
1ed0c597 88
f42c85e7
SR
89#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
90
9cbf1176 91
f42c85e7
SR
92/*
93 * Stage 2 of the trace events.
94 *
9cbf1176
FW
95 * Include the following:
96 *
7fcb7c47 97 * struct ftrace_data_offsets_<call> {
7d536cb3
LZ
98 * u32 <item1>;
99 * u32 <item2>;
9cbf1176
FW
100 * [...]
101 * };
102 *
7d536cb3 103 * The __dynamic_array() macro will create each u32 <item>, this is
7fcb7c47 104 * to keep the offset of each array from the beginning of the event.
7d536cb3 105 * The size of an array is also encoded, in the higher 16 bits of <item>.
9cbf1176
FW
106 */
107
7fcb7c47 108#undef __field
43b51ead
LZ
109#define __field(type, item)
110
111#undef __field_ext
112#define __field_ext(type, item, filter_type)
7fcb7c47 113
9cbf1176
FW
114#undef __array
115#define __array(type, item, len)
116
7fcb7c47 117#undef __dynamic_array
7d536cb3 118#define __dynamic_array(type, item, len) u32 item;
9cbf1176
FW
119
120#undef __string
7fcb7c47 121#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 122
091ad365
IM
123#undef DECLARE_EVENT_CLASS
124#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
7fcb7c47 125 struct ftrace_data_offsets_##call { \
9cbf1176
FW
126 tstruct; \
127 };
128
ff038f5c
SR
129#undef DEFINE_EVENT
130#define DEFINE_EVENT(template, name, proto, args)
131
e5bc9721
SR
132#undef DEFINE_EVENT_PRINT
133#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
134 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
135
1ed0c597
FW
136#undef TRACE_EVENT_FLAGS
137#define TRACE_EVENT_FLAGS(event, flag)
138
9cbf1176
FW
139#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
140
141/*
142 * Stage 3 of the trace events.
143 *
f42c85e7
SR
144 * Override the macros in <trace/trace_events.h> to include the following:
145 *
146 * enum print_line_t
147 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
148 * {
149 * struct trace_seq *s = &iter->seq;
150 * struct ftrace_raw_<call> *field; <-- defined in stage 1
151 * struct trace_entry *entry;
bc289ae9 152 * struct trace_seq *p = &iter->tmp_seq;
f42c85e7
SR
153 * int ret;
154 *
155 * entry = iter->ent;
156 *
32c0edae 157 * if (entry->type != event_<call>->event.type) {
f42c85e7
SR
158 * WARN_ON_ONCE(1);
159 * return TRACE_TYPE_UNHANDLED;
160 * }
161 *
162 * field = (typeof(field))entry;
163 *
56d8bd3f 164 * trace_seq_init(p);
50354a8a
LZ
165 * ret = trace_seq_printf(s, "%s: ", <call>);
166 * if (ret)
167 * ret = trace_seq_printf(s, <TP_printk> "\n");
f42c85e7
SR
168 * if (!ret)
169 * return TRACE_TYPE_PARTIAL_LINE;
170 *
171 * return TRACE_TYPE_HANDLED;
172 * }
173 *
174 * This is the method used to print the raw event to the trace
175 * output format. Note, this is not needed if the data is read
176 * in binary.
177 */
178
179#undef __entry
180#define __entry field
181
182#undef TP_printk
183#define TP_printk(fmt, args...) fmt "\n", args
184
7fcb7c47
LZ
185#undef __get_dynamic_array
186#define __get_dynamic_array(field) \
7d536cb3 187 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
7fcb7c47 188
9cbf1176 189#undef __get_str
7fcb7c47 190#define __get_str(field) (char *)__get_dynamic_array(field)
9cbf1176 191
be74b73a
SR
192#undef __print_flags
193#define __print_flags(flag, delim, flag_array...) \
194 ({ \
a48f494e 195 static const struct trace_print_flags __flags[] = \
be74b73a 196 { flag_array, { -1, NULL }}; \
a48f494e 197 ftrace_print_flags_seq(p, delim, flag, __flags); \
be74b73a
SR
198 })
199
0f4fc29d
SR
200#undef __print_symbolic
201#define __print_symbolic(value, symbol_array...) \
202 ({ \
203 static const struct trace_print_flags symbols[] = \
204 { symbol_array, { -1, NULL }}; \
205 ftrace_print_symbols_seq(p, value, symbols); \
206 })
207
2fc1b6f0 208#undef __print_symbolic_u64
209#if BITS_PER_LONG == 32
210#define __print_symbolic_u64(value, symbol_array...) \
211 ({ \
212 static const struct trace_print_flags_u64 symbols[] = \
213 { symbol_array, { -1, NULL } }; \
214 ftrace_print_symbols_seq_u64(p, value, symbols); \
215 })
216#else
217#define __print_symbolic_u64(value, symbol_array...) \
218 __print_symbolic(value, symbol_array)
219#endif
220
5a2e3995
KT
221#undef __print_hex
222#define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)
223
091ad365
IM
224#undef DECLARE_EVENT_CLASS
225#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
83f0d539 226static notrace enum print_line_t \
80decc70
SR
227ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
228 struct trace_event *trace_event) \
f42c85e7 229{ \
80decc70 230 struct ftrace_event_call *event; \
f42c85e7
SR
231 struct trace_seq *s = &iter->seq; \
232 struct ftrace_raw_##call *field; \
233 struct trace_entry *entry; \
bc289ae9 234 struct trace_seq *p = &iter->tmp_seq; \
f42c85e7
SR
235 int ret; \
236 \
80decc70
SR
237 event = container_of(trace_event, struct ftrace_event_call, \
238 event); \
239 \
f42c85e7
SR
240 entry = iter->ent; \
241 \
32c0edae 242 if (entry->type != event->event.type) { \
f42c85e7
SR
243 WARN_ON_ONCE(1); \
244 return TRACE_TYPE_UNHANDLED; \
245 } \
246 \
247 field = (typeof(field))entry; \
248 \
56d8bd3f 249 trace_seq_init(p); \
80decc70 250 ret = trace_seq_printf(s, "%s: ", event->name); \
ff038f5c
SR
251 if (ret) \
252 ret = trace_seq_printf(s, print); \
f42c85e7
SR
253 if (!ret) \
254 return TRACE_TYPE_PARTIAL_LINE; \
255 \
256 return TRACE_TYPE_HANDLED; \
80decc70
SR
257} \
258static struct trace_event_functions ftrace_event_type_funcs_##call = { \
259 .trace = ftrace_raw_output_##call, \
260};
ff038f5c 261
e5bc9721
SR
262#undef DEFINE_EVENT_PRINT
263#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
83f0d539 264static notrace enum print_line_t \
a9a57763
SR
265ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
266 struct trace_event *event) \
e5bc9721
SR
267{ \
268 struct trace_seq *s = &iter->seq; \
269 struct ftrace_raw_##template *field; \
270 struct trace_entry *entry; \
bc289ae9 271 struct trace_seq *p = &iter->tmp_seq; \
f42c85e7
SR
272 int ret; \
273 \
274 entry = iter->ent; \
275 \
32c0edae 276 if (entry->type != event_##call.event.type) { \
f42c85e7
SR
277 WARN_ON_ONCE(1); \
278 return TRACE_TYPE_UNHANDLED; \
279 } \
280 \
281 field = (typeof(field))entry; \
282 \
56d8bd3f 283 trace_seq_init(p); \
e5bc9721
SR
284 ret = trace_seq_printf(s, "%s: ", #call); \
285 if (ret) \
286 ret = trace_seq_printf(s, print); \
f42c85e7
SR
287 if (!ret) \
288 return TRACE_TYPE_PARTIAL_LINE; \
289 \
290 return TRACE_TYPE_HANDLED; \
80decc70
SR
291} \
292static struct trace_event_functions ftrace_event_type_funcs_##call = { \
293 .trace = ftrace_raw_output_##call, \
294};
e5bc9721 295
f42c85e7
SR
296#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
297
43b51ead
LZ
298#undef __field_ext
299#define __field_ext(type, item, filter_type) \
f42c85e7
SR
300 ret = trace_define_field(event_call, #type, #item, \
301 offsetof(typeof(field), item), \
43b51ead
LZ
302 sizeof(field.item), \
303 is_signed_type(type), filter_type); \
f42c85e7
SR
304 if (ret) \
305 return ret;
306
43b51ead
LZ
307#undef __field
308#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
309
f42c85e7
SR
310#undef __array
311#define __array(type, item, len) \
04295780
SR
312 do { \
313 mutex_lock(&event_storage_mutex); \
314 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
315 snprintf(event_storage, sizeof(event_storage), \
316 "%s[%d]", #type, len); \
317 ret = trace_define_field(event_call, event_storage, #item, \
f42c85e7 318 offsetof(typeof(field), item), \
fb7ae981
LJ
319 sizeof(field.item), \
320 is_signed_type(type), FILTER_OTHER); \
04295780
SR
321 mutex_unlock(&event_storage_mutex); \
322 if (ret) \
323 return ret; \
324 } while (0);
f42c85e7 325
7fcb7c47
LZ
326#undef __dynamic_array
327#define __dynamic_array(type, item, len) \
68fd60a8 328 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
43b51ead 329 offsetof(typeof(field), __data_loc_##item), \
fb7ae981
LJ
330 sizeof(field.__data_loc_##item), \
331 is_signed_type(type), FILTER_OTHER);
7fcb7c47 332
9cbf1176 333#undef __string
7fcb7c47 334#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 335
091ad365
IM
336#undef DECLARE_EVENT_CLASS
337#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
83f0d539 338static int notrace \
14be96c9 339ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
f42c85e7
SR
340{ \
341 struct ftrace_raw_##call field; \
f42c85e7
SR
342 int ret; \
343 \
f42c85e7
SR
344 tstruct; \
345 \
346 return ret; \
347}
348
ff038f5c
SR
349#undef DEFINE_EVENT
350#define DEFINE_EVENT(template, name, proto, args)
351
e5bc9721
SR
352#undef DEFINE_EVENT_PRINT
353#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
354 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
355
f42c85e7
SR
356#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
357
7fcb7c47
LZ
358/*
359 * remember the offset of each array from the beginning of the event.
360 */
361
362#undef __entry
363#define __entry entry
364
365#undef __field
366#define __field(type, item)
367
43b51ead
LZ
368#undef __field_ext
369#define __field_ext(type, item, filter_type)
370
7fcb7c47
LZ
371#undef __array
372#define __array(type, item, len)
373
374#undef __dynamic_array
375#define __dynamic_array(type, item, len) \
376 __data_offsets->item = __data_size + \
377 offsetof(typeof(*entry), __data); \
7d536cb3 378 __data_offsets->item |= (len * sizeof(type)) << 16; \
7fcb7c47
LZ
379 __data_size += (len) * sizeof(type);
380
381#undef __string
ff038f5c 382#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
7fcb7c47 383
091ad365
IM
384#undef DECLARE_EVENT_CLASS
385#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
83f0d539 386static inline notrace int ftrace_get_offsets_##call( \
7fcb7c47
LZ
387 struct ftrace_data_offsets_##call *__data_offsets, proto) \
388{ \
389 int __data_size = 0; \
390 struct ftrace_raw_##call __maybe_unused *entry; \
391 \
392 tstruct; \
393 \
394 return __data_size; \
395}
396
ff038f5c
SR
397#undef DEFINE_EVENT
398#define DEFINE_EVENT(template, name, proto, args)
399
e5bc9721
SR
400#undef DEFINE_EVENT_PRINT
401#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
402 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
403
7fcb7c47
LZ
404#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
405
c32e827b 406/*
9cbf1176 407 * Stage 4 of the trace events.
c32e827b 408 *
ea20d929 409 * Override the macros in <trace/trace_events.h> to include the following:
c32e827b 410 *
157587d7 411 * For those macros defined with TRACE_EVENT:
c32e827b
SR
412 *
413 * static struct ftrace_event_call event_<call>;
414 *
2239291a 415 * static void ftrace_raw_event_<call>(void *__data, proto)
c32e827b 416 * {
ccb469a1
SR
417 * struct ftrace_event_file *ftrace_file = __data;
418 * struct ftrace_event_call *event_call = ftrace_file->event_call;
50354a8a 419 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
ef18012b
SR
420 * struct ring_buffer_event *event;
421 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
e77405ad 422 * struct ring_buffer *buffer;
ef18012b 423 * unsigned long irq_flags;
50354a8a 424 * int __data_size;
ef18012b
SR
425 * int pc;
426 *
427 * local_save_flags(irq_flags);
428 * pc = preempt_count();
429 *
50354a8a
LZ
430 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
431 *
ccb469a1 432 * event = trace_event_buffer_lock_reserve(&buffer, ftrace_file,
32c0edae 433 * event_<call>->event.type,
50354a8a 434 * sizeof(*entry) + __data_size,
ef18012b
SR
435 * irq_flags, pc);
436 * if (!event)
437 * return;
438 * entry = ring_buffer_event_data(event);
439 *
50354a8a
LZ
440 * { <assign>; } <-- Here we assign the entries by the __field and
441 * __array macros.
c32e827b 442 *
50354a8a 443 * if (!filter_current_check_discard(buffer, event_call, entry, event))
ccb469a1 444 * trace_nowake_buffer_unlock_commit(buffer,
50354a8a 445 * event, irq_flags, pc);
c32e827b
SR
446 * }
447 *
c32e827b 448 * static struct trace_event ftrace_event_type_<call> = {
ef18012b 449 * .trace = ftrace_raw_output_<call>, <-- stage 2
c32e827b
SR
450 * };
451 *
50354a8a
LZ
452 * static const char print_fmt_<call>[] = <TP_printk>;
453 *
8f082018
SR
454 * static struct ftrace_event_class __used event_class_<template> = {
455 * .system = "<system>",
2e33af02 456 * .define_fields = ftrace_define_fields_<call>,
0405ab80
SR
457 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
458 * .raw_init = trace_event_raw_init,
459 * .probe = ftrace_raw_event_##call,
a1d0ce82 460 * .reg = ftrace_event_reg,
8f082018
SR
461 * };
462 *
e4a9ea5e 463 * static struct ftrace_event_call event_<call> = {
ef18012b 464 * .name = "<call>",
8f082018 465 * .class = event_class_<template>,
2e33af02 466 * .event = &ftrace_event_type_<call>,
50354a8a 467 * .print_fmt = print_fmt_<call>,
8f082018 468 * };
e4a9ea5e
SR
469 * // its only safe to use pointers when doing linker tricks to
470 * // create an array.
471 * static struct ftrace_event_call __used
472 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
c32e827b
SR
473 *
474 */
475
07b139c8 476#ifdef CONFIG_PERF_EVENTS
ac199db0 477
2239291a
SR
478#define _TRACE_PERF_PROTO(call, proto) \
479 static notrace void \
480 perf_trace_##call(void *__data, proto);
481
97d5a220 482#define _TRACE_PERF_INIT(call) \
2239291a 483 .perf_probe = perf_trace_##call,
ac199db0
PZ
484
485#else
2239291a 486#define _TRACE_PERF_PROTO(call, proto)
97d5a220 487#define _TRACE_PERF_INIT(call)
07b139c8 488#endif /* CONFIG_PERF_EVENTS */
ac199db0 489
da4d0302
SR
490#undef __entry
491#define __entry entry
d20e3b03 492
9cbf1176
FW
493#undef __field
494#define __field(type, item)
495
496#undef __array
497#define __array(type, item, len)
498
7fcb7c47
LZ
499#undef __dynamic_array
500#define __dynamic_array(type, item, len) \
501 __entry->__data_loc_##item = __data_offsets.item;
502
9cbf1176 503#undef __string
7fcb7c47 504#define __string(item, src) __dynamic_array(char, item, -1) \
9cbf1176
FW
505
506#undef __assign_str
507#define __assign_str(dst, src) \
9cbf1176
FW
508 strcpy(__get_str(dst), src);
509
0fa0edaf
LJ
510#undef TP_fast_assign
511#define TP_fast_assign(args...) args
512
513#undef TP_perf_assign
514#define TP_perf_assign(args...)
515
091ad365
IM
516#undef DECLARE_EVENT_CLASS
517#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
c32e827b 518 \
83f0d539 519static notrace void \
2239291a 520ftrace_raw_event_##call(void *__data, proto) \
c32e827b 521{ \
ae63b31e
SR
522 struct ftrace_event_file *ftrace_file = __data; \
523 struct ftrace_event_call *event_call = ftrace_file->event_call; \
7fcb7c47 524 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
c32e827b
SR
525 struct ring_buffer_event *event; \
526 struct ftrace_raw_##call *entry; \
e77405ad 527 struct ring_buffer *buffer; \
c32e827b 528 unsigned long irq_flags; \
7fcb7c47 529 int __data_size; \
c32e827b
SR
530 int pc; \
531 \
532 local_save_flags(irq_flags); \
533 pc = preempt_count(); \
534 \
7fcb7c47 535 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
9cbf1176 536 \
ccb469a1 537 event = trace_event_buffer_lock_reserve(&buffer, ftrace_file, \
32c0edae 538 event_call->event.type, \
7fcb7c47 539 sizeof(*entry) + __data_size, \
9cbf1176 540 irq_flags, pc); \
c32e827b
SR
541 if (!event) \
542 return; \
543 entry = ring_buffer_event_data(event); \
544 \
7fcb7c47
LZ
545 tstruct \
546 \
a9c1c3ab 547 { assign; } \
c32e827b 548 \
e77405ad 549 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
0d5c6e1c 550 trace_buffer_unlock_commit(buffer, event, irq_flags, pc); \
ff038f5c 551}
2239291a
SR
552/*
553 * The ftrace_test_probe is compiled out, it is only here as a build time check
554 * to make sure that if the tracepoint handling changes, the ftrace probe will
555 * fail to compile unless it too is updated.
556 */
ff038f5c
SR
557
558#undef DEFINE_EVENT
559#define DEFINE_EVENT(template, call, proto, args) \
2239291a 560static inline void ftrace_test_probe_##call(void) \
c32e827b 561{ \
2239291a
SR
562 check_trace_callback_type_##call(ftrace_raw_event_##template); \
563}
e5bc9721
SR
564
565#undef DEFINE_EVENT_PRINT
80decc70 566#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
e5bc9721
SR
567
568#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
569
509e760c
LJ
570#undef __entry
571#define __entry REC
572
573#undef __print_flags
574#undef __print_symbolic
b102f1d0 575#undef __print_hex
509e760c
LJ
576#undef __get_dynamic_array
577#undef __get_str
578
579#undef TP_printk
580#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
581
091ad365 582#undef DECLARE_EVENT_CLASS
509e760c 583#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
2239291a 584_TRACE_PERF_PROTO(call, PARAMS(proto)); \
8f082018
SR
585static const char print_fmt_##call[] = print; \
586static struct ftrace_event_class __used event_class_##call = { \
2239291a 587 .system = __stringify(TRACE_SYSTEM), \
2e33af02
SR
588 .define_fields = ftrace_define_fields_##call, \
589 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
0405ab80 590 .raw_init = trace_event_raw_init, \
2239291a 591 .probe = ftrace_raw_event_##call, \
a1d0ce82 592 .reg = ftrace_event_reg, \
2239291a 593 _TRACE_PERF_INIT(call) \
8f082018 594};
e5bc9721
SR
595
596#undef DEFINE_EVENT
597#define DEFINE_EVENT(template, call, proto, args) \
c32e827b 598 \
e4a9ea5e 599static struct ftrace_event_call __used event_##call = { \
ef18012b 600 .name = #call, \
8f082018 601 .class = &event_class_##template, \
80decc70 602 .event.funcs = &ftrace_event_type_funcs_##template, \
509e760c 603 .print_fmt = print_fmt_##template, \
e4a9ea5e
SR
604}; \
605static struct ftrace_event_call __used \
606__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
ac199db0 607
e5bc9721
SR
608#undef DEFINE_EVENT_PRINT
609#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
c32e827b 610 \
509e760c
LJ
611static const char print_fmt_##call[] = print; \
612 \
e4a9ea5e 613static struct ftrace_event_call __used event_##call = { \
ef18012b 614 .name = #call, \
8f082018 615 .class = &event_class_##template, \
80decc70 616 .event.funcs = &ftrace_event_type_funcs_##call, \
509e760c 617 .print_fmt = print_fmt_##call, \
e4a9ea5e
SR
618}; \
619static struct ftrace_event_call __used \
620__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
ac199db0 621
f42c85e7 622#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
ac199db0 623
f413cdb8 624
07b139c8 625#ifdef CONFIG_PERF_EVENTS
f413cdb8 626
509e760c
LJ
627#undef __entry
628#define __entry entry
629
630#undef __get_dynamic_array
631#define __get_dynamic_array(field) \
632 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
633
634#undef __get_str
635#define __get_str(field) (char *)__get_dynamic_array(field)
636
f413cdb8
FW
637#undef __perf_addr
638#define __perf_addr(a) __addr = (a)
639
640#undef __perf_count
641#define __perf_count(c) __count = (c)
642
e6dab5ff
AV
643#undef __perf_task
644#define __perf_task(t) __task = (t)
645
92e51938
AV
646#undef TP_perf_assign
647#define TP_perf_assign(args...) args
648
091ad365
IM
649#undef DECLARE_EVENT_CLASS
650#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
83f0d539 651static notrace void \
2239291a 652perf_trace_##call(void *__data, proto) \
f413cdb8 653{ \
2239291a 654 struct ftrace_event_call *event_call = __data; \
f413cdb8 655 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
f413cdb8 656 struct ftrace_raw_##call *entry; \
ff5f149b 657 struct pt_regs __regs; \
f413cdb8 658 u64 __addr = 0, __count = 1; \
e6dab5ff 659 struct task_struct *__task = NULL; \
1c024eca 660 struct hlist_head *head; \
f413cdb8
FW
661 int __entry_size; \
662 int __data_size; \
4ed7c92d 663 int rctx; \
f413cdb8 664 \
b0f82b81 665 perf_fetch_caller_regs(&__regs); \
f0218b3e 666 \
f413cdb8 667 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
a044560c
PZ
668 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
669 sizeof(u64)); \
304703ab 670 __entry_size -= sizeof(u32); \
f413cdb8 671 \
97d5a220 672 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
20ab4425
FW
673 "profile buffer not large enough")) \
674 return; \
b7e2ecef 675 \
97d5a220 676 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
ff5f149b 677 __entry_size, event_call->event.type, &__regs, &rctx); \
430ad5a6
XG
678 if (!entry) \
679 return; \
b7e2ecef 680 \
20ab4425
FW
681 tstruct \
682 \
683 { assign; } \
684 \
3771f077 685 head = this_cpu_ptr(event_call->perf_events); \
97d5a220 686 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
e6dab5ff 687 __count, &__regs, head, __task); \
f413cdb8
FW
688}
689
2239291a
SR
690/*
691 * This part is compiled out, it is only here as a build time check
692 * to make sure that if the tracepoint handling changes, the
693 * perf probe will fail to compile unless it too is updated.
694 */
ff038f5c 695#undef DEFINE_EVENT
6cc8a7c1 696#define DEFINE_EVENT(template, call, proto, args) \
2239291a 697static inline void perf_test_probe_##call(void) \
6cc8a7c1 698{ \
2239291a 699 check_trace_callback_type_##call(perf_trace_##template); \
ff038f5c
SR
700}
701
2239291a 702
e5bc9721
SR
703#undef DEFINE_EVENT_PRINT
704#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
705 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
706
f413cdb8 707#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
07b139c8 708#endif /* CONFIG_PERF_EVENTS */
f413cdb8 709
ac199db0
PZ
710#undef _TRACE_PROFILE_INIT
711