Commit fad052b0 authored by paul luse's avatar paul luse Committed by Tomasz Zawadzki
Browse files

accel: add write_config json for accel modules



Add both the plumbing in the engine to call module entry
points if they exist as well as the json write config
for idxd (the only module with config info at this time).

Signed-off-by: default avatarpaul luse <paul.e.luse@intel.com>
Change-Id: I91376d3fc60227cd79fae17b164722619eafb9e5
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2052


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 3044bd27
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -74,18 +74,28 @@ struct spdk_accel_module_if {
	 */
	void	(*config_text)(FILE *fp);

	/**
	 * Write Acceleration module configuration into provided JSON context.
	 */
	void	(*write_config_json)(struct spdk_json_write_ctx *w);

	/**
	 * Returns the allocation size required for the modules to use for context.
	 */
	size_t	(*get_ctx_size)(void);

	TAILQ_ENTRY(spdk_accel_module_if)	tailq;
};

void spdk_accel_hw_engine_register(struct spdk_accel_engine *accel_engine);
void spdk_accel_module_list_add(struct spdk_accel_module_if *accel_module);

#define SPDK_ACCEL_MODULE_REGISTER(init_fn, fini_fn, config_fn, ctx_size_fn)				\
#define SPDK_ACCEL_MODULE_REGISTER(init_fn, fini_fn, config_fn, config_json, ctx_size_fn)				\
	static struct spdk_accel_module_if init_fn ## _if = {						\
	.module_init		= init_fn,								\
	.module_fini		= fini_fn,								\
	.config_text		= config_fn,								\
	.write_config_json	= config_json,								\
	.get_ctx_size		= ctx_size_fn,								\
	};												\
	__attribute__((constructor)) static void init_fn ## _init(void)					\
+12 −6
Original line number Diff line number Diff line
@@ -223,11 +223,17 @@ spdk_accel_engine_module_finish_cb(void)
void
spdk_accel_write_config_json(struct spdk_json_write_ctx *w)
{
	/* TODO: call engine config_json entry points. */
	spdk_json_write_array_begin(w);
	spdk_json_write_object_begin(w);
	spdk_json_write_object_end(w);
	spdk_json_write_array_end(w);
	struct spdk_accel_module_if *accel_engine_module;

	/*
	 * The accel engine has no config, there may be some in
	 * the modules though.
	 */
	TAILQ_FOREACH(accel_engine_module, &spdk_accel_module_list, tailq) {
		if (accel_engine_module->write_config_json) {
			accel_engine_module->write_config_json(w);
		}
	}
}

void
@@ -364,4 +370,4 @@ sw_accel_engine_fini(void *ctxt)
}

SPDK_ACCEL_MODULE_REGISTER(sw_accel_engine_init, sw_accel_engine_fini,
			   NULL, sw_accel_engine_get_ctx_size)
			   NULL, NULL, sw_accel_engine_get_ctx_size)
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ DEPDIRS-reduce := log util
DEPDIRS-thread := log util

DEPDIRS-blob := log util thread
DEPDIRS-accel := log json thread
DEPDIRS-accel := log thread
DEPDIRS-jsonrpc := log util json
DEPDIRS-virtio := log util json thread

+23 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#include "spdk/thread.h"
#include "spdk/idxd.h"
#include "spdk/util.h"
#include "spdk/json.h"

/* Undefine this to require an RPC to enable IDXD. */
#undef DEVELOPER_DEBUG_MODE
@@ -55,6 +56,8 @@ static bool g_idxd_enable = true;
static bool g_idxd_enable = false;
#endif

uint32_t g_config_number;

enum channel_state {
	IDXD_CHANNEL_ACTIVE,
	IDXD_CHANNEL_PAUSED,
@@ -470,8 +473,9 @@ accel_engine_idxd_enable_probe(uint32_t config_number)
		config_number = 0;
	}

	g_config_number = config_number;
	g_idxd_enable = true;
	spdk_idxd_set_config(config_number);
	spdk_idxd_set_config(g_config_number);
}

static int
@@ -521,8 +525,25 @@ accel_engine_idxd_exit(void *ctx)
	spdk_accel_engine_module_finish();
}

static void
accel_engine_idxd_write_config_json(struct spdk_json_write_ctx *w)
{
	spdk_json_write_array_begin(w);

	if (g_idxd_enable) {
		spdk_json_write_object_begin(w);
		spdk_json_write_named_string(w, "method", "idxd_scan_accel_engine");
		spdk_json_write_named_object_begin(w, "params");
		spdk_json_write_named_uint32(w, "config_number", g_config_number);
		spdk_json_write_object_end(w);
		spdk_json_write_object_end(w);
	}

	spdk_json_write_array_end(w);
}

SPDK_ACCEL_MODULE_REGISTER(accel_engine_idxd_init, accel_engine_idxd_exit,
			   NULL,
			   NULL, accel_engine_idxd_write_config_json,
			   accel_engine_idxd_get_ctx_size)

SPDK_LOG_REGISTER_COMPONENT("accel_idxd", SPDK_LOG_ACCEL_IDXD)
+1 −1
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ accel_engine_ioat_get_ctx_size(void)
}

SPDK_ACCEL_MODULE_REGISTER(accel_engine_ioat_init, accel_engine_ioat_exit,
			   accel_engine_ioat_config_text,
			   accel_engine_ioat_config_text, NULL,
			   accel_engine_ioat_get_ctx_size)

static void
Loading