virtio-pci: add virtio_pci_optimal_num_queues() helper
commit1436f32a84c3fda61d0d80302e24d641d3f3f839
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 18 Aug 2020 14:33:44 +0000 (18 15:33 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 27 Aug 2020 12:29:13 +0000 (27 08:29 -0400)
tree7708fd7c4c1c7c01031b9127258cfb8b3d7227c4
parent3d7e78aa7777f052d72ec6070e611767f0db35ce
virtio-pci: add virtio_pci_optimal_num_queues() helper

Multi-queue devices achieve the best performance when each vCPU has a
dedicated queue. This ensures that virtqueue used notifications are
handled on the same vCPU that submitted virtqueue buffers.  When another
vCPU handles the the notification an IPI will be necessary to wake the
submission vCPU and this incurs a performance overhead.

Provide a helper function that virtio-pci devices will use in later
patches to automatically select the optimal number of queues.

The function handles guests with large numbers of CPUs by limiting the
number of queues to fit within the following constraints:
1. The maximum number of MSI-X vectors.
2. The maximum number of virtqueues.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Message-Id: <20200818143348.310613-4-stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/virtio/virtio-pci.c
hw/virtio/virtio-pci.h