Skip to content

Commit ce32496

Browse files
Christoph Hellwigaxboe
authored andcommitted
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: Christoph Hellwig <[email protected]> Reviewed-by: John Garry <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent e7602bb commit ce32496

File tree

14 files changed

+29
-55
lines changed

14 files changed

+29
-55
lines changed

block/blk-mq-debugfs.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,42 +172,25 @@ static int hctx_state_show(void *data, struct seq_file *m)
172172
return 0;
173173
}
174174

175-
#define BLK_TAG_ALLOC_NAME(name) [BLK_TAG_ALLOC_##name] = #name
176-
static const char *const alloc_policy_name[] = {
177-
BLK_TAG_ALLOC_NAME(FIFO),
178-
BLK_TAG_ALLOC_NAME(RR),
179-
};
180-
#undef BLK_TAG_ALLOC_NAME
181-
182175
#define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
183176
static const char *const hctx_flag_name[] = {
184177
HCTX_FLAG_NAME(TAG_QUEUE_SHARED),
185178
HCTX_FLAG_NAME(STACKING),
186179
HCTX_FLAG_NAME(TAG_HCTX_SHARED),
187180
HCTX_FLAG_NAME(BLOCKING),
181+
HCTX_FLAG_NAME(TAG_RR),
188182
HCTX_FLAG_NAME(NO_SCHED_BY_DEFAULT),
189183
};
190184
#undef HCTX_FLAG_NAME
191185

192186
static int hctx_flags_show(void *data, struct seq_file *m)
193187
{
194188
struct blk_mq_hw_ctx *hctx = data;
195-
const int alloc_policy = BLK_MQ_FLAG_TO_ALLOC_POLICY(hctx->flags);
196189

197-
BUILD_BUG_ON(ARRAY_SIZE(hctx_flag_name) !=
198-
BLK_MQ_F_ALLOC_POLICY_START_BIT);
199-
BUILD_BUG_ON(ARRAY_SIZE(alloc_policy_name) != BLK_TAG_ALLOC_MAX);
190+
BUILD_BUG_ON(ARRAY_SIZE(hctx_flag_name) != ilog2(BLK_MQ_F_MAX));
200191

201-
seq_puts(m, "alloc_policy=");
202-
if (alloc_policy < ARRAY_SIZE(alloc_policy_name) &&
203-
alloc_policy_name[alloc_policy])
204-
seq_puts(m, alloc_policy_name[alloc_policy]);
205-
else
206-
seq_printf(m, "%d", alloc_policy);
207-
seq_puts(m, " ");
208-
blk_flags_show(m,
209-
hctx->flags ^ BLK_ALLOC_POLICY_TO_MQ_FLAG(alloc_policy),
210-
hctx_flag_name, ARRAY_SIZE(hctx_flag_name));
192+
blk_flags_show(m, hctx->flags, hctx_flag_name,
193+
ARRAY_SIZE(hctx_flag_name));
211194
seq_puts(m, "\n");
212195
return 0;
213196
}

block/blk-mq-tag.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,10 @@ static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth,
545545
}
546546

547547
struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
548-
unsigned int reserved_tags,
549-
int node, int alloc_policy)
548+
unsigned int reserved_tags, unsigned int flags, int node)
550549
{
551550
unsigned int depth = total_tags - reserved_tags;
552-
bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
551+
bool round_robin = flags & BLK_MQ_F_TAG_RR;
553552
struct blk_mq_tags *tags;
554553

555554
if (total_tags > BLK_MQ_TAG_MAX) {

block/blk-mq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,8 +3476,7 @@ static struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set,
34763476
if (node == NUMA_NO_NODE)
34773477
node = set->numa_node;
34783478

3479-
tags = blk_mq_init_tags(nr_tags, reserved_tags, node,
3480-
BLK_MQ_FLAG_TO_ALLOC_POLICY(set->flags));
3479+
tags = blk_mq_init_tags(nr_tags, reserved_tags, set->flags, node);
34813480
if (!tags)
34823481
return NULL;
34833482

block/blk-mq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ struct blk_mq_alloc_data {
163163
};
164164

165165
struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags,
166-
unsigned int reserved_tags, int node, int alloc_policy);
166+
unsigned int reserved_tags, unsigned int flags, int node);
167167
void blk_mq_free_tags(struct blk_mq_tags *tags);
168168

169169
unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);

drivers/ata/ahci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ extern const struct attribute_group *ahci_sdev_groups[];
396396
.shost_groups = ahci_shost_groups, \
397397
.sdev_groups = ahci_sdev_groups, \
398398
.change_queue_depth = ata_scsi_change_queue_depth, \
399-
.tag_alloc_policy = BLK_TAG_ALLOC_RR, \
399+
.tag_alloc_policy_rr = true, \
400400
.device_configure = ata_scsi_device_configure
401401

402402
extern struct ata_port_operations ahci_ops;

drivers/ata/pata_macio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ static const struct scsi_host_template pata_macio_sht = {
935935
.device_configure = pata_macio_device_configure,
936936
.sdev_groups = ata_common_sdev_groups,
937937
.can_queue = ATA_DEF_QUEUE,
938-
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
938+
.tag_alloc_policy_rr = true,
939939
};
940940

941941
static struct ata_port_operations pata_macio_ops = {

drivers/ata/sata_mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ static const struct scsi_host_template mv6_sht = {
672672
.dma_boundary = MV_DMA_BOUNDARY,
673673
.sdev_groups = ata_ncq_sdev_groups,
674674
.change_queue_depth = ata_scsi_change_queue_depth,
675-
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
675+
.tag_alloc_policy_rr = true,
676676
.device_configure = ata_scsi_device_configure
677677
};
678678

drivers/ata/sata_nv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static const struct scsi_host_template nv_adma_sht = {
385385
.device_configure = nv_adma_device_configure,
386386
.sdev_groups = ata_ncq_sdev_groups,
387387
.change_queue_depth = ata_scsi_change_queue_depth,
388-
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
388+
.tag_alloc_policy_rr = true,
389389
};
390390

391391
static const struct scsi_host_template nv_swncq_sht = {
@@ -396,7 +396,7 @@ static const struct scsi_host_template nv_swncq_sht = {
396396
.device_configure = nv_swncq_device_configure,
397397
.sdev_groups = ata_ncq_sdev_groups,
398398
.change_queue_depth = ata_scsi_change_queue_depth,
399-
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
399+
.tag_alloc_policy_rr = true,
400400
};
401401

402402
/*

drivers/ata/sata_sil24.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ static const struct scsi_host_template sil24_sht = {
378378
.can_queue = SIL24_MAX_CMDS,
379379
.sg_tablesize = SIL24_MAX_SGE,
380380
.dma_boundary = ATA_DMA_BOUNDARY,
381-
.tag_alloc_policy = BLK_TAG_ALLOC_FIFO,
382381
.sdev_groups = ata_ncq_sdev_groups,
383382
.change_queue_depth = ata_scsi_change_queue_depth,
384383
.device_configure = ata_scsi_device_configure

drivers/scsi/hisi_sas/hisi_sas_v3_hw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3345,7 +3345,7 @@ static const struct scsi_host_template sht_v3_hw = {
33453345
.slave_alloc = hisi_sas_slave_alloc,
33463346
.shost_groups = host_v3_hw_groups,
33473347
.sdev_groups = sdev_groups_v3_hw,
3348-
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
3348+
.tag_alloc_policy_rr = true,
33493349
.host_reset = hisi_sas_host_reset,
33503350
.host_tagset = 1,
33513351
.mq_poll = queue_complete_v3_hw,

0 commit comments

Comments
 (0)