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