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
{
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_callbacks
{
287 struct side_callback
*cb
;
291 struct side_event_description
{
294 uint32_t loglevel
; /* enum side_loglevel */
299 const char *provider_name
;
300 const char *event_name
;
301 const struct side_event_field
*fields
;
302 const struct side_attr
*attr
;
303 struct side_callbacks
*callbacks
;
306 struct side_arg_dynamic_vec
{
307 uint32_t dynamic_type
; /* enum side_dynamic_type */
311 const struct side_attr
*attr
;
325 _Float16 side_float_binary16
;
328 _Float32 side_float_binary32
;
331 _Float64 side_float_binary64
;
334 _Float128 side_float_binary128
;
341 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
344 side_dynamic_struct_visitor visitor
;
345 const struct side_attr
*attr
;
347 } side_dynamic_struct_visitor
;
348 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
351 side_dynamic_vla_visitor visitor
;
352 const struct side_attr
*attr
;
354 } side_dynamic_vla_visitor
;
358 struct side_arg_dynamic_vec_vla
{
359 const struct side_arg_dynamic_vec
*sav
;
360 const struct side_attr
*attr
;
365 struct side_arg_dynamic_event_field
{
366 const char *field_name
;
367 const struct side_arg_dynamic_vec elem
;
370 struct side_arg_dynamic_event_struct
{
371 const struct side_arg_dynamic_event_field
*fields
;
372 const struct side_attr
*attr
;
377 struct side_arg_vec
{
392 _Float16 side_float_binary16
;
395 _Float32 side_float_binary32
;
398 _Float64 side_float_binary64
;
401 _Float128 side_float_binary128
;
406 const struct side_arg_vec_description
*side_struct
;
407 const struct side_arg_vec_description
*side_array
;
408 const struct side_arg_vec_description
*side_vla
;
409 void *side_vla_app_visitor_ctx
;
410 void *side_array_fixint
;
417 struct side_arg_dynamic_vec dynamic
;
421 struct side_arg_vec_description
{
422 const struct side_arg_vec
*sav
;
426 /* The visitor pattern is a double-dispatch visitor. */
427 struct side_tracer_visitor_ctx
{
428 enum side_visitor_status (*write_elem
)(
429 const struct side_tracer_visitor_ctx
*tracer_ctx
,
430 const struct side_arg_vec
*elem
);
431 void *priv
; /* Private tracer context. */
434 struct side_tracer_dynamic_struct_visitor_ctx
{
435 enum side_visitor_status (*write_field
)(
436 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
437 const struct side_arg_dynamic_event_field
*dynamic_field
);
438 void *priv
; /* Private tracer context. */
441 struct side_tracer_dynamic_vla_visitor_ctx
{
442 enum side_visitor_status (*write_elem
)(
443 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
444 const struct side_arg_dynamic_vec
*elem
);
445 void *priv
; /* Private tracer context. */
448 /* Event and type attributes */
450 #define side_attr(_key, _value) \
453 .value = SIDE_PARAM(_value), \
456 #define side_attr_list(...) \
457 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
459 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
460 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
461 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
462 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
463 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
464 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
465 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
466 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
467 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
468 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
469 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
470 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
471 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
472 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
473 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
475 /* Static field definition */
477 #define _side_type_basic(_type, _attr) \
483 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
488 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
489 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_PARAM(_attr))
490 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_PARAM(_attr))
491 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_PARAM(_attr))
492 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_PARAM(_attr))
493 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_PARAM(_attr))
494 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_PARAM(_attr))
495 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_PARAM(_attr))
496 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_PARAM(_attr))
497 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_PARAM(_attr))
498 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
499 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
500 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
501 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_PARAM(_attr))
502 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
503 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
505 #define _side_field(_name, _type) \
507 .field_name = _name, \
508 .side_type = _type, \
511 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
512 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
513 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
514 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
515 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
516 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
517 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
518 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
519 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
520 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
521 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
522 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
523 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
524 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
525 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
526 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
528 #define side_type_enum(_mappings, _elem_type) \
530 .type = SIDE_TYPE_ENUM, \
533 .mappings = _mappings, \
534 .elem_type = _elem_type, \
538 #define side_field_enum(_name, _mappings, _elem_type) \
539 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
541 #define side_type_enum_bitmap(_mappings, _elem_type) \
543 .type = SIDE_TYPE_ENUM_BITMAP, \
545 .side_enum_bitmap = { \
546 .mappings = _mappings, \
547 .elem_type = _elem_type, \
551 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
552 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
554 #define side_type_struct(_struct) \
556 .type = SIDE_TYPE_STRUCT, \
558 .side_struct = _struct, \
561 #define side_field_struct(_name, _struct) \
562 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
564 #define _side_type_struct_define(_fields, _attr) \
566 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
567 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
572 #define side_define_struct(_identifier, _fields, _attr) \
573 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
575 #define side_struct_literal(_fields, _attr) \
576 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
577 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
579 #define side_type_array(_elem_type, _length, _attr) \
581 .type = SIDE_TYPE_ARRAY, \
584 .elem_type = _elem_type, \
587 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
591 #define side_field_array(_name, _elem_type, _length, _attr) \
592 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
594 #define side_type_vla(_elem_type, _attr) \
596 .type = SIDE_TYPE_VLA, \
599 .elem_type = _elem_type, \
601 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
605 #define side_field_vla(_name, _elem_type, _attr) \
606 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
608 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
610 .type = SIDE_TYPE_VLA_VISITOR, \
612 .side_vla_visitor = { \
613 .elem_type = SIDE_PARAM(_elem_type), \
614 .visitor = _visitor, \
616 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
620 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
621 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
623 #define side_elem(...) \
624 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
626 #define side_field_list(...) \
627 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
629 /* Static field arguments */
631 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
632 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
633 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
634 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
635 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
636 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
637 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
638 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
639 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
640 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
641 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
642 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
643 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
644 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
645 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
646 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
647 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
648 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
649 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
650 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
652 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
653 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
654 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
655 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
656 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
658 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
659 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
660 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
661 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
662 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
663 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
664 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
665 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
666 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
668 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
669 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
670 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
671 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
672 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
673 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
674 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
675 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
676 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
678 #define side_arg_dynamic(_dynamic_arg_type) \
680 .type = SIDE_TYPE_DYNAMIC, \
682 .dynamic = _dynamic_arg_type, \
686 /* Dynamic field arguments */
688 #define side_arg_dynamic_null(_attr) \
690 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
694 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
699 #define side_arg_dynamic_bool(_val, _attr) \
701 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
705 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
707 .side_bool = !!(_val), \
713 #define side_arg_dynamic_u8(_val, _attr) \
715 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
719 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
726 #define side_arg_dynamic_u16(_val, _attr) \
728 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
732 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
734 .side_u16 = (_val), \
739 #define side_arg_dynamic_u32(_val, _attr) \
741 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
745 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
747 .side_u32 = (_val), \
752 #define side_arg_dynamic_u64(_val, _attr) \
754 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
758 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
760 .side_u64 = (_val), \
766 #define side_arg_dynamic_s8(_val, _attr) \
768 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
772 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
779 #define side_arg_dynamic_s16(_val, _attr) \
781 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
785 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
787 .side_s16 = (_val), \
792 #define side_arg_dynamic_s32(_val, _attr) \
794 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
798 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
800 .side_s32 = (_val), \
805 #define side_arg_dynamic_s64(_val, _attr) \
807 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
811 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
813 .side_s64 = (_val), \
818 #define side_arg_dynamic_byte(_val, _attr) \
820 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
824 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
826 .side_byte = (_val), \
832 #define side_arg_dynamic_float_binary16(_val, _attr) \
834 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
838 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
840 .side_float_binary16 = (_val), \
845 #define side_arg_dynamic_float_binary32(_val, _attr) \
847 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
851 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
853 .side_float_binary32 = (_val), \
858 #define side_arg_dynamic_float_binary64(_val, _attr) \
860 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
864 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
866 .side_float_binary64 = (_val), \
871 #define side_arg_dynamic_float_binary128(_val, _attr) \
873 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
877 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
879 .side_float_binary128 = (_val), \
885 #define side_arg_dynamic_string(_val, _attr) \
887 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
891 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
899 #define side_arg_dynamic_vla(_vla) \
901 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
903 .side_dynamic_vla = (_vla), \
907 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
909 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
911 .side_dynamic_vla_visitor = { \
913 .visitor = _dynamic_vla_visitor, \
915 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
920 #define side_arg_dynamic_struct(_struct) \
922 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
924 .side_dynamic_struct = (_struct), \
928 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
930 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
932 .side_dynamic_struct_visitor = { \
934 .visitor = _dynamic_struct_visitor, \
936 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
941 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
942 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
943 const struct side_arg_dynamic_vec_vla _identifier = { \
944 .sav = _identifier##_vec, \
946 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
947 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
950 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
951 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
952 const struct side_arg_dynamic_event_struct _identifier = { \
953 .fields = _identifier##_fields, \
955 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
956 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
959 #define side_arg_define_vec(_identifier, _sav) \
960 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
961 const struct side_arg_vec_description _identifier = { \
962 .sav = _identifier##_vec, \
963 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
966 #define side_arg_dynamic_field(_name, _elem) \
968 .field_name = _name, \
972 #define side_arg_list(...) __VA_ARGS__
974 #define side_define_enum(_identifier, _mappings, _attr) \
975 const struct side_enum_mappings _identifier = { \
976 .mappings = _mappings, \
978 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
979 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
982 #define side_enum_mapping_list(...) \
983 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
985 #define side_enum_mapping_range(_label, _begin, _end) \
987 .range_begin = _begin, \
992 #define side_enum_mapping_value(_label, _value) \
994 .range_begin = _value, \
995 .range_end = _value, \
999 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1000 const struct side_enum_bitmap_mappings _identifier = { \
1001 .mappings = _mappings, \
1003 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1004 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1007 #define side_enum_bitmap_mapping_list(...) \
1008 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1010 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1012 .range_begin = _begin, \
1013 .range_end = _end, \
1017 #define side_enum_bitmap_mapping_value(_label, _value) \
1019 .range_begin = _value, \
1020 .range_end = _value, \
1024 #define side_event_cond(_desc) if (side_unlikely(_desc##_enabled))
1026 #define side_event_call(_desc, _sav) \
1028 const struct side_arg_vec side_sav[] = { _sav }; \
1029 const struct side_arg_vec_description sav_desc = { \
1031 .len = SIDE_ARRAY_SIZE(side_sav), \
1033 side_call(&(_desc), &sav_desc); \
1036 #define side_event(_desc, _sav) \
1037 side_event_cond(_desc) \
1038 side_event_call(_desc, SIDE_PARAM(_sav))
1040 #define side_event_call_variadic(_desc, _sav, _var_fields, _attr) \
1042 const struct side_arg_vec side_sav[] = { _sav }; \
1043 const struct side_arg_vec_description sav_desc = { \
1045 .len = SIDE_ARRAY_SIZE(side_sav), \
1047 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1048 const struct side_arg_dynamic_event_struct var_struct = { \
1049 .fields = side_fields, \
1051 .len = SIDE_ARRAY_SIZE(side_fields), \
1052 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1054 side_call_variadic(&(_desc), &sav_desc, &var_struct); \
1057 #define side_event_variadic(_desc, _sav, _var, _attr) \
1058 side_event_cond(_desc) \
1059 side_event_call_variadic(_desc, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1061 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1062 uint32_t _identifier##_enabled __attribute__((section("side_event_enable"))); \
1063 struct side_callbacks _identifier##_callbacks __attribute__((section("side_event_callbacks"))); \
1064 const struct side_event_description _identifier = { \
1066 .enabled = &(_identifier##_enabled), \
1067 .loglevel = _loglevel, \
1068 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1069 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1070 .flags = (_flags), \
1071 .provider_name = _provider, \
1072 .event_name = _event, \
1073 .fields = _fields, \
1075 .callbacks = &(_identifier##_callbacks), \
1077 const struct side_event_description *_identifier##_ptr \
1078 __attribute__((section("side_event_description"), used)) = &(_identifier);
1080 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1081 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1082 SIDE_PARAM(_attr), 0)
1084 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1085 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1086 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1088 #define side_declare_event(_identifier) \
1089 struct side_event_description _identifier
1091 void side_call(const struct side_event_description
*desc
,
1092 const struct side_arg_vec_description
*sav_desc
);
1093 void side_call_variadic(const struct side_event_description
*desc
,
1094 const struct side_arg_vec_description
*sav_desc
,
1095 const struct side_arg_dynamic_event_struct
*var_struct
);
1097 #endif /* _SIDE_TRACE_H */