Commit | Line | Data |
---|---|---|
40652b65 MD |
1 | #include <lttng.h> |
2 | ||
3 | /* | |
4 | * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to | |
5 | * strcpy(). | |
6 | */ | |
1d12cebd | 7 | #undef tp_assign |
40652b65 MD |
8 | #define tp_assign(dest, src) \ |
9 | lib_ring_buffer_align_ctx(config, &ctx, sizeof(src)); \ | |
10 | lib_ring_buffer_write(config, &ctx, &src, sizeof(src)); | |
11 | ||
1d12cebd | 12 | #undef tp_memcpy |
40652b65 MD |
13 | #define tp_memcpy(dest, src, len) \ |
14 | lib_ring_buffer_align_ctx(config, &ctx, sizeof(*(src))); \ | |
15 | lib_ring_buffer_write(config, &ctx, &src, len); | |
16 | ||
17 | /* TODO */ | |
1d12cebd | 18 | #undef tp_strcpy |
40652b65 MD |
19 | #define tp_strcpy(dest, src) __assign_str(dest, src) |
20 | ||
21 | /* | |
22 | * Stage 1 of the trace events. | |
23 | * | |
24 | * Create event field type metadata section. | |
25 | */ | |
26 | ||
27 | /* | |
28 | * DECLARE_EVENT_CLASS can be used to add a generic function | |
29 | * handlers for events. That is, if all events have the same | |
30 | * parameters and just have distinct trace points. | |
31 | * Each tracepoint can be defined with DEFINE_EVENT and that | |
32 | * will map the DECLARE_EVENT_CLASS to the tracepoint. | |
33 | * | |
34 | * TRACE_EVENT is a one to one mapping between tracepoint and template. | |
35 | */ | |
36 | #undef TRACE_EVENT | |
37 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
38 | DECLARE_EVENT_CLASS(name, \ | |
39 | PARAMS(proto), \ | |
40 | PARAMS(args), \ | |
41 | PARAMS(tstruct), \ | |
42 | PARAMS(assign), \ | |
43 | PARAMS(print)); \ | |
44 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); | |
45 | ||
1d12cebd MD |
46 | /* Named field types must be defined in lttng-types.h */ |
47 | ||
48 | /* TODO turn into a structure definition ? */ | |
40652b65 MD |
49 | |
50 | #undef __field | |
1d12cebd | 51 | #define __field(_type, _item) #_type " " #_item ";\n" |
40652b65 MD |
52 | |
53 | #undef __field_ext | |
1d12cebd | 54 | #define __field_ext(_type, _item, _filter_type) #_type " " #_item ";\n" |
40652b65 MD |
55 | |
56 | #undef __array | |
1d12cebd MD |
57 | #define __array(_type, _item, _len) \ |
58 | "type { parent = array; length = " #_len "; elem_type = " #_type "; } " #_item";\n" | |
40652b65 MD |
59 | |
60 | #undef __dynamic_array | |
1d12cebd MD |
61 | #define __dynamic_array(_type, _item, _len) \ |
62 | "type { parent = sequence; length_type = u32; elem_type = " #_type "; } " #_item ";\n" | |
40652b65 MD |
63 | |
64 | #undef __string | |
1d12cebd MD |
65 | #define __string(_item, _src) \ |
66 | "type { parent = string; encoding = UTF8; } " #_item ";\n" | |
67 | ||
68 | #undef TP_PROTO | |
69 | #define TP_PROTO(args...) | |
70 | ||
71 | #undef TP_ARGS | |
72 | #define TP_ARGS(args...) | |
40652b65 MD |
73 | |
74 | #undef TP_STRUCT__entry | |
1d12cebd MD |
75 | #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ |
76 | ||
77 | #undef TP_fast_assign | |
78 | #define TP_fast_assign(args...) | |
79 | ||
80 | #undef TP_printk | |
81 | #define TP_printk(args...) | |
40652b65 MD |
82 | |
83 | #undef DECLARE_EVENT_CLASS | |
84 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ | |
1d12cebd | 85 | tstruct |
40652b65 MD |
86 | |
87 | #undef DEFINE_EVENT | |
1d12cebd | 88 | #define DEFINE_EVENT(template, name, proto, args) |
40652b65 MD |
89 | |
90 | #undef DEFINE_EVENT_PRINT | |
91 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
92 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
93 | ||
1d12cebd | 94 | /* Callbacks are meaningless to LTTng. */ |
40652b65 MD |
95 | #undef TRACE_EVENT_FN |
96 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ | |
97 | assign, print, reg, unreg) \ | |
98 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ | |
99 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ | |
100 | ||
1d12cebd MD |
101 | #undef DEFINE_TRACE_EVENT_METADATA |
102 | #define DEFINE_TRACE_EVENT_METADATA \ | |
103 | const char trace_event_metadata_##TRACE_SYSTEM[] | |
40652b65 | 104 | |
1d12cebd MD |
105 | //static DEFINE_TRACE_EVENT_METADATA = |
106 | static const char blah[] = | |
40652b65 | 107 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
1d12cebd MD |
108 | ; |
109 | ||
110 | #if 0 | |
40652b65 MD |
111 | |
112 | /* | |
113 | * Stage 2 of the trace events. | |
114 | * | |
115 | * Create static inline function that calculates event size. | |
116 | */ | |
117 | ||
118 | ||
119 | ||
120 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
121 | ||
122 | /* | |
123 | * Stage 3 of the trace events. | |
124 | * | |
125 | * Create the probe function : call even size calculation and write event data | |
126 | * into the buffer. | |
127 | */ | |
128 | ||
129 | ||
130 | ||
131 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
132 | ||
133 | ||
134 | ||
135 | ||
136 | #include <linux/ftrace_event.h> | |
137 | ||
138 | /* | |
139 | * DECLARE_EVENT_CLASS can be used to add a generic function | |
140 | * handlers for events. That is, if all events have the same | |
141 | * parameters and just have distinct trace points. | |
142 | * Each tracepoint can be defined with DEFINE_EVENT and that | |
143 | * will map the DECLARE_EVENT_CLASS to the tracepoint. | |
144 | * | |
145 | * TRACE_EVENT is a one to one mapping between tracepoint and template. | |
146 | */ | |
147 | #undef TRACE_EVENT | |
148 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
149 | DECLARE_EVENT_CLASS(name, \ | |
150 | PARAMS(proto), \ | |
151 | PARAMS(args), \ | |
152 | PARAMS(tstruct), \ | |
153 | PARAMS(assign), \ | |
154 | PARAMS(print)); \ | |
155 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); | |
156 | ||
157 | ||
158 | #undef __field | |
159 | #define __field(type, item) type item; | |
160 | ||
161 | #undef __field_ext | |
162 | #define __field_ext(type, item, filter_type) type item; | |
163 | ||
164 | #undef __array | |
165 | #define __array(type, item, len) type item[len]; | |
166 | ||
167 | #undef __dynamic_array | |
168 | #define __dynamic_array(type, item, len) u32 __data_loc_##item; | |
169 | ||
170 | #undef __string | |
171 | #define __string(item, src) __dynamic_array(char, item, -1) | |
172 | ||
173 | #undef TP_STRUCT__entry | |
174 | #define TP_STRUCT__entry(args...) args | |
175 | ||
176 | #undef DECLARE_EVENT_CLASS | |
177 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ | |
178 | struct ftrace_raw_##name { \ | |
179 | struct trace_entry ent; \ | |
180 | tstruct \ | |
181 | char __data[0]; \ | |
182 | }; \ | |
183 | \ | |
184 | static struct ftrace_event_class event_class_##name; | |
185 | ||
186 | #undef DEFINE_EVENT | |
187 | #define DEFINE_EVENT(template, name, proto, args) \ | |
188 | static struct ftrace_event_call __used \ | |
189 | __attribute__((__aligned__(4))) event_##name | |
190 | ||
191 | #undef DEFINE_EVENT_PRINT | |
192 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
193 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
194 | ||
195 | /* Callbacks are meaningless to ftrace. */ | |
196 | #undef TRACE_EVENT_FN | |
197 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ | |
198 | assign, print, reg, unreg) \ | |
199 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ | |
200 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ | |
201 | ||
202 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
203 | ||
204 | ||
205 | /* | |
206 | * Stage 2 of the trace events. | |
207 | * | |
208 | * Create static inline function that calculates event size. | |
209 | */ | |
210 | ||
211 | #undef __field | |
212 | #define __field(type, item) | |
213 | ||
214 | #undef __field_ext | |
215 | #define __field_ext(type, item, filter_type) | |
216 | ||
217 | #undef __array | |
218 | #define __array(type, item, len) | |
219 | ||
220 | #undef __dynamic_array | |
221 | #define __dynamic_array(type, item, len) u32 item; | |
222 | ||
223 | #undef __string | |
224 | #define __string(item, src) __dynamic_array(char, item, -1) | |
225 | ||
226 | #undef DECLARE_EVENT_CLASS | |
227 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
228 | struct ftrace_data_offsets_##call { \ | |
229 | tstruct; \ | |
230 | }; | |
231 | ||
232 | #undef DEFINE_EVENT | |
233 | #define DEFINE_EVENT(template, name, proto, args) | |
234 | ||
235 | #undef DEFINE_EVENT_PRINT | |
236 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
237 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
238 | ||
239 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
240 | ||
241 | /* | |
242 | * Stage 3 of the trace events. | |
243 | * | |
244 | * Create the probe function : call even size calculation and write event data | |
245 | * into the buffer. | |
246 | */ | |
247 | ||
248 | #undef __entry | |
249 | #define __entry field | |
250 | ||
251 | #undef TP_printk | |
252 | #define TP_printk(fmt, args...) fmt "\n", args | |
253 | ||
254 | #undef __get_dynamic_array | |
255 | #define __get_dynamic_array(field) \ | |
256 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) | |
257 | ||
258 | #undef __get_str | |
259 | #define __get_str(field) (char *)__get_dynamic_array(field) | |
260 | ||
261 | #undef __print_flags | |
262 | #define __print_flags(flag, delim, flag_array...) \ | |
263 | ({ \ | |
264 | static const struct trace_print_flags __flags[] = \ | |
265 | { flag_array, { -1, NULL }}; \ | |
266 | ftrace_print_flags_seq(p, delim, flag, __flags); \ | |
267 | }) | |
268 | ||
269 | #undef __print_symbolic | |
270 | #define __print_symbolic(value, symbol_array...) \ | |
271 | ({ \ | |
272 | static const struct trace_print_flags symbols[] = \ | |
273 | { symbol_array, { -1, NULL }}; \ | |
274 | ftrace_print_symbols_seq(p, value, symbols); \ | |
275 | }) | |
276 | ||
277 | #undef __print_hex | |
278 | #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len) | |
279 | ||
280 | #undef DECLARE_EVENT_CLASS | |
281 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
282 | static notrace enum print_line_t \ | |
283 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ | |
284 | struct trace_event *trace_event) \ | |
285 | { \ | |
286 | struct ftrace_event_call *event; \ | |
287 | struct trace_seq *s = &iter->seq; \ | |
288 | struct ftrace_raw_##call *field; \ | |
289 | struct trace_entry *entry; \ | |
290 | struct trace_seq *p = &iter->tmp_seq; \ | |
291 | int ret; \ | |
292 | \ | |
293 | event = container_of(trace_event, struct ftrace_event_call, \ | |
294 | event); \ | |
295 | \ | |
296 | entry = iter->ent; \ | |
297 | \ | |
298 | if (entry->type != event->event.type) { \ | |
299 | WARN_ON_ONCE(1); \ | |
300 | return TRACE_TYPE_UNHANDLED; \ | |
301 | } \ | |
302 | \ | |
303 | field = (typeof(field))entry; \ | |
304 | \ | |
305 | trace_seq_init(p); \ | |
306 | ret = trace_seq_printf(s, "%s: ", event->name); \ | |
307 | if (ret) \ | |
308 | ret = trace_seq_printf(s, print); \ | |
309 | if (!ret) \ | |
310 | return TRACE_TYPE_PARTIAL_LINE; \ | |
311 | \ | |
312 | return TRACE_TYPE_HANDLED; \ | |
313 | } \ | |
314 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
315 | .trace = ftrace_raw_output_##call, \ | |
316 | }; | |
317 | ||
318 | #undef DEFINE_EVENT_PRINT | |
319 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | |
320 | static notrace enum print_line_t \ | |
321 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ | |
322 | struct trace_event *event) \ | |
323 | { \ | |
324 | struct trace_seq *s = &iter->seq; \ | |
325 | struct ftrace_raw_##template *field; \ | |
326 | struct trace_entry *entry; \ | |
327 | struct trace_seq *p = &iter->tmp_seq; \ | |
328 | int ret; \ | |
329 | \ | |
330 | entry = iter->ent; \ | |
331 | \ | |
332 | if (entry->type != event_##call.event.type) { \ | |
333 | WARN_ON_ONCE(1); \ | |
334 | return TRACE_TYPE_UNHANDLED; \ | |
335 | } \ | |
336 | \ | |
337 | field = (typeof(field))entry; \ | |
338 | \ | |
339 | trace_seq_init(p); \ | |
340 | ret = trace_seq_printf(s, "%s: ", #call); \ | |
341 | if (ret) \ | |
342 | ret = trace_seq_printf(s, print); \ | |
343 | if (!ret) \ | |
344 | return TRACE_TYPE_PARTIAL_LINE; \ | |
345 | \ | |
346 | return TRACE_TYPE_HANDLED; \ | |
347 | } \ | |
348 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
349 | .trace = ftrace_raw_output_##call, \ | |
350 | }; | |
351 | ||
352 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
353 | ||
354 | #undef __field_ext | |
355 | #define __field_ext(type, item, filter_type) \ | |
356 | ret = trace_define_field(event_call, #type, #item, \ | |
357 | offsetof(typeof(field), item), \ | |
358 | sizeof(field.item), \ | |
359 | is_signed_type(type), filter_type); \ | |
360 | if (ret) \ | |
361 | return ret; | |
362 | ||
363 | #undef __field | |
364 | #define __field(type, item) __field_ext(type, item, FILTER_OTHER) | |
365 | ||
366 | #undef __array | |
367 | #define __array(type, item, len) \ | |
368 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ | |
369 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ | |
370 | offsetof(typeof(field), item), \ | |
371 | sizeof(field.item), \ | |
372 | is_signed_type(type), FILTER_OTHER); \ | |
373 | if (ret) \ | |
374 | return ret; | |
375 | ||
376 | #undef __dynamic_array | |
377 | #define __dynamic_array(type, item, len) \ | |
378 | ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \ | |
379 | offsetof(typeof(field), __data_loc_##item), \ | |
380 | sizeof(field.__data_loc_##item), \ | |
381 | is_signed_type(type), FILTER_OTHER); | |
382 | ||
383 | #undef __string | |
384 | #define __string(item, src) __dynamic_array(char, item, -1) | |
385 | ||
386 | #undef DECLARE_EVENT_CLASS | |
387 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ | |
388 | static int notrace \ | |
389 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ | |
390 | { \ | |
391 | struct ftrace_raw_##call field; \ | |
392 | int ret; \ | |
393 | \ | |
394 | tstruct; \ | |
395 | \ | |
396 | return ret; \ | |
397 | } | |
398 | ||
399 | #undef DEFINE_EVENT | |
400 | #define DEFINE_EVENT(template, name, proto, args) | |
401 | ||
402 | #undef DEFINE_EVENT_PRINT | |
403 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
404 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
405 | ||
406 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
407 | ||
408 | /* | |
409 | * remember the offset of each array from the beginning of the event. | |
410 | */ | |
411 | ||
412 | #undef __entry | |
413 | #define __entry entry | |
414 | ||
415 | #undef __field | |
416 | #define __field(type, item) | |
417 | ||
418 | #undef __field_ext | |
419 | #define __field_ext(type, item, filter_type) | |
420 | ||
421 | #undef __array | |
422 | #define __array(type, item, len) | |
423 | ||
424 | #undef __dynamic_array | |
425 | #define __dynamic_array(type, item, len) \ | |
426 | __data_offsets->item = __data_size + \ | |
427 | offsetof(typeof(*entry), __data); \ | |
428 | __data_offsets->item |= (len * sizeof(type)) << 16; \ | |
429 | __data_size += (len) * sizeof(type); | |
430 | ||
431 | #undef __string | |
432 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) | |
433 | ||
434 | #undef DECLARE_EVENT_CLASS | |
435 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
436 | static inline notrace int ftrace_get_offsets_##call( \ | |
437 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ | |
438 | { \ | |
439 | int __data_size = 0; \ | |
440 | struct ftrace_raw_##call __maybe_unused *entry; \ | |
441 | \ | |
442 | tstruct; \ | |
443 | \ | |
444 | return __data_size; \ | |
445 | } | |
446 | ||
447 | #undef DEFINE_EVENT | |
448 | #define DEFINE_EVENT(template, name, proto, args) | |
449 | ||
450 | #undef DEFINE_EVENT_PRINT | |
451 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
452 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
453 | ||
454 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
455 | ||
456 | /* | |
457 | * Stage 4 of the trace events. | |
458 | * | |
459 | * Override the macros in <trace/trace_events.h> to include the following: | |
460 | * | |
461 | * For those macros defined with TRACE_EVENT: | |
462 | * | |
463 | * static struct ftrace_event_call event_<call>; | |
464 | * | |
465 | * static void ftrace_raw_event_<call>(void *__data, proto) | |
466 | * { | |
467 | * struct ftrace_event_call *event_call = __data; | |
468 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | |
469 | * struct ring_buffer_event *event; | |
470 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | |
471 | * struct ring_buffer *buffer; | |
472 | * unsigned long irq_flags; | |
473 | * int __data_size; | |
474 | * int pc; | |
475 | * | |
476 | * local_save_flags(irq_flags); | |
477 | * pc = preempt_count(); | |
478 | * | |
479 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | |
480 | * | |
481 | * event = trace_current_buffer_lock_reserve(&buffer, | |
482 | * event_<call>->event.type, | |
483 | * sizeof(*entry) + __data_size, | |
484 | * irq_flags, pc); | |
485 | * if (!event) | |
486 | * return; | |
487 | * entry = ring_buffer_event_data(event); | |
488 | * | |
489 | * { <assign>; } <-- Here we assign the entries by the __field and | |
490 | * __array macros. | |
491 | * | |
492 | * if (!filter_current_check_discard(buffer, event_call, entry, event)) | |
493 | * trace_current_buffer_unlock_commit(buffer, | |
494 | * event, irq_flags, pc); | |
495 | * } | |
496 | * | |
497 | * static struct trace_event ftrace_event_type_<call> = { | |
498 | * .trace = ftrace_raw_output_<call>, <-- stage 2 | |
499 | * }; | |
500 | * | |
501 | * static const char print_fmt_<call>[] = <TP_printk>; | |
502 | * | |
503 | * static struct ftrace_event_class __used event_class_<template> = { | |
504 | * .system = "<system>", | |
505 | * .define_fields = ftrace_define_fields_<call>, | |
506 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), | |
507 | * .raw_init = trace_event_raw_init, | |
508 | * .probe = ftrace_raw_event_##call, | |
509 | * .reg = ftrace_event_reg, | |
510 | * }; | |
511 | * | |
512 | * static struct ftrace_event_call __used | |
513 | * __attribute__((__aligned__(4))) | |
514 | * __attribute__((section("_ftrace_events"))) event_<call> = { | |
515 | * .name = "<call>", | |
516 | * .class = event_class_<template>, | |
517 | * .event = &ftrace_event_type_<call>, | |
518 | * .print_fmt = print_fmt_<call>, | |
519 | * }; | |
520 | * | |
521 | */ | |
522 | ||
523 | #ifdef CONFIG_PERF_EVENTS | |
524 | ||
525 | #define _TRACE_PERF_PROTO(call, proto) \ | |
526 | static notrace void \ | |
527 | perf_trace_##call(void *__data, proto); | |
528 | ||
529 | #define _TRACE_PERF_INIT(call) \ | |
530 | .perf_probe = perf_trace_##call, | |
531 | ||
532 | #else | |
533 | #define _TRACE_PERF_PROTO(call, proto) | |
534 | #define _TRACE_PERF_INIT(call) | |
535 | #endif /* CONFIG_PERF_EVENTS */ | |
536 | ||
537 | #undef __entry | |
538 | #define __entry entry | |
539 | ||
540 | #undef __field | |
541 | #define __field(type, item) | |
542 | ||
543 | #undef __array | |
544 | #define __array(type, item, len) | |
545 | ||
546 | #undef __dynamic_array | |
547 | #define __dynamic_array(type, item, len) \ | |
548 | __entry->__data_loc_##item = __data_offsets.item; | |
549 | ||
550 | #undef __string | |
551 | #define __string(item, src) __dynamic_array(char, item, -1) \ | |
552 | ||
553 | #undef __assign_str | |
554 | #define __assign_str(dst, src) \ | |
555 | strcpy(__get_str(dst), src); | |
556 | ||
557 | #undef TP_fast_assign | |
558 | #define TP_fast_assign(args...) args | |
559 | ||
560 | #undef TP_perf_assign | |
561 | #define TP_perf_assign(args...) | |
562 | ||
563 | #undef DECLARE_EVENT_CLASS | |
564 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
565 | \ | |
566 | static notrace void \ | |
567 | ftrace_raw_event_##call(void *__data, proto) \ | |
568 | { \ | |
569 | struct ftrace_event_call *event_call = __data; \ | |
570 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | |
571 | struct ring_buffer_event *event; \ | |
572 | struct ftrace_raw_##call *entry; \ | |
573 | struct ring_buffer *buffer; \ | |
574 | unsigned long irq_flags; \ | |
575 | int __data_size; \ | |
576 | int pc; \ | |
577 | \ | |
578 | local_save_flags(irq_flags); \ | |
579 | pc = preempt_count(); \ | |
580 | \ | |
581 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | |
582 | \ | |
583 | event = trace_current_buffer_lock_reserve(&buffer, \ | |
584 | event_call->event.type, \ | |
585 | sizeof(*entry) + __data_size, \ | |
586 | irq_flags, pc); \ | |
587 | if (!event) \ | |
588 | return; \ | |
589 | entry = ring_buffer_event_data(event); \ | |
590 | \ | |
591 | tstruct \ | |
592 | \ | |
593 | { assign; } \ | |
594 | \ | |
595 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ | |
596 | trace_nowake_buffer_unlock_commit(buffer, \ | |
597 | event, irq_flags, pc); \ | |
598 | } | |
599 | /* | |
600 | * The ftrace_test_probe is compiled out, it is only here as a build time check | |
601 | * to make sure that if the tracepoint handling changes, the ftrace probe will | |
602 | * fail to compile unless it too is updated. | |
603 | */ | |
604 | ||
605 | #undef DEFINE_EVENT | |
606 | #define DEFINE_EVENT(template, call, proto, args) \ | |
607 | static inline void ftrace_test_probe_##call(void) \ | |
608 | { \ | |
609 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ | |
610 | } | |
611 | ||
612 | #undef DEFINE_EVENT_PRINT | |
613 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) | |
614 | ||
615 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
616 | ||
617 | #undef __entry | |
618 | #define __entry REC | |
619 | ||
620 | #undef __print_flags | |
621 | #undef __print_symbolic | |
622 | #undef __get_dynamic_array | |
623 | #undef __get_str | |
624 | ||
625 | #undef TP_printk | |
626 | #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) | |
627 | ||
628 | #undef DECLARE_EVENT_CLASS | |
629 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
630 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ | |
631 | static const char print_fmt_##call[] = print; \ | |
632 | static struct ftrace_event_class __used event_class_##call = { \ | |
633 | .system = __stringify(TRACE_SYSTEM), \ | |
634 | .define_fields = ftrace_define_fields_##call, \ | |
635 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ | |
636 | .raw_init = trace_event_raw_init, \ | |
637 | .probe = ftrace_raw_event_##call, \ | |
638 | .reg = ftrace_event_reg, \ | |
639 | _TRACE_PERF_INIT(call) \ | |
640 | }; | |
641 | ||
642 | #undef DEFINE_EVENT | |
643 | #define DEFINE_EVENT(template, call, proto, args) \ | |
644 | \ | |
645 | static struct ftrace_event_call __used \ | |
646 | __attribute__((__aligned__(4))) \ | |
647 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
648 | .name = #call, \ | |
649 | .class = &event_class_##template, \ | |
650 | .event.funcs = &ftrace_event_type_funcs_##template, \ | |
651 | .print_fmt = print_fmt_##template, \ | |
652 | }; | |
653 | ||
654 | #undef DEFINE_EVENT_PRINT | |
655 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | |
656 | \ | |
657 | static const char print_fmt_##call[] = print; \ | |
658 | \ | |
659 | static struct ftrace_event_call __used \ | |
660 | __attribute__((__aligned__(4))) \ | |
661 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
662 | .name = #call, \ | |
663 | .class = &event_class_##template, \ | |
664 | .event.funcs = &ftrace_event_type_funcs_##call, \ | |
665 | .print_fmt = print_fmt_##call, \ | |
666 | } | |
667 | ||
668 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
669 | ||
670 | /* | |
671 | * Define the insertion callback to perf events | |
672 | * | |
673 | * The job is very similar to ftrace_raw_event_<call> except that we don't | |
674 | * insert in the ring buffer but in a perf counter. | |
675 | * | |
676 | * static void ftrace_perf_<call>(proto) | |
677 | * { | |
678 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | |
679 | * struct ftrace_event_call *event_call = &event_<call>; | |
680 | * extern void perf_tp_event(int, u64, u64, void *, int); | |
681 | * struct ftrace_raw_##call *entry; | |
682 | * struct perf_trace_buf *trace_buf; | |
683 | * u64 __addr = 0, __count = 1; | |
684 | * unsigned long irq_flags; | |
685 | * struct trace_entry *ent; | |
686 | * int __entry_size; | |
687 | * int __data_size; | |
688 | * int __cpu | |
689 | * int pc; | |
690 | * | |
691 | * pc = preempt_count(); | |
692 | * | |
693 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | |
694 | * | |
695 | * // Below we want to get the aligned size by taking into account | |
696 | * // the u32 field that will later store the buffer size | |
697 | * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32), | |
698 | * sizeof(u64)); | |
699 | * __entry_size -= sizeof(u32); | |
700 | * | |
701 | * // Protect the non nmi buffer | |
702 | * // This also protects the rcu read side | |
703 | * local_irq_save(irq_flags); | |
704 | * __cpu = smp_processor_id(); | |
705 | * | |
706 | * if (in_nmi()) | |
707 | * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi); | |
708 | * else | |
709 | * trace_buf = rcu_dereference_sched(perf_trace_buf); | |
710 | * | |
711 | * if (!trace_buf) | |
712 | * goto end; | |
713 | * | |
714 | * trace_buf = per_cpu_ptr(trace_buf, __cpu); | |
715 | * | |
716 | * // Avoid recursion from perf that could mess up the buffer | |
717 | * if (trace_buf->recursion++) | |
718 | * goto end_recursion; | |
719 | * | |
720 | * raw_data = trace_buf->buf; | |
721 | * | |
722 | * // Make recursion update visible before entering perf_tp_event | |
723 | * // so that we protect from perf recursions. | |
724 | * | |
725 | * barrier(); | |
726 | * | |
727 | * //zero dead bytes from alignment to avoid stack leak to userspace: | |
728 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; | |
729 | * entry = (struct ftrace_raw_<call> *)raw_data; | |
730 | * ent = &entry->ent; | |
731 | * tracing_generic_entry_update(ent, irq_flags, pc); | |
732 | * ent->type = event_call->id; | |
733 | * | |
734 | * <tstruct> <- do some jobs with dynamic arrays | |
735 | * | |
736 | * <assign> <- affect our values | |
737 | * | |
738 | * perf_tp_event(event_call->id, __addr, __count, entry, | |
739 | * __entry_size); <- submit them to perf counter | |
740 | * | |
741 | * } | |
742 | */ | |
743 | ||
744 | #ifdef CONFIG_PERF_EVENTS | |
745 | ||
746 | #undef __entry | |
747 | #define __entry entry | |
748 | ||
749 | #undef __get_dynamic_array | |
750 | #define __get_dynamic_array(field) \ | |
751 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) | |
752 | ||
753 | #undef __get_str | |
754 | #define __get_str(field) (char *)__get_dynamic_array(field) | |
755 | ||
756 | #undef __perf_addr | |
757 | #define __perf_addr(a) __addr = (a) | |
758 | ||
759 | #undef __perf_count | |
760 | #define __perf_count(c) __count = (c) | |
761 | ||
762 | #undef DECLARE_EVENT_CLASS | |
763 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
764 | static notrace void \ | |
765 | perf_trace_##call(void *__data, proto) \ | |
766 | { \ | |
767 | struct ftrace_event_call *event_call = __data; \ | |
768 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | |
769 | struct ftrace_raw_##call *entry; \ | |
770 | struct pt_regs __regs; \ | |
771 | u64 __addr = 0, __count = 1; \ | |
772 | struct hlist_head *head; \ | |
773 | int __entry_size; \ | |
774 | int __data_size; \ | |
775 | int rctx; \ | |
776 | \ | |
777 | perf_fetch_caller_regs(&__regs); \ | |
778 | \ | |
779 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | |
780 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ | |
781 | sizeof(u64)); \ | |
782 | __entry_size -= sizeof(u32); \ | |
783 | \ | |
784 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ | |
785 | "profile buffer not large enough")) \ | |
786 | return; \ | |
787 | \ | |
788 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ | |
789 | __entry_size, event_call->event.type, &__regs, &rctx); \ | |
790 | if (!entry) \ | |
791 | return; \ | |
792 | \ | |
793 | tstruct \ | |
794 | \ | |
795 | { assign; } \ | |
796 | \ | |
797 | head = this_cpu_ptr(event_call->perf_events); \ | |
798 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ | |
799 | __count, &__regs, head); \ | |
800 | } | |
801 | ||
802 | /* | |
803 | * This part is compiled out, it is only here as a build time check | |
804 | * to make sure that if the tracepoint handling changes, the | |
805 | * perf probe will fail to compile unless it too is updated. | |
806 | */ | |
807 | #undef DEFINE_EVENT | |
808 | #define DEFINE_EVENT(template, call, proto, args) \ | |
809 | static inline void perf_test_probe_##call(void) \ | |
810 | { \ | |
811 | check_trace_callback_type_##call(perf_trace_##template); \ | |
812 | } | |
813 | ||
814 | ||
815 | #undef DEFINE_EVENT_PRINT | |
816 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
817 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
818 | ||
819 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
820 | #endif /* CONFIG_PERF_EVENTS */ | |
821 | ||
822 | #undef _TRACE_PROFILE_INIT | |
1d12cebd | 823 | #endif //0 |