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