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