From d5b059dedcf62c891054332bc57a62f1edcf29c1 Mon Sep 17 00:00:00 2001 From: paul luse Date: Fri, 24 Apr 2020 12:47:55 -0400 Subject: [PATCH] accel: add new API to discover an engine's capabilities This patch also implements the new API for the 3 existing engines. There was also some minor clean in one file, moving a function to eliminate multiple forward declarations (there would have been another one with this new API). The next patch will use this API in the accel perf tool. Signed-off-by: paul luse Change-Id: I4ebc9cb3d1c588919235b5080cbeec29189efa21 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2025 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker --- CHANGELOG.md | 5 +++++ include/spdk/accel_engine.h | 20 ++++++++++++++++++ include/spdk_internal/accel_engine.h | 9 +++++---- lib/accel/Makefile | 2 +- lib/accel/accel_engine.c | 21 ++++++++++++++++--- lib/accel/spdk_accel.map | 1 + module/accel/idxd/accel_engine_idxd.c | 29 ++++++++++++++------------- module/accel/ioat/accel_engine_ioat.c | 17 +++++++++++++--- 8 files changed, 79 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b84fb4a7..ec10c428a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +### accel + +A new API was added `spdk_accel_get_capabilities` that allows applications to +query the capabilities of the currently enabled accel engine back-end. + ## v20.04: (Upcoming Release) ### configuration diff --git a/include/spdk/accel_engine.h b/include/spdk/accel_engine.h index 0afa78061..2a74e3fd2 100644 --- a/include/spdk/accel_engine.h +++ b/include/spdk/accel_engine.h @@ -44,6 +44,16 @@ extern "C" { #endif +enum accel_capability { + ACCEL_COPY = 1 << 0, + ACCEL_FILL = 1 << 1, + ACCEL_DUALCAST = 1 << 2, + ACCEL_COMPARE = 1 << 3, + ACCEL_BATCH = 1 << 4, + ACCEL_CRC = 1 << 5, + ACCEL_DIF = 1 << 6, +}; + /** * Acceleration operation callback. * @@ -99,6 +109,16 @@ void spdk_accel_engine_module_finish(void); */ struct spdk_io_channel *spdk_accel_engine_get_io_channel(void); +/** + * Retrieve accel engine capabilities. + * + * \param ch I/O channel to submit request to the accel engine. This channel can + * be obtained by the function spdk_accel_engine_get_io_channel(). + * + * \return bitmap of capabilities defined by enum accel_capability. + */ +uint64_t spdk_accel_get_capabilities(struct spdk_io_channel *ch); + /** * Submit a copy request. * diff --git a/include/spdk_internal/accel_engine.h b/include/spdk_internal/accel_engine.h index 1c9808168..bb0b47bdc 100644 --- a/include/spdk_internal/accel_engine.h +++ b/include/spdk_internal/accel_engine.h @@ -55,10 +55,11 @@ struct spdk_accel_task { }; struct spdk_accel_engine { - int (*copy)(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, - uint64_t nbytes, spdk_accel_completion_cb cb); - int (*fill)(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, - uint64_t nbytes, spdk_accel_completion_cb cb); + uint64_t (*get_capabilities)(void); + int (*copy)(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, + uint64_t nbytes, spdk_accel_completion_cb cb); + int (*fill)(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, + uint64_t nbytes, spdk_accel_completion_cb cb); struct spdk_io_channel *(*get_io_channel)(void); }; diff --git a/lib/accel/Makefile b/lib/accel/Makefile index 510d1fb9d..1226ddb7c 100644 --- a/lib/accel/Makefile +++ b/lib/accel/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 2 -SO_MINOR := 0 +SO_MINOR := 1 SO_SUFFIX := $(SO_VER).$(SO_MINOR) LIBNAME = accel diff --git a/lib/accel/accel_engine.c b/lib/accel/accel_engine.c index c8adddd85..ff2b6187f 100644 --- a/lib/accel/accel_engine.c +++ b/lib/accel/accel_engine.c @@ -109,6 +109,14 @@ _accel_engine_done(void *ref, int status) req->cb(req, status); } +uint64_t +spdk_accel_get_capabilities(struct spdk_io_channel *ch) +{ + struct accel_io_channel *accel_ch = spdk_io_channel_get_ctx(ch); + + return accel_ch->engine->get_capabilities(); +} + /* Accel framework public API for copy function */ int spdk_accel_submit_copy(struct spdk_accel_task *accel_req, struct spdk_io_channel *ch, @@ -297,6 +305,12 @@ spdk_accel_engine_config_text(FILE *fp) /* The SW Accelerator module is "built in" here (rest of file) */ +static uint64_t +sw_accel_get_capabilities(void) +{ + return ACCEL_COPY | ACCEL_FILL; +} + static int sw_accel_submit_copy(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, uint64_t nbytes, @@ -330,9 +344,10 @@ sw_accel_submit_fill(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_ static struct spdk_io_channel *sw_accel_get_io_channel(void); static struct spdk_accel_engine sw_accel_engine = { - .copy = sw_accel_submit_copy, - .fill = sw_accel_submit_fill, - .get_io_channel = sw_accel_get_io_channel, + .get_capabilities = sw_accel_get_capabilities, + .copy = sw_accel_submit_copy, + .fill = sw_accel_submit_fill, + .get_io_channel = sw_accel_get_io_channel, }; static int diff --git a/lib/accel/spdk_accel.map b/lib/accel/spdk_accel.map index 959fb1dee..af490b3d2 100644 --- a/lib/accel/spdk_accel.map +++ b/lib/accel/spdk_accel.map @@ -7,6 +7,7 @@ spdk_accel_engine_config_text; spdk_accel_engine_module_finish; spdk_accel_engine_get_io_channel; + spdk_accel_get_capabilities; spdk_accel_submit_copy; spdk_accel_submit_fill; spdk_accel_task_size; diff --git a/module/accel/idxd/accel_engine_idxd.c b/module/accel/idxd/accel_engine_idxd.c index f6134f6fb..ae1d6a159 100644 --- a/module/accel/idxd/accel_engine_idxd.c +++ b/module/accel/idxd/accel_engine_idxd.c @@ -102,20 +102,9 @@ struct idxd_task { spdk_accel_completion_cb cb; }; -static int accel_engine_idxd_init(void); -static void accel_engine_idxd_exit(void *ctx); -static struct spdk_io_channel *idxd_get_io_channel(void); -static int idxd_submit_copy(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, - uint64_t nbytes, - spdk_accel_completion_cb cb); -static int idxd_submit_fill(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, - uint64_t nbytes, spdk_accel_completion_cb cb); +pthread_mutex_t g_num_channels_lock = PTHREAD_MUTEX_INITIALIZER; -static struct spdk_accel_engine idxd_accel_engine = { - .copy = idxd_submit_copy, - .fill = idxd_submit_fill, - .get_io_channel = idxd_get_io_channel, -}; +static struct spdk_io_channel *idxd_get_io_channel(void); static struct idxd_device * idxd_select_device(void) @@ -271,7 +260,19 @@ idxd_submit_fill(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fi return rc; } -pthread_mutex_t g_num_channels_lock = PTHREAD_MUTEX_INITIALIZER; +static uint64_t +idxd_get_capabilities(void) +{ + return ACCEL_COPY | ACCEL_FILL | ACCEL_DUALCAST | ACCEL_COMPARE | + ACCEL_BATCH | ACCEL_CRC | ACCEL_DIF; +} + +static struct spdk_accel_engine idxd_accel_engine = { + .get_capabilities = idxd_get_capabilities, + .copy = idxd_submit_copy, + .fill = idxd_submit_fill, + .get_io_channel = idxd_get_io_channel, +}; /* * Configure the max number of descriptors that a channel is diff --git a/module/accel/ioat/accel_engine_ioat.c b/module/accel/ioat/accel_engine_ioat.c index dc6b910db..cdad57a65 100644 --- a/module/accel/ioat/accel_engine_ioat.c +++ b/module/accel/ioat/accel_engine_ioat.c @@ -191,10 +191,21 @@ ioat_poll(void *arg) static struct spdk_io_channel *ioat_get_io_channel(void); +/* + * The IOAT engine has more capabilities than this but these are + * the only ones we expose via the accel engine. + */ +static uint64_t +ioat_get_capabilities(void) +{ + return ACCEL_COPY | ACCEL_FILL; +} + static struct spdk_accel_engine ioat_accel_engine = { - .copy = ioat_submit_copy, - .fill = ioat_submit_fill, - .get_io_channel = ioat_get_io_channel, + .get_capabilities = ioat_get_capabilities, + .copy = ioat_submit_copy, + .fill = ioat_submit_fill, + .get_io_channel = ioat_get_io_channel, }; static int