From nobody Fri May 17 23:29:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615181554; cv=none; d=zohomail.com; s=zohoarc; b=jYFlm8c+WLTEmLCGwMJeMqe7B661cX8y19k44y5zAx2AfEUKou2mhKrlFigGqJMGeQbjOnrdTbxcqsd6hrLvvoyJ+FWGPHWeBtkCPl+Z+YyvzKEjcO8tn1ACMnHQifEv7vNWldChFtv7PLX7JTLJwaZakG8olmYd4uVZEy6T7+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615181554; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=VQHFbV/TWv31UBvcFVxFe+9CVzlK9XeqXYwAco0Ct9w=; b=gCVCI4WhJ7fpF54qTQGfIlazoQzIWsG7Wo4eQXHq9KR3eOu9bimlqjLN1ey8eaOP0AsWd/MAgW+TGAqiVw+lEIm/O2tKhPPJIu8epH3TAO2VXqHINv9H7qLshbHEjSVTdsQlOi6vCdtxOYdUK5Ov8jkVnaWM/vR/4hz4T0Kj4Kg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615181554431152.6101519257013; Sun, 7 Mar 2021 21:32:34 -0800 (PST) Received: from localhost ([::1]:43596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJ8VN-0005fp-2e for importer@patchew.org; Mon, 08 Mar 2021 00:32:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJ8UF-0004or-FR for qemu-devel@nongnu.org; Mon, 08 Mar 2021 00:31:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lJ8UC-00083k-6V for qemu-devel@nongnu.org; Mon, 08 Mar 2021 00:31:22 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-84e2spzIOQ2x06Ib2dKReQ-1; Mon, 08 Mar 2021 00:31:15 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82A281084C95; Mon, 8 Mar 2021 05:31:14 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-193.pek2.redhat.com [10.72.13.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB7D85D9D3; Mon, 8 Mar 2021 05:31:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615181478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VQHFbV/TWv31UBvcFVxFe+9CVzlK9XeqXYwAco0Ct9w=; b=iEVHPawkuHdDj52VpU9yx81XlwxFMhrH3X04oUFMZW4QrabMKE9W8y2OUoByR75H9M2rtn cDDa4SH/1d0WwNNSgQH0aZgdNxEET+ARNfsT/B36clwHq9DIBsgv+Py5E9NyYRgAzJEhVn 23Shcy8u0GJ9S57WVzhkRJAqDNUZa3o= X-MC-Unique: 84e2spzIOQ2x06Ib2dKReQ-1 From: Jason Wang To: mst@redhat.com Subject: [PATCH] virtio-net: calculating proper msix vectors on init Date: Mon, 8 Mar 2021 13:30:59 +0800 Message-Id: <20210308053059.28753-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , stefanha@redhat.com, ehabkost@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 calculating the number of vectors on realize. Consider we have N queues, the number of vectors needed is 2*N + 2 (#queue pais + 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. Signed-off-by: Jason Wang --- hw/core/machine.c | 1 + hw/virtio/virtio-net-pci.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 4386f57b5c..979133f8b7 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -39,6 +39,7 @@ GlobalProperty hw_compat_5_2[] =3D { { "ICH9-LPC", "smm-compat", "on"}, { "PIIX4_PM", "smm-compat", "on"}, + { "virtio-net-pci", "vectors", "3"}, }; const size_t hw_compat_5_2_len =3D G_N_ELEMENTS(hw_compat_5_2); =20 diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c index 292d13d278..2894c46b66 100644 --- a/hw/virtio/virtio-net-pci.c +++ b/hw/virtio/virtio-net-pci.c @@ -41,7 +41,8 @@ struct VirtIONetPCI { static Property virtio_net_properties[] =3D { DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), - DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -50,6 +51,11 @@ static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_= dev, Error **errp) DeviceState *qdev =3D DEVICE(vpci_dev); VirtIONetPCI *dev =3D VIRTIO_NET_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); + VirtIONet *net =3D VIRTIO_NET(vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D 2 * MAX(net->nic_conf.peers.queues, 1) + 2; + } =20 virtio_net_set_netclient_name(&dev->vdev, qdev->id, object_get_typename(OBJECT(qdev))); --=20 2.24.3 (Apple Git-128)