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