Commit ce32496e authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

block: simplify tag allocation policy selection



Use a plain BLK_MQ_F_* flag to select the round robin tag selection
instead of overlaying an enum with just two possible values into the
flags space.

Doing so allows adding a BLK_MQ_F_MAX sentinel for simplified overflow
checking in the messy debugfs helpers.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20250106083531.799976-5-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e7602bb4
Loading
Loading
Loading
Loading
+4 −21
Original line number Diff line number Diff line
@@ -172,19 +172,13 @@ static int hctx_state_show(void *data, struct seq_file *m)
	return 0;
}

#define BLK_TAG_ALLOC_NAME(name) [BLK_TAG_ALLOC_##name] = #name
static const char *const alloc_policy_name[] = {
	BLK_TAG_ALLOC_NAME(FIFO),
	BLK_TAG_ALLOC_NAME(RR),
};
#undef BLK_TAG_ALLOC_NAME

#define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
static const char *const hctx_flag_name[] = {
	HCTX_FLAG_NAME(TAG_QUEUE_SHARED),
	HCTX_FLAG_NAME(STACKING),
	HCTX_FLAG_NAME(TAG_HCTX_SHARED),
	HCTX_FLAG_NAME(BLOCKING),
	HCTX_FLAG_NAME(TAG_RR),
	HCTX_FLAG_NAME(NO_SCHED_BY_DEFAULT),
};
#undef HCTX_FLAG_NAME
@@ -192,22 +186,11 @@ static const char *const hctx_flag_name[] = {
static int hctx_flags_show(void *data, struct seq_file *m)
{
	struct blk_mq_hw_ctx *hctx = data;
	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);
	BUILD_BUG_ON(ARRAY_SIZE(alloc_policy_name) != BLK_TAG_ALLOC_MAX);
	BUILD_BUG_ON(ARRAY_SIZE(hctx_flag_name) != ilog2(BLK_MQ_F_MAX));

	seq_puts(m, "alloc_policy=");
	if (alloc_policy < ARRAY_SIZE(alloc_policy_name) &&
	    alloc_policy_name[alloc_policy])
		seq_puts(m, alloc_policy_name[alloc_policy]);
	else
		seq_printf(m, "%d", alloc_policy);
	seq_puts(m, " ");
	blk_flags_show(m,
		       hctx->flags ^ BLK_ALLOC_POLICY_TO_MQ_FLAG(alloc_policy),
		       hctx_flag_name, ARRAY_SIZE(hctx_flag_name));
	blk_flags_show(m, hctx->flags, hctx_flag_name,
			ARRAY_SIZE(hctx_flag_name));
	seq_puts(m, "\n");
	return 0;
}
+2 −3
Original line number Diff line number Diff line
@@ -545,11 +545,10 @@ static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth,
}

struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
				     unsigned int reserved_tags,
				     int node, int alloc_policy)
		unsigned int reserved_tags, unsigned int flags, int node)
{
	unsigned int depth = total_tags - reserved_tags;
	bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
	bool round_robin = flags & BLK_MQ_F_TAG_RR;
	struct blk_mq_tags *tags;

	if (total_tags > BLK_MQ_TAG_MAX) {
+1 −2
Original line number Diff line number Diff line
@@ -3476,8 +3476,7 @@ static struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set,
	if (node == NUMA_NO_NODE)
		node = set->numa_node;

	tags = blk_mq_init_tags(nr_tags, reserved_tags, node,
				BLK_MQ_FLAG_TO_ALLOC_POLICY(set->flags));
	tags = blk_mq_init_tags(nr_tags, reserved_tags, set->flags, node);
	if (!tags)
		return NULL;

+1 −1
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ struct blk_mq_alloc_data {
};

struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags,
		unsigned int reserved_tags, int node, int alloc_policy);
		unsigned int reserved_tags, unsigned int flags, int node);
void blk_mq_free_tags(struct blk_mq_tags *tags);

unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
+1 −1
Original line number Diff line number Diff line
@@ -396,7 +396,7 @@ extern const struct attribute_group *ahci_sdev_groups[];
	.shost_groups		= ahci_shost_groups,			\
	.sdev_groups		= ahci_sdev_groups,			\
	.change_queue_depth     = ata_scsi_change_queue_depth,		\
	.tag_alloc_policy       = BLK_TAG_ALLOC_RR,             	\
	.tag_alloc_policy_rr	= true,					\
	.device_configure	= ata_scsi_device_configure

extern struct ata_port_operations ahci_ops;
Loading