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,
148 SIDE_ERROR_INVAL
= 1,
149 SIDE_ERROR_EXIST
= 2,
150 SIDE_ERROR_NOMEM
= 3,
151 SIDE_ERROR_NOENT
= 4,
154 typedef enum side_visitor_status (*side_visitor
)(
155 const struct side_tracer_visitor_ctx
*tracer_ctx
,
157 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
158 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
160 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
161 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
164 struct side_attr_value
{
165 uint32_t type
; /* enum side_attr_type */
177 _Float16 side_float_binary16
;
180 _Float32 side_float_binary32
;
183 _Float64 side_float_binary64
;
186 _Float128 side_float_binary128
;
192 /* User attributes. */
195 const struct side_attr_value value
;
198 struct side_enum_mapping
{
204 struct side_enum_mappings
{
205 const struct side_enum_mapping
*mappings
;
206 const struct side_attr
*attr
;
207 uint32_t nr_mappings
;
211 struct side_enum_bitmap_mapping
{
212 uint64_t range_begin
;
217 struct side_enum_bitmap_mappings
{
218 const struct side_enum_bitmap_mapping
*mappings
;
219 const struct side_attr
*attr
;
220 uint32_t nr_mappings
;
224 struct side_type_struct
{
227 const struct side_event_field
*fields
;
228 const struct side_attr
*attr
;
231 struct side_type_description
{
232 uint32_t type
; /* enum side_type */
236 const struct side_attr
*attr
;
242 const struct side_type_description
*elem_type
;
243 const struct side_attr
*attr
;
248 const struct side_type_description
*elem_type
;
249 const struct side_attr
*attr
;
253 const struct side_type_description
*elem_type
;
254 side_visitor visitor
;
255 const struct side_attr
*attr
;
258 const struct side_type_struct
*side_struct
;
260 /* Enumeration types */
262 const struct side_enum_mappings
*mappings
;
263 const struct side_type_description
*elem_type
;
266 const struct side_enum_bitmap_mappings
*mappings
;
267 const struct side_type_description
*elem_type
;
272 struct side_event_field
{
273 const char *field_name
;
274 struct side_type_description side_type
;
277 enum side_event_flags
{
278 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
281 struct side_callback
{
283 void (*call
)(const struct side_event_description
*desc
,
284 const struct side_arg_vec_description
*sav_desc
,
286 void (*call_variadic
)(const struct side_event_description
*desc
,
287 const struct side_arg_vec_description
*sav_desc
,
288 const struct side_arg_dynamic_event_struct
*var_struct
,
294 struct side_event_description
{
297 uint32_t loglevel
; /* enum side_loglevel */
302 const char *provider_name
;
303 const char *event_name
;
304 const struct side_event_field
*fields
;
305 const struct side_attr
*attr
;
306 const struct side_callback
*callbacks
;
309 struct side_arg_dynamic_vec
{
310 uint32_t dynamic_type
; /* enum side_dynamic_type */
314 const struct side_attr
*attr
;
328 _Float16 side_float_binary16
;
331 _Float32 side_float_binary32
;
334 _Float64 side_float_binary64
;
337 _Float128 side_float_binary128
;
344 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
347 side_dynamic_struct_visitor visitor
;
348 const struct side_attr
*attr
;
350 } side_dynamic_struct_visitor
;
351 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
354 side_dynamic_vla_visitor visitor
;
355 const struct side_attr
*attr
;
357 } side_dynamic_vla_visitor
;
361 struct side_arg_dynamic_vec_vla
{
362 const struct side_arg_dynamic_vec
*sav
;
363 const struct side_attr
*attr
;
368 struct side_arg_dynamic_event_field
{
369 const char *field_name
;
370 const struct side_arg_dynamic_vec elem
;
373 struct side_arg_dynamic_event_struct
{
374 const struct side_arg_dynamic_event_field
*fields
;
375 const struct side_attr
*attr
;
380 struct side_arg_vec
{
395 _Float16 side_float_binary16
;
398 _Float32 side_float_binary32
;
401 _Float64 side_float_binary64
;
404 _Float128 side_float_binary128
;
409 const struct side_arg_vec_description
*side_struct
;
410 const struct side_arg_vec_description
*side_array
;
411 const struct side_arg_vec_description
*side_vla
;
412 void *side_vla_app_visitor_ctx
;
413 void *side_array_fixint
;
420 struct side_arg_dynamic_vec dynamic
;
424 struct side_arg_vec_description
{
425 const struct side_arg_vec
*sav
;
429 /* The visitor pattern is a double-dispatch visitor. */
430 struct side_tracer_visitor_ctx
{
431 enum side_visitor_status (*write_elem
)(
432 const struct side_tracer_visitor_ctx
*tracer_ctx
,
433 const struct side_arg_vec
*elem
);
434 void *priv
; /* Private tracer context. */
437 struct side_tracer_dynamic_struct_visitor_ctx
{
438 enum side_visitor_status (*write_field
)(
439 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
440 const struct side_arg_dynamic_event_field
*dynamic_field
);
441 void *priv
; /* Private tracer context. */
444 struct side_tracer_dynamic_vla_visitor_ctx
{
445 enum side_visitor_status (*write_elem
)(
446 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
447 const struct side_arg_dynamic_vec
*elem
);
448 void *priv
; /* Private tracer context. */
451 /* Event and type attributes */
453 #define side_attr(_key, _value) \
456 .value = SIDE_PARAM(_value), \
459 #define side_attr_list(...) \
460 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
462 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
463 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
464 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
465 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
466 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
467 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
468 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
469 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
470 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
471 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
472 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
473 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
474 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
475 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
476 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
478 /* Static field definition */
480 #define _side_type_basic(_type, _attr) \
486 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
491 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
492 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_PARAM(_attr))
493 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_PARAM(_attr))
494 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_PARAM(_attr))
495 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_PARAM(_attr))
496 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_PARAM(_attr))
497 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_PARAM(_attr))
498 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_PARAM(_attr))
499 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_PARAM(_attr))
500 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_PARAM(_attr))
501 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
502 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
503 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
504 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_PARAM(_attr))
505 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
506 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
508 #define _side_field(_name, _type) \
510 .field_name = _name, \
511 .side_type = _type, \
514 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
515 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
516 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
517 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
518 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
519 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
520 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
521 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
522 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
523 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
524 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
525 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
526 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
527 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
528 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
529 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
531 #define side_type_enum(_mappings, _elem_type) \
533 .type = SIDE_TYPE_ENUM, \
536 .mappings = _mappings, \
537 .elem_type = _elem_type, \
541 #define side_field_enum(_name, _mappings, _elem_type) \
542 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
544 #define side_type_enum_bitmap(_mappings, _elem_type) \
546 .type = SIDE_TYPE_ENUM_BITMAP, \
548 .side_enum_bitmap = { \
549 .mappings = _mappings, \
550 .elem_type = _elem_type, \
554 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
555 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
557 #define side_type_struct(_struct) \
559 .type = SIDE_TYPE_STRUCT, \
561 .side_struct = _struct, \
564 #define side_field_struct(_name, _struct) \
565 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
567 #define _side_type_struct_define(_fields, _attr) \
569 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
570 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
575 #define side_define_struct(_identifier, _fields, _attr) \
576 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
578 #define side_struct_literal(_fields, _attr) \
579 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
580 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
582 #define side_type_array(_elem_type, _length, _attr) \
584 .type = SIDE_TYPE_ARRAY, \
587 .elem_type = _elem_type, \
590 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
594 #define side_field_array(_name, _elem_type, _length, _attr) \
595 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
597 #define side_type_vla(_elem_type, _attr) \
599 .type = SIDE_TYPE_VLA, \
602 .elem_type = _elem_type, \
604 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
608 #define side_field_vla(_name, _elem_type, _attr) \
609 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
611 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
613 .type = SIDE_TYPE_VLA_VISITOR, \
615 .side_vla_visitor = { \
616 .elem_type = SIDE_PARAM(_elem_type), \
617 .visitor = _visitor, \
619 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
623 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
624 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
626 #define side_elem(...) \
627 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
629 #define side_field_list(...) \
630 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
632 /* Static field arguments */
634 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
635 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
636 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
637 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
638 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
639 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
640 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
641 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
642 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
643 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
644 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
645 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
646 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
647 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
648 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
649 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
650 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
651 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
652 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
653 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
655 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
656 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
657 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
658 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
659 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
661 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
662 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
663 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
664 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
665 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
666 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
667 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
668 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
669 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
671 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
672 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
673 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
674 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
675 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
676 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
677 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
678 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
679 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
681 #define side_arg_dynamic(_dynamic_arg_type) \
683 .type = SIDE_TYPE_DYNAMIC, \
685 .dynamic = _dynamic_arg_type, \
689 /* Dynamic field arguments */
691 #define side_arg_dynamic_null(_attr) \
693 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
697 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
702 #define side_arg_dynamic_bool(_val, _attr) \
704 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
708 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
710 .side_bool = !!(_val), \
716 #define side_arg_dynamic_u8(_val, _attr) \
718 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
722 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
729 #define side_arg_dynamic_u16(_val, _attr) \
731 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
735 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
737 .side_u16 = (_val), \
742 #define side_arg_dynamic_u32(_val, _attr) \
744 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
748 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
750 .side_u32 = (_val), \
755 #define side_arg_dynamic_u64(_val, _attr) \
757 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
761 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
763 .side_u64 = (_val), \
769 #define side_arg_dynamic_s8(_val, _attr) \
771 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
775 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
782 #define side_arg_dynamic_s16(_val, _attr) \
784 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
788 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
790 .side_s16 = (_val), \
795 #define side_arg_dynamic_s32(_val, _attr) \
797 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
801 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
803 .side_s32 = (_val), \
808 #define side_arg_dynamic_s64(_val, _attr) \
810 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
814 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
816 .side_s64 = (_val), \
821 #define side_arg_dynamic_byte(_val, _attr) \
823 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
827 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
829 .side_byte = (_val), \
835 #define side_arg_dynamic_float_binary16(_val, _attr) \
837 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
841 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
843 .side_float_binary16 = (_val), \
848 #define side_arg_dynamic_float_binary32(_val, _attr) \
850 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
854 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
856 .side_float_binary32 = (_val), \
861 #define side_arg_dynamic_float_binary64(_val, _attr) \
863 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
867 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
869 .side_float_binary64 = (_val), \
874 #define side_arg_dynamic_float_binary128(_val, _attr) \
876 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
880 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
882 .side_float_binary128 = (_val), \
888 #define side_arg_dynamic_string(_val, _attr) \
890 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
894 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
902 #define side_arg_dynamic_vla(_vla) \
904 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
906 .side_dynamic_vla = (_vla), \
910 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
912 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
914 .side_dynamic_vla_visitor = { \
916 .visitor = _dynamic_vla_visitor, \
918 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
923 #define side_arg_dynamic_struct(_struct) \
925 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
927 .side_dynamic_struct = (_struct), \
931 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
933 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
935 .side_dynamic_struct_visitor = { \
937 .visitor = _dynamic_struct_visitor, \
939 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
944 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
945 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
946 const struct side_arg_dynamic_vec_vla _identifier = { \
947 .sav = _identifier##_vec, \
949 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
950 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
953 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
954 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
955 const struct side_arg_dynamic_event_struct _identifier = { \
956 .fields = _identifier##_fields, \
958 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
959 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
962 #define side_arg_define_vec(_identifier, _sav) \
963 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
964 const struct side_arg_vec_description _identifier = { \
965 .sav = _identifier##_vec, \
966 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
969 #define side_arg_dynamic_field(_name, _elem) \
971 .field_name = _name, \
975 #define side_arg_list(...) __VA_ARGS__
977 #define side_define_enum(_identifier, _mappings, _attr) \
978 const struct side_enum_mappings _identifier = { \
979 .mappings = _mappings, \
981 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
982 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
985 #define side_enum_mapping_list(...) \
986 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
988 #define side_enum_mapping_range(_label, _begin, _end) \
990 .range_begin = _begin, \
995 #define side_enum_mapping_value(_label, _value) \
997 .range_begin = _value, \
998 .range_end = _value, \
1002 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1003 const struct side_enum_bitmap_mappings _identifier = { \
1004 .mappings = _mappings, \
1006 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1007 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1010 #define side_enum_bitmap_mapping_list(...) \
1011 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1013 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1015 .range_begin = _begin, \
1016 .range_end = _end, \
1020 #define side_enum_bitmap_mapping_value(_label, _value) \
1022 .range_begin = _value, \
1023 .range_end = _value, \
1027 #define side_event_cond(_identifier) \
1028 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1031 #define side_event_call(_identifier, _sav) \
1033 const struct side_arg_vec side_sav[] = { _sav }; \
1034 const struct side_arg_vec_description sav_desc = { \
1036 .len = SIDE_ARRAY_SIZE(side_sav), \
1038 side_call(&(_identifier), &sav_desc); \
1041 #define side_event(_identifier, _sav) \
1042 side_event_cond(_identifier) \
1043 side_event_call(_identifier, SIDE_PARAM(_sav))
1045 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1047 const struct side_arg_vec side_sav[] = { _sav }; \
1048 const struct side_arg_vec_description sav_desc = { \
1050 .len = SIDE_ARRAY_SIZE(side_sav), \
1052 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1053 const struct side_arg_dynamic_event_struct var_struct = { \
1054 .fields = side_fields, \
1056 .len = SIDE_ARRAY_SIZE(side_fields), \
1057 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1059 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1062 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1063 side_event_cond(_identifier) \
1064 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1066 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1067 _linkage uint32_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1068 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1071 .enabled = &(side_event_enable__##_identifier), \
1072 .loglevel = _loglevel, \
1073 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1074 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1076 .flags = (_flags), \
1077 .provider_name = _provider, \
1078 .event_name = _event, \
1079 .fields = _fields, \
1081 .callbacks = &side_empty_callback, \
1083 static const struct side_event_description *side_event_ptr__##_identifier \
1084 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1086 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1087 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1088 SIDE_PARAM(_attr), 0)
1090 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1091 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1092 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1094 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1095 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1096 SIDE_PARAM(_attr), 0)
1098 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1099 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1100 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1102 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1103 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1104 SIDE_PARAM(_attr), 0)
1106 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1107 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1108 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1110 #define side_declare_event(_identifier) \
1111 extern uint32_t side_event_enable_##_identifier; \
1112 extern struct side_event_description _identifier
1114 extern const struct side_callback side_empty_callback
;
1116 void side_call(const struct side_event_description
*desc
,
1117 const struct side_arg_vec_description
*sav_desc
);
1118 void side_call_variadic(const struct side_event_description
*desc
,
1119 const struct side_arg_vec_description
*sav_desc
,
1120 const struct side_arg_dynamic_event_struct
*var_struct
);
1122 int side_tracer_callback_register(struct side_event_description
*desc
,
1123 void (*call
)(const struct side_event_description
*desc
,
1124 const struct side_arg_vec_description
*sav_desc
,
1127 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1128 void (*call_variadic
)(const struct side_event_description
*desc
,
1129 const struct side_arg_vec_description
*sav_desc
,
1130 const struct side_arg_dynamic_event_struct
*var_struct
,
1133 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1134 void (*call
)(const struct side_event_description
*desc
,
1135 const struct side_arg_vec_description
*sav_desc
,
1138 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1139 void (*call_variadic
)(const struct side_event_description
*desc
,
1140 const struct side_arg_vec_description
*sav_desc
,
1141 const struct side_arg_dynamic_event_struct
*var_struct
,
1145 #endif /* _SIDE_TRACE_H */