Tracepoint event: add "TP_code_post()"
[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>
f127e61e 5 * Copyright (C) 2009-2014 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 */
f127e61e 21
d28686c1 22#include <linux/uaccess.h>
d0dd2ecb 23#include <linux/debugfs.h>
f127e61e 24#include <linux/rculist.h>
43803cf2 25#include <asm/byteorder.h>
c0edae1d
MD
26#include "lttng.h"
27#include "lttng-types.h"
7b8ea3a5 28#include "lttng-probe-user.h"
b13f3ebe 29#include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
f3bc08c5 30#include "../wrapper/ringbuffer/frontend_types.h"
7a09dcb7 31#include "../wrapper/rcu.h"
a90917c3
MD
32#include "../lttng-events.h"
33#include "../lttng-tracer-core.h"
40652b65 34
40652b65 35/*
6db3d13b 36 * Macro declarations used for all stages.
40652b65
MD
37 */
38
76e4f017
MD
39/*
40 * LTTng name mapping macros. LTTng remaps some of the kernel events to
41 * enforce name-spacing.
42 */
3bc29f0a 43#undef LTTNG_TRACEPOINT_EVENT_MAP
f127e61e 44#define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
3bc29f0a 45 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
76e4f017
MD
46 PARAMS(proto), \
47 PARAMS(args), \
f127e61e 48 PARAMS(fields)) \
3bc29f0a 49 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
76e4f017 50
3bc29f0a 51#undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
f127e61e 52#define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
3bc29f0a 53 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
f127e61e 54 PARAMS(fields)) \
3bc29f0a 55 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
76e4f017 56
f127e61e 57#undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
265822ae 58#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
f127e61e
MD
59 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
60 PARAMS(proto), \
61 PARAMS(args), \
62 PARAMS(_locvar), \
265822ae
MD
63 PARAMS(_code_pre), \
64 PARAMS(fields), \
65 PARAMS(_code_post)) \
f127e61e
MD
66 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
67
3bc29f0a 68#undef LTTNG_TRACEPOINT_EVENT_CODE
265822ae 69#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
f127e61e 70 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
7ca580f8
MD
71 PARAMS(proto), \
72 PARAMS(args), \
73 PARAMS(_locvar), \
265822ae
MD
74 PARAMS(_code_pre), \
75 PARAMS(fields), \
76 PARAMS(_code_post))
fcf7fa33 77
40652b65 78/*
3bc29f0a
MD
79 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
80 * handlers for events. That is, if all events have the same parameters
81 * and just have distinct trace points. Each tracepoint can be defined
82 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
83 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
40652b65 84 *
3bc29f0a
MD
85 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
86 * template.
40652b65 87 */
6db3d13b 88
3bc29f0a 89#undef LTTNG_TRACEPOINT_EVENT
f127e61e 90#define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
3bc29f0a
MD
91 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
92 PARAMS(proto), \
93 PARAMS(args), \
f127e61e 94 PARAMS(fields))
40652b65 95
3bc29f0a 96#undef LTTNG_TRACEPOINT_EVENT_NOARGS
f127e61e
MD
97#define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
98 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
76e4f017 99
3bc29f0a
MD
100#undef LTTNG_TRACEPOINT_EVENT_INSTANCE
101#define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
102 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
76e4f017 103
3bc29f0a
MD
104#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
105#define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
106 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
76e4f017 107
3bc29f0a 108#undef LTTNG_TRACEPOINT_EVENT_CLASS
f127e61e 109#define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
3bc29f0a 110 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
265822ae 111 PARAMS(_fields), )
7ca580f8 112
3bc29f0a 113#undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
f127e61e 114#define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
265822ae 115 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
7ca580f8
MD
116
117
f62b389e 118/*
c099397a 119 * Stage 1 of the trace events.
f62b389e
MD
120 *
121 * Create dummy trace calls for each events, verifying that the LTTng module
3bc29f0a
MD
122 * instrumentation headers match the kernel arguments. Will be optimized
123 * out by the compiler.
f62b389e
MD
124 */
125
f127e61e
MD
126/* Reset all macros within TRACEPOINT_EVENT */
127#include "lttng-events-reset.h"
f62b389e
MD
128
129#undef TP_PROTO
f127e61e 130#define TP_PROTO(...) __VA_ARGS__
f62b389e
MD
131
132#undef TP_ARGS
f127e61e 133#define TP_ARGS(...) __VA_ARGS__
f62b389e 134
3bc29f0a
MD
135#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
136#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
7eb827f2 137void trace_##_name(_proto);
f62b389e 138
3bc29f0a
MD
139#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
140#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
cb1aa0c7 141void trace_##_name(void);
f7bdf4db 142
f62b389e
MD
143#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
144
d0558de2
MD
145/*
146 * Stage 1.1 of the trace events.
147 *
148 * Create dummy trace prototypes for each event class, and for each used
149 * template. This will allow checking whether the prototypes from the
150 * class and the instance using the class actually match.
151 */
152
153#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
154
155#undef TP_PROTO
156#define TP_PROTO(...) __VA_ARGS__
157
158#undef TP_ARGS
159#define TP_ARGS(...) __VA_ARGS__
160
161#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
162#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
163void __event_template_proto___##_template(_proto);
164
165#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
166#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
167void __event_template_proto___##_template(void);
168
169#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265822ae 170#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
d0558de2
MD
171void __event_template_proto___##_name(_proto);
172
173#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
265822ae 174#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
d0558de2
MD
175void __event_template_proto___##_name(void);
176
177#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
178
6db3d13b 179/*
c099397a 180 * Stage 2 of the trace events.
6db3d13b
MD
181 *
182 * Create event field type metadata section.
183 * Each event produce an array of fields.
184 */
185
f127e61e
MD
186/* Reset all macros within TRACEPOINT_EVENT */
187#include "lttng-events-reset.h"
188#include "lttng-events-write.h"
189#include "lttng-events-nowrite.h"
6db3d13b 190
f127e61e
MD
191#undef _ctf_integer_ext
192#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
c099397a
MD
193 { \
194 .name = #_item, \
43803cf2 195 .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none),\
f127e61e
MD
196 .nowrite = _nowrite, \
197 .user = _user, \
c099397a 198 },
40652b65 199
f127e61e
MD
200#undef _ctf_array_encoded
201#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
299338c8 202 { \
c099397a
MD
203 .name = #_item, \
204 .type = \
205 { \
299338c8 206 .atype = atype_array, \
f127e61e 207 .u = \
c099397a 208 { \
f127e61e
MD
209 .array = \
210 { \
43803cf2 211 .elem_type = __type_integer(_type, 0, 0, 0, __BYTE_ORDER, 10, _encoding), \
f127e61e
MD
212 .length = _length, \
213 } \
214 } \
299338c8 215 }, \
f127e61e
MD
216 .nowrite = _nowrite, \
217 .user = _user, \
299338c8 218 },
40652b65 219
43803cf2
MD
220#undef _ctf_array_bitfield
221#define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
222 { \
223 .name = #_item, \
224 .type = \
225 { \
226 .atype = atype_array, \
227 .u = \
228 { \
229 .array = \
230 { \
231 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
232 .length = (_length) * sizeof(_type) * CHAR_BIT, \
233 .elem_alignment = lttng_alignof(_type), \
234 } \
235 } \
236 }, \
237 .nowrite = _nowrite, \
238 .user = _user, \
239 },
240
241
f127e61e
MD
242#undef _ctf_sequence_encoded
243#define _ctf_sequence_encoded(_type, _item, _src, \
244 _length_type, _src_length, _encoding, \
57ede728 245 _byte_order, _base, _user, _nowrite) \
299338c8 246 { \
c099397a
MD
247 .name = #_item, \
248 .type = \
249 { \
299338c8 250 .atype = atype_sequence, \
f127e61e 251 .u = \
c099397a 252 { \
f127e61e
MD
253 .sequence = \
254 { \
43803cf2
MD
255 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
256 .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _base, _encoding), \
257 }, \
258 }, \
259 }, \
260 .nowrite = _nowrite, \
261 .user = _user, \
262 },
263
264#undef _ctf_sequence_bitfield
265#define _ctf_sequence_bitfield(_type, _item, _src, \
266 _length_type, _src_length, \
267 _user, _nowrite) \
268 { \
269 .name = #_item, \
270 .type = \
271 { \
272 .atype = atype_sequence, \
273 .u = \
274 { \
275 .sequence = \
276 { \
277 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
278 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
279 .elem_alignment = lttng_alignof(_type), \
f127e61e 280 }, \
c099397a 281 }, \
299338c8 282 }, \
f127e61e
MD
283 .nowrite = _nowrite, \
284 .user = _user, \
299338c8 285 },
40652b65 286
f127e61e
MD
287#undef _ctf_string
288#define _ctf_string(_item, _src, _user, _nowrite) \
299338c8 289 { \
c099397a
MD
290 .name = #_item, \
291 .type = \
292 { \
299338c8 293 .atype = atype_string, \
f127e61e
MD
294 .u = \
295 { \
296 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
297 }, \
299338c8 298 }, \
f127e61e
MD
299 .nowrite = _nowrite, \
300 .user = _user, \
299338c8 301 },
1d12cebd 302
f127e61e
MD
303#undef TP_FIELDS
304#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1d12cebd 305
3bc29f0a 306#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
265822ae 307#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
0d1d4002 308 static const struct lttng_event_field __event_fields___##_name[] = { \
f127e61e 309 _fields \
299338c8
MD
310 };
311
3bc29f0a 312#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265822ae
MD
313#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
314 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
f7bdf4db 315
299338c8
MD
316#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
317
19c57fbf 318/*
c099397a 319 * Stage 3 of the trace events.
19c57fbf
MD
320 *
321 * Create probe callback prototypes.
322 */
323
f127e61e
MD
324/* Reset all macros within TRACEPOINT_EVENT */
325#include "lttng-events-reset.h"
19c57fbf
MD
326
327#undef TP_PROTO
f127e61e 328#define TP_PROTO(...) __VA_ARGS__
19c57fbf 329
3bc29f0a 330#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265822ae 331#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
19c57fbf
MD
332static void __event_probe__##_name(void *__data, _proto);
333
3bc29f0a 334#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
265822ae 335#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
f7bdf4db
MD
336static void __event_probe__##_name(void *__data);
337
19c57fbf
MD
338#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
339
f7bdf4db
MD
340/*
341 * Stage 4 of the trace events.
342 *
40652b65
MD
343 * Create static inline function that calculates event size.
344 */
345
f127e61e
MD
346/* Reset all macros within TRACEPOINT_EVENT */
347#include "lttng-events-reset.h"
348#include "lttng-events-write.h"
6db3d13b 349
f127e61e
MD
350#undef _ctf_integer_ext
351#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
a90917c3 352 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 353 __event_len += sizeof(_type);
6db3d13b 354
f127e61e
MD
355#undef _ctf_array_encoded
356#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
a90917c3 357 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 358 __event_len += sizeof(_type) * (_length);
6db3d13b 359
43803cf2
MD
360#undef _ctf_array_bitfield
361#define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
362 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
363
f127e61e
MD
364#undef _ctf_sequence_encoded
365#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 366 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
f127e61e
MD
367 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
368 __event_len += sizeof(_length_type); \
a90917c3 369 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
f127e61e 370 __dynamic_len[__dynamic_len_idx] = (_src_length); \
41b59694
MD
371 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
372 __dynamic_len_idx++;
6db3d13b 373
43803cf2
MD
374#undef _ctf_sequence_bitfield
375#define _ctf_sequence_bitfield(_type, _item, _src, \
376 _length_type, _src_length, \
377 _user, _nowrite) \
378 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
379 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
380
d0255731 381/*
f127e61e 382 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
786b8312 383 * 1 (\0 only).
d0255731 384 */
f127e61e
MD
385#undef _ctf_string
386#define _ctf_string(_item, _src, _user, _nowrite) \
387 if (_user) \
388 __event_len += __dynamic_len[__dynamic_len_idx++] = \
96d0248a 389 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
f127e61e
MD
390 else \
391 __event_len += __dynamic_len[__dynamic_len_idx++] = \
96d0248a 392 strlen(_src) + 1;
c6e3f225 393
0d1d4002 394#undef TP_PROTO
f127e61e 395#define TP_PROTO(...) __VA_ARGS__
6db3d13b 396
f127e61e
MD
397#undef TP_FIELDS
398#define TP_FIELDS(...) __VA_ARGS__
6db3d13b 399
7ca580f8
MD
400#undef TP_locvar
401#define TP_locvar(...) __VA_ARGS__
402
3bc29f0a 403#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265822ae 404#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
7ca580f8
MD
405static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
406 void *__tp_locvar, _proto) \
0d1d4002
MD
407{ \
408 size_t __event_len = 0; \
d3de7f14 409 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
7ca580f8 410 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
d3de7f14 411 \
f127e61e 412 _fields \
d3de7f14
MD
413 return __event_len; \
414}
415
3bc29f0a 416#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
265822ae 417#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
7ca580f8
MD
418static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
419 void *__tp_locvar) \
d3de7f14
MD
420{ \
421 size_t __event_len = 0; \
422 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
7ca580f8 423 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
0d1d4002 424 \
f127e61e 425 _fields \
0d1d4002 426 return __event_len; \
6db3d13b 427}
40652b65
MD
428
429#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
430
f127e61e 431
40652b65 432/*
f127e61e 433 * Stage 4.1 of tracepoint event generation.
e763dbf5 434 *
f127e61e
MD
435 * Create static inline function that layout the filter stack data.
436 * We make both write and nowrite data available to the filter.
e763dbf5
MD
437 */
438
f127e61e
MD
439/* Reset all macros within TRACEPOINT_EVENT */
440#include "lttng-events-reset.h"
441#include "lttng-events-write.h"
442#include "lttng-events-nowrite.h"
443
444#undef _ctf_integer_ext_fetched
445#define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
446 if (lttng_is_signed_type(_type)) { \
447 int64_t __ctf_tmp_int64; \
448 switch (sizeof(_type)) { \
449 case 1: \
450 { \
451 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
452 __ctf_tmp_int64 = (int64_t) __tmp.v; \
453 break; \
454 } \
455 case 2: \
456 { \
457 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
458 __ctf_tmp_int64 = (int64_t) __tmp.v; \
459 break; \
460 } \
461 case 4: \
462 { \
463 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
464 __ctf_tmp_int64 = (int64_t) __tmp.v; \
465 break; \
466 } \
467 case 8: \
468 { \
469 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
470 __ctf_tmp_int64 = (int64_t) __tmp.v; \
471 break; \
472 } \
473 default: \
474 BUG_ON(1); \
475 }; \
476 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
477 } else { \
478 uint64_t __ctf_tmp_uint64; \
479 switch (sizeof(_type)) { \
480 case 1: \
481 { \
482 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
483 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
484 break; \
485 } \
486 case 2: \
487 { \
488 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
489 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
490 break; \
491 } \
492 case 4: \
493 { \
494 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
495 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
496 break; \
497 } \
498 case 8: \
499 { \
500 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
501 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
502 break; \
503 } \
504 default: \
505 BUG_ON(1); \
506 }; \
507 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
508 } \
509 __stack_data += sizeof(int64_t);
510
511#undef _ctf_integer_ext_isuser0
512#define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
513 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
514
515#undef _ctf_integer_ext_isuser1
516#define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
517{ \
518 __typeof__(_user_src) _src; \
519 if (get_user(_src, &(_user_src))) \
520 _src = 0; \
521 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
522}
e763dbf5 523
f127e61e
MD
524#undef _ctf_integer_ext
525#define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
526 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
527
528#undef _ctf_array_encoded
529#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
530 { \
531 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
532 const void *__ctf_tmp_ptr = (_src); \
533 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
534 __stack_data += sizeof(unsigned long); \
6b272cda
MD
535 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
536 __stack_data += sizeof(void *); \
f127e61e
MD
537 }
538
43803cf2
MD
539#undef _ctf_array_bitfield
540#define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
541 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
542
f127e61e
MD
543#undef _ctf_sequence_encoded
544#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 545 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
f127e61e
MD
546 { \
547 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
548 const void *__ctf_tmp_ptr = (_src); \
549 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
550 __stack_data += sizeof(unsigned long); \
6b272cda
MD
551 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
552 __stack_data += sizeof(void *); \
f127e61e
MD
553 }
554
43803cf2
MD
555#undef _ctf_sequence_bitfield
556#define _ctf_sequence_bitfield(_type, _item, _src, \
557 _length_type, _src_length, \
558 _user, _nowrite) \
559 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
560 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
561
f127e61e
MD
562#undef _ctf_string
563#define _ctf_string(_item, _src, _user, _nowrite) \
564 { \
565 const void *__ctf_tmp_ptr = (_src); \
6b272cda
MD
566 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
567 __stack_data += sizeof(void *); \
f127e61e 568 }
c6e3f225 569
e763dbf5 570#undef TP_PROTO
f127e61e 571#define TP_PROTO(...) __VA_ARGS__
e763dbf5 572
f127e61e
MD
573#undef TP_FIELDS
574#define TP_FIELDS(...) __VA_ARGS__
e763dbf5 575
7ca580f8
MD
576#undef TP_locvar
577#define TP_locvar(...) __VA_ARGS__
578
f127e61e 579#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
265822ae 580#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
f127e61e
MD
581static inline \
582void __event_prepare_filter_stack__##_name(char *__stack_data, \
583 void *__tp_locvar) \
e763dbf5 584{ \
7ca580f8
MD
585 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
586 \
f127e61e 587 _fields \
e763dbf5
MD
588}
589
f127e61e 590#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265822ae 591#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
f127e61e
MD
592static inline \
593void __event_prepare_filter_stack__##_name(char *__stack_data, \
594 void *__tp_locvar, _proto) \
d3de7f14 595{ \
7ca580f8
MD
596 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
597 \
f127e61e 598 _fields \
d3de7f14
MD
599}
600
e763dbf5
MD
601#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
602
e763dbf5 603/*
f127e61e 604 * Stage 5 of the trace events.
40652b65 605 *
f127e61e 606 * Create static inline function that calculates event payload alignment.
3c4ffab9
MD
607 */
608
f127e61e
MD
609/* Reset all macros within TRACEPOINT_EVENT */
610#include "lttng-events-reset.h"
611#include "lttng-events-write.h"
3c4ffab9 612
f127e61e
MD
613#undef _ctf_integer_ext
614#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
615 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
3c4ffab9 616
f127e61e
MD
617#undef _ctf_array_encoded
618#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
619 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
3c4ffab9 620
43803cf2
MD
621#undef _ctf_array_bitfield
622#define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
623 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
624
f127e61e
MD
625#undef _ctf_sequence_encoded
626#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 627 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
f127e61e
MD
628 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
629 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
64c796d8 630
43803cf2
MD
631#undef _ctf_sequence_bitfield
632#define _ctf_sequence_bitfield(_type, _item, _src, \
633 _length_type, _src_length, \
634 _user, _nowrite) \
635 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
636 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
637
f127e61e
MD
638#undef _ctf_string
639#define _ctf_string(_item, _src, _user, _nowrite)
64c796d8 640
f127e61e
MD
641#undef TP_PROTO
642#define TP_PROTO(...) __VA_ARGS__
84da5206 643
f127e61e
MD
644#undef TP_FIELDS
645#define TP_FIELDS(...) __VA_ARGS__
c6e3f225 646
f127e61e
MD
647#undef TP_locvar
648#define TP_locvar(...) __VA_ARGS__
3c4ffab9 649
f127e61e 650#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265822ae 651#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
f127e61e
MD
652static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
653{ \
654 size_t __event_align = 1; \
655 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
656 \
657 _fields \
658 return __event_align; \
659}
3c4ffab9 660
3bc29f0a 661#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
265822ae 662#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
f127e61e
MD
663static inline size_t __event_get_align__##_name(void *__tp_locvar) \
664{ \
665 size_t __event_align = 1; \
666 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
667 \
668 _fields \
669 return __event_align; \
670}
d3de7f14 671
3c4ffab9
MD
672#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
673
3c4ffab9 674/*
f127e61e 675 * Stage 6 of tracepoint event generation.
e763dbf5 676 *
f127e61e
MD
677 * Create the probe function. This function calls event size calculation
678 * and writes event data into the buffer.
40652b65
MD
679 */
680
f127e61e
MD
681/* Reset all macros within TRACEPOINT_EVENT */
682#include "lttng-events-reset.h"
683#include "lttng-events-write.h"
c6e3f225 684
f127e61e
MD
685#undef _ctf_integer_ext_fetched
686#define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
e763dbf5 687 { \
f127e61e
MD
688 _type __tmp = _src; \
689 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
aaa4004a 690 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
f127e61e
MD
691 }
692
693#undef _ctf_integer_ext_isuser0
694#define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
695 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
696
697#undef _ctf_integer_ext_isuser1
698#define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
699{ \
700 __typeof__(_user_src) _src; \
701 if (get_user(_src, &(_user_src))) \
702 _src = 0; \
703 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
704}
705
706#undef _ctf_integer_ext
707#define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
708 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
709
710#undef _ctf_array_encoded
711#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
712 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
713 if (_user) { \
714 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
715 } else { \
716 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
717 }
718
43803cf2
MD
719#if (__BYTE_ORDER == __LITTLE_ENDIAN)
720#undef _ctf_array_bitfield
721#define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
722 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
723 if (_user) { \
724 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
725 } else { \
726 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
727 }
728#else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
729/*
730 * For big endian, we need to byteswap into little endian.
731 */
732#undef _ctf_array_bitfield
733#define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
734 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
735 { \
736 size_t _i; \
737 \
738 for (_i = 0; _i < (_length); _i++) { \
739 _type _tmp; \
740 \
741 if (_user) { \
742 if (get_user(_tmp, (_type *) _src + _i)) \
743 _tmp = 0; \
744 } else { \
745 _tmp = ((_type *) _src)[_i]; \
746 } \
747 switch (sizeof(_type)) { \
748 case 1: \
749 break; \
750 case 2: \
751 _tmp = cpu_to_le16(_tmp); \
752 break; \
753 case 4: \
754 _tmp = cpu_to_le32(_tmp); \
755 break; \
756 case 8: \
757 _tmp = cpu_to_le64(_tmp); \
758 break; \
759 default: \
760 BUG_ON(1); \
761 } \
762 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
763 } \
764 }
765#endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
766
f127e61e
MD
767#undef _ctf_sequence_encoded
768#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 769 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
84da5206 770 { \
f127e61e
MD
771 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
772 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
773 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
84da5206 774 } \
f127e61e
MD
775 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
776 if (_user) { \
777 __chan->ops->event_write_from_user(&__ctx, _src, \
778 sizeof(_type) * __get_dynamic_len(dest)); \
779 } else { \
780 __chan->ops->event_write(&__ctx, _src, \
781 sizeof(_type) * __get_dynamic_len(dest)); \
782 }
783
43803cf2
MD
784#if (__BYTE_ORDER == __LITTLE_ENDIAN)
785#undef _ctf_sequence_bitfield
786#define _ctf_sequence_bitfield(_type, _item, _src, \
787 _length_type, _src_length, \
788 _user, _nowrite) \
789 { \
790 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
791 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
792 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
793 } \
794 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
795 if (_user) { \
796 __chan->ops->event_write_from_user(&__ctx, _src, \
797 sizeof(_type) * __get_dynamic_len(dest)); \
798 } else { \
799 __chan->ops->event_write(&__ctx, _src, \
800 sizeof(_type) * __get_dynamic_len(dest)); \
801 }
802#else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
803/*
804 * For big endian, we need to byteswap into little endian.
805 */
806#undef _ctf_sequence_bitfield
807#define _ctf_sequence_bitfield(_type, _item, _src, \
808 _length_type, _src_length, \
809 _user, _nowrite) \
810 { \
811 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
812 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
813 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
814 } \
815 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
816 { \
817 size_t _i, _length; \
818 \
819 _length = __get_dynamic_len(dest); \
820 for (_i = 0; _i < _length; _i++) { \
821 _type _tmp; \
822 \
823 if (_user) { \
824 if (get_user(_tmp, (_type *) _src + _i)) \
825 _tmp = 0; \
826 } else { \
827 _tmp = ((_type *) _src)[_i]; \
828 } \
829 switch (sizeof(_type)) { \
830 case 1: \
831 break; \
832 case 2: \
833 _tmp = cpu_to_le16(_tmp); \
834 break; \
835 case 4: \
836 _tmp = cpu_to_le32(_tmp); \
837 break; \
838 case 8: \
839 _tmp = cpu_to_le64(_tmp); \
840 break; \
841 default: \
842 BUG_ON(1); \
843 } \
844 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
845 } \
846 }
847#endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
848
f127e61e
MD
849#undef _ctf_string
850#define _ctf_string(_item, _src, _user, _nowrite) \
851 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
852 if (_user) { \
853 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
854 __get_dynamic_len(dest)); \
855 } else { \
856 __chan->ops->event_strcpy(&__ctx, _src, \
857 __get_dynamic_len(dest)); \
858 }
e763dbf5
MD
859
860/* Beware: this get len actually consumes the len value */
f127e61e
MD
861#undef __get_dynamic_len
862#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
e763dbf5
MD
863
864#undef TP_PROTO
f127e61e 865#define TP_PROTO(...) __VA_ARGS__
e763dbf5
MD
866
867#undef TP_ARGS
f127e61e 868#define TP_ARGS(...) __VA_ARGS__
e763dbf5 869
f127e61e
MD
870#undef TP_FIELDS
871#define TP_FIELDS(...) __VA_ARGS__
e763dbf5 872
7ca580f8
MD
873#undef TP_locvar
874#define TP_locvar(...) __VA_ARGS__
875
265822ae
MD
876#undef TP_code_pre
877#define TP_code_pre(...) __VA_ARGS__
878
879#undef TP_code_post
880#define TP_code_post(...) __VA_ARGS__
7ca580f8 881
c337ddc2
MD
882/*
883 * For state dump, check that "session" argument (mandatory) matches the
884 * session this event belongs to. Ensures that we write state dump data only
885 * into the started session, not into all sessions.
886 */
887#ifdef TP_SESSION_CHECK
888#define _TP_SESSION_CHECK(session, csession) (session == csession)
889#else /* TP_SESSION_CHECK */
890#define _TP_SESSION_CHECK(session, csession) 1
891#endif /* TP_SESSION_CHECK */
892
f9771d39 893/*
f127e61e
MD
894 * Using twice size for filter stack data to hold size and pointer for
895 * each field (worse case). For integers, max size required is 64-bit.
896 * Same for double-precision floats. Those fit within
897 * 2*sizeof(unsigned long) for all supported architectures.
898 * Perform UNION (||) of filter runtime list.
f9771d39 899 */
3bc29f0a 900#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
265822ae 901#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
e763dbf5
MD
902static void __event_probe__##_name(void *__data, _proto) \
903{ \
7ca580f8 904 struct probe_local_vars { _locvar }; \
a90917c3
MD
905 struct lttng_event *__event = __data; \
906 struct lttng_channel *__chan = __event->chan; \
e0130fab 907 struct lttng_session *__session = __chan->session; \
aaa4004a 908 struct lib_ring_buffer_ctx __ctx; \
e763dbf5 909 size_t __event_len, __event_align; \
d3de7f14 910 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
f127e61e
MD
911 union { \
912 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
913 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
914 } __stackvar; \
e763dbf5 915 int __ret; \
7ca580f8
MD
916 struct probe_local_vars __tp_locvar; \
917 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
918 &__tp_locvar; \
e0130fab 919 struct lttng_pid_tracker *__lpf; \
e763dbf5 920 \
e0130fab 921 if (!_TP_SESSION_CHECK(session, __session)) \
c337ddc2 922 return; \
e0130fab 923 if (unlikely(!ACCESS_ONCE(__session->active))) \
e64957da
MD
924 return; \
925 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
926 return; \
927 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
52fc2e1f 928 return; \
7a09dcb7 929 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
e0130fab
MD
930 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
931 return; \
265822ae 932 _code_pre \
f127e61e
MD
933 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
934 struct lttng_bytecode_runtime *bc_runtime; \
935 int __filter_record = __event->has_enablers_without_bytecode; \
936 \
937 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
938 tp_locvar, _args); \
7a09dcb7 939 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
f127e61e
MD
940 if (unlikely(bc_runtime->filter(bc_runtime, \
941 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
942 __filter_record = 1; \
943 } \
944 if (likely(!__filter_record)) \
265822ae 945 goto __post; \
f127e61e
MD
946 } \
947 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
948 tp_locvar, _args); \
7ca580f8 949 __event_align = __event_get_align__##_name(tp_locvar, _args); \
aaa4004a 950 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
e763dbf5 951 __event_align, -1); \
aaa4004a 952 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
e763dbf5 953 if (__ret < 0) \
265822ae 954 goto __post; \
f127e61e 955 _fields \
aaa4004a 956 __chan->ops->event_commit(&__ctx); \
265822ae
MD
957__post: \
958 _code_post \
959 return; \
e763dbf5
MD
960}
961
3bc29f0a 962#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
265822ae 963#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
f7bdf4db
MD
964static void __event_probe__##_name(void *__data) \
965{ \
7ca580f8 966 struct probe_local_vars { _locvar }; \
a90917c3
MD
967 struct lttng_event *__event = __data; \
968 struct lttng_channel *__chan = __event->chan; \
e0130fab 969 struct lttng_session *__session = __chan->session; \
f7bdf4db
MD
970 struct lib_ring_buffer_ctx __ctx; \
971 size_t __event_len, __event_align; \
d3de7f14 972 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
f127e61e
MD
973 union { \
974 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
975 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
976 } __stackvar; \
f7bdf4db 977 int __ret; \
7ca580f8
MD
978 struct probe_local_vars __tp_locvar; \
979 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
980 &__tp_locvar; \
e0130fab 981 struct lttng_pid_tracker *__lpf; \
f7bdf4db 982 \
e0130fab 983 if (!_TP_SESSION_CHECK(session, __session)) \
c337ddc2 984 return; \
e0130fab 985 if (unlikely(!ACCESS_ONCE(__session->active))) \
f7bdf4db
MD
986 return; \
987 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
988 return; \
989 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
990 return; \
7a09dcb7 991 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
e0130fab
MD
992 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
993 return; \
265822ae 994 _code_pre \
f127e61e
MD
995 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
996 struct lttng_bytecode_runtime *bc_runtime; \
997 int __filter_record = __event->has_enablers_without_bytecode; \
998 \
999 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1000 tp_locvar); \
7a09dcb7 1001 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
f127e61e
MD
1002 if (unlikely(bc_runtime->filter(bc_runtime, \
1003 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1004 __filter_record = 1; \
1005 } \
1006 if (likely(!__filter_record)) \
265822ae 1007 goto __post; \
f127e61e
MD
1008 } \
1009 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
7ca580f8 1010 __event_align = __event_get_align__##_name(tp_locvar); \
f7bdf4db
MD
1011 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
1012 __event_align, -1); \
1013 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1014 if (__ret < 0) \
265822ae 1015 goto __post; \
f127e61e 1016 _fields \
f7bdf4db 1017 __chan->ops->event_commit(&__ctx); \
265822ae
MD
1018__post: \
1019 _code_post \
1020 return; \
f7bdf4db
MD
1021}
1022
e763dbf5
MD
1023#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1024
f127e61e
MD
1025#undef __get_dynamic_len
1026
1027/*
1028 * Stage 7 of the trace events.
1029 *
1030 * Create event descriptions.
1031 */
1032
1033/* Named field types must be defined in lttng-types.h */
1034
1035#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1036
1037#ifndef TP_PROBE_CB
1038#define TP_PROBE_CB(_template) &__event_probe__##_template
1039#endif
1040
1041#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1042#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1043static const struct lttng_event_desc __event_desc___##_map = { \
1044 .fields = __event_fields___##_template, \
1045 .name = #_map, \
1046 .kname = #_name, \
1047 .probe_callback = (void *) TP_PROBE_CB(_template), \
1048 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1049 .owner = THIS_MODULE, \
1050};
1051
1052#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1053#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1054 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1055
1056#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1057
1058/*
1059 * Stage 8 of the trace events.
1060 *
1061 * Create an array of event description pointers.
1062 */
1063
1064#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1065
1066#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1067#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1068 &__event_desc___##_map,
1069
1070#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1071#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1072 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1073
1074#define TP_ID1(_token, _system) _token##_system
1075#define TP_ID(_token, _system) TP_ID1(_token, _system)
1076
1077static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
1078#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1079};
1080
1081#undef TP_ID1
1082#undef TP_ID
1083
1084/*
1085 * Stage 9 of the trace events.
1086 *
1087 * Create a toplevel descriptor for the whole probe.
1088 */
1089
1090#define TP_ID1(_token, _system) _token##_system
1091#define TP_ID(_token, _system) TP_ID1(_token, _system)
1092
1093/* non-const because list head will be modified when registered. */
1094static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
1095 .provider = __stringify(TRACE_SYSTEM),
1096 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
1097 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
1098 .head = { NULL, NULL },
1099 .lazy_init_head = { NULL, NULL },
1100 .lazy = 0,
1101};
1102
1103#undef TP_ID1
1104#undef TP_ID
1105
3afe7aac 1106/*
c099397a 1107 * Stage 10 of the trace events.
3afe7aac
MD
1108 *
1109 * Register/unregister probes at module load/unload.
1110 */
1111
f127e61e 1112#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
3afe7aac
MD
1113
1114#define TP_ID1(_token, _system) _token##_system
1115#define TP_ID(_token, _system) TP_ID1(_token, _system)
1116#define module_init_eval1(_token, _system) module_init(_token##_system)
1117#define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1118#define module_exit_eval1(_token, _system) module_exit(_token##_system)
1119#define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1120
2655f9ad 1121#ifndef TP_MODULE_NOINIT
3afe7aac
MD
1122static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
1123{
6d2a620c 1124 wrapper_vmalloc_sync_all();
a90917c3 1125 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
3afe7aac
MD
1126}
1127
3afe7aac
MD
1128static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
1129{
a90917c3 1130 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
3afe7aac
MD
1131}
1132
2655f9ad
MD
1133#ifndef TP_MODULE_NOAUTOLOAD
1134module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
3afe7aac 1135module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
259b6cb3 1136#endif
3afe7aac 1137
2655f9ad
MD
1138#endif
1139
3afe7aac
MD
1140#undef module_init_eval
1141#undef module_exit_eval
1142#undef TP_ID1
1143#undef TP_ID
177b3692
MD
1144
1145#undef TP_PROTO
1146#undef TP_ARGS
This page took 0.186206 seconds and 5 git commands to generate.