Skip to content

Commit eeabc85

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: merge blk_mq_insert_request and blk_mq_run_request
It's almost identical to blk_mq_insert_request, so fold the two into one slightly more generic function by making the flush special case a bit smarted. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 081241e commit eeabc85

5 files changed

Lines changed: 14 additions & 49 deletions

File tree

‎block/blk-exec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
6565
* be resued after dying flag is set
6666
*/
6767
if (q->mq_ops) {
68-
blk_mq_insert_request(q, rq, at_head, true);
68+
blk_mq_insert_request(rq, at_head, true, false);
6969
return;
7070
}
7171

‎block/blk-flush.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static void mq_flush_run(struct work_struct *work)
137137
rq = container_of(work, struct request, mq_flush_work);
138138

139139
memset(&rq->csd, 0, sizeof(rq->csd));
140-
blk_mq_run_request(rq, true, false);
140+
blk_mq_insert_request(rq, false, true, false);
141141
}
142142

143143
static bool blk_flush_queue_rq(struct request *rq)
@@ -411,7 +411,7 @@ void blk_insert_flush(struct request *rq)
411411
if ((policy & REQ_FSEQ_DATA) &&
412412
!(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) {
413413
if (q->mq_ops) {
414-
blk_mq_run_request(rq, false, true);
414+
blk_mq_insert_request(rq, false, false, true);
415415
} else
416416
list_add_tail(&rq->queuelist, &q->queue_head);
417417
return;

‎block/blk-mq.c‎

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -724,61 +724,28 @@ static void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx,
724724
blk_mq_add_timer(rq);
725725
}
726726

727-
void blk_mq_insert_request(struct request_queue *q, struct request *rq,
728-
bool at_head, bool run_queue)
727+
void blk_mq_insert_request(struct request *rq, bool at_head, bool run_queue,
728+
bool async)
729729
{
730+
struct request_queue *q = rq->q;
730731
struct blk_mq_hw_ctx *hctx;
731-
struct blk_mq_ctx *ctx, *current_ctx;
732+
struct blk_mq_ctx *ctx = rq->mq_ctx, *current_ctx;
733+
734+
current_ctx = blk_mq_get_ctx(q);
735+
if (!cpu_online(ctx->cpu))
736+
rq->mq_ctx = ctx = current_ctx;
732737

733-
ctx = rq->mq_ctx;
734738
hctx = q->mq_ops->map_queue(q, ctx->cpu);
735739

736-
if (rq->cmd_flags & (REQ_FLUSH | REQ_FUA)) {
740+
if (rq->cmd_flags & (REQ_FLUSH | REQ_FUA) &&
741+
!(rq->cmd_flags & (REQ_FLUSH_SEQ))) {
737742
blk_insert_flush(rq);
738743
} else {
739-
current_ctx = blk_mq_get_ctx(q);
740-
741-
if (!cpu_online(ctx->cpu)) {
742-
ctx = current_ctx;
743-
hctx = q->mq_ops->map_queue(q, ctx->cpu);
744-
rq->mq_ctx = ctx;
745-
}
746744
spin_lock(&ctx->lock);
747745
__blk_mq_insert_request(hctx, rq, at_head);
748746
spin_unlock(&ctx->lock);
749-
750-
blk_mq_put_ctx(current_ctx);
751747
}
752748

753-
if (run_queue)
754-
__blk_mq_run_hw_queue(hctx);
755-
}
756-
EXPORT_SYMBOL(blk_mq_insert_request);
757-
758-
/*
759-
* This is a special version of blk_mq_insert_request to bypass FLUSH request
760-
* check. Should only be used internally.
761-
*/
762-
void blk_mq_run_request(struct request *rq, bool run_queue, bool async)
763-
{
764-
struct request_queue *q = rq->q;
765-
struct blk_mq_hw_ctx *hctx;
766-
struct blk_mq_ctx *ctx, *current_ctx;
767-
768-
current_ctx = blk_mq_get_ctx(q);
769-
770-
ctx = rq->mq_ctx;
771-
if (!cpu_online(ctx->cpu)) {
772-
ctx = current_ctx;
773-
rq->mq_ctx = ctx;
774-
}
775-
hctx = q->mq_ops->map_queue(q, ctx->cpu);
776-
777-
/* ctx->cpu might be offline */
778-
spin_lock(&ctx->lock);
779-
__blk_mq_insert_request(hctx, rq, false);
780-
spin_unlock(&ctx->lock);
781-
782749
blk_mq_put_ctx(current_ctx);
783750

784751
if (run_queue)

‎block/blk-mq.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ struct blk_mq_ctx {
2323
};
2424

2525
void __blk_mq_complete_request(struct request *rq);
26-
void blk_mq_run_request(struct request *rq, bool run_queue, bool async);
2726
void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
2827
void blk_mq_init_flush(struct request_queue *q);
2928
void blk_mq_drain_queue(struct request_queue *q);

‎include/linux/blk-mq.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ void blk_mq_free_commands(struct request_queue *, void (*free)(void *data, struc
122122

123123
void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule);
124124

125-
void blk_mq_insert_request(struct request_queue *, struct request *,
126-
bool, bool);
125+
void blk_mq_insert_request(struct request *, bool, bool, bool);
127126
void blk_mq_run_queues(struct request_queue *q, bool async);
128127
void blk_mq_free_request(struct request *rq);
129128
bool blk_mq_can_queue(struct blk_mq_hw_ctx *);

0 commit comments

Comments
 (0)