Skip to content

Commit d514239

Browse files
KFilipeklplewa
authored andcommitted
add post-initialize function to pools and providers
Split between initialize and post-initialize function is necessary for properly handling CTL defaults.
1 parent 527d19e commit d514239

16 files changed

+371
-85
lines changed

.github/workflows/reusable_compatibility.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,16 @@ jobs:
102102
UMF_LOG: level:warning;flush:debug;output:stderr;pid:no
103103
LD_LIBRARY_PATH: ${{github.workspace}}/latest_version/build/lib/
104104
run: |
105-
ctest --verbose -E "test_memoryProvider"
105+
ctest --verbose -E "test_memoryProvider|test_disjoint_pool"
106+
107+
- name: Run disabled tests individually with latest UMF libs (warnings enabled)
108+
working-directory: ${{github.workspace}}/tag_version/build
109+
env:
110+
UMF_LOG: level:warning;flush:debug;output:stderr;pid:no
111+
LD_LIBRARY_PATH: ${{github.workspace}}/latest_version/build/lib/
112+
run: |
106113
test/test_memoryProvider --gtest_filter="-*Trace"
114+
test/test_disjoint_pool --gtest_filter="-test.internals"
107115
108116
# Browse all folders in the examples directory, build them using the
109117
# latest UMF version, and run them, excluding those in the exclude list.
@@ -228,10 +236,12 @@ jobs:
228236
env:
229237
UMF_LOG: level:warning;flush:debug;output:stderr;pid:no
230238
run: |
239+
$env:UMF_LOG="level:warning;flush:debug;output:stderr;pid:no"
231240
cp ${{github.workspace}}/latest_version/build/bin/Debug/umf.dll ${{github.workspace}}/tag_version/build/bin/Debug/umf.dll
232-
ctest -C Debug --verbose -E "test_memoryProvider"
241+
ctest -C Debug --verbose -E "test_memoryProvider|test_disjoint_pool"
233242
$env:Path = "${{github.workspace}}/tag_version/build/bin/Debug;${{env.VCPKG_BIN_PATH}};$env:Path"
234243
test/Debug/test_memoryProvider.exe --gtest_filter="-*Trace"
244+
test/Debug/test_disjoint_pool.exe --gtest_filter="-test.internals"
235245
236246
# Browse all folders in the examples directory, build them using the
237247
# latest UMF version, and run them, excluding those in the exclude list.
@@ -373,8 +383,16 @@ jobs:
373383
UMF_LOG: level:warning;flush:debug;output:stderr;pid:no
374384
LD_LIBRARY_PATH: ${{github.workspace}}/latest_version/build/lib/
375385
run: |
376-
ctest --verbose -E "test_memoryProvider"
386+
ctest --verbose -E "test_memoryProvider|test_disjoint_pool"
387+
388+
- name: Run disabled tests individually with latest UMF libs (warnings enabled)
389+
working-directory: ${{github.workspace}}/tag_version/build
390+
env:
391+
UMF_LOG: level:warning;flush:debug;output:stderr;pid:no
392+
LD_LIBRARY_PATH: ${{github.workspace}}/latest_version/build/lib/
393+
run: |
377394
test/test_memoryProvider --gtest_filter="-*Trace"
395+
test/test_disjoint_pool --gtest_filter="-test.internals"
378396
379397
# Browse all folders in the examples directory, build them using the
380398
# latest UMF version, and run them, excluding those in the exclude list.

include/umf/memory_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef enum umf_pool_create_flag_t {
4343
/// @brief Type for combinations of pool creation flags
4444
typedef uint32_t umf_pool_create_flags_t;
4545

46-
///
46+
/// @anchor umfPoolCreate
4747
/// @brief Creates new memory pool.
4848
/// @param ops instance of umf_memory_pool_ops_t
4949
/// @param provider memory provider that will be used for coarse-grain allocations.

include/umf/memory_pool_ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ typedef struct umf_memory_pool_ops_t {
191191
/// failure.
192192
///
193193
umf_result_t (*ext_trim_memory)(void *pool, size_t minBytesToKeep);
194+
194195
} umf_memory_pool_ops_t;
195196

196197
#ifdef __cplusplus

include/umf/memory_provider_ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ typedef struct umf_memory_provider_ops_t {
307307
void *provider, const void *ptr,
308308
umf_memory_property_id_t memory_property_id, void *property_value);
309309

310+
///
310311
/// @brief Retrieve size of the provider-specific properties of the memory
311312
/// allocation.
312313
/// \details

src/memory_pool.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <assert.h>
1111
#include <stdint.h>
1212
#include <string.h>
13+
#include <stdarg.h>
1314

1415
#include <umf/base.h>
1516
#include <umf/memory_pool.h>
@@ -372,6 +373,20 @@ static umf_result_t umfDefaultTrimMemory(void *provider,
372373
return UMF_RESULT_ERROR_NOT_SUPPORTED;
373374
}
374375

376+
static umf_result_t umfPoolPostInitialize(const umf_memory_pool_ops_t *ops,
377+
void *pool_priv, ...) {
378+
va_list args;
379+
va_start(args, pool_priv);
380+
umf_result_t ret = ops->ext_ctl(pool_priv, CTL_QUERY_PROGRAMMATIC,
381+
"post_initialize", NULL, 0,
382+
CTL_QUERY_RUNNABLE, args);
383+
va_end(args);
384+
if (ret == UMF_RESULT_ERROR_INVALID_ARGUMENT) {
385+
ret = UMF_RESULT_ERROR_NOT_SUPPORTED;
386+
}
387+
return ret;
388+
}
389+
375390
// logical sum (OR) of all umf_pool_create_flags_t flags
376391
static const umf_pool_create_flags_t UMF_POOL_CREATE_FLAG_ALL =
377392
UMF_POOL_CREATE_FLAG_OWN_PROVIDER | UMF_POOL_CREATE_FLAG_DISABLE_TRACKING;
@@ -393,7 +408,6 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
393408
}
394409

395410
umf_result_t ret = UMF_RESULT_SUCCESS;
396-
397411
umf_memory_pool_ops_t compatible_ops;
398412
if (ops->version != UMF_POOL_OPS_VERSION_CURRENT) {
399413
LOG_WARN("Memory Pool ops version \"%d\" is different than the current "
@@ -402,8 +416,8 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
402416

403417
// Create a new ops compatible structure with the current version
404418
memset(&compatible_ops, 0, sizeof(compatible_ops));
405-
if (UMF_MINOR_VERSION(ops->version) == 0) {
406-
LOG_INFO("Detected 1.0 version of Memory Pool ops, "
419+
if (ops->version < UMF_MAKE_VERSION(1, 1)) {
420+
LOG_INFO("Detected 1.0 version or below of Memory Pool ops, "
407421
"upgrading to current version");
408422
memcpy(&compatible_ops, ops,
409423
offsetof(umf_memory_pool_ops_t, ext_trim_memory));
@@ -451,7 +465,7 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
451465
goto err_lock_init;
452466
}
453467

454-
ret = ops->initialize(pool->provider, params, &pool->pool_priv);
468+
ret = pool->ops.initialize(pool->provider, params, &pool->pool_priv);
455469
if (ret != UMF_RESULT_SUCCESS) {
456470
goto err_pool_init;
457471
}
@@ -467,6 +481,12 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
467481

468482
ctl_default_apply(pool_default_list, pname, ops->ext_ctl, pool->pool_priv);
469483

484+
ret = umfPoolPostInitialize(ops, pool->pool_priv);
485+
if (ret != UMF_RESULT_SUCCESS && ret != UMF_RESULT_ERROR_NOT_SUPPORTED) {
486+
LOG_ERR("Failed to post-initialize pool");
487+
goto err_pool_init;
488+
}
489+
470490
*hPool = pool;
471491
pools_by_name_add(pool);
472492

src/memory_provider.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdio.h>
1313
#include <stdlib.h>
1414
#include <string.h>
15+
#include <stdarg.h>
1516

1617
#include <umf/base.h>
1718
#include <umf/memory_provider.h>
@@ -205,6 +206,7 @@ void assignOpsExtDefaults(umf_memory_provider_ops_t *ops) {
205206
ops->ext_get_allocation_properties_size =
206207
umfDefaultGetAllocationPropertiesSize;
207208
}
209+
208210
}
209211

210212
void assignOpsIpcDefaults(umf_memory_provider_ops_t *ops) {
@@ -229,6 +231,20 @@ void assignOpsIpcDefaults(umf_memory_provider_ops_t *ops) {
229231
}
230232
}
231233

234+
static umf_result_t umfProviderPostInitialize(umf_memory_provider_ops_t *ops,
235+
void *provider_priv, ...) {
236+
va_list args;
237+
va_start(args, provider_priv);
238+
umf_result_t ret = ops->ext_ctl(provider_priv, CTL_QUERY_PROGRAMMATIC,
239+
"post_initialize", NULL, 0,
240+
CTL_QUERY_RUNNABLE, args);
241+
va_end(args);
242+
if (ret == UMF_RESULT_ERROR_INVALID_ARGUMENT) {
243+
ret = UMF_RESULT_ERROR_NOT_SUPPORTED;
244+
}
245+
return ret;
246+
}
247+
232248
#define CHECK_OP(ops, fn) \
233249
if (!(ops)->fn) { \
234250
LOG_ERR("missing function pointer: %s\n", #fn); \
@@ -338,6 +354,12 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
338354
ctl_default_apply(provider_default_list, pname, provider->ops.ext_ctl,
339355
provider->provider_priv);
340356
}
357+
ret = umfProviderPostInitialize(&provider->ops, provider_priv);
358+
if (ret != UMF_RESULT_SUCCESS && ret != UMF_RESULT_ERROR_NOT_SUPPORTED) {
359+
LOG_ERR("Failed to post-initialize provider");
360+
umf_ba_global_free(provider);
361+
return ret;
362+
}
341363

342364
*hProvider = provider;
343365

src/pool/pool_disjoint.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ static char *DEFAULT_NAME = "disjoint";
3333
struct ctl disjoint_ctl_root;
3434
static UTIL_ONCE_FLAG ctl_initialized = UTIL_ONCE_FLAG_INIT;
3535

36+
umf_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) {
40+
(void)source;
41+
(void)arg;
42+
(void)size;
43+
(void)indexes;
44+
return disjoint_pool_post_initialize(ctx);
45+
}
46+
3647
// Disable name ctl for 1.0 release
3748
#if 0
3849
static umf_result_t CTL_READ_HANDLER(name)(void *ctx,
@@ -326,6 +337,13 @@ static void initialize_disjoint_ctl(void) {
326337
// TODO: this is hack. Need some way to register module as node with argument
327338
disjoint_ctl_root.root[disjoint_ctl_root.first_free - 1].arg =
328339
&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+
};
329347
}
330348

331349
umf_result_t disjoint_pool_ctl(void *hPool,
@@ -930,6 +948,14 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider,
930948
disjoint_pool->provider = provider;
931949
disjoint_pool->params = *dp_params;
932950

951+
*ppPool = (void *)disjoint_pool;
952+
953+
return UMF_RESULT_SUCCESS;
954+
}
955+
956+
umf_result_t disjoint_pool_post_initialize(void *ppPool) {
957+
disjoint_pool_t *disjoint_pool = (disjoint_pool_t *)ppPool;
958+
933959
disjoint_pool->known_slabs = critnib_new(free_slab, NULL);
934960
if (disjoint_pool->known_slabs == NULL) {
935961
goto err_free_disjoint_pool;
@@ -988,13 +1014,11 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider,
9881014
}
9891015

9901016
umf_result_t ret = umfMemoryProviderGetMinPageSize(
991-
provider, NULL, &disjoint_pool->provider_min_page_size);
1017+
disjoint_pool->provider, NULL, &disjoint_pool->provider_min_page_size);
9921018
if (ret != UMF_RESULT_SUCCESS) {
9931019
disjoint_pool->provider_min_page_size = 0;
9941020
}
9951021

996-
*ppPool = (void *)disjoint_pool;
997-
9981022
return UMF_RESULT_SUCCESS;
9991023

10001024
err_free_buckets:
@@ -1013,7 +1037,6 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider,
10131037

10141038
err_free_disjoint_pool:
10151039
umf_ba_global_free(disjoint_pool);
1016-
10171040
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
10181041
}
10191042

0 commit comments

Comments
 (0)