Commit | Line | Data |
---|---|---|
f42c85e7 SR |
1 | /* |
2 | * Stage 1 of the trace events. | |
3 | * | |
4 | * Override the macros in <trace/trace_events.h> to include the following: | |
5 | * | |
6 | * struct ftrace_raw_<call> { | |
7 | * struct trace_entry ent; | |
8 | * <type> <item>; | |
9 | * <type2> <item2>[<len>]; | |
10 | * [...] | |
11 | * }; | |
12 | * | |
13 | * The <type> <item> is created by the __field(type, item) macro or | |
14 | * the __array(type2, item2, len) macro. | |
15 | * We simply do "type item;", and that will create the fields | |
16 | * in the structure. | |
17 | */ | |
18 | ||
19 | #include <linux/ftrace_event.h> | |
20 | ||
ff038f5c | 21 | /* |
091ad365 | 22 | * DECLARE_EVENT_CLASS can be used to add a generic function |
ff038f5c SR |
23 | * handlers for events. That is, if all events have the same |
24 | * parameters and just have distinct trace points. | |
25 | * Each tracepoint can be defined with DEFINE_EVENT and that | |
091ad365 | 26 | * will map the DECLARE_EVENT_CLASS to the tracepoint. |
ff038f5c SR |
27 | * |
28 | * TRACE_EVENT is a one to one mapping between tracepoint and template. | |
29 | */ | |
30 | #undef TRACE_EVENT | |
31 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
091ad365 | 32 | DECLARE_EVENT_CLASS(name, \ |
ff038f5c SR |
33 | PARAMS(proto), \ |
34 | PARAMS(args), \ | |
35 | PARAMS(tstruct), \ | |
36 | PARAMS(assign), \ | |
37 | PARAMS(print)); \ | |
38 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); | |
39 | ||
40 | ||
7fcb7c47 LZ |
41 | #undef __field |
42 | #define __field(type, item) type item; | |
43 | ||
43b51ead LZ |
44 | #undef __field_ext |
45 | #define __field_ext(type, item, filter_type) type item; | |
46 | ||
f42c85e7 SR |
47 | #undef __array |
48 | #define __array(type, item, len) type item[len]; | |
49 | ||
7fcb7c47 | 50 | #undef __dynamic_array |
7d536cb3 | 51 | #define __dynamic_array(type, item, len) u32 __data_loc_##item; |
f42c85e7 | 52 | |
9cbf1176 | 53 | #undef __string |
7fcb7c47 | 54 | #define __string(item, src) __dynamic_array(char, item, -1) |
9cbf1176 | 55 | |
f42c85e7 SR |
56 | #undef TP_STRUCT__entry |
57 | #define TP_STRUCT__entry(args...) args | |
58 | ||
091ad365 IM |
59 | #undef DECLARE_EVENT_CLASS |
60 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ | |
ff038f5c SR |
61 | struct ftrace_raw_##name { \ |
62 | struct trace_entry ent; \ | |
63 | tstruct \ | |
64 | char __data[0]; \ | |
8f082018 SR |
65 | }; \ |
66 | \ | |
67 | static struct ftrace_event_class event_class_##name; | |
68 | ||
ff038f5c SR |
69 | #undef DEFINE_EVENT |
70 | #define DEFINE_EVENT(template, name, proto, args) \ | |
49c17746 | 71 | static struct ftrace_event_call __used \ |
86c38a31 | 72 | __attribute__((__aligned__(4))) event_##name |
f42c85e7 | 73 | |
e5bc9721 SR |
74 | #undef DEFINE_EVENT_PRINT |
75 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
76 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
77 | ||
97419875 JS |
78 | /* Callbacks are meaningless to ftrace. */ |
79 | #undef TRACE_EVENT_FN | |
0dd7b747 FW |
80 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ |
81 | assign, print, reg, unreg) \ | |
819ce45a FW |
82 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ |
83 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ | |
97419875 | 84 | |
1ed0c597 FW |
85 | #undef TRACE_EVENT_FLAGS |
86 | #define TRACE_EVENT_FLAGS(name, value) \ | |
53cf810b | 87 | __TRACE_EVENT_FLAGS(name, value) |
1ed0c597 | 88 | |
f42c85e7 SR |
89 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
90 | ||
9cbf1176 | 91 | |
f42c85e7 SR |
92 | /* |
93 | * Stage 2 of the trace events. | |
94 | * | |
9cbf1176 FW |
95 | * Include the following: |
96 | * | |
7fcb7c47 | 97 | * struct ftrace_data_offsets_<call> { |
7d536cb3 LZ |
98 | * u32 <item1>; |
99 | * u32 <item2>; | |
9cbf1176 FW |
100 | * [...] |
101 | * }; | |
102 | * | |
7d536cb3 | 103 | * The __dynamic_array() macro will create each u32 <item>, this is |
7fcb7c47 | 104 | * to keep the offset of each array from the beginning of the event. |
7d536cb3 | 105 | * The size of an array is also encoded, in the higher 16 bits of <item>. |
9cbf1176 FW |
106 | */ |
107 | ||
7fcb7c47 | 108 | #undef __field |
43b51ead LZ |
109 | #define __field(type, item) |
110 | ||
111 | #undef __field_ext | |
112 | #define __field_ext(type, item, filter_type) | |
7fcb7c47 | 113 | |
9cbf1176 FW |
114 | #undef __array |
115 | #define __array(type, item, len) | |
116 | ||
7fcb7c47 | 117 | #undef __dynamic_array |
7d536cb3 | 118 | #define __dynamic_array(type, item, len) u32 item; |
9cbf1176 FW |
119 | |
120 | #undef __string | |
7fcb7c47 | 121 | #define __string(item, src) __dynamic_array(char, item, -1) |
9cbf1176 | 122 | |
091ad365 IM |
123 | #undef DECLARE_EVENT_CLASS |
124 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
7fcb7c47 | 125 | struct ftrace_data_offsets_##call { \ |
9cbf1176 FW |
126 | tstruct; \ |
127 | }; | |
128 | ||
ff038f5c SR |
129 | #undef DEFINE_EVENT |
130 | #define DEFINE_EVENT(template, name, proto, args) | |
131 | ||
e5bc9721 SR |
132 | #undef DEFINE_EVENT_PRINT |
133 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
134 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
135 | ||
1ed0c597 FW |
136 | #undef TRACE_EVENT_FLAGS |
137 | #define TRACE_EVENT_FLAGS(event, flag) | |
138 | ||
9cbf1176 FW |
139 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
140 | ||
141 | /* | |
142 | * Stage 3 of the trace events. | |
143 | * | |
f42c85e7 SR |
144 | * Override the macros in <trace/trace_events.h> to include the following: |
145 | * | |
146 | * enum print_line_t | |
147 | * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags) | |
148 | * { | |
149 | * struct trace_seq *s = &iter->seq; | |
150 | * struct ftrace_raw_<call> *field; <-- defined in stage 1 | |
151 | * struct trace_entry *entry; | |
bc289ae9 | 152 | * struct trace_seq *p = &iter->tmp_seq; |
f42c85e7 SR |
153 | * int ret; |
154 | * | |
155 | * entry = iter->ent; | |
156 | * | |
32c0edae | 157 | * if (entry->type != event_<call>->event.type) { |
f42c85e7 SR |
158 | * WARN_ON_ONCE(1); |
159 | * return TRACE_TYPE_UNHANDLED; | |
160 | * } | |
161 | * | |
162 | * field = (typeof(field))entry; | |
163 | * | |
56d8bd3f | 164 | * trace_seq_init(p); |
50354a8a LZ |
165 | * ret = trace_seq_printf(s, "%s: ", <call>); |
166 | * if (ret) | |
167 | * ret = trace_seq_printf(s, <TP_printk> "\n"); | |
f42c85e7 SR |
168 | * if (!ret) |
169 | * return TRACE_TYPE_PARTIAL_LINE; | |
170 | * | |
171 | * return TRACE_TYPE_HANDLED; | |
172 | * } | |
173 | * | |
174 | * This is the method used to print the raw event to the trace | |
175 | * output format. Note, this is not needed if the data is read | |
176 | * in binary. | |
177 | */ | |
178 | ||
179 | #undef __entry | |
180 | #define __entry field | |
181 | ||
182 | #undef TP_printk | |
183 | #define TP_printk(fmt, args...) fmt "\n", args | |
184 | ||
7fcb7c47 LZ |
185 | #undef __get_dynamic_array |
186 | #define __get_dynamic_array(field) \ | |
7d536cb3 | 187 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) |
7fcb7c47 | 188 | |
9cbf1176 | 189 | #undef __get_str |
7fcb7c47 | 190 | #define __get_str(field) (char *)__get_dynamic_array(field) |
9cbf1176 | 191 | |
be74b73a SR |
192 | #undef __print_flags |
193 | #define __print_flags(flag, delim, flag_array...) \ | |
194 | ({ \ | |
a48f494e | 195 | static const struct trace_print_flags __flags[] = \ |
be74b73a | 196 | { flag_array, { -1, NULL }}; \ |
a48f494e | 197 | ftrace_print_flags_seq(p, delim, flag, __flags); \ |
be74b73a SR |
198 | }) |
199 | ||
0f4fc29d SR |
200 | #undef __print_symbolic |
201 | #define __print_symbolic(value, symbol_array...) \ | |
202 | ({ \ | |
203 | static const struct trace_print_flags symbols[] = \ | |
204 | { symbol_array, { -1, NULL }}; \ | |
205 | ftrace_print_symbols_seq(p, value, symbols); \ | |
206 | }) | |
207 | ||
2fc1b6f0 | 208 | #undef __print_symbolic_u64 |
209 | #if BITS_PER_LONG == 32 | |
210 | #define __print_symbolic_u64(value, symbol_array...) \ | |
211 | ({ \ | |
212 | static const struct trace_print_flags_u64 symbols[] = \ | |
213 | { symbol_array, { -1, NULL } }; \ | |
214 | ftrace_print_symbols_seq_u64(p, value, symbols); \ | |
215 | }) | |
216 | #else | |
217 | #define __print_symbolic_u64(value, symbol_array...) \ | |
218 | __print_symbolic(value, symbol_array) | |
219 | #endif | |
220 | ||
5a2e3995 KT |
221 | #undef __print_hex |
222 | #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len) | |
223 | ||
091ad365 IM |
224 | #undef DECLARE_EVENT_CLASS |
225 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
83f0d539 | 226 | static notrace enum print_line_t \ |
80decc70 SR |
227 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
228 | struct trace_event *trace_event) \ | |
f42c85e7 | 229 | { \ |
80decc70 | 230 | struct ftrace_event_call *event; \ |
f42c85e7 SR |
231 | struct trace_seq *s = &iter->seq; \ |
232 | struct ftrace_raw_##call *field; \ | |
233 | struct trace_entry *entry; \ | |
bc289ae9 | 234 | struct trace_seq *p = &iter->tmp_seq; \ |
f42c85e7 SR |
235 | int ret; \ |
236 | \ | |
80decc70 SR |
237 | event = container_of(trace_event, struct ftrace_event_call, \ |
238 | event); \ | |
239 | \ | |
f42c85e7 SR |
240 | entry = iter->ent; \ |
241 | \ | |
32c0edae | 242 | if (entry->type != event->event.type) { \ |
f42c85e7 SR |
243 | WARN_ON_ONCE(1); \ |
244 | return TRACE_TYPE_UNHANDLED; \ | |
245 | } \ | |
246 | \ | |
247 | field = (typeof(field))entry; \ | |
248 | \ | |
56d8bd3f | 249 | trace_seq_init(p); \ |
80decc70 | 250 | ret = trace_seq_printf(s, "%s: ", event->name); \ |
ff038f5c SR |
251 | if (ret) \ |
252 | ret = trace_seq_printf(s, print); \ | |
f42c85e7 SR |
253 | if (!ret) \ |
254 | return TRACE_TYPE_PARTIAL_LINE; \ | |
255 | \ | |
256 | return TRACE_TYPE_HANDLED; \ | |
80decc70 SR |
257 | } \ |
258 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
259 | .trace = ftrace_raw_output_##call, \ | |
260 | }; | |
ff038f5c | 261 | |
e5bc9721 SR |
262 | #undef DEFINE_EVENT_PRINT |
263 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | |
83f0d539 | 264 | static notrace enum print_line_t \ |
a9a57763 SR |
265 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
266 | struct trace_event *event) \ | |
e5bc9721 SR |
267 | { \ |
268 | struct trace_seq *s = &iter->seq; \ | |
269 | struct ftrace_raw_##template *field; \ | |
270 | struct trace_entry *entry; \ | |
bc289ae9 | 271 | struct trace_seq *p = &iter->tmp_seq; \ |
f42c85e7 SR |
272 | int ret; \ |
273 | \ | |
274 | entry = iter->ent; \ | |
275 | \ | |
32c0edae | 276 | if (entry->type != event_##call.event.type) { \ |
f42c85e7 SR |
277 | WARN_ON_ONCE(1); \ |
278 | return TRACE_TYPE_UNHANDLED; \ | |
279 | } \ | |
280 | \ | |
281 | field = (typeof(field))entry; \ | |
282 | \ | |
56d8bd3f | 283 | trace_seq_init(p); \ |
e5bc9721 SR |
284 | ret = trace_seq_printf(s, "%s: ", #call); \ |
285 | if (ret) \ | |
286 | ret = trace_seq_printf(s, print); \ | |
f42c85e7 SR |
287 | if (!ret) \ |
288 | return TRACE_TYPE_PARTIAL_LINE; \ | |
289 | \ | |
290 | return TRACE_TYPE_HANDLED; \ | |
80decc70 SR |
291 | } \ |
292 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
293 | .trace = ftrace_raw_output_##call, \ | |
294 | }; | |
e5bc9721 | 295 | |
f42c85e7 SR |
296 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
297 | ||
43b51ead LZ |
298 | #undef __field_ext |
299 | #define __field_ext(type, item, filter_type) \ | |
f42c85e7 SR |
300 | ret = trace_define_field(event_call, #type, #item, \ |
301 | offsetof(typeof(field), item), \ | |
43b51ead LZ |
302 | sizeof(field.item), \ |
303 | is_signed_type(type), filter_type); \ | |
f42c85e7 SR |
304 | if (ret) \ |
305 | return ret; | |
306 | ||
43b51ead LZ |
307 | #undef __field |
308 | #define __field(type, item) __field_ext(type, item, FILTER_OTHER) | |
309 | ||
f42c85e7 SR |
310 | #undef __array |
311 | #define __array(type, item, len) \ | |
04295780 SR |
312 | do { \ |
313 | mutex_lock(&event_storage_mutex); \ | |
314 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ | |
315 | snprintf(event_storage, sizeof(event_storage), \ | |
316 | "%s[%d]", #type, len); \ | |
317 | ret = trace_define_field(event_call, event_storage, #item, \ | |
f42c85e7 | 318 | offsetof(typeof(field), item), \ |
fb7ae981 LJ |
319 | sizeof(field.item), \ |
320 | is_signed_type(type), FILTER_OTHER); \ | |
04295780 SR |
321 | mutex_unlock(&event_storage_mutex); \ |
322 | if (ret) \ | |
323 | return ret; \ | |
324 | } while (0); | |
f42c85e7 | 325 | |
7fcb7c47 LZ |
326 | #undef __dynamic_array |
327 | #define __dynamic_array(type, item, len) \ | |
68fd60a8 | 328 | ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \ |
43b51ead | 329 | offsetof(typeof(field), __data_loc_##item), \ |
fb7ae981 LJ |
330 | sizeof(field.__data_loc_##item), \ |
331 | is_signed_type(type), FILTER_OTHER); | |
7fcb7c47 | 332 | |
9cbf1176 | 333 | #undef __string |
7fcb7c47 | 334 | #define __string(item, src) __dynamic_array(char, item, -1) |
9cbf1176 | 335 | |
091ad365 IM |
336 | #undef DECLARE_EVENT_CLASS |
337 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ | |
83f0d539 | 338 | static int notrace \ |
14be96c9 | 339 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ |
f42c85e7 SR |
340 | { \ |
341 | struct ftrace_raw_##call field; \ | |
f42c85e7 SR |
342 | int ret; \ |
343 | \ | |
f42c85e7 SR |
344 | tstruct; \ |
345 | \ | |
346 | return ret; \ | |
347 | } | |
348 | ||
ff038f5c SR |
349 | #undef DEFINE_EVENT |
350 | #define DEFINE_EVENT(template, name, proto, args) | |
351 | ||
e5bc9721 SR |
352 | #undef DEFINE_EVENT_PRINT |
353 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
354 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
355 | ||
f42c85e7 SR |
356 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
357 | ||
7fcb7c47 LZ |
358 | /* |
359 | * remember the offset of each array from the beginning of the event. | |
360 | */ | |
361 | ||
362 | #undef __entry | |
363 | #define __entry entry | |
364 | ||
365 | #undef __field | |
366 | #define __field(type, item) | |
367 | ||
43b51ead LZ |
368 | #undef __field_ext |
369 | #define __field_ext(type, item, filter_type) | |
370 | ||
7fcb7c47 LZ |
371 | #undef __array |
372 | #define __array(type, item, len) | |
373 | ||
374 | #undef __dynamic_array | |
375 | #define __dynamic_array(type, item, len) \ | |
376 | __data_offsets->item = __data_size + \ | |
377 | offsetof(typeof(*entry), __data); \ | |
7d536cb3 | 378 | __data_offsets->item |= (len * sizeof(type)) << 16; \ |
7fcb7c47 LZ |
379 | __data_size += (len) * sizeof(type); |
380 | ||
381 | #undef __string | |
ff038f5c | 382 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) |
7fcb7c47 | 383 | |
091ad365 IM |
384 | #undef DECLARE_EVENT_CLASS |
385 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
83f0d539 | 386 | static inline notrace int ftrace_get_offsets_##call( \ |
7fcb7c47 LZ |
387 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ |
388 | { \ | |
389 | int __data_size = 0; \ | |
390 | struct ftrace_raw_##call __maybe_unused *entry; \ | |
391 | \ | |
392 | tstruct; \ | |
393 | \ | |
394 | return __data_size; \ | |
395 | } | |
396 | ||
ff038f5c SR |
397 | #undef DEFINE_EVENT |
398 | #define DEFINE_EVENT(template, name, proto, args) | |
399 | ||
e5bc9721 SR |
400 | #undef DEFINE_EVENT_PRINT |
401 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
402 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
403 | ||
7fcb7c47 LZ |
404 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
405 | ||
c32e827b | 406 | /* |
9cbf1176 | 407 | * Stage 4 of the trace events. |
c32e827b | 408 | * |
ea20d929 | 409 | * Override the macros in <trace/trace_events.h> to include the following: |
c32e827b | 410 | * |
157587d7 | 411 | * For those macros defined with TRACE_EVENT: |
c32e827b SR |
412 | * |
413 | * static struct ftrace_event_call event_<call>; | |
414 | * | |
2239291a | 415 | * static void ftrace_raw_event_<call>(void *__data, proto) |
c32e827b | 416 | * { |
2239291a | 417 | * struct ftrace_event_call *event_call = __data; |
50354a8a | 418 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; |
ef18012b SR |
419 | * struct ring_buffer_event *event; |
420 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | |
e77405ad | 421 | * struct ring_buffer *buffer; |
ef18012b | 422 | * unsigned long irq_flags; |
50354a8a | 423 | * int __data_size; |
ef18012b SR |
424 | * int pc; |
425 | * | |
426 | * local_save_flags(irq_flags); | |
427 | * pc = preempt_count(); | |
428 | * | |
50354a8a LZ |
429 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); |
430 | * | |
e77405ad | 431 | * event = trace_current_buffer_lock_reserve(&buffer, |
32c0edae | 432 | * event_<call>->event.type, |
50354a8a | 433 | * sizeof(*entry) + __data_size, |
ef18012b SR |
434 | * irq_flags, pc); |
435 | * if (!event) | |
436 | * return; | |
437 | * entry = ring_buffer_event_data(event); | |
438 | * | |
50354a8a LZ |
439 | * { <assign>; } <-- Here we assign the entries by the __field and |
440 | * __array macros. | |
c32e827b | 441 | * |
50354a8a LZ |
442 | * if (!filter_current_check_discard(buffer, event_call, entry, event)) |
443 | * trace_current_buffer_unlock_commit(buffer, | |
444 | * event, irq_flags, pc); | |
c32e827b SR |
445 | * } |
446 | * | |
c32e827b | 447 | * static struct trace_event ftrace_event_type_<call> = { |
ef18012b | 448 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
c32e827b SR |
449 | * }; |
450 | * | |
50354a8a LZ |
451 | * static const char print_fmt_<call>[] = <TP_printk>; |
452 | * | |
8f082018 SR |
453 | * static struct ftrace_event_class __used event_class_<template> = { |
454 | * .system = "<system>", | |
2e33af02 | 455 | * .define_fields = ftrace_define_fields_<call>, |
0405ab80 SR |
456 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), |
457 | * .raw_init = trace_event_raw_init, | |
458 | * .probe = ftrace_raw_event_##call, | |
a1d0ce82 | 459 | * .reg = ftrace_event_reg, |
8f082018 SR |
460 | * }; |
461 | * | |
e4a9ea5e | 462 | * static struct ftrace_event_call event_<call> = { |
ef18012b | 463 | * .name = "<call>", |
8f082018 | 464 | * .class = event_class_<template>, |
2e33af02 | 465 | * .event = &ftrace_event_type_<call>, |
50354a8a | 466 | * .print_fmt = print_fmt_<call>, |
8f082018 | 467 | * }; |
e4a9ea5e SR |
468 | * // its only safe to use pointers when doing linker tricks to |
469 | * // create an array. | |
470 | * static struct ftrace_event_call __used | |
471 | * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>; | |
c32e827b SR |
472 | * |
473 | */ | |
474 | ||
07b139c8 | 475 | #ifdef CONFIG_PERF_EVENTS |
ac199db0 | 476 | |
2239291a SR |
477 | #define _TRACE_PERF_PROTO(call, proto) \ |
478 | static notrace void \ | |
479 | perf_trace_##call(void *__data, proto); | |
480 | ||
97d5a220 | 481 | #define _TRACE_PERF_INIT(call) \ |
2239291a | 482 | .perf_probe = perf_trace_##call, |
ac199db0 PZ |
483 | |
484 | #else | |
2239291a | 485 | #define _TRACE_PERF_PROTO(call, proto) |
97d5a220 | 486 | #define _TRACE_PERF_INIT(call) |
07b139c8 | 487 | #endif /* CONFIG_PERF_EVENTS */ |
ac199db0 | 488 | |
da4d0302 SR |
489 | #undef __entry |
490 | #define __entry entry | |
d20e3b03 | 491 | |
9cbf1176 FW |
492 | #undef __field |
493 | #define __field(type, item) | |
494 | ||
495 | #undef __array | |
496 | #define __array(type, item, len) | |
497 | ||
7fcb7c47 LZ |
498 | #undef __dynamic_array |
499 | #define __dynamic_array(type, item, len) \ | |
500 | __entry->__data_loc_##item = __data_offsets.item; | |
501 | ||
9cbf1176 | 502 | #undef __string |
7fcb7c47 | 503 | #define __string(item, src) __dynamic_array(char, item, -1) \ |
9cbf1176 FW |
504 | |
505 | #undef __assign_str | |
506 | #define __assign_str(dst, src) \ | |
9cbf1176 FW |
507 | strcpy(__get_str(dst), src); |
508 | ||
0fa0edaf LJ |
509 | #undef TP_fast_assign |
510 | #define TP_fast_assign(args...) args | |
511 | ||
512 | #undef TP_perf_assign | |
513 | #define TP_perf_assign(args...) | |
514 | ||
091ad365 IM |
515 | #undef DECLARE_EVENT_CLASS |
516 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
c32e827b | 517 | \ |
83f0d539 | 518 | static notrace void \ |
2239291a | 519 | ftrace_raw_event_##call(void *__data, proto) \ |
c32e827b | 520 | { \ |
2239291a | 521 | struct ftrace_event_call *event_call = __data; \ |
7fcb7c47 | 522 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
c32e827b SR |
523 | struct ring_buffer_event *event; \ |
524 | struct ftrace_raw_##call *entry; \ | |
e77405ad | 525 | struct ring_buffer *buffer; \ |
c32e827b | 526 | unsigned long irq_flags; \ |
7fcb7c47 | 527 | int __data_size; \ |
c32e827b SR |
528 | int pc; \ |
529 | \ | |
530 | local_save_flags(irq_flags); \ | |
531 | pc = preempt_count(); \ | |
532 | \ | |
7fcb7c47 | 533 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
9cbf1176 | 534 | \ |
e77405ad | 535 | event = trace_current_buffer_lock_reserve(&buffer, \ |
32c0edae | 536 | event_call->event.type, \ |
7fcb7c47 | 537 | sizeof(*entry) + __data_size, \ |
9cbf1176 | 538 | irq_flags, pc); \ |
c32e827b SR |
539 | if (!event) \ |
540 | return; \ | |
541 | entry = ring_buffer_event_data(event); \ | |
542 | \ | |
7fcb7c47 LZ |
543 | tstruct \ |
544 | \ | |
a9c1c3ab | 545 | { assign; } \ |
c32e827b | 546 | \ |
e77405ad | 547 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ |
0d5c6e1c | 548 | trace_buffer_unlock_commit(buffer, event, irq_flags, pc); \ |
ff038f5c | 549 | } |
2239291a SR |
550 | /* |
551 | * The ftrace_test_probe is compiled out, it is only here as a build time check | |
552 | * to make sure that if the tracepoint handling changes, the ftrace probe will | |
553 | * fail to compile unless it too is updated. | |
554 | */ | |
ff038f5c SR |
555 | |
556 | #undef DEFINE_EVENT | |
557 | #define DEFINE_EVENT(template, call, proto, args) \ | |
2239291a | 558 | static inline void ftrace_test_probe_##call(void) \ |
c32e827b | 559 | { \ |
2239291a SR |
560 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ |
561 | } | |
e5bc9721 SR |
562 | |
563 | #undef DEFINE_EVENT_PRINT | |
80decc70 | 564 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
e5bc9721 SR |
565 | |
566 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
567 | ||
509e760c LJ |
568 | #undef __entry |
569 | #define __entry REC | |
570 | ||
571 | #undef __print_flags | |
572 | #undef __print_symbolic | |
b102f1d0 | 573 | #undef __print_hex |
509e760c LJ |
574 | #undef __get_dynamic_array |
575 | #undef __get_str | |
576 | ||
577 | #undef TP_printk | |
578 | #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) | |
579 | ||
091ad365 | 580 | #undef DECLARE_EVENT_CLASS |
509e760c | 581 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
2239291a | 582 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ |
8f082018 SR |
583 | static const char print_fmt_##call[] = print; \ |
584 | static struct ftrace_event_class __used event_class_##call = { \ | |
2239291a | 585 | .system = __stringify(TRACE_SYSTEM), \ |
2e33af02 SR |
586 | .define_fields = ftrace_define_fields_##call, \ |
587 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ | |
0405ab80 | 588 | .raw_init = trace_event_raw_init, \ |
2239291a | 589 | .probe = ftrace_raw_event_##call, \ |
a1d0ce82 | 590 | .reg = ftrace_event_reg, \ |
2239291a | 591 | _TRACE_PERF_INIT(call) \ |
8f082018 | 592 | }; |
e5bc9721 SR |
593 | |
594 | #undef DEFINE_EVENT | |
595 | #define DEFINE_EVENT(template, call, proto, args) \ | |
c32e827b | 596 | \ |
e4a9ea5e | 597 | static struct ftrace_event_call __used event_##call = { \ |
ef18012b | 598 | .name = #call, \ |
8f082018 | 599 | .class = &event_class_##template, \ |
80decc70 | 600 | .event.funcs = &ftrace_event_type_funcs_##template, \ |
509e760c | 601 | .print_fmt = print_fmt_##template, \ |
e4a9ea5e SR |
602 | }; \ |
603 | static struct ftrace_event_call __used \ | |
604 | __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call | |
ac199db0 | 605 | |
e5bc9721 SR |
606 | #undef DEFINE_EVENT_PRINT |
607 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | |
c32e827b | 608 | \ |
509e760c LJ |
609 | static const char print_fmt_##call[] = print; \ |
610 | \ | |
e4a9ea5e | 611 | static struct ftrace_event_call __used event_##call = { \ |
ef18012b | 612 | .name = #call, \ |
8f082018 | 613 | .class = &event_class_##template, \ |
80decc70 | 614 | .event.funcs = &ftrace_event_type_funcs_##call, \ |
509e760c | 615 | .print_fmt = print_fmt_##call, \ |
e4a9ea5e SR |
616 | }; \ |
617 | static struct ftrace_event_call __used \ | |
618 | __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call | |
ac199db0 | 619 | |
f42c85e7 | 620 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
ac199db0 | 621 | |
f413cdb8 | 622 | |
07b139c8 | 623 | #ifdef CONFIG_PERF_EVENTS |
f413cdb8 | 624 | |
509e760c LJ |
625 | #undef __entry |
626 | #define __entry entry | |
627 | ||
628 | #undef __get_dynamic_array | |
629 | #define __get_dynamic_array(field) \ | |
630 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) | |
631 | ||
632 | #undef __get_str | |
633 | #define __get_str(field) (char *)__get_dynamic_array(field) | |
634 | ||
f413cdb8 FW |
635 | #undef __perf_addr |
636 | #define __perf_addr(a) __addr = (a) | |
637 | ||
638 | #undef __perf_count | |
639 | #define __perf_count(c) __count = (c) | |
640 | ||
e6dab5ff AV |
641 | #undef __perf_task |
642 | #define __perf_task(t) __task = (t) | |
643 | ||
92e51938 AV |
644 | #undef TP_perf_assign |
645 | #define TP_perf_assign(args...) args | |
646 | ||
091ad365 IM |
647 | #undef DECLARE_EVENT_CLASS |
648 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
83f0d539 | 649 | static notrace void \ |
2239291a | 650 | perf_trace_##call(void *__data, proto) \ |
f413cdb8 | 651 | { \ |
2239291a | 652 | struct ftrace_event_call *event_call = __data; \ |
f413cdb8 | 653 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
f413cdb8 | 654 | struct ftrace_raw_##call *entry; \ |
ff5f149b | 655 | struct pt_regs __regs; \ |
f413cdb8 | 656 | u64 __addr = 0, __count = 1; \ |
e6dab5ff | 657 | struct task_struct *__task = NULL; \ |
1c024eca | 658 | struct hlist_head *head; \ |
f413cdb8 FW |
659 | int __entry_size; \ |
660 | int __data_size; \ | |
4ed7c92d | 661 | int rctx; \ |
f413cdb8 | 662 | \ |
b0f82b81 | 663 | perf_fetch_caller_regs(&__regs); \ |
f0218b3e | 664 | \ |
f413cdb8 | 665 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
a044560c PZ |
666 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
667 | sizeof(u64)); \ | |
304703ab | 668 | __entry_size -= sizeof(u32); \ |
f413cdb8 | 669 | \ |
97d5a220 | 670 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ |
20ab4425 FW |
671 | "profile buffer not large enough")) \ |
672 | return; \ | |
b7e2ecef | 673 | \ |
97d5a220 | 674 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ |
ff5f149b | 675 | __entry_size, event_call->event.type, &__regs, &rctx); \ |
430ad5a6 XG |
676 | if (!entry) \ |
677 | return; \ | |
b7e2ecef | 678 | \ |
20ab4425 FW |
679 | tstruct \ |
680 | \ | |
681 | { assign; } \ | |
682 | \ | |
3771f077 | 683 | head = this_cpu_ptr(event_call->perf_events); \ |
97d5a220 | 684 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
e6dab5ff | 685 | __count, &__regs, head, __task); \ |
f413cdb8 FW |
686 | } |
687 | ||
2239291a SR |
688 | /* |
689 | * This part is compiled out, it is only here as a build time check | |
690 | * to make sure that if the tracepoint handling changes, the | |
691 | * perf probe will fail to compile unless it too is updated. | |
692 | */ | |
ff038f5c | 693 | #undef DEFINE_EVENT |
6cc8a7c1 | 694 | #define DEFINE_EVENT(template, call, proto, args) \ |
2239291a | 695 | static inline void perf_test_probe_##call(void) \ |
6cc8a7c1 | 696 | { \ |
2239291a | 697 | check_trace_callback_type_##call(perf_trace_##template); \ |
ff038f5c SR |
698 | } |
699 | ||
2239291a | 700 | |
e5bc9721 SR |
701 | #undef DEFINE_EVENT_PRINT |
702 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
703 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
704 | ||
f413cdb8 | 705 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
07b139c8 | 706 | #endif /* CONFIG_PERF_EVENTS */ |
f413cdb8 | 707 | |
ac199db0 PZ |
708 | #undef _TRACE_PROFILE_INIT |
709 |