diff --git a/doc/libpmem2/pmem2_async.3.md b/doc/libpmem2/pmem2_async.3.md index d7f1e654fbd4bb9718d19b0d1f933015650c5dda..ac9892e49e1da0fcf64bd99ff66fa0cff421beff 100644 --- a/doc/libpmem2/pmem2_async.3.md +++ b/doc/libpmem2/pmem2_async.3.md @@ -26,15 +26,17 @@ date: pmem2 API version 1.0 ```c #define PMEM2_USE_MINIASYNC 1 #include <libpmem2.h> +struct pmem2_future; + int pmem2_config_set_vdm(struct pmem2_config *cfg, struct vdm *vdm); -struct vdm_operation_future pmem2_memcpy_async(struct pmem2_map *map, +struct pmem2_future pmem2_memcpy_async(struct pmem2_map *map, void *pmemdest, const void *src, size_t len, unsigned flags); -pmem2_memmove_async(struct pmem2_map *map, void *pmemdest, const void *src, +struct pmem2_future pmem2_memmove_async(struct pmem2_map *map, void *pmemdest, const void *src, size_t len, unsigned flags) -struct vdm_operation_future pmem2_memset_async(struct pmem2_map *map, +struct pmem2_future pmem2_memset_async(struct pmem2_map *map, void *pmemstr, int c, size_t n, unsigned flags) { ``` @@ -43,30 +45,33 @@ struct vdm_operation_future pmem2_memset_async(struct pmem2_map *map, To use those functions, you must have *libminiasync* installed. Those functions use futures and vdm (virtual data mover) concepts from this library. Please check **miniasync**(7) for more details. +The struct **pmem2_future** is a structure describing a task to be done asynchronously taking into account persistence +of the operation. It means that by the time the future is complete, all the data is safely written into a persistent domain. + The **pmem2_config_set_vdm** sets a vdm structure in the *pmem2_config*. -This structure will be used by pmem2_*_async functions, to create a *vdm_operation_future*. +This structure will be used by pmem2_*_async functions, to create a *pmem2_future*. If vdm is not set in the config, pmem2_map_new will use a default one which uses a -pmem2 memory movement functions to perform memory operations. (**pmem2_get_memcpy_fn**(3), **pmem2_get_memmove_fn**(3), **pmem2_get_memsety_fn**(3)). +pmem2 memory movement functions to perform memory operations. (**pmem2_get_memcpy_fn**(3), **pmem2_get_memmove_fn**(3), **pmem2_get_memset_fn**(3)). -The **pmem2_memcpy_async** uses *vdm* structure held inside the *pmem2_map* structure to initialise and returns **vdm_operation_future**. +The **pmem2_memcpy_async** uses *vdm* structure held inside the *pmem2_map* structure to initialise and returns **pmem2_future**. This future will perform memcpy operation defined in *vdm* to copy *len* bytes from *src* to *pmemdest*. In the current implementation *flags* are ignored. -The **pmem2_memmove_async** returns **vdm_operation_future** which +The **pmem2_memmove_async** returns **pmem2_future** which will perform memmove operation defined in *vdm* to copy *len* bytes from *src* to *pmemdest*. In the current implementation *flags* are ignored. -The **pmem2_memmset_async** returns **vdm_operation_future** which +The **pmem2_memset_async** returns **pmem2_future** which will perform memset operation defined in *vdm* to fill *n* bytes from *pmemstr* with value of int *c* interpreted as unsigned char. In the current implementation *flags* are ignored. # RETURN VALUE # The **pmem2_config_set_vdm** always return 0. -The **pmem2_memcpy_async** returns a new instance of **vdm_operation_future** performing memcpy operation. +The **pmem2_memcpy_async** returns a new instance of **pmem2_future** performing memcpy operation. You can execute returned structure using methods from the **libminiasync**() library such as **FUTURE_BUSY_POLL**(3). -The **pmem2_memmove_async** returns a new instance of **vdm_operation_future** performing memmove operation. +The **pmem2_memmove_async** returns a new instance of **pmem2_future** performing memmove operation. -The **pmem2_memset_async** returns a new instance of **vdm_operation_future** performing memset operation. +The **pmem2_memset_async** returns a new instance of **pmem2_future** performing memset operation. # SEE ALSO # diff --git a/src/Makefile b/src/Makefile index ee2fb2e78df7801a32a5ab67321c323d3b823a7b..fb6d6ecddea9e2c338459b96553fdc75d8973184 100644 --- a/src/Makefile +++ b/src/Makefile @@ -45,6 +45,7 @@ HEADERS_INSTALL = include/libpmem.h\ include/libpmem2.h OBJ_HEADERS_INSTALL = include/libpmemobj/*.h +PMEM2_HEADERS_INSTALL = include/libpmem2/*.h PKG_CONFIG_DESTDIR = $(DESTDIR)$(pkgconfigdir) PKG_CONFIG_COMMON = common.pc @@ -85,6 +86,7 @@ HEADERS =\ freebsd/include/*/*.h\ include/lib*.h\ include/libpmemobj/*.h\ + include/libpmem2/*.h\ windows/include/*.h\ windows/include/*/*.h\ ), $(f)) @@ -182,7 +184,9 @@ install: all pkg-config install -d $(HEADERS_DESTDIR) install -p -m 0644 $(HEADERS_INSTALL) $(HEADERS_DESTDIR) install -d $(HEADERS_DESTDIR)/libpmemobj + install -d $(HEADERS_DESTDIR)/libpmem2 install -p -m 0644 $(OBJ_HEADERS_INSTALL) $(HEADERS_DESTDIR)/libpmemobj + install -p -m 0644 $(PMEM2_HEADERS_INSTALL) $(HEADERS_DESTDIR)/libpmem2 install -d $(PKG_CONFIG_DESTDIR) install -p -m 0644 $(PKG_CONFIG_FILES) $(PKG_CONFIG_DESTDIR) install -d $(PMREORDER_DESTDIR) @@ -196,6 +200,7 @@ install: all pkg-config uninstall: $(foreach f, $(HEADERS_INSTALL), $(RM) $(HEADERS_DESTDIR)/$(notdir $(f))) $(foreach f, $(OBJ_HEADERS_INSTALL), $(RM) $(HEADERS_DESTDIR)/libpmemobj/$(notdir $(f))) + $(foreach f, $(PMEM2_HEADERS_INSTALL), $(RM) $(HEADERS_DESTDIR)/libpmem2/$(notdir $(f))) $(foreach f, $(PKG_CONFIG_FILES), $(RM) $(PKG_CONFIG_DESTDIR)/$(notdir $(f))) $(foreach f, $(PMREORDER_FILES), $(RM) $(PMREORDER_DESTDIR)/$(notdir $(f))) $(RM) $(PMREORDER_BIN)/pmreorder diff --git a/src/PMDK.sln b/src/PMDK.sln index d3a46c5ae7552db54384978666787f0ac2fd37fd..d8220c1592138c28393306d196cb5653d8e76871 100644 --- a/src/PMDK.sln +++ b/src/PMDK.sln @@ -656,6 +656,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checksum", "test\checksum\c EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpmempool_transform_win", "test\libpmempool_transform_win\libpmempool_transform_win.vcxproj", "{B30C6212-A160-405A-8FE7-340E721738A2}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pmem2_future", "test\pmem2_future\pmem2_future.vcxproj", "{B31866FF-6B5D-4CF9-819C-FBA86079FB19}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pmemwrite", "test\tools\pmemwrite\pmemwrite.vcxproj", "{B35BFA09-DE68-483B-AB61-8790E8F060A8}" ProjectSection(ProjectDependencies) = postProject {901F04DB-E1A5-4A41-8B81-9D31C19ACD59} = {901F04DB-E1A5-4A41-8B81-9D31C19ACD59} @@ -1719,6 +1721,10 @@ Global {B30C6212-A160-405A-8FE7-340E721738A2}.Debug|x64.Build.0 = Debug|x64 {B30C6212-A160-405A-8FE7-340E721738A2}.Release|x64.ActiveCfg = Release|x64 {B30C6212-A160-405A-8FE7-340E721738A2}.Release|x64.Build.0 = Release|x64 + {B31866FF-6B5D-4CF9-819C-FBA86079FB19}.Debug|x64.ActiveCfg = Debug|x64 + {B31866FF-6B5D-4CF9-819C-FBA86079FB19}.Debug|x64.Build.0 = Debug|x64 + {B31866FF-6B5D-4CF9-819C-FBA86079FB19}.Release|x64.ActiveCfg = Release|x64 + {B31866FF-6B5D-4CF9-819C-FBA86079FB19}.Release|x64.Build.0 = Release|x64 {B35BFA09-DE68-483B-AB61-8790E8F060A8}.Debug|x64.ActiveCfg = Debug|x64 {B35BFA09-DE68-483B-AB61-8790E8F060A8}.Debug|x64.Build.0 = Debug|x64 {B35BFA09-DE68-483B-AB61-8790E8F060A8}.Release|x64.ActiveCfg = Release|x64 @@ -2321,6 +2327,7 @@ Global {AF038868-2432-4159-A62F-941F11D12C5D} = {59AB6976-D16B-48D0-8D16-94360D3FE51D} {AF0B7480-EBE3-486B-B0C8-134910BC9324} = {4C291EEB-3874-4724-9CC2-1335D13FF0EE} {B30C6212-A160-405A-8FE7-340E721738A2} = {2F543422-4B8A-4898-BE6B-590F52B4E9D1} + {B31866FF-6B5D-4CF9-819C-FBA86079FB19} = {A14A4556-9092-430D-B9CA-B2B1223D56CB} {B35BFA09-DE68-483B-AB61-8790E8F060A8} = {F09A0864-9221-47AD-872F-D4538104D747} {B36F115C-8139-4C35-A3E7-E6BF9F3DA793} = {F8373EDD-1B9E-462D-BF23-55638E23E98B} {B379539C-E130-460D-AE82-4EBDD1A97845} = {63C9B3F8-437D-4AD9-B32D-D04AE38C35B6} diff --git a/src/include/libpmem2.h b/src/include/libpmem2.h index c880ce64b4f6418273ef124e005a154c84f959d1..e8f0da0cf7cc3c57c4183f804c26dfd027192119 100644 --- a/src/include/libpmem2.h +++ b/src/include/libpmem2.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2019-2021, Intel Corporation */ +/* Copyright 2019-2022, Intel Corporation */ /* * libpmem2.h -- definitions of libpmem2 entry points @@ -14,304 +14,9 @@ #ifndef LIBPMEM2_H #define LIBPMEM2_H 1 -#include <stddef.h> -#include <stdint.h> +#include <libpmem2/base.h> #ifdef PMEM2_USE_MINIASYNC -#include <libminiasync/vdm.h> +#include <libpmem2/async.h> #endif -#ifdef _WIN32 -#include <pmemcompat.h> -#ifndef PMDK_UTF8_API -#define pmem2_source_device_id pmem2_source_device_idW -#define pmem2_errormsg pmem2_errormsgW -#define pmem2_perror pmem2_perrorW -#else -#define pmem2_source_device_id pmem2_source_device_idU -#define pmem2_errormsg pmem2_errormsgU -#define pmem2_perror pmem2_perrorU -#endif - -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define PMEM2_E_UNKNOWN (-100000) -#define PMEM2_E_NOSUPP (-100001) -#define PMEM2_E_FILE_HANDLE_NOT_SET (-100003) -#define PMEM2_E_INVALID_FILE_HANDLE (-100004) -#define PMEM2_E_INVALID_FILE_TYPE (-100005) -#define PMEM2_E_MAP_RANGE (-100006) -#define PMEM2_E_MAPPING_EXISTS (-100007) -#define PMEM2_E_GRANULARITY_NOT_SET (-100008) -#define PMEM2_E_GRANULARITY_NOT_SUPPORTED (-100009) -#define PMEM2_E_OFFSET_OUT_OF_RANGE (-100010) -#define PMEM2_E_OFFSET_UNALIGNED (-100011) -#define PMEM2_E_INVALID_ALIGNMENT_FORMAT (-100012) -#define PMEM2_E_INVALID_ALIGNMENT_VALUE (-100013) -#define PMEM2_E_INVALID_SIZE_FORMAT (-100014) -#define PMEM2_E_LENGTH_UNALIGNED (-100015) -#define PMEM2_E_MAPPING_NOT_FOUND (-100016) -#define PMEM2_E_BUFFER_TOO_SMALL (-100017) -#define PMEM2_E_SOURCE_EMPTY (-100018) -#define PMEM2_E_INVALID_SHARING_VALUE (-100019) -#define PMEM2_E_SRC_DEVDAX_PRIVATE (-100020) -#define PMEM2_E_INVALID_ADDRESS_REQUEST_TYPE (-100021) -#define PMEM2_E_ADDRESS_UNALIGNED (-100022) -#define PMEM2_E_ADDRESS_NULL (-100023) -#define PMEM2_E_DEEP_FLUSH_RANGE (-100024) -#define PMEM2_E_INVALID_REGION_FORMAT (-100025) -#define PMEM2_E_DAX_REGION_NOT_FOUND (-100026) -#define PMEM2_E_INVALID_DEV_FORMAT (-100027) -#define PMEM2_E_CANNOT_READ_BOUNDS (-100028) -#define PMEM2_E_NO_BAD_BLOCK_FOUND (-100029) -#define PMEM2_E_LENGTH_OUT_OF_RANGE (-100030) -#define PMEM2_E_INVALID_PROT_FLAG (-100031) -#define PMEM2_E_NO_ACCESS (-100032) -#define PMEM2_E_VM_RESERVATION_NOT_EMPTY (-100033) -#define PMEM2_E_MAP_EXISTS (-100034) -#define PMEM2_E_FILE_DESCRIPTOR_NOT_SET (-100035) -#define PMEM2_E_SOURCE_TYPE_NOT_SUPPORTED (-100036) -#define PMEM2_E_IO_FAIL (-100037) - -/* source setup */ - -struct pmem2_source; - -int pmem2_source_from_fd(struct pmem2_source **src, int fd); -int pmem2_source_from_anon(struct pmem2_source **src, size_t size); -#ifdef _WIN32 -int pmem2_source_from_handle(struct pmem2_source **src, HANDLE handle); -int pmem2_source_get_handle(const struct pmem2_source *src, HANDLE *h); -#else -int pmem2_source_get_fd(const struct pmem2_source *src, int *fd); -#endif - -int pmem2_source_size(const struct pmem2_source *src, size_t *size); - -int pmem2_source_alignment(const struct pmem2_source *src, - size_t *alignment); - -int pmem2_source_delete(struct pmem2_source **src); - -int pmem2_source_pread_mcsafe(struct pmem2_source *src, void *buf, size_t size, - size_t offset); - -int pmem2_source_pwrite_mcsafe(struct pmem2_source *src, void *buf, size_t size, - size_t offset); - -/* vm reservation setup */ - -struct pmem2_map; -struct pmem2_vm_reservation; - -void *pmem2_vm_reservation_get_address(struct pmem2_vm_reservation *rsv); - -size_t pmem2_vm_reservation_get_size(struct pmem2_vm_reservation *rsv); - -int pmem2_vm_reservation_new(struct pmem2_vm_reservation **rsv_ptr, - void *addr, size_t size); - -int pmem2_vm_reservation_delete(struct pmem2_vm_reservation **rsv_ptr); - -int pmem2_vm_reservation_extend(struct pmem2_vm_reservation *rsv, size_t size); - -int pmem2_vm_reservation_shrink(struct pmem2_vm_reservation *rsv, size_t offset, - size_t size); - -int pmem2_vm_reservation_map_find(struct pmem2_vm_reservation *rsv, - size_t reserv_offset, size_t len, struct pmem2_map **map); - -int pmem2_vm_reservation_map_find_prev(struct pmem2_vm_reservation *rsv, - struct pmem2_map *map, struct pmem2_map **prev_map); - -int pmem2_vm_reservation_map_find_next(struct pmem2_vm_reservation *rsv, - struct pmem2_map *map, struct pmem2_map **next_map); - -int pmem2_vm_reservation_map_find_first(struct pmem2_vm_reservation *rsv, - struct pmem2_map **map); - -int pmem2_vm_reservation_map_find_last(struct pmem2_vm_reservation *rsv, - struct pmem2_map **map); - -/* config setup */ - -struct pmem2_config; - -int pmem2_config_new(struct pmem2_config **cfg); - -int pmem2_config_delete(struct pmem2_config **cfg); - -enum pmem2_granularity { - PMEM2_GRANULARITY_BYTE, - PMEM2_GRANULARITY_CACHE_LINE, - PMEM2_GRANULARITY_PAGE, -}; - -int pmem2_config_set_required_store_granularity(struct pmem2_config *cfg, - enum pmem2_granularity g); - -int pmem2_config_set_offset(struct pmem2_config *cfg, size_t offset); - -int pmem2_config_set_length(struct pmem2_config *cfg, size_t length); - -enum pmem2_sharing_type { - PMEM2_SHARED, - PMEM2_PRIVATE, -}; - -int pmem2_config_set_sharing(struct pmem2_config *cfg, - enum pmem2_sharing_type type); - -#define PMEM2_PROT_EXEC (1U << 29) -#define PMEM2_PROT_READ (1U << 30) -#define PMEM2_PROT_WRITE (1U << 31) -#define PMEM2_PROT_NONE 0 - -int pmem2_config_set_protection(struct pmem2_config *cfg, - unsigned prot); - -int pmem2_config_set_vm_reservation(struct pmem2_config *cfg, - struct pmem2_vm_reservation *rsv, size_t offset); - -/* mapping */ -struct pmem2_map; -int pmem2_map_from_existing(struct pmem2_map **map, - const struct pmem2_source *src, void *addr, size_t len, - enum pmem2_granularity gran); - -int pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, - const struct pmem2_source *src); - -int pmem2_map_delete(struct pmem2_map **map_ptr); - -void *pmem2_map_get_address(struct pmem2_map *map); - -size_t pmem2_map_get_size(struct pmem2_map *map); - -enum pmem2_granularity pmem2_map_get_store_granularity(struct pmem2_map *map); - -/* flushing */ - -typedef void (*pmem2_persist_fn)(const void *ptr, size_t size); - -typedef void (*pmem2_flush_fn)(const void *ptr, size_t size); - -typedef void (*pmem2_drain_fn)(void); - -pmem2_persist_fn pmem2_get_persist_fn(struct pmem2_map *map); - -pmem2_flush_fn pmem2_get_flush_fn(struct pmem2_map *map); - -pmem2_drain_fn pmem2_get_drain_fn(struct pmem2_map *map); - -#define PMEM2_F_MEM_NODRAIN (1U << 0) - -#define PMEM2_F_MEM_NONTEMPORAL (1U << 1) -#define PMEM2_F_MEM_TEMPORAL (1U << 2) - -#define PMEM2_F_MEM_WC (1U << 3) -#define PMEM2_F_MEM_WB (1U << 4) - -#define PMEM2_F_MEM_NOFLUSH (1U << 5) - -#define PMEM2_F_MEM_VALID_FLAGS (PMEM2_F_MEM_NODRAIN | \ - PMEM2_F_MEM_NONTEMPORAL | \ - PMEM2_F_MEM_TEMPORAL | \ - PMEM2_F_MEM_WC | \ - PMEM2_F_MEM_WB | \ - PMEM2_F_MEM_NOFLUSH) - -typedef void *(*pmem2_memmove_fn)(void *pmemdest, const void *src, size_t len, - unsigned flags); - -typedef void *(*pmem2_memcpy_fn)(void *pmemdest, const void *src, size_t len, - unsigned flags); - -typedef void *(*pmem2_memset_fn)(void *pmemdest, int c, size_t len, - unsigned flags); - -pmem2_memmove_fn pmem2_get_memmove_fn(struct pmem2_map *map); - -pmem2_memcpy_fn pmem2_get_memcpy_fn(struct pmem2_map *map); - -pmem2_memset_fn pmem2_get_memset_fn(struct pmem2_map *map); - -/* RAS */ - -int pmem2_deep_flush(struct pmem2_map *map, void *ptr, size_t size); - -#ifndef _WIN32 -int pmem2_source_device_id(const struct pmem2_source *src, - char *id, size_t *len); -#else -int pmem2_source_device_idW(const struct pmem2_source *src, - wchar_t *id, size_t *len); - -int pmem2_source_device_idU(const struct pmem2_source *src, - char *id, size_t *len); -#endif - -int pmem2_source_device_usc(const struct pmem2_source *src, uint64_t *usc); - -int pmem2_source_numa_node(const struct pmem2_source *src, int *numa_node); - -struct pmem2_badblock_context; - -struct pmem2_badblock { - size_t offset; - size_t length; -}; - -int pmem2_badblock_context_new(struct pmem2_badblock_context **bbctx, - const struct pmem2_source *src); - -int pmem2_badblock_next(struct pmem2_badblock_context *bbctx, - struct pmem2_badblock *bb); - -void pmem2_badblock_context_delete( - struct pmem2_badblock_context **bbctx); - -int pmem2_badblock_clear(struct pmem2_badblock_context *bbctx, - const struct pmem2_badblock *bb); - -#ifdef PMEM2_USE_MINIASYNC -int pmem2_config_set_vdm(struct pmem2_config *cfg, struct vdm *vdm); - -struct vdm_operation_future pmem2_memcpy_async(struct pmem2_map *map, - void *pmemdest, const void *src, size_t len, unsigned flags); - -struct vdm_operation_future pmem2_memmove_async(struct pmem2_map *map, - void *pmemdest, const void *src, size_t len, unsigned flags); - -struct vdm_operation_future pmem2_memset_async(struct pmem2_map *map, - void *str, int c, size_t n, unsigned flags); -#endif - -/* error handling */ - -#ifndef _WIN32 -const char *pmem2_errormsg(void); -#else -const char *pmem2_errormsgU(void); - -const wchar_t *pmem2_errormsgW(void); -#endif - -int pmem2_err_to_errno(int); - -#ifndef _WIN32 -void pmem2_perror(const char *format, - ...) __attribute__((__format__(__printf__, 1, 2))); -#else -void pmem2_perrorU(const char *format, ...); - -void pmem2_perrorW(const wchar_t *format, ...); -#endif - -#ifdef __cplusplus -} -#endif #endif /* libpmem2.h */ diff --git a/src/include/libpmem2/async.h b/src/include/libpmem2/async.h new file mode 100644 index 0000000000000000000000000000000000000000..4ef4d8ab81ea83acb6e88df4cac81e0ac7e762a9 --- /dev/null +++ b/src/include/libpmem2/async.h @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2022, Intel Corporation */ + +/* + * libpmem2/async.h -- definitions of libpmem2 functions and structs for + * asynchronous operations + * + * See libpmem2_async(7) for details. + */ + +#ifndef LIBPMEM2_ASYNC +#define LIBPMEM2_ASYNC 1 + +#include <libpmem2/base.h> +#include <libminiasync/vdm.h> + +#ifdef __cplusplus +extern "C" { +#endif + +int pmem2_config_set_vdm(struct pmem2_config *cfg, struct vdm *vdm); + +/* + * Structures needed for persist future + */ +struct pmem2_persist_future_data { + struct pmem2_map *map; + void *ptr; + size_t size; +}; + +struct pmem2_persist_future_output { + /* + * Windows C compiler does not accept empty structs + */ + uint64_t unused; +}; + +/* + * Declaration of pmem2_persist_future struct + */ +FUTURE(pmem2_persist_future, + struct pmem2_persist_future_data, + struct pmem2_persist_future_output); + +/* + * Implementation of persist future, called upon future_poll + */ +static inline enum future_state +pmem2_persist_future_impl(struct future_context *ctx, + struct future_notifier *notifier) +{ + if (notifier) notifier->notifier_used = FUTURE_NOTIFIER_NONE; + + struct pmem2_persist_future_data *data = + future_context_get_data(ctx); + pmem2_persist_fn persist = + pmem2_get_persist_fn(data->map); + persist(data->ptr, data->size); + return FUTURE_STATE_COMPLETE; +} + +/* + * Union containing all possible futures called after vdm operation future + * in pmem2_future + */ +union pmem2_finalize_future { + struct pmem2_persist_future persist; + struct { char data[64]; } pad; +}; + +/* + * Returns a future for persisting data + */ +static inline union pmem2_finalize_future +pmem2_persist_future(struct pmem2_map *map, void *ptr, size_t size) +{ + union pmem2_finalize_future future; + future.persist.data.map = map; + future.persist.data.ptr = ptr; + future.persist.data.size = size; + + FUTURE_INIT(&future.persist, pmem2_persist_future_impl); + + return future; +} + +/* + * Data for chain pmem2_future which contains vdm operation + * future and future for finalizing the operation for e.g. persisting data. + */ +struct pmem2_future_data { + FUTURE_CHAIN_ENTRY(struct vdm_operation_future, op); + FUTURE_CHAIN_ENTRY_LAST(union pmem2_finalize_future, fin); +}; + +struct pmem2_future_output { + void *dest; +}; + +/* + * Declaration of struct pmem2_future + */ +FUTURE(pmem2_future, struct pmem2_future_data, + struct pmem2_future_output); + +struct pmem2_future pmem2_memcpy_async(struct pmem2_map *map, + void *pmemdest, const void *src, size_t len, unsigned flags); + +struct pmem2_future pmem2_memmove_async(struct pmem2_map *map, + void *pmemdest, const void *src, size_t len, unsigned flags); + +struct pmem2_future pmem2_memset_async(struct pmem2_map *map, + void *str, int c, size_t n, unsigned flags); + +#ifdef __cplusplus +} +#endif + +#endif /* libpmem2/async.h */ diff --git a/src/include/libpmem2/base.h b/src/include/libpmem2/base.h new file mode 100644 index 0000000000000000000000000000000000000000..4e13f01151e1c64dc6dcf0abbd21146f991c991a --- /dev/null +++ b/src/include/libpmem2/base.h @@ -0,0 +1,301 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2019-2022, Intel Corporation */ + +/* + * libpmem2.h -- definitions of libpmem2 entry points + * + * This library provides support for programming with persistent memory (pmem). + * + * libpmem2 provides support for using raw pmem directly. + * + * See libpmem2(7) for details. + */ + +#ifndef LIBPMEM2_BASE_H +#define LIBPMEM2_BASE_H 1 + +#include <stddef.h> +#include <stdint.h> +#ifdef _WIN32 +#include <pmemcompat.h> + +#ifndef PMDK_UTF8_API +#define pmem2_source_device_id pmem2_source_device_idW +#define pmem2_errormsg pmem2_errormsgW +#define pmem2_perror pmem2_perrorW +#else +#define pmem2_source_device_id pmem2_source_device_idU +#define pmem2_errormsg pmem2_errormsgU +#define pmem2_perror pmem2_perrorU +#endif + +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define PMEM2_E_UNKNOWN (-100000) +#define PMEM2_E_NOSUPP (-100001) +#define PMEM2_E_FILE_HANDLE_NOT_SET (-100003) +#define PMEM2_E_INVALID_FILE_HANDLE (-100004) +#define PMEM2_E_INVALID_FILE_TYPE (-100005) +#define PMEM2_E_MAP_RANGE (-100006) +#define PMEM2_E_MAPPING_EXISTS (-100007) +#define PMEM2_E_GRANULARITY_NOT_SET (-100008) +#define PMEM2_E_GRANULARITY_NOT_SUPPORTED (-100009) +#define PMEM2_E_OFFSET_OUT_OF_RANGE (-100010) +#define PMEM2_E_OFFSET_UNALIGNED (-100011) +#define PMEM2_E_INVALID_ALIGNMENT_FORMAT (-100012) +#define PMEM2_E_INVALID_ALIGNMENT_VALUE (-100013) +#define PMEM2_E_INVALID_SIZE_FORMAT (-100014) +#define PMEM2_E_LENGTH_UNALIGNED (-100015) +#define PMEM2_E_MAPPING_NOT_FOUND (-100016) +#define PMEM2_E_BUFFER_TOO_SMALL (-100017) +#define PMEM2_E_SOURCE_EMPTY (-100018) +#define PMEM2_E_INVALID_SHARING_VALUE (-100019) +#define PMEM2_E_SRC_DEVDAX_PRIVATE (-100020) +#define PMEM2_E_INVALID_ADDRESS_REQUEST_TYPE (-100021) +#define PMEM2_E_ADDRESS_UNALIGNED (-100022) +#define PMEM2_E_ADDRESS_NULL (-100023) +#define PMEM2_E_DEEP_FLUSH_RANGE (-100024) +#define PMEM2_E_INVALID_REGION_FORMAT (-100025) +#define PMEM2_E_DAX_REGION_NOT_FOUND (-100026) +#define PMEM2_E_INVALID_DEV_FORMAT (-100027) +#define PMEM2_E_CANNOT_READ_BOUNDS (-100028) +#define PMEM2_E_NO_BAD_BLOCK_FOUND (-100029) +#define PMEM2_E_LENGTH_OUT_OF_RANGE (-100030) +#define PMEM2_E_INVALID_PROT_FLAG (-100031) +#define PMEM2_E_NO_ACCESS (-100032) +#define PMEM2_E_VM_RESERVATION_NOT_EMPTY (-100033) +#define PMEM2_E_MAP_EXISTS (-100034) +#define PMEM2_E_FILE_DESCRIPTOR_NOT_SET (-100035) +#define PMEM2_E_SOURCE_TYPE_NOT_SUPPORTED (-100036) +#define PMEM2_E_IO_FAIL (-100037) + +/* source setup */ + +struct pmem2_source; + +int pmem2_source_from_fd(struct pmem2_source **src, int fd); +int pmem2_source_from_anon(struct pmem2_source **src, size_t size); +#ifdef _WIN32 +int pmem2_source_from_handle(struct pmem2_source **src, HANDLE handle); +int pmem2_source_get_handle(const struct pmem2_source *src, HANDLE *h); +#else +int pmem2_source_get_fd(const struct pmem2_source *src, int *fd); +#endif + +int pmem2_source_size(const struct pmem2_source *src, size_t *size); + +int pmem2_source_alignment(const struct pmem2_source *src, + size_t *alignment); + +int pmem2_source_delete(struct pmem2_source **src); + +int pmem2_source_pread_mcsafe(struct pmem2_source *src, void *buf, size_t size, + size_t offset); + +int pmem2_source_pwrite_mcsafe(struct pmem2_source *src, void *buf, size_t size, + size_t offset); + +/* vm reservation setup */ + +struct pmem2_map; +struct pmem2_vm_reservation; + +void *pmem2_vm_reservation_get_address(struct pmem2_vm_reservation *rsv); + +size_t pmem2_vm_reservation_get_size(struct pmem2_vm_reservation *rsv); + +int pmem2_vm_reservation_new(struct pmem2_vm_reservation **rsv_ptr, + void *addr, size_t size); + +int pmem2_vm_reservation_delete(struct pmem2_vm_reservation **rsv_ptr); + +int pmem2_vm_reservation_extend(struct pmem2_vm_reservation *rsv, size_t size); + +int pmem2_vm_reservation_shrink(struct pmem2_vm_reservation *rsv, size_t offset, + size_t size); + +int pmem2_vm_reservation_map_find(struct pmem2_vm_reservation *rsv, + size_t reserv_offset, size_t len, struct pmem2_map **map); + +int pmem2_vm_reservation_map_find_prev(struct pmem2_vm_reservation *rsv, + struct pmem2_map *map, struct pmem2_map **prev_map); + +int pmem2_vm_reservation_map_find_next(struct pmem2_vm_reservation *rsv, + struct pmem2_map *map, struct pmem2_map **next_map); + +int pmem2_vm_reservation_map_find_first(struct pmem2_vm_reservation *rsv, + struct pmem2_map **map); + +int pmem2_vm_reservation_map_find_last(struct pmem2_vm_reservation *rsv, + struct pmem2_map **map); + +/* config setup */ + +struct pmem2_config; + +int pmem2_config_new(struct pmem2_config **cfg); + +int pmem2_config_delete(struct pmem2_config **cfg); + +enum pmem2_granularity { + PMEM2_GRANULARITY_BYTE, + PMEM2_GRANULARITY_CACHE_LINE, + PMEM2_GRANULARITY_PAGE, +}; + +int pmem2_config_set_required_store_granularity(struct pmem2_config *cfg, + enum pmem2_granularity g); + +int pmem2_config_set_offset(struct pmem2_config *cfg, size_t offset); + +int pmem2_config_set_length(struct pmem2_config *cfg, size_t length); + +enum pmem2_sharing_type { + PMEM2_SHARED, + PMEM2_PRIVATE, +}; + +int pmem2_config_set_sharing(struct pmem2_config *cfg, + enum pmem2_sharing_type type); + +#define PMEM2_PROT_EXEC (1U << 29) +#define PMEM2_PROT_READ (1U << 30) +#define PMEM2_PROT_WRITE (1U << 31) +#define PMEM2_PROT_NONE 0 + +int pmem2_config_set_protection(struct pmem2_config *cfg, + unsigned prot); + +int pmem2_config_set_vm_reservation(struct pmem2_config *cfg, + struct pmem2_vm_reservation *rsv, size_t offset); + +/* mapping */ +struct pmem2_map; +int pmem2_map_from_existing(struct pmem2_map **map, + const struct pmem2_source *src, void *addr, size_t len, + enum pmem2_granularity gran); + +int pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, + const struct pmem2_source *src); + +int pmem2_map_delete(struct pmem2_map **map_ptr); + +void *pmem2_map_get_address(struct pmem2_map *map); + +size_t pmem2_map_get_size(struct pmem2_map *map); + +enum pmem2_granularity pmem2_map_get_store_granularity(struct pmem2_map *map); + +/* flushing */ + +typedef void (*pmem2_persist_fn)(const void *ptr, size_t size); + +typedef void (*pmem2_flush_fn)(const void *ptr, size_t size); + +typedef void (*pmem2_drain_fn)(void); + +pmem2_persist_fn pmem2_get_persist_fn(struct pmem2_map *map); + +pmem2_flush_fn pmem2_get_flush_fn(struct pmem2_map *map); + +pmem2_drain_fn pmem2_get_drain_fn(struct pmem2_map *map); + +#define PMEM2_F_MEM_NODRAIN (1U << 0) + +#define PMEM2_F_MEM_NONTEMPORAL (1U << 1) +#define PMEM2_F_MEM_TEMPORAL (1U << 2) + +#define PMEM2_F_MEM_WC (1U << 3) +#define PMEM2_F_MEM_WB (1U << 4) + +#define PMEM2_F_MEM_NOFLUSH (1U << 5) + +#define PMEM2_F_MEM_VALID_FLAGS (PMEM2_F_MEM_NODRAIN | \ + PMEM2_F_MEM_NONTEMPORAL | \ + PMEM2_F_MEM_TEMPORAL | \ + PMEM2_F_MEM_WC | \ + PMEM2_F_MEM_WB | \ + PMEM2_F_MEM_NOFLUSH) + +typedef void *(*pmem2_memmove_fn)(void *pmemdest, const void *src, size_t len, + unsigned flags); + +typedef void *(*pmem2_memcpy_fn)(void *pmemdest, const void *src, size_t len, + unsigned flags); + +typedef void *(*pmem2_memset_fn)(void *pmemdest, int c, size_t len, + unsigned flags); + +pmem2_memmove_fn pmem2_get_memmove_fn(struct pmem2_map *map); + +pmem2_memcpy_fn pmem2_get_memcpy_fn(struct pmem2_map *map); + +pmem2_memset_fn pmem2_get_memset_fn(struct pmem2_map *map); + +/* RAS */ + +int pmem2_deep_flush(struct pmem2_map *map, void *ptr, size_t size); + +#ifndef _WIN32 +int pmem2_source_device_id(const struct pmem2_source *src, + char *id, size_t *len); +#else +int pmem2_source_device_idW(const struct pmem2_source *src, + wchar_t *id, size_t *len); + +int pmem2_source_device_idU(const struct pmem2_source *src, + char *id, size_t *len); +#endif + +int pmem2_source_device_usc(const struct pmem2_source *src, uint64_t *usc); + +int pmem2_source_numa_node(const struct pmem2_source *src, int *numa_node); + +struct pmem2_badblock_context; + +struct pmem2_badblock { + size_t offset; + size_t length; +}; + +int pmem2_badblock_context_new(struct pmem2_badblock_context **bbctx, + const struct pmem2_source *src); + +int pmem2_badblock_next(struct pmem2_badblock_context *bbctx, + struct pmem2_badblock *bb); + +void pmem2_badblock_context_delete( + struct pmem2_badblock_context **bbctx); + +int pmem2_badblock_clear(struct pmem2_badblock_context *bbctx, + const struct pmem2_badblock *bb); + +/* error handling */ + +#ifndef _WIN32 +const char *pmem2_errormsg(void); +#else +const char *pmem2_errormsgU(void); + +const wchar_t *pmem2_errormsgW(void); +#endif + +int pmem2_err_to_errno(int); + +#ifndef _WIN32 +void pmem2_perror(const char *format, + ...) __attribute__((__format__(__printf__, 1, 2))); +#else +void pmem2_perrorU(const char *format, ...); + +void pmem2_perrorW(const wchar_t *format, ...); +#endif + +#ifdef __cplusplus +} +#endif +#endif /* libpmem2/base.h */ diff --git a/src/libpmem2/libpmem2.vcxproj b/src/libpmem2/libpmem2.vcxproj index 12fa556df42d25ca970ad0c80a0ade62eae45c24..6e0ffdde88dc0a10f27a09678583c89e417f58dc 100644 --- a/src/libpmem2/libpmem2.vcxproj +++ b/src/libpmem2/libpmem2.vcxproj @@ -69,6 +69,8 @@ <ItemGroup> <ClInclude Include="..\include\libpmem2.h" /> <ClInclude Include="..\core\os_thread.h" /> + <ClInclude Include="..\include\libpmem2\async.h" /> + <ClInclude Include="..\include\libpmem2\base.h" /> <ClInclude Include="auto_flush.h" /> <ClInclude Include="auto_flush_windows.h" /> <ClInclude Include="deep_flush.h" /> @@ -143,7 +145,11 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(solutionDir)deps\miniasync\src\include;x86_64\</IncludePath> </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PreprocessorDefinitions>PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS4;_CRT_SECURE_NO_WARNINGS;_WINDLL;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/src/libpmem2/libpmem2.vcxproj.filters b/src/libpmem2/libpmem2.vcxproj.filters index d8f7c1c76bf038eab963497a59f02203cafb7cc1..fc575635197c638408c96fae15a74e43d1e89635 100644 --- a/src/libpmem2/libpmem2.vcxproj.filters +++ b/src/libpmem2/libpmem2.vcxproj.filters @@ -230,6 +230,12 @@ <ClInclude Include="mover.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\include\libpmem2\async.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\include\libpmem2\base.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="libpmem2.def"> diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index b487655bab7c6e6dedc7840bc04acc95e6c96302..75d50fed8a999085ac9aa0a4ebe561fe43c1e20a 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -516,9 +516,10 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, if (vdm == NULL) { /* - * user did not provided custom vdm, + * user did not provide custom vdm, * so we have to use the fallback one. */ + LOG(3, "using libpmem2 default async mover"); ret = mover_new(map, &vdm); if (ret) goto err_free_map_struct; diff --git a/src/libpmem2/mover.c b/src/libpmem2/mover.c index 5a7157d0582abcde3e07aa667cff313e1e5e9025..a974970d2425c3e241dba7da3dfb57e13eb99be1 100644 --- a/src/libpmem2/mover.c +++ b/src/libpmem2/mover.c @@ -16,6 +16,8 @@ #include <stdlib.h> #include <unistd.h> +#define SUPPORTED_FLAGS VDM_F_MEM_DURABLE + struct data_mover { struct vdm base; /* must be first */ struct pmem2_map *map; @@ -28,8 +30,8 @@ struct data_mover_op { }; /* - * sync_operation_check -- always returns COMPLETE because sync mover operations - * are complete immediately after starting. + * sync_operation_check -- always returns COMPLETE because sync mover + * operations are complete immediately after starting. */ static enum future_state sync_operation_check(void *data, const struct vdm_operation *operation) @@ -41,7 +43,7 @@ sync_operation_check(void *data, const struct vdm_operation *operation) int complete; util_atomic_load_explicit32(&sync_op->complete, &complete, - memory_order_acquire); + memory_order_acquire); return complete ? FUTURE_STATE_COMPLETE : FUTURE_STATE_IDLE; } @@ -73,7 +75,7 @@ sync_operation_new(struct vdm *vdm, const enum vdm_operation_type type) */ static void sync_operation_delete(void *data, const struct vdm_operation *operation, - struct vdm_operation_output *output) + struct vdm_operation_output *output) { output->result = VDM_SUCCESS; @@ -103,7 +105,7 @@ sync_operation_delete(void *data, const struct vdm_operation *operation, */ static int sync_operation_start(void *data, const struct vdm_operation *operation, - struct future_notifier *n) + struct future_notifier *n) { LOG(3, "data %p op %p, notifier %p", data, operation, n); struct data_mover_op *sync_data = (struct data_mover_op *)data; @@ -146,7 +148,7 @@ sync_operation_start(void *data, const struct vdm_operation *operation, FATAL("unsupported operation type"); } util_atomic_store_explicit32(&sync_data->complete, 1, - memory_order_release); + memory_order_release); return 0; } @@ -156,6 +158,7 @@ static struct vdm data_mover_vdm = { .op_delete = sync_operation_delete, .op_check = sync_operation_check, .op_start = sync_operation_start, + .capabilities = SUPPORTED_FLAGS, }; /* @@ -182,7 +185,7 @@ mover_new(struct pmem2_map *map, struct vdm **vdm) return 0; -membuf_failed: + membuf_failed: free(dms); return ret; } @@ -197,41 +200,101 @@ mover_delete(struct vdm *dms) free((struct data_mover *)dms); } +/* + * Attach pmem2_future_persist into pmem2_future if required by + * characteristics of mapping and vdm + */ +static void +pmem2_future_attach_persist(struct pmem2_map *map, struct pmem2_future *future, + void *pmemdest, size_t len) { + struct future_chain_entry *operation_entry = + (struct future_chain_entry *)(&future->data.op); + enum pmem2_granularity gran = + pmem2_map_get_store_granularity(map); + bool pmem_support = vdm_is_supported(map->vdm, VDM_F_MEM_DURABLE); + + if (gran != PMEM2_GRANULARITY_BYTE && !pmem_support) { + /* + * The engine does not support PMEM, and we do not have eADR, + * so we have to assure that the copied data is moved into + * a persistent domain properly before the pmem2_future + * is complete + */ + FUTURE_CHAIN_ENTRY_INIT(&future->data.fin, + pmem2_persist_future(map, pmemdest, len), + NULL, NULL); + } else { + /* + * The engine supports PMEM, or we have eADR, so persistence + * of the data is handled by these features. + */ + operation_entry->flags |= + FUTURE_CHAIN_FLAG_ENTRY_LAST; + } +} + /* * pmem2_memcpy_async -- returns a memcpy future */ -struct vdm_operation_future +struct pmem2_future pmem2_memcpy_async(struct pmem2_map *map, void *pmemdest, const void *src, - size_t len, unsigned flags) + size_t len, unsigned flags) { LOG(3, "map %p, pmemdest %p, src %p, len %" PRIu64 ", flags %u", map, pmemdest, src, len, flags); SUPPRESS_UNUSED(flags); - return vdm_memcpy(map->vdm, pmemdest, (void *)src, len, 0); + + struct pmem2_future future; + FUTURE_CHAIN_ENTRY_INIT(&future.data.op, + vdm_memcpy(map->vdm, pmemdest, (void *)src, len, 0), + NULL, NULL); + + pmem2_future_attach_persist(map, &future, pmemdest, len); + + FUTURE_CHAIN_INIT(&future); + return future; } /* * pmem2_memove_async -- returns a memmove future */ -struct vdm_operation_future +struct pmem2_future pmem2_memmove_async(struct pmem2_map *map, void *pmemdest, const void *src, - size_t len, unsigned flags) + size_t len, unsigned flags) { LOG(3, "map %p, pmemdest %p, src %p, len %" PRIu64 ", flags %u", map, pmemdest, src, len, flags); SUPPRESS_UNUSED(flags); - return vdm_memmove(map->vdm, pmemdest, (void *)src, len, 0); + + struct pmem2_future future; + FUTURE_CHAIN_ENTRY_INIT(&future.data.op, + vdm_memmove(map->vdm, pmemdest, (void *)src, len, 0), + NULL, NULL); + + pmem2_future_attach_persist(map, &future, pmemdest, len); + + FUTURE_CHAIN_INIT(&future); + return future; } /* * pmem2_memset_async -- returns a memset future */ -struct vdm_operation_future +struct pmem2_future pmem2_memset_async(struct pmem2_map *map, void *pmemstr, int c, size_t n, - unsigned flags) + unsigned flags) { LOG(3, "map %p, pmemstr %p, c %d, len %" PRIu64 ", flags %u", map, pmemstr, c, n, flags); SUPPRESS_UNUSED(flags); - return vdm_memset(map->vdm, pmemstr, c, n, 0); + + struct pmem2_future future; + FUTURE_CHAIN_ENTRY_INIT(&future.data.op, + vdm_memset(map->vdm, pmemstr, c, n, 0), + NULL, NULL); + + pmem2_future_attach_persist(map, &future, pmemstr, n); + + FUTURE_CHAIN_INIT(&future); + return future; } diff --git a/src/test/Makefile b/src/test/Makefile index 3fb4b7b1bfba8fb1eb95b21a9c8c242f055f5426..4eebc21db6df14ecd9580371f44957165de8d83f 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -236,9 +236,10 @@ endif ifeq ($(OS_KERNEL_NAME),Linux) PMEM2_TESTS += pmem2_mover +PMEM2_TESTS += pmem2_future else $(info NOTE: Skipping tests because miniasync is not supported on this os.\ - Skipped tests: pmem2_mover) + Skipped tests: pmem2_mover, pmem2_future) endif PMEMPOOL_TESTS = \ diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index 90ffd5c3e2ebbfb1a6e34d8ef5e7c3f10b5ce906..8d60881eeab6e06a60741a0b637de54f96343b75 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -513,9 +513,9 @@ CFLAGS += $(LIBNDCTL_CFLAGS) LIBS += $(LIBNDCTL_LIBS) endif -ifeq ($(LINMINIASYNC),y) +ifeq ($(LIBMINIASYNC),y) LIBS += -lminiasync -# XXX: remover when we will swich to installed libminiasync +# XXX: remove when we will switch to installed libminiasync LIBS += -L$(TOP)/src/deps/miniasync/build/out endif diff --git a/src/test/pmem2_future/.gitignore b/src/test/pmem2_future/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d736f4c8f0e62c00fd9f1f8e842ede37a9dd14ad --- /dev/null +++ b/src/test/pmem2_future/.gitignore @@ -0,0 +1 @@ +pmem2_future diff --git a/src/test/pmem2_future/Makefile b/src/test/pmem2_future/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..18fe89178e33d23793778c4e6ea9d66a184210cc --- /dev/null +++ b/src/test/pmem2_future/Makefile @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2022, Intel Corporation +# + +# +# src/test/pmem2_future/Makefile -- build pmem2_future unit test +# +TOP = ../../.. + +vpath %.c $(TOP)/src/test/unittest + +TARGET = pmem2_future +OBJS = pmem2_future.o\ + ut_pmem2_utils.o\ + ut_pmem2_config.o\ + ut_pmem2_source.o\ + ut_pmem2_setup_integration.o + +LIBPMEM2=y +LIBMINIASYNC=y +include ../Makefile.inc diff --git a/src/test/pmem2_future/TESTS.py b/src/test/pmem2_future/TESTS.py new file mode 100755 index 0000000000000000000000000000000000000000..60b6a735878bf3d353870436064bee3ec1a869ba --- /dev/null +++ b/src/test/pmem2_future/TESTS.py @@ -0,0 +1,92 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2022, Intel Corporation +# +import sys +import testframework as t +import granularity as g +from consts import MINIASYNC_LIBDIR +import futils +import re + + +def check_match(matches, expected): + if len(matches) != len(expected): + return False + else: + for index in range(len(expected)): + if matches[index][0] != expected[index]: + return False + return True + + +@t.freebsd_exclude +@t.require_build('debug') +class PMEM2_FUTURE(t.Test): + test_type = t.Short + + def setup(self, ctx): + super().setup(ctx) + if sys.platform == 'win32': + env_dir = 'PATH' + pathh = ctx.env[env_dir] + ctx.env[env_dir] = pathh + ";" + MINIASYNC_LIBDIR + else: + env_dir = 'LD_LIBRARY_PATH' + pathh = ctx.env[env_dir] + ctx.env[env_dir] = pathh + ":" + MINIASYNC_LIBDIR + + def run(self, ctx): + file_path = ctx.create_holey_file(16 * t.MiB, 'testfile') + ctx.env['PMEM2_LOG_LEVEL'] = '15' + ctx.exec('pmem2_future', self.test_case, file_path, self.size) + + log_file = self.get_log_file_by_prefix("pmem2") + log_content = open(log_file).read() + + # We do not do any checks if the granularity is byte because + # in the case vdm instances do not have to call + # anything in order to persist the memory. + if isinstance(ctx.granularity, g.CacheLine): + regex = "((pmem2_drain)|(memory_barrier))" + matches = re.findall(regex, log_content) + expected = ["pmem2_drain", "memory_barrier"] + + # We expect matches of: + # [pmem2_drain, memory_barrier] because calling pmem2_memcpy_async + # should ensure persistence by calling pmem2_drain and + # memory_barrier after that. + if check_match(matches, expected) is not True: + futils.fail(F"Failed to find exact match to " + F"pmem2_drain+memory_barrier call!" + F"Got {matches} instead.") + elif isinstance(ctx.granularity, g.Page): + regex = "pmem2_log_flush" + matches = re.findall(regex, log_content) + + # We expect exactly one call of pmem2_log_flush which should + # be called by pmem2_memcpy_async + if len(matches) != 1: + futils.fail(F"Failed to find exactly one " + F"pmem2_log_flush call! " + F"Got {len(matches)} instead.") + + +class TEST0(PMEM2_FUTURE): + size = 64 + test_case = 'test_pmem2_future_mover' + + +class TEST1(PMEM2_FUTURE): + size = 4096 + test_case = 'test_pmem2_future_mover' + + +class TEST2(PMEM2_FUTURE): + size = 64 + test_case = 'test_pmem2_future_vdm' + + +class TEST3(PMEM2_FUTURE): + size = 4096 + test_case = 'test_pmem2_future_vdm' diff --git a/src/test/pmem2_future/pmem2_future.c b/src/test/pmem2_future/pmem2_future.c new file mode 100644 index 0000000000000000000000000000000000000000..392dfbc9ac72092d4b655a4214480c1e69f6158f --- /dev/null +++ b/src/test/pmem2_future/pmem2_future.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2022, Intel Corporation */ + +/* + * pmem2_future.c -- pmem2_future unittests + */ +#define PMEM2_USE_MINIASYNC 1 + +#include "libpmem2.h" +#include "out.h" +#include "unittest.h" +#include "ut_pmem2.h" +#include "ut_pmem2_setup_integration.h" +#include <libminiasync.h> + +/* + * map_valid -- return valid mapped pmem2_map + */ +static struct pmem2_map * +map_valid(struct pmem2_config *cfg, struct pmem2_source *src) +{ + struct pmem2_map *map = NULL; + int ret = pmem2_map_new(&map, cfg, src); + UT_PMEM2_EXPECT_RETURN(ret, 0); + UT_ASSERTne(map, NULL); + + return map; +} + +/* + * test_pmem2_future_mover - test if pmem2_*_async operations are properly + * moved into a persistent domain by the default libpmem2 mover + */ +static int +test_pmem2_future_mover(const struct test_case *tc, int argc, + char *argv[]) { + if (argc < 2) + UT_FATAL("usage: test_pmem2_future_mover <path> <size>"); + + char *file = argv[0]; + size_t test_len = ATOUL(argv[1]); + int fd = OPEN(file, O_RDWR); + + struct pmem2_source *src; + struct pmem2_config *cfg; + PMEM2_PREPARE_CONFIG_INTEGRATION(&cfg, &src, fd, + PMEM2_GRANULARITY_PAGE); + + struct pmem2_map *map = map_valid(cfg, src); + char *data = pmem2_map_get_address(map); + + /* + * We only test memcpy operation here, because all operations + * use the same mechanism for assuring data persistence + */ + struct pmem2_future cpy = + pmem2_memcpy_async(map, data, data + test_len, test_len, 0); + + FUTURE_BUSY_POLL(&cpy); + + if (memcmp(data, data + test_len, test_len)) + UT_FATAL("data should be equal"); + + pmem2_map_delete(&map); + pmem2_config_delete(&cfg); + pmem2_source_delete(&src); + CLOSE(fd); + return 2; +} + +/* + * test_pmem2_future_vdm - test if pmem2_*_async operations perform a call to + * pmem2_persist_fn if libpmem2 is using vdm specified by the user + */ +static int +test_pmem2_future_vdm(const struct test_case *tc, int argc, + char *argv[]) { + if (argc < 2) + UT_FATAL("usage: test_pmem2_future_vdm <path> <size>"); + + char *file = argv[0]; + size_t test_len = ATOUL(argv[1]); + int fd = OPEN(file, O_RDWR); + + struct pmem2_source *src; + struct pmem2_config *cfg; + PMEM2_PREPARE_CONFIG_INTEGRATION(&cfg, &src, fd, + PMEM2_GRANULARITY_PAGE); + + struct data_mover_sync *dms = data_mover_sync_new(); + UT_ASSERTne(dms, NULL); + struct vdm *vdm = data_mover_sync_get_vdm(dms); + UT_ASSERTne(vdm, NULL); + pmem2_config_set_vdm(cfg, vdm); + + struct pmem2_map *map = map_valid(cfg, src); + char *data = pmem2_map_get_address(map); + + struct pmem2_future cpy = + pmem2_memcpy_async(map, data, data + test_len, test_len, 0); + + FUTURE_BUSY_POLL(&cpy); + + if (memcmp(data, data + test_len, test_len)) + UT_FATAL("data should be equal"); + + pmem2_map_delete(&map); + pmem2_config_delete(&cfg); + pmem2_source_delete(&src); + CLOSE(fd); + return 2; +} + +/* + * test_cases -- available test cases + */ +static struct test_case test_cases[] = { + TEST_CASE(test_pmem2_future_mover), + TEST_CASE(test_pmem2_future_vdm), +}; + +#define NTESTS (sizeof(test_cases) / sizeof(test_cases[0])) + +int +main(int argc, char **argv) +{ + START(argc, argv, "pmem2_future"); + + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + + DONE(NULL); +} diff --git a/src/test/pmem2_future/pmem2_future.vcxproj b/src/test/pmem2_future/pmem2_future.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..705b0f4a71389013f7495aa9d517582b1141f40f --- /dev/null +++ b/src/test/pmem2_future/pmem2_future.vcxproj @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{B31866FF-6B5D-4CF9-819C-FBA86079FB19}</ProjectGuid> + <RootNamespace>pmem2_future</RootNamespace> + <WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\test_debug.props" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\test_release.props" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LibraryPath>$(solutionDir)deps\miniasync\build\src\Release;$(LibraryPath)</LibraryPath> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LibraryPath>$(solutionDir)deps\miniasync\build\src\Release;$(LibraryPath)</LibraryPath> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <AdditionalDependencies>miniasync.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalDependencies>miniasync.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="..\unittest\ut_pmem2_config.c" /> + <ClCompile Include="..\unittest\ut_pmem2_source.c" /> + <ClCompile Include="..\unittest\ut_pmem2_utils.c" /> + <ClCompile Include="..\unittest\ut_pmem2_setup_integration.c" /> + <ClCompile Include="pmem2_future.c" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\unittest\unittest.h" /> + <ClInclude Include="..\unittest\ut_pmem2.h" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\libpmem2\libpmem2.vcxproj"> + <Project>{f596c36c-5c96-4f08-b420-8908af500954}</Project> + </ProjectReference> + <ProjectReference Include="..\unittest\libut.vcxproj"> + <Project>{ce3f2dfb-8470-4802-ad37-21caf6cb2681}</Project> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <None Include="TESTS.py" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file diff --git a/src/test/pmem2_future/pmem2_future.vcxproj.filters b/src/test/pmem2_future/pmem2_future.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..66a50e8b24e53d53c9ddea1ca3d01d906c791e3b --- /dev/null +++ b/src/test/pmem2_future/pmem2_future.vcxproj.filters @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Test Scripts"> + <UniqueIdentifier>{4c1dd0a5-269b-43ca-aadb-69c54b295dc2}</UniqueIdentifier> + </Filter> + <Filter Include="Match Files"> + <UniqueIdentifier>{92f1ac35-e06e-4934-8606-adae8fb61b52}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\unittest\ut_pmem2_utils.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="pmem2_future.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\unittest\ut_pmem2_config.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\unittest\ut_pmem2_source.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\unittest\ut_pmem2_setup_integration.c"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\unittest\unittest.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\unittest\ut_pmem2.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <None Include="TESTS.py"> + <Filter>Test Scripts</Filter> + </None> + </ItemGroup> +</Project> \ No newline at end of file diff --git a/src/test/pmem2_granularity/pmem2_granularity.vcxproj b/src/test/pmem2_granularity/pmem2_granularity.vcxproj index 27a3974550f065e78f18a65664feb2ec4b936007..b68a706115c600d427eff80bf5c9d52b4af61e7c 100644 --- a/src/test/pmem2_granularity/pmem2_granularity.vcxproj +++ b/src/test/pmem2_granularity/pmem2_granularity.vcxproj @@ -51,7 +51,7 @@ <SDLCheck>true</SDLCheck> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <ForcedIncludeFiles>mocks_dax_windows.h;$(SolutionDir)\test\pmem_has_auto_flush_win\mocks_windows.h;%(ForcedIncludeFiles)</ForcedIncludeFiles> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -63,7 +63,7 @@ <SDLCheck>true</SDLCheck> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <ForcedIncludeFiles>mocks_dax_windows.h;$(SolutionDir)\test\pmem_has_auto_flush_win\mocks_windows.h;%(ForcedIncludeFiles)</ForcedIncludeFiles> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/src/test/pmem2_map/pmem2_map.vcxproj b/src/test/pmem2_map/pmem2_map.vcxproj index ee41737bee068f73d896e7e726201fcf7dc959bc..f08327146b5c461503e0140fb3f647dbe5d31147 100644 --- a/src/test/pmem2_map/pmem2_map.vcxproj +++ b/src/test/pmem2_map/pmem2_map.vcxproj @@ -49,7 +49,7 @@ <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <SDLCheck>true</SDLCheck> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> </ItemDefinitionGroup> @@ -61,7 +61,7 @@ <IntrinsicFunctions>true</IntrinsicFunctions> <SDLCheck>true</SDLCheck> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/src/test/pmem2_map_from_existing/pmem2_map_from_existing.vcxproj b/src/test/pmem2_map_from_existing/pmem2_map_from_existing.vcxproj index 5f5c042d94d851239ee4ae04b490397605f98395..22102e84d914ebd606711e2844508e079be49698 100644 --- a/src/test/pmem2_map_from_existing/pmem2_map_from_existing.vcxproj +++ b/src/test/pmem2_map_from_existing/pmem2_map_from_existing.vcxproj @@ -49,7 +49,7 @@ <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <SDLCheck>true</SDLCheck> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> </ItemDefinitionGroup> @@ -61,7 +61,7 @@ <IntrinsicFunctions>true</IntrinsicFunctions> <SDLCheck>true</SDLCheck> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/src/test/pmem2_map_prot/pmem2_map_prot.vcxproj b/src/test/pmem2_map_prot/pmem2_map_prot.vcxproj index 7c9a14a9a7b09c6de90aa0708f16bfd168b54d27..95ad13c0d65406a86b36951f1abd364ab97812a9 100644 --- a/src/test/pmem2_map_prot/pmem2_map_prot.vcxproj +++ b/src/test/pmem2_map_prot/pmem2_map_prot.vcxproj @@ -49,7 +49,7 @@ <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <SDLCheck>true</SDLCheck> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> </ItemDefinitionGroup> @@ -61,7 +61,7 @@ <IntrinsicFunctions>true</IntrinsicFunctions> <SDLCheck>true</SDLCheck> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/src/test/pmem2_mover/Makefile b/src/test/pmem2_mover/Makefile index 1aed2bcefff0c0ea33fdc0601797bbd986be409f..68bac9e2cbc9f29c0c797c78967cbf245d493c28 100644 --- a/src/test/pmem2_mover/Makefile +++ b/src/test/pmem2_mover/Makefile @@ -16,5 +16,5 @@ OBJS = pmem2_mover.o\ ut_pmem2_setup_integration.o LIBPMEM2=y -LINMINIASYNC=y +LIBMINIASYNC=y include ../Makefile.inc diff --git a/src/test/pmem2_mover/pmem2_mover.c b/src/test/pmem2_mover/pmem2_mover.c index 7602ab2c7db58c08aa6c34693ddbd8e88e53f35d..45d9deb6d1d46b6d25534c48f1b127d50d380e42 100644 --- a/src/test/pmem2_mover/pmem2_mover.c +++ b/src/test/pmem2_mover/pmem2_mover.c @@ -50,7 +50,7 @@ test_mover_memcpy_basic(const struct test_case *tc, int argc, char *argv[]) pmem2_memset_fn memset_fn = pmem2_get_memset_fn(map); memset_fn(data, 0xBA, 4096, 0); memset_fn(data + 4096, 0xAB, 4096, 0); - struct vdm_operation_future cpy = + struct pmem2_future cpy = pmem2_memcpy_async(map, data, data + 4096, 4096, 0); FUTURE_BUSY_POLL(&cpy); @@ -105,7 +105,7 @@ test_mover_memmove_basic(const struct test_case *tc, int argc, char *argv[]) * Create future to copy contents of first buffer into second buffer * which starts in the half of first buffer. */ - struct vdm_operation_future move = pmem2_memmove_async( + struct pmem2_future move = pmem2_memmove_async( map, data + string_size / 2, data, string_size, 0); FUTURE_BUSY_POLL(&move); @@ -154,7 +154,7 @@ test_mover_memset_basic(const struct test_case *tc, int argc, char *argv[]) /* * Create future to set every byte of the buffer to 5 */ - struct vdm_operation_future move = + struct pmem2_future move = pmem2_memset_async(map, data, 5, array_size, 0); FUTURE_BUSY_POLL(&move); @@ -200,7 +200,7 @@ thread_memcpy_worker(void *arg) for (int i = 0; i < WORKER_RUNS; i++) { unsigned *pattern = i % 2 ? pattern1 : pattern2; - struct vdm_operation_future cpy = pmem2_memcpy_async( + struct pmem2_future cpy = pmem2_memcpy_async( targ->map, targ->addr, pattern, TEST_SIZE, 0); FUTURE_BUSY_POLL(&cpy); @@ -287,7 +287,7 @@ thread_memove_worker(void *arg) for (int i = 0; i < WORKER_RUNS; i++) { unsigned *pattern = i % 2 ? pattern1 : pattern2; - struct vdm_operation_future move = pmem2_memmove_async( + struct pmem2_future move = pmem2_memmove_async( targ->map, targ->addr, pattern, TEST_SIZE, 0); FUTURE_BUSY_POLL(&move); @@ -377,7 +377,7 @@ thread_memset_worker(void *arg) : (int)(targ->thread_id + targ->threads); char *expected_result = i % 2 ? expected_result1 : expected_result2; - struct vdm_operation_future set = pmem2_memset_async( + struct pmem2_future set = pmem2_memset_async( targ->map, targ->addr, number, array_size, 0); FUTURE_BUSY_POLL(&set); @@ -470,7 +470,7 @@ test_miniasync_mover(const struct test_case *tc, int argc, char *argv[]) pmem2_memset_fn memset_fn = pmem2_get_memset_fn(map); memset_fn(data, 0xBA, 4096, 0); memset_fn(data + 4096, 0xAB, 4096, 0); - struct vdm_operation_future cpy = + struct pmem2_future cpy = pmem2_memcpy_async(map, data, data + 4096, 4096, 0); FUTURE_BUSY_POLL(&cpy); diff --git a/src/test/pmem2_source/pmem2_source.vcxproj b/src/test/pmem2_source/pmem2_source.vcxproj index 9cbc79c87e47d32a3b989764e4025dfe7a04f405..a9daf5aa35bba216f4e4904337ab0060e568a056 100644 --- a/src/test/pmem2_source/pmem2_source.vcxproj +++ b/src/test/pmem2_source/pmem2_source.vcxproj @@ -49,7 +49,7 @@ <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <SDLCheck>true</SDLCheck> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> </ItemDefinitionGroup> @@ -61,7 +61,7 @@ <IntrinsicFunctions>true</IntrinsicFunctions> <SDLCheck>true</SDLCheck> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/src/test/pmem2_vm_reservation/pmem2_vm_reservation.vcxproj b/src/test/pmem2_vm_reservation/pmem2_vm_reservation.vcxproj index 4bb81a2f26a5b36d913cc8243ec7db179e1b74b7..9a2940be09f3e4bd9b1f72510a79237624756fb4 100644 --- a/src/test/pmem2_vm_reservation/pmem2_vm_reservation.vcxproj +++ b/src/test/pmem2_vm_reservation/pmem2_vm_reservation.vcxproj @@ -49,7 +49,7 @@ <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <SDLCheck>true</SDLCheck> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> </ItemDefinitionGroup> @@ -61,7 +61,7 @@ <IntrinsicFunctions>true</IntrinsicFunctions> <SDLCheck>true</SDLCheck> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;SSE2_AVAILABLE=0;AVX_AVAILABLE=0;AVX512F_AVAILABLE=0;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/src/test/unicode_api/TEST0 b/src/test/unicode_api/TEST0 index 6d89cd9a02612493d7d30353f8fd60be6b946cef..67afaae225faeb047faef5eb76c527e5fc609e83 100755 --- a/src/test/unicode_api/TEST0 +++ b/src/test/unicode_api/TEST0 @@ -18,7 +18,6 @@ require_command clang SRC=../.. HEADERS_DIR=$SRC/include -INC_DIR=$SRC/include/libpmemobj EXC_PATT="set_funcs|strdup|rpmem" FAILED=0 DEF_COL=6 @@ -33,16 +32,15 @@ function pick_col { function check_file { local file=$1 - local dir=$2 - local h_dir=$3 - local pat=$4 + local h_dir=$2 + local pat=$3 local funcs=$(clang -Xclang -ast-dump -I$HEADERS_DIR $file -fno-color-diagnostics 2> /dev/null |\ grep "FunctionDecl.*pmem.*char \*" | cut -d " " -f $DEF_COL) for func in $funcs do local good=1 # Not starting at 0 allows set -e - to_check="$dir/*.h $h_dir/*.h" + to_check="$h_dir/*.h $h_dir/*/*.h" if [ -n "${pat:+x}" ] && [[ $func =~ $pat ]]; then continue fi @@ -64,7 +62,7 @@ pick_col for f in $HEADERS_DIR/*.h do - check_file $f $INC_DIR $HEADERS_DIR $EXC_PATT + check_file $f $HEADERS_DIR $EXC_PATT done if [ $FAILED -ne 0 ]; then diff --git a/src/test/util_sds/util_sds.vcxproj b/src/test/util_sds/util_sds.vcxproj index fbc7c85f14d6cc25654c69181b76e23046a9e0fc..0c0a9c23e0c3ff26e0f87831cce7dbba34c60eae 100644 --- a/src/test/util_sds/util_sds.vcxproj +++ b/src/test/util_sds/util_sds.vcxproj @@ -50,6 +50,7 @@ <Optimization>Disabled</Optimization> <ForcedIncludeFiles>mocks_windows.h;%(ForcedIncludeFiles)</ForcedIncludeFiles> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2\x86_64;$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS4;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> <Link /> </ItemDefinitionGroup> @@ -59,6 +60,7 @@ <ClCompile> <ForcedIncludeFiles>mocks_windows.h;%(ForcedIncludeFiles)</ForcedIncludeFiles> <AdditionalIncludeDirectories>$(SolutionDir)\libpmem2\x86_64;$(SolutionDir)\libpmem2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS4;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> </ItemDefinitionGroup> <ItemGroup> diff --git a/src/windows/libs_debug.props b/src/windows/libs_debug.props index 1f1704fbf501962d8fd1250b455ecf46819162b4..a9eb9ee5be8128fe5b334a0e3744af71adbc5cc8 100644 --- a/src/windows/libs_debug.props +++ b/src/windows/libs_debug.props @@ -10,7 +10,7 @@ <ItemDefinitionGroup> <ClCompile> <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\windows\include;$(SolutionDir)\common;$(SolutionDir)\core;$(SolutionDir)\$(TargetName)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS4;_CRT_SECURE_NO_WARNINGS;_WINDLL;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS4;_CRT_SECURE_NO_WARNINGS;_WINDLL;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <CompileAs>CompileAsC</CompileAs> <BrowseInformation>true</BrowseInformation> <ForcedIncludeFiles>platform.h</ForcedIncludeFiles> diff --git a/src/windows/libs_release.props b/src/windows/libs_release.props index 877536bc9861d9f21c60a484e340fecbac4bd84f..c733694ea5c78843d42a055fbf13f672c79b8b8a 100644 --- a/src/windows/libs_release.props +++ b/src/windows/libs_release.props @@ -10,7 +10,7 @@ <ItemDefinitionGroup> <ClCompile> <AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\windows\include;$(SolutionDir)\common;$(SolutionDir)\core;$(SolutionDir)\$(TargetName)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS4;_CRT_SECURE_NO_WARNINGS;_WINDLL;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PMEM2_USE_MINIASYNC;PMDK_UTF8_API;SDS_ENABLED;NTDDI_VERSION=NTDDI_WIN10_RS4;_CRT_SECURE_NO_WARNINGS;_WINDLL;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <CompileAs>CompileAsC</CompileAs> <BrowseInformation>true</BrowseInformation> <ForcedIncludeFiles>platform.h</ForcedIncludeFiles> diff --git a/utils/build-dpkg.sh b/utils/build-dpkg.sh index 256b6da4156245e7d830c1f2a665c569e21e1308..e4c64447363861ce35c19fb0a58fa68e937369d7 100755 --- a/utils/build-dpkg.sh +++ b/utils/build-dpkg.sh @@ -251,6 +251,7 @@ $LIB_DIR/pmdk_debug/libpmem2.so.* $LIB_DIR/pmdk_dbg/ $LIB_DIR/libpmem2.so $LIB_DIR/pkgconfig/libpmem2.pc $INC_DIR/libpmem2.h +$INC_DIR/libpmem2/*.h $MAN7_DIR/libpmem2.7 $MAN3_DIR/pmem2_*.3 EOF diff --git a/utils/check-area.sh b/utils/check-area.sh index 07d94802c952d39e6a32419f5e33fa4cd8aef273..32bb4334fd51b0d54c4bdc6be90acaaa8d5520eb 100755 --- a/utils/check-area.sh +++ b/utils/check-area.sh @@ -35,7 +35,7 @@ echo "Areas computed basing on the list of modified files: (see utils/check-area categorize core -e "^src/core/" categorize pmem -e "^src/libpmem/" -e "^src/include/libpmem.h" -categorize pmem2 -e "^src/libpmem2/" -e "^src/include/libpmem2.h" +categorize pmem2 -e "^src/libpmem2/" -e "^src/include/libpmem2.h" -e "^src/include/libpmem2/" categorize rpmem -e "^src/librpmem/" -e "^src/include/librpmem.h" -e "^src/tools/rpmemd/" -e "^src/rpmem_common/" categorize log -e "^src/libpmemlog/" -e "^src/include/libpmemlog.h" categorize blk -e "^src/libpmemblk/" -e "^src/include/libpmemblk.h" diff --git a/utils/pmdk.spec.in b/utils/pmdk.spec.in index 58e02e6d2ac7aba2a27ec2fb44d105481eed96d6..6831c8f8f735ddbb769533dd0752ae6149eaf8d1 100644 --- a/utils/pmdk.spec.in +++ b/utils/pmdk.spec.in @@ -128,6 +128,7 @@ convenient. %{_libdir}/libpmem2.so %{_libdir}/pkgconfig/libpmem2.pc %{_includedir}/libpmem2.h +%{_includedir}/libpmem2/*.h %{_mandir}/man7/libpmem2.7.gz %{_mandir}/man3/pmem2_*.3.gz %license LICENSE