scst: Use block layer helpers to calculate num of queues

The calculation of the upper limit for queues does not depend solely on
the number of online CPUs; for example, the isolcpus kernel
command-line option must also be considered.

To account for this, the block layer provides a helper function to
retrieve the maximum number of queues. Use it to set an appropriate
upper queue number limit.
This commit is contained in:
Gleb Chesnokov
2025-09-30 18:53:33 +03:00
parent 3960dc87ac
commit 2c69fe018c
7 changed files with 37 additions and 17 deletions

View File

@@ -4108,7 +4108,7 @@ create:
if (dedicated) {
count = 1;
} else if (!cpu_mask) {
count = max_t(int, num_online_cpus(), 2);
count = blk_mq_num_online_queues(2);
} else {
count = 0;
for_each_cpu(i, cpu_mask)

View File

@@ -922,8 +922,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
isert_dev->device_attr = ib_dev->attrs;
#endif
isert_dev->num_cqs = min_t(int, num_online_cpus(),
ib_dev->num_comp_vectors);
isert_dev->num_cqs = blk_mq_num_online_queues(ib_dev->num_comp_vectors);
isert_dev->cq_qps = kcalloc(isert_dev->num_cqs,
sizeof(*isert_dev->cq_qps),

View File

@@ -4628,13 +4628,13 @@ msix_failed:
if (USER_CTRL_IRQ(ha) || !ha->mqiobase) {
/* user wants to control IRQ setting for target mode */
ret = pci_alloc_irq_vectors(ha->pdev, min_vecs,
min((u16)ha->msix_count, (u16)(num_online_cpus() + min_vecs)),
PCI_IRQ_MSIX);
blk_mq_num_online_queues(ha->msix_count) + min_vecs,
PCI_IRQ_MSIX);
} else
ret = pci_alloc_irq_vectors_affinity(ha->pdev, min_vecs,
min((u16)ha->msix_count, (u16)(num_online_cpus() + min_vecs)),
PCI_IRQ_MSIX | PCI_IRQ_AFFINITY,
&desc);
blk_mq_num_online_queues(ha->msix_count) + min_vecs,
PCI_IRQ_MSIX | PCI_IRQ_AFFINITY,
&desc);
#endif
if (ret < 0) {

View File

@@ -1689,7 +1689,7 @@ skip_pio:
/* Max queues are bounded by available msix vectors */
/* queue 0 uses two msix vectors */
if (ql2xmultique_tag) {
cpus = num_online_cpus();
cpus = blk_mq_num_online_queues(0);
ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
(cpus + 1) : (ha->msix_count - 1);
ha->max_req_queues = 2;
@@ -1778,7 +1778,7 @@ qla83xx_iospace_config(struct qla_hw_data *ha)
/* Max queues are bounded by available msix vectors */
/* queue 0 uses two msix vectors */
if (ql2xmultique_tag) {
cpus = num_online_cpus();
cpus = blk_mq_num_online_queues(0);
ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
(cpus + 1) : (ha->msix_count - 1);
ha->max_req_queues = 2;

View File

@@ -237,6 +237,27 @@ void blk_execute_rq_nowait_backport(struct request *rq, bool at_head)
#define blk_execute_rq_nowait blk_execute_rq_nowait_backport
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 17, 0)
static inline unsigned int blk_mq_num_queues(const struct cpumask *mask,
unsigned int max_queues)
{
unsigned int num;
num = cpumask_weight(mask);
return min_not_zero(num, max_queues);
}
static inline unsigned int blk_mq_num_possible_queues(unsigned int max_queues)
{
return blk_mq_num_queues(cpu_possible_mask, max_queues);
}
static inline unsigned int blk_mq_num_online_queues(unsigned int max_queues)
{
return blk_mq_num_queues(cpu_online_mask, max_queues);
}
#endif
/* <linux/blkdev.h> */
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0) && \

View File

@@ -2237,7 +2237,7 @@ static void scst_suspended(struct percpu_ref *ref)
static int __init init_scst(void)
{
int res, i;
int scst_num_cpus;
int num_online_queues;
TRACE_ENTRY();
@@ -2284,16 +2284,16 @@ static int __init init_scst(void)
if (res != 0)
goto out_deinit_threads;
scst_num_cpus = num_online_cpus();
num_online_queues = blk_mq_num_online_queues(0);
/* ToDo: register_cpu_notifier() */
if (scst_threads == 0)
scst_threads = scst_num_cpus;
scst_threads = num_online_queues;
if (scst_threads < 1) {
PRINT_ERROR("scst_threads can not be less than 1");
scst_threads = scst_num_cpus;
scst_threads = num_online_queues;
}
/* Used for rarely used or read-mostly on fast path structures */
@@ -2456,8 +2456,8 @@ static int __init init_scst(void)
(unsigned long)&scst_percpu_infos[i]);
}
TRACE_DBG("%d CPUs found, starting %d threads",
scst_num_cpus, scst_threads);
TRACE_DBG("%d online queues, starting %d threads",
num_online_queues, scst_threads);
res = scst_start_global_threads(scst_threads);
if (res < 0)

View File

@@ -1445,7 +1445,7 @@ static int scst_local_driver_probe(struct device *dev)
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
hpnt->nr_hw_queues = num_possible_cpus();
hpnt->nr_hw_queues = blk_mq_num_possible_queues(0);
#endif
sess->shost = hpnt;