From e051eb8310ef401ad375099c1190264a6cd5ad77 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Fri, 15 Jun 2018 14:54:56 -0700 Subject: [PATCH] fio/nvme: Add a thread to occasionally poll admin qpairs This makes keep alive work correctly during long runs. Change-Id: Idc7277373920b48177a037aefe809e056f83cf10 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/415538 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- examples/nvme/fio_plugin/fio_plugin.c | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index 708fe4ed9..a5196b5a9 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -71,6 +71,7 @@ struct spdk_fio_ctrlr { static struct spdk_fio_ctrlr *ctrlr_g; static int td_count; +static pthread_t g_ctrlr_thread_id = 0; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static bool g_error; @@ -95,6 +96,44 @@ struct spdk_fio_thread { }; +static void * +spdk_fio_poll_ctrlrs(void *arg) +{ + struct spdk_fio_ctrlr *fio_ctrlr; + int oldstate; + int rc; + + /* Loop until the thread is cancelled */ + while (true) { + rc = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); + if (rc != 0) { + SPDK_ERRLOG("Unable to set cancel state disabled on g_init_thread (%d): %s\n", + rc, spdk_strerror(rc)); + } + + pthread_mutex_lock(&mutex); + fio_ctrlr = ctrlr_g; + + while (fio_ctrlr) { + spdk_nvme_ctrlr_process_admin_completions(fio_ctrlr->ctrlr); + fio_ctrlr = fio_ctrlr->next; + } + + pthread_mutex_unlock(&mutex); + + rc = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); + if (rc != 0) { + SPDK_ERRLOG("Unable to set cancel state enabled on g_init_thread (%d): %s\n", + rc, spdk_strerror(rc)); + } + + /* This is a pthread cancellation point and cannot be removed. */ + sleep(1); + } + + return NULL; +} + static bool probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, struct spdk_nvme_ctrlr_opts *opts) @@ -264,6 +303,12 @@ static int spdk_fio_setup(struct thread_data *td) } spdk_env_initialized = true; spdk_unaffinitize_thread(); + + /* Spawn a thread to continue polling the controllers */ + rc = pthread_create(&g_ctrlr_thread_id, NULL, &spdk_fio_poll_ctrlrs, NULL); + if (rc != 0) { + SPDK_ERRLOG("Unable to spawn a thread to poll admin queues. They won't be polled.\n"); + } } for_each_file(td, f, i) { @@ -573,6 +618,10 @@ static void spdk_fio_cleanup(struct thread_data *td) free(fio_thread); + if (pthread_cancel(g_ctrlr_thread_id) == 0) { + pthread_join(g_ctrlr_thread_id, NULL); + } + pthread_mutex_lock(&mutex); td_count--; if (td_count == 0) {