Skip to content

Commit

Permalink
Merge pull request #5446 from lplewa/master
Browse files Browse the repository at this point in the history
miniasync update
  • Loading branch information
lplewa authored May 18, 2022
2 parents 7dc446b + 2f431b8 commit ba0cd09
Show file tree
Hide file tree
Showing 26 changed files with 564 additions and 94 deletions.
15 changes: 15 additions & 0 deletions src/deps/miniasync/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Wed Apr 22 2022 Weronika Lewandowska <[email protected]>

* Version 0.1.0

This is the first official release of the miniasync library.

The library provides the API for asynchronous memory operations
through the use of features and runtime mechanisms and independence
in terms of hardware by implementing a virtual data mover.

This release also contains:
- documentation on the implemented functionality
- basic examples
- working build system based on GHA
- functional test cases
6 changes: 4 additions & 2 deletions src/deps/miniasync/doc/data_mover_dml_get_vdm.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ structure *struct vdm* is needed by every **miniasync**(7) data mover operation.
**DML** data mover implementation supports following operations:

* **vdm_memcpy**(3) - memory copy operation
* **vdm_memmove**(3) - memory move operation
* **vdm_memset**(3) - memory set operation

# RETURN VALUE #

The **data_mover_dml_get_vdm**() function returns a pointer to *struct vdm* structure.

# SEE ALSO #

**vdm_memcpy**(3), **miniasync**(7),
**miniasync_vdm_dml**(7) and **<https://pmem.io>**
**vdm_memcpy**(3), **vdm_memmove**(3), **vdm_memset**(3),
**miniasync**(7), **miniasync_vdm_dml**(7) and **<https://pmem.io>**
8 changes: 5 additions & 3 deletions src/deps/miniasync/doc/miniasync_vdm_dml.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ To create a new **DML** data mover instance, use **data_mover_dml_new**(3) funct
**DML** data mover supports following operations:

* **vdm_memcpy**(3) - memory copy operation
* **vdm_memmove**(3) - memory move operation
* **vdm_memset**(3) - memory set operation

**DML** data mover does not support notifier feature. For more information about
notifiers, see **miniasync_future**(7).
Expand All @@ -78,6 +80,6 @@ struct vdm_memcpy_future memcpy_fut = vdm_memcpy(dml_mover, dest, src,
# SEE ALSO #

**data_mover_dml_new**(3), **data_mover_dml_get_vdm**(3),
**vdm_memcpy**(3), **miniasync**(7), **miniasync_future**(7),
**miniasync_vdm**(7), **<https://github.com/intel/DML>**
and **<https://pmem.io>**
**vdm_memcpy**(3), **vdm_memmove**(3), **vdm_memset**(3),
**miniasync**(7), **miniasync_future**(7), **miniasync_vdm**(7),
**<https://github.com/intel/DML>** and **<https://pmem.io>**
15 changes: 4 additions & 11 deletions src/deps/miniasync/extras/dml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ add_check_whitespace(miniasync-vdm-dml
${CMAKE_CURRENT_SOURCE_DIR}/utils/*.[ch])

set(DML_SOURCES
data_mover_dml.c
data_mover_dml.c
)

set(DML_CORE_DEPS
${CORE_SOURCE_DIR}/cpu.c
${CORE_SOURCE_DIR}/os_posix.c
${CORE_SOURCE_DIR}/os_thread_posix.c
${CORE_SOURCE_DIR}/out.c
${CORE_SOURCE_DIR}/util.c
${CORE_SOURCE_DIR}/util_posix.c)

add_library(miniasync-vdm-dml SHARED ${DML_SOURCES} ${DML_CORE_DEPS})
add_library(miniasync-vdm-dml SHARED ${DML_SOURCES})
target_link_libraries(miniasync-vdm-dml PRIVATE dml dl)

target_include_directories(miniasync-vdm-dml PRIVATE .
${MINIASYNC_DML_INCLUDE_DIR}
Expand Down Expand Up @@ -59,4 +52,4 @@ set(CHECK_MOVDIR64B_SOURCES

add_link_executable(check_movdir64b
"${CHECK_MOVDIR64B_SOURCES}"
"")
"dml")
153 changes: 118 additions & 35 deletions src/deps/miniasync/extras/dml/data_mover_dml.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "core/membuf.h"
#include "core/out.h"
#include "core/util.h"
#include "libminiasync-vdm-dml.h"

#define SUPPORTED_FLAGS VDM_F_MEM_DURABLE | VDM_F_NO_CACHE_HINT
Expand Down Expand Up @@ -72,19 +71,69 @@ data_mover_dml_memcpy_job_init(dml_job_t *dml_job,
}

/*
* data_mover_dml_memcpy_job_delete -- delete job struct
* data_mover_dml_memmove_job_init -- initializes new memmove dml job
*/
static dml_job_t *
data_mover_dml_memmove_job_init(dml_job_t *dml_job,
void *dest, void *src, size_t n, uint64_t flags)
{
uint64_t dml_flags = 0;
data_mover_dml_translate_flags(flags, &dml_flags);

dml_job->operation = DML_OP_MEM_MOVE;
dml_job->source_first_ptr = (uint8_t *)src;
dml_job->destination_first_ptr = (uint8_t *)dest;
dml_job->source_length = n;
dml_job->destination_length = n;
dml_job->flags = dml_flags;

return dml_job;
}

/*
* data_mover_dml_memset_job_init -- initializes new memset dml job
*/
static dml_job_t *
data_mover_dml_memset_job_init(dml_job_t *dml_job,
void *ptr, int value, size_t n, uint64_t flags)
{
uint64_t dml_flags = 0;
data_mover_dml_translate_flags(flags, &dml_flags);

dml_job->operation = DML_OP_FILL;
dml_job->destination_first_ptr = (uint8_t *)ptr;
dml_job->destination_length = n;
dml_job->flags = dml_flags;

/*
* Original 'memset' implementation converts the provided 'value' into
* a 'unsigned char' type.
*/
unsigned char c = (unsigned char)value;

/* Populate the pattern */
for (size_t i = 0; i < 8 && i < n; i++) {
dml_job->pattern[i] = (uint8_t)c;
}

return dml_job;
}

/*
* data_mover_dml_job_delete -- delete job struct
*/
static void
data_mover_dml_memcpy_job_delete(dml_job_t **dml_job)
data_mover_dml_job_delete(dml_job_t **dml_job)
{
dml_finalize_job(*dml_job);
}

/*
* data_mover_dml_memcpy_job_submit -- submit memcpy job (nonblocking)
* data_mover_dml_memory_op_job_submit -- submit job for memory operations,
* which include memcpy and memmove (nonblocking)
*/
static void *
data_mover_dml_memcpy_job_submit(dml_job_t *dml_job)
data_mover_dml_memory_op_job_submit(dml_job_t *dml_job)
{
dml_status_t status;
status = dml_submit_job(dml_job);
Expand All @@ -105,28 +154,30 @@ data_mover_dml_operation_new(struct vdm *vdm,
dml_job_t *dml_job;

switch (type) {
case VDM_OPERATION_MEMCPY: {
status = dml_get_job_size(vdm_dml->path, &job_size);
if (status != DML_STATUS_OK)
return NULL;

dml_job = membuf_alloc(vdm_dml->membuf, job_size);
if (dml_job == NULL)
return NULL;

dml_status_t status =
dml_init_job(vdm_dml->path, dml_job);
if (status != DML_STATUS_OK) {
membuf_free(dml_job);
return NULL;
}

return dml_job;
}
case VDM_OPERATION_MEMCPY:
case VDM_OPERATION_MEMMOVE:
case VDM_OPERATION_MEMSET:
break;
default:
ASSERT(0); /* unreachable */
ASSERT(0); /* unreachable */
}

status = dml_get_job_size(vdm_dml->path, &job_size);
if (status != DML_STATUS_OK)
return NULL;

dml_job = membuf_alloc(vdm_dml->membuf, job_size);
if (dml_job == NULL)
return NULL;

dml_status_t job_status =
dml_init_job(vdm_dml->path, dml_job);
if (job_status != DML_STATUS_OK) {
membuf_free(dml_job);
return NULL;
}
return NULL;

return dml_job;
}

/*
Expand Down Expand Up @@ -154,15 +205,25 @@ data_mover_dml_operation_delete(void *data,

switch (job->operation) {
case DML_OP_MEM_MOVE:
output->type = VDM_OPERATION_MEMCPY;
output->output.memcpy.dest =
job->destination_first_ptr;
if (job->flags & DML_FLAG_COPY_ONLY) {
output->type = VDM_OPERATION_MEMCPY;
output->output.memcpy.dest =
job->destination_first_ptr;
} else {
output->type = VDM_OPERATION_MEMMOVE;
output->output.memmove.dest =
job->destination_first_ptr;
}
break;
case DML_OP_FILL:
output->type = VDM_OPERATION_MEMSET;
output->output.memset.str = job->destination_first_ptr;
break;
default:
ASSERT(0);
}

data_mover_dml_memcpy_job_delete(&job);
data_mover_dml_job_delete(&job);

membuf_free(data);
}
Expand Down Expand Up @@ -202,13 +263,35 @@ data_mover_dml_operation_start(void *data,
}

dml_job_t *job = (dml_job_t *)data;
data_mover_dml_memcpy_job_init(job,
operation->data.memcpy.dest,
operation->data.memcpy.src,
operation->data.memcpy.n,
operation->data.memcpy.flags);

data_mover_dml_memcpy_job_submit(job);
switch (operation->type) {
case VDM_OPERATION_MEMCPY:
data_mover_dml_memcpy_job_init(job,
operation->data.memcpy.dest,
operation->data.memcpy.src,
operation->data.memcpy.n,
operation->data.memcpy.flags);
data_mover_dml_memory_op_job_submit(job);
break;
case VDM_OPERATION_MEMMOVE:
data_mover_dml_memmove_job_init(job,
operation->data.memmove.dest,
operation->data.memmove.src,
operation->data.memmove.n,
operation->data.memmove.flags);
data_mover_dml_memory_op_job_submit(job);
break;
case VDM_OPERATION_MEMSET:
data_mover_dml_memset_job_init(job,
operation->data.memset.str,
operation->data.memset.c,
operation->data.memset.n,
operation->data.memset.flags);
data_mover_dml_memory_op_job_submit(job);
break;
default:
ASSERT(0);
}

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/deps/miniasync/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ if(WIN32)
endif()

set_target_properties(miniasync PROPERTIES
SOVERSION 0.1.0-rc1
PUBLIC_HEADER ${MINIASYNC_INCLUDE_DIR}/libminiasync.h
)

Expand Down
16 changes: 12 additions & 4 deletions src/deps/miniasync/src/core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include "cpu.h"

#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64) || \
defined(_M_AMD64)

#define EAX_IDX 0
#define EBX_IDX 1
#define ECX_IDX 2
Expand All @@ -43,10 +46,6 @@ cpuid(unsigned func, unsigned subfunc, unsigned cpuinfo[4])
__cpuidex((int *)cpuinfo, (int)func, (int)subfunc);
}

#else

#error unsupported compiler

#endif

#ifndef bit_MOVDIR64B
Expand Down Expand Up @@ -78,3 +77,12 @@ is_cpu_movdir64b_present(void)
{
return is_cpu_feature_present(0x7, ECX_IDX, bit_MOVDIR64B);
}

#else

/*
* Nothing to be done here yet. There is no support for 64B atomic copy on
* the other architectures yet.
*/

#endif
5 changes: 5 additions & 0 deletions src/deps/miniasync/src/core/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* cpu.h -- definitions for "cpu" module
*/

#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64) || \
defined(_M_AMD64)

int is_cpu_movdir64b_present(void);

#endif

#endif
17 changes: 17 additions & 0 deletions src/deps/miniasync/src/core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,23 @@ static
#define SUPPRESS_ARG_8(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_7(__VA_ARGS__)
#define SUPPRESS_ARG_9(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_8(__VA_ARGS__)

#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64) || \
defined(_M_AMD64)

#include <emmintrin.h>
#define WAIT() _mm_pause()

#else

/*
* Notice there are better implementations for wait-like functions on other
* architectures (e.g. powerpc64le), but the current code is generic enough
* and doesn't break the build.
*/
#define WAIT() do {} while (0)

#endif

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 10 additions & 1 deletion src/deps/miniasync/src/include/libminiasync/future.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,17 @@

#include <stddef.h>
#include <stdint.h>

#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64) || \
defined(_M_AMD64)
#include <emmintrin.h>

#define __FUTURE_WAIT() _mm_pause()
#else
#include <sched.h>
#define __FUTURE_WAIT() sched_yield()
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -261,7 +270,7 @@ future_poll(struct future *fut, struct future_notifier *notifier)

#define FUTURE_BUSY_POLL(_futurep)\
while (future_poll(FUTURE_AS_RUNNABLE((_futurep)), NULL) !=\
FUTURE_STATE_COMPLETE) { _mm_pause(); }
FUTURE_STATE_COMPLETE) { __FUTURE_WAIT(); }

static inline enum future_state
async_chain_impl(struct future_context *ctx, struct future_notifier *notifier)
Expand Down
Loading

0 comments on commit ba0cd09

Please sign in to comment.