Skip to content

Commit 3f27c1d

Browse files
igawaxboe
authored andcommitted
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 <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Ming Lei <[email protected]> Signed-off-by: Daniel Wagner <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent b6139a6 commit 3f27c1d

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

block/blk-mq-cpumap.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,50 @@
1212
#include <linux/cpu.h>
1313
#include <linux/group_cpus.h>
1414
#include <linux/device/bus.h>
15+
#include <linux/sched/isolation.h>
1516

1617
#include "blk.h"
1718
#include "blk-mq.h"
1819

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);
58+
1959
void blk_mq_map_queues(struct blk_mq_queue_map *qmap)
2060
{
2161
const struct cpumask *masks;

include/linux/blk-mq.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
947947
void blk_mq_unfreeze_queue_non_owner(struct request_queue *q);
948948
void blk_freeze_queue_start_non_owner(struct request_queue *q);
949949

950+
unsigned int blk_mq_num_possible_queues(unsigned int max_queues);
951+
unsigned int blk_mq_num_online_queues(unsigned int max_queues);
950952
void blk_mq_map_queues(struct blk_mq_queue_map *qmap);
951953
void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,
952954
struct device *dev, unsigned int offset);

0 commit comments

Comments
 (0)