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