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

scsi: 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.

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>

authored by

Daniel Wagner and committed by
Jens Axboe
94970cfb 4082c98c

+16 -14
+9 -6
drivers/scsi/megaraid/megaraid_sas_base.c
··· 5971 5971 else 5972 5972 instance->iopoll_q_count = 0; 5973 5973 5974 - num_msix_req = num_online_cpus() + instance->low_latency_index_start; 5974 + num_msix_req = blk_mq_num_online_queues(0) + 5975 + instance->low_latency_index_start; 5975 5976 instance->msix_vectors = min(num_msix_req, 5976 5977 instance->msix_vectors); 5977 5978 ··· 5988 5987 /* Disable Balanced IOPS mode and try realloc vectors */ 5989 5988 instance->perf_mode = MR_LATENCY_PERF_MODE; 5990 5989 instance->low_latency_index_start = 1; 5991 - num_msix_req = num_online_cpus() + instance->low_latency_index_start; 5990 + num_msix_req = blk_mq_num_online_queues(0) + 5991 + instance->low_latency_index_start; 5992 5992 5993 5993 instance->msix_vectors = min(num_msix_req, 5994 5994 instance->msix_vectors); ··· 6245 6243 intr_coalescing = (scratch_pad_1 & MR_INTR_COALESCING_SUPPORT_OFFSET) ? 6246 6244 true : false; 6247 6245 if (intr_coalescing && 6248 - (num_online_cpus() >= MR_HIGH_IOPS_QUEUE_COUNT) && 6246 + (blk_mq_num_online_queues(0) >= MR_HIGH_IOPS_QUEUE_COUNT) && 6249 6247 (instance->msix_vectors == MEGASAS_MAX_MSIX_QUEUES)) 6250 6248 instance->perf_mode = MR_BALANCED_PERF_MODE; 6251 6249 else ··· 6289 6287 else 6290 6288 instance->low_latency_index_start = 1; 6291 6289 6292 - num_msix_req = num_online_cpus() + instance->low_latency_index_start; 6290 + num_msix_req = blk_mq_num_online_queues(0) + 6291 + instance->low_latency_index_start; 6293 6292 6294 6293 instance->msix_vectors = min(num_msix_req, 6295 6294 instance->msix_vectors); ··· 6322 6319 megasas_setup_reply_map(instance); 6323 6320 6324 6321 dev_info(&instance->pdev->dev, 6325 - "current msix/online cpus\t: (%d/%d)\n", 6326 - instance->msix_vectors, (unsigned int)num_online_cpus()); 6322 + "current msix/max num queues\t: (%d/%u)\n", 6323 + instance->msix_vectors, blk_mq_num_online_queues(0)); 6327 6324 dev_info(&instance->pdev->dev, 6328 6325 "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); 6329 6326
+5 -5
drivers/scsi/qla2xxx/qla_isr.c
··· 4533 4533 if (USER_CTRL_IRQ(ha) || !ha->mqiobase) { 4534 4534 /* user wants to control IRQ setting for target mode */ 4535 4535 ret = pci_alloc_irq_vectors(ha->pdev, min_vecs, 4536 - min((u16)ha->msix_count, (u16)(num_online_cpus() + min_vecs)), 4537 - PCI_IRQ_MSIX); 4536 + blk_mq_num_online_queues(ha->msix_count) + min_vecs, 4537 + PCI_IRQ_MSIX); 4538 4538 } else 4539 4539 ret = pci_alloc_irq_vectors_affinity(ha->pdev, min_vecs, 4540 - min((u16)ha->msix_count, (u16)(num_online_cpus() + min_vecs)), 4541 - PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, 4542 - &desc); 4540 + blk_mq_num_online_queues(ha->msix_count) + min_vecs, 4541 + PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, 4542 + &desc); 4543 4543 4544 4544 if (ret < 0) { 4545 4545 ql_log(ql_log_fatal, vha, 0x00c7,
+2 -3
drivers/scsi/smartpqi/smartpqi_init.c
··· 5294 5294 if (is_kdump_kernel()) { 5295 5295 num_queue_groups = 1; 5296 5296 } else { 5297 - int num_cpus; 5298 5297 int max_queue_groups; 5299 5298 5300 5299 max_queue_groups = min(ctrl_info->max_inbound_queues / 2, 5301 5300 ctrl_info->max_outbound_queues - 1); 5302 5301 max_queue_groups = min(max_queue_groups, PQI_MAX_QUEUE_GROUPS); 5303 5302 5304 - num_cpus = num_online_cpus(); 5305 - num_queue_groups = min(num_cpus, ctrl_info->max_msix_vectors); 5303 + num_queue_groups = 5304 + blk_mq_num_online_queues(ctrl_info->max_msix_vectors); 5306 5305 num_queue_groups = min(num_queue_groups, max_queue_groups); 5307 5306 } 5308 5307