[PATCH 5/9] blk-mq: don't set data->ctx and data->hctx in blk_mq_alloc_request_hctx

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ming Lei <ming.lei@xxxxxxxxxx>

blk_mq_alloc_request_hctx() asks blk-mq to allocate request from a
specified hctx, which is usually bound with fixed cpu mapping, and
request is supposed to be allocated on CPU in hctx->cpumask.

Use smp_call_function_any() to allocate a request on a CPU that is set
in hctx->cpumask and return it in blk_mq_alloc_data instead to prepare
for better CPU hotplug support in blk-mq.

Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx>
[hch: reuse blk_mq_alloc_data for the smp_call_function_any argument]
Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
 block/blk-mq.c | 24 ++++++++++++++++++------
 block/blk-mq.h |  3 +++
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index fcfce666457e2..540b5845cd1d3 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -386,6 +386,20 @@ static struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data)
 	return rq;
 }
 
+static void __blk_mq_alloc_request_cb(void *__data)
+{
+	struct blk_mq_alloc_data *data = __data;
+
+	data->rq = __blk_mq_alloc_request(data);
+}
+
+static struct request *__blk_mq_alloc_request_on_cpumask(const cpumask_t *mask,
+		struct blk_mq_alloc_data *data)
+{
+	smp_call_function_any(mask, __blk_mq_alloc_request_cb, data, 1);
+	return data->rq;
+}
+
 struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
 		blk_mq_req_flags_t flags)
 {
@@ -423,7 +437,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 		.cmd_flags	= op,
 	};
 	struct request *rq;
-	unsigned int cpu;
+	struct blk_mq_hw_ctx *hctx;
 	int ret;
 
 	/*
@@ -447,14 +461,12 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	 * If not tell the caller that it should skip this queue.
 	 */
 	ret = -EXDEV;
-	data.hctx = q->queue_hw_ctx[hctx_idx];
-	if (!blk_mq_hw_queue_mapped(data.hctx))
+	hctx = q->queue_hw_ctx[hctx_idx];
+	if (!blk_mq_hw_queue_mapped(hctx))
 		goto out_queue_exit;
-	cpu = cpumask_first_and(data.hctx->cpumask, cpu_online_mask);
-	data.ctx = __blk_mq_get_ctx(q, cpu);
 
 	ret = -EWOULDBLOCK;
-	rq = __blk_mq_alloc_request(&data);
+	rq = __blk_mq_alloc_request_on_cpumask(hctx->cpumask, &data);
 	if (!rq)
 		goto out_queue_exit;
 	return rq;
diff --git a/block/blk-mq.h b/block/blk-mq.h
index e7d1da4b1f731..82921b30b6afa 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -155,6 +155,9 @@ struct blk_mq_alloc_data {
 	/* input & output parameter */
 	struct blk_mq_ctx *ctx;
 	struct blk_mq_hw_ctx *hctx;
+
+	/* output parameter for __blk_mq_alloc_request_cb */
+	struct request *rq;
 };
 
 static inline struct blk_mq_tags *blk_mq_tags_from_data(struct blk_mq_alloc_data *data)
-- 
2.26.2




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux