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 <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/415538
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Ben Walker 2018-06-15 14:54:56 -07:00 committed by Jim Harris
parent 8c6bd59704
commit e051eb8310

View File

@ -71,6 +71,7 @@ struct spdk_fio_ctrlr {
static struct spdk_fio_ctrlr *ctrlr_g; static struct spdk_fio_ctrlr *ctrlr_g;
static int td_count; static int td_count;
static pthread_t g_ctrlr_thread_id = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static bool g_error; 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 static bool
probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
struct spdk_nvme_ctrlr_opts *opts) struct spdk_nvme_ctrlr_opts *opts)
@ -264,6 +303,12 @@ static int spdk_fio_setup(struct thread_data *td)
} }
spdk_env_initialized = true; spdk_env_initialized = true;
spdk_unaffinitize_thread(); 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) { for_each_file(td, f, i) {
@ -573,6 +618,10 @@ static void spdk_fio_cleanup(struct thread_data *td)
free(fio_thread); free(fio_thread);
if (pthread_cancel(g_ctrlr_thread_id) == 0) {
pthread_join(g_ctrlr_thread_id, NULL);
}
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
td_count--; td_count--;
if (td_count == 0) { if (td_count == 0) {