]>
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 SR |
547 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ |
548 | trace_nowake_buffer_unlock_commit(buffer, \ | |
549 | event, irq_flags, pc); \ | |
ff038f5c | 550 | } |
2239291a SR |
551 | /* |
552 | * The ftrace_test_probe is compiled out, it is only here as a build time check | |
553 | * to make sure that if the tracepoint handling changes, the ftrace probe will | |
554 | * fail to compile unless it too is updated. | |
555 | */ | |
ff038f5c SR |
556 | |
557 | #undef DEFINE_EVENT | |
558 | #define DEFINE_EVENT(template, call, proto, args) \ | |
2239291a | 559 | static inline void ftrace_test_probe_##call(void) \ |
c32e827b | 560 | { \ |
2239291a SR |
561 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ |
562 | } | |
e5bc9721 SR |
563 | |
564 | #undef DEFINE_EVENT_PRINT | |
80decc70 | 565 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
e5bc9721 SR |
566 | |
567 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
568 | ||
509e760c LJ |
569 | #undef __entry |
570 | #define __entry REC | |
571 | ||
572 | #undef __print_flags | |
573 | #undef __print_symbolic | |
b102f1d0 | 574 | #undef __print_hex |
509e760c LJ |
575 | #undef __get_dynamic_array |
576 | #undef __get_str | |
577 | ||
578 | #undef TP_printk | |
579 | #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) | |
580 | ||
091ad365 | 581 | #undef DECLARE_EVENT_CLASS |
509e760c | 582 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
2239291a | 583 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ |
8f082018 SR |
584 | static const char print_fmt_##call[] = print; \ |
585 | static struct ftrace_event_class __used event_class_##call = { \ | |
2239291a | 586 | .system = __stringify(TRACE_SYSTEM), \ |
2e33af02 SR |
587 | .define_fields = ftrace_define_fields_##call, \ |
588 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ | |
0405ab80 | 589 | .raw_init = trace_event_raw_init, \ |
2239291a | 590 | .probe = ftrace_raw_event_##call, \ |
a1d0ce82 | 591 | .reg = ftrace_event_reg, \ |
2239291a | 592 | _TRACE_PERF_INIT(call) \ |
8f082018 | 593 | }; |
e5bc9721 SR |
594 | |
595 | #undef DEFINE_EVENT | |
596 | #define DEFINE_EVENT(template, call, proto, args) \ | |
c32e827b | 597 | \ |
e4a9ea5e | 598 | static 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_##template, \ |
509e760c | 602 | .print_fmt = print_fmt_##template, \ |
e4a9ea5e SR |
603 | }; \ |
604 | static struct ftrace_event_call __used \ | |
605 | __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call | |
ac199db0 | 606 | |
e5bc9721 SR |
607 | #undef DEFINE_EVENT_PRINT |
608 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | |
c32e827b | 609 | \ |
509e760c LJ |
610 | static const char print_fmt_##call[] = print; \ |
611 | \ | |
e4a9ea5e | 612 | static struct ftrace_event_call __used event_##call = { \ |
ef18012b | 613 | .name = #call, \ |
8f082018 | 614 | .class = &event_class_##template, \ |
80decc70 | 615 | .event.funcs = &ftrace_event_type_funcs_##call, \ |
509e760c | 616 | .print_fmt = print_fmt_##call, \ |
e4a9ea5e SR |
617 | }; \ |
618 | static struct ftrace_event_call __used \ | |
619 | __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call | |
ac199db0 | 620 | |
f42c85e7 | 621 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
ac199db0 | 622 | |
f413cdb8 | 623 | /* |
97d5a220 | 624 | * Define the insertion callback to perf events |
f413cdb8 FW |
625 | * |
626 | * The job is very similar to ftrace_raw_event_<call> except that we don't | |
627 | * insert in the ring buffer but in a perf counter. | |
628 | * | |
97d5a220 | 629 | * static void ftrace_perf_<call>(proto) |
f413cdb8 FW |
630 | * { |
631 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | |
632 | * struct ftrace_event_call *event_call = &event_<call>; | |
cdd6c482 | 633 | * extern void perf_tp_event(int, u64, u64, void *, int); |
f413cdb8 | 634 | * struct ftrace_raw_##call *entry; |
444a2a3b | 635 | * struct perf_trace_buf *trace_buf; |
f413cdb8 FW |
636 | * u64 __addr = 0, __count = 1; |
637 | * unsigned long irq_flags; | |
20ab4425 | 638 | * struct trace_entry *ent; |
f413cdb8 FW |
639 | * int __entry_size; |
640 | * int __data_size; | |
20ab4425 | 641 | * int __cpu |
f413cdb8 FW |
642 | * int pc; |
643 | * | |
f413cdb8 FW |
644 | * pc = preempt_count(); |
645 | * | |
646 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | |
304703ab FW |
647 | * |
648 | * // Below we want to get the aligned size by taking into account | |
649 | * // the u32 field that will later store the buffer size | |
650 | * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32), | |
651 | * sizeof(u64)); | |
652 | * __entry_size -= sizeof(u32); | |
f413cdb8 | 653 | * |
20ab4425 FW |
654 | * // Protect the non nmi buffer |
655 | * // This also protects the rcu read side | |
656 | * local_irq_save(irq_flags); | |
657 | * __cpu = smp_processor_id(); | |
658 | * | |
659 | * if (in_nmi()) | |
8d53dd54 | 660 | * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi); |
20ab4425 | 661 | * else |
8d53dd54 | 662 | * trace_buf = rcu_dereference_sched(perf_trace_buf); |
20ab4425 | 663 | * |
444a2a3b | 664 | * if (!trace_buf) |
20ab4425 | 665 | * goto end; |
f413cdb8 | 666 | * |
444a2a3b FW |
667 | * trace_buf = per_cpu_ptr(trace_buf, __cpu); |
668 | * | |
669 | * // Avoid recursion from perf that could mess up the buffer | |
670 | * if (trace_buf->recursion++) | |
671 | * goto end_recursion; | |
672 | * | |
673 | * raw_data = trace_buf->buf; | |
674 | * | |
675 | * // Make recursion update visible before entering perf_tp_event | |
676 | * // so that we protect from perf recursions. | |
677 | * | |
678 | * barrier(); | |
1853db0e | 679 | * |
20ab4425 FW |
680 | * //zero dead bytes from alignment to avoid stack leak to userspace: |
681 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; | |
682 | * entry = (struct ftrace_raw_<call> *)raw_data; | |
683 | * ent = &entry->ent; | |
684 | * tracing_generic_entry_update(ent, irq_flags, pc); | |
685 | * ent->type = event_call->id; | |
f413cdb8 | 686 | * |
20ab4425 | 687 | * <tstruct> <- do some jobs with dynamic arrays |
f413cdb8 | 688 | * |
20ab4425 | 689 | * <assign> <- affect our values |
f413cdb8 | 690 | * |
43c1266c | 691 | * perf_tp_event(event_call->id, __addr, __count, entry, |
20ab4425 | 692 | * __entry_size); <- submit them to perf counter |
f413cdb8 FW |
693 | * |
694 | * } | |
695 | */ | |
696 | ||
07b139c8 | 697 | #ifdef CONFIG_PERF_EVENTS |
f413cdb8 | 698 | |
509e760c LJ |
699 | #undef __entry |
700 | #define __entry entry | |
701 | ||
702 | #undef __get_dynamic_array | |
703 | #define __get_dynamic_array(field) \ | |
704 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) | |
705 | ||
706 | #undef __get_str | |
707 | #define __get_str(field) (char *)__get_dynamic_array(field) | |
708 | ||
f413cdb8 FW |
709 | #undef __perf_addr |
710 | #define __perf_addr(a) __addr = (a) | |
711 | ||
712 | #undef __perf_count | |
713 | #define __perf_count(c) __count = (c) | |
714 | ||
92e51938 AV |
715 | #undef TP_perf_assign |
716 | #define TP_perf_assign(args...) args | |
717 | ||
091ad365 IM |
718 | #undef DECLARE_EVENT_CLASS |
719 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
83f0d539 | 720 | static notrace void \ |
2239291a | 721 | perf_trace_##call(void *__data, proto) \ |
f413cdb8 | 722 | { \ |
2239291a | 723 | struct ftrace_event_call *event_call = __data; \ |
f413cdb8 | 724 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
f413cdb8 | 725 | struct ftrace_raw_##call *entry; \ |
ff5f149b | 726 | struct pt_regs __regs; \ |
f413cdb8 | 727 | u64 __addr = 0, __count = 1; \ |
1c024eca | 728 | struct hlist_head *head; \ |
f413cdb8 FW |
729 | int __entry_size; \ |
730 | int __data_size; \ | |
4ed7c92d | 731 | int rctx; \ |
f413cdb8 | 732 | \ |
b0f82b81 | 733 | perf_fetch_caller_regs(&__regs); \ |
f0218b3e | 734 | \ |
f413cdb8 | 735 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
a044560c PZ |
736 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
737 | sizeof(u64)); \ | |
304703ab | 738 | __entry_size -= sizeof(u32); \ |
f413cdb8 | 739 | \ |
97d5a220 | 740 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ |
20ab4425 FW |
741 | "profile buffer not large enough")) \ |
742 | return; \ | |
b7e2ecef | 743 | \ |
97d5a220 | 744 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ |
ff5f149b | 745 | __entry_size, event_call->event.type, &__regs, &rctx); \ |
430ad5a6 XG |
746 | if (!entry) \ |
747 | return; \ | |
b7e2ecef | 748 | \ |
20ab4425 FW |
749 | tstruct \ |
750 | \ | |
751 | { assign; } \ | |
752 | \ | |
3771f077 | 753 | head = this_cpu_ptr(event_call->perf_events); \ |
97d5a220 | 754 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
ff5f149b | 755 | __count, &__regs, head); \ |
f413cdb8 FW |
756 | } |
757 | ||
2239291a SR |
758 | /* |
759 | * This part is compiled out, it is only here as a build time check | |
760 | * to make sure that if the tracepoint handling changes, the | |
761 | * perf probe will fail to compile unless it too is updated. | |
762 | */ | |
ff038f5c | 763 | #undef DEFINE_EVENT |
6cc8a7c1 | 764 | #define DEFINE_EVENT(template, call, proto, args) \ |
2239291a | 765 | static inline void perf_test_probe_##call(void) \ |
6cc8a7c1 | 766 | { \ |
2239291a | 767 | check_trace_callback_type_##call(perf_trace_##template); \ |
ff038f5c SR |
768 | } |
769 | ||
2239291a | 770 | |
e5bc9721 SR |
771 | #undef DEFINE_EVENT_PRINT |
772 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
773 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
774 | ||
f413cdb8 | 775 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
07b139c8 | 776 | #endif /* CONFIG_PERF_EVENTS */ |
f413cdb8 | 777 | |
ac199db0 PZ |
778 | #undef _TRACE_PROFILE_INIT |
779 |