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