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