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 | ||
7fcb7c47 LZ |
21 | #undef __field |
22 | #define __field(type, item) type item; | |
23 | ||
f42c85e7 SR |
24 | #undef __array |
25 | #define __array(type, item, len) type item[len]; | |
26 | ||
7fcb7c47 | 27 | #undef __dynamic_array |
7d536cb3 | 28 | #define __dynamic_array(type, item, len) u32 __data_loc_##item; |
f42c85e7 | 29 | |
9cbf1176 | 30 | #undef __string |
7fcb7c47 | 31 | #define __string(item, src) __dynamic_array(char, item, -1) |
9cbf1176 | 32 | |
f42c85e7 SR |
33 | #undef TP_STRUCT__entry |
34 | #define TP_STRUCT__entry(args...) args | |
35 | ||
36 | #undef TRACE_EVENT | |
37 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
38 | struct ftrace_raw_##name { \ | |
39 | struct trace_entry ent; \ | |
40 | tstruct \ | |
7fcb7c47 | 41 | char __data[0]; \ |
f42c85e7 SR |
42 | }; \ |
43 | static struct ftrace_event_call event_##name | |
44 | ||
45 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
46 | ||
9cbf1176 | 47 | |
f42c85e7 SR |
48 | /* |
49 | * Stage 2 of the trace events. | |
50 | * | |
9cbf1176 FW |
51 | * Include the following: |
52 | * | |
7fcb7c47 | 53 | * struct ftrace_data_offsets_<call> { |
7d536cb3 LZ |
54 | * u32 <item1>; |
55 | * u32 <item2>; | |
9cbf1176 FW |
56 | * [...] |
57 | * }; | |
58 | * | |
7d536cb3 | 59 | * The __dynamic_array() macro will create each u32 <item>, this is |
7fcb7c47 | 60 | * to keep the offset of each array from the beginning of the event. |
7d536cb3 | 61 | * The size of an array is also encoded, in the higher 16 bits of <item>. |
9cbf1176 FW |
62 | */ |
63 | ||
7fcb7c47 LZ |
64 | #undef __field |
65 | #define __field(type, item); | |
66 | ||
9cbf1176 FW |
67 | #undef __array |
68 | #define __array(type, item, len) | |
69 | ||
7fcb7c47 | 70 | #undef __dynamic_array |
7d536cb3 | 71 | #define __dynamic_array(type, item, len) u32 item; |
9cbf1176 FW |
72 | |
73 | #undef __string | |
7fcb7c47 | 74 | #define __string(item, src) __dynamic_array(char, item, -1) |
9cbf1176 FW |
75 | |
76 | #undef TRACE_EVENT | |
77 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | |
7fcb7c47 | 78 | struct ftrace_data_offsets_##call { \ |
9cbf1176 FW |
79 | tstruct; \ |
80 | }; | |
81 | ||
82 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
83 | ||
6ff9a64d SR |
84 | /* |
85 | * Setup the showing format of trace point. | |
86 | * | |
87 | * int | |
88 | * ftrace_format_##call(struct trace_seq *s) | |
89 | * { | |
90 | * struct ftrace_raw_##call field; | |
91 | * int ret; | |
92 | * | |
93 | * ret = trace_seq_printf(s, #type " " #item ";" | |
94 | * " offset:%u; size:%u;\n", | |
95 | * offsetof(struct ftrace_raw_##call, item), | |
96 | * sizeof(field.type)); | |
97 | * | |
98 | * } | |
99 | */ | |
100 | ||
101 | #undef TP_STRUCT__entry | |
102 | #define TP_STRUCT__entry(args...) args | |
103 | ||
104 | #undef __field | |
105 | #define __field(type, item) \ | |
106 | ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \ | |
107 | "offset:%u;\tsize:%u;\n", \ | |
108 | (unsigned int)offsetof(typeof(field), item), \ | |
109 | (unsigned int)sizeof(field.item)); \ | |
110 | if (!ret) \ | |
111 | return 0; | |
112 | ||
113 | #undef __array | |
114 | #define __array(type, item, len) \ | |
115 | ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \ | |
116 | "offset:%u;\tsize:%u;\n", \ | |
117 | (unsigned int)offsetof(typeof(field), item), \ | |
118 | (unsigned int)sizeof(field.item)); \ | |
119 | if (!ret) \ | |
120 | return 0; | |
121 | ||
122 | #undef __dynamic_array | |
123 | #define __dynamic_array(type, item, len) \ | |
68fd60a8 | 124 | ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\ |
6ff9a64d SR |
125 | "offset:%u;\tsize:%u;\n", \ |
126 | (unsigned int)offsetof(typeof(field), \ | |
127 | __data_loc_##item), \ | |
128 | (unsigned int)sizeof(field.__data_loc_##item)); \ | |
129 | if (!ret) \ | |
130 | return 0; | |
131 | ||
132 | #undef __string | |
133 | #define __string(item, src) __dynamic_array(char, item, -1) | |
134 | ||
135 | #undef __entry | |
136 | #define __entry REC | |
137 | ||
138 | #undef __print_symbolic | |
139 | #undef __get_dynamic_array | |
140 | #undef __get_str | |
141 | ||
142 | #undef TP_printk | |
143 | #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args) | |
144 | ||
145 | #undef TP_fast_assign | |
146 | #define TP_fast_assign(args...) args | |
147 | ||
3a659305 PZ |
148 | #undef TP_perf_assign |
149 | #define TP_perf_assign(args...) | |
150 | ||
6ff9a64d SR |
151 | #undef TRACE_EVENT |
152 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ | |
153 | static int \ | |
e8f9f4d7 FW |
154 | ftrace_format_##call(struct ftrace_event_call *unused, \ |
155 | struct trace_seq *s) \ | |
6ff9a64d SR |
156 | { \ |
157 | struct ftrace_raw_##call field __attribute__((unused)); \ | |
158 | int ret = 0; \ | |
159 | \ | |
160 | tstruct; \ | |
161 | \ | |
162 | trace_seq_printf(s, "\nprint fmt: " print); \ | |
163 | \ | |
164 | return ret; \ | |
165 | } | |
166 | ||
167 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
168 | ||
9cbf1176 FW |
169 | /* |
170 | * Stage 3 of the trace events. | |
171 | * | |
f42c85e7 SR |
172 | * Override the macros in <trace/trace_events.h> to include the following: |
173 | * | |
174 | * enum print_line_t | |
175 | * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags) | |
176 | * { | |
177 | * struct trace_seq *s = &iter->seq; | |
178 | * struct ftrace_raw_<call> *field; <-- defined in stage 1 | |
179 | * struct trace_entry *entry; | |
be74b73a | 180 | * struct trace_seq *p; |
f42c85e7 SR |
181 | * int ret; |
182 | * | |
183 | * entry = iter->ent; | |
184 | * | |
185 | * if (entry->type != event_<call>.id) { | |
186 | * WARN_ON_ONCE(1); | |
187 | * return TRACE_TYPE_UNHANDLED; | |
188 | * } | |
189 | * | |
190 | * field = (typeof(field))entry; | |
191 | * | |
be74b73a | 192 | * p = get_cpu_var(ftrace_event_seq); |
56d8bd3f | 193 | * trace_seq_init(p); |
f42c85e7 | 194 | * ret = trace_seq_printf(s, <TP_printk> "\n"); |
be74b73a | 195 | * put_cpu(); |
f42c85e7 SR |
196 | * if (!ret) |
197 | * return TRACE_TYPE_PARTIAL_LINE; | |
198 | * | |
199 | * return TRACE_TYPE_HANDLED; | |
200 | * } | |
201 | * | |
202 | * This is the method used to print the raw event to the trace | |
203 | * output format. Note, this is not needed if the data is read | |
204 | * in binary. | |
205 | */ | |
206 | ||
207 | #undef __entry | |
208 | #define __entry field | |
209 | ||
210 | #undef TP_printk | |
211 | #define TP_printk(fmt, args...) fmt "\n", args | |
212 | ||
7fcb7c47 LZ |
213 | #undef __get_dynamic_array |
214 | #define __get_dynamic_array(field) \ | |
7d536cb3 | 215 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) |
7fcb7c47 | 216 | |
9cbf1176 | 217 | #undef __get_str |
7fcb7c47 | 218 | #define __get_str(field) (char *)__get_dynamic_array(field) |
9cbf1176 | 219 | |
be74b73a SR |
220 | #undef __print_flags |
221 | #define __print_flags(flag, delim, flag_array...) \ | |
222 | ({ \ | |
223 | static const struct trace_print_flags flags[] = \ | |
224 | { flag_array, { -1, NULL }}; \ | |
225 | ftrace_print_flags_seq(p, delim, flag, flags); \ | |
226 | }) | |
227 | ||
0f4fc29d SR |
228 | #undef __print_symbolic |
229 | #define __print_symbolic(value, symbol_array...) \ | |
230 | ({ \ | |
231 | static const struct trace_print_flags symbols[] = \ | |
232 | { symbol_array, { -1, NULL }}; \ | |
233 | ftrace_print_symbols_seq(p, value, symbols); \ | |
234 | }) | |
235 | ||
f42c85e7 SR |
236 | #undef TRACE_EVENT |
237 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | |
238 | enum print_line_t \ | |
239 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |
240 | { \ | |
241 | struct trace_seq *s = &iter->seq; \ | |
242 | struct ftrace_raw_##call *field; \ | |
243 | struct trace_entry *entry; \ | |
be74b73a | 244 | struct trace_seq *p; \ |
f42c85e7 SR |
245 | int ret; \ |
246 | \ | |
247 | entry = iter->ent; \ | |
248 | \ | |
249 | if (entry->type != event_##call.id) { \ | |
250 | WARN_ON_ONCE(1); \ | |
251 | return TRACE_TYPE_UNHANDLED; \ | |
252 | } \ | |
253 | \ | |
254 | field = (typeof(field))entry; \ | |
255 | \ | |
be74b73a | 256 | p = &get_cpu_var(ftrace_event_seq); \ |
56d8bd3f | 257 | trace_seq_init(p); \ |
f42c85e7 | 258 | ret = trace_seq_printf(s, #call ": " print); \ |
be74b73a | 259 | put_cpu(); \ |
f42c85e7 SR |
260 | if (!ret) \ |
261 | return TRACE_TYPE_PARTIAL_LINE; \ | |
262 | \ | |
263 | return TRACE_TYPE_HANDLED; \ | |
264 | } | |
265 | ||
266 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
267 | ||
f42c85e7 SR |
268 | #undef __field |
269 | #define __field(type, item) \ | |
270 | ret = trace_define_field(event_call, #type, #item, \ | |
271 | offsetof(typeof(field), item), \ | |
a118e4d1 | 272 | sizeof(field.item), is_signed_type(type)); \ |
f42c85e7 SR |
273 | if (ret) \ |
274 | return ret; | |
275 | ||
276 | #undef __array | |
277 | #define __array(type, item, len) \ | |
278 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ | |
279 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ | |
280 | offsetof(typeof(field), item), \ | |
a118e4d1 | 281 | sizeof(field.item), 0); \ |
f42c85e7 SR |
282 | if (ret) \ |
283 | return ret; | |
284 | ||
7fcb7c47 LZ |
285 | #undef __dynamic_array |
286 | #define __dynamic_array(type, item, len) \ | |
68fd60a8 | 287 | ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \ |
7fcb7c47 LZ |
288 | offsetof(typeof(field), __data_loc_##item), \ |
289 | sizeof(field.__data_loc_##item), 0); | |
290 | ||
9cbf1176 | 291 | #undef __string |
7fcb7c47 | 292 | #define __string(item, src) __dynamic_array(char, item, -1) |
9cbf1176 | 293 | |
f42c85e7 SR |
294 | #undef TRACE_EVENT |
295 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ | |
296 | int \ | |
297 | ftrace_define_fields_##call(void) \ | |
298 | { \ | |
299 | struct ftrace_raw_##call field; \ | |
300 | struct ftrace_event_call *event_call = &event_##call; \ | |
301 | int ret; \ | |
302 | \ | |
a118e4d1 TZ |
303 | __common_field(int, type, 1); \ |
304 | __common_field(unsigned char, flags, 0); \ | |
305 | __common_field(unsigned char, preempt_count, 0); \ | |
306 | __common_field(int, pid, 1); \ | |
307 | __common_field(int, tgid, 1); \ | |
f42c85e7 SR |
308 | \ |
309 | tstruct; \ | |
310 | \ | |
311 | return ret; \ | |
312 | } | |
313 | ||
314 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
315 | ||
7fcb7c47 LZ |
316 | /* |
317 | * remember the offset of each array from the beginning of the event. | |
318 | */ | |
319 | ||
320 | #undef __entry | |
321 | #define __entry entry | |
322 | ||
323 | #undef __field | |
324 | #define __field(type, item) | |
325 | ||
326 | #undef __array | |
327 | #define __array(type, item, len) | |
328 | ||
329 | #undef __dynamic_array | |
330 | #define __dynamic_array(type, item, len) \ | |
331 | __data_offsets->item = __data_size + \ | |
332 | offsetof(typeof(*entry), __data); \ | |
7d536cb3 | 333 | __data_offsets->item |= (len * sizeof(type)) << 16; \ |
7fcb7c47 LZ |
334 | __data_size += (len) * sizeof(type); |
335 | ||
336 | #undef __string | |
337 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \ | |
338 | ||
339 | #undef TRACE_EVENT | |
340 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | |
341 | static inline int ftrace_get_offsets_##call( \ | |
342 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ | |
343 | { \ | |
344 | int __data_size = 0; \ | |
345 | struct ftrace_raw_##call __maybe_unused *entry; \ | |
346 | \ | |
347 | tstruct; \ | |
348 | \ | |
349 | return __data_size; \ | |
350 | } | |
351 | ||
352 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
353 | ||
3a659305 PZ |
354 | #ifdef CONFIG_EVENT_PROFILE |
355 | ||
356 | /* | |
357 | * Generate the functions needed for tracepoint perf_counter support. | |
358 | * | |
f413cdb8 | 359 | * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later |
3a659305 PZ |
360 | * |
361 | * static int ftrace_profile_enable_<call>(struct ftrace_event_call *event_call) | |
362 | * { | |
363 | * int ret = 0; | |
364 | * | |
365 | * if (!atomic_inc_return(&event_call->profile_count)) | |
366 | * ret = register_trace_<call>(ftrace_profile_<call>); | |
367 | * | |
368 | * return ret; | |
369 | * } | |
370 | * | |
371 | * static void ftrace_profile_disable_<call>(struct ftrace_event_call *event_call) | |
372 | * { | |
373 | * if (atomic_add_negative(-1, &event->call->profile_count)) | |
374 | * unregister_trace_<call>(ftrace_profile_<call>); | |
375 | * } | |
376 | * | |
377 | */ | |
378 | ||
3a659305 PZ |
379 | #undef TRACE_EVENT |
380 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | |
381 | \ | |
f413cdb8 | 382 | static void ftrace_profile_##call(proto); \ |
3a659305 PZ |
383 | \ |
384 | static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \ | |
385 | { \ | |
386 | int ret = 0; \ | |
387 | \ | |
388 | if (!atomic_inc_return(&event_call->profile_count)) \ | |
389 | ret = register_trace_##call(ftrace_profile_##call); \ | |
390 | \ | |
391 | return ret; \ | |
392 | } \ | |
393 | \ | |
394 | static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\ | |
395 | { \ | |
396 | if (atomic_add_negative(-1, &event_call->profile_count)) \ | |
397 | unregister_trace_##call(ftrace_profile_##call); \ | |
398 | } | |
399 | ||
400 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
401 | ||
3a659305 PZ |
402 | #endif |
403 | ||
c32e827b | 404 | /* |
9cbf1176 | 405 | * Stage 4 of the trace events. |
c32e827b | 406 | * |
ea20d929 | 407 | * Override the macros in <trace/trace_events.h> to include the following: |
c32e827b SR |
408 | * |
409 | * static void ftrace_event_<call>(proto) | |
410 | * { | |
ef18012b | 411 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); |
c32e827b SR |
412 | * } |
413 | * | |
414 | * static int ftrace_reg_event_<call>(void) | |
415 | * { | |
ef18012b | 416 | * int ret; |
c32e827b | 417 | * |
ef18012b SR |
418 | * ret = register_trace_<call>(ftrace_event_<call>); |
419 | * if (!ret) | |
420 | * pr_info("event trace: Could not activate trace point " | |
421 | * "probe to <call>"); | |
422 | * return ret; | |
c32e827b SR |
423 | * } |
424 | * | |
425 | * static void ftrace_unreg_event_<call>(void) | |
426 | * { | |
ef18012b | 427 | * unregister_trace_<call>(ftrace_event_<call>); |
c32e827b SR |
428 | * } |
429 | * | |
c32e827b | 430 | * |
157587d7 | 431 | * For those macros defined with TRACE_EVENT: |
c32e827b SR |
432 | * |
433 | * static struct ftrace_event_call event_<call>; | |
434 | * | |
435 | * static void ftrace_raw_event_<call>(proto) | |
436 | * { | |
ef18012b SR |
437 | * struct ring_buffer_event *event; |
438 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | |
439 | * unsigned long irq_flags; | |
440 | * int pc; | |
441 | * | |
442 | * local_save_flags(irq_flags); | |
443 | * pc = preempt_count(); | |
444 | * | |
445 | * event = trace_current_buffer_lock_reserve(event_<call>.id, | |
446 | * sizeof(struct ftrace_raw_<call>), | |
447 | * irq_flags, pc); | |
448 | * if (!event) | |
449 | * return; | |
450 | * entry = ring_buffer_event_data(event); | |
451 | * | |
452 | * <assign>; <-- Here we assign the entries by the __field and | |
0e3d0f05 | 453 | * __array macros. |
c32e827b | 454 | * |
ef18012b | 455 | * trace_current_buffer_unlock_commit(event, irq_flags, pc); |
c32e827b SR |
456 | * } |
457 | * | |
458 | * static int ftrace_raw_reg_event_<call>(void) | |
459 | * { | |
ef18012b | 460 | * int ret; |
c32e827b | 461 | * |
ef18012b SR |
462 | * ret = register_trace_<call>(ftrace_raw_event_<call>); |
463 | * if (!ret) | |
464 | * pr_info("event trace: Could not activate trace point " | |
465 | * "probe to <call>"); | |
466 | * return ret; | |
c32e827b SR |
467 | * } |
468 | * | |
469 | * static void ftrace_unreg_event_<call>(void) | |
470 | * { | |
ef18012b | 471 | * unregister_trace_<call>(ftrace_raw_event_<call>); |
c32e827b SR |
472 | * } |
473 | * | |
474 | * static struct trace_event ftrace_event_type_<call> = { | |
ef18012b | 475 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
c32e827b SR |
476 | * }; |
477 | * | |
478 | * static int ftrace_raw_init_event_<call>(void) | |
479 | * { | |
ef18012b | 480 | * int id; |
c32e827b | 481 | * |
ef18012b SR |
482 | * id = register_ftrace_event(&ftrace_event_type_<call>); |
483 | * if (!id) | |
484 | * return -ENODEV; | |
485 | * event_<call>.id = id; | |
486 | * return 0; | |
c32e827b SR |
487 | * } |
488 | * | |
489 | * static struct ftrace_event_call __used | |
490 | * __attribute__((__aligned__(4))) | |
491 | * __attribute__((section("_ftrace_events"))) event_<call> = { | |
ef18012b | 492 | * .name = "<call>", |
0e3d0f05 | 493 | * .system = "<system>", |
ef18012b SR |
494 | * .raw_init = ftrace_raw_init_event_<call>, |
495 | * .regfunc = ftrace_reg_event_<call>, | |
496 | * .unregfunc = ftrace_unreg_event_<call>, | |
981d081e | 497 | * .show_format = ftrace_format_<call>, |
c32e827b SR |
498 | * } |
499 | * | |
500 | */ | |
501 | ||
2939b046 SR |
502 | #undef TP_FMT |
503 | #define TP_FMT(fmt, args...) fmt "\n", ##args | |
c32e827b | 504 | |
ac199db0 | 505 | #ifdef CONFIG_EVENT_PROFILE |
ac199db0 PZ |
506 | |
507 | #define _TRACE_PROFILE_INIT(call) \ | |
508 | .profile_count = ATOMIC_INIT(-1), \ | |
509 | .profile_enable = ftrace_profile_enable_##call, \ | |
510 | .profile_disable = ftrace_profile_disable_##call, | |
511 | ||
512 | #else | |
ac199db0 PZ |
513 | #define _TRACE_PROFILE_INIT(call) |
514 | #endif | |
515 | ||
da4d0302 SR |
516 | #undef __entry |
517 | #define __entry entry | |
d20e3b03 | 518 | |
9cbf1176 FW |
519 | #undef __field |
520 | #define __field(type, item) | |
521 | ||
522 | #undef __array | |
523 | #define __array(type, item, len) | |
524 | ||
7fcb7c47 LZ |
525 | #undef __dynamic_array |
526 | #define __dynamic_array(type, item, len) \ | |
527 | __entry->__data_loc_##item = __data_offsets.item; | |
528 | ||
9cbf1176 | 529 | #undef __string |
7fcb7c47 | 530 | #define __string(item, src) __dynamic_array(char, item, -1) \ |
9cbf1176 FW |
531 | |
532 | #undef __assign_str | |
533 | #define __assign_str(dst, src) \ | |
9cbf1176 FW |
534 | strcpy(__get_str(dst), src); |
535 | ||
da4d0302 | 536 | #undef TRACE_EVENT |
30a8fecc | 537 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
c32e827b SR |
538 | \ |
539 | static struct ftrace_event_call event_##call; \ | |
540 | \ | |
541 | static void ftrace_raw_event_##call(proto) \ | |
542 | { \ | |
7fcb7c47 | 543 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
f2aebaee | 544 | struct ftrace_event_call *event_call = &event_##call; \ |
c32e827b SR |
545 | struct ring_buffer_event *event; \ |
546 | struct ftrace_raw_##call *entry; \ | |
547 | unsigned long irq_flags; \ | |
7fcb7c47 | 548 | int __data_size; \ |
c32e827b SR |
549 | int pc; \ |
550 | \ | |
551 | local_save_flags(irq_flags); \ | |
552 | pc = preempt_count(); \ | |
553 | \ | |
7fcb7c47 | 554 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
9cbf1176 | 555 | \ |
c32e827b | 556 | event = trace_current_buffer_lock_reserve(event_##call.id, \ |
7fcb7c47 | 557 | sizeof(*entry) + __data_size, \ |
9cbf1176 | 558 | irq_flags, pc); \ |
c32e827b SR |
559 | if (!event) \ |
560 | return; \ | |
561 | entry = ring_buffer_event_data(event); \ | |
562 | \ | |
7fcb7c47 LZ |
563 | \ |
564 | tstruct \ | |
565 | \ | |
a9c1c3ab | 566 | { assign; } \ |
c32e827b | 567 | \ |
f2aebaee | 568 | if (!filter_current_check_discard(event_call, entry, event)) \ |
77d9f465 | 569 | trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \ |
c32e827b SR |
570 | } \ |
571 | \ | |
69fd4f0e | 572 | static int ftrace_raw_reg_event_##call(void *ptr) \ |
c32e827b SR |
573 | { \ |
574 | int ret; \ | |
575 | \ | |
576 | ret = register_trace_##call(ftrace_raw_event_##call); \ | |
633ddaa7 | 577 | if (ret) \ |
c32e827b | 578 | pr_info("event trace: Could not activate trace point " \ |
633ddaa7 | 579 | "probe to " #call "\n"); \ |
c32e827b SR |
580 | return ret; \ |
581 | } \ | |
582 | \ | |
69fd4f0e | 583 | static void ftrace_raw_unreg_event_##call(void *ptr) \ |
c32e827b SR |
584 | { \ |
585 | unregister_trace_##call(ftrace_raw_event_##call); \ | |
586 | } \ | |
587 | \ | |
588 | static struct trace_event ftrace_event_type_##call = { \ | |
589 | .trace = ftrace_raw_output_##call, \ | |
590 | }; \ | |
591 | \ | |
592 | static int ftrace_raw_init_event_##call(void) \ | |
593 | { \ | |
594 | int id; \ | |
595 | \ | |
596 | id = register_ftrace_event(&ftrace_event_type_##call); \ | |
597 | if (!id) \ | |
598 | return -ENODEV; \ | |
599 | event_##call.id = id; \ | |
cf027f64 | 600 | INIT_LIST_HEAD(&event_##call.fields); \ |
0a19e53c | 601 | init_preds(&event_##call); \ |
c32e827b SR |
602 | return 0; \ |
603 | } \ | |
604 | \ | |
605 | static struct ftrace_event_call __used \ | |
606 | __attribute__((__aligned__(4))) \ | |
607 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
ef18012b | 608 | .name = #call, \ |
9cc26a26 | 609 | .system = __stringify(TRACE_SYSTEM), \ |
6d723736 | 610 | .event = &ftrace_event_type_##call, \ |
c32e827b | 611 | .raw_init = ftrace_raw_init_event_##call, \ |
da4d0302 SR |
612 | .regfunc = ftrace_raw_reg_event_##call, \ |
613 | .unregfunc = ftrace_raw_unreg_event_##call, \ | |
981d081e | 614 | .show_format = ftrace_format_##call, \ |
cf027f64 | 615 | .define_fields = ftrace_define_fields_##call, \ |
ac199db0 | 616 | _TRACE_PROFILE_INIT(call) \ |
c32e827b | 617 | } |
ac199db0 | 618 | |
f42c85e7 | 619 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
ac199db0 | 620 | |
f413cdb8 FW |
621 | /* |
622 | * Define the insertion callback to profile events | |
623 | * | |
624 | * The job is very similar to ftrace_raw_event_<call> except that we don't | |
625 | * insert in the ring buffer but in a perf counter. | |
626 | * | |
627 | * static void ftrace_profile_<call>(proto) | |
628 | * { | |
629 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | |
630 | * struct ftrace_event_call *event_call = &event_<call>; | |
631 | * extern void perf_tpcounter_event(int, u64, u64, void *, int); | |
632 | * struct ftrace_raw_##call *entry; | |
633 | * u64 __addr = 0, __count = 1; | |
634 | * unsigned long irq_flags; | |
635 | * int __entry_size; | |
636 | * int __data_size; | |
637 | * int pc; | |
638 | * | |
639 | * local_save_flags(irq_flags); | |
640 | * pc = preempt_count(); | |
641 | * | |
642 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | |
304703ab FW |
643 | * |
644 | * // Below we want to get the aligned size by taking into account | |
645 | * // the u32 field that will later store the buffer size | |
646 | * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32), | |
647 | * sizeof(u64)); | |
648 | * __entry_size -= sizeof(u32); | |
f413cdb8 FW |
649 | * |
650 | * do { | |
651 | * char raw_data[__entry_size]; <- allocate our sample in the stack | |
652 | * struct trace_entry *ent; | |
653 | * | |
1853db0e FW |
654 | * zero dead bytes from alignment to avoid stack leak to userspace: |
655 | * | |
656 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; | |
f413cdb8 FW |
657 | * entry = (struct ftrace_raw_<call> *)raw_data; |
658 | * ent = &entry->ent; | |
659 | * tracing_generic_entry_update(ent, irq_flags, pc); | |
660 | * ent->type = event_call->id; | |
661 | * | |
662 | * <tstruct> <- do some jobs with dynamic arrays | |
663 | * | |
664 | * <assign> <- affect our values | |
665 | * | |
666 | * perf_tpcounter_event(event_call->id, __addr, __count, entry, | |
667 | * __entry_size); <- submit them to perf counter | |
668 | * } while (0); | |
669 | * | |
670 | * } | |
671 | */ | |
672 | ||
673 | #ifdef CONFIG_EVENT_PROFILE | |
674 | ||
675 | #undef __perf_addr | |
676 | #define __perf_addr(a) __addr = (a) | |
677 | ||
678 | #undef __perf_count | |
679 | #define __perf_count(c) __count = (c) | |
680 | ||
681 | #undef TRACE_EVENT | |
682 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | |
683 | static void ftrace_profile_##call(proto) \ | |
684 | { \ | |
685 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | |
686 | struct ftrace_event_call *event_call = &event_##call; \ | |
687 | extern void perf_tpcounter_event(int, u64, u64, void *, int); \ | |
688 | struct ftrace_raw_##call *entry; \ | |
689 | u64 __addr = 0, __count = 1; \ | |
690 | unsigned long irq_flags; \ | |
691 | int __entry_size; \ | |
692 | int __data_size; \ | |
693 | int pc; \ | |
694 | \ | |
695 | local_save_flags(irq_flags); \ | |
696 | pc = preempt_count(); \ | |
697 | \ | |
698 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | |
a044560c PZ |
699 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
700 | sizeof(u64)); \ | |
304703ab | 701 | __entry_size -= sizeof(u32); \ |
f413cdb8 FW |
702 | \ |
703 | do { \ | |
704 | char raw_data[__entry_size]; \ | |
705 | struct trace_entry *ent; \ | |
706 | \ | |
1853db0e | 707 | *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \ |
f413cdb8 FW |
708 | entry = (struct ftrace_raw_##call *)raw_data; \ |
709 | ent = &entry->ent; \ | |
710 | tracing_generic_entry_update(ent, irq_flags, pc); \ | |
711 | ent->type = event_call->id; \ | |
712 | \ | |
713 | tstruct \ | |
714 | \ | |
715 | { assign; } \ | |
716 | \ | |
717 | perf_tpcounter_event(event_call->id, __addr, __count, entry,\ | |
718 | __entry_size); \ | |
719 | } while (0); \ | |
720 | \ | |
721 | } | |
722 | ||
723 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
724 | #endif /* CONFIG_EVENT_PROFILE */ | |
725 | ||
ac199db0 PZ |
726 | #undef _TRACE_PROFILE_INIT |
727 |