From 0ee9e404069fdc7d528983b0ba0931197a202b66 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Mon, 22 May 2017 10:49:12 -0700 Subject: [PATCH] bdev: keep a count of each channel's outstanding IO There are several possible usages of this information - the first will be related to starting a poller for a bdev channel when there are I/O that need to be retried. Usually we can retry an I/O when a previous I/O completes, but if there are no outstanding I/O, we need to start a poller. This count will help us make that decision. Signed-off-by: Jim Harris Change-Id: Ifff7d99970510785a1cf30d20b86b3974ce8a106 Reviewed-on: https://review.gerrithub.io/362235 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- lib/bdev/bdev.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index d8c94a8c2..d58f67edf 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -99,6 +99,12 @@ struct spdk_bdev_channel { struct spdk_bdev_io_stat stat; + /* + * Count of I/O submitted to bdev module and waiting for completion. + * Incremented before submit_request() is called on an spdk_bdev_io. + */ + uint64_t io_outstanding; + #ifdef SPDK_CONFIG_VTUNE uint64_t start_tsc; uint64_t interval_tsc; @@ -483,6 +489,7 @@ __submit_request(struct spdk_bdev *bdev, struct spdk_bdev_io *bdev_io) ch = bdev_io->ch->channel; + bdev_io->ch->io_outstanding++; bdev_io->in_submit_request = true; bdev->fn_table->submit_request(ch, bdev_io); bdev_io->in_submit_request = false; @@ -509,6 +516,12 @@ spdk_bdev_io_resubmit(struct spdk_bdev_io *bdev_io, struct spdk_bdev *new_bdev) */ bdev_io->gencnt = new_bdev->gencnt; + /* + * This bdev_io was already submitted so decrement io_outstanding to ensure it + * does not get double-counted. + */ + assert(bdev_io->ch->io_outstanding > 0); + bdev_io->ch->io_outstanding--; __submit_request(new_bdev, bdev_io); } @@ -583,6 +596,7 @@ spdk_bdev_channel_create(void *io_device, void *ctx_buf) ch->channel = bdev->fn_table->get_io_channel(bdev->ctxt); ch->mgmt_channel = spdk_get_io_channel(&g_bdev_mgr); memset(&ch->stat, 0, sizeof(ch->stat)); + ch->io_outstanding = 0; #ifdef SPDK_CONFIG_VTUNE { @@ -626,6 +640,7 @@ spdk_bdev_channel_destroy(void *io_device, void *ctx_buf) _spdk_bdev_abort_io(&mgmt_channel->need_buf_small, ch); _spdk_bdev_abort_io(&mgmt_channel->need_buf_large, ch); + assert(ch->io_outstanding == 0); spdk_put_io_channel(ch->channel); spdk_put_io_channel(ch->mgmt_channel); } @@ -1132,6 +1147,8 @@ spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status sta return; } + assert(bdev_io->ch->io_outstanding > 0); + bdev_io->ch->io_outstanding--; if (bdev_io->type == SPDK_BDEV_IO_TYPE_RESET) { /* Successful reset */ if (status == SPDK_BDEV_IO_STATUS_SUCCESS) {