diff --git a/iscsi-scst/kernel/iscsi.c b/iscsi-scst/kernel/iscsi.c index 1e0d11f21..dd3d49704 100644 --- a/iscsi-scst/kernel/iscsi.c +++ b/iscsi-scst/kernel/iscsi.c @@ -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) diff --git a/iscsi-scst/kernel/isert-scst/iser_rdma.c b/iscsi-scst/kernel/isert-scst/iser_rdma.c index 39711068b..6ed53bc86 100644 --- a/iscsi-scst/kernel/isert-scst/iser_rdma.c +++ b/iscsi-scst/kernel/isert-scst/iser_rdma.c @@ -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), diff --git a/qla2x00t-32gbit/qla_isr.c b/qla2x00t-32gbit/qla_isr.c index 913152b7d..7f2eb9c75 100644 --- a/qla2x00t-32gbit/qla_isr.c +++ b/qla2x00t-32gbit/qla_isr.c @@ -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) { diff --git a/qla2x00t/qla_os.c b/qla2x00t/qla_os.c index c2940f659..c06cd8ee6 100644 --- a/qla2x00t/qla_os.c +++ b/qla2x00t/qla_os.c @@ -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; diff --git a/scst/include/backport.h b/scst/include/backport.h index 83a015491..ba9b457f0 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -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 + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0) && \ diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 137ed8348..a10cb69b5 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -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) diff --git a/scst_local/scst_local.c b/scst_local/scst_local.c index 4e833588b..93ffd61e8 100644 --- a/scst_local/scst_local.c +++ b/scst_local/scst_local.c @@ -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;