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