Skip to content

Update blk-mq-virtio.c #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions block/blk-mq-virtio.c
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down