Fix: ust-tracepoint: make sure to expand tracepoint provider token
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
1 /*
2 * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <urcu/compiler.h>
26 #include <urcu/rculist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/ringbuffer-config.h>
29 #include <lttng/ust-compiler.h>
30 #include <lttng/tracepoint.h>
31 #include <byteswap.h>
32 #include <string.h>
33
34 #define __LTTNG_UST_NULL_STRING "(null)"
35
36 #undef tp_list_for_each_entry_rcu
37 #define tp_list_for_each_entry_rcu(pos, head, member) \
38 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
39 &pos->member != (head); \
40 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
41
42 /*
43 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
44 * same arguments and having the same field layout.
45 *
46 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
47 * its own provider and name. It refers to a class (template).
48 *
49 * TRACEPOINT_EVENT declared both a class and an instance and does a
50 * direct mapping from the instance to the class.
51 */
52
53 #undef TRACEPOINT_EVENT
54 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
55 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
56 _TP_PARAMS(_args), \
57 _TP_PARAMS(_fields)) \
58 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
59 _TP_PARAMS(_args))
60
61 #undef TRACEPOINT_EVENT_CLASS
62 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
63 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
64
65 #undef TRACEPOINT_EVENT_INSTANCE
66 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
67 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
68
69 /* Helpers */
70 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
71
72 #define _tp_max_t(type, x, y) \
73 ({ \
74 type __max1 = (x); \
75 type __max2 = (y); \
76 __max1 > __max2 ? __max1: __max2; \
77 })
78
79 /*
80 * Stage 0 of tracepoint event generation.
81 *
82 * Check that each TRACEPOINT_EVENT provider argument match the
83 * TRACEPOINT_PROVIDER by creating dummy callbacks.
84 */
85
86 /* Reset all macros within TRACEPOINT_EVENT */
87 #include <lttng/ust-tracepoint-event-reset.h>
88
89 static inline lttng_ust_notrace
90 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void);
91 static inline
92 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
93 {
94 }
95
96 #undef _TRACEPOINT_EVENT_CLASS
97 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
98 __tracepoint_provider_mismatch_##_provider();
99
100 #undef _TRACEPOINT_EVENT_INSTANCE
101 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
102 __tracepoint_provider_mismatch_##_provider();
103
104 static inline lttng_ust_notrace
105 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void);
106 static inline
107 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
108 {
109 #include TRACEPOINT_INCLUDE
110 }
111
112 /*
113 * Stage 0.1 of tracepoint event generation.
114 *
115 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
116 * tracepoint name length limit.
117 */
118
119 /* Reset all macros within TRACEPOINT_EVENT */
120 #include <lttng/ust-tracepoint-event-reset.h>
121
122 #undef _TRACEPOINT_EVENT_INSTANCE
123 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
124 static const char \
125 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
126 __attribute__((unused)) = \
127 #_provider ":" #_name;
128
129 #include TRACEPOINT_INCLUDE
130
131 /*
132 * Stage 0.2 of tracepoint event generation.
133 *
134 * Create dummy trace prototypes for each event class, and for each used
135 * template. This will allow checking whether the prototypes from the
136 * class and the instance using the class actually match.
137 */
138
139 /* Reset all macros within TRACEPOINT_EVENT */
140 #include <lttng/ust-tracepoint-event-reset.h>
141
142 #undef TP_ARGS
143 #define TP_ARGS(...) __VA_ARGS__
144
145 #undef _TRACEPOINT_EVENT_INSTANCE
146 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
147 void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
148
149 #undef _TRACEPOINT_EVENT_CLASS
150 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
151 void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
152
153 #include TRACEPOINT_INCLUDE
154
155 /*
156 * Stage 0.9 of tracepoint event generation
157 *
158 * Unfolding the enums
159 */
160 #include <lttng/ust-tracepoint-event-reset.h>
161
162 /* Enumeration entry (single value) */
163 #undef ctf_enum_value
164 #define ctf_enum_value(_string, _value) \
165 { \
166 .start = { \
167 .value = lttng_is_signed_type(__typeof__(_value)) ? \
168 (long long) (_value) : (_value), \
169 .signedness = lttng_is_signed_type(__typeof__(_value)), \
170 }, \
171 .end = { \
172 .value = lttng_is_signed_type(__typeof__(_value)) ? \
173 (long long) (_value) : (_value), \
174 .signedness = lttng_is_signed_type(__typeof__(_value)), \
175 }, \
176 .string = (_string), \
177 },
178
179 /* Enumeration entry (range) */
180 #undef ctf_enum_range
181 #define ctf_enum_range(_string, _range_start, _range_end) \
182 { \
183 .start = { \
184 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
185 (long long) (_range_start) : (_range_start), \
186 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
187 }, \
188 .end = { \
189 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
190 (long long) (_range_end) : (_range_end), \
191 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
192 }, \
193 .string = (_string), \
194 },
195
196 /* Enumeration entry (automatic value; follows the rules of CTF) */
197 #undef ctf_enum_auto
198 #define ctf_enum_auto(_string) \
199 { \
200 .start = { \
201 .value = -1ULL, \
202 .signedness = 0, \
203 }, \
204 .end = { \
205 .value = -1ULL, \
206 .signedness = 0, \
207 }, \
208 .string = (_string), \
209 .u = { \
210 .extra = { \
211 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
212 }, \
213 }, \
214 },
215
216 #undef TP_ENUM_VALUES
217 #define TP_ENUM_VALUES(...) \
218 __VA_ARGS__
219
220 #undef TRACEPOINT_ENUM
221 #define TRACEPOINT_ENUM(_provider, _name, _values) \
222 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
223 _values \
224 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
225 };
226
227 #include TRACEPOINT_INCLUDE
228
229 /*
230 * Stage 1 of tracepoint event generation.
231 *
232 * Create event field type metadata section.
233 * Each event produce an array of fields.
234 */
235
236 /* Reset all macros within TRACEPOINT_EVENT */
237 #include <lttng/ust-tracepoint-event-reset.h>
238 #include <lttng/ust-tracepoint-event-write.h>
239 #include <lttng/ust-tracepoint-event-nowrite.h>
240
241 #undef _ctf_integer_ext
242 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
243 { \
244 .name = #_item, \
245 .type = __type_integer(_type, _byte_order, _base, none),\
246 .nowrite = _nowrite, \
247 },
248
249 #undef _ctf_float
250 #define _ctf_float(_type, _item, _src, _nowrite) \
251 { \
252 .name = #_item, \
253 .type = __type_float(_type), \
254 .nowrite = _nowrite, \
255 },
256
257 #undef _ctf_array_encoded
258 #define _ctf_array_encoded(_type, _item, _src, _byte_order, \
259 _length, _encoding, _nowrite, \
260 _elem_type_base) \
261 { \
262 .name = #_item, \
263 .type = \
264 { \
265 .atype = atype_array, \
266 .u = \
267 { \
268 .array = \
269 { \
270 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
271 .length = _length, \
272 } \
273 } \
274 }, \
275 .nowrite = _nowrite, \
276 },
277
278 #undef _ctf_sequence_encoded
279 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
280 _length_type, _src_length, _encoding, _nowrite, \
281 _elem_type_base) \
282 { \
283 .name = #_item, \
284 .type = \
285 { \
286 .atype = atype_sequence, \
287 .u = \
288 { \
289 .sequence = \
290 { \
291 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
292 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
293 }, \
294 }, \
295 }, \
296 .nowrite = _nowrite, \
297 },
298
299 #undef _ctf_string
300 #define _ctf_string(_item, _src, _nowrite) \
301 { \
302 .name = #_item, \
303 .type = \
304 { \
305 .atype = atype_string, \
306 .u = \
307 { \
308 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
309 }, \
310 }, \
311 .nowrite = _nowrite, \
312 },
313
314 #undef _ctf_enum
315 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
316 { \
317 .name = #_item, \
318 .type = { \
319 .atype = atype_enum, \
320 .u = { \
321 .basic = { \
322 .enumeration = { \
323 .desc = &__enum_##_provider##_##_name, \
324 .container_type = { \
325 .size = sizeof(_type) * CHAR_BIT, \
326 .alignment = lttng_alignof(_type) * CHAR_BIT, \
327 .signedness = lttng_is_signed_type(_type), \
328 .reverse_byte_order = 0, \
329 .base = 10, \
330 .encoding = lttng_encode_none, \
331 }, \
332 }, \
333 }, \
334 }, \
335 }, \
336 .nowrite = _nowrite, \
337 },
338
339 #undef TP_FIELDS
340 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
341
342 #undef _TRACEPOINT_EVENT_CLASS
343 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
344 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
345 _fields \
346 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
347 };
348
349 #undef TRACEPOINT_ENUM
350 #define TRACEPOINT_ENUM(_provider, _name, _values) \
351 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
352 .name = #_provider "_" #_name, \
353 .entries = __enum_values__##_provider##_##_name, \
354 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
355 };
356
357 #include TRACEPOINT_INCLUDE
358
359 /*
360 * Stage 2 of tracepoint event generation.
361 *
362 * Create probe callback prototypes.
363 */
364
365 /* Reset all macros within TRACEPOINT_EVENT */
366 #include <lttng/ust-tracepoint-event-reset.h>
367
368 #undef TP_ARGS
369 #define TP_ARGS(...) __VA_ARGS__
370
371 #undef _TRACEPOINT_EVENT_CLASS
372 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
373 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
374
375 #include TRACEPOINT_INCLUDE
376
377 /*
378 * Stage 3.0 of tracepoint event generation.
379 *
380 * Create static inline function that calculates event size.
381 */
382
383 /* Reset all macros within TRACEPOINT_EVENT */
384 #include <lttng/ust-tracepoint-event-reset.h>
385 #include <lttng/ust-tracepoint-event-write.h>
386
387 #undef _ctf_integer_ext
388 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
389 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
390 __event_len += sizeof(_type);
391
392 #undef _ctf_float
393 #define _ctf_float(_type, _item, _src, _nowrite) \
394 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
395 __event_len += sizeof(_type);
396
397 #undef _ctf_array_encoded
398 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
399 _nowrite, _elem_type_base) \
400 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
401 __event_len += sizeof(_type) * (_length);
402
403 #undef _ctf_sequence_encoded
404 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
405 _src_length, _encoding, _nowrite, _elem_type_base) \
406 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
407 __event_len += sizeof(_length_type); \
408 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
409 __dynamic_len[__dynamic_len_idx] = (_src_length); \
410 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
411 __dynamic_len_idx++;
412
413 #undef _ctf_string
414 #define _ctf_string(_item, _src, _nowrite) \
415 __event_len += __dynamic_len[__dynamic_len_idx++] = \
416 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
417
418 #undef _ctf_enum
419 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
420 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
421
422 #undef TP_ARGS
423 #define TP_ARGS(...) __VA_ARGS__
424
425 #undef TP_FIELDS
426 #define TP_FIELDS(...) __VA_ARGS__
427
428 #undef _TRACEPOINT_EVENT_CLASS
429 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
430 static inline lttng_ust_notrace \
431 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
432 static inline \
433 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
434 { \
435 size_t __event_len = 0; \
436 unsigned int __dynamic_len_idx = 0; \
437 \
438 if (0) \
439 (void) __dynamic_len_idx; /* don't warn if unused */ \
440 _fields \
441 return __event_len; \
442 }
443
444 #include TRACEPOINT_INCLUDE
445
446 /*
447 * Stage 3.1 of tracepoint event generation.
448 *
449 * Create static inline function that layout the filter stack data.
450 * We make both write and nowrite data available to the filter.
451 */
452
453 /* Reset all macros within TRACEPOINT_EVENT */
454 #include <lttng/ust-tracepoint-event-reset.h>
455 #include <lttng/ust-tracepoint-event-write.h>
456 #include <lttng/ust-tracepoint-event-nowrite.h>
457
458 #undef _ctf_integer_ext
459 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
460 if (lttng_is_signed_type(_type)) { \
461 int64_t __ctf_tmp_int64; \
462 switch (sizeof(_type)) { \
463 case 1: \
464 { \
465 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
466 __ctf_tmp_int64 = (int64_t) __tmp.v; \
467 break; \
468 } \
469 case 2: \
470 { \
471 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
472 if (_byte_order != BYTE_ORDER) \
473 __tmp.v = bswap_16(__tmp.v); \
474 __ctf_tmp_int64 = (int64_t) __tmp.v; \
475 break; \
476 } \
477 case 4: \
478 { \
479 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
480 if (_byte_order != BYTE_ORDER) \
481 __tmp.v = bswap_32(__tmp.v); \
482 __ctf_tmp_int64 = (int64_t) __tmp.v; \
483 break; \
484 } \
485 case 8: \
486 { \
487 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
488 if (_byte_order != BYTE_ORDER) \
489 __tmp.v = bswap_64(__tmp.v); \
490 __ctf_tmp_int64 = (int64_t) __tmp.v; \
491 break; \
492 } \
493 default: \
494 abort(); \
495 }; \
496 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
497 } else { \
498 uint64_t __ctf_tmp_uint64; \
499 switch (sizeof(_type)) { \
500 case 1: \
501 { \
502 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
503 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
504 break; \
505 } \
506 case 2: \
507 { \
508 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
509 if (_byte_order != BYTE_ORDER) \
510 __tmp.v = bswap_16(__tmp.v); \
511 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
512 break; \
513 } \
514 case 4: \
515 { \
516 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
517 if (_byte_order != BYTE_ORDER) \
518 __tmp.v = bswap_32(__tmp.v); \
519 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
520 break; \
521 } \
522 case 8: \
523 { \
524 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
525 if (_byte_order != BYTE_ORDER) \
526 __tmp.v = bswap_64(__tmp.v); \
527 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
528 break; \
529 } \
530 default: \
531 abort(); \
532 }; \
533 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
534 } \
535 __stack_data += sizeof(int64_t);
536
537 #undef _ctf_float
538 #define _ctf_float(_type, _item, _src, _nowrite) \
539 { \
540 double __ctf_tmp_double = (double) (_type) (_src); \
541 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
542 __stack_data += sizeof(double); \
543 }
544
545 #undef _ctf_array_encoded
546 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
547 _encoding, _nowrite, _elem_type_base) \
548 { \
549 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
550 const void *__ctf_tmp_ptr = (_src); \
551 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
552 __stack_data += sizeof(unsigned long); \
553 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
554 __stack_data += sizeof(void *); \
555 }
556
557 #undef _ctf_sequence_encoded
558 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
559 _src_length, _encoding, _nowrite, _elem_type_base) \
560 { \
561 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
562 const void *__ctf_tmp_ptr = (_src); \
563 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
564 __stack_data += sizeof(unsigned long); \
565 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
566 __stack_data += sizeof(void *); \
567 }
568
569 #undef _ctf_string
570 #define _ctf_string(_item, _src, _nowrite) \
571 { \
572 const void *__ctf_tmp_ptr = \
573 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
574 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
575 __stack_data += sizeof(void *); \
576 }
577
578 #undef _ctf_enum
579 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
580 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
581
582 #undef TP_ARGS
583 #define TP_ARGS(...) __VA_ARGS__
584
585 #undef TP_FIELDS
586 #define TP_FIELDS(...) __VA_ARGS__
587
588 #undef _TRACEPOINT_EVENT_CLASS
589 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
590 static inline \
591 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
592 _TP_ARGS_DATA_PROTO(_args)) \
593 { \
594 _fields \
595 }
596
597 #include TRACEPOINT_INCLUDE
598
599 /*
600 * Stage 4 of tracepoint event generation.
601 *
602 * Create static inline function that calculates event payload alignment.
603 */
604
605 /* Reset all macros within TRACEPOINT_EVENT */
606 #include <lttng/ust-tracepoint-event-reset.h>
607 #include <lttng/ust-tracepoint-event-write.h>
608
609 #undef _ctf_integer_ext
610 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
611 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
612
613 #undef _ctf_float
614 #define _ctf_float(_type, _item, _src, _nowrite) \
615 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
616
617 #undef _ctf_array_encoded
618 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
619 _encoding, _nowrite, _elem_type_base) \
620 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
621
622 #undef _ctf_sequence_encoded
623 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
624 _src_length, _encoding, _nowrite, _elem_type_base) \
625 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
626 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
627
628 #undef _ctf_string
629 #define _ctf_string(_item, _src, _nowrite)
630
631 #undef _ctf_enum
632 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
633 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
634
635 #undef TP_ARGS
636 #define TP_ARGS(...) __VA_ARGS__
637
638 #undef TP_FIELDS
639 #define TP_FIELDS(...) __VA_ARGS__
640
641 #undef _TRACEPOINT_EVENT_CLASS
642 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
643 static inline lttng_ust_notrace \
644 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
645 static inline \
646 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
647 { \
648 size_t __event_align = 1; \
649 _fields \
650 return __event_align; \
651 }
652
653 #include TRACEPOINT_INCLUDE
654
655
656 /*
657 * Stage 5 of tracepoint event generation.
658 *
659 * Create the probe function. This function calls event size calculation
660 * and writes event data into the buffer.
661 */
662
663 /* Reset all macros within TRACEPOINT_EVENT */
664 #include <lttng/ust-tracepoint-event-reset.h>
665 #include <lttng/ust-tracepoint-event-write.h>
666
667 #undef _ctf_integer_ext
668 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
669 { \
670 _type __tmp = (_src); \
671 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
672 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
673 }
674
675 #undef _ctf_float
676 #define _ctf_float(_type, _item, _src, _nowrite) \
677 { \
678 _type __tmp = (_src); \
679 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
680 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
681 }
682
683 #undef _ctf_array_encoded
684 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
685 _encoding, _nowrite, _elem_type_base) \
686 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
687 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
688
689 #undef _ctf_sequence_encoded
690 #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
691 _src_length, _encoding, _nowrite, _elem_type_base) \
692 { \
693 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
694 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
695 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
696 } \
697 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
698 __chan->ops->event_write(&__ctx, _src, \
699 sizeof(_type) * __get_dynamic_len(dest));
700
701 /*
702 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
703 * tracepoint provider ABI implements event_strcpy. This dynamic check
704 * can be removed when the tracepoint provider ABI moves to 2.
705 */
706 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
707 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
708 #endif
709
710 #undef _ctf_string
711 #define _ctf_string(_item, _src, _nowrite) \
712 { \
713 const char *__ctf_tmp_string = \
714 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
715 lib_ring_buffer_align_ctx(&__ctx, \
716 lttng_alignof(*__ctf_tmp_string)); \
717 if (__chan->ops->u.has_strcpy) \
718 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
719 __get_dynamic_len(dest)); \
720 else \
721 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
722 __get_dynamic_len(dest)); \
723 }
724
725
726 #undef _ctf_enum
727 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
728 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
729
730 /* Beware: this get len actually consumes the len value */
731 #undef __get_dynamic_len
732 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
733
734 #undef TP_ARGS
735 #define TP_ARGS(...) __VA_ARGS__
736
737 #undef TP_FIELDS
738 #define TP_FIELDS(...) __VA_ARGS__
739
740 /*
741 * For state dump, check that "session" argument (mandatory) matches the
742 * session this event belongs to. Ensures that we write state dump data only
743 * into the started session, not into all sessions.
744 */
745 #undef _TP_SESSION_CHECK
746 #ifdef TP_SESSION_CHECK
747 #define _TP_SESSION_CHECK(session, csession) (session == csession)
748 #else /* TP_SESSION_CHECK */
749 #define _TP_SESSION_CHECK(session, csession) 1
750 #endif /* TP_SESSION_CHECK */
751
752 /*
753 * Use of __builtin_return_address(0) sometimes seems to cause stack
754 * corruption on 32-bit PowerPC. Disable this feature on that
755 * architecture for now by always using the NULL value for the ip
756 * context.
757 */
758 #undef _TP_IP_PARAM
759 #ifdef TP_IP_PARAM
760 #define _TP_IP_PARAM(x) (x)
761 #else /* TP_IP_PARAM */
762
763 #if defined(__PPC__) && !defined(__PPC64__)
764 #define _TP_IP_PARAM(x) NULL
765 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
766 #define _TP_IP_PARAM(x) __builtin_return_address(0)
767 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
768
769 #endif /* TP_IP_PARAM */
770
771 /*
772 * Using twice size for filter stack data to hold size and pointer for
773 * each field (worse case). For integers, max size required is 64-bit.
774 * Same for double-precision floats. Those fit within
775 * 2*sizeof(unsigned long) for all supported architectures.
776 * Perform UNION (||) of filter runtime list.
777 */
778 #undef _TRACEPOINT_EVENT_CLASS
779 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
780 static lttng_ust_notrace \
781 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
782 static \
783 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
784 { \
785 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
786 struct lttng_channel *__chan = __event->chan; \
787 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
788 struct lttng_stack_ctx __lttng_ctx; \
789 size_t __event_len, __event_align; \
790 size_t __dynamic_len_idx = 0; \
791 union { \
792 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
793 char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
794 } __stackvar; \
795 int __ret; \
796 \
797 if (0) \
798 (void) __dynamic_len_idx; /* don't warn if unused */ \
799 if (!_TP_SESSION_CHECK(session, __chan->session)) \
800 return; \
801 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
802 return; \
803 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
804 return; \
805 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
806 return; \
807 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
808 return; \
809 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
810 struct lttng_bytecode_runtime *bc_runtime; \
811 int __filter_record = __event->has_enablers_without_bytecode; \
812 \
813 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
814 _TP_ARGS_DATA_VAR(_args)); \
815 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
816 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
817 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
818 __filter_record = 1; \
819 } \
820 if (caa_likely(!__filter_record)) \
821 return; \
822 } \
823 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
824 _TP_ARGS_DATA_VAR(_args)); \
825 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
826 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
827 __lttng_ctx.event = __event; \
828 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
829 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
830 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
831 __event_align, -1, __chan->handle, &__lttng_ctx); \
832 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
833 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
834 if (__ret < 0) \
835 return; \
836 _fields \
837 __chan->ops->event_commit(&__ctx); \
838 }
839
840 #include TRACEPOINT_INCLUDE
841
842 #undef __get_dynamic_len
843
844 /*
845 * Stage 5.1 of tracepoint event generation.
846 *
847 * Create probe signature
848 */
849
850 /* Reset all macros within TRACEPOINT_EVENT */
851 #include <lttng/ust-tracepoint-event-reset.h>
852
853 #undef TP_ARGS
854 #define TP_ARGS(...) __VA_ARGS__
855
856 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
857
858 #undef _TRACEPOINT_EVENT_CLASS
859 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
860 static const char __tp_event_signature___##_provider##___##_name[] = \
861 _TP_EXTRACT_STRING2(_args);
862
863 #include TRACEPOINT_INCLUDE
864
865 #undef _TP_EXTRACT_STRING2
866
867 /*
868 * Stage 6 of tracepoint event generation.
869 *
870 * Tracepoint loglevel mapping definition generation. We generate a
871 * symbol for each mapping for a provider/event to ensure at most a 1 to
872 * 1 mapping between events and loglevels. If the symbol is repeated,
873 * the compiler will complain.
874 */
875
876 /* Reset all macros within TRACEPOINT_EVENT */
877 #include <lttng/ust-tracepoint-event-reset.h>
878
879 /*
880 * Declare _loglevel___##__provider##___##__name as non-static, with
881 * hidden visibility for c++ handling of weakref. We do a weakref to the
882 * symbol in a later stage, which requires that the symbol is not
883 * mangled.
884 */
885 #ifdef __cplusplus
886 #define LTTNG_TP_EXTERN_C extern "C"
887 #else
888 #define LTTNG_TP_EXTERN_C
889 #endif
890
891 #undef TRACEPOINT_LOGLEVEL
892 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
893 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
894 LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
895 __attribute__((visibility("hidden"))) = \
896 &_loglevel_value___##__provider##___##__name;
897
898 #include TRACEPOINT_INCLUDE
899
900 #undef LTTNG_TP_EXTERN_C
901
902 /*
903 * Stage 6.1 of tracepoint event generation.
904 *
905 * Tracepoint UML URI info.
906 */
907
908 /* Reset all macros within TRACEPOINT_EVENT */
909 #include <lttng/ust-tracepoint-event-reset.h>
910
911 /*
912 * Declare _model_emf_uri___##__provider##___##__name as non-static,
913 * with hidden visibility for c++ handling of weakref. We do a weakref
914 * to the symbol in a later stage, which requires that the symbol is not
915 * mangled.
916 */
917 #ifdef __cplusplus
918 #define LTTNG_TP_EXTERN_C extern "C"
919 #else
920 #define LTTNG_TP_EXTERN_C
921 #endif
922
923 #undef TRACEPOINT_MODEL_EMF_URI
924 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
925 LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
926 __attribute__((visibility("hidden"))) = __uri; \
927
928 #include TRACEPOINT_INCLUDE
929
930 #undef LTTNG_TP_EXTERN_C
931
932 /*
933 * Stage 7.1 of tracepoint event generation.
934 *
935 * Create events description structures. We use a weakref because
936 * loglevels are optional. If not declared, the event will point to the
937 * a loglevel that contains NULL.
938 */
939
940 /* Reset all macros within TRACEPOINT_EVENT */
941 #include <lttng/ust-tracepoint-event-reset.h>
942
943 #undef _TRACEPOINT_EVENT_INSTANCE
944 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
945 static const int * \
946 __ref_loglevel___##_provider##___##_name \
947 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
948 static const char * \
949 __ref_model_emf_uri___##_provider##___##_name \
950 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
951 static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
952 .name = #_provider ":" #_name, \
953 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
954 .ctx = NULL, \
955 .fields = __event_fields___##_provider##___##_template, \
956 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
957 .loglevel = &__ref_loglevel___##_provider##___##_name, \
958 .signature = __tp_event_signature___##_provider##___##_template, \
959 .u = { \
960 .ext = { \
961 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
962 }, \
963 }, \
964 };
965
966 #include TRACEPOINT_INCLUDE
967
968 /*
969 * Stage 7.2 of tracepoint event generation.
970 *
971 * Create array of events.
972 */
973
974 /* Reset all macros within TRACEPOINT_EVENT */
975 #include <lttng/ust-tracepoint-event-reset.h>
976
977 #undef _TRACEPOINT_EVENT_INSTANCE
978 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
979 &__event_desc___##_provider##_##_name,
980
981 static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
982 #include TRACEPOINT_INCLUDE
983 NULL, /* Dummy, C99 forbids 0-len array. */
984 };
985
986
987 /*
988 * Stage 8 of tracepoint event generation.
989 *
990 * Create a toplevel descriptor for the whole probe.
991 */
992
993 /* non-const because list head will be modified when registered. */
994 static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
995 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
996 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
997 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
998 .head = { NULL, NULL },
999 .lazy_init_head = { NULL, NULL },
1000 .lazy = 0,
1001 .major = LTTNG_UST_PROVIDER_MAJOR,
1002 .minor = LTTNG_UST_PROVIDER_MINOR,
1003 };
1004
1005 static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
1006
1007 /*
1008 * Stage 9 of tracepoint event generation.
1009 *
1010 * Register/unregister probes at module load/unload.
1011 *
1012 * Generate the constructor as an externally visible symbol for use when
1013 * linking the probe statically.
1014 *
1015 * Register refcount is protected by libc dynamic loader mutex.
1016 */
1017
1018 /* Reset all macros within TRACEPOINT_EVENT */
1019 #include <lttng/ust-tracepoint-event-reset.h>
1020 static void lttng_ust_notrace __attribute__((constructor))
1021 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
1022 static void
1023 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
1024 {
1025 int ret;
1026
1027 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
1028 TRACEPOINT_PROVIDER)++) {
1029 return;
1030 }
1031 /*
1032 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1033 * static inline function that ensures every probe PROVIDER
1034 * argument match the provider within which they appear. It
1035 * calls empty static inline functions, and therefore has no
1036 * runtime effect. However, if it detects an error, a linker
1037 * error will appear.
1038 */
1039 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
1040 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1041 if (ret) {
1042 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret);
1043 abort();
1044 }
1045 }
1046
1047 static void lttng_ust_notrace __attribute__((destructor))
1048 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
1049 static void
1050 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
1051 {
1052 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
1053 TRACEPOINT_PROVIDER)) {
1054 return;
1055 }
1056 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1057 }
1058
1059 int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
This page took 0.050387 seconds and 4 git commands to generate.