All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-block@vger.kernel.org, linux-nvme@lists.infrdead.org
Subject: [PATCH 10/12] blk-mq: add a new blk_mq_complete_request_remote API
Date: Thu, 11 Jun 2020 08:44:50 +0200	[thread overview]
Message-ID: <20200611064452.12353-11-hch@lst.de> (raw)
In-Reply-To: <20200611064452.12353-1-hch@lst.de>

This is a variant of blk_mq_complete_request_remote that only completes
the request if it needs to be bounced to another CPU or a softirq.  If
the request can be completed locally the function returns false and lets
the driver complete it without requring and indirect function call.

Suggestions for a better name welcome.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-mq.c         | 45 ++++++++++++++++++++++++------------------
 include/linux/blk-mq.h |  1 +
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f83c81566de904..31d4bdd5bdb7bd 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -632,8 +632,11 @@ static int blk_softirq_cpu_dead(unsigned int cpu)
 	return 0;
 }
 
-static void __blk_mq_complete_request(struct request *rq)
+
+static void __blk_mq_complete_request_remote(void *data)
 {
+	struct request *rq = data;
+
 	/*
 	 * For most of single queue controllers, there is only one irq vector
 	 * for handling I/O completion, and the only irq's affinity is set
@@ -649,11 +652,6 @@ static void __blk_mq_complete_request(struct request *rq)
 		rq->q->mq_ops->complete(rq);
 }
 
-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();
@@ -672,14 +670,7 @@ static inline bool blk_mq_complete_need_ipi(struct request *rq)
 	return cpu_online(rq->mq_ctx->cpu);
 }
 
-/**
- * blk_mq_complete_request - end I/O on a request
- * @rq:		the request being processed
- *
- * Description:
- *	Complete a request by scheduling the ->complete_rq operation.
- **/
-void blk_mq_complete_request(struct request *rq)
+bool blk_mq_complete_request_remote(struct request *rq)
 {
 	WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
 
@@ -687,10 +678,8 @@ void blk_mq_complete_request(struct request *rq)
 	 * For a polled request, always complete locallly, it's pointless
 	 * to redirect the completion.
 	 */
-	if (rq->cmd_flags & REQ_HIPRI) {
-		rq->q->mq_ops->complete(rq);
-		return;
-	}
+	if (rq->cmd_flags & REQ_HIPRI)
+		return false;
 
 	if (blk_mq_complete_need_ipi(rq)) {
 		rq->csd.func = __blk_mq_complete_request_remote;
@@ -698,8 +687,26 @@ void blk_mq_complete_request(struct request *rq)
 		rq->csd.flags = 0;
 		smp_call_function_single_async(rq->mq_ctx->cpu, &rq->csd);
 	} else {
-		__blk_mq_complete_request(rq);
+		if (rq->q->nr_hw_queues > 1)
+			return false;
+		blk_mq_trigger_softirq(rq);
 	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(blk_mq_complete_request_remote);
+
+/**
+ * blk_mq_complete_request - end I/O on a request
+ * @rq:		the request being processed
+ *
+ * Description:
+ *	Complete a request by scheduling the ->complete_rq operation.
+ **/
+void blk_mq_complete_request(struct request *rq)
+{
+	if (!blk_mq_complete_request_remote(rq))
+		rq->q->mq_ops->complete(rq);
 }
 EXPORT_SYMBOL(blk_mq_complete_request);
 
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 8e6ab766aef76e..1641ec6cd7e551 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -504,6 +504,7 @@ void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list);
 void blk_mq_kick_requeue_list(struct request_queue *q);
 void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs);
 void blk_mq_complete_request(struct request *rq);
+bool blk_mq_complete_request_remote(struct request *rq);
 bool blk_mq_bio_list_merge(struct request_queue *q, struct list_head *list,
 			   struct bio *bio, unsigned int nr_segs);
 bool blk_mq_queue_stopped(struct request_queue *q);
-- 
2.26.2


  parent reply	other threads:[~2020-06-11  6:45 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-11  6:44 blk_mq_complete_request overhaul Christoph Hellwig
2020-06-11  6:44 ` [PATCH 01/12] blk-mq: merge blk-softirq.c into blk-mq.c Christoph Hellwig
2020-06-18 14:35   ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 02/12] blk-mq: factor out a helper to reise the block softirq Christoph Hellwig
2020-06-18 14:34   ` Daniel Wagner
2020-06-18 14:37     ` Daniel Wagner
2020-06-18 14:37       ` Daniel Wagner
2020-06-18 14:50   ` Daniel Wagner
2020-06-18 14:50     ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 03/12] blk-mq: remove raise_blk_irq Christoph Hellwig
2020-06-18 15:02   ` Daniel Wagner
2020-06-18 15:02     ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 04/12] blk-mq: complete polled requests directly Christoph Hellwig
2020-06-18 15:50   ` Daniel Wagner
2020-06-18 15:50     ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 05/12] blk-mq: short cut the IPI path in blk_mq_force_complete_rq for !SMP Christoph Hellwig
2020-06-18 15:52   ` Daniel Wagner
2020-06-18 15:52     ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 06/12] blk-mq: merge the softirq vs non-softirq IPI logic Christoph Hellwig
2020-06-18 16:12   ` Daniel Wagner
2020-06-18 16:12     ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 07/12] blk-mq: move failure injection out of blk_mq_complete_request Christoph Hellwig
2020-06-18 16:18   ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 08/12] blk-mq: remove the get_cpu/put_cpu pair in blk_mq_complete_request Christoph Hellwig
2020-06-18 16:24   ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 09/12] blk-mq: factor out a blk_mq_complete_need_ipi helper Christoph Hellwig
2020-06-18 16:33   ` Daniel Wagner
2020-06-18 16:33     ` Daniel Wagner
2020-06-11  6:44 ` Christoph Hellwig [this message]
2020-06-18 16:39   ` [PATCH 10/12] blk-mq: add a new blk_mq_complete_request_remote API Daniel Wagner
2020-06-18 16:39     ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 11/12] nvme-rdma: factor out a nvme_rdma_end_request helper Christoph Hellwig
2020-06-18 16:42   ` Daniel Wagner
2020-06-11  6:44 ` [PATCH 12/12] nvme: use blk_mq_complete_request_remote to avoid an indirect function call Christoph Hellwig
2020-06-18 16:47   ` Daniel Wagner
2020-06-18 16:47     ` Daniel Wagner
2020-06-18 14:11 ` blk_mq_complete_request overhaul Christoph Hellwig
2020-06-18 14:11   ` Christoph Hellwig
2020-06-18 14:54   ` Jens Axboe
2020-06-18 14:54     ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200611064452.12353-11-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infrdead.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.