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