Skip to content

Commit 38705d6

Browse files
Merge pull request #928 from vinser52/svinogra_devdax_params
Update DevDax provider config API
2 parents 134aafd + ae5b743 commit 38705d6

13 files changed

+523
-122
lines changed

include/umf/providers/provider_devdax_memory.h

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,43 @@ extern "C" {
1818
#define UMF_DEVDAX_RESULTS_START_FROM 2000
1919
/// @endcond
2020

21-
/// @brief Memory provider settings struct
22-
typedef struct umf_devdax_memory_provider_params_t {
23-
/// path of the device DAX
24-
char *path;
25-
/// size of the device DAX in bytes
26-
size_t size;
27-
/// combination of 'umf_mem_protection_flags_t' flags
28-
unsigned protection;
29-
} umf_devdax_memory_provider_params_t;
21+
struct umf_devdax_memory_provider_params_t;
22+
23+
typedef struct umf_devdax_memory_provider_params_t
24+
*umf_devdax_memory_provider_params_handle_t;
25+
26+
/// @brief Create a struct to store parameters of the Devdax Memory Provider.
27+
/// @param hParams [out] handle to the newly created parameters struct.
28+
/// @param path [in] path of the device DAX.
29+
/// @param size [in] size of the device DAX in bytes.
30+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
31+
umf_result_t umfDevDaxMemoryProviderParamsCreate(
32+
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
33+
size_t size);
34+
35+
/// @brief Destroy parameters struct.
36+
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
37+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
38+
umf_result_t umfDevDaxMemoryProviderParamsDestroy(
39+
umf_devdax_memory_provider_params_handle_t hParams);
40+
41+
/// @brief Set a device DAX in the parameters struct. Overwrites the previous value.
42+
/// It provides an ability to use the same instance of params to create multiple
43+
/// instances of the provider for different DAX devices.
44+
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
45+
/// @param path [in] path of the device DAX.
46+
/// @param size [in] size of the device DAX in bytes.
47+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
48+
umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
49+
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
50+
size_t size);
51+
52+
/// @brief Set the protection flags in the parameters struct.
53+
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
54+
/// @param protection [in] combination of 'umf_mem_protection_flags_t' flags.
55+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
56+
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
57+
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection);
3058

3159
/// @brief Devdax Memory Provider operation results
3260
typedef enum umf_devdax_memory_provider_native_error {
@@ -39,18 +67,6 @@ typedef enum umf_devdax_memory_provider_native_error {
3967

4068
umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void);
4169

42-
/// @brief Create default params for the devdax memory provider
43-
static inline umf_devdax_memory_provider_params_t
44-
umfDevDaxMemoryProviderParamsDefault(char *path, size_t size) {
45-
umf_devdax_memory_provider_params_t params = {
46-
path, /* path of the device DAX */
47-
size, /* size of the device DAX in bytes */
48-
UMF_PROTECTION_READ | UMF_PROTECTION_WRITE, /* protection */
49-
};
50-
51-
return params;
52-
}
53-
5470
#ifdef __cplusplus
5571
}
5672
#endif

src/libumf.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ EXPORTS
2323
umfCUDAMemoryProviderParamsSetDevice
2424
umfCUDAMemoryProviderParamsSetMemoryType
2525
umfDevDaxMemoryProviderOps
26+
umfDevDaxMemoryProviderParamsCreate
27+
umfDevDaxMemoryProviderParamsDestroy
28+
umfDevDaxMemoryProviderParamsSetDeviceDax
29+
umfDevDaxMemoryProviderParamsSetProtection
2630
umfFree
2731
umfFileMemoryProviderOps
2832
umfFileMemoryProviderParamsCreate

src/libumf.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ UMF_1.0 {
1717
umfCUDAMemoryProviderParamsSetDevice;
1818
umfCUDAMemoryProviderParamsSetMemoryType;
1919
umfDevDaxMemoryProviderOps;
20+
umfDevDaxMemoryProviderParamsCreate;
21+
umfDevDaxMemoryProviderParamsDestroy;
22+
umfDevDaxMemoryProviderParamsSetDeviceDax;
23+
umfDevDaxMemoryProviderParamsSetProtection;
2024
umfFree;
2125
umfFileMemoryProviderOps;
2226
umfFileMemoryProviderParamsCreate;

src/provider/provider_devdax_memory.c

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,41 @@ umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) {
2424
return NULL;
2525
}
2626

27+
umf_result_t umfDevDaxMemoryProviderParamsCreate(
28+
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
29+
size_t size) {
30+
(void)hParams;
31+
(void)path;
32+
(void)size;
33+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
34+
}
35+
36+
umf_result_t umfDevDaxMemoryProviderParamsDestroy(
37+
umf_devdax_memory_provider_params_handle_t hParams) {
38+
(void)hParams;
39+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
40+
}
41+
42+
umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
43+
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
44+
size_t size) {
45+
(void)hParams;
46+
(void)path;
47+
(void)size;
48+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
49+
}
50+
51+
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
52+
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection) {
53+
(void)hParams;
54+
(void)protection;
55+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
56+
}
57+
2758
#else // !defined(_WIN32) && !defined(UMF_NO_HWLOC)
2859

2960
#include "base_alloc_global.h"
61+
#include "libumf.h"
3062
#include "utils_common.h"
3163
#include "utils_concurrency.h"
3264
#include "utils_log.h"
@@ -44,6 +76,13 @@ typedef struct devdax_memory_provider_t {
4476
unsigned protection; // combination of OS-specific protection flags
4577
} devdax_memory_provider_t;
4678

79+
// DevDax Memory provider settings struct
80+
typedef struct umf_devdax_memory_provider_params_t {
81+
char *path;
82+
size_t size;
83+
unsigned protection;
84+
} umf_devdax_memory_provider_params_t;
85+
4786
typedef struct devdax_last_native_error_t {
4887
int32_t native_error;
4988
int errno_value;
@@ -511,4 +550,110 @@ umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) {
511550
return &UMF_DEVDAX_MEMORY_PROVIDER_OPS;
512551
}
513552

553+
umf_result_t umfDevDaxMemoryProviderParamsCreate(
554+
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
555+
size_t size) {
556+
libumfInit();
557+
if (hParams == NULL) {
558+
LOG_ERR("DevDax Memory Provider params handle is NULL");
559+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
560+
}
561+
562+
if (path == NULL) {
563+
LOG_ERR("DevDax path is NULL");
564+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
565+
}
566+
567+
umf_devdax_memory_provider_params_handle_t params =
568+
umf_ba_global_alloc(sizeof(*params));
569+
if (params == NULL) {
570+
LOG_ERR(
571+
"Allocating memory for the DevDax Memory Provider params failed");
572+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
573+
}
574+
575+
params->path = NULL;
576+
params->size = 0;
577+
params->protection = UMF_PROTECTION_READ | UMF_PROTECTION_WRITE;
578+
579+
umf_result_t res =
580+
umfDevDaxMemoryProviderParamsSetDeviceDax(params, path, size);
581+
if (res != UMF_RESULT_SUCCESS) {
582+
umf_ba_global_free(params);
583+
return res;
584+
}
585+
586+
*hParams = params;
587+
588+
return UMF_RESULT_SUCCESS;
589+
}
590+
591+
umf_result_t umfDevDaxMemoryProviderParamsDestroy(
592+
umf_devdax_memory_provider_params_handle_t hParams) {
593+
if (hParams != NULL) {
594+
umf_ba_global_free(hParams->path);
595+
umf_ba_global_free(hParams);
596+
}
597+
598+
return UMF_RESULT_SUCCESS;
599+
}
600+
601+
umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
602+
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
603+
size_t size) {
604+
if (hParams == NULL) {
605+
LOG_ERR("DevDax Memory Provider params handle is NULL");
606+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
607+
}
608+
609+
if (path == NULL) {
610+
LOG_ERR("DevDax path is NULL");
611+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
612+
}
613+
614+
size_t path_len = strlen(path);
615+
if (path_len == 0) {
616+
LOG_ERR("DevDax path is empty");
617+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
618+
}
619+
620+
path_len += 1; // for the null terminator
621+
char *new_path = umf_ba_global_alloc(path_len);
622+
if (new_path == NULL) {
623+
LOG_ERR("Allocating memory for the DevDax path failed");
624+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
625+
}
626+
627+
strncpy(new_path, path, path_len);
628+
629+
umf_ba_global_free(hParams->path);
630+
631+
hParams->path = new_path;
632+
hParams->size = size;
633+
634+
return UMF_RESULT_SUCCESS;
635+
}
636+
637+
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
638+
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection) {
639+
if (hParams == NULL) {
640+
LOG_ERR("DevDax Memory Provider params handle is NULL");
641+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
642+
}
643+
644+
// verify that protection contains only valid bits set
645+
// (UMF_PROTECTION_MAX-1) - highest possible bit
646+
// (UMF_PROTECTION_MAX-1) << 1 - next after highest possible bit
647+
// ((UMF_PROTECTION_MAX-1) << 1) - 1 - all valid bits set
648+
const unsigned VALID_FLAGS_ALL = ((UMF_PROTECTION_MAX - 1) << 1) - 1;
649+
if (protection & ~VALID_FLAGS_ALL || protection == 0) {
650+
LOG_ERR("Incorrect memory protection flags: %u", protection);
651+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
652+
}
653+
654+
hParams->protection = protection;
655+
656+
return UMF_RESULT_SUCCESS;
657+
}
658+
514659
#endif // !defined(_WIN32) && !defined(UMF_NO_HWLOC)

test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ else()
343343
NAME provider_file_memory_not_impl
344344
SRCS provider_file_memory_not_impl.cpp
345345
LIBS ${UMF_UTILS_FOR_TEST})
346+
add_umf_test(
347+
NAME provider_devdax_memory_not_impl
348+
SRCS provider_devdax_memory_not_impl.cpp
349+
LIBS ${UMF_UTILS_FOR_TEST})
346350
endif()
347351

348352
if(UMF_DISABLE_HWLOC)

test/ipc_devdax_prov_consumer.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int main(int argc, char *argv[]) {
1919
return -1;
2020
}
2121

22+
int ret = 0;
2223
int port = atoi(argv[1]);
2324

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

36-
umf_devdax_memory_provider_params_t devdax_params =
37-
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
37+
umf_devdax_memory_provider_params_handle_t devdax_params = NULL;
38+
umf_result_t umf_result =
39+
umfDevDaxMemoryProviderParamsCreate(&devdax_params, path, atol(size));
40+
if (umf_result != UMF_RESULT_SUCCESS) {
41+
fprintf(stderr, "[consumer] ERROR: creating DevDax Memory Provider "
42+
"params failed\n");
43+
return -1;
44+
}
3845

3946
void *pool_params = NULL;
4047

41-
return run_consumer(port, umfScalablePoolOps(), pool_params,
42-
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
43-
NULL);
48+
ret = run_consumer(port, umfScalablePoolOps(), pool_params,
49+
umfDevDaxMemoryProviderOps(), devdax_params, memcopy,
50+
NULL);
51+
52+
umfDevDaxMemoryProviderParamsDestroy(devdax_params);
53+
54+
return ret;
4455
}

test/ipc_devdax_prov_producer.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int main(int argc, char *argv[]) {
1919
return -1;
2020
}
2121

22+
int ret = 0;
2223
int port = atoi(argv[1]);
2324

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

36-
umf_devdax_memory_provider_params_t devdax_params =
37-
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
37+
umf_devdax_memory_provider_params_handle_t devdax_params = NULL;
38+
umf_result_t umf_result =
39+
umfDevDaxMemoryProviderParamsCreate(&devdax_params, path, atol(size));
40+
if (umf_result != UMF_RESULT_SUCCESS) {
41+
fprintf(stderr, "[producer] ERROR: creating DevDax Memory Provider "
42+
"params failed\n");
43+
return -1;
44+
}
3845

3946
void *pool_params = NULL;
4047

41-
return run_producer(port, umfScalablePoolOps(), pool_params,
42-
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
43-
NULL);
48+
ret = run_producer(port, umfScalablePoolOps(), pool_params,
49+
umfDevDaxMemoryProviderOps(), devdax_params, memcopy,
50+
NULL);
51+
52+
umfDevDaxMemoryProviderParamsDestroy(devdax_params);
53+
54+
return ret;
4455
}

test/poolFixtures.hpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,6 @@ struct umfPoolTest : umf_test::test,
6969
void SetUp() override {
7070
test::SetUp();
7171

72-
auto [pool_ops, pool_params, provider_ops, provider_params,
73-
coarse_params] = this->GetParam();
74-
(void)pool_ops;
75-
(void)pool_params;
76-
(void)provider_params;
77-
(void)coarse_params;
78-
79-
if (provider_ops == umfDevDaxMemoryProviderOps()) {
80-
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
81-
if (path == nullptr || path[0] == 0) {
82-
GTEST_SKIP()
83-
<< "Test skipped, UMF_TESTS_DEVDAX_PATH is not set";
84-
}
85-
86-
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
87-
if (size == nullptr || size[0] == 0) {
88-
GTEST_SKIP()
89-
<< "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set";
90-
}
91-
}
92-
9372
pool = poolCreateExtUnique(this->GetParam());
9473
}
9574

0 commit comments

Comments
 (0)