diff mbox series

block: Use enum for blk-mq tagset flags

Message ID 20241223104153.857953-1-john.g.garry@oracle.com (mailing list archive)
State New
Headers show
Series block: Use enum for blk-mq tagset flags | expand

Commit Message

John Garry Dec. 23, 2024, 10:41 a.m. UTC
Use an enum for tagset flags, so that they don't need to be manually
renumbered when modified.

Signed-off-by: John Garry <john.g.garry@oracle.com>

Comments

Christoph Hellwig Dec. 23, 2024, 7:27 p.m. UTC | #1
On Mon, Dec 23, 2024 at 10:41:53AM +0000, John Garry wrote:
> Use an enum for tagset flags, so that they don't need to be manually
> renumbered when modified.

They don't need to be renumbered.  Sparse bitfields work just fine
and are a lot simpler and cleaner than the indirection added here.
John Garry Dec. 24, 2024, 7:59 a.m. UTC | #2
On 23/12/2024 19:27, Christoph Hellwig wrote:
> On Mon, Dec 23, 2024 at 10:41:53AM +0000, John Garry wrote:
>> Use an enum for tagset flags, so that they don't need to be manually
>> renumbered when modified.
> 
> They don't need to be renumbered. 

Sure, they don't need to be. But using an auto-numbered enum makes easy 
to catch when we add a flag but don't update the respective debugfs flag 
name structure.

> Sparse bitfields work just fine
> and are a lot simpler and cleaner than the indirection added here.
> 

I don't think that having unused gaps in the bitfields is so neat.

FWIW, this patch could be further improved to remove the ilog2 usage in 
HCTX_FLAG_NAME, which is the only remaining debugfs macro to use this.
diff mbox series

Patch

diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index 4b6b20ccdb53..d00f1cb016fa 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -196,7 +196,7 @@  static int hctx_flags_show(void *data, struct seq_file *m)
 	const int alloc_policy = BLK_MQ_FLAG_TO_ALLOC_POLICY(hctx->flags);
 
 	BUILD_BUG_ON(ARRAY_SIZE(hctx_flag_name) !=
-			BLK_MQ_F_ALLOC_POLICY_START_BIT);
+			BLK_MQ_B_ALLOC_POLICY_START_BIT);
 	BUILD_BUG_ON(ARRAY_SIZE(alloc_policy_name) != BLK_TAG_ALLOC_MAX);
 
 	seq_puts(m, "alloc_policy=");
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 7f6c482ebf54..8ef1a2455490 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -666,33 +666,39 @@  struct blk_mq_ops {
 #endif
 };
 
-/* Keep hctx_flag_name[] in sync with the definitions below */
 enum {
-	BLK_MQ_F_TAG_QUEUE_SHARED = 1 << 1,
+	BLK_MQ_B_TAG_QUEUE_SHARED,
 	/*
 	 * Set when this device requires underlying blk-mq device for
 	 * completing IO:
 	 */
-	BLK_MQ_F_STACKING	= 1 << 2,
-	BLK_MQ_F_TAG_HCTX_SHARED = 1 << 3,
-	BLK_MQ_F_BLOCKING	= 1 << 4,
+	BLK_MQ_B_STACKING,
+	BLK_MQ_B_TAG_HCTX_SHARED,
+	BLK_MQ_B_BLOCKING,
 	/* Do not allow an I/O scheduler to be configured. */
-	BLK_MQ_F_NO_SCHED	= 1 << 5,
-
+	BLK_MQ_B_NO_SCHED,
 	/*
 	 * Select 'none' during queue registration in case of a single hwq
 	 * or shared hwqs instead of 'mq-deadline'.
 	 */
-	BLK_MQ_F_NO_SCHED_BY_DEFAULT	= 1 << 6,
-	BLK_MQ_F_ALLOC_POLICY_START_BIT = 7,
-	BLK_MQ_F_ALLOC_POLICY_BITS = 1,
+	BLK_MQ_B_NO_SCHED_BY_DEFAULT,
+	BLK_MQ_B_ALLOC_POLICY_START_BIT,
+	BLK_MQ_B_ALLOC_POLICY_BITS = 1,
 };
+/* Keep hctx_flag_name[] in sync with the definitions below */
+#define BLK_MQ_F_TAG_QUEUE_SHARED	(1 << BLK_MQ_B_TAG_QUEUE_SHARED)
+#define BLK_MQ_F_STACKING		(1 << BLK_MQ_B_STACKING)
+#define BLK_MQ_F_TAG_HCTX_SHARED	(1 << BLK_MQ_B_TAG_HCTX_SHARED)
+#define BLK_MQ_F_BLOCKING		(1 << BLK_MQ_B_BLOCKING)
+#define BLK_MQ_F_NO_SCHED		(1 << BLK_MQ_B_NO_SCHED)
+#define BLK_MQ_F_NO_SCHED_BY_DEFAULT	(1 << BLK_MQ_B_NO_SCHED_BY_DEFAULT)
+
 #define BLK_MQ_FLAG_TO_ALLOC_POLICY(flags) \
-	((flags >> BLK_MQ_F_ALLOC_POLICY_START_BIT) & \
-		((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1))
+	((flags >> BLK_MQ_B_ALLOC_POLICY_START_BIT) & \
+		((1 << BLK_MQ_B_ALLOC_POLICY_BITS) - 1))
 #define BLK_ALLOC_POLICY_TO_MQ_FLAG(policy) \
-	((policy & ((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1)) \
-		<< BLK_MQ_F_ALLOC_POLICY_START_BIT)
+	((policy & ((1 << BLK_MQ_B_ALLOC_POLICY_BITS) - 1)) \
+		<< BLK_MQ_B_ALLOC_POLICY_START_BIT)
 
 #define BLK_MQ_MAX_DEPTH	(10240)
 #define BLK_MQ_NO_HCTX_IDX	(-1U)