From patchwork Fri Feb 21 09:05:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 322501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C54542C0327 for ; Fri, 21 Feb 2014 20:06:00 +1100 (EST) Received: from localhost ([::1]:43206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGm3S-0000CF-5u for incoming@patchwork.ozlabs.org; Fri, 21 Feb 2014 04:05:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGm34-0008JU-Ro for qemu-devel@nongnu.org; Fri, 21 Feb 2014 04:05:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGm2y-0007xL-Mp for qemu-devel@nongnu.org; Fri, 21 Feb 2014 04:05:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGm2y-0007xB-2g for qemu-devel@nongnu.org; Fri, 21 Feb 2014 04:05:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1L95PFX003835 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Feb 2014 04:05:26 -0500 Received: from jason-ThinkPad-T430s.redhat.com (vpn1-114-211.nay.redhat.com [10.66.114.211]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1L95M99009923; Fri, 21 Feb 2014 04:05:22 -0500 From: Jason Wang To: aliguori@amazon.com, mst@redhat.com, qemu-devel@nongnu.org Date: Fri, 21 Feb 2014 17:05:19 +0800 Message-Id: <1392973519-5371-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Jason Wang Subject: [Qemu-devel] [PATCH V2] virtio-net: calculate proper msix vectors on init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Cc: Michael S. Tsirkin Signed-off-by: Jason Wang Reviewed-by: Gonglei --- hw/virtio/virtio-pci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 7b91841..3b3b0e2 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -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,11 @@ 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; + } virtio_net_set_config_size(&dev->vdev, vpci_dev->host_features); virtio_net_set_netclient_name(&dev->vdev, qdev->id,