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