Fix: tracepoint name remapping
[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
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 151void trace_##_name(_proto);
f62b389e 152
76e4f017
MD
153#undef DEFINE_EVENT_MAP_NOARGS
154#define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
f7bdf4db
MD
155void 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
3a50e00f
MD
239#undef __dynamic_array_enc_ext_2
240#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
241 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
242
64c796d8
MD
243#undef __dynamic_array
244#define __dynamic_array(_type, _item, _length) \
d71e6471 245 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
64c796d8
MD
246
247#undef __dynamic_array_text
248#define __dynamic_array_text(_type, _item, _length) \
d71e6471
MD
249 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
250
251#undef __dynamic_array_hex
252#define __dynamic_array_hex(_type, _item, _length) \
253 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
64c796d8 254
3a50e00f
MD
255#undef __dynamic_array_text_2
256#define __dynamic_array_text_2(_type, _item, _length1, _length2) \
257 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
258
40652b65 259#undef __string
1d12cebd 260#define __string(_item, _src) \
299338c8 261 { \
c099397a
MD
262 .name = #_item, \
263 .type = \
264 { \
299338c8 265 .atype = atype_string, \
c099397a 266 .u.basic.string.encoding = lttng_encode_UTF8, \
299338c8
MD
267 }, \
268 },
1d12cebd 269
c6e3f225
MD
270#undef __string_from_user
271#define __string_from_user(_item, _src) \
272 __string(_item, _src)
273
40652b65 274#undef TP_STRUCT__entry
1d12cebd
MD
275#define TP_STRUCT__entry(args...) args /* Only one used in this phase */
276
f7bdf4db
MD
277#undef DECLARE_EVENT_CLASS_NOARGS
278#define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
0d1d4002
MD
279 static const struct lttng_event_field __event_fields___##_name[] = { \
280 _tstruct \
299338c8
MD
281 };
282
f7bdf4db
MD
283#undef DECLARE_EVENT_CLASS
284#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
285 DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \
286 PARAMS(_print))
287
299338c8
MD
288#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
289
19c57fbf 290/*
c099397a 291 * Stage 3 of the trace events.
19c57fbf
MD
292 *
293 * Create probe callback prototypes.
294 */
295
296#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
297
298#undef TP_PROTO
299#define TP_PROTO(args...) args
300
301#undef DECLARE_EVENT_CLASS
302#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
303static void __event_probe__##_name(void *__data, _proto);
304
f7bdf4db
MD
305#undef DECLARE_EVENT_CLASS_NOARGS
306#define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
307static void __event_probe__##_name(void *__data);
308
19c57fbf
MD
309#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
310
299338c8 311/*
f7bdf4db 312 * Stage 3.9 of the trace events.
299338c8 313 *
f7bdf4db 314 * Create event descriptions.
299338c8
MD
315 */
316
299338c8
MD
317/* Named field types must be defined in lttng-types.h */
318
6db3d13b 319#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
299338c8 320
1ec65de1
MD
321#ifndef TP_PROBE_CB
322#define TP_PROBE_CB(_template) &__event_probe__##_template
323#endif
324
76e4f017
MD
325#undef DEFINE_EVENT_MAP_NOARGS
326#define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
327static const struct lttng_event_desc __event_desc___##_map = { \
f7bdf4db 328 .fields = __event_fields___##_template, \
76e4f017 329 .name = #_map, \
c991463e 330 .kname = #_name, \
f7bdf4db
MD
331 .probe_callback = (void *) TP_PROBE_CB(_template), \
332 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
333 .owner = THIS_MODULE, \
334};
335
76e4f017
MD
336#undef DEFINE_EVENT_MAP
337#define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
338 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
f7bdf4db
MD
339
340#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
341
342
343/*
344 * Stage 4 of the trace events.
345 *
346 * Create an array of event description pointers.
347 */
348
349/* Named field types must be defined in lttng-types.h */
350
351#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
352
76e4f017
MD
353#undef DEFINE_EVENT_MAP_NOARGS
354#define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
355 &__event_desc___##_map,
f7bdf4db 356
76e4f017
MD
357#undef DEFINE_EVENT_MAP
358#define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
359 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
40652b65 360
d0dd2ecb
MD
361#define TP_ID1(_token, _system) _token##_system
362#define TP_ID(_token, _system) TP_ID1(_token, _system)
40652b65 363
f7bdf4db 364static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
40652b65 365#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
299338c8
MD
366};
367
d0dd2ecb
MD
368#undef TP_ID1
369#undef TP_ID
370
85a9ca7f
MD
371
372/*
c099397a 373 * Stage 5 of the trace events.
85a9ca7f
MD
374 *
375 * Create a toplevel descriptor for the whole probe.
376 */
377
378#define TP_ID1(_token, _system) _token##_system
379#define TP_ID(_token, _system) TP_ID1(_token, _system)
380
381/* non-const because list head will be modified when registered. */
25631135 382static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
85a9ca7f
MD
383 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
384 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
385};
386
387#undef TP_ID1
388#undef TP_ID
389
d0dd2ecb 390/*
c099397a 391 * Stage 6 of the trace events.
40652b65
MD
392 *
393 * Create static inline function that calculates event size.
394 */
395
6db3d13b 396#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
40652b65 397
6db3d13b
MD
398/* Named field types must be defined in lttng-types.h */
399
d71e6471
MD
400#undef __field_full
401#define __field_full(_type, _item, _order, _base) \
a90917c3 402 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 403 __event_len += sizeof(_type);
6db3d13b 404
d71e6471
MD
405#undef __array_enc_ext
406#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
a90917c3 407 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 408 __event_len += sizeof(_type) * (_length);
6db3d13b 409
d71e6471
MD
410#undef __dynamic_array_enc_ext
411#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
a90917c3 412 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
85a80742 413 __event_len += sizeof(u32); \
a90917c3 414 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
41b59694
MD
415 __dynamic_len[__dynamic_len_idx] = (_length); \
416 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
417 __dynamic_len_idx++;
6db3d13b 418
3a50e00f
MD
419#undef __dynamic_array_enc_ext_2
420#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
421 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
422 __event_len += sizeof(u32); \
423 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
424 __dynamic_len[__dynamic_len_idx] = (_length1); \
425 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
426 __dynamic_len_idx++; \
427 __dynamic_len[__dynamic_len_idx] = (_length2); \
428 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
429 __dynamic_len_idx++;
430
6db3d13b 431#undef __string
85a80742 432#define __string(_item, _src) \
0d1d4002
MD
433 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
434
d0255731 435/*
786b8312
MD
436 * strlen_user includes \0. If returns 0, it faulted, so we set size to
437 * 1 (\0 only).
d0255731 438 */
c6e3f225
MD
439#undef __string_from_user
440#define __string_from_user(_item, _src) \
786b8312 441 __event_len += __dynamic_len[__dynamic_len_idx++] = \
7b8ea3a5 442 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
c6e3f225 443
0d1d4002
MD
444#undef TP_PROTO
445#define TP_PROTO(args...) args
6db3d13b
MD
446
447#undef TP_STRUCT__entry
0d1d4002 448#define TP_STRUCT__entry(args...) args
6db3d13b
MD
449
450#undef DECLARE_EVENT_CLASS
0d1d4002
MD
451#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
452static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
453{ \
454 size_t __event_len = 0; \
455 unsigned int __dynamic_len_idx = 0; \
456 \
457 if (0) \
458 (void) __dynamic_len_idx; /* don't warn if unused */ \
459 _tstruct \
460 return __event_len; \
6db3d13b 461}
40652b65
MD
462
463#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
464
465/*
c099397a 466 * Stage 7 of the trace events.
e763dbf5
MD
467 *
468 * Create static inline function that calculates event payload alignment.
469 */
470
471#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
472
473/* Named field types must be defined in lttng-types.h */
474
d71e6471
MD
475#undef __field_full
476#define __field_full(_type, _item, _order, _base) \
a90917c3 477 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
e763dbf5 478
d71e6471
MD
479#undef __array_enc_ext
480#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
a90917c3 481 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
e763dbf5 482
d71e6471
MD
483#undef __dynamic_array_enc_ext
484#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
a90917c3
MD
485 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
486 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
e763dbf5 487
3a50e00f
MD
488#undef __dynamic_array_enc_ext_2
489#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
490 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
491
e763dbf5
MD
492#undef __string
493#define __string(_item, _src)
494
c6e3f225
MD
495#undef __string_from_user
496#define __string_from_user(_item, _src)
497
e763dbf5
MD
498#undef TP_PROTO
499#define TP_PROTO(args...) args
500
501#undef TP_STRUCT__entry
502#define TP_STRUCT__entry(args...) args
503
504#undef DECLARE_EVENT_CLASS
505#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
506static inline size_t __event_get_align__##_name(_proto) \
507{ \
508 size_t __event_align = 1; \
509 _tstruct \
510 return __event_align; \
511}
512
513#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
514
515
e763dbf5 516/*
c099397a 517 * Stage 8 of the trace events.
40652b65 518 *
3c4ffab9
MD
519 * Create structure declaration that allows the "assign" macros to access the
520 * field types.
521 */
522
523#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
524
525/* Named field types must be defined in lttng-types.h */
526
d71e6471
MD
527#undef __field_full
528#define __field_full(_type, _item, _order, _base) _type _item;
3c4ffab9 529
d71e6471
MD
530#undef __array_enc_ext
531#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
532 _type _item;
64c796d8 533
d71e6471
MD
534#undef __dynamic_array_enc_ext
535#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
536 _type _item;
64c796d8 537
3a50e00f
MD
538#undef __dynamic_array_enc_ext_2
539#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
540 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
541
3c4ffab9 542#undef __string
c6e3f225
MD
543#define __string(_item, _src) char _item;
544
545#undef __string_from_user
546#define __string_from_user(_item, _src) \
547 __string(_item, _src)
3c4ffab9
MD
548
549#undef TP_STRUCT__entry
550#define TP_STRUCT__entry(args...) args
551
552#undef DECLARE_EVENT_CLASS
553#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
554struct __event_typemap__##_name { \
555 _tstruct \
556};
557
558#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
559
560
561/*
c099397a 562 * Stage 9 of the trace events.
3c4ffab9 563 *
40652b65
MD
564 * Create the probe function : call even size calculation and write event data
565 * into the buffer.
e763dbf5 566 *
67e5e60c
MD
567 * We use both the field and assignment macros to write the fields in the order
568 * defined in the field declaration. The field declarations control the
569 * execution order, jumping to the appropriate assignment block.
40652b65
MD
570 */
571
e763dbf5
MD
572#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
573
d71e6471
MD
574#undef __field_full
575#define __field_full(_type, _item, _order, _base) \
e763dbf5
MD
576 goto __assign_##_item; \
577__end_field_##_item:
40652b65 578
d71e6471
MD
579#undef __array_enc_ext
580#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
e763dbf5
MD
581 goto __assign_##_item; \
582__end_field_##_item:
40652b65 583
d71e6471
MD
584#undef __dynamic_array_enc_ext
585#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
e763dbf5
MD
586 goto __assign_##_item##_1; \
587__end_field_##_item##_1: \
e763dbf5
MD
588 goto __assign_##_item##_2; \
589__end_field_##_item##_2:
40652b65 590
3a50e00f
MD
591#undef __dynamic_array_enc_ext_2
592#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
593 goto __assign_##_item##_1; \
594__end_field_##_item##_1: \
595 goto __assign_##_item##_2; \
596__end_field_##_item##_2: \
597 goto __assign_##_item##_3; \
598__end_field_##_item##_3:
599
e763dbf5
MD
600#undef __string
601#define __string(_item, _src) \
602 goto __assign_##_item; \
603__end_field_##_item:
604
c6e3f225
MD
605#undef __string_from_user
606#define __string_from_user(_item, _src) \
607 __string(_item, _src)
608
e763dbf5
MD
609/*
610 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
611 * strcpy().
612 */
613#undef tp_assign
614#define tp_assign(dest, src) \
615__assign_##dest: \
616 { \
3c4ffab9 617 __typeof__(__typemap.dest) __tmp = (src); \
a90917c3 618 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
aaa4004a 619 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
e763dbf5
MD
620 } \
621 goto __end_field_##dest;
622
d9a7cf03
FG
623/* fixed length array memcpy */
624#undef tp_memcpy_gen
625#define tp_memcpy_gen(write_ops, dest, src, len) \
e763dbf5 626__assign_##dest: \
d793d5e1
MD
627 if (0) \
628 (void) __typemap.dest; \
a90917c3 629 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
d9a7cf03 630 __chan->ops->write_ops(&__ctx, src, len); \
e763dbf5
MD
631 goto __end_field_##dest;
632
d9a7cf03
FG
633#undef tp_memcpy
634#define tp_memcpy(dest, src, len) \
635 tp_memcpy_gen(event_write, dest, src, len)
636
637#undef tp_memcpy_from_user
638#define tp_memcpy_from_user(dest, src, len) \
639 tp_memcpy_gen(event_write_from_user, dest, src, len)
640
641/* variable length sequence memcpy */
642#undef tp_memcpy_dyn_gen
643#define tp_memcpy_dyn_gen(write_ops, dest, src) \
e763dbf5
MD
644__assign_##dest##_1: \
645 { \
41b59694 646 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
a90917c3 647 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
aaa4004a 648 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
e763dbf5
MD
649 } \
650 goto __end_field_##dest##_1; \
651__assign_##dest##_2: \
a90917c3 652 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
d9a7cf03 653 __chan->ops->write_ops(&__ctx, src, \
41b59694 654 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
e763dbf5 655 goto __end_field_##dest##_2;
58aa5d24 656
3a50e00f
MD
657#undef tp_memcpy_dyn_gen_2
658#define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
659__assign_##dest##_1: \
660 { \
661 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
662 + __dynamic_len[__dynamic_len_idx + 1]; \
663 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
664 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
665 } \
666 goto __end_field_##dest##_1; \
667__assign_##dest##_2: \
668 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
669 __chan->ops->write_ops(&__ctx, src1, \
670 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
671 goto __end_field_##dest##_2; \
672__assign_##dest##_3: \
673 __chan->ops->write_ops(&__ctx, src2, \
674 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
675 goto __end_field_##dest##_3;
676
d9a7cf03
FG
677#undef tp_memcpy_dyn
678#define tp_memcpy_dyn(dest, src) \
679 tp_memcpy_dyn_gen(event_write, dest, src)
680
3a50e00f
MD
681#undef tp_memcpy_dyn_2
682#define tp_memcpy_dyn_2(dest, src1, src2) \
683 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
684
d9a7cf03
FG
685#undef tp_memcpy_dyn_from_user
686#define tp_memcpy_dyn_from_user(dest, src) \
687 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
58aa5d24 688
d0255731 689/*
786b8312 690 * The string length including the final \0.
d0255731 691 */
4ea00e4f 692#undef tp_copy_string_from_user
58aa5d24 693#define tp_copy_string_from_user(dest, src) \
4ea00e4f 694 __assign_##dest: \
d0255731
MD
695 { \
696 size_t __ustrlen; \
697 \
698 if (0) \
699 (void) __typemap.dest; \
a90917c3 700 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));\
d0255731 701 __ustrlen = __get_dynamic_array_len(dest); \
b426d8af 702 if (likely(__ustrlen > 1)) { \
d0255731
MD
703 __chan->ops->event_write_from_user(&__ctx, src, \
704 __ustrlen - 1); \
705 } \
706 __chan->ops->event_memset(&__ctx, 0, 1); \
707 } \
4ea00e4f 708 goto __end_field_##dest;
e763dbf5
MD
709#undef tp_strcpy
710#define tp_strcpy(dest, src) \
3c4ffab9 711 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
40652b65 712
e763dbf5
MD
713/* Named field types must be defined in lttng-types.h */
714
715#undef __get_str
716#define __get_str(field) field
717
718#undef __get_dynamic_array
719#define __get_dynamic_array(field) field
720
721/* Beware: this get len actually consumes the len value */
722#undef __get_dynamic_array_len
723#define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
724
725#undef TP_PROTO
726#define TP_PROTO(args...) args
727
728#undef TP_ARGS
729#define TP_ARGS(args...) args
730
731#undef TP_STRUCT__entry
732#define TP_STRUCT__entry(args...) args
733
734#undef TP_fast_assign
735#define TP_fast_assign(args...) args
736
c337ddc2
MD
737/*
738 * For state dump, check that "session" argument (mandatory) matches the
739 * session this event belongs to. Ensures that we write state dump data only
740 * into the started session, not into all sessions.
741 */
742#ifdef TP_SESSION_CHECK
743#define _TP_SESSION_CHECK(session, csession) (session == csession)
744#else /* TP_SESSION_CHECK */
745#define _TP_SESSION_CHECK(session, csession) 1
746#endif /* TP_SESSION_CHECK */
747
7f88af10
MD
748/*
749 * __dynamic_len array length is twice the number of fields due to
750 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
751 * worse case, needing 2 entries per field.
752 */
e763dbf5
MD
753#undef DECLARE_EVENT_CLASS
754#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
755static void __event_probe__##_name(void *__data, _proto) \
756{ \
a90917c3
MD
757 struct lttng_event *__event = __data; \
758 struct lttng_channel *__chan = __event->chan; \
aaa4004a 759 struct lib_ring_buffer_ctx __ctx; \
e763dbf5
MD
760 size_t __event_len, __event_align; \
761 size_t __dynamic_len_idx = 0; \
7f88af10 762 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)]; \
3c4ffab9 763 struct __event_typemap__##_name __typemap; \
e763dbf5
MD
764 int __ret; \
765 \
c337ddc2 766 if (0) { \
e763dbf5 767 (void) __dynamic_len_idx; /* don't warn if unused */ \
c337ddc2
MD
768 (void) __typemap; /* don't warn if unused */ \
769 } \
770 if (!_TP_SESSION_CHECK(session, __chan->session)) \
771 return; \
e64957da
MD
772 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
773 return; \
774 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
775 return; \
776 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
52fc2e1f 777 return; \
e763dbf5
MD
778 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
779 __event_align = __event_get_align__##_name(_args); \
aaa4004a 780 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
e763dbf5 781 __event_align, -1); \
aaa4004a 782 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
e763dbf5
MD
783 if (__ret < 0) \
784 return; \
785 /* Control code (field ordering) */ \
786 _tstruct \
aaa4004a 787 __chan->ops->event_commit(&__ctx); \
e763dbf5
MD
788 return; \
789 /* Copy code, steered by control code */ \
790 _assign \
791}
792
f7bdf4db
MD
793#undef DECLARE_EVENT_CLASS_NOARGS
794#define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
795static void __event_probe__##_name(void *__data) \
796{ \
a90917c3
MD
797 struct lttng_event *__event = __data; \
798 struct lttng_channel *__chan = __event->chan; \
f7bdf4db
MD
799 struct lib_ring_buffer_ctx __ctx; \
800 size_t __event_len, __event_align; \
801 int __ret; \
802 \
c337ddc2
MD
803 if (!_TP_SESSION_CHECK(session, __chan->session)) \
804 return; \
f7bdf4db
MD
805 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
806 return; \
807 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
808 return; \
809 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
810 return; \
811 __event_len = 0; \
812 __event_align = 1; \
813 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
814 __event_align, -1); \
815 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
816 if (__ret < 0) \
817 return; \
818 /* Control code (field ordering) */ \
819 _tstruct \
820 __chan->ops->event_commit(&__ctx); \
821 return; \
822 /* Copy code, steered by control code */ \
823 _assign \
824}
825
e763dbf5
MD
826#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
827
3afe7aac 828/*
c099397a 829 * Stage 10 of the trace events.
3afe7aac
MD
830 *
831 * Register/unregister probes at module load/unload.
832 */
833
834#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
835
836#define TP_ID1(_token, _system) _token##_system
837#define TP_ID(_token, _system) TP_ID1(_token, _system)
838#define module_init_eval1(_token, _system) module_init(_token##_system)
839#define module_init_eval(_token, _system) module_init_eval1(_token, _system)
840#define module_exit_eval1(_token, _system) module_exit(_token##_system)
841#define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
842
2655f9ad 843#ifndef TP_MODULE_NOINIT
3afe7aac
MD
844static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
845{
6d2a620c 846 wrapper_vmalloc_sync_all();
a90917c3 847 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
3afe7aac
MD
848}
849
3afe7aac
MD
850static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
851{
a90917c3 852 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
3afe7aac
MD
853}
854
2655f9ad
MD
855#ifndef TP_MODULE_NOAUTOLOAD
856module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
3afe7aac 857module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
259b6cb3 858#endif
3afe7aac 859
2655f9ad
MD
860#endif
861
3afe7aac
MD
862#undef module_init_eval
863#undef module_exit_eval
864#undef TP_ID1
865#undef TP_ID
177b3692
MD
866
867#undef TP_PROTO
868#undef TP_ARGS
869#undef TRACE_EVENT_FLAGS
This page took 0.07004 seconds and 4 git commands to generate.