accel: Save overridden options in json config file

Signed-off-by: Alexey Marchuk <alexeymar@nvidia.com>
Change-Id: Ida2c6f1c460c2b66d2d4159d225036377e488e62
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14856
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
This commit is contained in:
Alexey Marchuk 2022-10-04 20:50:44 +02:00 committed by Tomasz Zawadzki
parent 8d27a5f7ed
commit c77b537786
3 changed files with 49 additions and 23 deletions

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation. * Copyright (c) Intel Corporation.
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
* All rights reserved. * All rights reserved.
*/ */
@ -43,6 +44,11 @@ static TAILQ_HEAD(, spdk_accel_module_if) spdk_accel_module_list =
static struct spdk_accel_module_if *g_modules_opc[ACCEL_OPC_LAST] = {}; static struct spdk_accel_module_if *g_modules_opc[ACCEL_OPC_LAST] = {};
static char *g_modules_opc_override[ACCEL_OPC_LAST] = {}; static char *g_modules_opc_override[ACCEL_OPC_LAST] = {};
static const char *g_opcode_strings[ACCEL_OPC_LAST] = {
"copy", "fill", "dualcast", "compare", "crc32c", "copy_crc32c",
"compress", "decompress"
};
struct accel_io_channel { struct accel_io_channel {
struct spdk_io_channel *module_ch[ACCEL_OPC_LAST]; struct spdk_io_channel *module_ch[ACCEL_OPC_LAST];
void *task_pool_base; void *task_pool_base;
@ -87,6 +93,21 @@ _accel_for_each_module(struct module_info *info, _accel_for_each_module_fn fn)
} }
} }
int
_accel_get_opc_name(enum accel_opcode opcode, const char **opcode_name)
{
int rc = 0;
if (opcode < ACCEL_OPC_LAST) {
*opcode_name = g_opcode_strings[opcode];
} else {
/* invalid opcode */
rc = -EINVAL;
}
return rc;
}
int int
spdk_accel_assign_opc(enum accel_opcode opcode, const char *name) spdk_accel_assign_opc(enum accel_opcode opcode, const char *name)
{ {
@ -625,10 +646,24 @@ accel_module_finish_cb(void)
g_fini_cb_arg = NULL; g_fini_cb_arg = NULL;
} }
static void
accel_write_overridden_opc(struct spdk_json_write_ctx *w, const char *opc_str,
const char *module_str)
{
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "accel_assign_opc");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "opname", opc_str);
spdk_json_write_named_string(w, "module", module_str);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
void void
spdk_accel_write_config_json(struct spdk_json_write_ctx *w) spdk_accel_write_config_json(struct spdk_json_write_ctx *w)
{ {
struct spdk_accel_module_if *accel_module; struct spdk_accel_module_if *accel_module;
int i;
/* /*
* The accel fw has no config, there may be some in * The accel fw has no config, there may be some in
@ -640,6 +675,11 @@ spdk_accel_write_config_json(struct spdk_json_write_ctx *w)
accel_module->write_config_json(w); accel_module->write_config_json(w);
} }
} }
for (i = 0; i < ACCEL_OPC_LAST; i++) {
if (g_modules_opc_override[i]) {
accel_write_overridden_opc(w, g_opcode_strings[i], g_modules_opc_override[i]);
}
}
spdk_json_write_array_end(w); spdk_json_write_array_end(w);
} }

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation. * Copyright (c) Intel Corporation.
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
* All rights reserved. * All rights reserved.
*/ */
@ -21,5 +22,6 @@ struct module_info {
typedef void (*_accel_for_each_module_fn)(struct module_info *info); typedef void (*_accel_for_each_module_fn)(struct module_info *info);
void _accel_for_each_module(struct module_info *info, _accel_for_each_module_fn fn); void _accel_for_each_module(struct module_info *info, _accel_for_each_module_fn fn);
int _accel_get_opc_name(enum accel_opcode opcode, const char **opcode_name);
#endif #endif

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation. * Copyright (c) Intel Corporation.
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
* All rights reserved. * All rights reserved.
*/ */
@ -11,26 +12,6 @@
#include "spdk/stdinc.h" #include "spdk/stdinc.h"
#include "spdk/env.h" #include "spdk/env.h"
const char *g_opcode_strings[ACCEL_OPC_LAST] = {
"copy", "fill", "dualcast", "compare", "crc32c", "copy_crc32c",
"compress", "decompress"
};
static int
_get_opc_name(enum accel_opcode opcode, const char **opcode_name)
{
int rc = 0;
if (opcode < ACCEL_OPC_LAST) {
*opcode_name = g_opcode_strings[opcode];
} else {
/* invalid opcode */
rc = -EINVAL;
}
return rc;
}
static void static void
rpc_accel_get_opc_assignments(struct spdk_jsonrpc_request *request, rpc_accel_get_opc_assignments(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params) const struct spdk_json_val *params)
@ -50,7 +31,7 @@ rpc_accel_get_opc_assignments(struct spdk_jsonrpc_request *request,
spdk_json_write_object_begin(w); spdk_json_write_object_begin(w);
for (opcode = 0; opcode < ACCEL_OPC_LAST; opcode++) { for (opcode = 0; opcode < ACCEL_OPC_LAST; opcode++) {
rc = _get_opc_name(opcode, &name); rc = _accel_get_opc_name(opcode, &name);
if (rc == 0) { if (rc == 0) {
rc = spdk_accel_get_opc_module_name(opcode, &module_name); rc = spdk_accel_get_opc_module_name(opcode, &module_name);
if (rc != 0) { if (rc != 0) {
@ -86,7 +67,7 @@ rpc_dump_module_info(struct module_info *info)
spdk_json_write_named_array_begin(w, "supported ops"); spdk_json_write_named_array_begin(w, "supported ops");
for (i = 0; i < info->num_ops; i++) { for (i = 0; i < info->num_ops; i++) {
rc = _get_opc_name(i, &name); rc = _accel_get_opc_name(i, &name);
if (rc == 0) { if (rc == 0) {
spdk_json_write_string(w, name); spdk_json_write_string(w, name);
} else { } else {
@ -146,6 +127,7 @@ rpc_accel_assign_opc(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params) const struct spdk_json_val *params)
{ {
struct rpc_accel_assign_opc req = {}; struct rpc_accel_assign_opc req = {};
const char *opcode_str;
enum accel_opcode opcode; enum accel_opcode opcode;
bool found = false; bool found = false;
int rc; int rc;
@ -160,7 +142,9 @@ rpc_accel_assign_opc(struct spdk_jsonrpc_request *request,
} }
for (opcode = 0; opcode < ACCEL_OPC_LAST; opcode++) { for (opcode = 0; opcode < ACCEL_OPC_LAST; opcode++) {
if (strcmp(g_opcode_strings[opcode], req.opname) == 0) { rc = _accel_get_opc_name(opcode, &opcode_str);
assert(!rc);
if (strcmp(opcode_str, req.opname) == 0) {
found = true; found = true;
break; break;
} }