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
;
33 struct side_events_register_handle
;
47 SIDE_TYPE_FLOAT_BINARY16
,
48 SIDE_TYPE_FLOAT_BINARY32
,
49 SIDE_TYPE_FLOAT_BINARY64
,
50 SIDE_TYPE_FLOAT_BINARY128
,
57 SIDE_TYPE_VLA_VISITOR
,
79 /* Enumeration types */
81 SIDE_TYPE_ENUM_BITMAP
,
87 enum side_dynamic_type
{
89 SIDE_DYNAMIC_TYPE_NULL
,
90 SIDE_DYNAMIC_TYPE_BOOL
,
92 SIDE_DYNAMIC_TYPE_U16
,
93 SIDE_DYNAMIC_TYPE_U32
,
94 SIDE_DYNAMIC_TYPE_U64
,
96 SIDE_DYNAMIC_TYPE_S16
,
97 SIDE_DYNAMIC_TYPE_S32
,
98 SIDE_DYNAMIC_TYPE_S64
,
99 SIDE_DYNAMIC_TYPE_BYTE
,
100 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
101 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
102 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
103 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
104 SIDE_DYNAMIC_TYPE_STRING
,
107 SIDE_DYNAMIC_TYPE_STRUCT
,
108 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
109 SIDE_DYNAMIC_TYPE_VLA
,
110 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
113 enum side_attr_type
{
124 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
125 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
126 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
127 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
128 SIDE_ATTR_TYPE_STRING
,
132 SIDE_LOGLEVEL_EMERG
= 0,
133 SIDE_LOGLEVEL_ALERT
= 1,
134 SIDE_LOGLEVEL_CRIT
= 2,
135 SIDE_LOGLEVEL_ERR
= 3,
136 SIDE_LOGLEVEL_WARNING
= 4,
137 SIDE_LOGLEVEL_NOTICE
= 5,
138 SIDE_LOGLEVEL_INFO
= 6,
139 SIDE_LOGLEVEL_DEBUG
= 7,
142 enum side_visitor_status
{
143 SIDE_VISITOR_STATUS_OK
= 0,
144 SIDE_VISITOR_STATUS_ERROR
= -1,
149 SIDE_ERROR_INVAL
= 1,
150 SIDE_ERROR_EXIST
= 2,
151 SIDE_ERROR_NOMEM
= 3,
152 SIDE_ERROR_NOENT
= 4,
153 SIDE_ERROR_EXITING
= 5,
156 typedef enum side_visitor_status (*side_visitor
)(
157 const struct side_tracer_visitor_ctx
*tracer_ctx
,
159 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
160 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
162 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
163 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
166 struct side_attr_value
{
167 uint32_t type
; /* enum side_attr_type */
179 _Float16 side_float_binary16
;
182 _Float32 side_float_binary32
;
185 _Float64 side_float_binary64
;
188 _Float128 side_float_binary128
;
194 /* User attributes. */
197 const struct side_attr_value value
;
200 struct side_enum_mapping
{
206 struct side_enum_mappings
{
207 const struct side_enum_mapping
*mappings
;
208 const struct side_attr
*attr
;
209 uint32_t nr_mappings
;
213 struct side_enum_bitmap_mapping
{
214 uint64_t range_begin
;
219 struct side_enum_bitmap_mappings
{
220 const struct side_enum_bitmap_mapping
*mappings
;
221 const struct side_attr
*attr
;
222 uint32_t nr_mappings
;
226 struct side_type_struct
{
229 const struct side_event_field
*fields
;
230 const struct side_attr
*attr
;
233 struct side_type_description
{
234 uint32_t type
; /* enum side_type */
238 const struct side_attr
*attr
;
244 const struct side_type_description
*elem_type
;
245 const struct side_attr
*attr
;
250 const struct side_type_description
*elem_type
;
251 const struct side_attr
*attr
;
255 const struct side_type_description
*elem_type
;
256 side_visitor visitor
;
257 const struct side_attr
*attr
;
260 const struct side_type_struct
*side_struct
;
262 /* Enumeration types */
264 const struct side_enum_mappings
*mappings
;
265 const struct side_type_description
*elem_type
;
268 const struct side_enum_bitmap_mappings
*mappings
;
269 const struct side_type_description
*elem_type
;
274 struct side_event_field
{
275 const char *field_name
;
276 struct side_type_description side_type
;
279 enum side_event_flags
{
280 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
283 struct side_callback
{
285 void (*call
)(const struct side_event_description
*desc
,
286 const struct side_arg_vec_description
*sav_desc
,
288 void (*call_variadic
)(const struct side_event_description
*desc
,
289 const struct side_arg_vec_description
*sav_desc
,
290 const struct side_arg_dynamic_event_struct
*var_struct
,
296 struct side_event_description
{
299 uint32_t loglevel
; /* enum side_loglevel */
304 const char *provider_name
;
305 const char *event_name
;
306 const struct side_event_field
*fields
;
307 const struct side_attr
*attr
;
308 const struct side_callback
*callbacks
;
311 struct side_arg_dynamic_vec
{
312 uint32_t dynamic_type
; /* enum side_dynamic_type */
316 const struct side_attr
*attr
;
330 _Float16 side_float_binary16
;
333 _Float32 side_float_binary32
;
336 _Float64 side_float_binary64
;
339 _Float128 side_float_binary128
;
346 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
349 side_dynamic_struct_visitor visitor
;
350 const struct side_attr
*attr
;
352 } side_dynamic_struct_visitor
;
353 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
356 side_dynamic_vla_visitor visitor
;
357 const struct side_attr
*attr
;
359 } side_dynamic_vla_visitor
;
363 struct side_arg_dynamic_vec_vla
{
364 const struct side_arg_dynamic_vec
*sav
;
365 const struct side_attr
*attr
;
370 struct side_arg_dynamic_event_field
{
371 const char *field_name
;
372 const struct side_arg_dynamic_vec elem
;
375 struct side_arg_dynamic_event_struct
{
376 const struct side_arg_dynamic_event_field
*fields
;
377 const struct side_attr
*attr
;
382 struct side_arg_vec
{
397 _Float16 side_float_binary16
;
400 _Float32 side_float_binary32
;
403 _Float64 side_float_binary64
;
406 _Float128 side_float_binary128
;
411 const struct side_arg_vec_description
*side_struct
;
412 const struct side_arg_vec_description
*side_array
;
413 const struct side_arg_vec_description
*side_vla
;
414 void *side_vla_app_visitor_ctx
;
415 void *side_array_fixint
;
422 struct side_arg_dynamic_vec dynamic
;
426 struct side_arg_vec_description
{
427 const struct side_arg_vec
*sav
;
431 /* The visitor pattern is a double-dispatch visitor. */
432 struct side_tracer_visitor_ctx
{
433 enum side_visitor_status (*write_elem
)(
434 const struct side_tracer_visitor_ctx
*tracer_ctx
,
435 const struct side_arg_vec
*elem
);
436 void *priv
; /* Private tracer context. */
439 struct side_tracer_dynamic_struct_visitor_ctx
{
440 enum side_visitor_status (*write_field
)(
441 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
442 const struct side_arg_dynamic_event_field
*dynamic_field
);
443 void *priv
; /* Private tracer context. */
446 struct side_tracer_dynamic_vla_visitor_ctx
{
447 enum side_visitor_status (*write_elem
)(
448 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
449 const struct side_arg_dynamic_vec
*elem
);
450 void *priv
; /* Private tracer context. */
453 /* Event and type attributes */
455 #define side_attr(_key, _value) \
458 .value = SIDE_PARAM(_value), \
461 #define side_attr_list(...) \
462 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
464 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
465 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
466 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
467 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
468 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
469 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
470 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
471 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
472 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
473 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
474 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
475 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
476 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
477 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
478 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
480 /* Static field definition */
482 #define _side_type_basic(_type, _attr) \
488 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
493 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
494 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_PARAM(_attr))
495 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_PARAM(_attr))
496 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_PARAM(_attr))
497 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_PARAM(_attr))
498 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_PARAM(_attr))
499 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_PARAM(_attr))
500 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_PARAM(_attr))
501 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_PARAM(_attr))
502 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_PARAM(_attr))
503 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
504 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
505 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
506 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_PARAM(_attr))
507 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
508 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
510 #define _side_field(_name, _type) \
512 .field_name = _name, \
513 .side_type = _type, \
516 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
517 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
518 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
519 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
520 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
521 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
522 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
523 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
524 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
525 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
526 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
527 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
528 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
529 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
530 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
531 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
533 #define side_type_enum(_mappings, _elem_type) \
535 .type = SIDE_TYPE_ENUM, \
538 .mappings = _mappings, \
539 .elem_type = _elem_type, \
543 #define side_field_enum(_name, _mappings, _elem_type) \
544 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
546 #define side_type_enum_bitmap(_mappings, _elem_type) \
548 .type = SIDE_TYPE_ENUM_BITMAP, \
550 .side_enum_bitmap = { \
551 .mappings = _mappings, \
552 .elem_type = _elem_type, \
556 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
557 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
559 #define side_type_struct(_struct) \
561 .type = SIDE_TYPE_STRUCT, \
563 .side_struct = _struct, \
566 #define side_field_struct(_name, _struct) \
567 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
569 #define _side_type_struct_define(_fields, _attr) \
571 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
572 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
577 #define side_define_struct(_identifier, _fields, _attr) \
578 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
580 #define side_struct_literal(_fields, _attr) \
581 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
582 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
584 #define side_type_array(_elem_type, _length, _attr) \
586 .type = SIDE_TYPE_ARRAY, \
589 .elem_type = _elem_type, \
592 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
596 #define side_field_array(_name, _elem_type, _length, _attr) \
597 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
599 #define side_type_vla(_elem_type, _attr) \
601 .type = SIDE_TYPE_VLA, \
604 .elem_type = _elem_type, \
606 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
610 #define side_field_vla(_name, _elem_type, _attr) \
611 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
613 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
615 .type = SIDE_TYPE_VLA_VISITOR, \
617 .side_vla_visitor = { \
618 .elem_type = SIDE_PARAM(_elem_type), \
619 .visitor = _visitor, \
621 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
625 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
626 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
628 #define side_elem(...) \
629 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
631 #define side_field_list(...) \
632 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
634 /* Static field arguments */
636 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
637 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
638 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
639 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
640 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
641 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
642 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
643 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
644 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
645 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
646 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
647 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
648 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
649 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
650 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
651 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
652 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
653 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
654 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
655 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
657 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
658 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
659 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
660 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
661 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
663 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
664 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
665 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
666 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
667 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
668 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
669 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
670 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
671 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
673 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
674 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
675 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
676 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
677 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
678 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
679 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
680 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
681 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
683 #define side_arg_dynamic(_dynamic_arg_type) \
685 .type = SIDE_TYPE_DYNAMIC, \
687 .dynamic = _dynamic_arg_type, \
691 /* Dynamic field arguments */
693 #define side_arg_dynamic_null(_attr) \
695 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
699 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
704 #define side_arg_dynamic_bool(_val, _attr) \
706 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
710 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
712 .side_bool = !!(_val), \
718 #define side_arg_dynamic_u8(_val, _attr) \
720 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
724 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
731 #define side_arg_dynamic_u16(_val, _attr) \
733 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
737 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
739 .side_u16 = (_val), \
744 #define side_arg_dynamic_u32(_val, _attr) \
746 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
750 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
752 .side_u32 = (_val), \
757 #define side_arg_dynamic_u64(_val, _attr) \
759 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
763 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
765 .side_u64 = (_val), \
771 #define side_arg_dynamic_s8(_val, _attr) \
773 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
777 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
784 #define side_arg_dynamic_s16(_val, _attr) \
786 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
790 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
792 .side_s16 = (_val), \
797 #define side_arg_dynamic_s32(_val, _attr) \
799 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
803 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
805 .side_s32 = (_val), \
810 #define side_arg_dynamic_s64(_val, _attr) \
812 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
816 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
818 .side_s64 = (_val), \
823 #define side_arg_dynamic_byte(_val, _attr) \
825 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
829 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
831 .side_byte = (_val), \
837 #define side_arg_dynamic_float_binary16(_val, _attr) \
839 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
843 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
845 .side_float_binary16 = (_val), \
850 #define side_arg_dynamic_float_binary32(_val, _attr) \
852 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
856 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
858 .side_float_binary32 = (_val), \
863 #define side_arg_dynamic_float_binary64(_val, _attr) \
865 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
869 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
871 .side_float_binary64 = (_val), \
876 #define side_arg_dynamic_float_binary128(_val, _attr) \
878 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
882 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
884 .side_float_binary128 = (_val), \
890 #define side_arg_dynamic_string(_val, _attr) \
892 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
896 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
904 #define side_arg_dynamic_vla(_vla) \
906 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
908 .side_dynamic_vla = (_vla), \
912 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
914 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
916 .side_dynamic_vla_visitor = { \
918 .visitor = _dynamic_vla_visitor, \
920 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
925 #define side_arg_dynamic_struct(_struct) \
927 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
929 .side_dynamic_struct = (_struct), \
933 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
935 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
937 .side_dynamic_struct_visitor = { \
939 .visitor = _dynamic_struct_visitor, \
941 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
946 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
947 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
948 const struct side_arg_dynamic_vec_vla _identifier = { \
949 .sav = _identifier##_vec, \
951 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
952 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
955 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
956 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
957 const struct side_arg_dynamic_event_struct _identifier = { \
958 .fields = _identifier##_fields, \
960 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
961 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
964 #define side_arg_define_vec(_identifier, _sav) \
965 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
966 const struct side_arg_vec_description _identifier = { \
967 .sav = _identifier##_vec, \
968 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
971 #define side_arg_dynamic_field(_name, _elem) \
973 .field_name = _name, \
977 #define side_arg_list(...) __VA_ARGS__
979 #define side_define_enum(_identifier, _mappings, _attr) \
980 const struct side_enum_mappings _identifier = { \
981 .mappings = _mappings, \
983 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
984 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
987 #define side_enum_mapping_list(...) \
988 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
990 #define side_enum_mapping_range(_label, _begin, _end) \
992 .range_begin = _begin, \
997 #define side_enum_mapping_value(_label, _value) \
999 .range_begin = _value, \
1000 .range_end = _value, \
1004 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1005 const struct side_enum_bitmap_mappings _identifier = { \
1006 .mappings = _mappings, \
1008 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1009 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1012 #define side_enum_bitmap_mapping_list(...) \
1013 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1015 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1017 .range_begin = _begin, \
1018 .range_end = _end, \
1022 #define side_enum_bitmap_mapping_value(_label, _value) \
1024 .range_begin = _value, \
1025 .range_end = _value, \
1029 #define side_event_cond(_identifier) \
1030 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1033 #define side_event_call(_identifier, _sav) \
1035 const struct side_arg_vec side_sav[] = { _sav }; \
1036 const struct side_arg_vec_description sav_desc = { \
1038 .len = SIDE_ARRAY_SIZE(side_sav), \
1040 side_call(&(_identifier), &sav_desc); \
1043 #define side_event(_identifier, _sav) \
1044 side_event_cond(_identifier) \
1045 side_event_call(_identifier, SIDE_PARAM(_sav))
1047 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1049 const struct side_arg_vec side_sav[] = { _sav }; \
1050 const struct side_arg_vec_description sav_desc = { \
1052 .len = SIDE_ARRAY_SIZE(side_sav), \
1054 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1055 const struct side_arg_dynamic_event_struct var_struct = { \
1056 .fields = side_fields, \
1058 .len = SIDE_ARRAY_SIZE(side_fields), \
1059 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1061 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1064 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1065 side_event_cond(_identifier) \
1066 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1068 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1069 _linkage uint32_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1070 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1073 .enabled = &(side_event_enable__##_identifier), \
1074 .loglevel = _loglevel, \
1075 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1076 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1078 .flags = (_flags), \
1079 .provider_name = _provider, \
1080 .event_name = _event, \
1081 .fields = _fields, \
1083 .callbacks = &side_empty_callback, \
1085 static const struct side_event_description *side_event_ptr__##_identifier \
1086 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1088 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1089 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1090 SIDE_PARAM(_attr), 0)
1092 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1093 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1094 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1096 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1097 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1098 SIDE_PARAM(_attr), 0)
1100 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1101 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1102 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1104 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1105 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1106 SIDE_PARAM(_attr), 0)
1108 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1109 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1110 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1112 #define side_declare_event(_identifier) \
1113 extern uint32_t side_event_enable_##_identifier; \
1114 extern struct side_event_description _identifier
1116 extern const struct side_callback side_empty_callback
;
1118 void side_call(const struct side_event_description
*desc
,
1119 const struct side_arg_vec_description
*sav_desc
);
1120 void side_call_variadic(const struct side_event_description
*desc
,
1121 const struct side_arg_vec_description
*sav_desc
,
1122 const struct side_arg_dynamic_event_struct
*var_struct
);
1124 int side_tracer_callback_register(struct side_event_description
*desc
,
1125 void (*call
)(const struct side_event_description
*desc
,
1126 const struct side_arg_vec_description
*sav_desc
,
1129 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1130 void (*call_variadic
)(const struct side_event_description
*desc
,
1131 const struct side_arg_vec_description
*sav_desc
,
1132 const struct side_arg_dynamic_event_struct
*var_struct
,
1135 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1136 void (*call
)(const struct side_event_description
*desc
,
1137 const struct side_arg_vec_description
*sav_desc
,
1140 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1141 void (*call_variadic
)(const struct side_event_description
*desc
,
1142 const struct side_arg_vec_description
*sav_desc
,
1143 const struct side_arg_dynamic_event_struct
*var_struct
,
1147 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1148 void side_events_unregister(struct side_events_register_handle
*handle
);
1150 enum side_tracer_notification
{
1151 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1152 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1155 /* Callback is invoked with side library internal lock held. */
1156 struct side_tracer_handle
*side_tracer_event_notification_register(
1157 void (*cb
)(enum side_tracer_notification notif
,
1158 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1160 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1162 void side_init(void);
1163 void side_exit(void);
1165 #endif /* _SIDE_TRACE_H */