Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/umf/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 15 additions & 14 deletions include/umf/memory_pool_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///

///
Expand All @@ -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
Expand Down
20 changes: 5 additions & 15 deletions src/memory_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/pool/pool_disjoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
7 changes: 7 additions & 0 deletions src/pool/pool_jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion src/pool/pool_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/pool/pool_scalable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions test/common/pool_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
7 changes: 7 additions & 0 deletions test/common/pool_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
6 changes: 6 additions & 0 deletions test/utils/cpp_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ template <typename T> 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;
}

Expand Down
Loading