]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: use block layer helpers to calculate num of queues
authorDaniel Wagner <wagi@kernel.org>
Tue, 17 Jun 2025 13:43:26 +0000 (15:43 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 1 Jul 2025 16:24:19 +0000 (10:24 -0600)
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.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
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-4-13923686b54b@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/scsi/megaraid/megaraid_sas_base.c
drivers/scsi/qla2xxx/qla_isr.c
drivers/scsi/smartpqi/smartpqi_init.c

index 9179f8aee96444d010faa67f3913fa39182d9dcf..615e06fd4ee8e5d1c14ef912460962eacb450c04 100644 (file)
@@ -5971,7 +5971,8 @@ megasas_alloc_irq_vectors(struct megasas_instance *instance)
                else
                        instance->iopoll_q_count = 0;
 
-               num_msix_req = num_online_cpus() + instance->low_latency_index_start;
+               num_msix_req = blk_mq_num_online_queues(0) +
+                       instance->low_latency_index_start;
                instance->msix_vectors = min(num_msix_req,
                                instance->msix_vectors);
 
@@ -5987,7 +5988,8 @@ megasas_alloc_irq_vectors(struct megasas_instance *instance)
                /* Disable Balanced IOPS mode and try realloc vectors */
                instance->perf_mode = MR_LATENCY_PERF_MODE;
                instance->low_latency_index_start = 1;
-               num_msix_req = num_online_cpus() + instance->low_latency_index_start;
+               num_msix_req = blk_mq_num_online_queues(0) +
+                       instance->low_latency_index_start;
 
                instance->msix_vectors = min(num_msix_req,
                                instance->msix_vectors);
@@ -6243,7 +6245,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
                intr_coalescing = (scratch_pad_1 & MR_INTR_COALESCING_SUPPORT_OFFSET) ?
                                                                true : false;
                if (intr_coalescing &&
-                       (num_online_cpus() >= MR_HIGH_IOPS_QUEUE_COUNT) &&
+                       (blk_mq_num_online_queues(0) >= MR_HIGH_IOPS_QUEUE_COUNT) &&
                        (instance->msix_vectors == MEGASAS_MAX_MSIX_QUEUES))
                        instance->perf_mode = MR_BALANCED_PERF_MODE;
                else
@@ -6287,7 +6289,8 @@ static int megasas_init_fw(struct megasas_instance *instance)
                else
                        instance->low_latency_index_start = 1;
 
-               num_msix_req = num_online_cpus() + instance->low_latency_index_start;
+               num_msix_req = blk_mq_num_online_queues(0) +
+                       instance->low_latency_index_start;
 
                instance->msix_vectors = min(num_msix_req,
                                instance->msix_vectors);
@@ -6319,8 +6322,8 @@ static int megasas_init_fw(struct megasas_instance *instance)
        megasas_setup_reply_map(instance);
 
        dev_info(&instance->pdev->dev,
-               "current msix/online cpus\t: (%d/%d)\n",
-               instance->msix_vectors, (unsigned int)num_online_cpus());
+               "current msix/max num queues\t: (%d/%u)\n",
+               instance->msix_vectors, blk_mq_num_online_queues(0));
        dev_info(&instance->pdev->dev,
                "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled");
 
index fe98c76e9be32ff03a1960f366f0d700d1168383..c4c6b5c6658c0734f7ff68bcc31b33dde87296dd 100644 (file)
@@ -4533,13 +4533,13 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
        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);
 
        if (ret < 0) {
                ql_log(ql_log_fatal, vha, 0x00c7,
index 3d40a63e378d792ffc005c51cb2fdbb04e1acc5f..125944941601e683e9aa9d4fc6a346230bef904b 100644 (file)
@@ -5294,15 +5294,14 @@ static void pqi_calculate_queue_resources(struct pqi_ctrl_info *ctrl_info)
        if (is_kdump_kernel()) {
                num_queue_groups = 1;
        } else {
-               int num_cpus;
                int max_queue_groups;
 
                max_queue_groups = min(ctrl_info->max_inbound_queues / 2,
                        ctrl_info->max_outbound_queues - 1);
                max_queue_groups = min(max_queue_groups, PQI_MAX_QUEUE_GROUPS);
 
-               num_cpus = num_online_cpus();
-               num_queue_groups = min(num_cpus, ctrl_info->max_msix_vectors);
+               num_queue_groups =
+                       blk_mq_num_online_queues(ctrl_info->max_msix_vectors);
                num_queue_groups = min(num_queue_groups, max_queue_groups);
        }