Commit 64b16eda authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

accel: add error module



This module will allow users to inject errors to selected accel
operations, similarly to how bdev_error allows user to inject errors on
the bdev layer.

Since the errors won't necessarily be injected to each submitted
operation, the module needs to be able to actually execute some of them
correctly.  To avoid duplicating the code, it forwards the execution of
the tasks to the software module.

This patch only defines the basic module structures, but doesn't inject
any errors.  That will be done in the following patches.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I708e2429cf7ce5373beaf991ccd0be8fc45b9fc0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20436


Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 92a2649c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ DEPDIRS-accel_dsa := log idxd thread $(JSON_LIBS) accel trace
DEPDIRS-accel_iaa := log idxd thread $(JSON_LIBS) accel trace
DEPDIRS-accel_dpdk_cryptodev := log thread $(JSON_LIBS) accel util
DEPDIRS-accel_dpdk_compressdev := log thread $(JSON_LIBS) accel util
DEPDIRS-accel_error := accel thread

ifeq ($(CONFIG_RDMA_PROV),mlx5_dv)
DEPDIRS-accel_mlx5 := accel thread log mlx5 rdma util
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ SOCK_MODULES_LIST += sock_uring
endif
endif

ACCEL_MODULES_LIST = accel_ioat ioat
ACCEL_MODULES_LIST = accel_error accel_ioat ioat
ifeq ($(CONFIG_IDXD),y)
ACCEL_MODULES_LIST += accel_dsa accel_iaa idxd
endif
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

DIRS-y = ioat
DIRS-y = error ioat
DIRS-$(CONFIG_DPDK_COMPRESSDEV) += dpdk_compressdev
DIRS-$(CONFIG_IDXD) += dsa
DIRS-$(CONFIG_IDXD) += iaa
+15 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Intel Corporation. All rights reserved.

SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 1
SO_MINOR := 0

LIBNAME = accel_error
C_SRCS = accel_error.c

SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map

include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
+131 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (C) 2023 Intel Corporation. All rights reserved.
 */

#include "spdk/accel.h"
#include "spdk/accel_module.h"
#include "spdk/thread.h"

struct accel_error_channel {
	struct spdk_io_channel *swch;
};

struct accel_error_task {
	spdk_accel_completion_cb	cb_fn;
	void				*cb_arg;
};

static struct spdk_accel_module_if *g_sw_module;
static size_t g_task_offset;

static struct accel_error_task *
accel_error_get_task_ctx(struct spdk_accel_task *task)
{
	return (void *)((uint8_t *)task + g_task_offset);
}

static void
accel_error_task_complete_cb(void *arg, int status)
{
	struct spdk_accel_task *task = arg;
	struct accel_error_task *errtask = accel_error_get_task_ctx(task);
	spdk_accel_completion_cb cb_fn = errtask->cb_fn;
	void *cb_arg = errtask->cb_arg;

	cb_fn(cb_arg, status);
}

static int
accel_error_submit_tasks(struct spdk_io_channel *ch, struct spdk_accel_task *task)
{
	struct accel_error_channel *errch = spdk_io_channel_get_ctx(ch);
	struct accel_error_task *errtask = accel_error_get_task_ctx(task);

	errtask->cb_fn = task->cb_fn;
	errtask->cb_arg = task->cb_arg;
	task->cb_fn = accel_error_task_complete_cb;
	task->cb_arg = task;

	return g_sw_module->submit_tasks(errch->swch, task);
}

static int
accel_error_channel_create_cb(void *io_device, void *ctx)
{
	struct accel_error_channel *errch = ctx;

	errch->swch = g_sw_module->get_io_channel();
	if (errch->swch == NULL) {
		return -ENOMEM;
	}

	return 0;
}

static void
accel_error_channel_destroy_cb(void *io_device, void *ctx)
{
	struct accel_error_channel *errch = ctx;

	spdk_put_io_channel(errch->swch);
}

static int
accel_error_module_init(void)
{
	g_sw_module = spdk_accel_get_module("software");
	if (g_sw_module == NULL) {
		/* Should never really happen */
		return -ENODEV;
	}

	g_task_offset = g_sw_module->get_ctx_size();

	spdk_io_device_register(&g_sw_module, accel_error_channel_create_cb,
				accel_error_channel_destroy_cb,
				sizeof(struct accel_error_channel), "accel_error");

	return 0;
}

static void
accel_error_unregister_cb(void *unused)
{
	spdk_accel_module_finish();
}

static void
accel_error_module_fini(void *unused)
{
	spdk_io_device_unregister(&g_sw_module, accel_error_unregister_cb);
}

static bool
accel_error_supports_opcode(enum spdk_accel_opcode opcode)
{
	return false;
}

static struct spdk_io_channel *
accel_error_get_io_channel(void)
{
	return spdk_get_io_channel(&g_sw_module);
}

static size_t
accel_error_get_ctx_size(void)
{
	return g_task_offset + sizeof(struct accel_error_task);
}

static struct spdk_accel_module_if g_accel_error_module = {
	.name			= "error",
	.priority		= INT_MIN,
	.module_init		= accel_error_module_init,
	.module_fini		= accel_error_module_fini,
	.supports_opcode	= accel_error_supports_opcode,
	.get_ctx_size		= accel_error_get_ctx_size,
	.get_io_channel		= accel_error_get_io_channel,
	.submit_tasks		= accel_error_submit_tasks,
};
SPDK_ACCEL_MODULE_REGISTER(error, &g_accel_error_module)