Skip to content

Commit 9633952

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: factor out a blk_mq_complete_need_ipi helper
Add a helper to decide if we can complete locally or need an IPI. Reviewed-by: Daniel Wagner <dwagner@suse.de> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 4c8fc19 commit 9633952

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

block/blk-mq.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,24 @@ static void __blk_mq_complete_request_remote(void *data)
654654
__blk_mq_complete_request(data);
655655
}
656656

657+
static inline bool blk_mq_complete_need_ipi(struct request *rq)
658+
{
659+
int cpu = raw_smp_processor_id();
660+
661+
if (!IS_ENABLED(CONFIG_SMP) ||
662+
!test_bit(QUEUE_FLAG_SAME_COMP, &rq->q->queue_flags))
663+
return false;
664+
665+
/* same CPU or cache domain? Complete locally */
666+
if (cpu == rq->mq_ctx->cpu ||
667+
(!test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags) &&
668+
cpus_share_cache(cpu, rq->mq_ctx->cpu)))
669+
return false;
670+
671+
/* don't try to IPI to an offline CPU */
672+
return cpu_online(rq->mq_ctx->cpu);
673+
}
674+
657675
/**
658676
* blk_mq_complete_request - end I/O on a request
659677
* @rq: the request being processed
@@ -663,37 +681,22 @@ static void __blk_mq_complete_request_remote(void *data)
663681
**/
664682
void blk_mq_complete_request(struct request *rq)
665683
{
666-
struct blk_mq_ctx *ctx = rq->mq_ctx;
667-
struct request_queue *q = rq->q;
668-
bool shared = false;
669-
int cpu;
670-
671684
WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
672685

673686
/*
674687
* For a polled request, always complete locallly, it's pointless
675688
* to redirect the completion.
676689
*/
677690
if (rq->cmd_flags & REQ_HIPRI) {
678-
q->mq_ops->complete(rq);
679-
return;
680-
}
681-
682-
if (!IS_ENABLED(CONFIG_SMP) ||
683-
!test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags)) {
684-
__blk_mq_complete_request(rq);
691+
rq->q->mq_ops->complete(rq);
685692
return;
686693
}
687694

688-
cpu = raw_smp_processor_id();
689-
if (!test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags))
690-
shared = cpus_share_cache(cpu, ctx->cpu);
691-
692-
if (cpu != ctx->cpu && !shared && cpu_online(ctx->cpu)) {
695+
if (blk_mq_complete_need_ipi(rq)) {
693696
rq->csd.func = __blk_mq_complete_request_remote;
694697
rq->csd.info = rq;
695698
rq->csd.flags = 0;
696-
smp_call_function_single_async(ctx->cpu, &rq->csd);
699+
smp_call_function_single_async(rq->mq_ctx->cpu, &rq->csd);
697700
} else {
698701
__blk_mq_complete_request(rq);
699702
}

0 commit comments

Comments
 (0)