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