From d90cb96f3280bbcb7f5c20ac6c49889b96a0e71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Plewa?= Date: Mon, 30 Jun 2025 17:14:13 +0200 Subject: [PATCH] make get_name not experimental --- include/umf/base.h | 2 +- include/umf/memory_pool_ops.h | 29 +++++++++++++++-------------- src/memory_pool.c | 20 +++++--------------- src/pool/pool_disjoint.c | 2 +- src/pool/pool_jemalloc.c | 7 +++++++ src/pool/pool_proxy.c | 9 ++++++++- src/pool/pool_scalable.c | 2 +- test/common/pool_null.c | 7 +++++++ test/common/pool_trace.c | 7 +++++++ test/utils/cpp_helpers.hpp | 6 ++++++ 10 files changed, 58 insertions(+), 33 deletions(-) diff --git a/include/umf/base.h b/include/umf/base.h index ab306870c0..ae0d43e15d 100644 --- a/include/umf/base.h +++ b/include/umf/base.h @@ -28,7 +28,7 @@ extern "C" { #define UMF_MINOR_VERSION(_ver) (_ver & 0x0000ffff) /// @brief Current version of the UMF headers -#define UMF_VERSION_CURRENT UMF_MAKE_VERSION(0, 11) +#define UMF_VERSION_CURRENT UMF_MAKE_VERSION(0, 12) /// @brief Operation results typedef enum umf_result_t { diff --git a/include/umf/memory_pool_ops.h b/include/umf/memory_pool_ops.h index 42fd168030..ebf7e57727 100644 --- a/include/umf/memory_pool_ops.h +++ b/include/umf/memory_pool_ops.h @@ -130,8 +130,21 @@ typedef struct umf_memory_pool_ops_t { umf_result_t (*get_last_allocation_error)(void *pool); /// - /// Following functions, with ext prefix, are optional and memory pool implementation - /// can keep them NULL. + /// @brief Retrieves the name of the memory pool + /// @param pool valid pointer to the memory pool or NULL value + /// @param name [out] pointer to a constant character string that will be set to the pool's name + /// \details + /// * Implementations *must* return a literal null-terminated string. + /// + /// * Implementations *must* return default pool name when NULL is provided, + /// otherwise the pool's name is returned. + /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. + /// + umf_result_t (*get_name)(void *pool, const char **name); + + /// + /// The following function is optional and memory pool implementation + /// can keep it NULL. /// /// @@ -152,18 +165,6 @@ typedef struct umf_memory_pool_ops_t { void *arg, size_t size, umf_ctl_query_type_t queryType); - /// - /// @brief Retrieves the name of the memory pool - /// @param pool valid pointer to the memory pool or NULL value - /// @param name [out] pointer to a constant character string that will be set to the pool's name - /// \details - /// * Implementations *must* return a literal null-terminated string. - /// - /// * Implementations *must* return default pool name when NULL is provided, - /// otherwise the pool's name is returned. - /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. - /// - umf_result_t (*ext_get_name)(void *pool, const char **name); } umf_memory_pool_ops_t; #ifdef __cplusplus diff --git a/src/memory_pool.c b/src/memory_pool.c index 9791cef936..0aa0ef5abe 100644 --- a/src/memory_pool.c +++ b/src/memory_pool.c @@ -210,16 +210,10 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops, // Set default property "name" to pool if exists for (int i = 0; i < UMF_DEFAULT_SIZE; i++) { const char *pname = NULL; - if (ops->ext_get_name) { - ret = ops->ext_get_name(NULL, &pname); - if (ret != UMF_RESULT_SUCCESS) { - LOG_ERR("Failed to get pool name"); - goto err_pool_init; - } - } else { - LOG_INFO("Pool name getter is not implemented, CTL defaults " - "settings are not supported for this pool"); - break; + ret = ops->get_name(NULL, &pname); + if (ret != UMF_RESULT_SUCCESS) { + LOG_ERR("Failed to get pool name"); + goto err_pool_init; } if (CTL_DEFAULT_ENTRIES[i][0] != '\0' && pname && strstr(CTL_DEFAULT_ENTRIES[i], pname)) { @@ -314,11 +308,7 @@ umf_result_t umfPoolGetMemoryProvider(umf_memory_pool_handle_t hPool, umf_result_t umfPoolGetName(umf_memory_pool_handle_t pool, const char **name) { UMF_CHECK((pool != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT); UMF_CHECK((name != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT); - if (pool->ops.ext_get_name == NULL) { - *name = NULL; - return UMF_RESULT_ERROR_NOT_SUPPORTED; - } - return pool->ops.ext_get_name(pool->pool_priv, name); + return pool->ops.get_name(pool->pool_priv, name); } umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops, diff --git a/src/pool/pool_disjoint.c b/src/pool/pool_disjoint.c index 702a30f91a..6db89f330f 100644 --- a/src/pool/pool_disjoint.c +++ b/src/pool/pool_disjoint.c @@ -1056,7 +1056,7 @@ static umf_memory_pool_ops_t UMF_DISJOINT_POOL_OPS = { .malloc_usable_size = disjoint_pool_malloc_usable_size, .free = disjoint_pool_free, .get_last_allocation_error = disjoint_pool_get_last_allocation_error, - .ext_get_name = disjoint_pool_get_name, + .get_name = disjoint_pool_get_name, .ext_ctl = disjoint_pool_ctl, }; diff --git a/src/pool/pool_jemalloc.c b/src/pool/pool_jemalloc.c index 60a6e6e970..abbf50d2b5 100644 --- a/src/pool/pool_jemalloc.c +++ b/src/pool/pool_jemalloc.c @@ -557,6 +557,12 @@ static umf_result_t op_get_last_allocation_error(void *pool) { return TLS_last_allocation_error; } +static umf_result_t op_get_name(void *pool, const char **name) { + (void)pool; + *name = "jemalloc"; + return UMF_RESULT_SUCCESS; +} + static umf_memory_pool_ops_t UMF_JEMALLOC_POOL_OPS = { .version = UMF_POOL_OPS_VERSION_CURRENT, .initialize = op_initialize, @@ -568,6 +574,7 @@ static umf_memory_pool_ops_t UMF_JEMALLOC_POOL_OPS = { .malloc_usable_size = op_malloc_usable_size, .free = op_free, .get_last_allocation_error = op_get_last_allocation_error, + .get_name = op_get_name, }; const umf_memory_pool_ops_t *umfJemallocPoolOps(void) { diff --git a/src/pool/pool_proxy.c b/src/pool/pool_proxy.c index d8376155e8..c6bf74124f 100644 --- a/src/pool/pool_proxy.c +++ b/src/pool/pool_proxy.c @@ -130,6 +130,12 @@ static umf_result_t proxy_get_last_allocation_error(void *pool) { return TLS_last_allocation_error; } +static umf_result_t proxy_get_name(void *pool, const char **name) { + (void)pool; + *name = "proxy"; + return UMF_RESULT_SUCCESS; +} + static umf_memory_pool_ops_t UMF_PROXY_POOL_OPS = { .version = UMF_POOL_OPS_VERSION_CURRENT, .initialize = proxy_pool_initialize, @@ -140,7 +146,8 @@ static umf_memory_pool_ops_t UMF_PROXY_POOL_OPS = { .aligned_malloc = proxy_aligned_malloc, .malloc_usable_size = proxy_malloc_usable_size, .free = proxy_free, - .get_last_allocation_error = proxy_get_last_allocation_error}; + .get_last_allocation_error = proxy_get_last_allocation_error, + .get_name = proxy_get_name}; const umf_memory_pool_ops_t *umfProxyPoolOps(void) { return &UMF_PROXY_POOL_OPS; diff --git a/src/pool/pool_scalable.c b/src/pool/pool_scalable.c index 8c17e76ae9..f44c5cb1f5 100644 --- a/src/pool/pool_scalable.c +++ b/src/pool/pool_scalable.c @@ -449,7 +449,7 @@ static umf_memory_pool_ops_t UMF_SCALABLE_POOL_OPS = { .free = tbb_free, .get_last_allocation_error = tbb_get_last_allocation_error, .ext_ctl = pool_ctl, - .ext_get_name = scalable_get_name, + .get_name = scalable_get_name, }; const umf_memory_pool_ops_t *umfScalablePoolOps(void) { diff --git a/test/common/pool_null.c b/test/common/pool_null.c index 4073fe6598..ccabfee562 100644 --- a/test/common/pool_null.c +++ b/test/common/pool_null.c @@ -70,6 +70,12 @@ static umf_result_t nullGetLastStatus(void *pool) { return UMF_RESULT_SUCCESS; } +static umf_result_t nullGetName(void *pool, const char **name) { + (void)pool; + *name = "null"; + return UMF_RESULT_SUCCESS; +} + umf_memory_pool_ops_t UMF_NULL_POOL_OPS = { .version = UMF_POOL_OPS_VERSION_CURRENT, .initialize = nullInitialize, @@ -81,4 +87,5 @@ umf_memory_pool_ops_t UMF_NULL_POOL_OPS = { .malloc_usable_size = nullMallocUsableSize, .free = nullFree, .get_last_allocation_error = nullGetLastStatus, + .get_name = nullGetName, }; diff --git a/test/common/pool_trace.c b/test/common/pool_trace.c index 719a57fb4c..ce944479f0 100644 --- a/test/common/pool_trace.c +++ b/test/common/pool_trace.c @@ -93,6 +93,12 @@ static umf_result_t traceGetLastStatus(void *pool) { return umfPoolGetLastAllocationError(trace_pool->params.hUpstreamPool); } +static umf_result_t traceGetName(void *pool, const char **name) { + (void)pool; + *name = "trace"; + return UMF_RESULT_SUCCESS; +} + umf_memory_pool_ops_t UMF_TRACE_POOL_OPS = { .version = UMF_POOL_OPS_VERSION_CURRENT, .initialize = traceInitialize, @@ -104,4 +110,5 @@ umf_memory_pool_ops_t UMF_TRACE_POOL_OPS = { .malloc_usable_size = traceMallocUsableSize, .free = traceFree, .get_last_allocation_error = traceGetLastStatus, + .get_name = traceGetName, }; diff --git a/test/utils/cpp_helpers.hpp b/test/utils/cpp_helpers.hpp index 8594a6aa07..0baf2ba87c 100644 --- a/test/utils/cpp_helpers.hpp +++ b/test/utils/cpp_helpers.hpp @@ -79,6 +79,12 @@ template umf_memory_pool_ops_t poolOpsBase() { UMF_ASSIGN_OP(ops, T, malloc_usable_size, UMF_RESULT_SUCCESS); UMF_ASSIGN_OP(ops, T, free, UMF_RESULT_SUCCESS); UMF_ASSIGN_OP(ops, T, get_last_allocation_error, UMF_RESULT_ERROR_UNKNOWN); + ops.get_name = [](void *, const char **name) { + if (name) { + *name = "test_pool"; + } + return UMF_RESULT_SUCCESS; + }; return ops; }