Skip to content

Commit caf8eb0

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq-sched: move actual dispatching into one helper
So that it becomes easy to support to dispatch from sw queue in the following patch. No functional change. Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com> Reviewed-by: Omar Sandoval <osandov@fb.com> Suggested-by: Christoph Hellwig <hch@lst.de> # for simplifying dispatch logic Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5e3d02b commit caf8eb0

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

block/blk-mq-sched.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,26 @@ static bool blk_mq_sched_restart_hctx(struct blk_mq_hw_ctx *hctx)
8989
return false;
9090
}
9191

92+
static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
93+
{
94+
struct request_queue *q = hctx->queue;
95+
struct elevator_queue *e = q->elevator;
96+
LIST_HEAD(rq_list);
97+
98+
do {
99+
struct request *rq = e->type->ops.mq.dispatch_request(hctx);
100+
101+
if (!rq)
102+
break;
103+
list_add(&rq->queuelist, &rq_list);
104+
} while (blk_mq_dispatch_rq_list(q, &rq_list));
105+
}
106+
92107
void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
93108
{
94109
struct request_queue *q = hctx->queue;
95110
struct elevator_queue *e = q->elevator;
96111
const bool has_sched_dispatch = e && e->type->ops.mq.dispatch_request;
97-
bool do_sched_dispatch = true;
98112
LIST_HEAD(rq_list);
99113

100114
/* RCU or SRCU read lock is needed before checking quiesced flag */
@@ -122,30 +136,21 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
122136
* scheduler, we can no longer merge or sort them. So it's best to
123137
* leave them there for as long as we can. Mark the hw queue as
124138
* needing a restart in that case.
139+
*
140+
* We want to dispatch from the scheduler if there was nothing
141+
* on the dispatch list or we were able to dispatch from the
142+
* dispatch list.
125143
*/
126144
if (!list_empty(&rq_list)) {
127145
blk_mq_sched_mark_restart_hctx(hctx);
128-
do_sched_dispatch = blk_mq_dispatch_rq_list(q, &rq_list);
129-
} else if (!has_sched_dispatch) {
146+
if (blk_mq_dispatch_rq_list(q, &rq_list) && has_sched_dispatch)
147+
blk_mq_do_dispatch_sched(hctx);
148+
} else if (has_sched_dispatch) {
149+
blk_mq_do_dispatch_sched(hctx);
150+
} else {
130151
blk_mq_flush_busy_ctxs(hctx, &rq_list);
131152
blk_mq_dispatch_rq_list(q, &rq_list);
132153
}
133-
134-
/*
135-
* We want to dispatch from the scheduler if there was nothing
136-
* on the dispatch list or we were able to dispatch from the
137-
* dispatch list.
138-
*/
139-
if (do_sched_dispatch && has_sched_dispatch) {
140-
do {
141-
struct request *rq;
142-
143-
rq = e->type->ops.mq.dispatch_request(hctx);
144-
if (!rq)
145-
break;
146-
list_add(&rq->queuelist, &rq_list);
147-
} while (blk_mq_dispatch_rq_list(q, &rq_list));
148-
}
149154
}
150155

151156
bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,

0 commit comments

Comments
 (0)