Skip to content

Commit

Permalink
Update DevDax provider config API
Browse files Browse the repository at this point in the history
  • Loading branch information
vinser52 committed Nov 25, 2024
1 parent 6daa1bf commit 0a4b57b
Show file tree
Hide file tree
Showing 11 changed files with 420 additions and 121 deletions.
56 changes: 35 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,41 @@ 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 device DAX in the parameters struct.
/// @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 +65,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
umfGetIPCHandle
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;
umfGetIPCHandle;
Expand Down
135 changes: 135 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,100 @@ 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;
}

hParams->protection = protection;

return UMF_RESULT_SUCCESS;
}

#endif // !defined(_WIN32) && !defined(UMF_NO_HWLOC)
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
41 changes: 33 additions & 8 deletions test/pools/jemalloc_coarse_devdax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,39 @@

#include "pool_coarse.hpp"

using devdax_params_unique_handle_t =
std::unique_ptr<umf_devdax_memory_provider_params_t,
decltype(&umfDevDaxMemoryProviderParamsDestroy)>;

devdax_params_unique_handle_t create_devdax_params() {
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) {
return devdax_params_unique_handle_t(
nullptr, &umfDevDaxMemoryProviderParamsDestroy);
}

umf_devdax_memory_provider_params_handle_t params = NULL;
umf_result_t res =
umfDevDaxMemoryProviderParamsCreate(&params, path, atol(size));
if (res != UMF_RESULT_SUCCESS) {
throw std::runtime_error(
"Failed to create DevDax Memory Provider params");
}

return devdax_params_unique_handle_t(params,
&umfDevDaxMemoryProviderParamsDestroy);
}

auto coarseParams = umfCoarseMemoryProviderParamsDefault();
auto devdaxParams = umfDevDaxMemoryProviderParamsDefault(
getenv("UMF_TESTS_DEVDAX_PATH"), getenv("UMF_TESTS_DEVDAX_SIZE")
? atol(getenv("UMF_TESTS_DEVDAX_SIZE"))
: 0);
auto devdaxParams = create_devdax_params();

static std::vector<poolCreateExtParams> poolParamsList =
devdaxParams.get()
? std::vector<poolCreateExtParams>{poolCreateExtParams{
umfJemallocPoolOps(), nullptr, umfDevDaxMemoryProviderOps(),
devdaxParams.get(), &coarseParams}}
: std::vector<poolCreateExtParams>{};

INSTANTIATE_TEST_SUITE_P(jemallocCoarseDevDaxTest, umfPoolTest,
::testing::Values(poolCreateExtParams{
umfJemallocPoolOps(), nullptr,
umfDevDaxMemoryProviderOps(), &devdaxParams,
&coarseParams}));
::testing::ValuesIn(poolParamsList));
Loading

0 comments on commit 0a4b57b

Please sign in to comment.