]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/trace/ftrace.h
tracing: Add a helper function for event print functions
[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
SR
229{ \
230 struct trace_seq *s = &iter->seq; \
f71130de 231 struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
f42c85e7 232 struct ftrace_raw_##call *field; \
f42c85e7
SR
233 int ret; \
234 \
f71130de 235 field = (typeof(field))iter->ent; \
80decc70 236 \
f71130de 237 ret = ftrace_raw_output_prep(iter, trace_event); \
ff038f5c 238 if (ret) \
f71130de
LZ
239 return ret; \
240 \
241 ret = trace_seq_printf(s, print); \
f42c85e7
SR
242 if (!ret) \
243 return TRACE_TYPE_PARTIAL_LINE; \
244 \
245 return TRACE_TYPE_HANDLED; \
80decc70
SR
246} \
247static struct trace_event_functions ftrace_event_type_funcs_##call = { \
248 .trace = ftrace_raw_output_##call, \
249};
ff038f5c 250
e5bc9721
SR
251#undef DEFINE_EVENT_PRINT
252#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
83f0d539 253static notrace enum print_line_t \
a9a57763
SR
254ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
255 struct trace_event *event) \
e5bc9721
SR
256{ \
257 struct trace_seq *s = &iter->seq; \
258 struct ftrace_raw_##template *field; \
259 struct trace_entry *entry; \
bc289ae9 260 struct trace_seq *p = &iter->tmp_seq; \
f42c85e7
SR
261 int ret; \
262 \
263 entry = iter->ent; \
264 \
32c0edae 265 if (entry->type != event_##call.event.type) { \
f42c85e7
SR
266 WARN_ON_ONCE(1); \
267 return TRACE_TYPE_UNHANDLED; \
268 } \
269 \
270 field = (typeof(field))entry; \
271 \
56d8bd3f 272 trace_seq_init(p); \
e5bc9721
SR
273 ret = trace_seq_printf(s, "%s: ", #call); \
274 if (ret) \
275 ret = trace_seq_printf(s, print); \
f42c85e7
SR
276 if (!ret) \
277 return TRACE_TYPE_PARTIAL_LINE; \
278 \
279 return TRACE_TYPE_HANDLED; \
80decc70
SR
280} \
281static struct trace_event_functions ftrace_event_type_funcs_##call = { \
282 .trace = ftrace_raw_output_##call, \
283};
e5bc9721 284
f42c85e7
SR
285#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
286
43b51ead
LZ
287#undef __field_ext
288#define __field_ext(type, item, filter_type) \
f42c85e7
SR
289 ret = trace_define_field(event_call, #type, #item, \
290 offsetof(typeof(field), item), \
43b51ead
LZ
291 sizeof(field.item), \
292 is_signed_type(type), filter_type); \
f42c85e7
SR
293 if (ret) \
294 return ret;
295
43b51ead
LZ
296#undef __field
297#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
298
f42c85e7
SR
299#undef __array
300#define __array(type, item, len) \
04295780
SR
301 do { \
302 mutex_lock(&event_storage_mutex); \
303 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
304 snprintf(event_storage, sizeof(event_storage), \
305 "%s[%d]", #type, len); \
306 ret = trace_define_field(event_call, event_storage, #item, \
f42c85e7 307 offsetof(typeof(field), item), \
fb7ae981
LJ
308 sizeof(field.item), \
309 is_signed_type(type), FILTER_OTHER); \
04295780
SR
310 mutex_unlock(&event_storage_mutex); \
311 if (ret) \
312 return ret; \
313 } while (0);
f42c85e7 314
7fcb7c47
LZ
315#undef __dynamic_array
316#define __dynamic_array(type, item, len) \
68fd60a8 317 ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
43b51ead 318 offsetof(typeof(field), __data_loc_##item), \
fb7ae981
LJ
319 sizeof(field.__data_loc_##item), \
320 is_signed_type(type), FILTER_OTHER);
7fcb7c47 321
9cbf1176 322#undef __string
7fcb7c47 323#define __string(item, src) __dynamic_array(char, item, -1)
9cbf1176 324
091ad365
IM
325#undef DECLARE_EVENT_CLASS
326#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
83f0d539 327static int notrace \
14be96c9 328ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
f42c85e7
SR
329{ \
330 struct ftrace_raw_##call field; \
f42c85e7
SR
331 int ret; \
332 \
f42c85e7
SR
333 tstruct; \
334 \
335 return ret; \
336}
337
ff038f5c
SR
338#undef DEFINE_EVENT
339#define DEFINE_EVENT(template, name, proto, args)
340
e5bc9721
SR
341#undef DEFINE_EVENT_PRINT
342#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
343 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
344
f42c85e7
SR
345#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
346
7fcb7c47
LZ
347/*
348 * remember the offset of each array from the beginning of the event.
349 */
350
351#undef __entry
352#define __entry entry
353
354#undef __field
355#define __field(type, item)
356
43b51ead
LZ
357#undef __field_ext
358#define __field_ext(type, item, filter_type)
359
7fcb7c47
LZ
360#undef __array
361#define __array(type, item, len)
362
363#undef __dynamic_array
364#define __dynamic_array(type, item, len) \
365 __data_offsets->item = __data_size + \
366 offsetof(typeof(*entry), __data); \
7d536cb3 367 __data_offsets->item |= (len * sizeof(type)) << 16; \
7fcb7c47
LZ
368 __data_size += (len) * sizeof(type);
369
370#undef __string
ff038f5c 371#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
7fcb7c47 372
091ad365
IM
373#undef DECLARE_EVENT_CLASS
374#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
83f0d539 375static inline notrace int ftrace_get_offsets_##call( \
7fcb7c47
LZ
376 struct ftrace_data_offsets_##call *__data_offsets, proto) \
377{ \
378 int __data_size = 0; \
379 struct ftrace_raw_##call __maybe_unused *entry; \
380 \
381 tstruct; \
382 \
383 return __data_size; \
384}
385
ff038f5c
SR
386#undef DEFINE_EVENT
387#define DEFINE_EVENT(template, name, proto, args)
388
e5bc9721
SR
389#undef DEFINE_EVENT_PRINT
390#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
391 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
392
7fcb7c47
LZ
393#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
394
c32e827b 395/*
9cbf1176 396 * Stage 4 of the trace events.
c32e827b 397 *
ea20d929 398 * Override the macros in <trace/trace_events.h> to include the following:
c32e827b 399 *
157587d7 400 * For those macros defined with TRACE_EVENT:
c32e827b
SR
401 *
402 * static struct ftrace_event_call event_<call>;
403 *
2239291a 404 * static void ftrace_raw_event_<call>(void *__data, proto)
c32e827b 405 * {
ccb469a1
SR
406 * struct ftrace_event_file *ftrace_file = __data;
407 * struct ftrace_event_call *event_call = ftrace_file->event_call;
50354a8a 408 * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
ef18012b
SR
409 * struct ring_buffer_event *event;
410 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
e77405ad 411 * struct ring_buffer *buffer;
ef18012b 412 * unsigned long irq_flags;
50354a8a 413 * int __data_size;
ef18012b
SR
414 * int pc;
415 *
416 * local_save_flags(irq_flags);
417 * pc = preempt_count();
418 *
50354a8a
LZ
419 * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
420 *
ccb469a1 421 * event = trace_event_buffer_lock_reserve(&buffer, ftrace_file,
32c0edae 422 * event_<call>->event.type,
50354a8a 423 * sizeof(*entry) + __data_size,
ef18012b
SR
424 * irq_flags, pc);
425 * if (!event)
426 * return;
427 * entry = ring_buffer_event_data(event);
428 *
50354a8a
LZ
429 * { <assign>; } <-- Here we assign the entries by the __field and
430 * __array macros.
c32e827b 431 *
50354a8a 432 * if (!filter_current_check_discard(buffer, event_call, entry, event))
ccb469a1 433 * trace_nowake_buffer_unlock_commit(buffer,
50354a8a 434 * event, irq_flags, pc);
c32e827b
SR
435 * }
436 *
c32e827b 437 * static struct trace_event ftrace_event_type_<call> = {
ef18012b 438 * .trace = ftrace_raw_output_<call>, <-- stage 2
c32e827b
SR
439 * };
440 *
50354a8a
LZ
441 * static const char print_fmt_<call>[] = <TP_printk>;
442 *
8f082018
SR
443 * static struct ftrace_event_class __used event_class_<template> = {
444 * .system = "<system>",
2e33af02 445 * .define_fields = ftrace_define_fields_<call>,
0405ab80
SR
446 * .fields = LIST_HEAD_INIT(event_class_##call.fields),
447 * .raw_init = trace_event_raw_init,
448 * .probe = ftrace_raw_event_##call,
a1d0ce82 449 * .reg = ftrace_event_reg,
8f082018
SR
450 * };
451 *
e4a9ea5e 452 * static struct ftrace_event_call event_<call> = {
ef18012b 453 * .name = "<call>",
8f082018 454 * .class = event_class_<template>,
2e33af02 455 * .event = &ftrace_event_type_<call>,
50354a8a 456 * .print_fmt = print_fmt_<call>,
8f082018 457 * };
e4a9ea5e
SR
458 * // its only safe to use pointers when doing linker tricks to
459 * // create an array.
460 * static struct ftrace_event_call __used
461 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
c32e827b
SR
462 *
463 */
464
07b139c8 465#ifdef CONFIG_PERF_EVENTS
ac199db0 466
2239291a
SR
467#define _TRACE_PERF_PROTO(call, proto) \
468 static notrace void \
469 perf_trace_##call(void *__data, proto);
470
97d5a220 471#define _TRACE_PERF_INIT(call) \
2239291a 472 .perf_probe = perf_trace_##call,
ac199db0
PZ
473
474#else
2239291a 475#define _TRACE_PERF_PROTO(call, proto)
97d5a220 476#define _TRACE_PERF_INIT(call)
07b139c8 477#endif /* CONFIG_PERF_EVENTS */
ac199db0 478
da4d0302
SR
479#undef __entry
480#define __entry entry
d20e3b03 481
9cbf1176
FW
482#undef __field
483#define __field(type, item)
484
485#undef __array
486#define __array(type, item, len)
487
7fcb7c47
LZ
488#undef __dynamic_array
489#define __dynamic_array(type, item, len) \
490 __entry->__data_loc_##item = __data_offsets.item;
491
9cbf1176 492#undef __string
7fcb7c47 493#define __string(item, src) __dynamic_array(char, item, -1) \
9cbf1176
FW
494
495#undef __assign_str
496#define __assign_str(dst, src) \
9cbf1176
FW
497 strcpy(__get_str(dst), src);
498
0fa0edaf
LJ
499#undef TP_fast_assign
500#define TP_fast_assign(args...) args
501
502#undef TP_perf_assign
503#define TP_perf_assign(args...)
504
091ad365
IM
505#undef DECLARE_EVENT_CLASS
506#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
c32e827b 507 \
83f0d539 508static notrace void \
2239291a 509ftrace_raw_event_##call(void *__data, proto) \
c32e827b 510{ \
ae63b31e
SR
511 struct ftrace_event_file *ftrace_file = __data; \
512 struct ftrace_event_call *event_call = ftrace_file->event_call; \
7fcb7c47 513 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
c32e827b
SR
514 struct ring_buffer_event *event; \
515 struct ftrace_raw_##call *entry; \
e77405ad 516 struct ring_buffer *buffer; \
c32e827b 517 unsigned long irq_flags; \
7fcb7c47 518 int __data_size; \
c32e827b
SR
519 int pc; \
520 \
521 local_save_flags(irq_flags); \
522 pc = preempt_count(); \
523 \
7fcb7c47 524 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
9cbf1176 525 \
ccb469a1 526 event = trace_event_buffer_lock_reserve(&buffer, ftrace_file, \
32c0edae 527 event_call->event.type, \
7fcb7c47 528 sizeof(*entry) + __data_size, \
9cbf1176 529 irq_flags, pc); \
c32e827b
SR
530 if (!event) \
531 return; \
532 entry = ring_buffer_event_data(event); \
533 \
7fcb7c47
LZ
534 tstruct \
535 \
a9c1c3ab 536 { assign; } \
c32e827b 537 \
e77405ad 538 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
0d5c6e1c 539 trace_buffer_unlock_commit(buffer, event, irq_flags, pc); \
ff038f5c 540}
2239291a
SR
541/*
542 * The ftrace_test_probe is compiled out, it is only here as a build time check
543 * to make sure that if the tracepoint handling changes, the ftrace probe will
544 * fail to compile unless it too is updated.
545 */
ff038f5c
SR
546
547#undef DEFINE_EVENT
548#define DEFINE_EVENT(template, call, proto, args) \
2239291a 549static inline void ftrace_test_probe_##call(void) \
c32e827b 550{ \
2239291a
SR
551 check_trace_callback_type_##call(ftrace_raw_event_##template); \
552}
e5bc9721
SR
553
554#undef DEFINE_EVENT_PRINT
80decc70 555#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
e5bc9721
SR
556
557#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
558
509e760c
LJ
559#undef __entry
560#define __entry REC
561
562#undef __print_flags
563#undef __print_symbolic
b102f1d0 564#undef __print_hex
509e760c
LJ
565#undef __get_dynamic_array
566#undef __get_str
567
568#undef TP_printk
569#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
570
091ad365 571#undef DECLARE_EVENT_CLASS
509e760c 572#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
2239291a 573_TRACE_PERF_PROTO(call, PARAMS(proto)); \
8f082018
SR
574static const char print_fmt_##call[] = print; \
575static struct ftrace_event_class __used event_class_##call = { \
2239291a 576 .system = __stringify(TRACE_SYSTEM), \
2e33af02
SR
577 .define_fields = ftrace_define_fields_##call, \
578 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
0405ab80 579 .raw_init = trace_event_raw_init, \
2239291a 580 .probe = ftrace_raw_event_##call, \
a1d0ce82 581 .reg = ftrace_event_reg, \
2239291a 582 _TRACE_PERF_INIT(call) \
8f082018 583};
e5bc9721
SR
584
585#undef DEFINE_EVENT
586#define DEFINE_EVENT(template, call, proto, args) \
c32e827b 587 \
e4a9ea5e 588static struct ftrace_event_call __used event_##call = { \
ef18012b 589 .name = #call, \
8f082018 590 .class = &event_class_##template, \
80decc70 591 .event.funcs = &ftrace_event_type_funcs_##template, \
509e760c 592 .print_fmt = print_fmt_##template, \
e4a9ea5e
SR
593}; \
594static struct ftrace_event_call __used \
595__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
ac199db0 596
e5bc9721
SR
597#undef DEFINE_EVENT_PRINT
598#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
c32e827b 599 \
509e760c
LJ
600static const char print_fmt_##call[] = print; \
601 \
e4a9ea5e 602static struct ftrace_event_call __used event_##call = { \
ef18012b 603 .name = #call, \
8f082018 604 .class = &event_class_##template, \
80decc70 605 .event.funcs = &ftrace_event_type_funcs_##call, \
509e760c 606 .print_fmt = print_fmt_##call, \
e4a9ea5e
SR
607}; \
608static struct ftrace_event_call __used \
609__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
ac199db0 610
f42c85e7 611#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
ac199db0 612
f413cdb8 613
07b139c8 614#ifdef CONFIG_PERF_EVENTS
f413cdb8 615
509e760c
LJ
616#undef __entry
617#define __entry entry
618
619#undef __get_dynamic_array
620#define __get_dynamic_array(field) \
621 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
622
623#undef __get_str
624#define __get_str(field) (char *)__get_dynamic_array(field)
625
f413cdb8
FW
626#undef __perf_addr
627#define __perf_addr(a) __addr = (a)
628
629#undef __perf_count
630#define __perf_count(c) __count = (c)
631
e6dab5ff
AV
632#undef __perf_task
633#define __perf_task(t) __task = (t)
634
92e51938
AV
635#undef TP_perf_assign
636#define TP_perf_assign(args...) args
637
091ad365
IM
638#undef DECLARE_EVENT_CLASS
639#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
83f0d539 640static notrace void \
2239291a 641perf_trace_##call(void *__data, proto) \
f413cdb8 642{ \
2239291a 643 struct ftrace_event_call *event_call = __data; \
f413cdb8 644 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
f413cdb8 645 struct ftrace_raw_##call *entry; \
ff5f149b 646 struct pt_regs __regs; \
f413cdb8 647 u64 __addr = 0, __count = 1; \
e6dab5ff 648 struct task_struct *__task = NULL; \
1c024eca 649 struct hlist_head *head; \
f413cdb8
FW
650 int __entry_size; \
651 int __data_size; \
4ed7c92d 652 int rctx; \
f413cdb8 653 \
b0f82b81 654 perf_fetch_caller_regs(&__regs); \
f0218b3e 655 \
f413cdb8 656 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
a044560c
PZ
657 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
658 sizeof(u64)); \
304703ab 659 __entry_size -= sizeof(u32); \
f413cdb8 660 \
97d5a220 661 if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
20ab4425
FW
662 "profile buffer not large enough")) \
663 return; \
b7e2ecef 664 \
97d5a220 665 entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
ff5f149b 666 __entry_size, event_call->event.type, &__regs, &rctx); \
430ad5a6
XG
667 if (!entry) \
668 return; \
b7e2ecef 669 \
20ab4425
FW
670 tstruct \
671 \
672 { assign; } \
673 \
3771f077 674 head = this_cpu_ptr(event_call->perf_events); \
97d5a220 675 perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
e6dab5ff 676 __count, &__regs, head, __task); \
f413cdb8
FW
677}
678
2239291a
SR
679/*
680 * This part is compiled out, it is only here as a build time check
681 * to make sure that if the tracepoint handling changes, the
682 * perf probe will fail to compile unless it too is updated.
683 */
ff038f5c 684#undef DEFINE_EVENT
6cc8a7c1 685#define DEFINE_EVENT(template, call, proto, args) \
2239291a 686static inline void perf_test_probe_##call(void) \
6cc8a7c1 687{ \
2239291a 688 check_trace_callback_type_##call(perf_trace_##template); \
ff038f5c
SR
689}
690
2239291a 691
e5bc9721
SR
692#undef DEFINE_EVENT_PRINT
693#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
694 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
695
f413cdb8 696#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
07b139c8 697#endif /* CONFIG_PERF_EVENTS */
f413cdb8 698
ac199db0
PZ
699#undef _TRACE_PROFILE_INIT
700