Skip to content

Commit

Permalink
blk-mq: factor out a blk_mq_complete_need_ipi helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Jun 24, 2020
1 parent 4c8fc19 commit 9633952
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,24 @@ static void __blk_mq_complete_request_remote(void *data)
__blk_mq_complete_request(data);
}

static inline bool blk_mq_complete_need_ipi(struct request *rq)
{
int cpu = raw_smp_processor_id();

if (!IS_ENABLED(CONFIG_SMP) ||
!test_bit(QUEUE_FLAG_SAME_COMP, &rq->q->queue_flags))
return false;

/* same CPU or cache domain? Complete locally */
if (cpu == rq->mq_ctx->cpu ||
(!test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags) &&
cpus_share_cache(cpu, rq->mq_ctx->cpu)))
return false;

/* don't try to IPI to an offline CPU */
return cpu_online(rq->mq_ctx->cpu);
}

/**
* blk_mq_complete_request - end I/O on a request
* @rq: the request being processed
Expand All @@ -663,37 +681,22 @@ static void __blk_mq_complete_request_remote(void *data)
**/
void blk_mq_complete_request(struct request *rq)
{
struct blk_mq_ctx *ctx = rq->mq_ctx;
struct request_queue *q = rq->q;
bool shared = false;
int cpu;

WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);

/*
* For a polled request, always complete locallly, it's pointless
* to redirect the completion.
*/
if (rq->cmd_flags & REQ_HIPRI) {
q->mq_ops->complete(rq);
return;
}

if (!IS_ENABLED(CONFIG_SMP) ||
!test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags)) {
__blk_mq_complete_request(rq);
rq->q->mq_ops->complete(rq);
return;
}

cpu = raw_smp_processor_id();
if (!test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags))
shared = cpus_share_cache(cpu, ctx->cpu);

if (cpu != ctx->cpu && !shared && cpu_online(ctx->cpu)) {
if (blk_mq_complete_need_ipi(rq)) {
rq->csd.func = __blk_mq_complete_request_remote;
rq->csd.info = rq;
rq->csd.flags = 0;
smp_call_function_single_async(ctx->cpu, &rq->csd);
smp_call_function_single_async(rq->mq_ctx->cpu, &rq->csd);
} else {
__blk_mq_complete_request(rq);
}
Expand Down

0 comments on commit 9633952

Please sign in to comment.