From c224997be5155be5487f19b282fcf6c17cd8393f Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 15 Jun 2017 12:01:53 -0700 Subject: [PATCH] bdev: Remove direct calls to start/stop pollers Abstract these through the bdev API to break this dependency on the event framework. Change-Id: I108505bf27e94b2985f53d0a4dc0b847ae264d25 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/366340 Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp --- include/spdk/bdev.h | 14 +++++++++++++- include/spdk_internal/bdev.h | 9 ++++++++- lib/bdev/aio/blockdev_aio.c | 6 +++--- lib/bdev/aio/blockdev_aio.h | 2 +- lib/bdev/bdev.c | 30 +++++++++++++++++++++++++++++- lib/bdev/nvme/blockdev_nvme.c | 25 +++++++++++++------------ lib/bdev/rbd/blockdev_rbd.c | 8 ++++---- lib/event/subsystems/bdev/bdev.c | 24 +++++++++++++++++++++++- 8 files changed, 94 insertions(+), 24 deletions(-) diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index 39230f1ef..1b7d2be74 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -106,9 +106,21 @@ struct spdk_bdev_io_stat { uint64_t num_write_ops; }; +struct spdk_bdev_poller; + typedef void (*spdk_bdev_init_cb)(void *cb_arg, int rc); -void spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg); +typedef void (*spdk_bdev_poller_fn)(void *arg); +typedef void (*spdk_bdev_poller_start_cb)(struct spdk_bdev_poller **ppoller, + spdk_bdev_poller_fn fn, + void *arg, + uint32_t lcore, + uint64_t period_microseconds); +typedef void (*spdk_bdev_poller_stop_cb)(struct spdk_bdev_poller **ppoller); + +void spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg, + spdk_bdev_poller_start_cb start_poller_fn, + spdk_bdev_poller_stop_cb stop_poller_fn); int spdk_bdev_finish(void); void spdk_bdev_config_text(FILE *fp); diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index 79a7710c3..f013c23cc 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -42,7 +42,6 @@ #include "spdk/stdinc.h" #include "spdk/bdev.h" -#include "spdk/event.h" #include "spdk/queue.h" #include "spdk/scsi_spec.h" @@ -355,6 +354,14 @@ struct spdk_bdev_io { void spdk_bdev_register(struct spdk_bdev *bdev); void spdk_bdev_unregister(struct spdk_bdev *bdev); +void spdk_bdev_poller_start(struct spdk_bdev_poller **ppoller, + spdk_bdev_poller_fn fn, + void *arg, + uint32_t lcore, + uint64_t period_microseconds); + +void spdk_bdev_poller_stop(struct spdk_bdev_poller **ppoller); + void spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb); struct spdk_bdev_io *spdk_bdev_get_io(void); void spdk_bdev_io_resubmit(struct spdk_bdev_io *bdev_io, struct spdk_bdev *new_bdev); diff --git a/lib/bdev/aio/blockdev_aio.c b/lib/bdev/aio/blockdev_aio.c index b5fc1690d..10f5cb449 100644 --- a/lib/bdev/aio/blockdev_aio.c +++ b/lib/bdev/aio/blockdev_aio.c @@ -298,8 +298,8 @@ blockdev_aio_create_cb(void *io_device, void *ctx_buf) return -1; } - spdk_poller_register(&ch->poller, blockdev_aio_poll, ch, - spdk_env_get_current_core(), 0); + spdk_bdev_poller_start(&ch->poller, blockdev_aio_poll, ch, + spdk_env_get_current_core(), 0); return 0; } @@ -310,7 +310,7 @@ blockdev_aio_destroy_cb(void *io_device, void *ctx_buf) io_destroy(io_channel->io_ctx); free(io_channel->events); - spdk_poller_unregister(&io_channel->poller, NULL); + spdk_bdev_poller_stop(&io_channel->poller); } static struct spdk_io_channel * diff --git a/lib/bdev/aio/blockdev_aio.h b/lib/bdev/aio/blockdev_aio.h index b71346525..b315a13da 100644 --- a/lib/bdev/aio/blockdev_aio.h +++ b/lib/bdev/aio/blockdev_aio.h @@ -53,7 +53,7 @@ struct blockdev_aio_io_channel { io_context_t io_ctx; long queue_depth; struct io_event *events; - struct spdk_poller *poller; + struct spdk_bdev_poller *poller; }; struct file_disk { diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 9b58cb6cc..f1ae4748f 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -68,15 +68,21 @@ struct spdk_bdev_mgr { TAILQ_HEAD(, spdk_bdev) bdevs; + spdk_bdev_poller_start_cb start_poller_fn; + spdk_bdev_poller_stop_cb stop_poller_fn; + #ifdef SPDK_CONFIG_VTUNE __itt_domain *domain; #endif + }; static struct spdk_bdev_mgr g_bdev_mgr = { .bdev_modules = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.bdev_modules), .vbdev_modules = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.vbdev_modules), .bdevs = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.bdevs), + .start_poller_fn = NULL, + .stop_poller_fn = NULL }; static struct spdk_bdev_module_if *g_next_bdev_module; @@ -84,6 +90,7 @@ static struct spdk_bdev_module_if *g_next_vbdev_module; static spdk_bdev_init_cb g_cb_fn = NULL; static void *g_cb_arg = NULL; + struct spdk_bdev_mgmt_channel { need_buf_tailq_t need_buf_small; need_buf_tailq_t need_buf_large; @@ -358,7 +365,25 @@ spdk_vbdev_module_init_next(int rc) } void -spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg) +spdk_bdev_poller_start(struct spdk_bdev_poller **ppoller, + spdk_bdev_poller_fn fn, + void *arg, + uint32_t lcore, + uint64_t period_microseconds) +{ + g_bdev_mgr.start_poller_fn(ppoller, fn, arg, lcore, period_microseconds); +} + +void +spdk_bdev_poller_stop(struct spdk_bdev_poller **ppoller) +{ + g_bdev_mgr.stop_poller_fn(ppoller); +} + +void +spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg, + spdk_bdev_poller_start_cb start_poller_fn, + spdk_bdev_poller_stop_cb stop_poller_fn) { int cache_size; int rc = 0; @@ -368,6 +393,9 @@ spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg) g_cb_fn = cb_fn; g_cb_arg = cb_arg; + g_bdev_mgr.start_poller_fn = start_poller_fn; + g_bdev_mgr.stop_poller_fn = stop_poller_fn; + g_bdev_mgr.bdev_io_pool = spdk_mempool_create("blockdev_io", SPDK_BDEV_IO_POOL_SIZE, sizeof(struct spdk_bdev_io) + diff --git a/lib/bdev/nvme/blockdev_nvme.c b/lib/bdev/nvme/blockdev_nvme.c index c9ba6f6e4..e3a316167 100644 --- a/lib/bdev/nvme/blockdev_nvme.c +++ b/lib/bdev/nvme/blockdev_nvme.c @@ -60,7 +60,7 @@ struct nvme_ctrlr { char *name; int ref; - struct spdk_poller *adminq_timer_poller; + struct spdk_bdev_poller *adminq_timer_poller; /** linked list pointer for device list */ TAILQ_ENTRY(nvme_ctrlr) tailq; @@ -76,7 +76,7 @@ struct nvme_bdev { struct nvme_io_channel { struct spdk_nvme_qpair *qpair; - struct spdk_poller *poller; + struct spdk_bdev_poller *poller; }; #define NVME_DEFAULT_MAX_UNMAP_BDESC_COUNT 1 @@ -124,7 +124,7 @@ static int g_nvme_adminq_poll_timeout_us = 0; static bool g_nvme_hotplug_enabled = false; static int g_nvme_hotplug_poll_timeout_us = 0; static int g_nvme_hotplug_poll_core = 0; -static struct spdk_poller *g_hotplug_poller; +static struct spdk_bdev_poller *g_hotplug_poller; static pthread_mutex_t g_bdev_nvme_mutex = PTHREAD_MUTEX_INITIALIZER; static TAILQ_HEAD(, nvme_ctrlr) g_nvme_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_ctrlrs); @@ -217,7 +217,7 @@ bdev_nvme_destruct(void *ctx) TAILQ_REMOVE(&g_nvme_ctrlrs, nvme_ctrlr, tailq); pthread_mutex_unlock(&g_bdev_nvme_mutex); spdk_io_device_unregister(nvme_ctrlr->ctrlr); - spdk_poller_unregister(&nvme_ctrlr->adminq_timer_poller, NULL); + spdk_bdev_poller_stop(&nvme_ctrlr->adminq_timer_poller); spdk_nvme_detach(nvme_ctrlr->ctrlr); free(nvme_ctrlr->name); free(nvme_ctrlr); @@ -429,8 +429,8 @@ bdev_nvme_create_cb(void *io_device, void *ctx_buf) return -1; } - spdk_poller_register(&ch->poller, bdev_nvme_poll, ch, - spdk_env_get_current_core(), 0); + spdk_bdev_poller_start(&ch->poller, bdev_nvme_poll, ch, + spdk_env_get_current_core(), 0); return 0; } @@ -440,7 +440,7 @@ bdev_nvme_destroy_cb(void *io_device, void *ctx_buf) struct nvme_io_channel *ch = ctx_buf; spdk_nvme_ctrlr_free_io_qpair(ch->qpair); - spdk_poller_unregister(&ch->poller, NULL); + spdk_bdev_poller_stop(&ch->poller); } static struct spdk_io_channel * @@ -742,8 +742,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, nvme_ctrlr_create_bdevs(nvme_ctrlr); - spdk_poller_register(&nvme_ctrlr->adminq_timer_poller, bdev_nvme_poll_adminq, ctrlr, - spdk_env_get_current_core(), g_nvme_adminq_poll_timeout_us); + spdk_bdev_poller_start(&nvme_ctrlr->adminq_timer_poller, bdev_nvme_poll_adminq, ctrlr, + spdk_env_get_current_core(), g_nvme_adminq_poll_timeout_us); spdk_io_device_register(ctrlr, bdev_nvme_create_cb, bdev_nvme_destroy_cb, sizeof(struct nvme_io_channel)); @@ -974,8 +974,9 @@ bdev_nvme_library_init(void) } if (g_nvme_hotplug_enabled) { - spdk_poller_register(&g_hotplug_poller, blockdev_nvme_hotplug, NULL, - g_nvme_hotplug_poll_core, g_nvme_hotplug_poll_timeout_us); + spdk_bdev_poller_start(&g_hotplug_poller, blockdev_nvme_hotplug, NULL, + g_nvme_hotplug_poll_core, + g_nvme_hotplug_poll_timeout_us); } end: @@ -989,7 +990,7 @@ bdev_nvme_library_fini(void) struct nvme_bdev *nvme_bdev, *btmp; if (g_nvme_hotplug_enabled) { - spdk_poller_unregister(&g_hotplug_poller, NULL); + spdk_bdev_poller_stop(&g_hotplug_poller); } TAILQ_FOREACH_SAFE(nvme_bdev, &g_nvme_bdevs, link, btmp) { diff --git a/lib/bdev/rbd/blockdev_rbd.c b/lib/bdev/rbd/blockdev_rbd.c index a89e71127..24e71e419 100644 --- a/lib/bdev/rbd/blockdev_rbd.c +++ b/lib/bdev/rbd/blockdev_rbd.c @@ -71,7 +71,7 @@ struct blockdev_rbd_io_channel { rbd_completion_t *comps; uint32_t queue_depth; struct blockdev_rbd *disk; - struct spdk_poller *poller; + struct spdk_bdev_poller *poller; }; static void @@ -442,8 +442,8 @@ blockdev_rbd_create_cb(void *io_device, void *ctx_buf) goto err; } - spdk_poller_register(&ch->poller, blockdev_rbd_io_poll, ch, - spdk_env_get_current_core(), 0); + spdk_bdev_poller_start(&ch->poller, blockdev_rbd_io_poll, ch, + spdk_env_get_current_core(), 0); return 0; @@ -459,7 +459,7 @@ blockdev_rbd_destroy_cb(void *io_device, void *ctx_buf) blockdev_rbd_free_channel(io_channel); - spdk_poller_unregister(&io_channel->poller, NULL); + spdk_bdev_poller_stop(&io_channel->poller); } static struct spdk_io_channel * diff --git a/lib/event/subsystems/bdev/bdev.c b/lib/event/subsystems/bdev/bdev.c index 252416c07..75f56a9d5 100644 --- a/lib/event/subsystems/bdev/bdev.c +++ b/lib/event/subsystems/bdev/bdev.c @@ -43,10 +43,32 @@ spdk_bdev_initialize_complete(void *cb_arg, int rc) spdk_subsystem_init_next(rc); } +static void +spdk_bdev_subsystem_start_poller(struct spdk_bdev_poller **ppoller, + spdk_bdev_poller_fn fn, + void *arg, + uint32_t lcore, + uint64_t period_microseconds) +{ + spdk_poller_register((struct spdk_poller **)ppoller, + fn, + arg, + lcore, + period_microseconds); +} + +static void +spdk_bdev_subsystem_stop_poller(struct spdk_bdev_poller **ppoller) +{ + spdk_poller_unregister((struct spdk_poller **)ppoller, NULL); +} + static void spdk_bdev_subsystem_initialize(void) { - spdk_bdev_initialize(spdk_bdev_initialize_complete, NULL); + spdk_bdev_initialize(spdk_bdev_initialize_complete, NULL, + spdk_bdev_subsystem_start_poller, + spdk_bdev_subsystem_stop_poller); } static int