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