Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

blk-mq: add number of queue calc helper

Add two variants of helper functions that calculate the correct number
of queues to use. Two variants are needed because some drivers base
their maximum number of queues on the possible CPU mask, while others
use the online CPU mask.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Daniel Wagner <wagi@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20250617-isolcpus-queue-counters-v1-2-13923686b54b@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Daniel Wagner and committed by
Jens Axboe
3f27c1de b6139a6a

+42
+40
block/blk-mq-cpumap.c
··· 12 12 #include <linux/cpu.h> 13 13 #include <linux/group_cpus.h> 14 14 #include <linux/device/bus.h> 15 + #include <linux/sched/isolation.h> 15 16 16 17 #include "blk.h" 17 18 #include "blk-mq.h" 19 + 20 + static unsigned int blk_mq_num_queues(const struct cpumask *mask, 21 + unsigned int max_queues) 22 + { 23 + unsigned int num; 24 + 25 + num = cpumask_weight(mask); 26 + return min_not_zero(num, max_queues); 27 + } 28 + 29 + /** 30 + * blk_mq_num_possible_queues - Calc nr of queues for multiqueue devices 31 + * @max_queues: The maximum number of queues the hardware/driver 32 + * supports. If max_queues is 0, the argument is 33 + * ignored. 34 + * 35 + * Calculates the number of queues to be used for a multiqueue 36 + * device based on the number of possible CPUs. 37 + */ 38 + unsigned int blk_mq_num_possible_queues(unsigned int max_queues) 39 + { 40 + return blk_mq_num_queues(cpu_possible_mask, max_queues); 41 + } 42 + EXPORT_SYMBOL_GPL(blk_mq_num_possible_queues); 43 + 44 + /** 45 + * blk_mq_num_online_queues - Calc nr of queues for multiqueue devices 46 + * @max_queues: The maximum number of queues the hardware/driver 47 + * supports. If max_queues is 0, the argument is 48 + * ignored. 49 + * 50 + * Calculates the number of queues to be used for a multiqueue 51 + * device based on the number of online CPUs. 52 + */ 53 + unsigned int blk_mq_num_online_queues(unsigned int max_queues) 54 + { 55 + return blk_mq_num_queues(cpu_online_mask, max_queues); 56 + } 57 + EXPORT_SYMBOL_GPL(blk_mq_num_online_queues); 18 58 19 59 void blk_mq_map_queues(struct blk_mq_queue_map *qmap) 20 60 {
+2
include/linux/blk-mq.h
··· 947 947 void blk_mq_unfreeze_queue_non_owner(struct request_queue *q); 948 948 void blk_freeze_queue_start_non_owner(struct request_queue *q); 949 949 950 + unsigned int blk_mq_num_possible_queues(unsigned int max_queues); 951 + unsigned int blk_mq_num_online_queues(unsigned int max_queues); 950 952 void blk_mq_map_queues(struct blk_mq_queue_map *qmap); 951 953 void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap, 952 954 struct device *dev, unsigned int offset);