diff mbox series

[2/5] virtio: add VirtioDeviceClass->get_num_virtqueues()

Message ID 20200116105842.271179-3-stefanha@redhat.com
State New
Headers show
Series virtio: enable blk and scsi multi-queue by default | expand

Commit Message

Stefan Hajnoczi Jan. 16, 2020, 10:58 a.m. UTC
The virtio-pci proxy objects have an "nvectors" qdev property to
allocate MSI vectors.  This property defaults to
DEV_NVECTORS_UNSPECIFIED on multi-queue devices and the final value is
based on the number of virtqueues.

The number of virtqueues is typically calculated like this by the
virtio-pci proxy object:

  num_virtqueues = NUM_FIXED_VIRTQUEUES + conf.num_queues

where conf.num_queues is a qdev property to allocate virtqueues.

Add VirtioDeviceClass->get_num_virtqueues() so that this calculation can
be performed by the device instead of the proxy object.  This removes
knowledge of virtqueue layout from the proxy object and allows the
device to implement other formulas for calculating the number of
virtqueues.

This patch has no use on its own but keeping it separate eases backports
if someone wants the virtio-blk patch but not virtio-scsi, or vice
versa.  The next patch uses this new function to automatically set
conf.num_queues to -smp N for automatic multi-queue configuration.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/hw/virtio/virtio.h | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index b69d517496..048c81fcef 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -163,6 +163,13 @@  typedef struct VirtioDeviceClass {
     int (*post_load)(VirtIODevice *vdev);
     const VMStateDescription *vmsd;
     bool (*primary_unplug_pending)(void *opaque);
+
+    /*
+     * Return the number of virtqueues.  Called by transports that need to
+     * allocate per-virtqueue interrupt resources.  This function may be called
+     * before the device is realized.
+     */
+    uint32_t (*get_num_virtqueues)(VirtIODevice *vdev);
 } VirtioDeviceClass;
 
 void virtio_instance_init_common(Object *proxy_obj, void *data,