Skip to content

Update DevDax provider config API #928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2024
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
58 changes: 37 additions & 21 deletions include/umf/providers/provider_devdax_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,43 @@ extern "C" {
#define UMF_DEVDAX_RESULTS_START_FROM 2000
/// @endcond

/// @brief Memory provider settings struct
typedef struct umf_devdax_memory_provider_params_t {
/// path of the device DAX
char *path;
/// size of the device DAX in bytes
size_t size;
/// combination of 'umf_mem_protection_flags_t' flags
unsigned protection;
} umf_devdax_memory_provider_params_t;
struct umf_devdax_memory_provider_params_t;

typedef struct umf_devdax_memory_provider_params_t
*umf_devdax_memory_provider_params_handle_t;

/// @brief Create a struct to store parameters of the Devdax Memory Provider.
/// @param hParams [out] handle to the newly created parameters struct.
/// @param path [in] path of the device DAX.
/// @param size [in] size of the device DAX in bytes.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfDevDaxMemoryProviderParamsCreate(
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
size_t size);

/// @brief Destroy parameters struct.
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfDevDaxMemoryProviderParamsDestroy(
umf_devdax_memory_provider_params_handle_t hParams);

/// @brief Set a device DAX in the parameters struct. Overwrites the previous value.
/// It provides an ability to use the same instance of params to create multiple
/// instances of the provider for different DAX devices.
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
/// @param path [in] path of the device DAX.
/// @param size [in] size of the device DAX in bytes.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
size_t size);

/// @brief Set the protection flags in the parameters struct.
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
/// @param protection [in] combination of 'umf_mem_protection_flags_t' flags.
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection);

/// @brief Devdax Memory Provider operation results
typedef enum umf_devdax_memory_provider_native_error {
Expand All @@ -39,18 +67,6 @@ typedef enum umf_devdax_memory_provider_native_error {

umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void);

/// @brief Create default params for the devdax memory provider
static inline umf_devdax_memory_provider_params_t
umfDevDaxMemoryProviderParamsDefault(char *path, size_t size) {
umf_devdax_memory_provider_params_t params = {
path, /* path of the device DAX */
size, /* size of the device DAX in bytes */
UMF_PROTECTION_READ | UMF_PROTECTION_WRITE, /* protection */
};

return params;
}

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/libumf.def
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ EXPORTS
umfCUDAMemoryProviderParamsSetDevice
umfCUDAMemoryProviderParamsSetMemoryType
umfDevDaxMemoryProviderOps
umfDevDaxMemoryProviderParamsCreate
umfDevDaxMemoryProviderParamsDestroy
umfDevDaxMemoryProviderParamsSetDeviceDax
umfDevDaxMemoryProviderParamsSetProtection
umfFree
umfFileMemoryProviderOps
umfFileMemoryProviderParamsCreate
Expand Down
4 changes: 4 additions & 0 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ UMF_1.0 {
umfCUDAMemoryProviderParamsSetDevice;
umfCUDAMemoryProviderParamsSetMemoryType;
umfDevDaxMemoryProviderOps;
umfDevDaxMemoryProviderParamsCreate;
umfDevDaxMemoryProviderParamsDestroy;
umfDevDaxMemoryProviderParamsSetDeviceDax;
umfDevDaxMemoryProviderParamsSetProtection;
umfFree;
umfFileMemoryProviderOps;
umfFileMemoryProviderParamsCreate;
Expand Down
145 changes: 145 additions & 0 deletions src/provider/provider_devdax_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,41 @@ umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) {
return NULL;
}

umf_result_t umfDevDaxMemoryProviderParamsCreate(
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
size_t size) {
(void)hParams;
(void)path;
(void)size;
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

umf_result_t umfDevDaxMemoryProviderParamsDestroy(
umf_devdax_memory_provider_params_handle_t hParams) {
(void)hParams;
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
size_t size) {
(void)hParams;
(void)path;
(void)size;
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection) {
(void)hParams;
(void)protection;
return UMF_RESULT_ERROR_NOT_SUPPORTED;
}

#else // !defined(_WIN32) && !defined(UMF_NO_HWLOC)

#include "base_alloc_global.h"
#include "libumf.h"
#include "utils_common.h"
#include "utils_concurrency.h"
#include "utils_log.h"
Expand All @@ -44,6 +76,13 @@ typedef struct devdax_memory_provider_t {
unsigned protection; // combination of OS-specific protection flags
} devdax_memory_provider_t;

// DevDax Memory provider settings struct
typedef struct umf_devdax_memory_provider_params_t {
char *path;
size_t size;
unsigned protection;
} umf_devdax_memory_provider_params_t;

typedef struct devdax_last_native_error_t {
int32_t native_error;
int errno_value;
Expand Down Expand Up @@ -511,4 +550,110 @@ umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) {
return &UMF_DEVDAX_MEMORY_PROVIDER_OPS;
}

umf_result_t umfDevDaxMemoryProviderParamsCreate(
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
size_t size) {
libumfInit();
if (hParams == NULL) {
LOG_ERR("DevDax Memory Provider params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

if (path == NULL) {
LOG_ERR("DevDax path is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

umf_devdax_memory_provider_params_handle_t params =
umf_ba_global_alloc(sizeof(*params));
if (params == NULL) {
LOG_ERR(
"Allocating memory for the DevDax Memory Provider params failed");
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

params->path = NULL;
params->size = 0;
params->protection = UMF_PROTECTION_READ | UMF_PROTECTION_WRITE;

umf_result_t res =
umfDevDaxMemoryProviderParamsSetDeviceDax(params, path, size);
if (res != UMF_RESULT_SUCCESS) {
umf_ba_global_free(params);
return res;
}

*hParams = params;

return UMF_RESULT_SUCCESS;
}

umf_result_t umfDevDaxMemoryProviderParamsDestroy(
umf_devdax_memory_provider_params_handle_t hParams) {
if (hParams != NULL) {
umf_ba_global_free(hParams->path);
umf_ba_global_free(hParams);
}

return UMF_RESULT_SUCCESS;
}

umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
size_t size) {
if (hParams == NULL) {
LOG_ERR("DevDax Memory Provider params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

if (path == NULL) {
LOG_ERR("DevDax path is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

size_t path_len = strlen(path);
if (path_len == 0) {
LOG_ERR("DevDax path is empty");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

path_len += 1; // for the null terminator
char *new_path = umf_ba_global_alloc(path_len);
if (new_path == NULL) {
LOG_ERR("Allocating memory for the DevDax path failed");
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

strncpy(new_path, path, path_len);

umf_ba_global_free(hParams->path);

hParams->path = new_path;
hParams->size = size;

return UMF_RESULT_SUCCESS;
}

umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection) {
if (hParams == NULL) {
LOG_ERR("DevDax Memory Provider params handle is NULL");
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

// verify that protection contains only valid bits set
// (UMF_PROTECTION_MAX-1) - highest possible bit
// (UMF_PROTECTION_MAX-1) << 1 - next after highest possible bit
// ((UMF_PROTECTION_MAX-1) << 1) - 1 - all valid bits set
const unsigned VALID_FLAGS_ALL = ((UMF_PROTECTION_MAX - 1) << 1) - 1;
if (protection & ~VALID_FLAGS_ALL || protection == 0) {
LOG_ERR("Incorrect memory protection flags: %u", protection);
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

hParams->protection = protection;

return UMF_RESULT_SUCCESS;
}

#endif // !defined(_WIN32) && !defined(UMF_NO_HWLOC)
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ else()
NAME provider_file_memory_not_impl
SRCS provider_file_memory_not_impl.cpp
LIBS ${UMF_UTILS_FOR_TEST})
add_umf_test(
NAME provider_devdax_memory_not_impl
SRCS provider_devdax_memory_not_impl.cpp
LIBS ${UMF_UTILS_FOR_TEST})
endif()

if(UMF_DISABLE_HWLOC)
Expand Down
21 changes: 16 additions & 5 deletions test/ipc_devdax_prov_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ int main(int argc, char *argv[]) {
return -1;
}

int ret = 0;
int port = atoi(argv[1]);

char *path = getenv("UMF_TESTS_DEVDAX_PATH");
Expand All @@ -33,12 +34,22 @@ int main(int argc, char *argv[]) {
return 0;
}

umf_devdax_memory_provider_params_t devdax_params =
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
umf_devdax_memory_provider_params_handle_t devdax_params = NULL;
umf_result_t umf_result =
umfDevDaxMemoryProviderParamsCreate(&devdax_params, path, atol(size));
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "[consumer] ERROR: creating DevDax Memory Provider "
"params failed\n");
return -1;
}

void *pool_params = NULL;

return run_consumer(port, umfScalablePoolOps(), pool_params,
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
NULL);
ret = run_consumer(port, umfScalablePoolOps(), pool_params,
umfDevDaxMemoryProviderOps(), devdax_params, memcopy,
NULL);

umfDevDaxMemoryProviderParamsDestroy(devdax_params);

return ret;
}
21 changes: 16 additions & 5 deletions test/ipc_devdax_prov_producer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ int main(int argc, char *argv[]) {
return -1;
}

int ret = 0;
int port = atoi(argv[1]);

char *path = getenv("UMF_TESTS_DEVDAX_PATH");
Expand All @@ -33,12 +34,22 @@ int main(int argc, char *argv[]) {
return 0;
}

umf_devdax_memory_provider_params_t devdax_params =
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
umf_devdax_memory_provider_params_handle_t devdax_params = NULL;
umf_result_t umf_result =
umfDevDaxMemoryProviderParamsCreate(&devdax_params, path, atol(size));
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "[producer] ERROR: creating DevDax Memory Provider "
"params failed\n");
return -1;
}

void *pool_params = NULL;

return run_producer(port, umfScalablePoolOps(), pool_params,
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
NULL);
ret = run_producer(port, umfScalablePoolOps(), pool_params,
umfDevDaxMemoryProviderOps(), devdax_params, memcopy,
NULL);

umfDevDaxMemoryProviderParamsDestroy(devdax_params);

return ret;
}
21 changes: 0 additions & 21 deletions test/poolFixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,6 @@ struct umfPoolTest : umf_test::test,
void SetUp() override {
test::SetUp();

auto [pool_ops, pool_params, provider_ops, provider_params,
coarse_params] = this->GetParam();
(void)pool_ops;
(void)pool_params;
(void)provider_params;
(void)coarse_params;

if (provider_ops == umfDevDaxMemoryProviderOps()) {
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
if (path == nullptr || path[0] == 0) {
GTEST_SKIP()
<< "Test skipped, UMF_TESTS_DEVDAX_PATH is not set";
}

char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
if (size == nullptr || size[0] == 0) {
GTEST_SKIP()
<< "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set";
}
}

pool = poolCreateExtUnique(this->GetParam());
}

Expand Down
Loading
Loading