1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/trace_events.h>
22
23#ifndef TRACE_SYSTEM_VAR
24#define TRACE_SYSTEM_VAR TRACE_SYSTEM
25#endif
26
27#include "stages/init.h"
28
29
30
31
32
33
34
35
36
37
38#undef TRACE_EVENT
39#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
40 DECLARE_EVENT_CLASS(name, \
41 PARAMS(proto), \
42 PARAMS(args), \
43 PARAMS(tstruct), \
44 PARAMS(assign), \
45 PARAMS(print)); \
46 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
47
48#undef TRACE_EVENT_SYSCALL
49#define TRACE_EVENT_SYSCALL(name, proto, args, tstruct, assign, print, reg, unreg) \
50 DECLARE_EVENT_SYSCALL_CLASS(name, \
51 PARAMS(proto), \
52 PARAMS(args), \
53 PARAMS(tstruct), \
54 PARAMS(assign), \
55 PARAMS(print)); \
56 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
57
58#include "stages/stage1_struct_define.h"
59
60#undef DECLARE_EVENT_CLASS
61#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
62 struct trace_event_raw_##name { \
63 struct trace_entry ent; \
64 tstruct \
65 char __data[]; \
66 }; \
67 \
68 static struct trace_event_class event_class_##name;
69
70#undef DECLARE_EVENT_SYSCALL_CLASS
71#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
72
73#undef DEFINE_EVENT
74#define DEFINE_EVENT(template, name, proto, args) \
75 static struct trace_event_call __used \
76 __attribute__((__aligned__(4))) event_##name
77
78#undef DEFINE_EVENT_FN
79#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
80 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
81
82#undef DEFINE_EVENT_PRINT
83#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
84 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
85
86
87#undef TRACE_EVENT_FN
88#define TRACE_EVENT_FN(name, proto, args, tstruct, \
89 assign, print, reg, unreg) \
90 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
91 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
92
93#undef TRACE_EVENT_FN_COND
94#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
95 assign, print, reg, unreg) \
96 TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
97 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
98
99#undef TRACE_EVENT_FLAGS
100#define TRACE_EVENT_FLAGS(name, value) \
101 __TRACE_EVENT_FLAGS(name, value)
102
103#undef TRACE_EVENT_PERF_PERM
104#define TRACE_EVENT_PERF_PERM(name, expr...) \
105 __TRACE_EVENT_PERF_PERM(name, expr)
106
107#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125#include "stages/stage2_data_offsets.h"
126
127#undef DECLARE_EVENT_CLASS
128#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
129 struct trace_event_data_offsets_##call { \
130 tstruct; \
131 };
132
133#undef DECLARE_EVENT_SYSCALL_CLASS
134#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
135
136#undef DEFINE_EVENT
137#define DEFINE_EVENT(template, name, proto, args)
138
139#undef DEFINE_EVENT_PRINT
140#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
141
142#undef TRACE_EVENT_FLAGS
143#define TRACE_EVENT_FLAGS(event, flag)
144
145#undef TRACE_EVENT_PERF_PERM
146#define TRACE_EVENT_PERF_PERM(event, expr...)
147
148#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200#include "stages/stage3_trace_output.h"
201
202#undef DECLARE_EVENT_CLASS
203#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
204static notrace enum print_line_t \
205trace_raw_output_##call(struct trace_iterator *iter, int flags, \
206 struct trace_event *trace_event) \
207{ \
208 struct trace_seq *s = &iter->seq; \
209 struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
210 struct trace_event_raw_##call *field; \
211 int ret; \
212 \
213 field = (typeof(field))iter->ent; \
214 \
215 ret = trace_raw_output_prep(iter, trace_event); \
216 if (ret != TRACE_TYPE_HANDLED) \
217 return ret; \
218 \
219 trace_event_printf(iter, print); \
220 \
221 return trace_handle_return(s); \
222} \
223static struct trace_event_functions trace_event_type_funcs_##call = { \
224 .trace = trace_raw_output_##call, \
225};
226
227#undef DECLARE_EVENT_SYSCALL_CLASS
228#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
229
230#undef DEFINE_EVENT_PRINT
231#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
232static notrace enum print_line_t \
233trace_raw_output_##call(struct trace_iterator *iter, int flags, \
234 struct trace_event *event) \
235{ \
236 struct trace_event_raw_##template *field; \
237 struct trace_entry *entry; \
238 struct trace_seq *p = &iter->tmp_seq; \
239 \
240 entry = iter->ent; \
241 \
242 if (entry->type != event_##call.event.type) { \
243 WARN_ON_ONCE(1); \
244 return TRACE_TYPE_UNHANDLED; \
245 } \
246 \
247 field = (typeof(field))entry; \
248 \
249 trace_seq_init(p); \
250 return trace_output_call(iter, #call, print); \
251} \
252static struct trace_event_functions trace_event_type_funcs_##call = { \
253 .trace = trace_raw_output_##call, \
254};
255
256#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
257
258#include "stages/stage4_event_fields.h"
259
260#undef DECLARE_EVENT_CLASS
261#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
262static struct trace_event_fields trace_event_fields_##call[] = { \
263 tstruct \
264 {} };
265
266#undef DECLARE_EVENT_SYSCALL_CLASS
267#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
268
269#undef DEFINE_EVENT_PRINT
270#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
271
272#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
273
274#include "stages/stage5_get_offsets.h"
275
276#undef DECLARE_EVENT_CLASS
277#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
278static inline notrace int trace_event_get_offsets_##call( \
279 struct trace_event_data_offsets_##call *__data_offsets, proto) \
280{ \
281 int __data_size = 0; \
282 int __maybe_unused __item_length; \
283 struct trace_event_raw_##call __maybe_unused *entry; \
284 \
285 tstruct; \
286 \
287 return __data_size; \
288}
289
290#undef DECLARE_EVENT_SYSCALL_CLASS
291#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
292
293#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386#ifdef CONFIG_PERF_EVENTS
387
388#define _TRACE_PERF_PROTO(call, proto) \
389 static notrace void \
390 perf_trace_##call(void *__data, proto);
391
392#define _TRACE_PERF_INIT(call) \
393 .perf_probe = perf_trace_##call,
394
395#else
396#define _TRACE_PERF_PROTO(call, proto)
397#define _TRACE_PERF_INIT(call)
398#endif
399
400#include "stages/stage6_event_callback.h"
401
402
403#undef __DECLARE_EVENT_CLASS
404#define __DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
405static notrace void \
406do_trace_event_raw_event_##call(void *__data, proto) \
407{ \
408 struct trace_event_file *trace_file = __data; \
409 struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
410 struct trace_event_buffer fbuffer; \
411 struct trace_event_raw_##call *entry; \
412 int __data_size; \
413 \
414 if (trace_trigger_soft_disabled(trace_file)) \
415 return; \
416 \
417 __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
418 \
419 entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
420 sizeof(*entry) + __data_size); \
421 \
422 if (!entry) \
423 return; \
424 \
425 tstruct \
426 \
427 { assign; } \
428 \
429 trace_event_buffer_commit(&fbuffer); \
430}
431
432#undef DECLARE_EVENT_CLASS
433#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
434__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
435 PARAMS(assign), PARAMS(print)) \
436static notrace void \
437trace_event_raw_event_##call(void *__data, proto) \
438{ \
439 do_trace_event_raw_event_##call(__data, args); \
440}
441
442#undef DECLARE_EVENT_SYSCALL_CLASS
443#define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, print) \
444__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
445 PARAMS(assign), PARAMS(print)) \
446static notrace void \
447trace_event_raw_event_##call(void *__data, proto) \
448{ \
449 might_fault(); \
450 preempt_disable_notrace(); \
451 do_trace_event_raw_event_##call(__data, args); \
452 preempt_enable_notrace(); \
453}
454
455
456
457
458
459
460
461#undef DEFINE_EVENT
462#define DEFINE_EVENT(template, call, proto, args) \
463static inline void ftrace_test_probe_##call(void) \
464{ \
465 check_trace_callback_type_##call(trace_event_raw_event_##template); \
466}
467
468#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
469
470#undef __DECLARE_EVENT_CLASS
471
472#include "stages/stage7_class_define.h"
473
474#undef DECLARE_EVENT_CLASS
475#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
476_TRACE_PERF_PROTO(call, PARAMS(proto)); \
477static char print_fmt_##call[] = print; \
478static struct trace_event_class __used __refdata event_class_##call = { \
479 .system = TRACE_SYSTEM_STRING, \
480 .fields_array = trace_event_fields_##call, \
481 .fields = LIST_HEAD_INIT(event_class_##call.fields),\
482 .raw_init = trace_event_raw_init, \
483 .probe = trace_event_raw_event_##call, \
484 .reg = trace_event_reg, \
485 _TRACE_PERF_INIT(call) \
486};
487
488#undef DECLARE_EVENT_SYSCALL_CLASS
489#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
490
491#undef DEFINE_EVENT
492#define DEFINE_EVENT(template, call, proto, args) \
493 \
494static struct trace_event_call __used event_##call = { \
495 .class = &event_class_##template, \
496 { \
497 .tp = &__tracepoint_##call, \
498 }, \
499 .event.funcs = &trace_event_type_funcs_##template, \
500 .print_fmt = print_fmt_##template, \
501 .flags = TRACE_EVENT_FL_TRACEPOINT, \
502}; \
503static struct trace_event_call __used \
504__section("_ftrace_events") *__event_##call = &event_##call
505
506#undef DEFINE_EVENT_PRINT
507#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
508 \
509static char print_fmt_##call[] = print; \
510 \
511static struct trace_event_call __used event_##call = { \
512 .class = &event_class_##template, \
513 { \
514 .tp = &__tracepoint_##call, \
515 }, \
516 .event.funcs = &trace_event_type_funcs_##call, \
517 .print_fmt = print_fmt_##call, \
518 .flags = TRACE_EVENT_FL_TRACEPOINT, \
519}; \
520static struct trace_event_call __used \
521__section("_ftrace_events") *__event_##call = &event_##call
522
523#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
524