Commit | Line | Data |
---|---|---|
40652b65 | 1 | #include <lttng.h> |
299338c8 | 2 | #include <lttng-types.h> |
d0dd2ecb | 3 | #include <linux/debugfs.h> |
e763dbf5 MD |
4 | #include <linux/ringbuffer/frontend_types.h> |
5 | #include "../ltt-events.h" | |
6db3d13b | 6 | #include "../ltt-tracer-core.h" |
40652b65 | 7 | |
299338c8 MD |
8 | struct lttng_event_field { |
9 | const char *name; | |
10 | const struct lttng_type type; | |
11 | }; | |
12 | ||
13 | struct lttng_event_desc { | |
14 | const struct lttng_event_field *fields; | |
d0dd2ecb MD |
15 | const char *name; |
16 | unsigned int nr_fields; | |
299338c8 | 17 | }; |
40652b65 MD |
18 | |
19 | /* | |
6db3d13b | 20 | * Macro declarations used for all stages. |
40652b65 MD |
21 | */ |
22 | ||
23 | /* | |
24 | * DECLARE_EVENT_CLASS can be used to add a generic function | |
25 | * handlers for events. That is, if all events have the same | |
26 | * parameters and just have distinct trace points. | |
27 | * Each tracepoint can be defined with DEFINE_EVENT and that | |
28 | * will map the DECLARE_EVENT_CLASS to the tracepoint. | |
29 | * | |
30 | * TRACE_EVENT is a one to one mapping between tracepoint and template. | |
31 | */ | |
6db3d13b | 32 | |
40652b65 MD |
33 | #undef TRACE_EVENT |
34 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
35 | DECLARE_EVENT_CLASS(name, \ | |
36 | PARAMS(proto), \ | |
37 | PARAMS(args), \ | |
38 | PARAMS(tstruct), \ | |
39 | PARAMS(assign), \ | |
299338c8 MD |
40 | PARAMS(print)) \ |
41 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)) | |
40652b65 | 42 | |
6db3d13b MD |
43 | #undef DEFINE_EVENT_PRINT |
44 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
45 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
46 | ||
47 | /* Callbacks are meaningless to LTTng. */ | |
48 | #undef TRACE_EVENT_FN | |
49 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ | |
50 | assign, print, reg, unreg) \ | |
51 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ | |
52 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ | |
53 | ||
54 | /* | |
55 | * Stage 1 of the trace events. | |
56 | * | |
57 | * Create event field type metadata section. | |
58 | * Each event produce an array of fields. | |
59 | */ | |
60 | ||
61 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
62 | ||
1d12cebd MD |
63 | /* Named field types must be defined in lttng-types.h */ |
64 | ||
40652b65 | 65 | #undef __field |
299338c8 MD |
66 | #define __field(_type, _item) \ |
67 | { .name = #_item, .type = { .atype = atype_integer, .name = #_type} }, | |
40652b65 MD |
68 | |
69 | #undef __field_ext | |
6db3d13b | 70 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) |
40652b65 MD |
71 | |
72 | #undef __array | |
299338c8 MD |
73 | #define __array(_type, _item, _length) \ |
74 | { \ | |
75 | .name = #_item, \ | |
76 | .type = { \ | |
77 | .atype = atype_array, \ | |
78 | .name = NULL, \ | |
79 | .u.array.elem_type = #_type, \ | |
80 | .u.array.length = _length, \ | |
81 | }, \ | |
82 | }, | |
40652b65 MD |
83 | |
84 | #undef __dynamic_array | |
299338c8 MD |
85 | #define __dynamic_array(_type, _item, _length) \ |
86 | { \ | |
87 | .name = #_item, \ | |
88 | .type = { \ | |
89 | .atype = atype_sequence, \ | |
90 | .name = NULL, \ | |
91 | .u.sequence.elem_type = #_type, \ | |
92 | .u.sequence.length_type = "u32", \ | |
93 | }, \ | |
94 | }, | |
40652b65 MD |
95 | |
96 | #undef __string | |
1d12cebd | 97 | #define __string(_item, _src) \ |
299338c8 | 98 | { \ |
0d1d4002 | 99 | .name = #_item, \ |
299338c8 MD |
100 | .type = { \ |
101 | .atype = atype_string, \ | |
102 | .name = NULL, \ | |
103 | .u.string.encoding = lttng_encode_UTF8, \ | |
104 | }, \ | |
105 | }, | |
1d12cebd | 106 | |
40652b65 | 107 | #undef TP_STRUCT__entry |
1d12cebd MD |
108 | #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ |
109 | ||
40652b65 | 110 | #undef DECLARE_EVENT_CLASS |
0d1d4002 MD |
111 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
112 | static const struct lttng_event_field __event_fields___##_name[] = { \ | |
113 | _tstruct \ | |
299338c8 MD |
114 | }; |
115 | ||
299338c8 MD |
116 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
117 | ||
118 | /* | |
119 | * Stage 2 of the trace events. | |
120 | * | |
121 | * Create an array of events. | |
122 | */ | |
123 | ||
299338c8 MD |
124 | /* Named field types must be defined in lttng-types.h */ |
125 | ||
6db3d13b | 126 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
299338c8 | 127 | |
d32a57a2 MD |
128 | #undef DEFINE_EVENT |
129 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ | |
130 | { \ | |
131 | .fields = __event_fields___##_template, \ | |
132 | .name = #_name, \ | |
133 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ | |
6db3d13b | 134 | }, |
40652b65 | 135 | |
d0dd2ecb MD |
136 | #define TP_ID1(_token, _system) _token##_system |
137 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
40652b65 | 138 | |
d0dd2ecb | 139 | static const struct lttng_event_desc TP_ID(__event_desc___, TRACE_SYSTEM)[] = { |
40652b65 | 140 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
299338c8 MD |
141 | }; |
142 | ||
d0dd2ecb MD |
143 | #undef TP_ID1 |
144 | #undef TP_ID | |
145 | ||
146 | /* | |
147 | * Stage 3 of the trace events. | |
148 | * | |
149 | * Create seq file metadata output. | |
150 | */ | |
151 | ||
d0dd2ecb MD |
152 | #define TP_ID1(_token, _system) _token##_system |
153 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
154 | #define module_init_eval1(_token, _system) module_init(_token##_system) | |
155 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) | |
156 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) | |
157 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) | |
158 | ||
159 | static void *TP_ID(__lttng_seq_start__, TRACE_SYSTEM)(struct seq_file *m, | |
160 | loff_t *pos) | |
161 | { | |
6db3d13b MD |
162 | const struct lttng_event_desc *desc = |
163 | &TP_ID(__event_desc___, TRACE_SYSTEM)[*pos]; | |
d0dd2ecb | 164 | |
6db3d13b MD |
165 | if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM) |
166 | [ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1]) | |
d0dd2ecb MD |
167 | return NULL; |
168 | return (void *) desc; | |
169 | } | |
170 | ||
171 | static void *TP_ID(__lttng_seq_next__, TRACE_SYSTEM)(struct seq_file *m, | |
172 | void *p, loff_t *ppos) | |
173 | { | |
6db3d13b MD |
174 | const struct lttng_event_desc *desc = |
175 | &TP_ID(__event_desc___, TRACE_SYSTEM)[++(*ppos)]; | |
d0dd2ecb | 176 | |
6db3d13b MD |
177 | if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM) |
178 | [ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1]) | |
d0dd2ecb MD |
179 | return NULL; |
180 | return (void *) desc; | |
181 | } | |
182 | ||
183 | static void TP_ID(__lttng_seq_stop__, TRACE_SYSTEM)(struct seq_file *m, | |
184 | void *p) | |
185 | { | |
186 | } | |
187 | ||
188 | static int TP_ID(__lttng_seq_show__, TRACE_SYSTEM)(struct seq_file *m, | |
189 | void *p) | |
190 | { | |
191 | const struct lttng_event_desc *desc = p; | |
192 | int i; | |
193 | ||
194 | seq_printf(m, "event {\n" | |
195 | "\tname = %s;\n" | |
196 | "\tid = UNKNOWN;\n" | |
197 | "\tstream = UNKNOWN;\n" | |
198 | "\tfields = {\n", | |
199 | desc->name); | |
200 | for (i = 0; i < desc->nr_fields; i++) { | |
201 | if (desc->fields[i].type.name) /* Named type */ | |
202 | seq_printf(m, "\t\t%s", | |
203 | desc->fields[i].type.name); | |
204 | else /* Nameless type */ | |
205 | lttng_print_event_type(m, 2, &desc->fields[i].type); | |
206 | seq_printf(m, " %s;\n", desc->fields[i].name); | |
207 | } | |
208 | seq_printf(m, "\t};\n"); | |
209 | seq_printf(m, "};\n"); | |
210 | return 0; | |
211 | } | |
212 | ||
213 | static const | |
214 | struct seq_operations TP_ID(__lttng_types_seq_ops__, TRACE_SYSTEM) = { | |
215 | .start = TP_ID(__lttng_seq_start__, TRACE_SYSTEM), | |
216 | .next = TP_ID(__lttng_seq_next__, TRACE_SYSTEM), | |
217 | .stop = TP_ID(__lttng_seq_stop__, TRACE_SYSTEM), | |
218 | .show = TP_ID(__lttng_seq_show__, TRACE_SYSTEM), | |
219 | }; | |
220 | ||
221 | static int | |
222 | TP_ID(__lttng_types_open__, TRACE_SYSTEM)(struct inode *inode, struct file *file) | |
223 | { | |
224 | return seq_open(file, &TP_ID(__lttng_types_seq_ops__, TRACE_SYSTEM)); | |
225 | } | |
226 | ||
6db3d13b MD |
227 | static const |
228 | struct file_operations TP_ID(__lttng_types_fops__, TRACE_SYSTEM) = { | |
d0dd2ecb MD |
229 | .open = TP_ID(__lttng_types_open__, TRACE_SYSTEM), |
230 | .read = seq_read, | |
231 | .llseek = seq_lseek, | |
232 | .release = seq_release_private, | |
233 | }; | |
234 | ||
235 | static struct dentry *TP_ID(__lttng_types_dentry__, TRACE_SYSTEM); | |
236 | ||
237 | static int TP_ID(__lttng_types_init__, TRACE_SYSTEM)(void) | |
238 | { | |
239 | int ret = 0; | |
240 | ||
241 | TP_ID(__lttng_types_dentry__, TRACE_SYSTEM) = | |
6db3d13b MD |
242 | debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM), |
243 | S_IWUSR, NULL, NULL, | |
244 | &TP_ID(__lttng_types_fops__, TRACE_SYSTEM)); | |
d0dd2ecb MD |
245 | if (IS_ERR(TP_ID(__lttng_types_dentry__, TRACE_SYSTEM)) |
246 | || !TP_ID(__lttng_types_dentry__, TRACE_SYSTEM)) { | |
247 | printk(KERN_ERR "Error creating LTTng type export file\n"); | |
248 | ret = -ENOMEM; | |
249 | goto error; | |
250 | } | |
251 | error: | |
252 | return ret; | |
253 | } | |
254 | ||
255 | module_init_eval(__lttng_types_init__, TRACE_SYSTEM); | |
256 | ||
257 | static void TP_ID(__lttng_types_exit__, TRACE_SYSTEM)(void) | |
258 | { | |
259 | debugfs_remove(TP_ID(__lttng_types_dentry__, TRACE_SYSTEM)); | |
260 | } | |
261 | ||
262 | module_exit_eval(__lttng_types_exit__, TRACE_SYSTEM); | |
263 | ||
264 | #undef module_init_eval | |
265 | #undef module_exit_eval | |
266 | #undef TP_ID1 | |
267 | #undef TP_ID | |
268 | ||
40652b65 | 269 | /* |
6db3d13b | 270 | * Stage 4 of the trace events. |
40652b65 MD |
271 | * |
272 | * Create static inline function that calculates event size. | |
273 | */ | |
274 | ||
6db3d13b | 275 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
40652b65 | 276 | |
6db3d13b MD |
277 | /* Named field types must be defined in lttng-types.h */ |
278 | ||
279 | #undef __field | |
0d1d4002 MD |
280 | #define __field(_type, _item) \ |
281 | __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \ | |
282 | __event_len += sizeof(_type); | |
6db3d13b MD |
283 | |
284 | #undef __field_ext | |
285 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) | |
286 | ||
287 | #undef __array | |
0d1d4002 MD |
288 | #define __array(_type, _item, _length) \ |
289 | __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \ | |
290 | __event_len += sizeof(_type) * (_length); | |
6db3d13b MD |
291 | |
292 | #undef __dynamic_array | |
0d1d4002 MD |
293 | #define __dynamic_array(_type, _item, _length) \ |
294 | __event_len += lib_ring_buffer_align(__event_len, sizeof(u32)); \ | |
295 | __event_len += sizeof(u32); \ | |
296 | __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \ | |
297 | __event_len += sizeof(_type) * (_length); | |
6db3d13b MD |
298 | |
299 | #undef __string | |
300 | #define __string(_item, _src) \ | |
0d1d4002 MD |
301 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
302 | ||
303 | #undef TP_PROTO | |
304 | #define TP_PROTO(args...) args | |
6db3d13b MD |
305 | |
306 | #undef TP_STRUCT__entry | |
0d1d4002 | 307 | #define TP_STRUCT__entry(args...) args |
6db3d13b MD |
308 | |
309 | #undef DECLARE_EVENT_CLASS | |
0d1d4002 MD |
310 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
311 | static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ | |
312 | { \ | |
313 | size_t __event_len = 0; \ | |
314 | unsigned int __dynamic_len_idx = 0; \ | |
315 | \ | |
316 | if (0) \ | |
317 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
318 | _tstruct \ | |
319 | return __event_len; \ | |
6db3d13b | 320 | } |
40652b65 MD |
321 | |
322 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
323 | ||
6db3d13b | 324 | |
6db3d13b | 325 | |
40652b65 | 326 | /* |
e763dbf5 MD |
327 | * Stage 5 of the trace events. |
328 | * | |
329 | * Create static inline function that calculates event payload alignment. | |
330 | */ | |
331 | ||
332 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
333 | ||
334 | /* Named field types must be defined in lttng-types.h */ | |
335 | ||
336 | #undef __field | |
337 | #define __field(_type, _item) \ | |
338 | __event_align = max_t(size_t, __event_align, sizeof(_type)); | |
339 | ||
340 | #undef __field_ext | |
341 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) | |
342 | ||
343 | #undef __array | |
344 | #define __array(_type, _item, _length) \ | |
345 | __event_align = max_t(size_t, __event_align, sizeof(_type)); | |
346 | ||
347 | #undef __dynamic_array | |
348 | #define __dynamic_array(_type, _item, _length) \ | |
349 | __event_align = max_t(size_t, __event_align, sizeof(u32)); \ | |
350 | __event_align = max_t(size_t, __event_align, sizeof(_type)); | |
351 | ||
352 | #undef __string | |
353 | #define __string(_item, _src) | |
354 | ||
355 | #undef TP_PROTO | |
356 | #define TP_PROTO(args...) args | |
357 | ||
358 | #undef TP_STRUCT__entry | |
359 | #define TP_STRUCT__entry(args...) args | |
360 | ||
361 | #undef DECLARE_EVENT_CLASS | |
362 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
363 | static inline size_t __event_get_align__##_name(_proto) \ | |
364 | { \ | |
365 | size_t __event_align = 1; \ | |
366 | _tstruct \ | |
367 | return __event_align; \ | |
368 | } | |
369 | ||
370 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
371 | ||
372 | ||
373 | ||
374 | /* | |
375 | * Stage 6 of the trace events. | |
40652b65 MD |
376 | * |
377 | * Create the probe function : call even size calculation and write event data | |
378 | * into the buffer. | |
e763dbf5 MD |
379 | * |
380 | * Note: the order of fields in TP_fast_assign and TP_STRUCT__entry must be the | |
381 | * same. | |
40652b65 MD |
382 | */ |
383 | ||
e763dbf5 MD |
384 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
385 | ||
386 | #undef __field | |
387 | #define __field(_type, _item) \ | |
388 | lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \ | |
389 | goto __assign_##_item; \ | |
390 | __end_field_##_item: | |
40652b65 | 391 | |
e763dbf5 MD |
392 | #undef __field_ext |
393 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) | |
40652b65 | 394 | |
e763dbf5 MD |
395 | #undef __array |
396 | #define __array(_type, _item, _length) \ | |
397 | lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \ | |
398 | goto __assign_##_item; \ | |
399 | __end_field_##_item: | |
40652b65 | 400 | |
e763dbf5 MD |
401 | #undef __dynamic_array |
402 | #define __dynamic_array(_type, _item, _length) \ | |
403 | lib_ring_buffer_align_ctx(&ctx, sizeof(u32)); \ | |
404 | goto __assign_##_item##_1; \ | |
405 | __end_field_##_item##_1: \ | |
406 | lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \ | |
407 | goto __assign_##_item##_2; \ | |
408 | __end_field_##_item##_2: | |
40652b65 | 409 | |
e763dbf5 MD |
410 | #undef __string |
411 | #define __string(_item, _src) \ | |
412 | goto __assign_##_item; \ | |
413 | __end_field_##_item: | |
414 | ||
415 | /* | |
416 | * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to | |
417 | * strcpy(). | |
418 | */ | |
419 | #undef tp_assign | |
420 | #define tp_assign(dest, src) \ | |
421 | __assign_##dest: \ | |
422 | { \ | |
423 | __typeof__(src) __tmp = (src); \ | |
424 | __chan->ops->event_write(&ctx, &__tmp, sizeof(src)); \ | |
425 | } \ | |
426 | goto __end_field_##dest; | |
427 | ||
428 | #undef tp_memcpy | |
429 | #define tp_memcpy(dest, src, len) \ | |
430 | __assign_##dest: \ | |
431 | __chan->ops->event_write(&ctx, src, len); \ | |
432 | goto __end_field_##dest; | |
433 | ||
434 | #undef tp_memcpy_dyn | |
435 | #define tp_memcpy_dyn(dest, src, len) \ | |
436 | __assign_##dest##_1: \ | |
437 | { \ | |
438 | __typeof__(len) __tmpl = (len); \ | |
439 | __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \ | |
440 | } \ | |
441 | goto __end_field_##dest##_1; \ | |
442 | __assign_##dest##_2: \ | |
443 | __chan->ops->event_write(&ctx, src, len); \ | |
444 | goto __end_field_##dest##_2; | |
445 | ||
446 | #undef tp_strcpy | |
447 | #define tp_strcpy(dest, src) \ | |
448 | tp_memcpy(dest, src, __get_dynamic_array_len(dest)); \ | |
40652b65 | 449 | |
e763dbf5 MD |
450 | /* Named field types must be defined in lttng-types.h */ |
451 | ||
452 | #undef __get_str | |
453 | #define __get_str(field) field | |
454 | ||
455 | #undef __get_dynamic_array | |
456 | #define __get_dynamic_array(field) field | |
457 | ||
458 | /* Beware: this get len actually consumes the len value */ | |
459 | #undef __get_dynamic_array_len | |
460 | #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++] | |
461 | ||
462 | #undef TP_PROTO | |
463 | #define TP_PROTO(args...) args | |
464 | ||
465 | #undef TP_ARGS | |
466 | #define TP_ARGS(args...) args | |
467 | ||
468 | #undef TP_STRUCT__entry | |
469 | #define TP_STRUCT__entry(args...) args | |
470 | ||
471 | #undef TP_fast_assign | |
472 | #define TP_fast_assign(args...) args | |
473 | ||
474 | #undef DECLARE_EVENT_CLASS | |
475 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
476 | static void __event_probe__##_name(void *__data, _proto) \ | |
477 | { \ | |
478 | struct ltt_event *__event = __data; \ | |
479 | struct ltt_channel *__chan = __event->chan; \ | |
480 | struct lib_ring_buffer_ctx ctx; \ | |
481 | size_t __event_len, __event_align; \ | |
482 | size_t __dynamic_len_idx = 0; \ | |
483 | size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \ | |
484 | int __ret; \ | |
485 | \ | |
486 | if (0) \ | |
487 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
488 | __event_len = __event_get_size__##_name(__dynamic_len, _args); \ | |
489 | __event_align = __event_get_align__##_name(_args); \ | |
490 | lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \ | |
491 | __event_align, -1); \ | |
492 | __ret = __chan->ops->event_reserve(&ctx); \ | |
493 | if (__ret < 0) \ | |
494 | return; \ | |
495 | /* Control code (field ordering) */ \ | |
496 | _tstruct \ | |
497 | __chan->ops->event_commit(&ctx); \ | |
498 | return; \ | |
499 | /* Copy code, steered by control code */ \ | |
500 | _assign \ | |
501 | } | |
502 | ||
503 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
504 | ||
505 | ||
506 | #if 0 | |
40652b65 MD |
507 | |
508 | #include <linux/ftrace_event.h> | |
509 | ||
510 | /* | |
511 | * DECLARE_EVENT_CLASS can be used to add a generic function | |
512 | * handlers for events. That is, if all events have the same | |
513 | * parameters and just have distinct trace points. | |
514 | * Each tracepoint can be defined with DEFINE_EVENT and that | |
515 | * will map the DECLARE_EVENT_CLASS to the tracepoint. | |
516 | * | |
517 | * TRACE_EVENT is a one to one mapping between tracepoint and template. | |
518 | */ | |
519 | #undef TRACE_EVENT | |
520 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
521 | DECLARE_EVENT_CLASS(name, \ | |
522 | PARAMS(proto), \ | |
523 | PARAMS(args), \ | |
524 | PARAMS(tstruct), \ | |
525 | PARAMS(assign), \ | |
526 | PARAMS(print)); \ | |
527 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); | |
528 | ||
529 | ||
530 | #undef __field | |
531 | #define __field(type, item) type item; | |
532 | ||
533 | #undef __field_ext | |
534 | #define __field_ext(type, item, filter_type) type item; | |
535 | ||
536 | #undef __array | |
537 | #define __array(type, item, len) type item[len]; | |
538 | ||
539 | #undef __dynamic_array | |
540 | #define __dynamic_array(type, item, len) u32 __data_loc_##item; | |
541 | ||
542 | #undef __string | |
543 | #define __string(item, src) __dynamic_array(char, item, -1) | |
544 | ||
545 | #undef TP_STRUCT__entry | |
546 | #define TP_STRUCT__entry(args...) args | |
547 | ||
548 | #undef DECLARE_EVENT_CLASS | |
549 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ | |
550 | struct ftrace_raw_##name { \ | |
551 | struct trace_entry ent; \ | |
552 | tstruct \ | |
553 | char __data[0]; \ | |
554 | }; \ | |
555 | \ | |
556 | static struct ftrace_event_class event_class_##name; | |
557 | ||
558 | #undef DEFINE_EVENT | |
559 | #define DEFINE_EVENT(template, name, proto, args) \ | |
560 | static struct ftrace_event_call __used \ | |
561 | __attribute__((__aligned__(4))) event_##name | |
562 | ||
563 | #undef DEFINE_EVENT_PRINT | |
564 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
565 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
566 | ||
567 | /* Callbacks are meaningless to ftrace. */ | |
568 | #undef TRACE_EVENT_FN | |
569 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ | |
570 | assign, print, reg, unreg) \ | |
571 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ | |
572 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ | |
573 | ||
574 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
575 | ||
576 | ||
577 | /* | |
578 | * Stage 2 of the trace events. | |
579 | * | |
580 | * Create static inline function that calculates event size. | |
581 | */ | |
582 | ||
583 | #undef __field | |
584 | #define __field(type, item) | |
585 | ||
586 | #undef __field_ext | |
587 | #define __field_ext(type, item, filter_type) | |
588 | ||
589 | #undef __array | |
590 | #define __array(type, item, len) | |
591 | ||
592 | #undef __dynamic_array | |
593 | #define __dynamic_array(type, item, len) u32 item; | |
594 | ||
595 | #undef __string | |
596 | #define __string(item, src) __dynamic_array(char, item, -1) | |
597 | ||
598 | #undef DECLARE_EVENT_CLASS | |
599 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
600 | struct ftrace_data_offsets_##call { \ | |
601 | tstruct; \ | |
602 | }; | |
603 | ||
604 | #undef DEFINE_EVENT | |
605 | #define DEFINE_EVENT(template, name, proto, args) | |
606 | ||
607 | #undef DEFINE_EVENT_PRINT | |
608 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
609 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
610 | ||
611 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
612 | ||
613 | /* | |
614 | * Stage 3 of the trace events. | |
615 | * | |
616 | * Create the probe function : call even size calculation and write event data | |
617 | * into the buffer. | |
618 | */ | |
619 | ||
620 | #undef __entry | |
621 | #define __entry field | |
622 | ||
623 | #undef TP_printk | |
624 | #define TP_printk(fmt, args...) fmt "\n", args | |
625 | ||
626 | #undef __get_dynamic_array | |
627 | #define __get_dynamic_array(field) \ | |
628 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) | |
629 | ||
630 | #undef __get_str | |
631 | #define __get_str(field) (char *)__get_dynamic_array(field) | |
632 | ||
633 | #undef __print_flags | |
634 | #define __print_flags(flag, delim, flag_array...) \ | |
635 | ({ \ | |
636 | static const struct trace_print_flags __flags[] = \ | |
637 | { flag_array, { -1, NULL }}; \ | |
638 | ftrace_print_flags_seq(p, delim, flag, __flags); \ | |
639 | }) | |
640 | ||
641 | #undef __print_symbolic | |
642 | #define __print_symbolic(value, symbol_array...) \ | |
643 | ({ \ | |
644 | static const struct trace_print_flags symbols[] = \ | |
645 | { symbol_array, { -1, NULL }}; \ | |
646 | ftrace_print_symbols_seq(p, value, symbols); \ | |
647 | }) | |
648 | ||
649 | #undef __print_hex | |
650 | #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len) | |
651 | ||
652 | #undef DECLARE_EVENT_CLASS | |
653 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
654 | static notrace enum print_line_t \ | |
655 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ | |
656 | struct trace_event *trace_event) \ | |
657 | { \ | |
658 | struct ftrace_event_call *event; \ | |
659 | struct trace_seq *s = &iter->seq; \ | |
660 | struct ftrace_raw_##call *field; \ | |
661 | struct trace_entry *entry; \ | |
662 | struct trace_seq *p = &iter->tmp_seq; \ | |
663 | int ret; \ | |
664 | \ | |
665 | event = container_of(trace_event, struct ftrace_event_call, \ | |
666 | event); \ | |
667 | \ | |
668 | entry = iter->ent; \ | |
669 | \ | |
670 | if (entry->type != event->event.type) { \ | |
671 | WARN_ON_ONCE(1); \ | |
672 | return TRACE_TYPE_UNHANDLED; \ | |
673 | } \ | |
674 | \ | |
675 | field = (typeof(field))entry; \ | |
676 | \ | |
677 | trace_seq_init(p); \ | |
678 | ret = trace_seq_printf(s, "%s: ", event->name); \ | |
679 | if (ret) \ | |
680 | ret = trace_seq_printf(s, print); \ | |
681 | if (!ret) \ | |
682 | return TRACE_TYPE_PARTIAL_LINE; \ | |
683 | \ | |
684 | return TRACE_TYPE_HANDLED; \ | |
685 | } \ | |
686 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
687 | .trace = ftrace_raw_output_##call, \ | |
688 | }; | |
689 | ||
690 | #undef DEFINE_EVENT_PRINT | |
691 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | |
692 | static notrace enum print_line_t \ | |
693 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ | |
694 | struct trace_event *event) \ | |
695 | { \ | |
696 | struct trace_seq *s = &iter->seq; \ | |
697 | struct ftrace_raw_##template *field; \ | |
698 | struct trace_entry *entry; \ | |
699 | struct trace_seq *p = &iter->tmp_seq; \ | |
700 | int ret; \ | |
701 | \ | |
702 | entry = iter->ent; \ | |
703 | \ | |
704 | if (entry->type != event_##call.event.type) { \ | |
705 | WARN_ON_ONCE(1); \ | |
706 | return TRACE_TYPE_UNHANDLED; \ | |
707 | } \ | |
708 | \ | |
709 | field = (typeof(field))entry; \ | |
710 | \ | |
711 | trace_seq_init(p); \ | |
712 | ret = trace_seq_printf(s, "%s: ", #call); \ | |
713 | if (ret) \ | |
714 | ret = trace_seq_printf(s, print); \ | |
715 | if (!ret) \ | |
716 | return TRACE_TYPE_PARTIAL_LINE; \ | |
717 | \ | |
718 | return TRACE_TYPE_HANDLED; \ | |
719 | } \ | |
720 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
721 | .trace = ftrace_raw_output_##call, \ | |
722 | }; | |
723 | ||
724 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
725 | ||
726 | #undef __field_ext | |
727 | #define __field_ext(type, item, filter_type) \ | |
728 | ret = trace_define_field(event_call, #type, #item, \ | |
729 | offsetof(typeof(field), item), \ | |
730 | sizeof(field.item), \ | |
731 | is_signed_type(type), filter_type); \ | |
732 | if (ret) \ | |
733 | return ret; | |
734 | ||
735 | #undef __field | |
736 | #define __field(type, item) __field_ext(type, item, FILTER_OTHER) | |
737 | ||
738 | #undef __array | |
739 | #define __array(type, item, len) \ | |
740 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ | |
741 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ | |
742 | offsetof(typeof(field), item), \ | |
743 | sizeof(field.item), \ | |
744 | is_signed_type(type), FILTER_OTHER); \ | |
745 | if (ret) \ | |
746 | return ret; | |
747 | ||
748 | #undef __dynamic_array | |
749 | #define __dynamic_array(type, item, len) \ | |
750 | ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \ | |
751 | offsetof(typeof(field), __data_loc_##item), \ | |
752 | sizeof(field.__data_loc_##item), \ | |
753 | is_signed_type(type), FILTER_OTHER); | |
754 | ||
755 | #undef __string | |
756 | #define __string(item, src) __dynamic_array(char, item, -1) | |
757 | ||
758 | #undef DECLARE_EVENT_CLASS | |
759 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ | |
760 | static int notrace \ | |
761 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ | |
762 | { \ | |
763 | struct ftrace_raw_##call field; \ | |
764 | int ret; \ | |
765 | \ | |
766 | tstruct; \ | |
767 | \ | |
768 | return ret; \ | |
769 | } | |
770 | ||
771 | #undef DEFINE_EVENT | |
772 | #define DEFINE_EVENT(template, name, proto, args) | |
773 | ||
774 | #undef DEFINE_EVENT_PRINT | |
775 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
776 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
777 | ||
778 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
779 | ||
780 | /* | |
781 | * remember the offset of each array from the beginning of the event. | |
782 | */ | |
783 | ||
784 | #undef __entry | |
785 | #define __entry entry | |
786 | ||
787 | #undef __field | |
788 | #define __field(type, item) | |
789 | ||
790 | #undef __field_ext | |
791 | #define __field_ext(type, item, filter_type) | |
792 | ||
793 | #undef __array | |
794 | #define __array(type, item, len) | |
795 | ||
796 | #undef __dynamic_array | |
797 | #define __dynamic_array(type, item, len) \ | |
798 | __data_offsets->item = __data_size + \ | |
799 | offsetof(typeof(*entry), __data); \ | |
800 | __data_offsets->item |= (len * sizeof(type)) << 16; \ | |
801 | __data_size += (len) * sizeof(type); | |
802 | ||
803 | #undef __string | |
804 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) | |
805 | ||
806 | #undef DECLARE_EVENT_CLASS | |
807 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
808 | static inline notrace int ftrace_get_offsets_##call( \ | |
809 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ | |
810 | { \ | |
811 | int __data_size = 0; \ | |
812 | struct ftrace_raw_##call __maybe_unused *entry; \ | |
813 | \ | |
814 | tstruct; \ | |
815 | \ | |
816 | return __data_size; \ | |
817 | } | |
818 | ||
819 | #undef DEFINE_EVENT | |
820 | #define DEFINE_EVENT(template, name, proto, args) | |
821 | ||
822 | #undef DEFINE_EVENT_PRINT | |
823 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
824 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
825 | ||
826 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
827 | ||
828 | /* | |
829 | * Stage 4 of the trace events. | |
830 | * | |
831 | * Override the macros in <trace/trace_events.h> to include the following: | |
832 | * | |
833 | * For those macros defined with TRACE_EVENT: | |
834 | * | |
835 | * static struct ftrace_event_call event_<call>; | |
836 | * | |
837 | * static void ftrace_raw_event_<call>(void *__data, proto) | |
838 | * { | |
839 | * struct ftrace_event_call *event_call = __data; | |
840 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | |
841 | * struct ring_buffer_event *event; | |
842 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | |
843 | * struct ring_buffer *buffer; | |
844 | * unsigned long irq_flags; | |
845 | * int __data_size; | |
846 | * int pc; | |
847 | * | |
848 | * local_save_flags(irq_flags); | |
849 | * pc = preempt_count(); | |
850 | * | |
851 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | |
852 | * | |
853 | * event = trace_current_buffer_lock_reserve(&buffer, | |
854 | * event_<call>->event.type, | |
855 | * sizeof(*entry) + __data_size, | |
856 | * irq_flags, pc); | |
857 | * if (!event) | |
858 | * return; | |
859 | * entry = ring_buffer_event_data(event); | |
860 | * | |
861 | * { <assign>; } <-- Here we assign the entries by the __field and | |
862 | * __array macros. | |
863 | * | |
864 | * if (!filter_current_check_discard(buffer, event_call, entry, event)) | |
865 | * trace_current_buffer_unlock_commit(buffer, | |
866 | * event, irq_flags, pc); | |
867 | * } | |
868 | * | |
869 | * static struct trace_event ftrace_event_type_<call> = { | |
870 | * .trace = ftrace_raw_output_<call>, <-- stage 2 | |
871 | * }; | |
872 | * | |
873 | * static const char print_fmt_<call>[] = <TP_printk>; | |
874 | * | |
875 | * static struct ftrace_event_class __used event_class_<template> = { | |
876 | * .system = "<system>", | |
877 | * .define_fields = ftrace_define_fields_<call>, | |
878 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), | |
879 | * .raw_init = trace_event_raw_init, | |
880 | * .probe = ftrace_raw_event_##call, | |
881 | * .reg = ftrace_event_reg, | |
882 | * }; | |
883 | * | |
884 | * static struct ftrace_event_call __used | |
885 | * __attribute__((__aligned__(4))) | |
886 | * __attribute__((section("_ftrace_events"))) event_<call> = { | |
887 | * .name = "<call>", | |
888 | * .class = event_class_<template>, | |
889 | * .event = &ftrace_event_type_<call>, | |
890 | * .print_fmt = print_fmt_<call>, | |
891 | * }; | |
892 | * | |
893 | */ | |
894 | ||
895 | #ifdef CONFIG_PERF_EVENTS | |
896 | ||
897 | #define _TRACE_PERF_PROTO(call, proto) \ | |
898 | static notrace void \ | |
899 | perf_trace_##call(void *__data, proto); | |
900 | ||
901 | #define _TRACE_PERF_INIT(call) \ | |
902 | .perf_probe = perf_trace_##call, | |
903 | ||
904 | #else | |
905 | #define _TRACE_PERF_PROTO(call, proto) | |
906 | #define _TRACE_PERF_INIT(call) | |
907 | #endif /* CONFIG_PERF_EVENTS */ | |
908 | ||
909 | #undef __entry | |
910 | #define __entry entry | |
911 | ||
912 | #undef __field | |
913 | #define __field(type, item) | |
914 | ||
915 | #undef __array | |
916 | #define __array(type, item, len) | |
917 | ||
918 | #undef __dynamic_array | |
919 | #define __dynamic_array(type, item, len) \ | |
920 | __entry->__data_loc_##item = __data_offsets.item; | |
921 | ||
922 | #undef __string | |
923 | #define __string(item, src) __dynamic_array(char, item, -1) \ | |
924 | ||
925 | #undef __assign_str | |
926 | #define __assign_str(dst, src) \ | |
927 | strcpy(__get_str(dst), src); | |
928 | ||
929 | #undef TP_fast_assign | |
930 | #define TP_fast_assign(args...) args | |
931 | ||
932 | #undef TP_perf_assign | |
933 | #define TP_perf_assign(args...) | |
934 | ||
935 | #undef DECLARE_EVENT_CLASS | |
936 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
937 | \ | |
938 | static notrace void \ | |
939 | ftrace_raw_event_##call(void *__data, proto) \ | |
940 | { \ | |
941 | struct ftrace_event_call *event_call = __data; \ | |
942 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | |
943 | struct ring_buffer_event *event; \ | |
944 | struct ftrace_raw_##call *entry; \ | |
945 | struct ring_buffer *buffer; \ | |
946 | unsigned long irq_flags; \ | |
947 | int __data_size; \ | |
948 | int pc; \ | |
949 | \ | |
950 | local_save_flags(irq_flags); \ | |
951 | pc = preempt_count(); \ | |
952 | \ | |
953 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | |
954 | \ | |
955 | event = trace_current_buffer_lock_reserve(&buffer, \ | |
956 | event_call->event.type, \ | |
957 | sizeof(*entry) + __data_size, \ | |
958 | irq_flags, pc); \ | |
959 | if (!event) \ | |
960 | return; \ | |
961 | entry = ring_buffer_event_data(event); \ | |
962 | \ | |
963 | tstruct \ | |
964 | \ | |
965 | { assign; } \ | |
966 | \ | |
967 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ | |
968 | trace_nowake_buffer_unlock_commit(buffer, \ | |
969 | event, irq_flags, pc); \ | |
970 | } | |
971 | /* | |
972 | * The ftrace_test_probe is compiled out, it is only here as a build time check | |
973 | * to make sure that if the tracepoint handling changes, the ftrace probe will | |
974 | * fail to compile unless it too is updated. | |
975 | */ | |
976 | ||
977 | #undef DEFINE_EVENT | |
978 | #define DEFINE_EVENT(template, call, proto, args) \ | |
979 | static inline void ftrace_test_probe_##call(void) \ | |
980 | { \ | |
981 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ | |
982 | } | |
983 | ||
984 | #undef DEFINE_EVENT_PRINT | |
985 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) | |
986 | ||
987 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
988 | ||
989 | #undef __entry | |
990 | #define __entry REC | |
991 | ||
992 | #undef __print_flags | |
993 | #undef __print_symbolic | |
994 | #undef __get_dynamic_array | |
995 | #undef __get_str | |
996 | ||
997 | #undef TP_printk | |
998 | #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) | |
999 | ||
1000 | #undef DECLARE_EVENT_CLASS | |
1001 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
1002 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ | |
1003 | static const char print_fmt_##call[] = print; \ | |
1004 | static struct ftrace_event_class __used event_class_##call = { \ | |
1005 | .system = __stringify(TRACE_SYSTEM), \ | |
1006 | .define_fields = ftrace_define_fields_##call, \ | |
1007 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ | |
1008 | .raw_init = trace_event_raw_init, \ | |
1009 | .probe = ftrace_raw_event_##call, \ | |
1010 | .reg = ftrace_event_reg, \ | |
1011 | _TRACE_PERF_INIT(call) \ | |
1012 | }; | |
1013 | ||
1014 | #undef DEFINE_EVENT | |
1015 | #define DEFINE_EVENT(template, call, proto, args) \ | |
1016 | \ | |
1017 | static struct ftrace_event_call __used \ | |
1018 | __attribute__((__aligned__(4))) \ | |
1019 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
1020 | .name = #call, \ | |
1021 | .class = &event_class_##template, \ | |
1022 | .event.funcs = &ftrace_event_type_funcs_##template, \ | |
1023 | .print_fmt = print_fmt_##template, \ | |
1024 | }; | |
1025 | ||
1026 | #undef DEFINE_EVENT_PRINT | |
1027 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | |
1028 | \ | |
1029 | static const char print_fmt_##call[] = print; \ | |
1030 | \ | |
1031 | static struct ftrace_event_call __used \ | |
1032 | __attribute__((__aligned__(4))) \ | |
1033 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
1034 | .name = #call, \ | |
1035 | .class = &event_class_##template, \ | |
1036 | .event.funcs = &ftrace_event_type_funcs_##call, \ | |
1037 | .print_fmt = print_fmt_##call, \ | |
1038 | } | |
1039 | ||
1040 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
1041 | ||
1042 | /* | |
1043 | * Define the insertion callback to perf events | |
1044 | * | |
1045 | * The job is very similar to ftrace_raw_event_<call> except that we don't | |
1046 | * insert in the ring buffer but in a perf counter. | |
1047 | * | |
1048 | * static void ftrace_perf_<call>(proto) | |
1049 | * { | |
1050 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | |
1051 | * struct ftrace_event_call *event_call = &event_<call>; | |
1052 | * extern void perf_tp_event(int, u64, u64, void *, int); | |
1053 | * struct ftrace_raw_##call *entry; | |
1054 | * struct perf_trace_buf *trace_buf; | |
1055 | * u64 __addr = 0, __count = 1; | |
1056 | * unsigned long irq_flags; | |
1057 | * struct trace_entry *ent; | |
1058 | * int __entry_size; | |
1059 | * int __data_size; | |
1060 | * int __cpu | |
1061 | * int pc; | |
1062 | * | |
1063 | * pc = preempt_count(); | |
1064 | * | |
1065 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | |
1066 | * | |
1067 | * // Below we want to get the aligned size by taking into account | |
1068 | * // the u32 field that will later store the buffer size | |
1069 | * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32), | |
1070 | * sizeof(u64)); | |
1071 | * __entry_size -= sizeof(u32); | |
1072 | * | |
1073 | * // Protect the non nmi buffer | |
1074 | * // This also protects the rcu read side | |
1075 | * local_irq_save(irq_flags); | |
1076 | * __cpu = smp_processor_id(); | |
1077 | * | |
1078 | * if (in_nmi()) | |
1079 | * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi); | |
1080 | * else | |
1081 | * trace_buf = rcu_dereference_sched(perf_trace_buf); | |
1082 | * | |
1083 | * if (!trace_buf) | |
1084 | * goto end; | |
1085 | * | |
1086 | * trace_buf = per_cpu_ptr(trace_buf, __cpu); | |
1087 | * | |
1088 | * // Avoid recursion from perf that could mess up the buffer | |
1089 | * if (trace_buf->recursion++) | |
1090 | * goto end_recursion; | |
1091 | * | |
1092 | * raw_data = trace_buf->buf; | |
1093 | * | |
1094 | * // Make recursion update visible before entering perf_tp_event | |
1095 | * // so that we protect from perf recursions. | |
1096 | * | |
1097 | * barrier(); | |
1098 | * | |
1099 | * //zero dead bytes from alignment to avoid stack leak to userspace: | |
1100 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; | |
1101 | * entry = (struct ftrace_raw_<call> *)raw_data; | |
1102 | * ent = &entry->ent; | |
1103 | * tracing_generic_entry_update(ent, irq_flags, pc); | |
1104 | * ent->type = event_call->id; | |
1105 | * | |
1106 | * <tstruct> <- do some jobs with dynamic arrays | |
1107 | * | |
1108 | * <assign> <- affect our values | |
1109 | * | |
1110 | * perf_tp_event(event_call->id, __addr, __count, entry, | |
1111 | * __entry_size); <- submit them to perf counter | |
1112 | * | |
1113 | * } | |
1114 | */ | |
1115 | ||
1116 | #ifdef CONFIG_PERF_EVENTS | |
1117 | ||
1118 | #undef __entry | |
1119 | #define __entry entry | |
1120 | ||
1121 | #undef __get_dynamic_array | |
1122 | #define __get_dynamic_array(field) \ | |
1123 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) | |
1124 | ||
1125 | #undef __get_str | |
1126 | #define __get_str(field) (char *)__get_dynamic_array(field) | |
1127 | ||
1128 | #undef __perf_addr | |
1129 | #define __perf_addr(a) __addr = (a) | |
1130 | ||
1131 | #undef __perf_count | |
1132 | #define __perf_count(c) __count = (c) | |
1133 | ||
1134 | #undef DECLARE_EVENT_CLASS | |
1135 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | |
1136 | static notrace void \ | |
1137 | perf_trace_##call(void *__data, proto) \ | |
1138 | { \ | |
1139 | struct ftrace_event_call *event_call = __data; \ | |
1140 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | |
1141 | struct ftrace_raw_##call *entry; \ | |
1142 | struct pt_regs __regs; \ | |
1143 | u64 __addr = 0, __count = 1; \ | |
1144 | struct hlist_head *head; \ | |
1145 | int __entry_size; \ | |
1146 | int __data_size; \ | |
1147 | int rctx; \ | |
1148 | \ | |
1149 | perf_fetch_caller_regs(&__regs); \ | |
1150 | \ | |
1151 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | |
1152 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ | |
1153 | sizeof(u64)); \ | |
1154 | __entry_size -= sizeof(u32); \ | |
1155 | \ | |
1156 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ | |
1157 | "profile buffer not large enough")) \ | |
1158 | return; \ | |
1159 | \ | |
1160 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ | |
1161 | __entry_size, event_call->event.type, &__regs, &rctx); \ | |
1162 | if (!entry) \ | |
1163 | return; \ | |
1164 | \ | |
1165 | tstruct \ | |
1166 | \ | |
1167 | { assign; } \ | |
1168 | \ | |
1169 | head = this_cpu_ptr(event_call->perf_events); \ | |
1170 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ | |
1171 | __count, &__regs, head); \ | |
1172 | } | |
1173 | ||
1174 | /* | |
1175 | * This part is compiled out, it is only here as a build time check | |
1176 | * to make sure that if the tracepoint handling changes, the | |
1177 | * perf probe will fail to compile unless it too is updated. | |
1178 | */ | |
1179 | #undef DEFINE_EVENT | |
1180 | #define DEFINE_EVENT(template, call, proto, args) \ | |
1181 | static inline void perf_test_probe_##call(void) \ | |
1182 | { \ | |
1183 | check_trace_callback_type_##call(perf_trace_##template); \ | |
1184 | } | |
1185 | ||
1186 | ||
1187 | #undef DEFINE_EVENT_PRINT | |
1188 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
1189 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
1190 | ||
1191 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
1192 | #endif /* CONFIG_PERF_EVENTS */ | |
1193 | ||
1194 | #undef _TRACE_PROFILE_INIT | |
1d12cebd | 1195 | #endif //0 |