Skip to contentSkip to conversation

virtio-net: calculate proper msix vectors on init

PATCH Superseded Jason Wang 2 participants 4 messages Feb 21, 2014 – Feb 24, 2014

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 virtio-net: calculate proper msix vectors on init

Currently, the default msix vectors for virtio-net-pci is 3 which is obvious not suitable for multiqueue guest, so we depends on the user or management tools to pass a correct vectors parameter. In fact, we can simplifying this by calculate the number of vectors on init.

Consider we have N queues, the number of vectors needed is 2*N + 2 (plus one config interrupt and control vq). We didn't check whether or not host support control vq because it was added unconditionally by qemu to avoid breaking legacy guests such as Minix.

Cc Paolo Bonzini <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-pci.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +9 -1
index 7b91841..1dec491 100644
@@ -1416,7 +1416,8 @@ static const TypeInfo virtio_serial_pci_info = {
 static Property virtio_net_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
-    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+                       DEV_NVECTORS_UNSPECIFIED),
     DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
     DEFINE_NIC_PROPERTIES(VirtIONetPCI, vdev.nic_conf),
     DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetPCI, vdev.net_conf),
@@ -1428,6 +1429,13 @@ static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev)
     DeviceState *qdev = DEVICE(vpci_dev);
     VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
+    VirtIONet *net = VIRTIO_NET(&dev->vdev);
+
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = 2 * MAX(net->nic_conf.queues, 1) + 2;
+    }
+
+    fprintf(stderr, "vectors is %d\n", vpci_dev->nvectors);
 
     virtio_net_set_config_size(&dev->vdev, vpci_dev->host_features);
     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
Signature · 1 line
1.8.3.2
author
#1 lore raw
Quoted 10 lines · Jason Wang

Currently, the default msix vectors for virtio-net-pci is 3 which is obvious not suitable for multiqueue guest, so we depends on the user or management tools to pass a correct vectors parameter. In fact, we can simplifying this by calculate the number of vectors on init.

Consider we have N queues, the number of vectors needed is 2*N + 2 (plus one config interrupt and control vq). We didn't check whether or not host support control vq because it was added unconditionally by qemu to avoid breaking legacy guests such as Minix.

Quoted 4 lines
Cc Paolo Bonzini <[email protected]>
Cc Michael S. Tsirkin <[email protected]>

---

Unnecessary debug line was found, will send V2.

#2 lore raw
In reply to Jason Wang
Quoted 32 lines · Jason Wang

Currently, the default msix vectors for virtio-net-pci is 3 which is obvious not suitable for multiqueue guest, so we depends on the user or management tools to pass a correct vectors parameter. In fact, we can simplifying this by calculate the number of vectors on init.

Consider we have N queues, the number of vectors needed is 2*N + 2 (plus one config interrupt and control vq). We didn't check whether or not host support control vq because it was added unconditionally by qemu to avoid breaking legacy guests such as Minix.

Cc Paolo Bonzini <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-pci.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +2 -1
index 7b91841..1dec491 100644
@@ -1416,7 +1416,8 @@ static const TypeInfo virtio_serial_pci_info = {
 static Property virtio_net_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
-    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+                       DEV_NVECTORS_UNSPECIFIED),
     DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
     DEFINE_NIC_PROPERTIES(VirtIONetPCI, vdev.nic_conf),
     DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetPCI, vdev.net_conf),

hw/virtio/virtio-pci.c static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev) · line 1438

Quoted 10 lines
hw/virtio/virtio-pci.c +7 -0
@@ -1428,6 +1429,13 @@ static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev)
     DeviceState *qdev = DEVICE(vpci_dev);
     VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
+    VirtIONet *net = VIRTIO_NET(&dev->vdev);
+
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = 2 * MAX(net->nic_conf.queues, 1) + 2;
+    }
+
+    fprintf(stderr, "vectors is %d\n", vpci_dev->nvectors);

last lin shouldn't be there obviously.

Quoted 5 lines
hw/virtio/virtio-pci.c +0 -0
     virtio_net_set_config_size(&dev->vdev, vpci_dev->host_features);
     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
Signature · 1 line
1.8.3.2
author
#3 lore raw
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Jason Wang

Currently, the default msix vectors for virtio-net-pci is 3 which is obvious not suitable for multiqueue guest, so we depends on the user or management tools to pass a correct vectors parameter. In fact, we can simplifying this by calculate the number of vectors on init.

Consider we have N queues, the number of vectors needed is 2*N + 2 (plus one config interrupt and control vq). We didn't check whether or not host support control vq because it was added unconditionally by qemu to avoid breaking legacy guests such as Minix.

Cc Paolo Bonzini <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-pci.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +2 -1
index 7b91841..1dec491 100644
@@ -1416,7 +1416,8 @@ static const TypeInfo virtio_serial_pci_info = {
 static Property virtio_net_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
-    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+                       DEV_NVECTORS_UNSPECIFIED),
     DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
     DEFINE_NIC_PROPERTIES(VirtIONetPCI, vdev.nic_conf),
     DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetPCI, vdev.net_conf),
@@ -1428,6 +1429,13 @@ static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev)
     DeviceState *qdev = DEVICE(vpci_dev);
     VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
Quoted 8 lines

hw/virtio/virtio-pci.c static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev) · line 1438

Quoted 7 lines
hw/virtio/virtio-pci.c +7 -0
+    VirtIONet *net = VIRTIO_NET(&dev->vdev);
+
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = 2 * MAX(net->nic_conf.queues, 1) + 2;
+    }
+
+    fprintf(stderr, "vectors is %d\n", vpci_dev->nvectors);

last lin shouldn't be there obviously.

True, I've sent V2 to the list, please have a look.

Thanks

Quoted 5 lines
Quoted 5 lines
hw/virtio/virtio-pci.c +0 -0
     virtio_net_set_config_size(&dev->vdev, vpci_dev->host_features);
     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
Signature · 1 line
1.8.3.2