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 | |
c099397a MD |
114 | #undef __field_network |
115 | #define __field_network(_type, _item) \ | |
d71e6471 MD |
116 | __field_full(_type, _item, __BIG_ENDIAN, 10) |
117 | ||
118 | #undef __field_network_hex | |
119 | #define __field_network_hex(_type, _item) \ | |
120 | __field_full(_type, _item, __BIG_ENDIAN, 16) | |
c099397a | 121 | |
d71e6471 MD |
122 | #undef __array_enc_ext |
123 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
299338c8 | 124 | { \ |
c099397a MD |
125 | .name = #_item, \ |
126 | .type = \ | |
127 | { \ | |
299338c8 | 128 | .atype = atype_array, \ |
c099397a MD |
129 | .u.array = \ |
130 | { \ | |
131 | .length = _length, \ | |
d71e6471 | 132 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
c099397a | 133 | }, \ |
299338c8 MD |
134 | }, \ |
135 | }, | |
40652b65 | 136 | |
64c796d8 MD |
137 | #undef __array |
138 | #define __array(_type, _item, _length) \ | |
d71e6471 | 139 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
64c796d8 MD |
140 | |
141 | #undef __array_text | |
142 | #define __array_text(_type, _item, _length) \ | |
d71e6471 | 143 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
64c796d8 | 144 | |
d71e6471 MD |
145 | #undef __array_hex |
146 | #define __array_hex(_type, _item, _length) \ | |
147 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) | |
148 | ||
149 | #undef __dynamic_array_enc_ext | |
150 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
299338c8 | 151 | { \ |
c099397a MD |
152 | .name = #_item, \ |
153 | .type = \ | |
154 | { \ | |
299338c8 | 155 | .atype = atype_sequence, \ |
c099397a MD |
156 | .u.sequence = \ |
157 | { \ | |
64c796d8 | 158 | .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \ |
d71e6471 | 159 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
c099397a | 160 | }, \ |
299338c8 MD |
161 | }, \ |
162 | }, | |
40652b65 | 163 | |
64c796d8 MD |
164 | #undef __dynamic_array |
165 | #define __dynamic_array(_type, _item, _length) \ | |
d71e6471 | 166 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
64c796d8 MD |
167 | |
168 | #undef __dynamic_array_text | |
169 | #define __dynamic_array_text(_type, _item, _length) \ | |
d71e6471 MD |
170 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
171 | ||
172 | #undef __dynamic_array_hex | |
173 | #define __dynamic_array_hex(_type, _item, _length) \ | |
174 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) | |
64c796d8 | 175 | |
40652b65 | 176 | #undef __string |
1d12cebd | 177 | #define __string(_item, _src) \ |
299338c8 | 178 | { \ |
c099397a MD |
179 | .name = #_item, \ |
180 | .type = \ | |
181 | { \ | |
299338c8 | 182 | .atype = atype_string, \ |
c099397a | 183 | .u.basic.string.encoding = lttng_encode_UTF8, \ |
299338c8 MD |
184 | }, \ |
185 | }, | |
1d12cebd | 186 | |
40652b65 | 187 | #undef TP_STRUCT__entry |
1d12cebd MD |
188 | #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ |
189 | ||
f7bdf4db MD |
190 | #undef DECLARE_EVENT_CLASS_NOARGS |
191 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ | |
0d1d4002 MD |
192 | static const struct lttng_event_field __event_fields___##_name[] = { \ |
193 | _tstruct \ | |
299338c8 MD |
194 | }; |
195 | ||
f7bdf4db MD |
196 | #undef DECLARE_EVENT_CLASS |
197 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
198 | DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \ | |
199 | PARAMS(_print)) | |
200 | ||
299338c8 MD |
201 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
202 | ||
19c57fbf | 203 | /* |
c099397a | 204 | * Stage 3 of the trace events. |
19c57fbf MD |
205 | * |
206 | * Create probe callback prototypes. | |
207 | */ | |
208 | ||
209 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
210 | ||
211 | #undef TP_PROTO | |
212 | #define TP_PROTO(args...) args | |
213 | ||
214 | #undef DECLARE_EVENT_CLASS | |
215 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
216 | static void __event_probe__##_name(void *__data, _proto); | |
217 | ||
f7bdf4db MD |
218 | #undef DECLARE_EVENT_CLASS_NOARGS |
219 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ | |
220 | static void __event_probe__##_name(void *__data); | |
221 | ||
19c57fbf MD |
222 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
223 | ||
299338c8 | 224 | /* |
f7bdf4db | 225 | * Stage 3.9 of the trace events. |
299338c8 | 226 | * |
f7bdf4db | 227 | * Create event descriptions. |
299338c8 MD |
228 | */ |
229 | ||
299338c8 MD |
230 | /* Named field types must be defined in lttng-types.h */ |
231 | ||
6db3d13b | 232 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
299338c8 | 233 | |
1ec65de1 MD |
234 | #ifndef TP_PROBE_CB |
235 | #define TP_PROBE_CB(_template) &__event_probe__##_template | |
236 | #endif | |
237 | ||
f7bdf4db MD |
238 | #undef DEFINE_EVENT_NOARGS |
239 | #define DEFINE_EVENT_NOARGS(_template, _name) \ | |
240 | static const struct lttng_event_desc __event_desc___##_name = { \ | |
241 | .fields = __event_fields___##_template, \ | |
242 | .name = #_name, \ | |
243 | .probe_callback = (void *) TP_PROBE_CB(_template), \ | |
244 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ | |
245 | .owner = THIS_MODULE, \ | |
246 | }; | |
247 | ||
248 | #undef DEFINE_EVENT | |
249 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ | |
250 | DEFINE_EVENT_NOARGS(_template, _name) | |
251 | ||
252 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
253 | ||
254 | ||
255 | /* | |
256 | * Stage 4 of the trace events. | |
257 | * | |
258 | * Create an array of event description pointers. | |
259 | */ | |
260 | ||
261 | /* Named field types must be defined in lttng-types.h */ | |
262 | ||
263 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
264 | ||
265 | #undef DEFINE_EVENT_NOARGS | |
266 | #define DEFINE_EVENT_NOARGS(_template, _name) \ | |
267 | &__event_desc___##_name, | |
268 | ||
d32a57a2 MD |
269 | #undef DEFINE_EVENT |
270 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ | |
f7bdf4db | 271 | DEFINE_EVENT_NOARGS(_template, _name) |
40652b65 | 272 | |
d0dd2ecb MD |
273 | #define TP_ID1(_token, _system) _token##_system |
274 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
40652b65 | 275 | |
f7bdf4db | 276 | static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = { |
40652b65 | 277 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
299338c8 MD |
278 | }; |
279 | ||
d0dd2ecb MD |
280 | #undef TP_ID1 |
281 | #undef TP_ID | |
282 | ||
85a9ca7f MD |
283 | |
284 | /* | |
c099397a | 285 | * Stage 5 of the trace events. |
85a9ca7f MD |
286 | * |
287 | * Create a toplevel descriptor for the whole probe. | |
288 | */ | |
289 | ||
290 | #define TP_ID1(_token, _system) _token##_system | |
291 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
292 | ||
293 | /* non-const because list head will be modified when registered. */ | |
25631135 | 294 | static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { |
85a9ca7f MD |
295 | .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM), |
296 | .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)), | |
297 | }; | |
298 | ||
299 | #undef TP_ID1 | |
300 | #undef TP_ID | |
301 | ||
d0dd2ecb | 302 | /* |
c099397a | 303 | * Stage 6 of the trace events. |
40652b65 MD |
304 | * |
305 | * Create static inline function that calculates event size. | |
306 | */ | |
307 | ||
6db3d13b | 308 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
40652b65 | 309 | |
6db3d13b MD |
310 | /* Named field types must be defined in lttng-types.h */ |
311 | ||
d71e6471 MD |
312 | #undef __field_full |
313 | #define __field_full(_type, _item, _order, _base) \ | |
d793d5e1 | 314 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
0d1d4002 | 315 | __event_len += sizeof(_type); |
6db3d13b | 316 | |
d71e6471 MD |
317 | #undef __array_enc_ext |
318 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
d793d5e1 | 319 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
0d1d4002 | 320 | __event_len += sizeof(_type) * (_length); |
6db3d13b | 321 | |
d71e6471 MD |
322 | #undef __dynamic_array_enc_ext |
323 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
d793d5e1 | 324 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \ |
85a80742 | 325 | __event_len += sizeof(u32); \ |
d793d5e1 | 326 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
41b59694 MD |
327 | __dynamic_len[__dynamic_len_idx] = (_length); \ |
328 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ | |
329 | __dynamic_len_idx++; | |
6db3d13b MD |
330 | |
331 | #undef __string | |
85a80742 | 332 | #define __string(_item, _src) \ |
0d1d4002 MD |
333 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
334 | ||
335 | #undef TP_PROTO | |
336 | #define TP_PROTO(args...) args | |
6db3d13b MD |
337 | |
338 | #undef TP_STRUCT__entry | |
0d1d4002 | 339 | #define TP_STRUCT__entry(args...) args |
6db3d13b MD |
340 | |
341 | #undef DECLARE_EVENT_CLASS | |
0d1d4002 MD |
342 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
343 | static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ | |
344 | { \ | |
345 | size_t __event_len = 0; \ | |
346 | unsigned int __dynamic_len_idx = 0; \ | |
347 | \ | |
348 | if (0) \ | |
349 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
350 | _tstruct \ | |
351 | return __event_len; \ | |
6db3d13b | 352 | } |
40652b65 MD |
353 | |
354 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
355 | ||
356 | /* | |
c099397a | 357 | * Stage 7 of the trace events. |
e763dbf5 MD |
358 | * |
359 | * Create static inline function that calculates event payload alignment. | |
360 | */ | |
361 | ||
362 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
363 | ||
364 | /* Named field types must be defined in lttng-types.h */ | |
365 | ||
d71e6471 MD |
366 | #undef __field_full |
367 | #define __field_full(_type, _item, _order, _base) \ | |
d793d5e1 | 368 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); |
e763dbf5 | 369 | |
d71e6471 MD |
370 | #undef __array_enc_ext |
371 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
d793d5e1 | 372 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); |
e763dbf5 | 373 | |
d71e6471 MD |
374 | #undef __dynamic_array_enc_ext |
375 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
d793d5e1 MD |
376 | __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \ |
377 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); | |
e763dbf5 MD |
378 | |
379 | #undef __string | |
380 | #define __string(_item, _src) | |
381 | ||
382 | #undef TP_PROTO | |
383 | #define TP_PROTO(args...) args | |
384 | ||
385 | #undef TP_STRUCT__entry | |
386 | #define TP_STRUCT__entry(args...) args | |
387 | ||
388 | #undef DECLARE_EVENT_CLASS | |
389 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
390 | static inline size_t __event_get_align__##_name(_proto) \ | |
391 | { \ | |
392 | size_t __event_align = 1; \ | |
393 | _tstruct \ | |
394 | return __event_align; \ | |
395 | } | |
396 | ||
397 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
398 | ||
399 | ||
e763dbf5 | 400 | /* |
c099397a | 401 | * Stage 8 of the trace events. |
40652b65 | 402 | * |
3c4ffab9 MD |
403 | * Create structure declaration that allows the "assign" macros to access the |
404 | * field types. | |
405 | */ | |
406 | ||
407 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
408 | ||
409 | /* Named field types must be defined in lttng-types.h */ | |
410 | ||
d71e6471 MD |
411 | #undef __field_full |
412 | #define __field_full(_type, _item, _order, _base) _type _item; | |
3c4ffab9 | 413 | |
d71e6471 MD |
414 | #undef __array_enc_ext |
415 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ | |
416 | _type _item; | |
64c796d8 | 417 | |
d71e6471 MD |
418 | #undef __dynamic_array_enc_ext |
419 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
420 | _type _item; | |
64c796d8 | 421 | |
3c4ffab9 MD |
422 | #undef __string |
423 | #define __string(_item, _src) char _item; | |
424 | ||
425 | #undef TP_STRUCT__entry | |
426 | #define TP_STRUCT__entry(args...) args | |
427 | ||
428 | #undef DECLARE_EVENT_CLASS | |
429 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
430 | struct __event_typemap__##_name { \ | |
431 | _tstruct \ | |
432 | }; | |
433 | ||
434 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
435 | ||
436 | ||
437 | /* | |
c099397a | 438 | * Stage 9 of the trace events. |
3c4ffab9 | 439 | * |
40652b65 MD |
440 | * Create the probe function : call even size calculation and write event data |
441 | * into the buffer. | |
e763dbf5 | 442 | * |
67e5e60c MD |
443 | * We use both the field and assignment macros to write the fields in the order |
444 | * defined in the field declaration. The field declarations control the | |
445 | * execution order, jumping to the appropriate assignment block. | |
40652b65 MD |
446 | */ |
447 | ||
e763dbf5 MD |
448 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
449 | ||
d71e6471 MD |
450 | #undef __field_full |
451 | #define __field_full(_type, _item, _order, _base) \ | |
e763dbf5 MD |
452 | goto __assign_##_item; \ |
453 | __end_field_##_item: | |
40652b65 | 454 | |
d71e6471 MD |
455 | #undef __array_enc_ext |
456 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
e763dbf5 MD |
457 | goto __assign_##_item; \ |
458 | __end_field_##_item: | |
40652b65 | 459 | |
d71e6471 MD |
460 | #undef __dynamic_array_enc_ext |
461 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ | |
e763dbf5 MD |
462 | goto __assign_##_item##_1; \ |
463 | __end_field_##_item##_1: \ | |
e763dbf5 MD |
464 | goto __assign_##_item##_2; \ |
465 | __end_field_##_item##_2: | |
40652b65 | 466 | |
e763dbf5 MD |
467 | #undef __string |
468 | #define __string(_item, _src) \ | |
469 | goto __assign_##_item; \ | |
470 | __end_field_##_item: | |
471 | ||
472 | /* | |
473 | * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to | |
474 | * strcpy(). | |
475 | */ | |
476 | #undef tp_assign | |
477 | #define tp_assign(dest, src) \ | |
478 | __assign_##dest: \ | |
479 | { \ | |
3c4ffab9 | 480 | __typeof__(__typemap.dest) __tmp = (src); \ |
aaa4004a MD |
481 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__tmp)); \ |
482 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ | |
e763dbf5 MD |
483 | } \ |
484 | goto __end_field_##dest; | |
485 | ||
486 | #undef tp_memcpy | |
487 | #define tp_memcpy(dest, src, len) \ | |
488 | __assign_##dest: \ | |
d793d5e1 MD |
489 | if (0) \ |
490 | (void) __typemap.dest; \ | |
aaa4004a MD |
491 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ |
492 | __chan->ops->event_write(&__ctx, src, len); \ | |
e763dbf5 MD |
493 | goto __end_field_##dest; |
494 | ||
495 | #undef tp_memcpy_dyn | |
41b59694 | 496 | #define tp_memcpy_dyn(dest, src) \ |
e763dbf5 MD |
497 | __assign_##dest##_1: \ |
498 | { \ | |
41b59694 | 499 | u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \ |
aaa4004a MD |
500 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(u32)); \ |
501 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \ | |
e763dbf5 MD |
502 | } \ |
503 | goto __end_field_##dest##_1; \ | |
504 | __assign_##dest##_2: \ | |
aaa4004a MD |
505 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ |
506 | __chan->ops->event_write(&__ctx, src, \ | |
41b59694 | 507 | sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\ |
e763dbf5 MD |
508 | goto __end_field_##dest##_2; |
509 | ||
510 | #undef tp_strcpy | |
511 | #define tp_strcpy(dest, src) \ | |
3c4ffab9 | 512 | tp_memcpy(dest, src, __get_dynamic_array_len(dest)) |
40652b65 | 513 | |
e763dbf5 MD |
514 | /* Named field types must be defined in lttng-types.h */ |
515 | ||
516 | #undef __get_str | |
517 | #define __get_str(field) field | |
518 | ||
519 | #undef __get_dynamic_array | |
520 | #define __get_dynamic_array(field) field | |
521 | ||
522 | /* Beware: this get len actually consumes the len value */ | |
523 | #undef __get_dynamic_array_len | |
524 | #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++] | |
525 | ||
526 | #undef TP_PROTO | |
527 | #define TP_PROTO(args...) args | |
528 | ||
529 | #undef TP_ARGS | |
530 | #define TP_ARGS(args...) args | |
531 | ||
532 | #undef TP_STRUCT__entry | |
533 | #define TP_STRUCT__entry(args...) args | |
534 | ||
535 | #undef TP_fast_assign | |
536 | #define TP_fast_assign(args...) args | |
537 | ||
538 | #undef DECLARE_EVENT_CLASS | |
539 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ | |
540 | static void __event_probe__##_name(void *__data, _proto) \ | |
541 | { \ | |
542 | struct ltt_event *__event = __data; \ | |
543 | struct ltt_channel *__chan = __event->chan; \ | |
aaa4004a | 544 | struct lib_ring_buffer_ctx __ctx; \ |
e763dbf5 MD |
545 | size_t __event_len, __event_align; \ |
546 | size_t __dynamic_len_idx = 0; \ | |
547 | size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \ | |
3c4ffab9 | 548 | struct __event_typemap__##_name __typemap; \ |
e763dbf5 MD |
549 | int __ret; \ |
550 | \ | |
551 | if (0) \ | |
552 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
e64957da MD |
553 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ |
554 | return; \ | |
555 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ | |
556 | return; \ | |
557 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ | |
52fc2e1f | 558 | return; \ |
e763dbf5 MD |
559 | __event_len = __event_get_size__##_name(__dynamic_len, _args); \ |
560 | __event_align = __event_get_align__##_name(_args); \ | |
aaa4004a | 561 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
e763dbf5 | 562 | __event_align, -1); \ |
aaa4004a | 563 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
e763dbf5 MD |
564 | if (__ret < 0) \ |
565 | return; \ | |
566 | /* Control code (field ordering) */ \ | |
567 | _tstruct \ | |
aaa4004a | 568 | __chan->ops->event_commit(&__ctx); \ |
e763dbf5 MD |
569 | return; \ |
570 | /* Copy code, steered by control code */ \ | |
571 | _assign \ | |
572 | } | |
573 | ||
f7bdf4db MD |
574 | #undef DECLARE_EVENT_CLASS_NOARGS |
575 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ | |
576 | static void __event_probe__##_name(void *__data) \ | |
577 | { \ | |
578 | struct ltt_event *__event = __data; \ | |
579 | struct ltt_channel *__chan = __event->chan; \ | |
580 | struct lib_ring_buffer_ctx __ctx; \ | |
581 | size_t __event_len, __event_align; \ | |
582 | int __ret; \ | |
583 | \ | |
584 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ | |
585 | return; \ | |
586 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ | |
587 | return; \ | |
588 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ | |
589 | return; \ | |
590 | __event_len = 0; \ | |
591 | __event_align = 1; \ | |
592 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ | |
593 | __event_align, -1); \ | |
594 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ | |
595 | if (__ret < 0) \ | |
596 | return; \ | |
597 | /* Control code (field ordering) */ \ | |
598 | _tstruct \ | |
599 | __chan->ops->event_commit(&__ctx); \ | |
600 | return; \ | |
601 | /* Copy code, steered by control code */ \ | |
602 | _assign \ | |
603 | } | |
604 | ||
e763dbf5 MD |
605 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
606 | ||
3afe7aac | 607 | /* |
c099397a | 608 | * Stage 10 of the trace events. |
3afe7aac MD |
609 | * |
610 | * Register/unregister probes at module load/unload. | |
611 | */ | |
612 | ||
613 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ | |
614 | ||
615 | #define TP_ID1(_token, _system) _token##_system | |
616 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
617 | #define module_init_eval1(_token, _system) module_init(_token##_system) | |
618 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) | |
619 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) | |
620 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) | |
621 | ||
259b6cb3 | 622 | #ifndef TP_MODULE_OVERRIDE |
3afe7aac MD |
623 | static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void) |
624 | { | |
6d2a620c | 625 | wrapper_vmalloc_sync_all(); |
259b6cb3 | 626 | return ltt_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
627 | } |
628 | ||
629 | module_init_eval(__lttng_events_init__, TRACE_SYSTEM); | |
630 | ||
3afe7aac MD |
631 | static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void) |
632 | { | |
259b6cb3 | 633 | ltt_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
634 | } |
635 | ||
636 | module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM); | |
259b6cb3 | 637 | #endif |
3afe7aac MD |
638 | |
639 | #undef module_init_eval | |
640 | #undef module_exit_eval | |
641 | #undef TP_ID1 | |
642 | #undef TP_ID | |
177b3692 MD |
643 | |
644 | #undef TP_PROTO | |
645 | #undef TP_ARGS | |
646 | #undef TRACE_EVENT_FLAGS |