Skip to content

Commit 30a91cb

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: rework I/O completions
Rework I/O completions to work more like the old code path. blk_mq_end_io now stays out of the business of deferring completions to others CPUs and calling blk_mark_rq_complete. The latter is very important to allow completing requests that have timed out and thus are already marked completed, the former allows using the IPI callout even for driver specific completions instead of having to reimplement them. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent c4540a7 commit 30a91cb

4 files changed

Lines changed: 37 additions & 24 deletions

File tree

‎block/blk-mq.c‎

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static void blk_mq_bio_endio(struct request *rq, struct bio *bio, int error)
326326
bio_endio(bio, error);
327327
}
328328

329-
void blk_mq_complete_request(struct request *rq, int error)
329+
void blk_mq_end_io(struct request *rq, int error)
330330
{
331331
struct bio *bio = rq->bio;
332332
unsigned int bytes = 0;
@@ -351,46 +351,53 @@ void blk_mq_complete_request(struct request *rq, int error)
351351
else
352352
blk_mq_free_request(rq);
353353
}
354+
EXPORT_SYMBOL(blk_mq_end_io);
354355

355-
void __blk_mq_end_io(struct request *rq, int error)
356-
{
357-
if (!blk_mark_rq_complete(rq))
358-
blk_mq_complete_request(rq, error);
359-
}
360-
361-
static void blk_mq_end_io_remote(void *data)
356+
static void __blk_mq_complete_request_remote(void *data)
362357
{
363358
struct request *rq = data;
364359

365-
__blk_mq_end_io(rq, rq->errors);
360+
rq->q->softirq_done_fn(rq);
366361
}
367362

368-
/*
369-
* End IO on this request on a multiqueue enabled driver. We'll either do
370-
* it directly inline, or punt to a local IPI handler on the matching
371-
* remote CPU.
372-
*/
373-
void blk_mq_end_io(struct request *rq, int error)
363+
void __blk_mq_complete_request(struct request *rq)
374364
{
375365
struct blk_mq_ctx *ctx = rq->mq_ctx;
376366
int cpu;
377367

378-
if (!ctx->ipi_redirect)
379-
return __blk_mq_end_io(rq, error);
368+
if (!ctx->ipi_redirect) {
369+
rq->q->softirq_done_fn(rq);
370+
return;
371+
}
380372

381373
cpu = get_cpu();
382374
if (cpu != ctx->cpu && cpu_online(ctx->cpu)) {
383-
rq->errors = error;
384-
rq->csd.func = blk_mq_end_io_remote;
375+
rq->csd.func = __blk_mq_complete_request_remote;
385376
rq->csd.info = rq;
386377
rq->csd.flags = 0;
387378
__smp_call_function_single(ctx->cpu, &rq->csd, 0);
388379
} else {
389-
__blk_mq_end_io(rq, error);
380+
rq->q->softirq_done_fn(rq);
390381
}
391382
put_cpu();
392383
}
393-
EXPORT_SYMBOL(blk_mq_end_io);
384+
385+
/**
386+
* blk_mq_complete_request - end I/O on a request
387+
* @rq: the request being processed
388+
*
389+
* Description:
390+
* Ends all I/O on a request. It does not handle partial completions.
391+
* The actual completion happens out-of-order, through a IPI handler.
392+
**/
393+
void blk_mq_complete_request(struct request *rq)
394+
{
395+
if (unlikely(blk_should_fake_timeout(rq->q)))
396+
return;
397+
if (!blk_mark_rq_complete(rq))
398+
__blk_mq_complete_request(rq);
399+
}
400+
EXPORT_SYMBOL(blk_mq_complete_request);
394401

395402
static void blk_mq_start_request(struct request *rq)
396403
{
@@ -1399,6 +1406,9 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_reg *reg,
13991406
if (reg->timeout)
14001407
blk_queue_rq_timeout(q, reg->timeout);
14011408

1409+
if (reg->ops->complete)
1410+
blk_queue_softirq_done(q, reg->ops->complete);
1411+
14021412
blk_mq_init_flush(q);
14031413
blk_mq_init_cpu_queues(q, reg->nr_hw_queues);
14041414

‎block/blk-mq.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ struct blk_mq_ctx {
2222
struct kobject kobj;
2323
};
2424

25-
void __blk_mq_end_io(struct request *rq, int error);
26-
void blk_mq_complete_request(struct request *rq, int error);
25+
void __blk_mq_complete_request(struct request *rq);
2726
void blk_mq_run_request(struct request *rq, bool run_queue, bool async);
2827
void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
2928
void blk_mq_init_flush(struct request_queue *q);

‎block/blk-timeout.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void blk_rq_timed_out(struct request *req)
9191
case BLK_EH_HANDLED:
9292
/* Can we use req->errors here? */
9393
if (q->mq_ops)
94-
blk_mq_complete_request(req, req->errors);
94+
__blk_mq_complete_request(req);
9595
else
9696
__blk_complete_request(req);
9797
break;

‎include/linux/blk-mq.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct blk_mq_ops {
8686
*/
8787
rq_timed_out_fn *timeout;
8888

89+
softirq_done_fn *complete;
90+
8991
/*
9092
* Override for hctx allocations (should probably go)
9193
*/
@@ -137,6 +139,8 @@ void blk_mq_free_single_hw_queue(struct blk_mq_hw_ctx *, unsigned int);
137139

138140
void blk_mq_end_io(struct request *rq, int error);
139141

142+
void blk_mq_complete_request(struct request *rq);
143+
140144
void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx);
141145
void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx);
142146
void blk_mq_stop_hw_queues(struct request_queue *q);

0 commit comments

Comments
 (0)