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