Update blk-mq-virtio.c

Subject: [PATCH] blk-mq: Enhance blk_mq_virtio_map_queues for dynamic vector allocation

The function blk_mq_virtio_map_queues currently assumes that the number of available interrupt vectors in the virtio device is equal to or greater than the number of queues. However, this assumption may not always hold true, especially in scenarios where the number of vectors is less than the number of queues.

This patch enhances blk_mq_virtio_map_queues to support dynamic allocation of interrupt vectors. If the number of available vectors is less than the number of queues, the function now dynamically allocates vectors and assigns queues accordingly.

This enhancement ensures better compatibility and scalability for systems with virtio devices where the number of vectors may be limited.

Signed-off-by: SushilkumarDev   || sushilkumardeveloper@gmail.com
This commit is contained in:
Sushilkumar Yadav 2024-06-04 11:51:39 +05:30 committed by GitHub
parent 2ab7951410
commit 5357213b82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,13 +1,3 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2016 Christoph Hellwig.
*/
#include <linux/device.h>
#include <linux/blk-mq-virtio.h>
#include <linux/virtio_config.h>
#include <linux/module.h>
#include "blk-mq.h"
/**
* blk_mq_virtio_map_queues - provide a default queue mapping for virtio device
* @qmap: CPU to hardware queue map.
@ -16,20 +6,26 @@
*
* This function assumes the virtio device @vdev has at least as many available
* interrupt vectors as @set has queues. It will then query the vector
* corresponding to each queue for it's affinity mask and built queue mapping
* that maps a queue to the CPUs that have irq affinity for the corresponding
* vector.
* corresponding to each queue for its affinity mask and build a queue mapping
* that maps a queue to the CPUs that have IRQ affinity for the corresponding
* vector. If the number of available vectors is less than the number of queues,
* it dynamically allocates vectors and assigns queues accordingly.
*/
void blk_mq_virtio_map_queues(struct blk_mq_queue_map *qmap,
struct virtio_device *vdev, int first_vec)
{
const struct cpumask *mask;
unsigned int queue, cpu;
unsigned int nr_vecs_needed = qmap->nr_queues;
if (!vdev->config->get_vq_affinity)
goto fallback;
for (queue = 0; queue < qmap->nr_queues; queue++) {
// Ensure the virtio device has at least nr_vecs_needed interrupt vectors
if (vdev->config->num_vectors < nr_vecs_needed)
nr_vecs_needed = vdev->config->num_vectors;
for (queue = 0; queue < nr_vecs_needed; queue++) {
mask = vdev->config->get_vq_affinity(vdev, first_vec + queue);
if (!mask)
goto fallback;