virtio: allow drivers to request IRQ affinity when creating VQs
Add a struct irq_affinity pointer to the find_vqs methods, which if set is used to tell the PCI layer to create the MSI-X vectors for our I/O virtqueues with the proper affinity from the start. Compared to after the fact affinity hints this gives us an instantly working setup and allows to allocate the irq descritors node-local and avoid interconnect traffic. Last but not least this will allow blk-mq queues are created based on the interrupt affinity for storage drivers. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:

committed by
Michael S. Tsirkin

parent
52a6151612
commit
fb5e31d970
@@ -143,22 +143,28 @@ void vp_del_vqs(struct virtio_device *vdev)
|
||||
|
||||
static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
|
||||
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
||||
const char * const names[])
|
||||
const char * const names[], struct irq_affinity *desc)
|
||||
{
|
||||
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
|
||||
const char *name = dev_name(&vp_dev->vdev.dev);
|
||||
int i, err = -ENOMEM, allocated_vectors, nvectors;
|
||||
unsigned flags = PCI_IRQ_MSIX;
|
||||
bool shared = false;
|
||||
u16 msix_vec;
|
||||
|
||||
if (desc) {
|
||||
flags |= PCI_IRQ_AFFINITY;
|
||||
desc->pre_vectors++; /* virtio config vector */
|
||||
}
|
||||
|
||||
nvectors = 1;
|
||||
for (i = 0; i < nvqs; i++)
|
||||
if (callbacks[i])
|
||||
nvectors++;
|
||||
|
||||
/* Try one vector per queue first. */
|
||||
err = pci_alloc_irq_vectors(vp_dev->pci_dev, nvectors, nvectors,
|
||||
PCI_IRQ_MSIX);
|
||||
err = pci_alloc_irq_vectors_affinity(vp_dev->pci_dev, nvectors,
|
||||
nvectors, flags, desc);
|
||||
if (err < 0) {
|
||||
/* Fallback to one vector for config, one shared for queues. */
|
||||
shared = true;
|
||||
@@ -308,13 +314,12 @@ out_remove_vqs:
|
||||
|
||||
/* the config->find_vqs() implementation */
|
||||
int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
|
||||
struct virtqueue *vqs[],
|
||||
vq_callback_t *callbacks[],
|
||||
const char * const names[])
|
||||
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
||||
const char * const names[], struct irq_affinity *desc)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names);
|
||||
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, desc);
|
||||
if (!err)
|
||||
return 0;
|
||||
return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names);
|
||||
|
Reference in New Issue
Block a user