qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 2/5] virtio: add VirtioDeviceClass->get_num_virtqueues()
Date: Thu, 16 Jan 2020 10:58:39 +0000	[thread overview]
Message-ID: <20200116105842.271179-3-stefanha@redhat.com> (raw)
In-Reply-To: <20200116105842.271179-1-stefanha@redhat.com>

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 --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,
-- 
2.24.1



  parent reply	other threads:[~2020-01-16 11:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16 10:58 [PATCH 0/5] virtio: enable blk and scsi multi-queue by default Stefan Hajnoczi
2020-01-16 10:58 ` [PATCH 1/5] virtio-scsi: introduce a constant for fixed virtqueues Stefan Hajnoczi
2020-01-16 10:58 ` Stefan Hajnoczi [this message]
2020-01-16 10:58 ` [PATCH 3/5] virtio-scsi: default num_queues to -smp N Stefan Hajnoczi
2020-01-16 11:53   ` Cornelia Huck
2020-01-16 14:16     ` Stefan Hajnoczi
2020-01-16 15:02       ` Cornelia Huck
2020-01-16 10:58 ` [PATCH 4/5] virtio-blk: " Stefan Hajnoczi
2020-01-16 10:58 ` [PATCH 5/5] vhost-user-blk: " Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200116105842.271179-3-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).