Commit | Line | Data |
---|---|---|
17baffe2 MD |
1 | /* |
2 | * lttng-events.h | |
3 | * | |
4 | * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org> | |
5 | * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
6 | * | |
7 | * Dual LGPL v2.1/GPL v2 license. | |
8 | */ | |
9 | ||
d0dd2ecb | 10 | #include <linux/debugfs.h> |
c0edae1d MD |
11 | #include "lttng.h" |
12 | #include "lttng-types.h" | |
b13f3ebe | 13 | #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ |
f3bc08c5 | 14 | #include "../wrapper/ringbuffer/frontend_types.h" |
e763dbf5 | 15 | #include "../ltt-events.h" |
6db3d13b | 16 | #include "../ltt-tracer-core.h" |
40652b65 | 17 | |
40652b65 | 18 | /* |
6db3d13b | 19 | * Macro declarations used for all stages. |
40652b65 MD |
20 | */ |
21 | ||
22 | /* | |
23 | * DECLARE_EVENT_CLASS can be used to add a generic function | |
24 | * handlers for events. That is, if all events have the same | |
25 | * parameters and just have distinct trace points. | |
26 | * Each tracepoint can be defined with DEFINE_EVENT and that | |
27 | * will map the DECLARE_EVENT_CLASS to the tracepoint. | |
28 | * | |
29 | * TRACE_EVENT is a one to one mapping between tracepoint and template. | |
30 | */ | |
6db3d13b | 31 | |
40652b65 MD |
32 | #undef TRACE_EVENT |
33 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | |
34 | DECLARE_EVENT_CLASS(name, \ | |
35 | PARAMS(proto), \ | |
36 | PARAMS(args), \ | |
37 | PARAMS(tstruct), \ | |
38 | PARAMS(assign), \ | |
299338c8 MD |
39 | PARAMS(print)) \ |
40 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)) | |
40652b65 | 41 | |
f7bdf4db MD |
42 | #undef TRACE_EVENT_NOARGS |
43 | #define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \ | |
44 | DECLARE_EVENT_CLASS_NOARGS(name, \ | |
45 | PARAMS(tstruct), \ | |
46 | PARAMS(assign), \ | |
47 | PARAMS(print)) \ | |
48 | DEFINE_EVENT_NOARGS(name, name) | |
49 | ||
50 | ||
6db3d13b MD |
51 | #undef DEFINE_EVENT_PRINT |
52 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | |
53 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | |
54 | ||
55 | /* Callbacks are meaningless to LTTng. */ | |
56 | #undef TRACE_EVENT_FN | |
57 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ | |
58 | assign, print, reg, unreg) \ | |
59 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ | |
60 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ | |
61 | ||
f62b389e | 62 | /* |
c099397a | 63 | * Stage 1 of the trace events. |
f62b389e MD |
64 | * |
65 | * Create dummy trace calls for each events, verifying that the LTTng module | |
66 | * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the | |
67 | * compiler. | |
68 | */ | |
69 | ||
70 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
71 | ||
72 | #undef TP_PROTO | |
73 | #define TP_PROTO(args...) args | |
74 | ||
75 | #undef TP_ARGS | |
76 | #define TP_ARGS(args...) args | |
77 | ||
78 | #undef DEFINE_EVENT | |
79 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ | |
7eb827f2 | 80 | void trace_##_name(_proto); |
f62b389e | 81 | |
f7bdf4db MD |
82 | #undef DEFINE_EVENT_NOARGS |
83 | #define DEFINE_EVENT_NOARGS(_template, _name) \ | |
84 | void trace_##_name(void *__data); | |
85 | ||
f62b389e MD |
86 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
87 | ||
6db3d13b | 88 | /* |
c099397a | 89 | * Stage 2 of the trace events. |
6db3d13b MD |
90 | * |
91 | * Create event field type metadata section. | |
92 | * Each event produce an array of fields. | |
93 | */ | |
94 | ||
95 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
96 | ||
1d12cebd MD |
97 | /* Named field types must be defined in lttng-types.h */ |
98 | ||
d71e6471 MD |
99 | #undef __field_full |
100 | #define __field_full(_type, _item, _order, _base) \ | |
c099397a MD |
101 | { \ |
102 | .name = #_item, \ | |
d71e6471 | 103 | .type = __type_integer(_type, _order, _base, none), \ |
c099397a | 104 | }, |
40652b65 | 105 | |
d71e6471 MD |
106 | #undef __field |
107 | #define __field(_type, _item) \ | |
108 | __field_full(_type, _item, __BYTE_ORDER, 10) | |
109 | ||
40652b65 | 110 | #undef __field_ext |
d71e6471 MD |
111 | #define __field_ext(_type, _item, _filter_type) \ |
112 | __field(_type, _item) | |
40652b65 | 113 | |
6d20e0ae MD |
114 | #undef __field_hex |
115 | #define __field_hex(_type, _item) \ | |
116 | __field_full(_type, _item, __BYTE_ORDER, 16) | |
117 | ||
c099397a MD |
118 | #undef __field_network |
119 | #define __field_network(_type, _item) \ | |
d71e6471 MD |
120 | __field_full(_type, _item, __BIG_ENDIAN, 10) |
121 | ||
122 | #undef __field_network_hex | |
123 | #define __field_network_hex(_type, _item) \ | |
124 | __field_full(_type, _item, __BIG_ENDIAN, 16) | |
c099397a | 125 | |
d71e6471 MD |
126 | #undef __array_enc_ext |
127 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
299338c8 | 128 | { \ |
c099397a MD |
129 | .name = #_item, \ |
130 | .type = \ | |
131 | { \ | |
299338c8 | 132 | .atype = atype_array, \ |
c099397a MD |
133 | .u.array = \ |
134 | { \ | |
135 | .length = _length, \ | |
d71e6471 | 136 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
c099397a | 137 | }, \ |
299338c8 MD |
138 | }, \ |
139 | }, | |
40652b65 | 140 | |
64c796d8 MD |
141 | #undef __array |
142 | #define __array(_type, _item, _length) \ | |
d71e6471 | 143 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
64c796d8 MD |
144 | |
145 | #undef __array_text | |
146 | #define __array_text(_type, _item, _length) \ | |
d71e6471 | 147 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
64c796d8 | 148 | |
d71e6471 MD |
149 | #undef __array_hex |
150 | #define __array_hex(_type, _item, _length) \ | |
151 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) | |
152 | ||
153 | #undef __dynamic_array_enc_ext | |
154 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
299338c8 | 155 | { \ |
c099397a MD |
156 | .name = #_item, \ |
157 | .type = \ | |
158 | { \ | |
299338c8 | 159 | .atype = atype_sequence, \ |
c099397a MD |
160 | .u.sequence = \ |
161 | { \ | |
64c796d8 | 162 | .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \ |
d71e6471 | 163 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
c099397a | 164 | }, \ |
299338c8 MD |
165 | }, \ |
166 | }, | |
40652b65 | 167 | |
64c796d8 MD |
168 | #undef __dynamic_array |
169 | #define __dynamic_array(_type, _item, _length) \ | |
d71e6471 | 170 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
64c796d8 MD |
171 | |
172 | #undef __dynamic_array_text | |
173 | #define __dynamic_array_text(_type, _item, _length) \ | |
d71e6471 MD |
174 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
175 | ||
176 | #undef __dynamic_array_hex | |
177 | #define __dynamic_array_hex(_type, _item, _length) \ | |
178 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) | |
64c796d8 | 179 | |
40652b65 | 180 | #undef __string |
1d12cebd | 181 | #define __string(_item, _src) \ |
299338c8 | 182 | { \ |
c099397a MD |
183 | .name = #_item, \ |
184 | .type = \ | |
185 | { \ | |
299338c8 | 186 | .atype = atype_string, \ |
c099397a | 187 | .u.basic.string.encoding = lttng_encode_UTF8, \ |
299338c8 MD |
188 | }, \ |
189 | }, | |
1d12cebd | 190 | |
c6e3f225 MD |
191 | #undef __string_from_user |
192 | #define __string_from_user(_item, _src) \ | |
193 | __string(_item, _src) | |
194 | ||
40652b65 | 195 | #undef TP_STRUCT__entry |
1d12cebd MD |
196 | #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ |
197 | ||
f7bdf4db MD |
198 | #undef DECLARE_EVENT_CLASS_NOARGS |
199 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ | |
0d1d4002 MD |
200 | static const struct lttng_event_field __event_fields___##_name[] = { \ |
201 | _tstruct \ | |
299338c8 MD |
202 | }; |
203 | ||
f7bdf4db MD |
204 | #undef DECLARE_EVENT_CLASS |
205 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
206 | DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \ | |
207 | PARAMS(_print)) | |
208 | ||
299338c8 MD |
209 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
210 | ||
19c57fbf | 211 | /* |
c099397a | 212 | * Stage 3 of the trace events. |
19c57fbf MD |
213 | * |
214 | * Create probe callback prototypes. | |
215 | */ | |
216 | ||
217 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
218 | ||
219 | #undef TP_PROTO | |
220 | #define TP_PROTO(args...) args | |
221 | ||
222 | #undef DECLARE_EVENT_CLASS | |
223 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
224 | static void __event_probe__##_name(void *__data, _proto); | |
225 | ||
f7bdf4db MD |
226 | #undef DECLARE_EVENT_CLASS_NOARGS |
227 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ | |
228 | static void __event_probe__##_name(void *__data); | |
229 | ||
19c57fbf MD |
230 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
231 | ||
299338c8 | 232 | /* |
f7bdf4db | 233 | * Stage 3.9 of the trace events. |
299338c8 | 234 | * |
f7bdf4db | 235 | * Create event descriptions. |
299338c8 MD |
236 | */ |
237 | ||
299338c8 MD |
238 | /* Named field types must be defined in lttng-types.h */ |
239 | ||
6db3d13b | 240 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
299338c8 | 241 | |
1ec65de1 MD |
242 | #ifndef TP_PROBE_CB |
243 | #define TP_PROBE_CB(_template) &__event_probe__##_template | |
244 | #endif | |
245 | ||
f7bdf4db MD |
246 | #undef DEFINE_EVENT_NOARGS |
247 | #define DEFINE_EVENT_NOARGS(_template, _name) \ | |
248 | static const struct lttng_event_desc __event_desc___##_name = { \ | |
249 | .fields = __event_fields___##_template, \ | |
250 | .name = #_name, \ | |
251 | .probe_callback = (void *) TP_PROBE_CB(_template), \ | |
252 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ | |
253 | .owner = THIS_MODULE, \ | |
254 | }; | |
255 | ||
256 | #undef DEFINE_EVENT | |
257 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ | |
258 | DEFINE_EVENT_NOARGS(_template, _name) | |
259 | ||
260 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
261 | ||
262 | ||
263 | /* | |
264 | * Stage 4 of the trace events. | |
265 | * | |
266 | * Create an array of event description pointers. | |
267 | */ | |
268 | ||
269 | /* Named field types must be defined in lttng-types.h */ | |
270 | ||
271 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
272 | ||
273 | #undef DEFINE_EVENT_NOARGS | |
274 | #define DEFINE_EVENT_NOARGS(_template, _name) \ | |
275 | &__event_desc___##_name, | |
276 | ||
d32a57a2 MD |
277 | #undef DEFINE_EVENT |
278 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ | |
f7bdf4db | 279 | DEFINE_EVENT_NOARGS(_template, _name) |
40652b65 | 280 | |
d0dd2ecb MD |
281 | #define TP_ID1(_token, _system) _token##_system |
282 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
40652b65 | 283 | |
f7bdf4db | 284 | static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = { |
40652b65 | 285 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
299338c8 MD |
286 | }; |
287 | ||
d0dd2ecb MD |
288 | #undef TP_ID1 |
289 | #undef TP_ID | |
290 | ||
85a9ca7f MD |
291 | |
292 | /* | |
c099397a | 293 | * Stage 5 of the trace events. |
85a9ca7f MD |
294 | * |
295 | * Create a toplevel descriptor for the whole probe. | |
296 | */ | |
297 | ||
298 | #define TP_ID1(_token, _system) _token##_system | |
299 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
300 | ||
301 | /* non-const because list head will be modified when registered. */ | |
25631135 | 302 | static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { |
85a9ca7f MD |
303 | .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM), |
304 | .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)), | |
305 | }; | |
306 | ||
307 | #undef TP_ID1 | |
308 | #undef TP_ID | |
309 | ||
d0dd2ecb | 310 | /* |
c099397a | 311 | * Stage 6 of the trace events. |
40652b65 MD |
312 | * |
313 | * Create static inline function that calculates event size. | |
314 | */ | |
315 | ||
6db3d13b | 316 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
40652b65 | 317 | |
6db3d13b MD |
318 | /* Named field types must be defined in lttng-types.h */ |
319 | ||
d71e6471 MD |
320 | #undef __field_full |
321 | #define __field_full(_type, _item, _order, _base) \ | |
d793d5e1 | 322 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
0d1d4002 | 323 | __event_len += sizeof(_type); |
6db3d13b | 324 | |
d71e6471 MD |
325 | #undef __array_enc_ext |
326 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
d793d5e1 | 327 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
0d1d4002 | 328 | __event_len += sizeof(_type) * (_length); |
6db3d13b | 329 | |
d71e6471 MD |
330 | #undef __dynamic_array_enc_ext |
331 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
d793d5e1 | 332 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \ |
85a80742 | 333 | __event_len += sizeof(u32); \ |
d793d5e1 | 334 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
41b59694 MD |
335 | __dynamic_len[__dynamic_len_idx] = (_length); \ |
336 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ | |
337 | __dynamic_len_idx++; | |
6db3d13b MD |
338 | |
339 | #undef __string | |
85a80742 | 340 | #define __string(_item, _src) \ |
0d1d4002 MD |
341 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
342 | ||
d0255731 | 343 | /* |
786b8312 MD |
344 | * strlen_user includes \0. If returns 0, it faulted, so we set size to |
345 | * 1 (\0 only). | |
d0255731 | 346 | */ |
c6e3f225 MD |
347 | #undef __string_from_user |
348 | #define __string_from_user(_item, _src) \ | |
786b8312 MD |
349 | __event_len += __dynamic_len[__dynamic_len_idx++] = \ |
350 | min_t(size_t, strlen_user(_src), 1); | |
c6e3f225 | 351 | |
0d1d4002 MD |
352 | #undef TP_PROTO |
353 | #define TP_PROTO(args...) args | |
6db3d13b MD |
354 | |
355 | #undef TP_STRUCT__entry | |
0d1d4002 | 356 | #define TP_STRUCT__entry(args...) args |
6db3d13b MD |
357 | |
358 | #undef DECLARE_EVENT_CLASS | |
0d1d4002 MD |
359 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
360 | static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ | |
361 | { \ | |
362 | size_t __event_len = 0; \ | |
363 | unsigned int __dynamic_len_idx = 0; \ | |
364 | \ | |
365 | if (0) \ | |
366 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
367 | _tstruct \ | |
368 | return __event_len; \ | |
6db3d13b | 369 | } |
40652b65 MD |
370 | |
371 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
372 | ||
373 | /* | |
c099397a | 374 | * Stage 7 of the trace events. |
e763dbf5 MD |
375 | * |
376 | * Create static inline function that calculates event payload alignment. | |
377 | */ | |
378 | ||
379 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
380 | ||
381 | /* Named field types must be defined in lttng-types.h */ | |
382 | ||
d71e6471 MD |
383 | #undef __field_full |
384 | #define __field_full(_type, _item, _order, _base) \ | |
d793d5e1 | 385 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); |
e763dbf5 | 386 | |
d71e6471 MD |
387 | #undef __array_enc_ext |
388 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
d793d5e1 | 389 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); |
e763dbf5 | 390 | |
d71e6471 MD |
391 | #undef __dynamic_array_enc_ext |
392 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
d793d5e1 MD |
393 | __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \ |
394 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); | |
e763dbf5 MD |
395 | |
396 | #undef __string | |
397 | #define __string(_item, _src) | |
398 | ||
c6e3f225 MD |
399 | #undef __string_from_user |
400 | #define __string_from_user(_item, _src) | |
401 | ||
e763dbf5 MD |
402 | #undef TP_PROTO |
403 | #define TP_PROTO(args...) args | |
404 | ||
405 | #undef TP_STRUCT__entry | |
406 | #define TP_STRUCT__entry(args...) args | |
407 | ||
408 | #undef DECLARE_EVENT_CLASS | |
409 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
410 | static inline size_t __event_get_align__##_name(_proto) \ | |
411 | { \ | |
412 | size_t __event_align = 1; \ | |
413 | _tstruct \ | |
414 | return __event_align; \ | |
415 | } | |
416 | ||
417 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
418 | ||
419 | ||
e763dbf5 | 420 | /* |
c099397a | 421 | * Stage 8 of the trace events. |
40652b65 | 422 | * |
3c4ffab9 MD |
423 | * Create structure declaration that allows the "assign" macros to access the |
424 | * field types. | |
425 | */ | |
426 | ||
427 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
428 | ||
429 | /* Named field types must be defined in lttng-types.h */ | |
430 | ||
d71e6471 MD |
431 | #undef __field_full |
432 | #define __field_full(_type, _item, _order, _base) _type _item; | |
3c4ffab9 | 433 | |
d71e6471 MD |
434 | #undef __array_enc_ext |
435 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
436 | _type _item; | |
64c796d8 | 437 | |
d71e6471 MD |
438 | #undef __dynamic_array_enc_ext |
439 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
440 | _type _item; | |
64c796d8 | 441 | |
3c4ffab9 | 442 | #undef __string |
c6e3f225 MD |
443 | #define __string(_item, _src) char _item; |
444 | ||
445 | #undef __string_from_user | |
446 | #define __string_from_user(_item, _src) \ | |
447 | __string(_item, _src) | |
3c4ffab9 MD |
448 | |
449 | #undef TP_STRUCT__entry | |
450 | #define TP_STRUCT__entry(args...) args | |
451 | ||
452 | #undef DECLARE_EVENT_CLASS | |
453 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
454 | struct __event_typemap__##_name { \ | |
455 | _tstruct \ | |
456 | }; | |
457 | ||
458 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
459 | ||
460 | ||
461 | /* | |
c099397a | 462 | * Stage 9 of the trace events. |
3c4ffab9 | 463 | * |
40652b65 MD |
464 | * Create the probe function : call even size calculation and write event data |
465 | * into the buffer. | |
e763dbf5 | 466 | * |
67e5e60c MD |
467 | * We use both the field and assignment macros to write the fields in the order |
468 | * defined in the field declaration. The field declarations control the | |
469 | * execution order, jumping to the appropriate assignment block. | |
40652b65 MD |
470 | */ |
471 | ||
e763dbf5 MD |
472 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
473 | ||
d71e6471 MD |
474 | #undef __field_full |
475 | #define __field_full(_type, _item, _order, _base) \ | |
e763dbf5 MD |
476 | goto __assign_##_item; \ |
477 | __end_field_##_item: | |
40652b65 | 478 | |
d71e6471 MD |
479 | #undef __array_enc_ext |
480 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
e763dbf5 MD |
481 | goto __assign_##_item; \ |
482 | __end_field_##_item: | |
40652b65 | 483 | |
d71e6471 MD |
484 | #undef __dynamic_array_enc_ext |
485 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
e763dbf5 MD |
486 | goto __assign_##_item##_1; \ |
487 | __end_field_##_item##_1: \ | |
e763dbf5 MD |
488 | goto __assign_##_item##_2; \ |
489 | __end_field_##_item##_2: | |
40652b65 | 490 | |
e763dbf5 MD |
491 | #undef __string |
492 | #define __string(_item, _src) \ | |
493 | goto __assign_##_item; \ | |
494 | __end_field_##_item: | |
495 | ||
c6e3f225 MD |
496 | #undef __string_from_user |
497 | #define __string_from_user(_item, _src) \ | |
498 | __string(_item, _src) | |
499 | ||
e763dbf5 MD |
500 | /* |
501 | * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to | |
502 | * strcpy(). | |
503 | */ | |
504 | #undef tp_assign | |
505 | #define tp_assign(dest, src) \ | |
506 | __assign_##dest: \ | |
507 | { \ | |
3c4ffab9 | 508 | __typeof__(__typemap.dest) __tmp = (src); \ |
aaa4004a MD |
509 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__tmp)); \ |
510 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ | |
e763dbf5 MD |
511 | } \ |
512 | goto __end_field_##dest; | |
513 | ||
514 | #undef tp_memcpy | |
515 | #define tp_memcpy(dest, src, len) \ | |
516 | __assign_##dest: \ | |
d793d5e1 MD |
517 | if (0) \ |
518 | (void) __typemap.dest; \ | |
aaa4004a MD |
519 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ |
520 | __chan->ops->event_write(&__ctx, src, len); \ | |
e763dbf5 MD |
521 | goto __end_field_##dest; |
522 | ||
523 | #undef tp_memcpy_dyn | |
41b59694 | 524 | #define tp_memcpy_dyn(dest, src) \ |
e763dbf5 MD |
525 | __assign_##dest##_1: \ |
526 | { \ | |
41b59694 | 527 | u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \ |
aaa4004a MD |
528 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(u32)); \ |
529 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \ | |
e763dbf5 MD |
530 | } \ |
531 | goto __end_field_##dest##_1; \ | |
532 | __assign_##dest##_2: \ | |
aaa4004a MD |
533 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ |
534 | __chan->ops->event_write(&__ctx, src, \ | |
41b59694 | 535 | sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\ |
e763dbf5 | 536 | goto __end_field_##dest##_2; |
58aa5d24 | 537 | |
4ea00e4f JD |
538 | #undef tp_memcpy_from_user |
539 | #define tp_memcpy_from_user(dest, src, len) \ | |
540 | __assign_##dest: \ | |
541 | if (0) \ | |
542 | (void) __typemap.dest; \ | |
543 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ | |
544 | __chan->ops->event_write_from_user(&__ctx, src, len); \ | |
545 | goto __end_field_##dest; | |
58aa5d24 | 546 | |
d0255731 | 547 | /* |
786b8312 | 548 | * The string length including the final \0. |
d0255731 | 549 | */ |
4ea00e4f | 550 | #undef tp_copy_string_from_user |
58aa5d24 | 551 | #define tp_copy_string_from_user(dest, src) \ |
4ea00e4f | 552 | __assign_##dest: \ |
d0255731 MD |
553 | { \ |
554 | size_t __ustrlen; \ | |
555 | \ | |
556 | if (0) \ | |
557 | (void) __typemap.dest; \ | |
558 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest));\ | |
559 | __ustrlen = __get_dynamic_array_len(dest); \ | |
560 | if (likely(__ustrlen) > 1) { \ | |
561 | __chan->ops->event_write_from_user(&__ctx, src, \ | |
562 | __ustrlen - 1); \ | |
563 | } \ | |
564 | __chan->ops->event_memset(&__ctx, 0, 1); \ | |
565 | } \ | |
4ea00e4f | 566 | goto __end_field_##dest; |
e763dbf5 MD |
567 | #undef tp_strcpy |
568 | #define tp_strcpy(dest, src) \ | |
3c4ffab9 | 569 | tp_memcpy(dest, src, __get_dynamic_array_len(dest)) |
40652b65 | 570 | |
e763dbf5 MD |
571 | /* Named field types must be defined in lttng-types.h */ |
572 | ||
573 | #undef __get_str | |
574 | #define __get_str(field) field | |
575 | ||
576 | #undef __get_dynamic_array | |
577 | #define __get_dynamic_array(field) field | |
578 | ||
579 | /* Beware: this get len actually consumes the len value */ | |
580 | #undef __get_dynamic_array_len | |
581 | #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++] | |
582 | ||
583 | #undef TP_PROTO | |
584 | #define TP_PROTO(args...) args | |
585 | ||
586 | #undef TP_ARGS | |
587 | #define TP_ARGS(args...) args | |
588 | ||
589 | #undef TP_STRUCT__entry | |
590 | #define TP_STRUCT__entry(args...) args | |
591 | ||
592 | #undef TP_fast_assign | |
593 | #define TP_fast_assign(args...) args | |
594 | ||
595 | #undef DECLARE_EVENT_CLASS | |
596 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
597 | static void __event_probe__##_name(void *__data, _proto) \ | |
598 | { \ | |
599 | struct ltt_event *__event = __data; \ | |
600 | struct ltt_channel *__chan = __event->chan; \ | |
aaa4004a | 601 | struct lib_ring_buffer_ctx __ctx; \ |
e763dbf5 MD |
602 | size_t __event_len, __event_align; \ |
603 | size_t __dynamic_len_idx = 0; \ | |
604 | size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \ | |
3c4ffab9 | 605 | struct __event_typemap__##_name __typemap; \ |
e763dbf5 MD |
606 | int __ret; \ |
607 | \ | |
608 | if (0) \ | |
609 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
e64957da MD |
610 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ |
611 | return; \ | |
612 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ | |
613 | return; \ | |
614 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ | |
52fc2e1f | 615 | return; \ |
e763dbf5 MD |
616 | __event_len = __event_get_size__##_name(__dynamic_len, _args); \ |
617 | __event_align = __event_get_align__##_name(_args); \ | |
aaa4004a | 618 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
e763dbf5 | 619 | __event_align, -1); \ |
aaa4004a | 620 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
e763dbf5 MD |
621 | if (__ret < 0) \ |
622 | return; \ | |
623 | /* Control code (field ordering) */ \ | |
624 | _tstruct \ | |
aaa4004a | 625 | __chan->ops->event_commit(&__ctx); \ |
e763dbf5 MD |
626 | return; \ |
627 | /* Copy code, steered by control code */ \ | |
628 | _assign \ | |
629 | } | |
630 | ||
f7bdf4db MD |
631 | #undef DECLARE_EVENT_CLASS_NOARGS |
632 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ | |
633 | static void __event_probe__##_name(void *__data) \ | |
634 | { \ | |
635 | struct ltt_event *__event = __data; \ | |
636 | struct ltt_channel *__chan = __event->chan; \ | |
637 | struct lib_ring_buffer_ctx __ctx; \ | |
638 | size_t __event_len, __event_align; \ | |
639 | int __ret; \ | |
640 | \ | |
641 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ | |
642 | return; \ | |
643 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ | |
644 | return; \ | |
645 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ | |
646 | return; \ | |
647 | __event_len = 0; \ | |
648 | __event_align = 1; \ | |
649 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ | |
650 | __event_align, -1); \ | |
651 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ | |
652 | if (__ret < 0) \ | |
653 | return; \ | |
654 | /* Control code (field ordering) */ \ | |
655 | _tstruct \ | |
656 | __chan->ops->event_commit(&__ctx); \ | |
657 | return; \ | |
658 | /* Copy code, steered by control code */ \ | |
659 | _assign \ | |
660 | } | |
661 | ||
e763dbf5 MD |
662 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
663 | ||
3afe7aac | 664 | /* |
c099397a | 665 | * Stage 10 of the trace events. |
3afe7aac MD |
666 | * |
667 | * Register/unregister probes at module load/unload. | |
668 | */ | |
669 | ||
670 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
671 | ||
672 | #define TP_ID1(_token, _system) _token##_system | |
673 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
674 | #define module_init_eval1(_token, _system) module_init(_token##_system) | |
675 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) | |
676 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) | |
677 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) | |
678 | ||
259b6cb3 | 679 | #ifndef TP_MODULE_OVERRIDE |
3afe7aac MD |
680 | static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void) |
681 | { | |
6d2a620c | 682 | wrapper_vmalloc_sync_all(); |
259b6cb3 | 683 | return ltt_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
684 | } |
685 | ||
686 | module_init_eval(__lttng_events_init__, TRACE_SYSTEM); | |
687 | ||
3afe7aac MD |
688 | static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void) |
689 | { | |
259b6cb3 | 690 | ltt_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
691 | } |
692 | ||
693 | module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM); | |
259b6cb3 | 694 | #endif |
3afe7aac MD |
695 | |
696 | #undef module_init_eval | |
697 | #undef module_exit_eval | |
698 | #undef TP_ID1 | |
699 | #undef TP_ID | |
177b3692 MD |
700 | |
701 | #undef TP_PROTO | |
702 | #undef TP_ARGS | |
703 | #undef TRACE_EVENT_FLAGS |