1b7df762b92586b29b90b6301b0f7fbf25b06cf7
[lttng-modules.git] / probes / lttng-events.h
1 /*
2 * lttng-events.h
3 *
4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
5 * Copyright (C) 2009-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
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
20 */
21
22 #include <linux/uaccess.h>
23 #include <linux/debugfs.h>
24 #include <linux/rculist.h>
25 #include "lttng.h"
26 #include "lttng-types.h"
27 #include "lttng-probe-user.h"
28 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
29 #include "../wrapper/ringbuffer/frontend_types.h"
30 #include "../lttng-events.h"
31 #include "../lttng-tracer-core.h"
32
33 /*
34 * Macro declarations used for all stages.
35 */
36
37 /*
38 * LTTng name mapping macros. LTTng remaps some of the kernel events to
39 * enforce name-spacing.
40 */
41 #undef LTTNG_TRACEPOINT_EVENT_MAP
42 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
43 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
44 PARAMS(proto), \
45 PARAMS(args), \
46 PARAMS(fields)) \
47 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
48
49 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
50 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
51 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
52 PARAMS(fields)) \
53 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
54
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
65 #undef LTTNG_TRACEPOINT_EVENT_CODE
66 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
67 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
68 PARAMS(proto), \
69 PARAMS(args), \
70 PARAMS(_locvar), \
71 PARAMS(_code), \
72 PARAMS(fields))
73
74 /*
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.
80 *
81 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
82 * template.
83 */
84
85 #undef LTTNG_TRACEPOINT_EVENT
86 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
87 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
88 PARAMS(proto), \
89 PARAMS(args), \
90 PARAMS(fields))
91
92 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
93 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
94 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
95
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))
99
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)
103
104 #undef LTTNG_TRACEPOINT_EVENT_CLASS
105 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
106 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
107 PARAMS(_fields))
108
109 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
110 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
111 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
112
113
114 /*
115 * Stage 1 of the trace events.
116 *
117 * Create dummy trace calls for each events, verifying that the LTTng module
118 * instrumentation headers match the kernel arguments. Will be optimized
119 * out by the compiler.
120 */
121
122 /* Reset all macros within TRACEPOINT_EVENT */
123 #include "lttng-events-reset.h"
124
125 #undef TP_PROTO
126 #define TP_PROTO(...) __VA_ARGS__
127
128 #undef TP_ARGS
129 #define TP_ARGS(...) __VA_ARGS__
130
131 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
132 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
133 void trace_##_name(_proto);
134
135 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
136 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
137 void trace_##_name(void *__data);
138
139 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
140
141 /*
142 * Stage 2 of the trace events.
143 *
144 * Create event field type metadata section.
145 * Each event produce an array of fields.
146 */
147
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"
152
153 #undef _ctf_integer_ext
154 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
155 { \
156 .name = #_item, \
157 .type = __type_integer(_type, _byte_order, _base, none),\
158 .nowrite = _nowrite, \
159 .user = _user, \
160 },
161
162 #undef _ctf_array_encoded
163 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
164 { \
165 .name = #_item, \
166 .type = \
167 { \
168 .atype = atype_array, \
169 .u = \
170 { \
171 .array = \
172 { \
173 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
174 .length = _length, \
175 } \
176 } \
177 }, \
178 .nowrite = _nowrite, \
179 .user = _user, \
180 },
181
182 #undef _ctf_sequence_encoded
183 #define _ctf_sequence_encoded(_type, _item, _src, \
184 _length_type, _src_length, _encoding, \
185 _base, _user, _nowrite) \
186 { \
187 .name = #_item, \
188 .type = \
189 { \
190 .atype = atype_sequence, \
191 .u = \
192 { \
193 .sequence = \
194 { \
195 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
196 .elem_type = __type_integer(_type, __BYTE_ORDER, _base, _encoding), \
197 }, \
198 }, \
199 }, \
200 .nowrite = _nowrite, \
201 .user = _user, \
202 },
203
204 #undef _ctf_string
205 #define _ctf_string(_item, _src, _user, _nowrite) \
206 { \
207 .name = #_item, \
208 .type = \
209 { \
210 .atype = atype_string, \
211 .u = \
212 { \
213 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
214 }, \
215 }, \
216 .nowrite = _nowrite, \
217 .user = _user, \
218 },
219
220 #undef TP_FIELDS
221 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
222
223 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
224 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
225 static const struct lttng_event_field __event_fields___##_name[] = { \
226 _fields \
227 };
228
229 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
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))
232
233 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
234
235 /*
236 * Stage 3 of the trace events.
237 *
238 * Create probe callback prototypes.
239 */
240
241 /* Reset all macros within TRACEPOINT_EVENT */
242 #include "lttng-events-reset.h"
243
244 #undef TP_PROTO
245 #define TP_PROTO(...) __VA_ARGS__
246
247 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
248 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
249 static void __event_probe__##_name(void *__data, _proto);
250
251 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
252 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
253 static void __event_probe__##_name(void *__data);
254
255 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
256
257 /*
258 * Stage 4 of the trace events.
259 *
260 * Create static inline function that calculates event size.
261 */
262
263 /* Reset all macros within TRACEPOINT_EVENT */
264 #include "lttng-events-reset.h"
265 #include "lttng-events-write.h"
266
267 #undef _ctf_integer_ext
268 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
269 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
270 __event_len += sizeof(_type);
271
272 #undef _ctf_array_encoded
273 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
274 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
275 __event_len += sizeof(_type) * (_length);
276
277 #undef _ctf_sequence_encoded
278 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
279 _src_length, _encoding, _base, _user, _nowrite) \
280 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
281 __event_len += sizeof(_length_type); \
282 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
283 __dynamic_len[__dynamic_len_idx] = (_src_length); \
284 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
285 __dynamic_len_idx++;
286
287 /*
288 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
289 * 1 (\0 only).
290 */
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);
299
300 #undef TP_PROTO
301 #define TP_PROTO(...) __VA_ARGS__
302
303 #undef TP_FIELDS
304 #define TP_FIELDS(...) __VA_ARGS__
305
306 #undef TP_locvar
307 #define TP_locvar(...) __VA_ARGS__
308
309 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
310 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
311 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
312 void *__tp_locvar, _proto) \
313 { \
314 size_t __event_len = 0; \
315 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
316 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
317 \
318 _fields \
319 return __event_len; \
320 }
321
322 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
323 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
324 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
325 void *__tp_locvar) \
326 { \
327 size_t __event_len = 0; \
328 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
329 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
330 \
331 _fields \
332 return __event_len; \
333 }
334
335 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
336
337
338 /*
339 * Stage 4.1 of tracepoint event generation.
340 *
341 * Create static inline function that layout the filter stack data.
342 * We make both write and nowrite data available to the filter.
343 */
344
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 }
429
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); \
441 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
442 __stack_data += sizeof(void **); \
443 }
444
445 #undef _ctf_sequence_encoded
446 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
447 _src_length, _encoding, _base, _user, _nowrite) \
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); \
453 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
454 __stack_data += sizeof(void **); \
455 }
456
457 #undef _ctf_string
458 #define _ctf_string(_item, _src, _user, _nowrite) \
459 { \
460 const void *__ctf_tmp_ptr = (_src); \
461 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
462 __stack_data += sizeof(void **); \
463 }
464
465 #undef TP_PROTO
466 #define TP_PROTO(...) __VA_ARGS__
467
468 #undef TP_FIELDS
469 #define TP_FIELDS(...) __VA_ARGS__
470
471 #undef TP_locvar
472 #define TP_locvar(...) __VA_ARGS__
473
474 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
475 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
476 static inline \
477 void __event_prepare_filter_stack__##_name(char *__stack_data, \
478 void *__tp_locvar) \
479 { \
480 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
481 \
482 _fields \
483 }
484
485 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
486 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
487 static inline \
488 void __event_prepare_filter_stack__##_name(char *__stack_data, \
489 void *__tp_locvar, _proto) \
490 { \
491 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
492 \
493 _fields \
494 }
495
496 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
497
498 /*
499 * Stage 5 of the trace events.
500 *
501 * Create static inline function that calculates event payload alignment.
502 */
503
504 /* Reset all macros within TRACEPOINT_EVENT */
505 #include "lttng-events-reset.h"
506 #include "lttng-events-write.h"
507
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));
511
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));
515
516 #undef _ctf_sequence_encoded
517 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
518 _src_length, _encoding, _base, _user, _nowrite) \
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));
521
522 #undef _ctf_string
523 #define _ctf_string(_item, _src, _user, _nowrite)
524
525 #undef TP_PROTO
526 #define TP_PROTO(...) __VA_ARGS__
527
528 #undef TP_FIELDS
529 #define TP_FIELDS(...) __VA_ARGS__
530
531 #undef TP_locvar
532 #define TP_locvar(...) __VA_ARGS__
533
534 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
535 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
536 static 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 }
544
545 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
546 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
547 static 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 }
555
556 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
557
558 /*
559 * Stage 6 of tracepoint event generation.
560 *
561 * Create the probe function. This function calls event size calculation
562 * and writes event data into the buffer.
563 */
564
565 /* Reset all macros within TRACEPOINT_EVENT */
566 #include "lttng-events-reset.h"
567 #include "lttng-events-write.h"
568
569 #undef _ctf_integer_ext_fetched
570 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
571 { \
572 _type __tmp = _src; \
573 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
574 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
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, \
605 _src_length, _encoding, _base, _user, _nowrite) \
606 { \
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));\
610 } \
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 }
630
631 /* Beware: this get len actually consumes the len value */
632 #undef __get_dynamic_len
633 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
634
635 #undef TP_PROTO
636 #define TP_PROTO(...) __VA_ARGS__
637
638 #undef TP_ARGS
639 #define TP_ARGS(...) __VA_ARGS__
640
641 #undef TP_FIELDS
642 #define TP_FIELDS(...) __VA_ARGS__
643
644 #undef TP_locvar
645 #define TP_locvar(...) __VA_ARGS__
646
647 #undef TP_code
648 #define TP_code(...) __VA_ARGS__
649
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
661 /*
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.
667 */
668 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
669 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
670 static void __event_probe__##_name(void *__data, _proto) \
671 { \
672 struct probe_local_vars { _locvar }; \
673 struct lttng_event *__event = __data; \
674 struct lttng_channel *__chan = __event->chan; \
675 struct lttng_session *__session = __chan->session; \
676 struct lib_ring_buffer_ctx __ctx; \
677 size_t __event_len, __event_align; \
678 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
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; \
683 int __ret; \
684 struct probe_local_vars __tp_locvar; \
685 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
686 &__tp_locvar; \
687 struct lttng_pid_tracker *__lpf; \
688 \
689 if (!_TP_SESSION_CHECK(session, __session)) \
690 return; \
691 if (unlikely(!ACCESS_ONCE(__session->active))) \
692 return; \
693 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
694 return; \
695 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
696 return; \
697 __lpf = rcu_dereference(__session->pid_tracker); \
698 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
699 return; \
700 _code \
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); \
717 __event_align = __event_get_align__##_name(tp_locvar, _args); \
718 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
719 __event_align, -1); \
720 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
721 if (__ret < 0) \
722 return; \
723 _fields \
724 __chan->ops->event_commit(&__ctx); \
725 }
726
727 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
728 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
729 static void __event_probe__##_name(void *__data) \
730 { \
731 struct probe_local_vars { _locvar }; \
732 struct lttng_event *__event = __data; \
733 struct lttng_channel *__chan = __event->chan; \
734 struct lttng_session *__session = __chan->session; \
735 struct lib_ring_buffer_ctx __ctx; \
736 size_t __event_len, __event_align; \
737 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
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; \
742 int __ret; \
743 struct probe_local_vars __tp_locvar; \
744 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
745 &__tp_locvar; \
746 struct lttng_pid_tracker *__lpf; \
747 \
748 if (!_TP_SESSION_CHECK(session, __session)) \
749 return; \
750 if (unlikely(!ACCESS_ONCE(__session->active))) \
751 return; \
752 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
753 return; \
754 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
755 return; \
756 __lpf = rcu_dereference(__session->pid_tracker); \
757 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
758 return; \
759 _code \
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); \
775 __event_align = __event_get_align__##_name(tp_locvar); \
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; \
781 _fields \
782 __chan->ops->event_commit(&__ctx); \
783 }
784
785 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
786
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) \
805 static 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
839 static 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. */
856 static __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
868 /*
869 * Stage 10 of the trace events.
870 *
871 * Register/unregister probes at module load/unload.
872 */
873
874 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
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
883 #ifndef TP_MODULE_NOINIT
884 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
885 {
886 wrapper_vmalloc_sync_all();
887 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
888 }
889
890 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
891 {
892 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
893 }
894
895 #ifndef TP_MODULE_NOAUTOLOAD
896 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
897 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
898 #endif
899
900 #endif
901
902 #undef module_init_eval
903 #undef module_exit_eval
904 #undef TP_ID1
905 #undef TP_ID
906
907 #undef TP_PROTO
908 #undef TP_ARGS
This page took 0.045201 seconds and 3 git commands to generate.