diff mbox series

[1/4] blk-mq-tag: support queue filter in bt_tags_iter()

Message ID 20230821073528.3469210-2-chengming.zhou@linux.dev (mailing list archive)
State New, archived
Headers show
Series blk-mq-tag: remove bt_for_each() | expand

Commit Message

Chengming Zhou Aug. 21, 2023, 7:35 a.m. UTC
From: Chengming Zhou <zhouchengming@bytedance.com>

The only user of bt_for_each() is blk_mq_queue_tag_busy_iter(), which
need to filter queue when iterate the tags. In preparation of removing
bt_for_each(), support queue filter in bt_tags_iter().

The new created __blk_mq_tagset_busy_iter() will be used by the next
patch to iterate requests of only one specified queue.

Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
 block/blk-mq-tag.c | 45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)

Comments

Bart Van Assche Aug. 21, 2023, 7:58 p.m. UTC | #1
On 8/21/23 00:35, chengming.zhou@linux.dev wrote:
> @@ -417,7 +425,23 @@ static void __blk_mq_all_tag_iter(struct blk_mq_tags *tags,
>   void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
>   		void *priv)
>   {
> -	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
> +	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS, NULL);
> +}
> +
> +static void __blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
> +				      busy_tag_iter_fn *fn, void *priv,
> +				      struct request_queue *q)
> +{
> +	unsigned int flags = tagset->flags;
> +	int i, nr_tags;
> +
> +	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
> +
> +	for (i = 0; i < nr_tags; i++) {
> +		if (tagset->tags && tagset->tags[i])
> +			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
> +					      BT_TAG_ITER_STARTED, q);
> +	}
>   }
>   
>   /**
> @@ -436,16 +460,7 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
>   void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
>   		busy_tag_iter_fn *fn, void *priv)
>   {
> -	unsigned int flags = tagset->flags;
> -	int i, nr_tags;
> -
> -	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
> -
> -	for (i = 0; i < nr_tags; i++) {
> -		if (tagset->tags && tagset->tags[i])
> -			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
> -					      BT_TAG_ITER_STARTED);
> -	}
> +	__blk_mq_tagset_busy_iter(tagset, fn, priv, NULL);
>   }
>   EXPORT_SYMBOL(blk_mq_tagset_busy_iter);

One change per patch please. I think the introduction of __blk_mq_tagset_busy_iter()
should be a separate patch instead of happening in this patch.

Thanks,

Bart.
Chengming Zhou Aug. 22, 2023, 2:21 a.m. UTC | #2
On 2023/8/22 03:58, Bart Van Assche wrote:
> On 8/21/23 00:35, chengming.zhou@linux.dev wrote:
>> @@ -417,7 +425,23 @@ static void __blk_mq_all_tag_iter(struct blk_mq_tags *tags,
>>   void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
>>           void *priv)
>>   {
>> -    __blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
>> +    __blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS, NULL);
>> +}
>> +
>> +static void __blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
>> +                      busy_tag_iter_fn *fn, void *priv,
>> +                      struct request_queue *q)
>> +{
>> +    unsigned int flags = tagset->flags;
>> +    int i, nr_tags;
>> +
>> +    nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
>> +
>> +    for (i = 0; i < nr_tags; i++) {
>> +        if (tagset->tags && tagset->tags[i])
>> +            __blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
>> +                          BT_TAG_ITER_STARTED, q);
>> +    }
>>   }
>>     /**
>> @@ -436,16 +460,7 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
>>   void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
>>           busy_tag_iter_fn *fn, void *priv)
>>   {
>> -    unsigned int flags = tagset->flags;
>> -    int i, nr_tags;
>> -
>> -    nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
>> -
>> -    for (i = 0; i < nr_tags; i++) {
>> -        if (tagset->tags && tagset->tags[i])
>> -            __blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
>> -                          BT_TAG_ITER_STARTED);
>> -    }
>> +    __blk_mq_tagset_busy_iter(tagset, fn, priv, NULL);
>>   }
>>   EXPORT_SYMBOL(blk_mq_tagset_busy_iter);
> 
> One change per patch please. I think the introduction of __blk_mq_tagset_busy_iter()
> should be a separate patch instead of happening in this patch.
> 

Yes, it's better. I will put it in a separate patch.

Thanks.
diff mbox series

Patch

diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index cc57e2dd9a0b..75b33ae6acef 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -329,6 +329,7 @@  struct bt_tags_iter_data {
 	busy_tag_iter_fn *fn;
 	void *data;
 	unsigned int flags;
+	struct request_queue *q;
 };
 
 #define BT_TAG_ITER_RESERVED		(1 << 0)
@@ -357,9 +358,13 @@  static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
 	if (!rq)
 		return true;
 
+	if (iter_data->q && iter_data->q != rq->q)
+		goto out;
+
 	if (!(iter_data->flags & BT_TAG_ITER_STARTED) ||
 	    blk_mq_request_started(rq))
 		ret = iter_data->fn(rq, iter_data->data);
+out:
 	if (!iter_static_rqs)
 		blk_mq_put_rq_ref(rq);
 	return ret;
@@ -378,13 +383,15 @@  static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
  * @flags:	BT_TAG_ITER_*
  */
 static void bt_tags_for_each(struct blk_mq_tags *tags, struct sbitmap_queue *bt,
-			     busy_tag_iter_fn *fn, void *data, unsigned int flags)
+			     busy_tag_iter_fn *fn, void *data, unsigned int flags,
+			     struct request_queue *q)
 {
 	struct bt_tags_iter_data iter_data = {
 		.tags = tags,
 		.fn = fn,
 		.data = data,
 		.flags = flags,
+		.q = q,
 	};
 
 	if (tags->rqs)
@@ -392,14 +399,15 @@  static void bt_tags_for_each(struct blk_mq_tags *tags, struct sbitmap_queue *bt,
 }
 
 static void __blk_mq_all_tag_iter(struct blk_mq_tags *tags,
-		busy_tag_iter_fn *fn, void *priv, unsigned int flags)
+		busy_tag_iter_fn *fn, void *priv, unsigned int flags,
+		struct request_queue *q)
 {
 	WARN_ON_ONCE(flags & BT_TAG_ITER_RESERVED);
 
 	if (tags->nr_reserved_tags)
 		bt_tags_for_each(tags, &tags->breserved_tags, fn, priv,
-				 flags | BT_TAG_ITER_RESERVED);
-	bt_tags_for_each(tags, &tags->bitmap_tags, fn, priv, flags);
+				 flags | BT_TAG_ITER_RESERVED, q);
+	bt_tags_for_each(tags, &tags->bitmap_tags, fn, priv, flags, q);
 }
 
 /**
@@ -417,7 +425,23 @@  static void __blk_mq_all_tag_iter(struct blk_mq_tags *tags,
 void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
 		void *priv)
 {
-	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
+	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS, NULL);
+}
+
+static void __blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
+				      busy_tag_iter_fn *fn, void *priv,
+				      struct request_queue *q)
+{
+	unsigned int flags = tagset->flags;
+	int i, nr_tags;
+
+	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
+
+	for (i = 0; i < nr_tags; i++) {
+		if (tagset->tags && tagset->tags[i])
+			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
+					      BT_TAG_ITER_STARTED, q);
+	}
 }
 
 /**
@@ -436,16 +460,7 @@  void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
 void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
 		busy_tag_iter_fn *fn, void *priv)
 {
-	unsigned int flags = tagset->flags;
-	int i, nr_tags;
-
-	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
-
-	for (i = 0; i < nr_tags; i++) {
-		if (tagset->tags && tagset->tags[i])
-			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
-					      BT_TAG_ITER_STARTED);
-	}
+	__blk_mq_tagset_busy_iter(tagset, fn, priv, NULL);
 }
 EXPORT_SYMBOL(blk_mq_tagset_busy_iter);