From 40649b005743e98d460edd8c570e238ded14f0a5 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 4 Dec 2015 10:20:57 -0700 Subject: [PATCH] workqueue: properly account ->cur_depth Also handle edge cases better. Signed-off-by: Jens Axboe --- backend.c | 30 ++++++++++++++++++++++++++---- workqueue.c | 6 +++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/backend.c b/backend.c index 4a689eb0..10622efe 100644 --- a/backend.c +++ b/backend.c @@ -1358,16 +1358,38 @@ static void io_workqueue_fn(struct thread_data *td, struct io_u *io_u) td->cur_depth++; - ret = td_io_queue(td, io_u); + do { + ret = td_io_queue(td, io_u); + if (ret != FIO_Q_BUSY) + break; + ret = io_u_queued_complete(td, 1); + if (ret > 0) + td->cur_depth -= ret; + io_u_clear(io_u, IO_U_F_FLIGHT); + } while (1); dprint(FD_RATE, "io_u %p ret %d by %u\n", io_u, ret, gettid()); io_queue_event(td, io_u, &ret, ddir, NULL, 0, NULL); - if (ret == FIO_Q_QUEUED) - ret = io_u_queued_complete(td, 1); + if (ret == FIO_Q_COMPLETED) + td->cur_depth--; + else if (ret == FIO_Q_QUEUED) { + unsigned int min_evts; - td->cur_depth--; + if (td->o.iodepth == 1) + min_evts = 1; + else + min_evts = 0; + + ret = io_u_queued_complete(td, min_evts); + if (ret > 0) + td->cur_depth -= ret; + } else if (ret == FIO_Q_BUSY) { + ret = io_u_queued_complete(td, td->cur_depth); + if (ret > 0) + td->cur_depth -= ret; + } } /* diff --git a/workqueue.c b/workqueue.c index 34423753..27d1060c 100644 --- a/workqueue.c +++ b/workqueue.c @@ -283,8 +283,12 @@ static void *worker_thread(void *data) if (td->io_u_queued || td->cur_depth || td->io_u_in_flight) { + int ret; + pthread_mutex_unlock(&sw->lock); - io_u_quiesce(td); + ret = io_u_quiesce(td); + if (ret > 0) + td->cur_depth -= ret; pthread_mutex_lock(&sw->lock); } -- 2.25.1