Linux-Block Archive on lore.kernel.org
 help / color / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: unlisted-recipients:; (no To-header on input)
Cc: linux-block@vger.kernel.org, John Garry <john.garry@huawei.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Hannes Reinecke <hare@suse.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 4/9] blk-mq: merge blk_mq_rq_ctx_init into __blk_mq_alloc_request
Date: Mon, 18 May 2020 08:39:32 +0200
Message-ID: <20200518063937.757218-5-hch@lst.de> (raw)
In-Reply-To: <20200518063937.757218-1-hch@lst.de>

There is no logical split between what gets initialized by which
function, so just merge the two.

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

diff --git a/block/blk-mq.c b/block/blk-mq.c
index ef8f50cdab858..fcfce666457e2 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -270,17 +270,59 @@ static inline bool blk_mq_need_time_stamp(struct request *rq)
 	return (rq->rq_flags & (RQF_IO_STAT | RQF_STATS)) || rq->q->elevator;
 }
 
-static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
-		unsigned int tag, unsigned int op, u64 alloc_time_ns)
+static struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data)
 {
-	struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
-	struct request *rq = tags->static_rqs[tag];
+	struct request_queue *q = data->q;
+	struct elevator_queue *e = q->elevator;
+	struct request *rq;
+	unsigned int tag;
+	bool clear_ctx_on_error = false;
 	req_flags_t rq_flags = 0;
+	u64 alloc_time_ns = 0;
+
+	/* alloc_time includes depth and tag waits */
+	if (blk_queue_rq_alloc_time(q))
+		alloc_time_ns = ktime_get_ns();
+
+	if (likely(!data->ctx)) {
+		data->ctx = blk_mq_get_ctx(q);
+		clear_ctx_on_error = true;
+	}
+	if (likely(!data->hctx))
+		data->hctx = blk_mq_map_queue(q, data->cmd_flags,
+						data->ctx);
+	if (data->cmd_flags & REQ_NOWAIT)
+		data->flags |= BLK_MQ_REQ_NOWAIT;
+
+	if (e) {
+		data->flags |= BLK_MQ_REQ_INTERNAL;
+
+		/*
+		 * Flush requests are special and go directly to the
+		 * dispatch list. Don't include reserved tags in the
+		 * limiting, as it isn't useful.
+		 */
+		if (!op_is_flush(data->cmd_flags) &&
+		    e->type->ops.limit_depth &&
+		    !(data->flags & BLK_MQ_REQ_RESERVED))
+			e->type->ops.limit_depth(data->cmd_flags, data);
+	} else {
+		blk_mq_tag_busy(data->hctx);
+	}
+
+	tag = blk_mq_get_tag(data);
+	if (tag == BLK_MQ_TAG_FAIL) {
+		if (clear_ctx_on_error)
+			data->ctx = NULL;
+		return NULL;
+	}
 
 	if (data->flags & BLK_MQ_REQ_INTERNAL) {
+		rq = data->hctx->sched_tags->static_rqs[tag];
 		rq->tag = -1;
 		rq->internal_tag = tag;
 	} else {
+		rq = data->hctx->tags->static_rqs[tag];
 		if (data->hctx->flags & BLK_MQ_F_TAG_SHARED) {
 			rq_flags = RQF_MQ_INFLIGHT;
 			atomic_inc(&data->hctx->nr_active);
@@ -295,7 +337,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
 	rq->mq_ctx = data->ctx;
 	rq->mq_hctx = data->hctx;
 	rq->rq_flags = rq_flags;
-	rq->cmd_flags = op;
+	rq->cmd_flags = data->cmd_flags;
 	if (data->flags & BLK_MQ_REQ_PREEMPT)
 		rq->rq_flags |= RQF_PREEMPT;
 	if (blk_queue_io_stat(data->q))
@@ -327,58 +369,9 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
 	rq->end_io = NULL;
 	rq->end_io_data = NULL;
 
-	data->ctx->rq_dispatched[op_is_sync(op)]++;
+	data->ctx->rq_dispatched[op_is_sync(data->cmd_flags)]++;
 	refcount_set(&rq->ref, 1);
-	return rq;
-}
-
-static struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data)
-{
-	struct request_queue *q = data->q;
-	struct elevator_queue *e = q->elevator;
-	struct request *rq;
-	unsigned int tag;
-	bool clear_ctx_on_error = false;
-	u64 alloc_time_ns = 0;
-
-	/* alloc_time includes depth and tag waits */
-	if (blk_queue_rq_alloc_time(q))
-		alloc_time_ns = ktime_get_ns();
-
-	if (likely(!data->ctx)) {
-		data->ctx = blk_mq_get_ctx(q);
-		clear_ctx_on_error = true;
-	}
-	if (likely(!data->hctx))
-		data->hctx = blk_mq_map_queue(q, data->cmd_flags,
-						data->ctx);
-	if (data->cmd_flags & REQ_NOWAIT)
-		data->flags |= BLK_MQ_REQ_NOWAIT;
-
-	if (e) {
-		data->flags |= BLK_MQ_REQ_INTERNAL;
-
-		/*
-		 * Flush requests are special and go directly to the
-		 * dispatch list. Don't include reserved tags in the
-		 * limiting, as it isn't useful.
-		 */
-		if (!op_is_flush(data->cmd_flags) &&
-		    e->type->ops.limit_depth &&
-		    !(data->flags & BLK_MQ_REQ_RESERVED))
-			e->type->ops.limit_depth(data->cmd_flags, data);
-	} else {
-		blk_mq_tag_busy(data->hctx);
-	}
-
-	tag = blk_mq_get_tag(data);
-	if (tag == BLK_MQ_TAG_FAIL) {
-		if (clear_ctx_on_error)
-			data->ctx = NULL;
-		return NULL;
-	}
 
-	rq = blk_mq_rq_ctx_init(data, tag, data->cmd_flags, alloc_time_ns);
 	if (!op_is_flush(data->cmd_flags)) {
 		rq->elv.icq = NULL;
 		if (e && e->type->ops.prepare_request) {
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 2b33166b9daf1..e44d56ee435db 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -126,7 +126,7 @@ enum mq_rq_state {
  * Try to put the fields that are referenced together in the same cacheline.
  *
  * If you modify this structure, make sure to update blk_rq_init() and
- * especially blk_mq_rq_ctx_init() to take care of the added fields.
+ * especially __blk_mq_alloc_request() to take care of the added fields.
  */
 struct request {
 	struct request_queue *q;
-- 
2.26.2


  parent reply index

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18  6:39 blk-mq: improvement CPU hotplug (simplified version) v2 Christoph Hellwig
2020-05-18  6:39 ` [PATCH 1/9] blk-mq: split out a __blk_mq_get_driver_tag helper Christoph Hellwig
2020-05-18  6:39 ` [PATCH 2/9] blk-mq: remove the bio argument to ->prepare_request Christoph Hellwig
2020-05-18  6:39 ` [PATCH 3/9] blk-mq: simplify the blk_mq_get_request calling convention Christoph Hellwig
2020-05-18  6:39 ` Christoph Hellwig [this message]
2020-05-18  6:39 ` [PATCH 5/9] blk-mq: don't set data->ctx and data->hctx in blk_mq_alloc_request_hctx Christoph Hellwig
2020-05-18  8:32   ` Thomas Gleixner
2020-05-18  9:31     ` Ming Lei
2020-05-18 10:42       ` Thomas Gleixner
2020-05-18 11:54         ` Ming Lei
2020-05-18 13:16           ` Christoph Hellwig
2020-05-18 14:11             ` Ming Lei
2020-05-18 16:56               ` Christoph Hellwig
2020-05-18 18:38                 ` Thomas Gleixner
2020-05-18 18:45                   ` Christoph Hellwig
2020-05-18 18:59                     ` Thomas Gleixner
2020-05-19  1:54                 ` Ming Lei
2020-05-19 15:30                   ` Christoph Hellwig
2020-05-20  1:18                     ` Ming Lei
2020-05-20  3:04                       ` Ming Lei
2020-05-20  8:03                         ` io_uring vs CPU hotplug, was " Christoph Hellwig
2020-05-20 14:45                           ` Jens Axboe
2020-05-20 15:20                             ` Jens Axboe
2020-05-20 15:31                               ` Christoph Hellwig
2020-05-20 19:41                               ` Thomas Gleixner
2020-05-20 20:18                                 ` Jens Axboe
2020-05-20 22:14                                   ` Thomas Gleixner
2020-05-20 22:40                                     ` Jens Axboe
2020-05-21  2:27                                     ` Ming Lei
2020-05-21  8:13                                       ` Thomas Gleixner
2020-05-21  9:23                                         ` Ming Lei
2020-05-21 18:39                                           ` Thomas Gleixner
2020-05-21 18:45                                             ` Jens Axboe
2020-05-21 20:00                                               ` Thomas Gleixner
2020-05-22  1:57                                             ` Ming Lei
2020-05-18 18:47             ` Thomas Gleixner
2020-05-18 13:18           ` Thomas Gleixner
2020-05-18  6:39 ` [PATCH 6/9] blk-mq: don't set data->ctx and data->hctx in __blk_mq_alloc_request Christoph Hellwig
2020-05-18  6:39 ` [PATCH 7/9] blk-mq: disable preemption during allocating request tag Christoph Hellwig
2020-05-18  6:39 ` [PATCH 8/9] blk-mq: add blk_mq_all_tag_iter Christoph Hellwig
2020-05-18  6:39 ` [PATCH 9/9] blk-mq: drain I/O when all CPUs in a hctx are offline Christoph Hellwig
2020-05-18  8:42   ` John Garry
2020-05-18  9:21     ` Ming Lei
2020-05-18 11:49 ` blk-mq: improvement CPU hotplug (simplified version) v2 John Garry
2020-05-19 15:30   ` Christoph Hellwig
2020-05-19 17:17     ` John Garry
2020-05-20 14:35     ` John Garry

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=20200518063937.757218-5-hch@lst.de \
    --to=hch@lst.de \
    --cc=bvanassche@acm.org \
    --cc=hare@suse.com \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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

Linux-Block Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-block/0 linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ https://lore.kernel.org/linux-block \
		linux-block@vger.kernel.org
	public-inbox-index linux-block

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-block


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git