All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org,
	Christoph Hellwig <hch@infradead.org>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
	Stefan Haberland <sth@linux.vnet.ibm.com>,
	Ming Lei <ming.lei@redhat.com>, Christoph Hellwig <hch@lst.de>
Subject: [PATCH 4/8] blk-mq: introduce blk_mq_hw_queue_first_cpu() to figure out first cpu
Date: Sun,  8 Apr 2018 17:48:10 +0800	[thread overview]
Message-ID: <20180408094814.28953-5-ming.lei@redhat.com> (raw)
In-Reply-To: <20180408094814.28953-1-ming.lei@redhat.com>

This patch introduces helper of blk_mq_hw_queue_first_cpu() for
figuring out the hctx's first cpu, and code duplication can be
avoided.

Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-mq.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index a16efa6f2e7f..e3d02af79010 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1336,6 +1336,15 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
 	hctx_unlock(hctx, srcu_idx);
 }
 
+static inline int blk_mq_first_mapped_cpu(struct blk_mq_hw_ctx *hctx)
+{
+	int cpu = cpumask_first_and(hctx->cpumask, cpu_online_mask);
+
+	if (cpu >= nr_cpu_ids)
+		cpu = cpumask_first(hctx->cpumask);
+	return cpu;
+}
+
 /*
  * It'd be great if the workqueue API had a way to pass
  * in a mask and had some smarts for more clever placement.
@@ -1355,14 +1364,7 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
 		next_cpu = cpumask_next_and(next_cpu, hctx->cpumask,
 				cpu_online_mask);
 		if (next_cpu >= nr_cpu_ids)
-			next_cpu = cpumask_first_and(hctx->cpumask, cpu_online_mask);
-
-		/*
-		 * No online CPU is found, so have to make sure hctx->next_cpu
-		 * is set correctly for not breaking workqueue.
-		 */
-		if (next_cpu >= nr_cpu_ids)
-			next_cpu = cpumask_first(hctx->cpumask);
+			next_cpu = blk_mq_first_mapped_cpu(hctx);
 		hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
 	}
 
@@ -2431,10 +2433,7 @@ static void blk_mq_map_swqueue(struct request_queue *q)
 		/*
 		 * Initialize batch roundrobin counts
 		 */
-		hctx->next_cpu = cpumask_first_and(hctx->cpumask,
-				cpu_online_mask);
-		if (hctx->next_cpu >= nr_cpu_ids)
-			hctx->next_cpu = cpumask_first(hctx->cpumask);
+		hctx->next_cpu = blk_mq_first_mapped_cpu(hctx);
 		hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
 	}
 }
-- 
2.9.5

  parent reply	other threads:[~2018-04-08  9:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-08  9:48 [PATCH 0/8] blk-mq: fix and improve queue mapping Ming Lei
2018-04-08  9:48 ` [PATCH 1/8] blk-mq: make sure that correct hctx->next_cpu is set Ming Lei
2018-04-09 10:04   ` Christoph Hellwig
2018-04-09 11:02   ` Sagi Grimberg
2018-04-08  9:48 ` [PATCH 2/8] blk-mq: don't keep offline CPUs mapped to hctx 0 Ming Lei
2018-04-09 10:04   ` Christoph Hellwig
2018-04-09 11:02   ` Sagi Grimberg
2018-04-08  9:48 ` [PATCH 3/8] blk-mq: avoid to write intermediate result to hctx->next_cpu Ming Lei
2018-04-09 10:05   ` Christoph Hellwig
2018-04-09 11:02   ` Sagi Grimberg
2018-04-08  9:48 ` Ming Lei [this message]
2018-04-09 10:06   ` [PATCH 4/8] blk-mq: introduce blk_mq_hw_queue_first_cpu() to figure out first cpu Christoph Hellwig
2018-04-09 11:02   ` Sagi Grimberg
2018-04-08  9:48 ` [PATCH 5/8] blk-mq: remove blk_mq_delay_queue() Ming Lei
2018-04-09 10:06   ` Christoph Hellwig
2018-04-09 11:03   ` Sagi Grimberg
2018-04-08  9:48 ` [PATCH 6/8] blk-mq: don't check queue mapped in __blk_mq_delay_run_hw_queue() Ming Lei
2018-04-09 10:07   ` Christoph Hellwig
2018-04-09 11:03   ` Sagi Grimberg
2018-04-08  9:48 ` [PATCH 7/8] blk-mq: reimplement blk_mq_hw_queue_mapped Ming Lei
2018-04-09 10:08   ` Christoph Hellwig
2018-04-09 11:03   ` Sagi Grimberg
2018-04-08  9:48 ` [PATCH 8/8] blk-mq: remove code for dealing with remapping queue Ming Lei
2018-04-09 10:09   ` Christoph Hellwig
2018-04-09 11:03   ` Sagi Grimberg
2018-04-09 10:13 ` [PATCH 0/8] blk-mq: fix and improve queue mapping Christian Borntraeger
2018-04-09 15:00 ` Jens Axboe
2018-04-09 15:48 ` Stefan Haberland

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=20180408094814.28953-5-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=borntraeger@de.ibm.com \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=sth@linux.vnet.ibm.com \
    /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.