Skip to content

Commit bf09ce5

Browse files
damien-lemoalaxboe
authored andcommitted
mq-deadline: Introduce dispatch helpers
Avoid directly referencing the next_rq and fifo_list arrays using the helper functions deadline_next_request() and deadline_fifo_request() to facilitate changes in the dispatch request selection in __dd_dispatch_request() for zoned block devices. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Bart Van Assche <Bart.VanAssche@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6cc77e9 commit bf09ce5

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

block/mq-deadline.c

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,43 @@ static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
191191
return 0;
192192
}
193193

194+
/*
195+
* For the specified data direction, return the next request to
196+
* dispatch using arrival ordered lists.
197+
*/
198+
static struct request *
199+
deadline_fifo_request(struct deadline_data *dd, int data_dir)
200+
{
201+
if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
202+
return NULL;
203+
204+
if (list_empty(&dd->fifo_list[data_dir]))
205+
return NULL;
206+
207+
return rq_entry_fifo(dd->fifo_list[data_dir].next);
208+
}
209+
210+
/*
211+
* For the specified data direction, return the next request to
212+
* dispatch using sector position sorted lists.
213+
*/
214+
static struct request *
215+
deadline_next_request(struct deadline_data *dd, int data_dir)
216+
{
217+
if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
218+
return NULL;
219+
220+
return dd->next_rq[data_dir];
221+
}
222+
194223
/*
195224
* deadline_dispatch_requests selects the best request according to
196225
* read/write expire, fifo_batch, etc
197226
*/
198227
static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
199228
{
200229
struct deadline_data *dd = hctx->queue->elevator->elevator_data;
201-
struct request *rq;
230+
struct request *rq, *next_rq;
202231
bool reads, writes;
203232
int data_dir;
204233

@@ -214,10 +243,9 @@ static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
214243
/*
215244
* batches are currently reads XOR writes
216245
*/
217-
if (dd->next_rq[WRITE])
218-
rq = dd->next_rq[WRITE];
219-
else
220-
rq = dd->next_rq[READ];
246+
rq = deadline_next_request(dd, WRITE);
247+
if (!rq)
248+
rq = deadline_next_request(dd, READ);
221249

222250
if (rq && dd->batching < dd->fifo_batch)
223251
/* we have a next request are still entitled to batch */
@@ -260,19 +288,20 @@ static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
260288
/*
261289
* we are not running a batch, find best request for selected data_dir
262290
*/
263-
if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) {
291+
next_rq = deadline_next_request(dd, data_dir);
292+
if (deadline_check_fifo(dd, data_dir) || !next_rq) {
264293
/*
265294
* A deadline has expired, the last request was in the other
266295
* direction, or we have run out of higher-sectored requests.
267296
* Start again from the request with the earliest expiry time.
268297
*/
269-
rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
298+
rq = deadline_fifo_request(dd, data_dir);
270299
} else {
271300
/*
272301
* The last req was the same dir and we have a next request in
273302
* sort order. No expired requests so continue on from here.
274303
*/
275-
rq = dd->next_rq[data_dir];
304+
rq = next_rq;
276305
}
277306

278307
dd->batching = 0;

0 commit comments

Comments
 (0)