]>
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 | ||
f42c85e7 SR |
21 | #undef __array |
22 | #define __array(type, item, len) type item[len]; | |
23 | ||
24 | #undef __field | |
25 | #define __field(type, item) type item; | |
26 | ||
9cbf1176 | 27 | #undef __string |
b0aae68c | 28 | #define __string(item, src) unsigned short __str_loc_##item; |
9cbf1176 | 29 | |
f42c85e7 SR |
30 | #undef TP_STRUCT__entry |
31 | #define TP_STRUCT__entry(args...) args | |
32 | ||
33 | #undef TRACE_EVENT | |
34 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
35 | struct ftrace_raw_##name { \ | |
36 | struct trace_entry ent; \ | |
37 | tstruct \ | |
9cbf1176 | 38 | char __str_data[0]; \ |
f42c85e7 SR |
39 | }; \ |
40 | static struct ftrace_event_call event_##name | |
41 | ||
42 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
43 | ||
9cbf1176 | 44 | |
f42c85e7 SR |
45 | /* |
46 | * Stage 2 of the trace events. | |
47 | * | |
9cbf1176 FW |
48 | * Include the following: |
49 | * | |
50 | * struct ftrace_str_offsets_<call> { | |
51 | * int <str1>; | |
52 | * int <str2>; | |
53 | * [...] | |
54 | * }; | |
55 | * | |
56 | * The __string() macro will create each int <str>, this is to | |
57 | * keep the offset of each string from the beggining of the event | |
58 | * once we perform the strlen() of the src strings. | |
59 | * | |
60 | */ | |
61 | ||
9cbf1176 FW |
62 | #undef __array |
63 | #define __array(type, item, len) | |
64 | ||
65 | #undef __field | |
66 | #define __field(type, item); | |
67 | ||
68 | #undef __string | |
69 | #define __string(item, src) int item; | |
70 | ||
71 | #undef TRACE_EVENT | |
72 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | |
73 | struct ftrace_str_offsets_##call { \ | |
74 | tstruct; \ | |
75 | }; | |
76 | ||
77 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
78 | ||
79 | /* | |
80 | * Stage 3 of the trace events. | |
81 | * | |
f42c85e7 SR |
82 | * Override the macros in <trace/trace_events.h> to include the following: |
83 | * | |
84 | * enum print_line_t | |
85 | * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags) | |
86 | * { | |
87 | * struct trace_seq *s = &iter->seq; | |
88 | * struct ftrace_raw_<call> *field; <-- defined in stage 1 | |
89 | * struct trace_entry *entry; | |
be74b73a | 90 | * struct trace_seq *p; |
f42c85e7 SR |
91 | * int ret; |
92 | * | |
93 | * entry = iter->ent; | |
94 | * | |
95 | * if (entry->type != event_<call>.id) { | |
96 | * WARN_ON_ONCE(1); | |
97 | * return TRACE_TYPE_UNHANDLED; | |
98 | * } | |
99 | * | |
100 | * field = (typeof(field))entry; | |
101 | * | |
be74b73a | 102 | * p = get_cpu_var(ftrace_event_seq); |
f42c85e7 | 103 | * ret = trace_seq_printf(s, <TP_printk> "\n"); |
be74b73a | 104 | * put_cpu(); |
f42c85e7 SR |
105 | * if (!ret) |
106 | * return TRACE_TYPE_PARTIAL_LINE; | |
107 | * | |
108 | * return TRACE_TYPE_HANDLED; | |
109 | * } | |
110 | * | |
111 | * This is the method used to print the raw event to the trace | |
112 | * output format. Note, this is not needed if the data is read | |
113 | * in binary. | |
114 | */ | |
115 | ||
116 | #undef __entry | |
117 | #define __entry field | |
118 | ||
119 | #undef TP_printk | |
120 | #define TP_printk(fmt, args...) fmt "\n", args | |
121 | ||
9cbf1176 | 122 | #undef __get_str |
6a74aa40 | 123 | #define __get_str(field) ((char *)__entry + __entry->__str_loc_##field) |
9cbf1176 | 124 | |
be74b73a SR |
125 | #undef __print_flags |
126 | #define __print_flags(flag, delim, flag_array...) \ | |
127 | ({ \ | |
128 | static const struct trace_print_flags flags[] = \ | |
129 | { flag_array, { -1, NULL }}; \ | |
130 | ftrace_print_flags_seq(p, delim, flag, flags); \ | |
131 | }) | |
132 | ||
0f4fc29d SR |
133 | #undef __print_symbolic |
134 | #define __print_symbolic(value, symbol_array...) \ | |
135 | ({ \ | |
136 | static const struct trace_print_flags symbols[] = \ | |
137 | { symbol_array, { -1, NULL }}; \ | |
138 | ftrace_print_symbols_seq(p, value, symbols); \ | |
139 | }) | |
140 | ||
f42c85e7 SR |
141 | #undef TRACE_EVENT |
142 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | |
143 | enum print_line_t \ | |
144 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |
145 | { \ | |
146 | struct trace_seq *s = &iter->seq; \ | |
147 | struct ftrace_raw_##call *field; \ | |
148 | struct trace_entry *entry; \ | |
be74b73a | 149 | struct trace_seq *p; \ |
f42c85e7 SR |
150 | int ret; \ |
151 | \ | |
152 | entry = iter->ent; \ | |
153 | \ | |
154 | if (entry->type != event_##call.id) { \ | |
155 | WARN_ON_ONCE(1); \ | |
156 | return TRACE_TYPE_UNHANDLED; \ | |
157 | } \ | |
158 | \ | |
159 | field = (typeof(field))entry; \ | |
160 | \ | |
be74b73a | 161 | p = &get_cpu_var(ftrace_event_seq); \ |
f42c85e7 | 162 | ret = trace_seq_printf(s, #call ": " print); \ |
be74b73a | 163 | put_cpu(); \ |
f42c85e7 SR |
164 | if (!ret) \ |
165 | return TRACE_TYPE_PARTIAL_LINE; \ | |
166 | \ | |
167 | return TRACE_TYPE_HANDLED; \ | |
168 | } | |
169 | ||
170 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
171 | ||
172 | /* | |
173 | * Setup the showing format of trace point. | |
174 | * | |
175 | * int | |
176 | * ftrace_format_##call(struct trace_seq *s) | |
177 | * { | |
178 | * struct ftrace_raw_##call field; | |
179 | * int ret; | |
180 | * | |
181 | * ret = trace_seq_printf(s, #type " " #item ";" | |
182 | * " offset:%u; size:%u;\n", | |
183 | * offsetof(struct ftrace_raw_##call, item), | |
184 | * sizeof(field.type)); | |
185 | * | |
186 | * } | |
187 | */ | |
188 | ||
189 | #undef TP_STRUCT__entry | |
190 | #define TP_STRUCT__entry(args...) args | |
191 | ||
192 | #undef __field | |
193 | #define __field(type, item) \ | |
194 | ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \ | |
195 | "offset:%u;\tsize:%u;\n", \ | |
196 | (unsigned int)offsetof(typeof(field), item), \ | |
197 | (unsigned int)sizeof(field.item)); \ | |
198 | if (!ret) \ | |
199 | return 0; | |
200 | ||
201 | #undef __array | |
202 | #define __array(type, item, len) \ | |
203 | ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \ | |
204 | "offset:%u;\tsize:%u;\n", \ | |
205 | (unsigned int)offsetof(typeof(field), item), \ | |
206 | (unsigned int)sizeof(field.item)); \ | |
207 | if (!ret) \ | |
208 | return 0; | |
209 | ||
9cbf1176 FW |
210 | #undef __string |
211 | #define __string(item, src) \ | |
6e25db44 LZ |
212 | ret = trace_seq_printf(s, "\tfield:__str_loc " #item ";\t" \ |
213 | "offset:%u;\tsize:%u;\n", \ | |
9cbf1176 FW |
214 | (unsigned int)offsetof(typeof(field), \ |
215 | __str_loc_##item), \ | |
216 | (unsigned int)sizeof(field.__str_loc_##item)); \ | |
217 | if (!ret) \ | |
218 | return 0; | |
219 | ||
f42c85e7 SR |
220 | #undef __entry |
221 | #define __entry REC | |
222 | ||
223 | #undef TP_printk | |
224 | #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args) | |
225 | ||
226 | #undef TP_fast_assign | |
227 | #define TP_fast_assign(args...) args | |
228 | ||
229 | #undef TRACE_EVENT | |
230 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ | |
231 | static int \ | |
232 | ftrace_format_##call(struct trace_seq *s) \ | |
233 | { \ | |
76aa8111 JF |
234 | struct ftrace_raw_##call field __attribute__((unused)); \ |
235 | int ret = 0; \ | |
f42c85e7 SR |
236 | \ |
237 | tstruct; \ | |
238 | \ | |
239 | trace_seq_printf(s, "\nprint fmt: " print); \ | |
240 | \ | |
241 | return ret; \ | |
242 | } | |
243 | ||
244 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
245 | ||
246 | #undef __field | |
247 | #define __field(type, item) \ | |
248 | ret = trace_define_field(event_call, #type, #item, \ | |
249 | offsetof(typeof(field), item), \ | |
a118e4d1 | 250 | sizeof(field.item), is_signed_type(type)); \ |
f42c85e7 SR |
251 | if (ret) \ |
252 | return ret; | |
253 | ||
254 | #undef __array | |
255 | #define __array(type, item, len) \ | |
256 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ | |
257 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ | |
258 | offsetof(typeof(field), item), \ | |
a118e4d1 | 259 | sizeof(field.item), 0); \ |
f42c85e7 SR |
260 | if (ret) \ |
261 | return ret; | |
262 | ||
9cbf1176 FW |
263 | #undef __string |
264 | #define __string(item, src) \ | |
265 | ret = trace_define_field(event_call, "__str_loc", #item, \ | |
266 | offsetof(typeof(field), __str_loc_##item), \ | |
a118e4d1 | 267 | sizeof(field.__str_loc_##item), 0); |
9cbf1176 | 268 | |
f42c85e7 SR |
269 | #undef TRACE_EVENT |
270 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ | |
271 | int \ | |
272 | ftrace_define_fields_##call(void) \ | |
273 | { \ | |
274 | struct ftrace_raw_##call field; \ | |
275 | struct ftrace_event_call *event_call = &event_##call; \ | |
276 | int ret; \ | |
277 | \ | |
a118e4d1 TZ |
278 | __common_field(int, type, 1); \ |
279 | __common_field(unsigned char, flags, 0); \ | |
280 | __common_field(unsigned char, preempt_count, 0); \ | |
281 | __common_field(int, pid, 1); \ | |
282 | __common_field(int, tgid, 1); \ | |
f42c85e7 SR |
283 | \ |
284 | tstruct; \ | |
285 | \ | |
286 | return ret; \ | |
287 | } | |
288 | ||
289 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
290 | ||
c32e827b | 291 | /* |
9cbf1176 | 292 | * Stage 4 of the trace events. |
c32e827b | 293 | * |
ea20d929 | 294 | * Override the macros in <trace/trace_events.h> to include the following: |
c32e827b SR |
295 | * |
296 | * static void ftrace_event_<call>(proto) | |
297 | * { | |
ef18012b | 298 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); |
c32e827b SR |
299 | * } |
300 | * | |
301 | * static int ftrace_reg_event_<call>(void) | |
302 | * { | |
ef18012b | 303 | * int ret; |
c32e827b | 304 | * |
ef18012b SR |
305 | * ret = register_trace_<call>(ftrace_event_<call>); |
306 | * if (!ret) | |
307 | * pr_info("event trace: Could not activate trace point " | |
308 | * "probe to <call>"); | |
309 | * return ret; | |
c32e827b SR |
310 | * } |
311 | * | |
312 | * static void ftrace_unreg_event_<call>(void) | |
313 | * { | |
ef18012b | 314 | * unregister_trace_<call>(ftrace_event_<call>); |
c32e827b SR |
315 | * } |
316 | * | |
c32e827b | 317 | * |
157587d7 | 318 | * For those macros defined with TRACE_EVENT: |
c32e827b SR |
319 | * |
320 | * static struct ftrace_event_call event_<call>; | |
321 | * | |
322 | * static void ftrace_raw_event_<call>(proto) | |
323 | * { | |
ef18012b SR |
324 | * struct ring_buffer_event *event; |
325 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | |
326 | * unsigned long irq_flags; | |
327 | * int pc; | |
328 | * | |
329 | * local_save_flags(irq_flags); | |
330 | * pc = preempt_count(); | |
331 | * | |
332 | * event = trace_current_buffer_lock_reserve(event_<call>.id, | |
333 | * sizeof(struct ftrace_raw_<call>), | |
334 | * irq_flags, pc); | |
335 | * if (!event) | |
336 | * return; | |
337 | * entry = ring_buffer_event_data(event); | |
338 | * | |
339 | * <assign>; <-- Here we assign the entries by the __field and | |
0e3d0f05 | 340 | * __array macros. |
c32e827b | 341 | * |
ef18012b | 342 | * trace_current_buffer_unlock_commit(event, irq_flags, pc); |
c32e827b SR |
343 | * } |
344 | * | |
345 | * static int ftrace_raw_reg_event_<call>(void) | |
346 | * { | |
ef18012b | 347 | * int ret; |
c32e827b | 348 | * |
ef18012b SR |
349 | * ret = register_trace_<call>(ftrace_raw_event_<call>); |
350 | * if (!ret) | |
351 | * pr_info("event trace: Could not activate trace point " | |
352 | * "probe to <call>"); | |
353 | * return ret; | |
c32e827b SR |
354 | * } |
355 | * | |
356 | * static void ftrace_unreg_event_<call>(void) | |
357 | * { | |
ef18012b | 358 | * unregister_trace_<call>(ftrace_raw_event_<call>); |
c32e827b SR |
359 | * } |
360 | * | |
361 | * static struct trace_event ftrace_event_type_<call> = { | |
ef18012b | 362 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
c32e827b SR |
363 | * }; |
364 | * | |
365 | * static int ftrace_raw_init_event_<call>(void) | |
366 | * { | |
ef18012b | 367 | * int id; |
c32e827b | 368 | * |
ef18012b SR |
369 | * id = register_ftrace_event(&ftrace_event_type_<call>); |
370 | * if (!id) | |
371 | * return -ENODEV; | |
372 | * event_<call>.id = id; | |
373 | * return 0; | |
c32e827b SR |
374 | * } |
375 | * | |
376 | * static struct ftrace_event_call __used | |
377 | * __attribute__((__aligned__(4))) | |
378 | * __attribute__((section("_ftrace_events"))) event_<call> = { | |
ef18012b | 379 | * .name = "<call>", |
0e3d0f05 | 380 | * .system = "<system>", |
ef18012b SR |
381 | * .raw_init = ftrace_raw_init_event_<call>, |
382 | * .regfunc = ftrace_reg_event_<call>, | |
383 | * .unregfunc = ftrace_unreg_event_<call>, | |
981d081e | 384 | * .show_format = ftrace_format_<call>, |
c32e827b SR |
385 | * } |
386 | * | |
387 | */ | |
388 | ||
2939b046 SR |
389 | #undef TP_FMT |
390 | #define TP_FMT(fmt, args...) fmt "\n", ##args | |
c32e827b | 391 | |
ac199db0 PZ |
392 | #ifdef CONFIG_EVENT_PROFILE |
393 | #define _TRACE_PROFILE(call, proto, args) \ | |
394 | static void ftrace_profile_##call(proto) \ | |
395 | { \ | |
396 | extern void perf_tpcounter_event(int); \ | |
397 | perf_tpcounter_event(event_##call.id); \ | |
398 | } \ | |
399 | \ | |
f2aebaee | 400 | static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \ |
ac199db0 PZ |
401 | { \ |
402 | int ret = 0; \ | |
403 | \ | |
f2aebaee | 404 | if (!atomic_inc_return(&event_call->profile_count)) \ |
ac199db0 PZ |
405 | ret = register_trace_##call(ftrace_profile_##call); \ |
406 | \ | |
407 | return ret; \ | |
408 | } \ | |
409 | \ | |
f2aebaee | 410 | static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\ |
ac199db0 | 411 | { \ |
f2aebaee | 412 | if (atomic_add_negative(-1, &event_call->profile_count)) \ |
ac199db0 PZ |
413 | unregister_trace_##call(ftrace_profile_##call); \ |
414 | } | |
415 | ||
416 | #define _TRACE_PROFILE_INIT(call) \ | |
417 | .profile_count = ATOMIC_INIT(-1), \ | |
418 | .profile_enable = ftrace_profile_enable_##call, \ | |
419 | .profile_disable = ftrace_profile_disable_##call, | |
420 | ||
421 | #else | |
422 | #define _TRACE_PROFILE(call, proto, args) | |
423 | #define _TRACE_PROFILE_INIT(call) | |
424 | #endif | |
425 | ||
da4d0302 SR |
426 | #undef __entry |
427 | #define __entry entry | |
d20e3b03 | 428 | |
9cbf1176 FW |
429 | #undef __field |
430 | #define __field(type, item) | |
431 | ||
432 | #undef __array | |
433 | #define __array(type, item, len) | |
434 | ||
435 | #undef __string | |
f2aebaee Z |
436 | #define __string(item, src) \ |
437 | __str_offsets.item = __str_size + \ | |
438 | offsetof(typeof(*entry), __str_data); \ | |
9cbf1176 FW |
439 | __str_size += strlen(src) + 1; |
440 | ||
441 | #undef __assign_str | |
442 | #define __assign_str(dst, src) \ | |
443 | __entry->__str_loc_##dst = __str_offsets.dst; \ | |
444 | strcpy(__get_str(dst), src); | |
445 | ||
da4d0302 | 446 | #undef TRACE_EVENT |
30a8fecc | 447 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
ac199db0 | 448 | _TRACE_PROFILE(call, PARAMS(proto), PARAMS(args)) \ |
c32e827b SR |
449 | \ |
450 | static struct ftrace_event_call event_##call; \ | |
451 | \ | |
452 | static void ftrace_raw_event_##call(proto) \ | |
453 | { \ | |
f2aebaee Z |
454 | struct ftrace_str_offsets_##call __maybe_unused __str_offsets; \ |
455 | struct ftrace_event_call *event_call = &event_##call; \ | |
c32e827b SR |
456 | struct ring_buffer_event *event; \ |
457 | struct ftrace_raw_##call *entry; \ | |
458 | unsigned long irq_flags; \ | |
9cbf1176 | 459 | int __str_size = 0; \ |
c32e827b SR |
460 | int pc; \ |
461 | \ | |
462 | local_save_flags(irq_flags); \ | |
463 | pc = preempt_count(); \ | |
464 | \ | |
9cbf1176 FW |
465 | tstruct; \ |
466 | \ | |
c32e827b | 467 | event = trace_current_buffer_lock_reserve(event_##call.id, \ |
9cbf1176 FW |
468 | sizeof(struct ftrace_raw_##call) + __str_size,\ |
469 | irq_flags, pc); \ | |
c32e827b SR |
470 | if (!event) \ |
471 | return; \ | |
472 | entry = ring_buffer_event_data(event); \ | |
473 | \ | |
da4d0302 | 474 | assign; \ |
c32e827b | 475 | \ |
f2aebaee | 476 | if (!filter_current_check_discard(event_call, entry, event)) \ |
77d9f465 | 477 | trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \ |
c32e827b SR |
478 | } \ |
479 | \ | |
480 | static int ftrace_raw_reg_event_##call(void) \ | |
481 | { \ | |
482 | int ret; \ | |
483 | \ | |
484 | ret = register_trace_##call(ftrace_raw_event_##call); \ | |
633ddaa7 | 485 | if (ret) \ |
c32e827b | 486 | pr_info("event trace: Could not activate trace point " \ |
633ddaa7 | 487 | "probe to " #call "\n"); \ |
c32e827b SR |
488 | return ret; \ |
489 | } \ | |
490 | \ | |
491 | static void ftrace_raw_unreg_event_##call(void) \ | |
492 | { \ | |
493 | unregister_trace_##call(ftrace_raw_event_##call); \ | |
494 | } \ | |
495 | \ | |
496 | static struct trace_event ftrace_event_type_##call = { \ | |
497 | .trace = ftrace_raw_output_##call, \ | |
498 | }; \ | |
499 | \ | |
500 | static int ftrace_raw_init_event_##call(void) \ | |
501 | { \ | |
502 | int id; \ | |
503 | \ | |
504 | id = register_ftrace_event(&ftrace_event_type_##call); \ | |
505 | if (!id) \ | |
506 | return -ENODEV; \ | |
507 | event_##call.id = id; \ | |
cf027f64 | 508 | INIT_LIST_HEAD(&event_##call.fields); \ |
0a19e53c | 509 | init_preds(&event_##call); \ |
c32e827b SR |
510 | return 0; \ |
511 | } \ | |
512 | \ | |
513 | static struct ftrace_event_call __used \ | |
514 | __attribute__((__aligned__(4))) \ | |
515 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
ef18012b | 516 | .name = #call, \ |
9cc26a26 | 517 | .system = __stringify(TRACE_SYSTEM), \ |
6d723736 | 518 | .event = &ftrace_event_type_##call, \ |
c32e827b | 519 | .raw_init = ftrace_raw_init_event_##call, \ |
da4d0302 SR |
520 | .regfunc = ftrace_raw_reg_event_##call, \ |
521 | .unregfunc = ftrace_raw_unreg_event_##call, \ | |
981d081e | 522 | .show_format = ftrace_format_##call, \ |
cf027f64 | 523 | .define_fields = ftrace_define_fields_##call, \ |
ac199db0 | 524 | _TRACE_PROFILE_INIT(call) \ |
c32e827b | 525 | } |
ac199db0 | 526 | |
f42c85e7 | 527 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
ac199db0 PZ |
528 | |
529 | #undef _TRACE_PROFILE | |
530 | #undef _TRACE_PROFILE_INIT | |
531 |