From acf116c6d5cf29811779fe9dc14302cea86cb9b5 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 18 Dec 2020 06:10:56 -0700 Subject: [PATCH] bdev/nvme: run poller more frequently while probe in progress When we do detect new devices, we would like to get them attached as quickly as possible. Controller initialization requires a non-trivial number of admin commands, and when using async probe, it means that after we have detected a new device, it will take many iterations of calling spdk_nvme_probe_poll_async() before the controller is fully attached. So when we are actively probing a probe_ctx, create a new poller that is solely responsible for probing that context at a much higher frequency. Signed-off-by: Jim Harris Change-Id: I72fbe3faef2d72608edb163bd87907902d7c3adc Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5646 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Paul Luse Reviewed-by: Reviewed-by: Changpeng Liu --- module/bdev/nvme/bdev_nvme.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index f54629cd6..ed8ec4f7f 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -130,6 +130,7 @@ static uint64_t g_nvme_hotplug_poll_period_us = NVME_HOTPLUG_POLL_PERIOD_DEFAULT static bool g_nvme_hotplug_enabled = false; static struct spdk_thread *g_bdev_nvme_init_thread; static struct spdk_poller *g_hotplug_poller; +static struct spdk_poller *g_hotplug_probe_poller; static struct spdk_nvme_probe_ctx *g_hotplug_probe_ctx; static void nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, @@ -1666,26 +1667,35 @@ remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr) _nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr); } +static int +bdev_nvme_hotplug_probe(void *arg) +{ + if (spdk_nvme_probe_poll_async(g_hotplug_probe_ctx) != -EAGAIN) { + g_hotplug_probe_ctx = NULL; + spdk_poller_unregister(&g_hotplug_probe_poller); + } + + return SPDK_POLLER_BUSY; +} + static int bdev_nvme_hotplug(void *arg) { struct spdk_nvme_transport_id trid_pcie; - int done; - if (!g_hotplug_probe_ctx) { - memset(&trid_pcie, 0, sizeof(trid_pcie)); - spdk_nvme_trid_populate_transport(&trid_pcie, SPDK_NVME_TRANSPORT_PCIE); - - g_hotplug_probe_ctx = spdk_nvme_probe_async(&trid_pcie, NULL, - hotplug_probe_cb, attach_cb, NULL); - if (!g_hotplug_probe_ctx) { - return SPDK_POLLER_BUSY; - } + if (g_hotplug_probe_ctx) { + return SPDK_POLLER_BUSY; } - done = spdk_nvme_probe_poll_async(g_hotplug_probe_ctx); - if (done != -EAGAIN) { - g_hotplug_probe_ctx = NULL; + memset(&trid_pcie, 0, sizeof(trid_pcie)); + spdk_nvme_trid_populate_transport(&trid_pcie, SPDK_NVME_TRANSPORT_PCIE); + + g_hotplug_probe_ctx = spdk_nvme_probe_async(&trid_pcie, NULL, + hotplug_probe_cb, attach_cb, NULL); + + if (g_hotplug_probe_ctx) { + assert(g_hotplug_probe_poller == NULL); + g_hotplug_probe_poller = SPDK_POLLER_REGISTER(bdev_nvme_hotplug_probe, NULL, 1000); } return SPDK_POLLER_BUSY;