Commit 55b047a7 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

module/iobuf: introduce iobuf module



This gives us a place to initialize iobuf pools, specify subsystem
dependencies, and execute RPCs to configure the sizes of the pools.

We allow users to configure the size of the pools either through the
options in spdk_bdev_opts or through the new RPC, iobuf_set_options.
The second option has higher priority, so it will override the options
set by the bdev layer.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 36df38c0
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -11150,3 +11150,42 @@ Example response:
  "result": true
}
~~~

### iobuf_set_options {#rpc_iobuf_set_options}

Set iobuf buffer pool options.

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
small_pool_count        | Optional | number      | Number of small buffers in the global pool
large_pool_count        | Optional | number      | Number of large buffers in the global pool
small_bufsize           | Optional | number      | Size of a small buffer
large_bufsize           | Optional | number      | Size of a small buffer

#### Example

Example request:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "iobuf_set_options",
  "params": {
    "small_pool_count": 16383,
    "large_pool_count": 2047
  }
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
~~~
+1 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@ DEPDIRS-event_vhost_blk := init vhost
DEPDIRS-event_vhost_scsi := init vhost event_scheduler event_scsi
DEPDIRS-event_sock := init sock
DEPDIRS-event_vfu_tgt := init vfu_tgt
DEPDIRS-event_iobuf := init log thread util $(JSON_LIBS)

# module/vfu_device

+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

DIRS-y += bdev accel scheduler iscsi nvmf scsi vmd sock
DIRS-y += bdev accel scheduler iscsi nvmf scsi vmd sock iobuf

ifeq ($(OS),Linux)
DIRS-y += nbd
+17 −0
Original line number Diff line number Diff line
#  SPDX-License-Identifier: BSD-3-Clause
#  Copyright (C) 2022 Intel Corporation.
#  All rights reserved.
#

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

SO_VER := 1
SO_MINOR := 0

C_SRCS = iobuf.c iobuf_rpc.c
LIBNAME = event_iobuf

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

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

#include "spdk/stdinc.h"
#include "spdk/bdev.h"
#include "spdk/log.h"
#include "spdk/thread.h"
#include "spdk_internal/init.h"

int iobuf_set_opts(struct spdk_iobuf_opts *opts);

static struct spdk_iobuf_opts g_opts;
static bool g_opts_set;

int
iobuf_set_opts(struct spdk_iobuf_opts *opts)
{
	int rc;

	rc = spdk_iobuf_set_opts(opts);
	if (rc != 0) {
		return rc;
	}

	g_opts = *opts;
	g_opts_set = true;

	return 0;
}

static void
iobuf_subsystem_initialize(void)
{
	int rc;

	if (g_opts_set) {
		/* We want to allow users to keep using bdev layer's spdk_bdev_opts to specify the
		 * sizes of the pools, but want to have iobuf_set_opts to take precedence over what
		 * was set by the spdk_bdev_opts.  So, reset the opts here in case bdev layer set
		 * them after iobuf_set_opts.
		 */
		rc = spdk_iobuf_set_opts(&g_opts);
		if (rc != 0) {
			/* This should never happen, we've already validated these options */
			assert(0);
			goto finish;
		}
	}

	rc = spdk_iobuf_initialize();
	if (rc != 0) {
		SPDK_ERRLOG("Failed to initialize iobuf\n");
	}
finish:
	spdk_subsystem_init_next(rc);
}

static void
iobuf_finish_cb(void *ctx)
{
	spdk_subsystem_fini_next();
}

static void
iobuf_subsystem_finish(void)
{
	spdk_iobuf_finish(iobuf_finish_cb, NULL);
}

static void
iobuf_write_config_json(struct spdk_json_write_ctx *w)
{
	struct spdk_iobuf_opts opts;

	spdk_iobuf_get_opts(&opts);

	spdk_json_write_array_begin(w);
	/* Make sure we don't override the options from spdk_bdev_opts, unless iobuf_set_options
	 * has been executed
	 */
	if (g_opts_set) {
		spdk_json_write_object_begin(w);
		spdk_json_write_named_string(w, "method", "iobuf_set_options");

		spdk_json_write_named_object_begin(w, "params");
		spdk_json_write_named_uint64(w, "small_pool_count", opts.small_pool_count);
		spdk_json_write_named_uint64(w, "large_pool_count", opts.large_pool_count);
		spdk_json_write_named_uint32(w, "small_bufsize", opts.small_bufsize);
		spdk_json_write_named_uint32(w, "large_bufsize", opts.large_bufsize);
		spdk_json_write_object_end(w);

		spdk_json_write_object_end(w);
	}
	spdk_json_write_array_end(w);
}

static struct spdk_subsystem g_subsystem_iobuf = {
	.name = "iobuf",
	.init = iobuf_subsystem_initialize,
	.fini = iobuf_subsystem_finish,
	.write_config_json = iobuf_write_config_json,
};

SPDK_SUBSYSTEM_REGISTER(g_subsystem_iobuf);
Loading