aboutsummaryrefslogtreecommitdiff
path: root/hw/net/virtio-net.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-07-04 11:17:02 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-07-04 11:17:02 +0100
commit0c7a8b9baa744ae4323bb46cb4fe942355beaa85 (patch)
treee28faa62f48d74006d5b1c871ef13a23f4f9bb64 /hw/net/virtio-net.c
parentfd479c60f5766f7fb247ad146b9e3c33d03d2055 (diff)
parentd2f9ca94165b10c51d6d6cae5fe1cadf1ca42076 (diff)
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
pc, acpi, pci, virtio: fixes, cleanups, features, tests Some fixes and cleanups. New tests. Configurable tx queue size for virtio-net. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # gpg: Signature made Mon 03 Jul 2017 20:43:17 BST # gpg: using RSA key 0x281F0DB8D28D5469 # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * remotes/mst/tags/for_upstream: (21 commits) i386/acpi: update expected acpi files virtio-net: fix tx queue size for !vhost-user tests: Add unit tests for the VM Generation ID feature vhost-user: unregister slave req handler at cleanup time vhost: ensure vhost_ops are set before calling iotlb callback intel_iommu: fix migration breakage on mr switch hw/acpi: remove dead acpi code fw_cfg: move setting of FW_CFG_VERSION_DMA bit to fw_cfg_init1() fw_cfg: don't map the fw_cfg IO ports in fw_cfg_io_realize() i386/kvm/pci-assign: Use errp directly rather than local_err i386/kvm/pci-assign: Fix return type of verify_irqchip_kernel() pci: Convert shpc_init() to Error pci: Convert to realize pci: Replace pci_add_capability2() with pci_add_capability() pci: Make errp the last parameter of pci_add_capability() pci: Fix the wrong assertion. pci: Add comment for pci_add_capability2() pci: Clean up error checking in pci_add_capability() intel_iommu: relax iq tail check on VTD_GCMD_QIE enable hw/pci-bridge/dec: Classify the DEC PCI bridge as bridge device ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/net/virtio-net.c')
-rw-r--r--hw/net/virtio-net.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 91eddaf93b..5630a9ec44 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -34,8 +34,11 @@
/* previously fixed value */
#define VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE 256
+#define VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE 256
+
/* for now, only allow larger queues; with virtio-1, guest can downsize */
#define VIRTIO_NET_RX_QUEUE_MIN_SIZE VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE
+#define VIRTIO_NET_TX_QUEUE_MIN_SIZE VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE
/*
* Calculate the number of bytes up to and including the given 'field' of
@@ -495,6 +498,24 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs,
}
}
+static int virtio_net_max_tx_queue_size(VirtIONet *n)
+{
+ NetClientState *peer = n->nic_conf.peers.ncs[0];
+
+ /*
+ * Backends other than vhost-user don't support max queue size.
+ */
+ if (!peer) {
+ return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE;
+ }
+
+ if (peer->info->type != NET_CLIENT_DRIVER_VHOST_USER) {
+ return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE;
+ }
+
+ return VIRTQUEUE_MAX_SIZE;
+}
+
static int peer_attach(VirtIONet *n, int index)
{
NetClientState *nc = qemu_get_subqueue(n->nic, index);
@@ -1508,15 +1529,18 @@ static void virtio_net_add_queue(VirtIONet *n, int index)
n->vqs[index].rx_vq = virtio_add_queue(vdev, n->net_conf.rx_queue_size,
virtio_net_handle_rx);
+
if (n->net_conf.tx && !strcmp(n->net_conf.tx, "timer")) {
n->vqs[index].tx_vq =
- virtio_add_queue(vdev, 256, virtio_net_handle_tx_timer);
+ virtio_add_queue(vdev, n->net_conf.tx_queue_size,
+ virtio_net_handle_tx_timer);
n->vqs[index].tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
virtio_net_tx_timer,
&n->vqs[index]);
} else {
n->vqs[index].tx_vq =
- virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh);
+ virtio_add_queue(vdev, n->net_conf.tx_queue_size,
+ virtio_net_handle_tx_bh);
n->vqs[index].tx_bh = qemu_bh_new(virtio_net_tx_bh, &n->vqs[index]);
}
@@ -1927,6 +1951,17 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
return;
}
+ if (n->net_conf.tx_queue_size < VIRTIO_NET_TX_QUEUE_MIN_SIZE ||
+ n->net_conf.tx_queue_size > VIRTQUEUE_MAX_SIZE ||
+ !is_power_of_2(n->net_conf.tx_queue_size)) {
+ error_setg(errp, "Invalid tx_queue_size (= %" PRIu16 "), "
+ "must be a power of 2 between %d and %d",
+ n->net_conf.tx_queue_size, VIRTIO_NET_TX_QUEUE_MIN_SIZE,
+ VIRTQUEUE_MAX_SIZE);
+ virtio_cleanup(vdev);
+ return;
+ }
+
n->max_queues = MAX(n->nic_conf.peers.queues, 1);
if (n->max_queues * 2 + 1 > VIRTIO_QUEUE_MAX) {
error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
@@ -1947,6 +1982,9 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
error_report("Defaulting to \"bh\"");
}
+ n->net_conf.tx_queue_size = MIN(virtio_net_max_tx_queue_size(n),
+ n->net_conf.tx_queue_size);
+
for (i = 0; i < n->max_queues; i++) {
virtio_net_add_queue(n, i);
}
@@ -2106,6 +2144,8 @@ static Property virtio_net_properties[] = {
DEFINE_PROP_STRING("tx", VirtIONet, net_conf.tx),
DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size,
VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE),
+ DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size,
+ VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE),
DEFINE_PROP_UINT16("host_mtu", VirtIONet, net_conf.mtu, 0),
DEFINE_PROP_BOOL("x-mtu-bypass-backend", VirtIONet, mtu_bypass_backend,
true),