* [PATCH] block: Use enum for blk-mq tagset flags
@ 2024-12-23 10:41 John Garry
2024-12-23 19:27 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: John Garry @ 2024-12-23 10:41 UTC (permalink / raw)
To: axboe; +Cc: linux-block, hch, John Garry
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>
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)
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block: Use enum for blk-mq tagset flags
2024-12-23 10:41 [PATCH] block: Use enum for blk-mq tagset flags John Garry
@ 2024-12-23 19:27 ` Christoph Hellwig
2024-12-24 7:59 ` John Garry
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2024-12-23 19:27 UTC (permalink / raw)
To: John Garry; +Cc: axboe, linux-block, hch
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: Use enum for blk-mq tagset flags
2024-12-23 19:27 ` Christoph Hellwig
@ 2024-12-24 7:59 ` John Garry
0 siblings, 0 replies; 3+ messages in thread
From: John Garry @ 2024-12-24 7:59 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: axboe, linux-block
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-24 7:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-23 10:41 [PATCH] block: Use enum for blk-mq tagset flags John Garry
2024-12-23 19:27 ` Christoph Hellwig
2024-12-24 7:59 ` John Garry
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).