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