77
88#include <assert.h>
99#include <ctype.h>
10- #include <errno.h>
1110#include <inttypes.h>
1211#include <stdlib.h>
1312#include <string.h>
2928
3029static char * DEFAULT_NAME = "disjoint" ;
3130
31+ enum {
32+ DP_OVERRIDE_SLAB_MIN_SIZE = 1 << 0 ,
33+ DP_OVERRIDE_MAX_POOLABLE_SIZE = 1 << 1 ,
34+ DP_OVERRIDE_CAPACITY = 1 << 2 ,
35+ DP_OVERRIDE_MIN_BUCKET_SIZE = 1 << 3 ,
36+ DP_OVERRIDE_POOL_TRACE = 1 << 4 ,
37+ };
38+
3239/* Disjoint pool CTL implementation */
3340struct ctl disjoint_ctl_root ;
3441static UTIL_ONCE_FLAG ctl_initialized = UTIL_ONCE_FLAG_INIT ;
3542
3643umf_result_t disjoint_pool_post_initialize (void * ppPool );
37- static umf_result_t CTL_RUNNABLE_HANDLER (post_initialize )(
38- void * ctx , umf_ctl_query_source_t source , void * arg , size_t size ,
39- umf_ctl_index_utlist_t * indexes ) {
44+ static umf_result_t
45+ CTL_RUNNABLE_HANDLER (post_initialize )(void * ctx , umf_ctl_query_source_t source ,
46+ void * arg , size_t size ,
47+ umf_ctl_index_utlist_t * indexes ) {
4048 (void )source ;
4149 (void )arg ;
4250 (void )size ;
@@ -86,6 +94,204 @@ static umf_result_t CTL_WRITE_HANDLER(name)(void *ctx,
8694 return UMF_RESULT_SUCCESS ;
8795}
8896#endif
97+
98+ static const struct ctl_argument
99+ CTL_ARG (slab_min_size ) = CTL_ARG_UNSIGNED_LONG_LONG ;
100+ static const struct ctl_argument
101+ CTL_ARG (max_poolable_size ) = CTL_ARG_UNSIGNED_LONG_LONG ;
102+ static const struct ctl_argument CTL_ARG (capacity ) = CTL_ARG_UNSIGNED_LONG_LONG ;
103+ static const struct ctl_argument
104+ CTL_ARG (min_bucket_size ) = CTL_ARG_UNSIGNED_LONG_LONG ;
105+ static const struct ctl_argument CTL_ARG (pool_trace ) = CTL_ARG_INT ;
106+
107+ static umf_result_t
108+ CTL_READ_HANDLER (slab_min_size )(void * ctx , umf_ctl_query_source_t source ,
109+ void * arg , size_t size ,
110+ umf_ctl_index_utlist_t * indexes ) {
111+ (void )source , (void )indexes ;
112+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
113+ if (arg == NULL || size != sizeof (size_t )) {
114+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
115+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
116+ }
117+ * (size_t * )arg = pool -> params .slab_min_size ;
118+ return UMF_RESULT_SUCCESS ;
119+ }
120+
121+ static umf_result_t
122+ CTL_WRITE_HANDLER (slab_min_size )(void * ctx , umf_ctl_query_source_t source ,
123+ void * arg , size_t size ,
124+ umf_ctl_index_utlist_t * indexes ) {
125+ (void )source , (void )indexes ;
126+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
127+ if (pool -> post_initialized ) {
128+ LOG_ERR ("writing parameter after post_initialize is not allowed" );
129+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
130+ }
131+ if (arg == NULL || size != sizeof (size_t )) {
132+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
133+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
134+ }
135+ size_t value = * (size_t * )arg ;
136+ umf_result_t ret =
137+ umfDisjointPoolParamsSetSlabMinSize (& pool -> params , value );
138+ if (ret == UMF_RESULT_SUCCESS ) {
139+ pool -> params_overridden |= DP_OVERRIDE_SLAB_MIN_SIZE ;
140+ }
141+ return ret ;
142+ }
143+
144+ static umf_result_t
145+ CTL_READ_HANDLER (max_poolable_size )(void * ctx , umf_ctl_query_source_t source ,
146+ void * arg , size_t size ,
147+ umf_ctl_index_utlist_t * indexes ) {
148+ (void )source , (void )indexes ;
149+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
150+ if (arg == NULL || size != sizeof (size_t )) {
151+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
152+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
153+ }
154+ * (size_t * )arg = pool -> params .max_poolable_size ;
155+ return UMF_RESULT_SUCCESS ;
156+ }
157+
158+ static umf_result_t
159+ CTL_WRITE_HANDLER (max_poolable_size )(void * ctx , umf_ctl_query_source_t source ,
160+ void * arg , size_t size ,
161+ umf_ctl_index_utlist_t * indexes ) {
162+ (void )source , (void )indexes ;
163+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
164+ if (pool -> post_initialized ) {
165+ LOG_ERR ("writing parameter after post_initialize is not allowed" );
166+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
167+ }
168+ if (arg == NULL || size != sizeof (size_t )) {
169+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
170+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
171+ }
172+ size_t value = * (size_t * )arg ;
173+ umf_result_t ret =
174+ umfDisjointPoolParamsSetMaxPoolableSize (& pool -> params , value );
175+ if (ret == UMF_RESULT_SUCCESS ) {
176+ pool -> params_overridden |= DP_OVERRIDE_MAX_POOLABLE_SIZE ;
177+ }
178+ return ret ;
179+ }
180+
181+ static umf_result_t
182+ CTL_READ_HANDLER (capacity )(void * ctx , umf_ctl_query_source_t source , void * arg ,
183+ size_t size , umf_ctl_index_utlist_t * indexes ) {
184+ (void )source , (void )indexes ;
185+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
186+ if (arg == NULL || size != sizeof (size_t )) {
187+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
188+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
189+ }
190+ * (size_t * )arg = pool -> params .capacity ;
191+ return UMF_RESULT_SUCCESS ;
192+ }
193+
194+ static umf_result_t
195+ CTL_WRITE_HANDLER (capacity )(void * ctx , umf_ctl_query_source_t source , void * arg ,
196+ size_t size , umf_ctl_index_utlist_t * indexes ) {
197+ (void )source , (void )indexes ;
198+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
199+ if (pool -> post_initialized ) {
200+ LOG_ERR ("writing parameter after post_initialize is not allowed" );
201+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
202+ }
203+ if (arg == NULL || size != sizeof (size_t )) {
204+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
205+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
206+ }
207+ size_t value = * (size_t * )arg ;
208+ umf_result_t ret =
209+ umfDisjointPoolParamsSetCapacity (& pool -> params , value );
210+ if (ret == UMF_RESULT_SUCCESS ) {
211+ pool -> params_overridden |= DP_OVERRIDE_CAPACITY ;
212+ }
213+ return ret ;
214+ }
215+
216+ static umf_result_t
217+ CTL_READ_HANDLER (min_bucket_size )(void * ctx , umf_ctl_query_source_t source ,
218+ void * arg , size_t size ,
219+ umf_ctl_index_utlist_t * indexes ) {
220+ (void )source , (void )indexes ;
221+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
222+ if (arg == NULL || size != sizeof (size_t )) {
223+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
224+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
225+ }
226+ * (size_t * )arg = pool -> params .min_bucket_size ;
227+ return UMF_RESULT_SUCCESS ;
228+ }
229+
230+ static umf_result_t
231+ CTL_WRITE_HANDLER (min_bucket_size )(void * ctx , umf_ctl_query_source_t source ,
232+ void * arg , size_t size ,
233+ umf_ctl_index_utlist_t * indexes ) {
234+ (void )source , (void )indexes ;
235+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
236+ if (pool -> post_initialized ) {
237+ LOG_ERR ("writing parameter after post_initialize is not allowed" );
238+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
239+ }
240+ if (arg == NULL || size != sizeof (size_t )) {
241+ LOG_ERR ("arg is NULL or size is not sizeof(size_t)" );
242+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
243+ }
244+ size_t value = * (size_t * )arg ;
245+ umf_result_t ret =
246+ umfDisjointPoolParamsSetMinBucketSize (& pool -> params , value );
247+ if (ret == UMF_RESULT_SUCCESS ) {
248+ pool -> params_overridden |= DP_OVERRIDE_MIN_BUCKET_SIZE ;
249+ }
250+ return ret ;
251+ }
252+
253+ static umf_result_t
254+ CTL_READ_HANDLER (pool_trace )(void * ctx , umf_ctl_query_source_t source ,
255+ void * arg , size_t size ,
256+ umf_ctl_index_utlist_t * indexes ) {
257+ (void )source , (void )indexes ;
258+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
259+ if (arg == NULL || size != sizeof (int )) {
260+ LOG_ERR ("arg is NULL or size is not sizeof(int)" );
261+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
262+ }
263+ * (int * )arg = pool -> params .pool_trace ;
264+ return UMF_RESULT_SUCCESS ;
265+ }
266+
267+ static umf_result_t
268+ CTL_WRITE_HANDLER (pool_trace )(void * ctx , umf_ctl_query_source_t source ,
269+ void * arg , size_t size ,
270+ umf_ctl_index_utlist_t * indexes ) {
271+ (void )source , (void )indexes ;
272+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
273+ if (pool -> post_initialized ) {
274+ LOG_ERR ("writing parameter after post_initialize is not allowed" );
275+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
276+ }
277+ if (arg == NULL || size != sizeof (int )) {
278+ LOG_ERR ("arg is NULL or size is not sizeof(int)" );
279+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
280+ }
281+ int value = * (int * )arg ;
282+ umf_result_t ret =
283+ umfDisjointPoolParamsSetTrace (& pool -> params , value );
284+ if (ret == UMF_RESULT_SUCCESS ) {
285+ pool -> params_overridden |= DP_OVERRIDE_POOL_TRACE ;
286+ }
287+ return ret ;
288+ }
289+
290+ static const umf_ctl_node_t CTL_NODE (params )[] = {
291+ CTL_LEAF_RW (slab_min_size ), CTL_LEAF_RW (max_poolable_size ),
292+ CTL_LEAF_RW (capacity ), CTL_LEAF_RW (min_bucket_size ),
293+ CTL_LEAF_RW (pool_trace ), CTL_NODE_END ,
294+ };
89295static umf_result_t
90296CTL_READ_HANDLER (used_memory )(void * ctx , umf_ctl_query_source_t source ,
91297 void * arg , size_t size ,
@@ -332,28 +538,26 @@ static const struct ctl_argument CTL_ARG(buckets) = {
332538 CTL_ARG_PARSER_END }};
333539
334540static void initialize_disjoint_ctl (void ) {
541+ CTL_REGISTER_MODULE (& disjoint_ctl_root , params );
335542 CTL_REGISTER_MODULE (& disjoint_ctl_root , stats );
336543 CTL_REGISTER_MODULE (& disjoint_ctl_root , buckets );
337544 // TODO: this is hack. Need some way to register module as node with argument
338545 disjoint_ctl_root .root [disjoint_ctl_root .first_free - 1 ].arg =
339546 & CTL_ARG (buckets );
340- disjoint_ctl_root .root [disjoint_ctl_root .first_free ++ ] =
341- (umf_ctl_node_t ){
342- .name = "post_initialize" ,
343- .type = CTL_NODE_LEAF ,
344- .runnable_cb =
345- CTL_RUNNABLE_HANDLER (post_initialize ),
346- };
547+ disjoint_ctl_root .root [disjoint_ctl_root .first_free ++ ] = (umf_ctl_node_t ){
548+ .name = "post_initialize" ,
549+ .type = CTL_NODE_LEAF ,
550+ .runnable_cb = CTL_RUNNABLE_HANDLER (post_initialize ),
551+ };
347552}
348553
349554umf_result_t disjoint_pool_ctl (void * hPool ,
350555 umf_ctl_query_source_t operationType ,
351556 const char * name , void * arg , size_t size ,
352557 umf_ctl_query_type_t queryType , va_list args ) {
353- (void )operationType ;
354558 utils_init_once (& ctl_initialized , initialize_disjoint_ctl );
355559
356- return ctl_query (& disjoint_ctl_root , hPool , CTL_QUERY_PROGRAMMATIC , name ,
560+ return ctl_query (& disjoint_ctl_root , hPool , operationType , name ,
357561 queryType , arg , size , args );
358562}
359563
@@ -947,6 +1151,8 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider,
9471151
9481152 disjoint_pool -> provider = provider ;
9491153 disjoint_pool -> params = * dp_params ;
1154+ disjoint_pool -> post_initialized = false;
1155+ disjoint_pool -> params_overridden = 0 ;
9501156
9511157 * ppPool = (void * )disjoint_pool ;
9521158
@@ -956,6 +1162,31 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider,
9561162umf_result_t disjoint_pool_post_initialize (void * ppPool ) {
9571163 disjoint_pool_t * disjoint_pool = (disjoint_pool_t * )ppPool ;
9581164
1165+ disjoint_pool -> post_initialized = true;
1166+
1167+ if (disjoint_pool -> params_overridden ) {
1168+ if (disjoint_pool -> params_overridden & DP_OVERRIDE_SLAB_MIN_SIZE ) {
1169+ LOG_INFO ("CTL override: slab_min_size=%zu" ,
1170+ disjoint_pool -> params .slab_min_size );
1171+ }
1172+ if (disjoint_pool -> params_overridden & DP_OVERRIDE_MAX_POOLABLE_SIZE ) {
1173+ LOG_INFO ("CTL override: max_poolable_size=%zu" ,
1174+ disjoint_pool -> params .max_poolable_size );
1175+ }
1176+ if (disjoint_pool -> params_overridden & DP_OVERRIDE_CAPACITY ) {
1177+ LOG_INFO ("CTL override: capacity=%zu" ,
1178+ disjoint_pool -> params .capacity );
1179+ }
1180+ if (disjoint_pool -> params_overridden & DP_OVERRIDE_MIN_BUCKET_SIZE ) {
1181+ LOG_INFO ("CTL override: min_bucket_size=%zu" ,
1182+ disjoint_pool -> params .min_bucket_size );
1183+ }
1184+ if (disjoint_pool -> params_overridden & DP_OVERRIDE_POOL_TRACE ) {
1185+ LOG_INFO ("CTL override: pool_trace=%d" ,
1186+ disjoint_pool -> params .pool_trace );
1187+ }
1188+ }
1189+
9591190 disjoint_pool -> known_slabs = critnib_new (free_slab , NULL );
9601191 if (disjoint_pool -> known_slabs == NULL ) {
9611192 goto err_free_disjoint_pool ;
0 commit comments