accel: add accel_set_options

It'll allow for setting accel-specific options.  For now, it makes the
size of iobuf caches configurable.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Iaf505cc5e98dc6411453d9964250a4ba22267d79
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17188
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Konrad Sztyber 2023-02-23 09:32:10 +01:00 committed by David Ko
parent 6b7ec13c8f
commit 35993ac9de
8 changed files with 172 additions and 6 deletions

View File

@ -441,6 +441,7 @@ Example response:
"framework_get_subsystems", "framework_get_subsystems",
"framework_monitor_context_switch", "framework_monitor_context_switch",
"spdk_kill_instance", "spdk_kill_instance",
"accel_set_options",
"accel_set_driver", "accel_set_driver",
"accel_crypto_key_create", "accel_crypto_key_create",
"accel_crypto_key_destroy", "accel_crypto_key_destroy",
@ -1943,6 +1944,43 @@ Example response:
} }
~~~ ~~~
### accel_set_options {#rpc_accel_set_options}
Set accel framework's options.
#### Parameters
Name | Optional | Type | Description
----------------------- |----------| ----------- | -----------------
small_cache_size | Optional | number | Size of the small iobuf cache
large_cache_size | Optional | number | Size of the large iobuf cache
#### Example
Example request:
~~~json
{
"jsonrpc": "2.0",
"method": "accel_set_options",
"id": 1,
"params": {
"small_cache_size": 128,
"large_cache_size": 32
}
}
~~~
Example response:
~~~json
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
~~~
### compressdev_scan_accel_module {#rpc_compressdev_scan_accel_module} ### compressdev_scan_accel_module {#rpc_compressdev_scan_accel_module}
Set config and enable compressdev accel module offload. Set config and enable compressdev accel module offload.

View File

@ -641,6 +641,31 @@ int spdk_accel_set_driver(const char *name);
*/ */
struct spdk_memory_domain *spdk_accel_get_memory_domain(void); struct spdk_memory_domain *spdk_accel_get_memory_domain(void);
struct spdk_accel_opts {
/** Size of this structure */
size_t size;
/** Size of the small iobuf cache */
uint32_t small_cache_size;
/** Size of the large iobuf cache */
uint32_t large_cache_size;
} __attribute__((packed));
/**
* Set the options for the accel framework.
*
* \param opts Accel options.
*
* \return 0 on success, negative errno otherwise.
*/
int spdk_accel_set_opts(const struct spdk_accel_opts *opts);
/**
* Get the options for the accel framework.
*
* \param opts Accel options.
*/
void spdk_accel_get_opts(struct spdk_accel_opts *opts);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -62,6 +62,10 @@ static struct accel_module g_modules_opc[ACCEL_OPC_LAST] = {};
static char *g_modules_opc_override[ACCEL_OPC_LAST] = {}; static char *g_modules_opc_override[ACCEL_OPC_LAST] = {};
TAILQ_HEAD(, spdk_accel_driver) g_accel_drivers = TAILQ_HEAD_INITIALIZER(g_accel_drivers); TAILQ_HEAD(, spdk_accel_driver) g_accel_drivers = TAILQ_HEAD_INITIALIZER(g_accel_drivers);
static struct spdk_accel_driver *g_accel_driver; static struct spdk_accel_driver *g_accel_driver;
static struct spdk_accel_opts g_opts = {
.small_cache_size = ACCEL_SMALL_CACHE_SIZE,
.large_cache_size = ACCEL_LARGE_CACHE_SIZE,
};
static const char *g_opcode_strings[ACCEL_OPC_LAST] = { static const char *g_opcode_strings[ACCEL_OPC_LAST] = {
"copy", "fill", "dualcast", "compare", "crc32c", "copy_crc32c", "copy", "fill", "dualcast", "compare", "crc32c", "copy_crc32c",
@ -2137,8 +2141,8 @@ accel_create_channel(void *io_device, void *ctx_buf)
} }
} }
rc = spdk_iobuf_channel_init(&accel_ch->iobuf, "accel", ACCEL_SMALL_CACHE_SIZE, rc = spdk_iobuf_channel_init(&accel_ch->iobuf, "accel", g_opts.small_cache_size,
ACCEL_LARGE_CACHE_SIZE); g_opts.large_cache_size);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Failed to initialize iobuf accel channel\n"); SPDK_ERRLOG("Failed to initialize iobuf accel channel\n");
goto err; goto err;
@ -2341,6 +2345,18 @@ _accel_crypto_key_write_config_json(struct spdk_json_write_ctx *w,
spdk_json_write_object_end(w); spdk_json_write_object_end(w);
} }
static void
accel_write_options(struct spdk_json_write_ctx *w)
{
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "accel_set_options");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_uint32(w, "small_cache_size", g_opts.small_cache_size);
spdk_json_write_named_uint32(w, "large_cache_size", g_opts.large_cache_size);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
static void static void
_accel_crypto_keys_write_config_json(struct spdk_json_write_ctx *w, bool full_dump) _accel_crypto_keys_write_config_json(struct spdk_json_write_ctx *w, bool full_dump)
{ {
@ -2369,11 +2385,9 @@ 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; int i;
/*
* The accel fw has no config, there may be some in
* the modules though.
*/
spdk_json_write_array_begin(w); spdk_json_write_array_begin(w);
accel_write_options(w);
TAILQ_FOREACH(accel_module, &spdk_accel_module_list, tailq) { TAILQ_FOREACH(accel_module, &spdk_accel_module_list, tailq) {
if (accel_module->write_config_json) { if (accel_module->write_config_json) {
accel_module->write_config_json(w); accel_module->write_config_json(w);
@ -2483,4 +2497,27 @@ spdk_accel_driver_register(struct spdk_accel_driver *driver)
TAILQ_INSERT_TAIL(&g_accel_drivers, driver, tailq); TAILQ_INSERT_TAIL(&g_accel_drivers, driver, tailq);
} }
int
spdk_accel_set_opts(const struct spdk_accel_opts *opts)
{
if (opts->size > sizeof(*opts)) {
return -EINVAL;
}
memcpy(&g_opts, opts, opts->size);
return 0;
}
void
spdk_accel_get_opts(struct spdk_accel_opts *opts)
{
size_t size = opts->size;
assert(size <= sizeof(*opts));
memcpy(opts, &g_opts, spdk_min(sizeof(*opts), size));
opts->size = size;
}
SPDK_LOG_REGISTER_COMPONENT(accel) SPDK_LOG_REGISTER_COMPONENT(accel)

View File

@ -354,3 +354,46 @@ cleanup:
free_rpc_accel_set_driver(&req); free_rpc_accel_set_driver(&req);
} }
SPDK_RPC_REGISTER("accel_set_driver", rpc_accel_set_driver, SPDK_RPC_STARTUP) SPDK_RPC_REGISTER("accel_set_driver", rpc_accel_set_driver, SPDK_RPC_STARTUP)
struct rpc_accel_opts {
uint32_t small_cache_size;
uint32_t large_cache_size;
};
static const struct spdk_json_object_decoder rpc_accel_set_options_decoders[] = {
{"small_cache_size", offsetof(struct rpc_accel_opts, small_cache_size), spdk_json_decode_uint32, true},
{"large_cache_size", offsetof(struct rpc_accel_opts, large_cache_size), spdk_json_decode_uint32, true},
};
static void
rpc_accel_set_options(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
{
struct spdk_accel_opts opts = { .size = sizeof(opts) };
struct rpc_accel_opts rpc_opts;
int rc;
/* We can't pass spdk_accel_opts directly to spdk_json_decode_object(), because that
* structure is packed, leading undefined behavior due to misaligned pointer access */
spdk_accel_get_opts(&opts);
rpc_opts.small_cache_size = opts.small_cache_size;
rpc_opts.large_cache_size = opts.large_cache_size;
if (spdk_json_decode_object(params, rpc_accel_set_options_decoders,
SPDK_COUNTOF(rpc_accel_set_options_decoders), &rpc_opts)) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
"spdk_json_decode_object failed");
return;
}
opts.small_cache_size = rpc_opts.small_cache_size;
opts.large_cache_size = rpc_opts.large_cache_size;
rc = spdk_accel_set_opts(&opts);
if (rc != 0) {
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
return;
}
spdk_jsonrpc_send_bool_response(request, true);
}
SPDK_RPC_REGISTER("accel_set_options", rpc_accel_set_options, SPDK_RPC_STARTUP)

View File

@ -36,6 +36,8 @@
spdk_accel_crypto_key_get; spdk_accel_crypto_key_get;
spdk_accel_set_driver; spdk_accel_set_driver;
spdk_accel_get_memory_domain; spdk_accel_get_memory_domain;
spdk_accel_set_opts;
spdk_accel_get_opts;
# functions needed by modules # functions needed by modules
spdk_accel_module_list_add; spdk_accel_module_list_add;

View File

@ -88,3 +88,15 @@ def accel_set_driver(client, name):
name: name of the driver name: name of the driver
""" """
return client.call('accel_set_driver', {'name': name}) return client.call('accel_set_driver', {'name': name})
def accel_set_options(client, small_cache_size, large_cache_size):
"""Set accel framework's options."""
params = {}
if small_cache_size is not None:
params['small_cache_size'] = small_cache_size
if large_cache_size is not None:
params['large_cache_size'] = large_cache_size
return client.call('accel_set_options', params)

View File

@ -2866,6 +2866,14 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
p.add_argument('name', help='name of the platform driver') p.add_argument('name', help='name of the platform driver')
p.set_defaults(func=accel_set_driver) p.set_defaults(func=accel_set_driver)
def accel_set_options(args):
rpc.accel.accel_set_options(args.client, args.small_cache_size, args.large_cache_size)
p = subparsers.add_parser('accel_set_options', help='Set accel framework\'s options')
p.add_argument('--small-cache-size', type=int, help='Size of the small iobuf cache')
p.add_argument('--large-cache-size', type=int, help='Size of the large iobuf cache')
p.set_defaults(func=accel_set_options)
# ioat # ioat
def ioat_scan_accel_module(args): def ioat_scan_accel_module(args):
rpc.ioat.ioat_scan_accel_module(args.client) rpc.ioat.ioat_scan_accel_module(args.client)

View File

@ -43,6 +43,7 @@ def filter_methods(do_remove_global_rpcs):
'framework_set_scheduler', 'framework_set_scheduler',
'accel_crypto_key_create', 'accel_crypto_key_create',
'accel_assign_opc', 'accel_assign_opc',
'accel_set_options',
'dpdk_cryptodev_scan_accel_module', 'dpdk_cryptodev_scan_accel_module',
'dpdk_cryptodev_set_driver', 'dpdk_cryptodev_set_driver',
'virtio_blk_create_transport', 'virtio_blk_create_transport',