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