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