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 <james.r.harris@intel.com>
Change-Id: Ifff7d99970510785a1cf30d20b86b3974ce8a106
Reviewed-on: https://review.gerrithub.io/362235
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2017-05-22 10:49:12 -07:00 committed by Ben Walker
parent 7a7593c0d4
commit 0ee9e40406

View File

@ -99,6 +99,12 @@ struct spdk_bdev_channel {
struct spdk_bdev_io_stat stat; 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 #ifdef SPDK_CONFIG_VTUNE
uint64_t start_tsc; uint64_t start_tsc;
uint64_t interval_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; ch = bdev_io->ch->channel;
bdev_io->ch->io_outstanding++;
bdev_io->in_submit_request = true; bdev_io->in_submit_request = true;
bdev->fn_table->submit_request(ch, bdev_io); bdev->fn_table->submit_request(ch, bdev_io);
bdev_io->in_submit_request = false; 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; 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); __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->channel = bdev->fn_table->get_io_channel(bdev->ctxt);
ch->mgmt_channel = spdk_get_io_channel(&g_bdev_mgr); ch->mgmt_channel = spdk_get_io_channel(&g_bdev_mgr);
memset(&ch->stat, 0, sizeof(ch->stat)); memset(&ch->stat, 0, sizeof(ch->stat));
ch->io_outstanding = 0;
#ifdef SPDK_CONFIG_VTUNE #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_small, ch);
_spdk_bdev_abort_io(&mgmt_channel->need_buf_large, 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->channel);
spdk_put_io_channel(ch->mgmt_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; return;
} }
assert(bdev_io->ch->io_outstanding > 0);
bdev_io->ch->io_outstanding--;
if (bdev_io->type == SPDK_BDEV_IO_TYPE_RESET) { if (bdev_io->type == SPDK_BDEV_IO_TYPE_RESET) {
/* Successful reset */ /* Successful reset */
if (status == SPDK_BDEV_IO_STATUS_SUCCESS) { if (status == SPDK_BDEV_IO_STATUS_SUCCESS) {