1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2016-2020, Intel Corporation */
5 * ctl.h -- internal declaration of statistics and control related structures
24 PMDK_SLIST_ENTRY(ctl_index
) entry
;
27 PMDK_SLIST_HEAD(ctl_indexes
, ctl_index
);
29 enum ctl_query_source
{
30 CTL_UNKNOWN_QUERY_SOURCE
,
31 /* query executed directly from the program */
32 CTL_QUERY_PROGRAMMATIC
,
33 /* query executed from the config file */
34 CTL_QUERY_CONFIG_INPUT
,
47 typedef int (*node_callback
)(void *ctx
, enum ctl_query_source type
,
48 void *arg
, struct ctl_indexes
*indexes
);
59 typedef int (*ctl_arg_parser
)(const void *arg
, void *dest
, size_t dest_size
);
61 struct ctl_argument_parser
{
62 size_t dest_offset
; /* offset of the field inside of the argument */
63 size_t dest_size
; /* size of the field inside of the argument */
64 ctl_arg_parser parser
;
68 size_t dest_size
; /* sizeof the entire argument */
69 struct ctl_argument_parser parsers
[]; /* array of 'fields' in arg */
72 #define sizeof_member(t, m) sizeof(((t *)0)->m)
74 #define CTL_ARG_PARSER(t, p)\
77 #define CTL_ARG_PARSER_STRUCT(t, m, p)\
78 {offsetof(t, m), sizeof_member(t, m), p}
80 #define CTL_ARG_PARSER_END {0, 0, NULL}
83 * CTL Tree node structure, do not use directly. All the necessary functionality
84 * is provided by the included macros.
88 enum ctl_node_type type
;
90 node_callback cb
[MAX_CTL_QUERY_TYPE
];
91 const struct ctl_argument
*arg
;
93 const struct ctl_node
*children
;
96 struct ctl
*ctl_new(void);
97 void ctl_delete(struct ctl
*stats
);
99 int ctl_load_config_from_string(struct ctl
*ctl
, void *ctx
,
100 const char *cfg_string
);
101 int ctl_load_config_from_file(struct ctl
*ctl
, void *ctx
,
102 const char *cfg_file
);
104 /* Use through CTL_REGISTER_MODULE, never directly */
105 void ctl_register_module_node(struct ctl
*c
,
106 const char *name
, struct ctl_node
*n
);
108 int ctl_arg_boolean(const void *arg
, void *dest
, size_t dest_size
);
109 #define CTL_ARG_BOOLEAN {sizeof(int),\
110 {{0, sizeof(int), ctl_arg_boolean},\
111 CTL_ARG_PARSER_END}};
113 int ctl_arg_integer(const void *arg
, void *dest
, size_t dest_size
);
114 #define CTL_ARG_INT {sizeof(int),\
115 {{0, sizeof(int), ctl_arg_integer},\
116 CTL_ARG_PARSER_END}};
118 #define CTL_ARG_LONG_LONG {sizeof(long long),\
119 {{0, sizeof(long long), ctl_arg_integer},\
120 CTL_ARG_PARSER_END}};
122 int ctl_arg_string(const void *arg
, void *dest
, size_t dest_size
);
123 #define CTL_ARG_STRING(len) {len,\
124 {{0, len, ctl_arg_string},\
125 CTL_ARG_PARSER_END}};
127 #define CTL_STR(name) #name
129 #define CTL_NODE_END {NULL, CTL_NODE_UNKNOWN, {NULL, NULL, NULL}, NULL, NULL}
131 #define CTL_NODE(name, ...)\
132 ctl_node_##__VA_ARGS__##_##name
134 int ctl_query(struct ctl
*ctl
, void *ctx
, enum ctl_query_source source
,
135 const char *name
, enum ctl_query_type type
, void *arg
);
137 /* Declaration of a new child node */
138 #define CTL_CHILD(name, ...)\
139 {CTL_STR(name), CTL_NODE_NAMED, {NULL, NULL, NULL}, NULL,\
140 (struct ctl_node *)CTL_NODE(name, __VA_ARGS__)}
142 /* Declaration of a new indexed node */
143 #define CTL_INDEXED(name, ...)\
144 {CTL_STR(name), CTL_NODE_INDEXED, {NULL, NULL, NULL}, NULL,\
145 (struct ctl_node *)CTL_NODE(name, __VA_ARGS__)}
147 #define CTL_READ_HANDLER(name, ...)\
148 ctl_##__VA_ARGS__##_##name##_read
150 #define CTL_WRITE_HANDLER(name, ...)\
151 ctl_##__VA_ARGS__##_##name##_write
153 #define CTL_RUNNABLE_HANDLER(name, ...)\
154 ctl_##__VA_ARGS__##_##name##_runnable
156 #define CTL_ARG(name)\
160 * Declaration of a new read-only leaf. If used the corresponding read function
161 * must be declared by CTL_READ_HANDLER macro.
163 #define CTL_LEAF_RO(name, ...)\
164 {CTL_STR(name), CTL_NODE_LEAF, \
165 {CTL_READ_HANDLER(name, __VA_ARGS__), NULL, NULL}, NULL, NULL}
168 * Declaration of a new write-only leaf. If used the corresponding write
169 * function must be declared by CTL_WRITE_HANDLER macro.
171 #define CTL_LEAF_WO(name, ...)\
172 {CTL_STR(name), CTL_NODE_LEAF, \
173 {NULL, CTL_WRITE_HANDLER(name, __VA_ARGS__), NULL},\
174 &CTL_ARG(name), NULL}
177 * Declaration of a new runnable leaf. If used the corresponding run
178 * function must be declared by CTL_RUNNABLE_HANDLER macro.
180 #define CTL_LEAF_RUNNABLE(name, ...)\
181 {CTL_STR(name), CTL_NODE_LEAF, \
182 {NULL, NULL, CTL_RUNNABLE_HANDLER(name, __VA_ARGS__)},\
186 * Declaration of a new read-write leaf. If used both read and write function
187 * must be declared by CTL_READ_HANDLER and CTL_WRITE_HANDLER macros.
189 #define CTL_LEAF_RW(name)\
190 {CTL_STR(name), CTL_NODE_LEAF,\
191 {CTL_READ_HANDLER(name), CTL_WRITE_HANDLER(name), NULL},\
192 &CTL_ARG(name), NULL}
194 #define CTL_REGISTER_MODULE(_ctl, name)\
195 ctl_register_module_node((_ctl), CTL_STR(name),\
196 (struct ctl_node *)CTL_NODE(name))