1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 #include <side/macros.h>
16 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
18 //TODO: as those structures will be ABI, we need to either consider them
19 //fixed forever, or think of a scheme that would allow their binary
20 //representation to be extended if need be.
23 struct side_arg_vec_description
;
24 struct side_arg_dynamic_vec
;
25 struct side_arg_dynamic_vec_vla
;
26 struct side_type_description
;
27 struct side_event_field
;
28 struct side_tracer_visitor_ctx
;
29 struct side_tracer_dynamic_struct_visitor_ctx
;
30 struct side_tracer_dynamic_vla_visitor_ctx
;
31 struct side_event_description
;
32 struct side_arg_dynamic_event_struct
;
46 SIDE_TYPE_FLOAT_BINARY16
,
47 SIDE_TYPE_FLOAT_BINARY32
,
48 SIDE_TYPE_FLOAT_BINARY64
,
49 SIDE_TYPE_FLOAT_BINARY128
,
56 SIDE_TYPE_VLA_VISITOR
,
78 /* Enumeration types */
80 SIDE_TYPE_ENUM_BITMAP
,
86 enum side_dynamic_type
{
88 SIDE_DYNAMIC_TYPE_NULL
,
89 SIDE_DYNAMIC_TYPE_BOOL
,
91 SIDE_DYNAMIC_TYPE_U16
,
92 SIDE_DYNAMIC_TYPE_U32
,
93 SIDE_DYNAMIC_TYPE_U64
,
95 SIDE_DYNAMIC_TYPE_S16
,
96 SIDE_DYNAMIC_TYPE_S32
,
97 SIDE_DYNAMIC_TYPE_S64
,
98 SIDE_DYNAMIC_TYPE_BYTE
,
99 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
100 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
101 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
102 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
103 SIDE_DYNAMIC_TYPE_STRING
,
106 SIDE_DYNAMIC_TYPE_STRUCT
,
107 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
108 SIDE_DYNAMIC_TYPE_VLA
,
109 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
112 enum side_attr_type
{
123 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
124 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
125 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
126 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
127 SIDE_ATTR_TYPE_STRING
,
131 SIDE_LOGLEVEL_EMERG
= 0,
132 SIDE_LOGLEVEL_ALERT
= 1,
133 SIDE_LOGLEVEL_CRIT
= 2,
134 SIDE_LOGLEVEL_ERR
= 3,
135 SIDE_LOGLEVEL_WARNING
= 4,
136 SIDE_LOGLEVEL_NOTICE
= 5,
137 SIDE_LOGLEVEL_INFO
= 6,
138 SIDE_LOGLEVEL_DEBUG
= 7,
141 enum side_visitor_status
{
142 SIDE_VISITOR_STATUS_OK
= 0,
143 SIDE_VISITOR_STATUS_ERROR
= -1,
146 typedef enum side_visitor_status (*side_visitor
)(
147 const struct side_tracer_visitor_ctx
*tracer_ctx
,
149 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
150 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
152 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
153 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
156 struct side_attr_value
{
157 uint32_t type
; /* enum side_attr_type */
169 _Float16 side_float_binary16
;
172 _Float32 side_float_binary32
;
175 _Float64 side_float_binary64
;
178 _Float128 side_float_binary128
;
184 /* User attributes. */
187 const struct side_attr_value value
;
190 struct side_enum_mapping
{
196 struct side_enum_mappings
{
197 const struct side_enum_mapping
*mappings
;
198 const struct side_attr
*attr
;
199 uint32_t nr_mappings
;
203 struct side_enum_bitmap_mapping
{
204 uint64_t range_begin
;
209 struct side_enum_bitmap_mappings
{
210 const struct side_enum_bitmap_mapping
*mappings
;
211 const struct side_attr
*attr
;
212 uint32_t nr_mappings
;
216 struct side_type_struct
{
219 const struct side_event_field
*fields
;
220 const struct side_attr
*attr
;
223 struct side_type_description
{
224 uint32_t type
; /* enum side_type */
228 const struct side_attr
*attr
;
234 const struct side_type_description
*elem_type
;
235 const struct side_attr
*attr
;
240 const struct side_type_description
*elem_type
;
241 const struct side_attr
*attr
;
245 const struct side_type_description
*elem_type
;
246 side_visitor visitor
;
247 const struct side_attr
*attr
;
250 const struct side_type_struct
*side_struct
;
252 /* Enumeration types */
254 const struct side_enum_mappings
*mappings
;
255 const struct side_type_description
*elem_type
;
258 const struct side_enum_bitmap_mappings
*mappings
;
259 const struct side_type_description
*elem_type
;
264 struct side_event_field
{
265 const char *field_name
;
266 struct side_type_description side_type
;
269 enum side_event_flags
{
270 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
273 struct side_callback
{
275 void (*call
)(const struct side_event_description
*desc
,
276 const struct side_arg_vec_description
*sav_desc
,
278 void (*call_variadic
)(const struct side_event_description
*desc
,
279 const struct side_arg_vec_description
*sav_desc
,
280 const struct side_arg_dynamic_event_struct
*var_struct
,
286 struct side_event_description
{
289 uint32_t loglevel
; /* enum side_loglevel */
294 const char *provider_name
;
295 const char *event_name
;
296 const struct side_event_field
*fields
;
297 const struct side_attr
*attr
;
298 const struct side_callback
*callbacks
;
301 struct side_arg_dynamic_vec
{
302 uint32_t dynamic_type
; /* enum side_dynamic_type */
306 const struct side_attr
*attr
;
320 _Float16 side_float_binary16
;
323 _Float32 side_float_binary32
;
326 _Float64 side_float_binary64
;
329 _Float128 side_float_binary128
;
336 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
339 side_dynamic_struct_visitor visitor
;
340 const struct side_attr
*attr
;
342 } side_dynamic_struct_visitor
;
343 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
346 side_dynamic_vla_visitor visitor
;
347 const struct side_attr
*attr
;
349 } side_dynamic_vla_visitor
;
353 struct side_arg_dynamic_vec_vla
{
354 const struct side_arg_dynamic_vec
*sav
;
355 const struct side_attr
*attr
;
360 struct side_arg_dynamic_event_field
{
361 const char *field_name
;
362 const struct side_arg_dynamic_vec elem
;
365 struct side_arg_dynamic_event_struct
{
366 const struct side_arg_dynamic_event_field
*fields
;
367 const struct side_attr
*attr
;
372 struct side_arg_vec
{
387 _Float16 side_float_binary16
;
390 _Float32 side_float_binary32
;
393 _Float64 side_float_binary64
;
396 _Float128 side_float_binary128
;
401 const struct side_arg_vec_description
*side_struct
;
402 const struct side_arg_vec_description
*side_array
;
403 const struct side_arg_vec_description
*side_vla
;
404 void *side_vla_app_visitor_ctx
;
405 void *side_array_fixint
;
412 struct side_arg_dynamic_vec dynamic
;
416 struct side_arg_vec_description
{
417 const struct side_arg_vec
*sav
;
421 /* The visitor pattern is a double-dispatch visitor. */
422 struct side_tracer_visitor_ctx
{
423 enum side_visitor_status (*write_elem
)(
424 const struct side_tracer_visitor_ctx
*tracer_ctx
,
425 const struct side_arg_vec
*elem
);
426 void *priv
; /* Private tracer context. */
429 struct side_tracer_dynamic_struct_visitor_ctx
{
430 enum side_visitor_status (*write_field
)(
431 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
432 const struct side_arg_dynamic_event_field
*dynamic_field
);
433 void *priv
; /* Private tracer context. */
436 struct side_tracer_dynamic_vla_visitor_ctx
{
437 enum side_visitor_status (*write_elem
)(
438 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
439 const struct side_arg_dynamic_vec
*elem
);
440 void *priv
; /* Private tracer context. */
443 /* Event and type attributes */
445 #define side_attr(_key, _value) \
448 .value = SIDE_PARAM(_value), \
451 #define side_attr_list(...) \
452 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
454 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
455 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
456 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
457 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
458 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
459 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
460 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
461 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
462 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
463 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
464 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
465 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
466 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
467 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
468 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
470 /* Static field definition */
472 #define _side_type_basic(_type, _attr) \
478 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
483 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
484 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_PARAM(_attr))
485 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_PARAM(_attr))
486 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_PARAM(_attr))
487 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_PARAM(_attr))
488 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_PARAM(_attr))
489 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_PARAM(_attr))
490 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_PARAM(_attr))
491 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_PARAM(_attr))
492 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_PARAM(_attr))
493 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
494 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
495 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
496 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_PARAM(_attr))
497 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
498 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
500 #define _side_field(_name, _type) \
502 .field_name = _name, \
503 .side_type = _type, \
506 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
507 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
508 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
509 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
510 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
511 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
512 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
513 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
514 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
515 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
516 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
517 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
518 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
519 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
520 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
521 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
523 #define side_type_enum(_mappings, _elem_type) \
525 .type = SIDE_TYPE_ENUM, \
528 .mappings = _mappings, \
529 .elem_type = _elem_type, \
533 #define side_field_enum(_name, _mappings, _elem_type) \
534 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
536 #define side_type_enum_bitmap(_mappings, _elem_type) \
538 .type = SIDE_TYPE_ENUM_BITMAP, \
540 .side_enum_bitmap = { \
541 .mappings = _mappings, \
542 .elem_type = _elem_type, \
546 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
547 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
549 #define side_type_struct(_struct) \
551 .type = SIDE_TYPE_STRUCT, \
553 .side_struct = _struct, \
556 #define side_field_struct(_name, _struct) \
557 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
559 #define _side_type_struct_define(_fields, _attr) \
561 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
562 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
567 #define side_define_struct(_identifier, _fields, _attr) \
568 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
570 #define side_struct_literal(_fields, _attr) \
571 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
572 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
574 #define side_type_array(_elem_type, _length, _attr) \
576 .type = SIDE_TYPE_ARRAY, \
579 .elem_type = _elem_type, \
582 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
586 #define side_field_array(_name, _elem_type, _length, _attr) \
587 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
589 #define side_type_vla(_elem_type, _attr) \
591 .type = SIDE_TYPE_VLA, \
594 .elem_type = _elem_type, \
596 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
600 #define side_field_vla(_name, _elem_type, _attr) \
601 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
603 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
605 .type = SIDE_TYPE_VLA_VISITOR, \
607 .side_vla_visitor = { \
608 .elem_type = SIDE_PARAM(_elem_type), \
609 .visitor = _visitor, \
611 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
615 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
616 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
618 #define side_elem(...) \
619 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
621 #define side_field_list(...) \
622 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
624 /* Static field arguments */
626 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
627 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
628 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
629 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
630 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
631 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
632 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
633 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
634 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
635 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
636 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
637 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
638 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
639 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
640 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
641 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
642 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
643 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
644 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
645 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
647 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
648 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
649 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
650 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
651 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
653 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
654 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
655 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
656 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
657 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
658 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
659 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
660 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
661 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
663 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
664 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
665 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
666 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
667 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
668 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
669 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
670 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
671 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
673 #define side_arg_dynamic(_dynamic_arg_type) \
675 .type = SIDE_TYPE_DYNAMIC, \
677 .dynamic = _dynamic_arg_type, \
681 /* Dynamic field arguments */
683 #define side_arg_dynamic_null(_attr) \
685 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
689 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
694 #define side_arg_dynamic_bool(_val, _attr) \
696 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
700 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
702 .side_bool = !!(_val), \
708 #define side_arg_dynamic_u8(_val, _attr) \
710 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
714 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
721 #define side_arg_dynamic_u16(_val, _attr) \
723 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
727 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
729 .side_u16 = (_val), \
734 #define side_arg_dynamic_u32(_val, _attr) \
736 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
740 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
742 .side_u32 = (_val), \
747 #define side_arg_dynamic_u64(_val, _attr) \
749 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
753 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
755 .side_u64 = (_val), \
761 #define side_arg_dynamic_s8(_val, _attr) \
763 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
767 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
774 #define side_arg_dynamic_s16(_val, _attr) \
776 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
780 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
782 .side_s16 = (_val), \
787 #define side_arg_dynamic_s32(_val, _attr) \
789 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
793 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
795 .side_s32 = (_val), \
800 #define side_arg_dynamic_s64(_val, _attr) \
802 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
806 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
808 .side_s64 = (_val), \
813 #define side_arg_dynamic_byte(_val, _attr) \
815 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
819 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
821 .side_byte = (_val), \
827 #define side_arg_dynamic_float_binary16(_val, _attr) \
829 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
833 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
835 .side_float_binary16 = (_val), \
840 #define side_arg_dynamic_float_binary32(_val, _attr) \
842 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
846 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
848 .side_float_binary32 = (_val), \
853 #define side_arg_dynamic_float_binary64(_val, _attr) \
855 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
859 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
861 .side_float_binary64 = (_val), \
866 #define side_arg_dynamic_float_binary128(_val, _attr) \
868 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
872 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
874 .side_float_binary128 = (_val), \
880 #define side_arg_dynamic_string(_val, _attr) \
882 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
886 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
894 #define side_arg_dynamic_vla(_vla) \
896 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
898 .side_dynamic_vla = (_vla), \
902 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
904 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
906 .side_dynamic_vla_visitor = { \
908 .visitor = _dynamic_vla_visitor, \
910 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
915 #define side_arg_dynamic_struct(_struct) \
917 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
919 .side_dynamic_struct = (_struct), \
923 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
925 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
927 .side_dynamic_struct_visitor = { \
929 .visitor = _dynamic_struct_visitor, \
931 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
936 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
937 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
938 const struct side_arg_dynamic_vec_vla _identifier = { \
939 .sav = _identifier##_vec, \
941 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
942 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
945 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
946 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
947 const struct side_arg_dynamic_event_struct _identifier = { \
948 .fields = _identifier##_fields, \
950 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
951 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
954 #define side_arg_define_vec(_identifier, _sav) \
955 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
956 const struct side_arg_vec_description _identifier = { \
957 .sav = _identifier##_vec, \
958 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
961 #define side_arg_dynamic_field(_name, _elem) \
963 .field_name = _name, \
967 #define side_arg_list(...) __VA_ARGS__
969 #define side_define_enum(_identifier, _mappings, _attr) \
970 const struct side_enum_mappings _identifier = { \
971 .mappings = _mappings, \
973 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
974 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
977 #define side_enum_mapping_list(...) \
978 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
980 #define side_enum_mapping_range(_label, _begin, _end) \
982 .range_begin = _begin, \
987 #define side_enum_mapping_value(_label, _value) \
989 .range_begin = _value, \
990 .range_end = _value, \
994 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
995 const struct side_enum_bitmap_mappings _identifier = { \
996 .mappings = _mappings, \
998 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
999 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1002 #define side_enum_bitmap_mapping_list(...) \
1003 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1005 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1007 .range_begin = _begin, \
1008 .range_end = _end, \
1012 #define side_enum_bitmap_mapping_value(_label, _value) \
1014 .range_begin = _value, \
1015 .range_end = _value, \
1019 #define side_event_cond(_identifier) if (side_unlikely(side_event_enable__##_identifier))
1021 #define side_event_call(_identifier, _sav) \
1023 const struct side_arg_vec side_sav[] = { _sav }; \
1024 const struct side_arg_vec_description sav_desc = { \
1026 .len = SIDE_ARRAY_SIZE(side_sav), \
1028 side_call(&(_identifier), &sav_desc); \
1031 #define side_event(_identifier, _sav) \
1032 side_event_cond(_identifier) \
1033 side_event_call(_identifier, SIDE_PARAM(_sav))
1035 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1037 const struct side_arg_vec side_sav[] = { _sav }; \
1038 const struct side_arg_vec_description sav_desc = { \
1040 .len = SIDE_ARRAY_SIZE(side_sav), \
1042 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1043 const struct side_arg_dynamic_event_struct var_struct = { \
1044 .fields = side_fields, \
1046 .len = SIDE_ARRAY_SIZE(side_fields), \
1047 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1049 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1052 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1053 side_event_cond(_identifier) \
1054 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1056 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1057 _linkage uint32_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1058 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1061 .enabled = &(side_event_enable__##_identifier), \
1062 .loglevel = _loglevel, \
1063 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1064 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1066 .flags = (_flags), \
1067 .provider_name = _provider, \
1068 .event_name = _event, \
1069 .fields = _fields, \
1071 .callbacks = &side_empty_callback, \
1073 static const struct side_event_description *side_event_ptr__##_identifier \
1074 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1076 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1077 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1078 SIDE_PARAM(_attr), 0)
1080 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1081 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1082 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1084 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1085 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1086 SIDE_PARAM(_attr), 0)
1088 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1089 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1090 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1092 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1093 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1094 SIDE_PARAM(_attr), 0)
1096 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1097 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1098 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1100 #define side_declare_event(_identifier) \
1101 extern uint32_t side_event_enable_##_identifier; \
1102 extern struct side_event_description _identifier
1104 void side_call(const struct side_event_description
*desc
,
1105 const struct side_arg_vec_description
*sav_desc
);
1106 void side_call_variadic(const struct side_event_description
*desc
,
1107 const struct side_arg_vec_description
*sav_desc
,
1108 const struct side_arg_dynamic_event_struct
*var_struct
);
1110 extern const struct side_callback side_empty_callback
;
1112 #endif /* _SIDE_TRACE_H */