diff mbox

[v2,02/12] blk-mq: Add blk_mq_unique_tag()

Message ID 5433E493.9030304@acm.org (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Bart Van Assche Oct. 7, 2014, 1:03 p.m. UTC
The queuecommand() callback functions in SCSI low-level drivers
need to know which hardware context has been selected by the
block layer. Since this information is not available in the
request structure, and since passing the hctx pointer directly to
the queuecommand callback function would require modification of
all SCSI LLDs, add a function to the block layer that allows to
query the hardware context index.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@canonical.com>
Cc: Sagi Grimberg <sagig@mellanox.com>
---
 block/blk-mq-tag.c     | 27 +++++++++++++++++++++++++++
 block/blk-mq.c         |  2 ++
 include/linux/blk-mq.h | 22 ++++++++++++++++++++++
 3 files changed, 51 insertions(+)

Comments

Christoph Hellwig Oct. 11, 2014, 11:08 a.m. UTC | #1
> +static inline u32 blk_mq_build_unique_tag(int hwq, int tag)
> +{
> +	return (hwq << BLK_MQ_UNIQUE_TAG_BITS) | (tag & BLK_MQ_UNIQUE_TAG_MASK);
> +}

Is there any value in having this as a separate helper?

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bart Van Assche Oct. 13, 2014, 9:21 a.m. UTC | #2
On 10/11/14 13:08, Christoph Hellwig wrote:
>> +static inline u32 blk_mq_build_unique_tag(int hwq, int tag)
>> +{
>> +	return (hwq << BLK_MQ_UNIQUE_TAG_BITS) | (tag & BLK_MQ_UNIQUE_TAG_MASK);
>> +}
>
> Is there any value in having this as a separate helper?

Hello Christoph,

With the approach for block layer tag management proposed in this patch 
series SCSI LLDs no longer need to call this function. This means that 
the blk_mq_build_unique_tag() function can be eliminated by inlining it 
into blk_mq_unique_tag(). Would you like me to rework this patch 
accordingly ?

Bart.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig Oct. 13, 2014, 10:15 a.m. UTC | #3
On Mon, Oct 13, 2014 at 11:21:54AM +0200, Bart Van Assche wrote:
> With the approach for block layer tag management proposed in this patch
> series SCSI LLDs no longer need to call this function. This means that the
> blk_mq_build_unique_tag() function can be eliminated by inlining it into
> blk_mq_unique_tag(). Would you like me to rework this patch accordingly ?

Yes, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sagi Grimberg Oct. 19, 2014, 4:14 p.m. UTC | #4
On 10/13/2014 1:15 PM, Christoph Hellwig wrote:
> On Mon, Oct 13, 2014 at 11:21:54AM +0200, Bart Van Assche wrote:
>> With the approach for block layer tag management proposed in this patch
>> series SCSI LLDs no longer need to call this function. This means that the
>> blk_mq_build_unique_tag() function can be eliminated by inlining it into
>> blk_mq_unique_tag(). Would you like me to rework this patch accordingly ?
>
> Yes, please.
>

With this bit you can add:

Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Martin K. Petersen Oct. 28, 2014, 1:55 a.m. UTC | #5
>>>>> "Bart" == Bart Van Assche <bvanassche@acm.org> writes:

Bart> The queuecommand() callback functions in SCSI low-level drivers
Bart> need to know which hardware context has been selected by the block
Bart> layer. Since this information is not available in the request
Bart> structure, and since passing the hctx pointer directly to the
Bart> queuecommand callback function would require modification of all
Bart> SCSI LLDs, add a function to the block layer that allows to query
Bart> the hardware context index.

I agree with consolidating the two functions. Otherwise OK.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
diff mbox

Patch

diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 88d512f..2c63a2b 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -592,6 +592,33 @@  int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int tdepth)
 	return 0;
 }
 
+/**
+ * blk_mq_unique_tag() - return a tag that is unique queue-wide
+ * @rq: request for which to compute a unique tag
+ *
+ * The tag field in struct request is unique per hardware queue but not over
+ * all hardware queues. Hence this function that returns a tag with the
+ * hardware context index in the upper bits and the per hardware queue tag in
+ * the lower bits.
+ *
+ * Note: When called for a request that queued on a non-multiqueue request
+ * queue, the hardware context index is set to zero.
+ */
+u32 blk_mq_unique_tag(struct request *rq)
+{
+	struct request_queue *q = rq->q;
+	struct blk_mq_hw_ctx *hctx;
+	int hwq = 0;
+
+	if (q->mq_ops) {
+		hctx = q->mq_ops->map_queue(q, rq->mq_ctx->cpu);
+		hwq = hctx->queue_num;
+	}
+
+	return blk_mq_build_unique_tag(hwq, rq->tag);
+}
+EXPORT_SYMBOL(blk_mq_unique_tag);
+
 ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page)
 {
 	char *orig_page = page;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index df8e1e0..bf1959c 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2018,6 +2018,8 @@  static int blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set)
  */
 int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
 {
+	BUILD_BUG_ON(BLK_MQ_MAX_DEPTH > 1 << BLK_MQ_UNIQUE_TAG_BITS);
+
 	if (!set->nr_hw_queues)
 		return -EINVAL;
 	if (!set->queue_depth)
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index eac4f31..6050a23 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -167,6 +167,28 @@  struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
 		gfp_t gfp, bool reserved);
 struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag);
 
+enum {
+	BLK_MQ_UNIQUE_TAG_BITS = 16,
+	BLK_MQ_UNIQUE_TAG_MASK = (1 << BLK_MQ_UNIQUE_TAG_BITS) - 1,
+};
+
+u32 blk_mq_unique_tag(struct request *rq);
+
+static inline u32 blk_mq_build_unique_tag(int hwq, int tag)
+{
+	return (hwq << BLK_MQ_UNIQUE_TAG_BITS) | (tag & BLK_MQ_UNIQUE_TAG_MASK);
+}
+
+static inline u16 blk_mq_unique_tag_to_hwq(u32 unique_tag)
+{
+	return unique_tag >> BLK_MQ_UNIQUE_TAG_BITS;
+}
+
+static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
+{
+	return unique_tag & BLK_MQ_UNIQUE_TAG_MASK;
+}
+
 struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
 struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);