diff --git a/include/spdk/copy_engine.h b/include/spdk/copy_engine.h index a80cb0038..97e001b7c 100644 --- a/include/spdk/copy_engine.h +++ b/include/spdk/copy_engine.h @@ -53,6 +53,8 @@ struct copy_task { struct spdk_copy_engine { int64_t (*copy)(void *cb_arg, void *dst, void *src, uint64_t nbytes, copy_completion_cb cb); + int64_t (*fill)(void *cb_arg, void *dst, uint8_t fill, + uint64_t nbytes, copy_completion_cb cb); void (*check_io)(void); }; @@ -84,6 +86,8 @@ struct spdk_copy_module_if { void spdk_copy_engine_register(struct spdk_copy_engine *copy_engine); int64_t spdk_copy_submit(struct copy_task *copy_req, void *dst, void *src, uint64_t nbytes, copy_completion_cb cb); +int64_t spdk_copy_submit_fill(struct copy_task *copy_req, void *dst, uint8_t fill, + uint64_t nbytes, copy_completion_cb cb); int spdk_copy_check_io(void); int spdk_copy_module_get_max_ctx_size(void); void spdk_copy_module_list_add(struct spdk_copy_module_if *copy_module); diff --git a/lib/copy/copy_engine.c b/lib/copy/copy_engine.c index f317cd71e..7ae86d54e 100644 --- a/lib/copy/copy_engine.c +++ b/lib/copy/copy_engine.c @@ -113,6 +113,23 @@ spdk_copy_submit(struct copy_task *copy_req, void *dst, void *src, copy_engine_done); } +int64_t +spdk_copy_submit_fill(struct copy_task *copy_req, void *dst, uint8_t fill, + uint64_t nbytes, copy_completion_cb cb) +{ + struct copy_task *req = copy_req; + + req->cb = cb; + + if (hw_copy_engine && hw_copy_engine->fill) { + return hw_copy_engine->fill(req->offload_ctx, dst, fill, nbytes, + copy_engine_done); + } + + return mem_copy_engine->fill(req->offload_ctx, dst, fill, nbytes, + copy_engine_done); +} + /* memcpy default copy engine */ static void mem_copy_check_io(void) @@ -150,8 +167,25 @@ mem_copy_submit(void *cb_arg, void *dst, void *src, uint64_t nbytes, return nbytes; } +static int64_t +mem_copy_fill(void *cb_arg, void *dst, uint8_t fill, uint64_t nbytes, + copy_completion_cb cb) +{ + struct mem_request **req_head = ©_engine_req_head[rte_lcore_id()]; + struct mem_request *req = (struct mem_request *)cb_arg; + + req->next = *req_head; + *req_head = req; + req->cb = cb; + + memset(dst, fill, nbytes); + + return nbytes; +} + static struct spdk_copy_engine memcpy_copy_engine = { .copy = mem_copy_submit, + .fill = mem_copy_fill, .check_io = mem_copy_check_io, }; diff --git a/lib/copy/ioat/copy_engine_ioat.c b/lib/copy/ioat/copy_engine_ioat.c index 7e57e6df0..34bfbb4ea 100644 --- a/lib/copy/ioat/copy_engine_ioat.c +++ b/lib/copy/ioat/copy_engine_ioat.c @@ -142,6 +142,22 @@ ioat_copy_submit(void *cb_arg, void *dst, void *src, uint64_t nbytes, return spdk_ioat_submit_copy(chan, ioat_task, ioat_done, dst, src, nbytes); } +static int64_t +ioat_copy_submit_fill(void *cb_arg, void *dst, uint8_t fill, uint64_t nbytes, + copy_completion_cb cb) +{ + struct ioat_task *ioat_task = (struct ioat_task *)cb_arg; + struct spdk_ioat_chan *chan = g_ioat_chan[rte_lcore_id()]; + uint64_t fill64 = 0x0101010101010101ULL * fill; + + RTE_VERIFY(chan != NULL); + + ioat_task->cb = cb; + + return spdk_ioat_submit_fill(chan, ioat_task, ioat_done, dst, fill64, nbytes); +} + + static void ioat_check_io(void) { @@ -153,6 +169,7 @@ ioat_check_io(void) static struct spdk_copy_engine ioat_copy_engine = { .copy = ioat_copy_submit, + .fill = ioat_copy_submit_fill, .check_io = ioat_check_io, };