Fix: version checks for kernel 4.0
[deliverable/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/rcu.h"
31 #include "../lttng-events.h"
32 #include "../lttng-tracer-core.h"
33
34 /*
35 * Macro declarations used for all stages.
36 */
37
38 /*
39 * LTTng name mapping macros. LTTng remaps some of the kernel events to
40 * enforce name-spacing.
41 */
42 #undef LTTNG_TRACEPOINT_EVENT_MAP
43 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
44 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
45 PARAMS(proto), \
46 PARAMS(args), \
47 PARAMS(fields)) \
48 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
49
50 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
51 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
52 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
53 PARAMS(fields)) \
54 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
55
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
66 #undef LTTNG_TRACEPOINT_EVENT_CODE
67 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
68 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
69 PARAMS(proto), \
70 PARAMS(args), \
71 PARAMS(_locvar), \
72 PARAMS(_code), \
73 PARAMS(fields))
74
75 /*
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.
81 *
82 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
83 * template.
84 */
85
86 #undef LTTNG_TRACEPOINT_EVENT
87 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
88 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
89 PARAMS(proto), \
90 PARAMS(args), \
91 PARAMS(fields))
92
93 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
94 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
95 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
96
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))
100
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)
104
105 #undef LTTNG_TRACEPOINT_EVENT_CLASS
106 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
107 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
108 PARAMS(_fields))
109
110 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
111 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
112 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
113
114
115 /*
116 * Stage 1 of the trace events.
117 *
118 * Create dummy trace calls for each events, verifying that the LTTng module
119 * instrumentation headers match the kernel arguments. Will be optimized
120 * out by the compiler.
121 */
122
123 /* Reset all macros within TRACEPOINT_EVENT */
124 #include "lttng-events-reset.h"
125
126 #undef TP_PROTO
127 #define TP_PROTO(...) __VA_ARGS__
128
129 #undef TP_ARGS
130 #define TP_ARGS(...) __VA_ARGS__
131
132 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
133 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
134 void trace_##_name(_proto);
135
136 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
137 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
138 void trace_##_name(void);
139
140 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
141
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) \
160 void __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) \
164 void __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) \
168 void __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) \
172 void __event_template_proto___##_name(void);
173
174 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
175
176 /*
177 * Stage 2 of the trace events.
178 *
179 * Create event field type metadata section.
180 * Each event produce an array of fields.
181 */
182
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"
187
188 #undef _ctf_integer_ext
189 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
190 { \
191 .name = #_item, \
192 .type = __type_integer(_type, _byte_order, _base, none),\
193 .nowrite = _nowrite, \
194 .user = _user, \
195 },
196
197 #undef _ctf_array_encoded
198 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
199 { \
200 .name = #_item, \
201 .type = \
202 { \
203 .atype = atype_array, \
204 .u = \
205 { \
206 .array = \
207 { \
208 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
209 .length = _length, \
210 } \
211 } \
212 }, \
213 .nowrite = _nowrite, \
214 .user = _user, \
215 },
216
217 #undef _ctf_sequence_encoded
218 #define _ctf_sequence_encoded(_type, _item, _src, \
219 _length_type, _src_length, _encoding, \
220 _byte_order, _base, _user, _nowrite) \
221 { \
222 .name = #_item, \
223 .type = \
224 { \
225 .atype = atype_sequence, \
226 .u = \
227 { \
228 .sequence = \
229 { \
230 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
231 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
232 }, \
233 }, \
234 }, \
235 .nowrite = _nowrite, \
236 .user = _user, \
237 },
238
239 #undef _ctf_string
240 #define _ctf_string(_item, _src, _user, _nowrite) \
241 { \
242 .name = #_item, \
243 .type = \
244 { \
245 .atype = atype_string, \
246 .u = \
247 { \
248 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
249 }, \
250 }, \
251 .nowrite = _nowrite, \
252 .user = _user, \
253 },
254
255 #undef TP_FIELDS
256 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
257
258 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
259 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
260 static const struct lttng_event_field __event_fields___##_name[] = { \
261 _fields \
262 };
263
264 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
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))
267
268 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
269
270 /*
271 * Stage 3 of the trace events.
272 *
273 * Create probe callback prototypes.
274 */
275
276 /* Reset all macros within TRACEPOINT_EVENT */
277 #include "lttng-events-reset.h"
278
279 #undef TP_PROTO
280 #define TP_PROTO(...) __VA_ARGS__
281
282 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
283 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
284 static void __event_probe__##_name(void *__data, _proto);
285
286 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
287 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
288 static void __event_probe__##_name(void *__data);
289
290 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
291
292 /*
293 * Stage 4 of the trace events.
294 *
295 * Create static inline function that calculates event size.
296 */
297
298 /* Reset all macros within TRACEPOINT_EVENT */
299 #include "lttng-events-reset.h"
300 #include "lttng-events-write.h"
301
302 #undef _ctf_integer_ext
303 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
304 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
305 __event_len += sizeof(_type);
306
307 #undef _ctf_array_encoded
308 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
309 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
310 __event_len += sizeof(_type) * (_length);
311
312 #undef _ctf_sequence_encoded
313 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
314 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
315 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
316 __event_len += sizeof(_length_type); \
317 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
318 __dynamic_len[__dynamic_len_idx] = (_src_length); \
319 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
320 __dynamic_len_idx++;
321
322 /*
323 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
324 * 1 (\0 only).
325 */
326 #undef _ctf_string
327 #define _ctf_string(_item, _src, _user, _nowrite) \
328 if (_user) \
329 __event_len += __dynamic_len[__dynamic_len_idx++] = \
330 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
331 else \
332 __event_len += __dynamic_len[__dynamic_len_idx++] = \
333 strlen(_src) + 1;
334
335 #undef TP_PROTO
336 #define TP_PROTO(...) __VA_ARGS__
337
338 #undef TP_FIELDS
339 #define TP_FIELDS(...) __VA_ARGS__
340
341 #undef TP_locvar
342 #define TP_locvar(...) __VA_ARGS__
343
344 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
345 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
346 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
347 void *__tp_locvar, _proto) \
348 { \
349 size_t __event_len = 0; \
350 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
351 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
352 \
353 _fields \
354 return __event_len; \
355 }
356
357 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
358 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
359 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
360 void *__tp_locvar) \
361 { \
362 size_t __event_len = 0; \
363 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
364 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
365 \
366 _fields \
367 return __event_len; \
368 }
369
370 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
371
372
373 /*
374 * Stage 4.1 of tracepoint event generation.
375 *
376 * Create static inline function that layout the filter stack data.
377 * We make both write and nowrite data available to the filter.
378 */
379
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 }
464
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); \
476 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
477 __stack_data += sizeof(void *); \
478 }
479
480 #undef _ctf_sequence_encoded
481 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
482 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
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); \
488 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
489 __stack_data += sizeof(void *); \
490 }
491
492 #undef _ctf_string
493 #define _ctf_string(_item, _src, _user, _nowrite) \
494 { \
495 const void *__ctf_tmp_ptr = (_src); \
496 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
497 __stack_data += sizeof(void *); \
498 }
499
500 #undef TP_PROTO
501 #define TP_PROTO(...) __VA_ARGS__
502
503 #undef TP_FIELDS
504 #define TP_FIELDS(...) __VA_ARGS__
505
506 #undef TP_locvar
507 #define TP_locvar(...) __VA_ARGS__
508
509 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
510 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
511 static inline \
512 void __event_prepare_filter_stack__##_name(char *__stack_data, \
513 void *__tp_locvar) \
514 { \
515 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
516 \
517 _fields \
518 }
519
520 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
521 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
522 static inline \
523 void __event_prepare_filter_stack__##_name(char *__stack_data, \
524 void *__tp_locvar, _proto) \
525 { \
526 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
527 \
528 _fields \
529 }
530
531 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
532
533 /*
534 * Stage 5 of the trace events.
535 *
536 * Create static inline function that calculates event payload alignment.
537 */
538
539 /* Reset all macros within TRACEPOINT_EVENT */
540 #include "lttng-events-reset.h"
541 #include "lttng-events-write.h"
542
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));
546
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));
550
551 #undef _ctf_sequence_encoded
552 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
553 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
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));
556
557 #undef _ctf_string
558 #define _ctf_string(_item, _src, _user, _nowrite)
559
560 #undef TP_PROTO
561 #define TP_PROTO(...) __VA_ARGS__
562
563 #undef TP_FIELDS
564 #define TP_FIELDS(...) __VA_ARGS__
565
566 #undef TP_locvar
567 #define TP_locvar(...) __VA_ARGS__
568
569 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
570 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
571 static 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 }
579
580 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
581 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
582 static 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 }
590
591 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
592
593 /*
594 * Stage 6 of tracepoint event generation.
595 *
596 * Create the probe function. This function calls event size calculation
597 * and writes event data into the buffer.
598 */
599
600 /* Reset all macros within TRACEPOINT_EVENT */
601 #include "lttng-events-reset.h"
602 #include "lttng-events-write.h"
603
604 #undef _ctf_integer_ext_fetched
605 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
606 { \
607 _type __tmp = _src; \
608 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
609 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
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, \
640 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
641 { \
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));\
645 } \
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 }
665
666 /* Beware: this get len actually consumes the len value */
667 #undef __get_dynamic_len
668 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
669
670 #undef TP_PROTO
671 #define TP_PROTO(...) __VA_ARGS__
672
673 #undef TP_ARGS
674 #define TP_ARGS(...) __VA_ARGS__
675
676 #undef TP_FIELDS
677 #define TP_FIELDS(...) __VA_ARGS__
678
679 #undef TP_locvar
680 #define TP_locvar(...) __VA_ARGS__
681
682 #undef TP_code
683 #define TP_code(...) __VA_ARGS__
684
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
696 /*
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.
702 */
703 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
704 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
705 static void __event_probe__##_name(void *__data, _proto) \
706 { \
707 struct probe_local_vars { _locvar }; \
708 struct lttng_event *__event = __data; \
709 struct lttng_channel *__chan = __event->chan; \
710 struct lttng_session *__session = __chan->session; \
711 struct lib_ring_buffer_ctx __ctx; \
712 size_t __event_len, __event_align; \
713 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
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; \
718 int __ret; \
719 struct probe_local_vars __tp_locvar; \
720 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
721 &__tp_locvar; \
722 struct lttng_pid_tracker *__lpf; \
723 \
724 if (!_TP_SESSION_CHECK(session, __session)) \
725 return; \
726 if (unlikely(!ACCESS_ONCE(__session->active))) \
727 return; \
728 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
729 return; \
730 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
731 return; \
732 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
733 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
734 return; \
735 _code \
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); \
742 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
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); \
752 __event_align = __event_get_align__##_name(tp_locvar, _args); \
753 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
754 __event_align, -1); \
755 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
756 if (__ret < 0) \
757 return; \
758 _fields \
759 __chan->ops->event_commit(&__ctx); \
760 }
761
762 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
763 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
764 static void __event_probe__##_name(void *__data) \
765 { \
766 struct probe_local_vars { _locvar }; \
767 struct lttng_event *__event = __data; \
768 struct lttng_channel *__chan = __event->chan; \
769 struct lttng_session *__session = __chan->session; \
770 struct lib_ring_buffer_ctx __ctx; \
771 size_t __event_len, __event_align; \
772 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
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; \
777 int __ret; \
778 struct probe_local_vars __tp_locvar; \
779 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
780 &__tp_locvar; \
781 struct lttng_pid_tracker *__lpf; \
782 \
783 if (!_TP_SESSION_CHECK(session, __session)) \
784 return; \
785 if (unlikely(!ACCESS_ONCE(__session->active))) \
786 return; \
787 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
788 return; \
789 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
790 return; \
791 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
792 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
793 return; \
794 _code \
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); \
801 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
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); \
810 __event_align = __event_get_align__##_name(tp_locvar); \
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; \
816 _fields \
817 __chan->ops->event_commit(&__ctx); \
818 }
819
820 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
821
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) \
840 static 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
874 static 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. */
891 static __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
903 /*
904 * Stage 10 of the trace events.
905 *
906 * Register/unregister probes at module load/unload.
907 */
908
909 #include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
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
918 #ifndef TP_MODULE_NOINIT
919 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
920 {
921 wrapper_vmalloc_sync_all();
922 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
923 }
924
925 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
926 {
927 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
928 }
929
930 #ifndef TP_MODULE_NOAUTOLOAD
931 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
932 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
933 #endif
934
935 #endif
936
937 #undef module_init_eval
938 #undef module_exit_eval
939 #undef TP_ID1
940 #undef TP_ID
941
942 #undef TP_PROTO
943 #undef TP_ARGS
This page took 0.064386 seconds and 5 git commands to generate.