Skip to content

Commit 89ea5ce

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: cleanup __blk_mq_sched_dispatch_requests
__blk_mq_sched_dispatch_requests currently has duplicated logic for the cases where requests are on the hctx dispatch list or not. Merge the two with a new need_dispatch variable and remove a few pointless local variables. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Link: https://lore.kernel.org/r/20230413060651.694656-2-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b12e5c6 commit 89ea5ce

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

block/blk-mq-sched.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ static int blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
269269

270270
static int __blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
271271
{
272-
struct request_queue *q = hctx->queue;
273-
const bool has_sched = q->elevator;
274-
int ret = 0;
272+
bool need_dispatch = false;
275273
LIST_HEAD(rq_list);
276274

277275
/*
@@ -300,23 +298,22 @@ static int __blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
300298
*/
301299
if (!list_empty(&rq_list)) {
302300
blk_mq_sched_mark_restart_hctx(hctx);
303-
if (blk_mq_dispatch_rq_list(hctx, &rq_list, 0)) {
304-
if (has_sched)
305-
ret = blk_mq_do_dispatch_sched(hctx);
306-
else
307-
ret = blk_mq_do_dispatch_ctx(hctx);
308-
}
309-
} else if (has_sched) {
310-
ret = blk_mq_do_dispatch_sched(hctx);
311-
} else if (hctx->dispatch_busy) {
312-
/* dequeue request one by one from sw queue if queue is busy */
313-
ret = blk_mq_do_dispatch_ctx(hctx);
301+
if (!blk_mq_dispatch_rq_list(hctx, &rq_list, 0))
302+
return 0;
303+
need_dispatch = true;
314304
} else {
315-
blk_mq_flush_busy_ctxs(hctx, &rq_list);
316-
blk_mq_dispatch_rq_list(hctx, &rq_list, 0);
305+
need_dispatch = hctx->dispatch_busy;
317306
}
318307

319-
return ret;
308+
if (hctx->queue->elevator)
309+
return blk_mq_do_dispatch_sched(hctx);
310+
311+
/* dequeue request one by one from sw queue if queue is busy */
312+
if (need_dispatch)
313+
return blk_mq_do_dispatch_ctx(hctx);
314+
blk_mq_flush_busy_ctxs(hctx, &rq_list);
315+
blk_mq_dispatch_rq_list(hctx, &rq_list, 0);
316+
return 0;
320317
}
321318

322319
void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)

0 commit comments

Comments
 (0)