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_BLOB
,
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
{
122 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
123 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
124 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
125 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
126 SIDE_ATTR_TYPE_STRING
,
130 SIDE_LOGLEVEL_EMERG
= 0,
131 SIDE_LOGLEVEL_ALERT
= 1,
132 SIDE_LOGLEVEL_CRIT
= 2,
133 SIDE_LOGLEVEL_ERR
= 3,
134 SIDE_LOGLEVEL_WARNING
= 4,
135 SIDE_LOGLEVEL_NOTICE
= 5,
136 SIDE_LOGLEVEL_INFO
= 6,
137 SIDE_LOGLEVEL_DEBUG
= 7,
140 enum side_visitor_status
{
141 SIDE_VISITOR_STATUS_OK
= 0,
142 SIDE_VISITOR_STATUS_ERROR
= -1,
145 typedef enum side_visitor_status (*side_visitor
)(
146 const struct side_tracer_visitor_ctx
*tracer_ctx
,
148 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
149 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
151 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
152 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
155 struct side_attr_value
{
156 uint32_t type
; /* enum side_attr_type */
168 _Float16 side_float_binary16
;
171 _Float32 side_float_binary32
;
174 _Float64 side_float_binary64
;
177 _Float128 side_float_binary128
;
183 /* User attributes. */
186 const struct side_attr_value value
;
189 struct side_enum_mapping
{
195 struct side_enum_mappings
{
196 const struct side_enum_mapping
*mappings
;
197 const struct side_attr
*attr
;
198 uint32_t nr_mappings
;
202 struct side_enum_bitmap_mapping
{
208 struct side_enum_bitmap_mappings
{
209 const struct side_enum_bitmap_mapping
*mappings
;
210 const struct side_attr
*attr
;
211 uint32_t nr_mappings
;
215 struct side_type_struct
{
218 const struct side_event_field
*fields
;
219 const struct side_attr
*attr
;
222 struct side_type_description
{
223 uint32_t type
; /* enum side_type */
227 const struct side_attr
*attr
;
233 const struct side_type_description
*elem_type
;
234 const struct side_attr
*attr
;
239 const struct side_type_description
*elem_type
;
240 const struct side_attr
*attr
;
244 const struct side_type_description
*elem_type
;
245 side_visitor visitor
;
246 const struct side_attr
*attr
;
249 const struct side_type_struct
*side_struct
;
251 /* Enumeration types */
253 const struct side_type_description
*elem_type
;
254 const struct side_enum_mappings
*mappings
;
257 const struct side_type_description
*elem_type
;
258 const struct side_enum_bitmap_mappings
*mappings
;
263 struct side_event_field
{
264 const char *field_name
;
265 struct side_type_description side_type
;
268 enum side_event_flags
{
269 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
272 struct side_callback
{
274 void (*call
)(const struct side_event_description
*desc
,
275 const struct side_arg_vec_description
*sav_desc
,
277 void (*call_variadic
)(const struct side_event_description
*desc
,
278 const struct side_arg_vec_description
*sav_desc
,
279 const struct side_arg_dynamic_event_struct
*var_struct
,
285 struct side_callbacks
{
286 struct side_callback
*cb
;
290 struct side_event_description
{
293 uint32_t loglevel
; /* enum side_loglevel */
298 const char *provider_name
;
299 const char *event_name
;
300 const struct side_event_field
*fields
;
301 const struct side_attr
*attr
;
302 struct side_callbacks
*callbacks
;
305 struct side_arg_dynamic_vec
{
306 uint32_t dynamic_type
; /* enum side_dynamic_type */
310 const struct side_attr
*attr
;
324 _Float16 side_float_binary16
;
327 _Float32 side_float_binary32
;
330 _Float64 side_float_binary64
;
333 _Float128 side_float_binary128
;
340 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
343 side_dynamic_struct_visitor visitor
;
344 const struct side_attr
*attr
;
346 } side_dynamic_struct_visitor
;
347 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
350 side_dynamic_vla_visitor visitor
;
351 const struct side_attr
*attr
;
353 } side_dynamic_vla_visitor
;
357 struct side_arg_dynamic_vec_vla
{
358 const struct side_arg_dynamic_vec
*sav
;
359 const struct side_attr
*attr
;
364 struct side_arg_dynamic_event_field
{
365 const char *field_name
;
366 const struct side_arg_dynamic_vec elem
;
369 struct side_arg_dynamic_event_struct
{
370 const struct side_arg_dynamic_event_field
*fields
;
371 const struct side_attr
*attr
;
376 struct side_arg_vec
{
391 _Float16 side_float_binary16
;
394 _Float32 side_float_binary32
;
397 _Float64 side_float_binary64
;
400 _Float128 side_float_binary128
;
405 const struct side_arg_vec_description
*side_struct
;
406 const struct side_arg_vec_description
*side_array
;
407 const struct side_arg_vec_description
*side_vla
;
408 void *side_vla_app_visitor_ctx
;
409 void *side_array_fixint
;
416 struct side_arg_dynamic_vec dynamic
;
420 struct side_arg_vec_description
{
421 const struct side_arg_vec
*sav
;
425 /* The visitor pattern is a double-dispatch visitor. */
426 struct side_tracer_visitor_ctx
{
427 enum side_visitor_status (*write_elem
)(
428 const struct side_tracer_visitor_ctx
*tracer_ctx
,
429 const struct side_arg_vec
*elem
);
430 void *priv
; /* Private tracer context. */
433 struct side_tracer_dynamic_struct_visitor_ctx
{
434 enum side_visitor_status (*write_field
)(
435 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
436 const struct side_arg_dynamic_event_field
*dynamic_field
);
437 void *priv
; /* Private tracer context. */
440 struct side_tracer_dynamic_vla_visitor_ctx
{
441 enum side_visitor_status (*write_elem
)(
442 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
443 const struct side_arg_dynamic_vec
*elem
);
444 void *priv
; /* Private tracer context. */
447 /* Event and type attributes */
449 #define side_attr(_key, _value) \
452 .value = SIDE_PARAM(_value), \
455 #define side_attr_list(...) \
456 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
458 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
459 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
460 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
461 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
462 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
463 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
464 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
465 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
466 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
467 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
468 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
469 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
470 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
471 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
473 /* Static field definition */
475 #define _side_type_basic(_type, _attr) \
481 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
486 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
487 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_PARAM(_attr))
488 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_PARAM(_attr))
489 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_PARAM(_attr))
490 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_PARAM(_attr))
491 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_PARAM(_attr))
492 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_PARAM(_attr))
493 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_PARAM(_attr))
494 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_PARAM(_attr))
495 #define side_type_blob(_attr) _side_type_basic(SIDE_TYPE_BLOB, SIDE_PARAM(_attr))
496 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
497 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
498 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
499 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_PARAM(_attr))
500 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
501 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
503 #define _side_field(_name, _type) \
505 .field_name = _name, \
506 .side_type = _type, \
509 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
510 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
511 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
512 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
513 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
514 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
515 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
516 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
517 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
518 #define side_field_blob(_name, _attr) _side_field(_name, side_type_blob(SIDE_PARAM(_attr)))
519 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
520 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
521 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
522 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
523 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
524 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
526 #define side_type_enum(_elem_type, _mappings) \
528 .type = SIDE_TYPE_ENUM, \
531 .elem_type = _elem_type, \
532 .mappings = _mappings, \
536 #define side_field_enum(_name, _elem_type, _mappings) \
537 _side_field(_name, side_type_enum(SIDE_PARAM(_elem_type), SIDE_PARAM(_mappings)))
539 #define side_type_enum_bitmap(_elem_type, _mappings) \
541 .type = SIDE_TYPE_ENUM_BITMAP, \
543 .side_enum_bitmap = { \
544 .elem_type = _elem_type, \
545 .mappings = _mappings, \
549 #define side_field_enum_bitmap(_name, _elem_type, _mappings) \
550 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_elem_type), SIDE_PARAM(_mappings)))
552 #define side_type_struct(_struct) \
554 .type = SIDE_TYPE_STRUCT, \
556 .side_struct = _struct, \
559 #define side_field_struct(_name, _struct) \
560 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
562 #define _side_type_struct_define(_fields, _attr) \
564 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
565 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
570 #define side_define_struct(_identifier, _fields, _attr) \
571 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
573 #define side_struct_literal(_fields, _attr) \
574 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
575 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
577 #define side_type_array(_elem_type, _length, _attr) \
579 .type = SIDE_TYPE_ARRAY, \
582 .elem_type = _elem_type, \
585 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
589 #define side_field_array(_name, _elem_type, _length, _attr) \
590 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
592 #define side_type_vla(_elem_type, _attr) \
594 .type = SIDE_TYPE_VLA, \
597 .elem_type = _elem_type, \
599 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
603 #define side_field_vla(_name, _elem_type, _attr) \
604 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
606 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
608 .type = SIDE_TYPE_VLA_VISITOR, \
610 .side_vla_visitor = { \
611 .elem_type = SIDE_PARAM(_elem_type), \
612 .visitor = _visitor, \
614 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
618 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
619 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
621 #define side_elem(...) \
622 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
624 #define side_field_list(...) \
625 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
627 /* Static field arguments */
629 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
630 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
631 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
632 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
633 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
634 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
635 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
636 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
637 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
638 #define side_arg_blob(_val) { .type = SIDE_TYPE_BLOB, .u = { .side_blob = (_val) } }
639 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
640 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
641 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
642 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
643 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
644 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
645 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
646 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
647 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
648 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
650 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
651 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
652 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
653 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
654 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
656 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
657 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
658 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
659 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
660 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
661 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
662 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
663 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
664 #define side_arg_array_blob(_ptr) { .type = SIDE_TYPE_ARRAY_BLOB, .u = { .side_array_fixint = (_ptr) } }
666 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
667 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
668 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
669 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
670 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
671 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
672 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
673 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
674 #define side_arg_vla_blob(_ptr, _length) { .type = SIDE_TYPE_VLA_BLOB, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
676 #define side_arg_dynamic(_dynamic_arg_type) \
678 .type = SIDE_TYPE_DYNAMIC, \
680 .dynamic = _dynamic_arg_type, \
684 /* Dynamic field arguments */
686 #define side_arg_dynamic_null(_attr) \
688 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
692 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
697 #define side_arg_dynamic_bool(_val, _attr) \
699 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
703 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
705 .side_bool = !!(_val), \
711 #define side_arg_dynamic_u8(_val, _attr) \
713 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
717 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
724 #define side_arg_dynamic_u16(_val, _attr) \
726 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
730 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
732 .side_u16 = (_val), \
737 #define side_arg_dynamic_u32(_val, _attr) \
739 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
743 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
745 .side_u32 = (_val), \
750 #define side_arg_dynamic_u64(_val, _attr) \
752 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
756 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
758 .side_u64 = (_val), \
764 #define side_arg_dynamic_s8(_val, _attr) \
766 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
770 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
777 #define side_arg_dynamic_s16(_val, _attr) \
779 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
783 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
785 .side_s16 = (_val), \
790 #define side_arg_dynamic_s32(_val, _attr) \
792 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
796 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
798 .side_s32 = (_val), \
803 #define side_arg_dynamic_s64(_val, _attr) \
805 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
809 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
811 .side_s64 = (_val), \
816 #define side_arg_dynamic_blob(_val, _attr) \
818 .dynamic_type = SIDE_DYNAMIC_TYPE_BLOB, \
822 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
824 .side_blob = (_val), \
830 #define side_arg_dynamic_float_binary16(_val, _attr) \
832 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
836 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
838 .side_float_binary16 = (_val), \
843 #define side_arg_dynamic_float_binary32(_val, _attr) \
845 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
849 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
851 .side_float_binary32 = (_val), \
856 #define side_arg_dynamic_float_binary64(_val, _attr) \
858 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
862 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
864 .side_float_binary64 = (_val), \
869 #define side_arg_dynamic_float_binary128(_val, _attr) \
871 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
875 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
877 .side_float_binary128 = (_val), \
883 #define side_arg_dynamic_string(_val, _attr) \
885 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
889 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
897 #define side_arg_dynamic_vla(_vla) \
899 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
901 .side_dynamic_vla = (_vla), \
905 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
907 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
909 .side_dynamic_vla_visitor = { \
911 .visitor = _dynamic_vla_visitor, \
913 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
918 #define side_arg_dynamic_struct(_struct) \
920 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
922 .side_dynamic_struct = (_struct), \
926 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
928 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
930 .side_dynamic_struct_visitor = { \
932 .visitor = _dynamic_struct_visitor, \
934 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
939 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
940 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
941 const struct side_arg_dynamic_vec_vla _identifier = { \
942 .sav = _identifier##_vec, \
944 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
945 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
948 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
949 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
950 const struct side_arg_dynamic_event_struct _identifier = { \
951 .fields = _identifier##_fields, \
953 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
954 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
957 #define side_arg_define_vec(_identifier, _sav) \
958 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
959 const struct side_arg_vec_description _identifier = { \
960 .sav = _identifier##_vec, \
961 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
964 #define side_arg_dynamic_field(_name, _elem) \
966 .field_name = _name, \
970 #define side_arg_list(...) __VA_ARGS__
972 #define side_define_enum(_identifier, _mappings, _attr) \
973 const struct side_enum_mappings _identifier = { \
974 .mappings = _mappings, \
976 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
977 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
980 #define side_enum_mapping_list(...) \
981 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
983 #define side_enum_mapping_range(_label, _begin, _end) \
985 .range_begin = _begin, \
990 #define side_enum_mapping_value(_label, _value) \
992 .range_begin = _value, \
993 .range_end = _value, \
997 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
998 const struct side_enum_bitmap_mappings _identifier = { \
999 .mappings = _mappings, \
1001 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1002 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1005 #define side_enum_bitmap_mapping_list(...) \
1006 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1008 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1010 .range_begin = _begin, \
1011 .range_end = _end, \
1015 #define side_enum_bitmap_mapping_value(_label, _value) \
1017 .range_begin = _value, \
1018 .range_end = _value, \
1022 #define side_event_cond(_desc) if (side_unlikely(_desc##_enabled))
1024 #define side_event_call(_desc, _sav) \
1026 const struct side_arg_vec side_sav[] = { _sav }; \
1027 const struct side_arg_vec_description sav_desc = { \
1029 .len = SIDE_ARRAY_SIZE(side_sav), \
1031 side_call(&(_desc), &sav_desc); \
1034 #define side_event(_desc, _sav) \
1035 side_event_cond(_desc) \
1036 side_event_call(_desc, SIDE_PARAM(_sav))
1038 #define side_event_call_variadic(_desc, _sav, _var_fields, _attr) \
1040 const struct side_arg_vec side_sav[] = { _sav }; \
1041 const struct side_arg_vec_description sav_desc = { \
1043 .len = SIDE_ARRAY_SIZE(side_sav), \
1045 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1046 const struct side_arg_dynamic_event_struct var_struct = { \
1047 .fields = side_fields, \
1049 .len = SIDE_ARRAY_SIZE(side_fields), \
1050 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1052 side_call_variadic(&(_desc), &sav_desc, &var_struct); \
1055 #define side_event_variadic(_desc, _sav, _var, _attr) \
1056 side_event_cond(_desc) \
1057 side_event_call_variadic(_desc, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1059 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1060 uint32_t _identifier##_enabled __attribute__((section("side_event_enable"))); \
1061 struct side_callbacks _identifier##_callbacks __attribute__((section("side_event_callbacks"))); \
1062 const struct side_event_description _identifier = { \
1064 .enabled = &(_identifier##_enabled), \
1065 .loglevel = _loglevel, \
1066 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1067 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1068 .flags = (_flags), \
1069 .provider_name = _provider, \
1070 .event_name = _event, \
1071 .fields = _fields, \
1073 .callbacks = &(_identifier##_callbacks), \
1075 const struct side_event_description *_identifier##_ptr \
1076 __attribute__((section("side_event_description"), used)) = &(_identifier);
1078 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1079 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1080 SIDE_PARAM(_attr), 0)
1082 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1083 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1084 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1086 #define side_declare_event(_identifier) \
1087 struct side_event_description _identifier
1089 void side_call(const struct side_event_description
*desc
,
1090 const struct side_arg_vec_description
*sav_desc
);
1091 void side_call_variadic(const struct side_event_description
*desc
,
1092 const struct side_arg_vec_description
*sav_desc
,
1093 const struct side_arg_dynamic_event_struct
*var_struct
);
1095 #endif /* _SIDE_TRACE_H */