From nobody Sat May 4 09:50:24 2024 Delivered-To: importer@patchew.org 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; 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=1579172455; cv=none; d=zohomail.com; s=zohoarc; b=SacEJNrVlCQXhb3cki6it729uL+vOlGjqMwqNOMUs8a47dqJxHgZWDSGHFIqD+/mpBBSf8/W9gcFP+BSMYpMq4CXRng+Atg4yeZ2ilz6d6UbwmbMwAqH5ynFJKGfpt3SmX4jQmYIiW7/PlIBNnPMW2cHW28JmfuDwgNj8qfirJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579172455; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1croXUzum/qSSRlM+s0uaE6Fw2t2Z7a0QNUg85ZvAyo=; b=Z81r5+3pp1yvJr8pOMP0gCk5A7EMf7ITDiZdm2yLJmS5ZctQufqdWUah3K39HmPD1uDUoj71SMf/35VtVnYnyeqAaNEHleC4/R/SlxjGKsrjpSXPXiRjGdmCYqurVbmDMHKeIjdwVmXLM8XBRDtGFTAmNqb96BaUxXujY3r4m/Q= 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 157917245564460.04012565656956; Thu, 16 Jan 2020 03:00:55 -0800 (PST) Received: from localhost ([::1]:39868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2tS-0007ET-33 for importer@patchew.org; Thu, 16 Jan 2020 06:00:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50679) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2rh-0005YZ-R6 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is2re-0008J8-2C for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:05 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:33984 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is2rd-0008I6-TX for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:01 -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-422-oDPQkXAyO1eit8fxX9VFkg-1; Thu, 16 Jan 2020 05:58:57 -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 0B0238010C0; Thu, 16 Jan 2020 10:58:56 +0000 (UTC) Received: from localhost (ovpn-117-207.ams2.redhat.com [10.36.117.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84A4F5D9C9; Thu, 16 Jan 2020 10:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579172340; 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: in-reply-to:in-reply-to:references:references; bh=1croXUzum/qSSRlM+s0uaE6Fw2t2Z7a0QNUg85ZvAyo=; b=TsJiBUu60MNvMiB1gmupsHWMAV9swacEpF/pvsTpvUF4OKpDxTy54+8befS8w855Y5jS8o 1bcJ0FnI69JTvHSb+rIjXU1mRk80seOoRBTrIoA8WbFNwIzVn9FZAsMBW6CqR4ot7y0prC 478EVG2VKew8ySWSdryQ4IRxhvIZJU0= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 1/5] virtio-scsi: introduce a constant for fixed virtqueues Date: Thu, 16 Jan 2020 10:58:38 +0000 Message-Id: <20200116105842.271179-2-stefanha@redhat.com> In-Reply-To: <20200116105842.271179-1-stefanha@redhat.com> References: <20200116105842.271179-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: oDPQkXAyO1eit8fxX9VFkg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: Fam Zheng , Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Max Reitz , Paolo Bonzini 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" The event and control virtqueues are always present, regardless of the multi-queue configuration. Define a constant so that virtqueue number calculations are easier to read. Signed-off-by: Stefan Hajnoczi --- hw/scsi/vhost-user-scsi.c | 2 +- hw/scsi/virtio-scsi.c | 7 ++++--- include/hw/virtio/virtio-scsi.h | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 23f972df59..eb37733bd0 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -115,7 +115,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, E= rror **errp) goto free_virtio; } =20 - vsc->dev.nvqs =3D 2 + vs->conf.num_queues; + vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; vsc->dev.vqs =3D g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vq_index =3D 0; vsc->dev.backend_features =3D 0; diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 4bc73a370e..5622dd54e5 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -191,7 +191,7 @@ static void virtio_scsi_save_request(QEMUFile *f, SCSIR= equest *sreq) VirtIOSCSIReq *req =3D sreq->hba_private; VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(req->dev); VirtIODevice *vdev =3D VIRTIO_DEVICE(req->dev); - uint32_t n =3D virtio_get_queue_index(req->vq) - 2; + uint32_t n =3D virtio_get_queue_index(req->vq) - VIRTIO_SCSI_VQ_NUM_FI= XED; =20 assert(n < vs->conf.num_queues); qemu_put_be32s(f, &n); @@ -892,10 +892,11 @@ void virtio_scsi_common_realize(DeviceState *dev, sizeof(VirtIOSCSIConfig)); =20 if (s->conf.num_queues =3D=3D 0 || - s->conf.num_queues > VIRTIO_QUEUE_MAX - 2) { + s->conf.num_queues > VIRTIO_QUEUE_MAX - VIRTIO_SCSI_VQ_NUM_FIX= ED) { error_setg(errp, "Invalid number of queues (=3D %" PRIu32 "), " "must be a positive integer less than %d.", - s->conf.num_queues, VIRTIO_QUEUE_MAX - 2); + s->conf.num_queues, + VIRTIO_QUEUE_MAX - VIRTIO_SCSI_VQ_NUM_FIXED); virtio_cleanup(vdev); return; } diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scs= i.h index 24e768909d..9f293bcb80 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -36,6 +36,9 @@ #define VIRTIO_SCSI_MAX_TARGET 255 #define VIRTIO_SCSI_MAX_LUN 16383 =20 +/* Number of virtqueues that are always present */ +#define VIRTIO_SCSI_VQ_NUM_FIXED 2 + typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq; typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp; typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq; --=20 2.24.1 From nobody Sat May 4 09:50:24 2024 Delivered-To: importer@patchew.org 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; 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=1579172454; cv=none; d=zohomail.com; s=zohoarc; b=BH1mTFj09n67h3/B4UOOt7odQObvO69vesp413LuqgfDohxJ28j8q8DgKITj3b0zExZbw3LaK7KnIUzFIrpPO/y2CjrO3BvS8htUdEcb36hIno0wD+/TBjz61QOIXMZxBN0vF1RY7z117XruMUf4zI7zNHhTFQH0JShcbBfQ5HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579172454; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bDGEv0wwyRCiswn1dmcYbXoPkWJxDjK0HvmEsSxTJdw=; b=glcOZpGRx4sGg60voVig8pasK1/bcZDekDBRVyj9ZdHEdJpmcR1CdkGTNQY0I8KlT4zlzCFsUeppAvMx9MvR9VuD+a4Cte813hLaxX6gPJlkzmDjGE4X9Bzmm6UlJhjZODFSIl4m/FzNFImJAoQI925KhcIQTDUZV4QqXQXBKRQ= 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 1579172454649167.7994720087455; Thu, 16 Jan 2020 03:00:54 -0800 (PST) Received: from localhost ([::1]:39870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2tQ-0007GH-VY for importer@patchew.org; Thu, 16 Jan 2020 06:00:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50715) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2rj-0005ac-6b for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is2rh-0008NA-Vp for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:07 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:22599 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is2rh-0008Mp-QH for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:05 -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-412-l6FyMOLuOLSGf4vhrYwYcQ-1; Thu, 16 Jan 2020 05:59:03 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D0BC1800D50; Thu, 16 Jan 2020 10:59:02 +0000 (UTC) Received: from localhost (ovpn-117-207.ams2.redhat.com [10.36.117.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7ACAE10842A9; Thu, 16 Jan 2020 10:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579172345; 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: in-reply-to:in-reply-to:references:references; bh=bDGEv0wwyRCiswn1dmcYbXoPkWJxDjK0HvmEsSxTJdw=; b=FppqSZpHQli43h+43cV36D+TXn2MPd6Kibg5tu3rNL9QWa6x0SnYhJmqtslOTPpFcG/wTg DBdSI+SAXyJ2NZWa6kiucoZMjoUpuLtrm7BrAVyS2uAex1SqywXndvEEPmNPlFhuJL/lW8 zVEaId4lKYI6vt/89/+hjKS+wfTUNHo= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 2/5] virtio: add VirtioDeviceClass->get_num_virtqueues() Date: Thu, 16 Jan 2020 10:58:39 +0000 Message-Id: <20200116105842.271179-3-stefanha@redhat.com> In-Reply-To: <20200116105842.271179-1-stefanha@redhat.com> References: <20200116105842.271179-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: l6FyMOLuOLSGf4vhrYwYcQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: Fam Zheng , Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Max Reitz , Paolo Bonzini 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" The virtio-pci proxy objects have an "nvectors" qdev property to allocate MSI vectors. This property defaults to DEV_NVECTORS_UNSPECIFIED on multi-queue devices and the final value is based on the number of virtqueues. The number of virtqueues is typically calculated like this by the virtio-pci proxy object: num_virtqueues =3D NUM_FIXED_VIRTQUEUES + conf.num_queues where conf.num_queues is a qdev property to allocate virtqueues. Add VirtioDeviceClass->get_num_virtqueues() so that this calculation can be performed by the device instead of the proxy object. This removes knowledge of virtqueue layout from the proxy object and allows the device to implement other formulas for calculating the number of virtqueues. This patch has no use on its own but keeping it separate eases backports if someone wants the virtio-blk patch but not virtio-scsi, or vice versa. The next patch uses this new function to automatically set conf.num_queues to -smp N for automatic multi-queue configuration. Signed-off-by: Stefan Hajnoczi --- include/hw/virtio/virtio.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b69d517496..048c81fcef 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -163,6 +163,13 @@ typedef struct VirtioDeviceClass { int (*post_load)(VirtIODevice *vdev); const VMStateDescription *vmsd; bool (*primary_unplug_pending)(void *opaque); + + /* + * Return the number of virtqueues. Called by transports that need to + * allocate per-virtqueue interrupt resources. This function may be c= alled + * before the device is realized. + */ + uint32_t (*get_num_virtqueues)(VirtIODevice *vdev); } VirtioDeviceClass; =20 void virtio_instance_init_common(Object *proxy_obj, void *data, --=20 2.24.1 From nobody Sat May 4 09:50:24 2024 Delivered-To: importer@patchew.org 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; 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=1579172617; cv=none; d=zohomail.com; s=zohoarc; b=M3pdFsVKtc0F4blc7miTU1wnIv57AVk6FqrNtTUua6//xCF2/iEbarMJGL/UckeqfWv29gQtn1BwrtIw7fhk3d+WoJAO/uTQ78mhl8kO/mqLdu6PcIS6skcLyzFVOTsbSPIWA3AcWYPWaefbBXXtecqw44Kjc82Ky5l+Il8yU5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579172617; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o3H4WA4qyYoNmCPE+S/ug1ggpeMg8EU8QXjs712xrC4=; b=HTEvtVcZyaDiY4hTiICRoHGTa2k4NG6rXcGRMSRserDpx2lJGYMSgDU/BZ9gfd2wRmlqCrLqS/S8h87D/MFr+kvXZzd4tUG40/oEsZn4l7MdhDfMXSMlmXyudqKIbrqpeoXjMjc6QHAD+oA0cOBezW24o+zCH18LIkiDfp7ou+0= 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 1579172617850134.75150635315572; Thu, 16 Jan 2020 03:03:37 -0800 (PST) Received: from localhost ([::1]:39950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2w4-0002Pf-Ek for importer@patchew.org; Thu, 16 Jan 2020 06:03:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50862) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2s8-0006DR-Ds for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is2s3-0000Al-On for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:32 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50670 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is2s3-0000AQ-Jk for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:27 -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-152-3Uve9H2zOlObarlMh2QW4A-1; Thu, 16 Jan 2020 05:59:10 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF50010120A1; Thu, 16 Jan 2020 10:59:09 +0000 (UTC) Received: from localhost (ovpn-117-207.ams2.redhat.com [10.36.117.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40950619DB; Thu, 16 Jan 2020 10:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579172367; 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: in-reply-to:in-reply-to:references:references; bh=o3H4WA4qyYoNmCPE+S/ug1ggpeMg8EU8QXjs712xrC4=; b=WEHw5zbQzwb9gxVZ19guFXyuLYgoh24r5okGz9OSpvQKF6GYQ0UMB0m9jY0rzWb8f+CbfF 7p8T09e0m7qEbDhA5KA7IB1mF4UTox1/qOq4I1W+tP0TlYjk/HtyyLtyb9tehHFE7CzFyb 3VQRJaayyla2+/cIBNpdkoljcdSGvDk= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 3/5] virtio-scsi: default num_queues to -smp N Date: Thu, 16 Jan 2020 10:58:40 +0000 Message-Id: <20200116105842.271179-4-stefanha@redhat.com> In-Reply-To: <20200116105842.271179-1-stefanha@redhat.com> References: <20200116105842.271179-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: 3Uve9H2zOlObarlMh2QW4A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: Fam Zheng , Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Max Reitz , Paolo Bonzini 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" Automatically size the number of request virtqueues to match the number of vCPUs. This ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. Remember that virtqueue numbering assumptions are being removed from the virtio-pci proxy object, so the Control and Event virtqueues are counted by ->get_num_virtqueues() and we only add 1 for the Configuration Change interrupt: if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { - vpci_dev->nvectors =3D vs->conf.num_queues + 3; + vpci_dev->nvectors =3D vdc->get_num_virtqueues(VIRTIO_DEVICE(vdev)= ) + 1; } Signed-off-by: Stefan Hajnoczi --- hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 2 ++ hw/scsi/vhost-user-scsi.c | 2 ++ hw/scsi/virtio-scsi.c | 18 ++++++++++++++++++ hw/virtio/vhost-scsi-pci.c | 4 ++-- hw/virtio/vhost-user-scsi-pci.c | 4 ++-- hw/virtio/virtio-scsi-pci.c | 4 ++-- include/hw/virtio/virtio-scsi.h | 1 + 8 files changed, 32 insertions(+), 6 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 3e288bfceb..41da19d85b 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -30,8 +30,11 @@ GlobalProperty hw_compat_4_2[] =3D { { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" }, { "virtio-blk-device", "seg-max-adjust", "off"}, + { "virtio-scsi-device", "auto_num_queues", "off"}, { "virtio-scsi-device", "seg_max_adjust", "off"}, { "vhost-blk-device", "seg_max_adjust", "off"}, + { "vhost-scsi", "auto_num_queues", "off"}, + { "vhost-user-scsi", "auto_num_queues", "off"}, { "usb-host", "suppress-remote-wake", "off" }, { "usb-redir", "suppress-remote-wake", "off" }, }; diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 26f710d3ec..1dfc269a29 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -273,6 +273,8 @@ static Property vhost_scsi_properties[] =3D { DEFINE_PROP_STRING("wwpn", VirtIOSCSICommon, conf.wwpn), DEFINE_PROP_UINT32("boot_tpgt", VirtIOSCSICommon, conf.boot_tpgt, 0), DEFINE_PROP_UINT32("num_queues", VirtIOSCSICommon, conf.num_queues, 1), + DEFINE_PROP_BOOL("auto_num_queues", VirtIOSCSICommon, + conf.auto_num_queues, true), DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSICommon, conf.virtqueue_= size, 128), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSICommon, conf.seg_max_adju= st, diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index eb37733bd0..92dbdf1042 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -164,6 +164,8 @@ static Property vhost_user_scsi_properties[] =3D { DEFINE_PROP_CHR("chardev", VirtIOSCSICommon, conf.chardev), DEFINE_PROP_UINT32("boot_tpgt", VirtIOSCSICommon, conf.boot_tpgt, 0), DEFINE_PROP_UINT32("num_queues", VirtIOSCSICommon, conf.num_queues, 1), + DEFINE_PROP_BOOL("auto_num_queues", VirtIOSCSICommon, + conf.auto_num_queues, true), DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSICommon, conf.virtqueue_= size, 128), DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors, diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 5622dd54e5..73c6030b22 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -16,6 +16,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "standard-headers/linux/virtio_ids.h" +#include "hw/boards.h" #include "hw/virtio/virtio-scsi.h" #include "migration/qemu-file-types.h" #include "qemu/error-report.h" @@ -878,6 +879,18 @@ static struct SCSIBusInfo virtio_scsi_scsi_info =3D { .load_request =3D virtio_scsi_load_request, }; =20 +static uint32_t virtio_scsi_get_num_virtqueues(VirtIODevice *vdev) +{ + VirtIOSCSICommon *s =3D VIRTIO_SCSI_COMMON(vdev); + uint32_t request_queues =3D s->conf.num_queues; + + if (s->conf.num_queues =3D=3D 1 && s->conf.auto_num_queues) { + request_queues =3D current_machine->smp.cpus; + } + + return VIRTIO_SCSI_VQ_NUM_FIXED + request_queues; +} + void virtio_scsi_common_realize(DeviceState *dev, VirtIOHandleOutput ctrl, VirtIOHandleOutput evt, @@ -905,6 +918,8 @@ void virtio_scsi_common_realize(DeviceState *dev, "must be > 2", s->conf.virtqueue_size); return; } + s->conf.num_queues =3D virtio_scsi_get_num_virtqueues(vdev) - + VIRTIO_SCSI_VQ_NUM_FIXED; s->cmd_vqs =3D g_new0(VirtQueue *, s->conf.num_queues); s->sense_size =3D VIRTIO_SCSI_SENSE_DEFAULT_SIZE; s->cdb_size =3D VIRTIO_SCSI_CDB_DEFAULT_SIZE; @@ -959,6 +974,8 @@ static void virtio_scsi_device_unrealize(DeviceState *d= ev, Error **errp) =20 static Property virtio_scsi_properties[] =3D { DEFINE_PROP_UINT32("num_queues", VirtIOSCSI, parent_obj.conf.num_queue= s, 1), + DEFINE_PROP_BOOL("auto_num_queues", VirtIOSCSI, + parent_obj.conf.auto_num_queues, true), DEFINE_PROP_UINT32("virtqueue_size", VirtIOSCSI, parent_obj.conf.virtqueue_size, 1= 28), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSI, @@ -1011,6 +1028,7 @@ static void virtio_scsi_class_init(ObjectClass *klass= , void *data) vdc->reset =3D virtio_scsi_reset; vdc->start_ioeventfd =3D virtio_scsi_dataplane_start; vdc->stop_ioeventfd =3D virtio_scsi_dataplane_stop; + vdc->get_num_virtqueues =3D virtio_scsi_get_num_virtqueues; hc->pre_plug =3D virtio_scsi_pre_hotplug; hc->plug =3D virtio_scsi_hotplug; hc->unplug =3D virtio_scsi_hotunplug; diff --git a/hw/virtio/vhost-scsi-pci.c b/hw/virtio/vhost-scsi-pci.c index e8dfbfc60f..94f64afde4 100644 --- a/hw/virtio/vhost-scsi-pci.c +++ b/hw/virtio/vhost-scsi-pci.c @@ -47,10 +47,10 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci= _dev, Error **errp) { VHostSCSIPCI *dev =3D VHOST_SCSI_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); - VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { - vpci_dev->nvectors =3D vs->conf.num_queues + 3; + vpci_dev->nvectors =3D vdc->get_num_virtqueues(VIRTIO_DEVICE(vdev)= ) + 1; } =20 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); diff --git a/hw/virtio/vhost-user-scsi-pci.c b/hw/virtio/vhost-user-scsi-pc= i.c index ff13af7030..6b518e6d72 100644 --- a/hw/virtio/vhost-user-scsi-pci.c +++ b/hw/virtio/vhost-user-scsi-pci.c @@ -53,10 +53,10 @@ static void vhost_user_scsi_pci_realize(VirtIOPCIProxy = *vpci_dev, Error **errp) { VHostUserSCSIPCI *dev =3D VHOST_USER_SCSI_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); - VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { - vpci_dev->nvectors =3D vs->conf.num_queues + 3; + vpci_dev->nvectors =3D vdc->get_num_virtqueues(VIRTIO_DEVICE(vdev)= ) + 1; } =20 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); diff --git a/hw/virtio/virtio-scsi-pci.c b/hw/virtio/virtio-scsi-pci.c index 3c55dc19a1..447344869d 100644 --- a/hw/virtio/virtio-scsi-pci.c +++ b/hw/virtio/virtio-scsi-pci.c @@ -46,12 +46,12 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpc= i_dev, Error **errp) { VirtIOSCSIPCI *dev =3D VIRTIO_SCSI_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); - VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); DeviceState *proxy =3D DEVICE(vpci_dev); char *bus_name; =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { - vpci_dev->nvectors =3D vs->conf.num_queues + 3; + vpci_dev->nvectors =3D vdc->get_num_virtqueues(VIRTIO_DEVICE(vdev)= ) + 1; } =20 /* diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scs= i.h index 9f293bcb80..672e703bd2 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -50,6 +50,7 @@ typedef struct virtio_scsi_config VirtIOSCSIConfig; =20 struct VirtIOSCSIConf { uint32_t num_queues; + bool auto_num_queues; uint32_t virtqueue_size; bool seg_max_adjust; uint32_t max_sectors; --=20 2.24.1 From nobody Sat May 4 09:50:24 2024 Delivered-To: importer@patchew.org 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; 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=1579172486; cv=none; d=zohomail.com; s=zohoarc; b=GlcOIq2VtBKVSQxYBM3WaQlqh/f0hegy42n7L+5f4+mjt6OKt7x9bvSJZF9xNU8NfGugpga/8SSeHJzWJfyZTJdr9KQj3flJcWpH5QS9fcw08hU2Fhy1NmXec/jYjfvr+JuannLJO262oQ5SbeQkf6Ew8lPmqRp+7uYIUbsDmZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579172486; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FO3ciqLIW+McLfC6WRnXcY6Q4TbB9eEpMOV+jy4G19E=; b=DegizYie2TN+EkcLhQ0Aj3s1mmk7Re+1JV0foGvNdlbKyfnRzjbj6vHp3pbaJMqt2j5MKJc5gfNKZ3L+RuQjvuB9R1+GJ+KzDLbrTCw4vSyh6y09SCmQTXXvlX7kol1nDsotK4NLa3b4Lk2vrDO8rzNdC0hIVSOJVGkGg9flwCs= 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 1579172486705205.54829340616493; Thu, 16 Jan 2020 03:01:26 -0800 (PST) Received: from localhost ([::1]:39884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2tt-0007nd-44 for importer@patchew.org; Thu, 16 Jan 2020 06:01:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50779) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2rw-0005v7-2h for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is2rr-0008SD-E2 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:19 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:35572 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is2rr-0008Ry-96 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:15 -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-180-Yu1f1f4fOcGfadT4lrH89Q-1; Thu, 16 Jan 2020 05:59:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A4D4D8010C0; Thu, 16 Jan 2020 10:59:11 +0000 (UTC) Received: from localhost (ovpn-117-207.ams2.redhat.com [10.36.117.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 374301000328; Thu, 16 Jan 2020 10:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579172354; 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: in-reply-to:in-reply-to:references:references; bh=FO3ciqLIW+McLfC6WRnXcY6Q4TbB9eEpMOV+jy4G19E=; b=QnJEG0LNA9xemhaI3nYriK2CjJG8IA3CDQloLGDPdT/lfWkfFc+iZMrF5XPKrvWnxftXqe imVlr4ZQkQLY4aEv+mtmX7soX9ySIgH+GmensNFuNl/0iPucwemCw9f7zogicy5fBpoabk Lfp2gJXyXyKhFUWubH+gDarjBsmot5o= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 4/5] virtio-blk: default num_queues to -smp N Date: Thu, 16 Jan 2020 10:58:41 +0000 Message-Id: <20200116105842.271179-5-stefanha@redhat.com> In-Reply-To: <20200116105842.271179-1-stefanha@redhat.com> References: <20200116105842.271179-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: Yu1f1f4fOcGfadT4lrH89Q-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 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: Fam Zheng , Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Max Reitz , Paolo Bonzini 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" Automatically size the number of request virtqueues to match the number of vCPUs. This ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. Signed-off-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 17 +++++++++++++++++ hw/core/machine.c | 1 + hw/virtio/virtio-blk-pci.c | 3 ++- include/hw/virtio/virtio-blk.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 9bee514c4e..8966b5a571 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -18,6 +18,7 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "trace.h" +#include "hw/boards.h" #include "hw/block/block.h" #include "hw/qdev-properties.h" #include "sysemu/blockdev.h" @@ -1119,6 +1120,18 @@ static const BlockDevOps virtio_block_ops =3D { .resize_cb =3D virtio_blk_resize, }; =20 +static uint32_t virtio_blk_get_num_virtqueues(VirtIODevice *vdev) +{ + VirtIOBlock *s =3D VIRTIO_BLK(vdev); + VirtIOBlkConf *conf =3D &s->conf; + + if (conf->num_queues =3D=3D 1 && conf->auto_num_queues) { + return current_machine->smp.cpus; + } + + return conf->num_queues; +} + static void virtio_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -1135,6 +1148,7 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) error_setg(errp, "Device needs media, but drive is empty"); return; } + conf->num_queues =3D virtio_blk_get_num_virtqueues(vdev); if (!conf->num_queues) { error_setg(errp, "num-queues property must be larger than 0"); return; @@ -1272,6 +1286,8 @@ static Property virtio_blk_properties[] =3D { DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, = 0, true), DEFINE_PROP_UINT16("num-queues", VirtIOBlock, conf.num_queues, 1), + DEFINE_PROP_BOOL("auto-num-queues", VirtIOBlock, + conf.auto_num_queues, true), DEFINE_PROP_UINT16("queue-size", VirtIOBlock, conf.queue_size, 128), DEFINE_PROP_BOOL("seg-max-adjust", VirtIOBlock, conf.seg_max_adjust, t= rue), DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD, @@ -1297,6 +1313,7 @@ static void virtio_blk_class_init(ObjectClass *klass,= void *data) dc->props =3D virtio_blk_properties; dc->vmsd =3D &vmstate_virtio_blk; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + vdc->get_num_virtqueues =3D virtio_blk_get_num_virtqueues; vdc->realize =3D virtio_blk_device_realize; vdc->unrealize =3D virtio_blk_device_unrealize; vdc->get_config =3D virtio_blk_update_config; diff --git a/hw/core/machine.c b/hw/core/machine.c index 41da19d85b..a33d1e93b1 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -28,6 +28,7 @@ #include "hw/mem/nvdimm.h" =20 GlobalProperty hw_compat_4_2[] =3D { + { "virtio-blk-device", "auto-num-queues", "off"}, { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" }, { "virtio-blk-device", "seg-max-adjust", "off"}, { "virtio-scsi-device", "auto_num_queues", "off"}, diff --git a/hw/virtio/virtio-blk-pci.c b/hw/virtio/virtio-blk-pci.c index d9b69a5af3..5131955cec 100644 --- a/hw/virtio/virtio-blk-pci.c +++ b/hw/virtio/virtio-blk-pci.c @@ -50,9 +50,10 @@ static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_= dev, Error **errp) { VirtIOBlkPCI *dev =3D VIRTIO_BLK_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { - vpci_dev->nvectors =3D dev->vdev.conf.num_queues + 1; + vpci_dev->nvectors =3D vdc->get_num_virtqueues(VIRTIO_DEVICE(vdev)= ) + 1; } =20 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 1e62f869b2..375d7b920a 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -37,6 +37,7 @@ struct VirtIOBlkConf char *serial; uint32_t request_merging; uint16_t num_queues; + bool auto_num_queues; uint16_t queue_size; bool seg_max_adjust; uint32_t max_discard_sectors; --=20 2.24.1 From nobody Sat May 4 09:50:24 2024 Delivered-To: importer@patchew.org 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; 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=1579172621; cv=none; d=zohomail.com; s=zohoarc; b=cky98Zv1QkNDZ/jDOrM31fZ9FIfYZ12niTI3q0qs2x2aBkLhZwFWXMwX4Ivk2TQfWw8mithm9QaTY2TgW7WtaiMO/sqvXMZJIoVEcSxWk+5k959ALnAG5nRdpc0+7XHuyqE9LKW0KGhGzSRftzPoXMXV4FkT/6d4fO6jJXX80PI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579172621; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1EJUAyINaXAVU17lKziI/hzu+/NjWM5FzY/Y9KFvO6g=; b=axFouYCz2GERtK1JIcXkXl5nLornAiY2m/r0lr/zEx/C4FSIIve/F7957e/NS2RGQFOAciTJ4XHlD+eIkYJk86WGxgwmniieqLB5+pkFCiJU/yBHIkMvNiqAAvTEjTbno2BbLq17kXG+auyUTvxA3+tZ44r9YyAUFg6oRq1hqKE= 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 157917262115198.66664410758005; Thu, 16 Jan 2020 03:03:41 -0800 (PST) Received: from localhost ([::1]:39954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2w7-0002aN-Du for importer@patchew.org; Thu, 16 Jan 2020 06:03:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50825) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2s2-00064j-G1 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is2ry-00004s-Hd for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59:26 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:32487 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is2ry-0008W4-DD for qemu-devel@nongnu.org; Thu, 16 Jan 2020 05:59: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-9-ldWcLZtmNiyCgIbDYhJ2jQ-1; Thu, 16 Jan 2020 05:59:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36C6C107ACC9; Thu, 16 Jan 2020 10:59:18 +0000 (UTC) Received: from localhost (ovpn-117-207.ams2.redhat.com [10.36.117.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 112A419C5B; Thu, 16 Jan 2020 10:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579172362; 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: in-reply-to:in-reply-to:references:references; bh=1EJUAyINaXAVU17lKziI/hzu+/NjWM5FzY/Y9KFvO6g=; b=gyXgj8Fe7hIu3DT31G033Q/bPlbfe21Za9qNn9mAoKlplniLdTxuG6QSDVBLepZcTo1ctH zhVxkdR8+aGJMZoo34p+mmWGJ6PHwCqSuA8nlzqDqu4/wf4lDd8QwKgvm5z3w9wSK3Ra5w y8YZYFskWyjM814B+quJlEdwp0YMS0Q= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 5/5] vhost-user-blk: default num_queues to -smp N Date: Thu, 16 Jan 2020 10:58:42 +0000 Message-Id: <20200116105842.271179-6-stefanha@redhat.com> In-Reply-To: <20200116105842.271179-1-stefanha@redhat.com> References: <20200116105842.271179-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: ldWcLZtmNiyCgIbDYhJ2jQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Fam Zheng , Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Max Reitz , Paolo Bonzini 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" Automatically size the number of request virtqueues to match the number of vCPUs. This ensures that completion interrupts are handled on the same vCPU that submitted the request. No IPI is necessary to complete an I/O request and performance is improved. This patch duplicates the .get_num_virtqueues() function because vhost-user-blk defines its own qdev property fields and does not share VirtIOBlkConf. Signed-off-by: Stefan Hajnoczi --- hw/block/vhost-user-blk.c | 15 +++++++++++++++ hw/core/machine.c | 1 + hw/virtio/vhost-user-blk-pci.c | 3 ++- include/hw/virtio/vhost-user-blk.h | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 98b383f90e..ac61ce9835 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -21,6 +21,7 @@ #include "qemu/error-report.h" #include "qemu/cutils.h" #include "qom/object.h" +#include "hw/boards.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost.h" @@ -391,6 +392,17 @@ static void vhost_user_blk_event(void *opaque, QEMUChr= Event event) } } =20 +static uint32_t vhost_user_blk_get_num_virtqueues(VirtIODevice *vdev) +{ + VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + + if (s->num_queues =3D=3D 1 && s->auto_num_queues) { + return current_machine->smp.cpus; + } + + return s->num_queues; +} + static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -403,6 +415,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) return; } =20 + s->num_queues =3D vhost_user_blk_get_num_virtqueues(vdev); if (!s->num_queues || s->num_queues > VIRTIO_QUEUE_MAX) { error_setg(errp, "vhost-user-blk: invalid number of IO queues"); return; @@ -501,6 +514,7 @@ static const VMStateDescription vmstate_vhost_user_blk = =3D { static Property vhost_user_blk_properties[] =3D { DEFINE_PROP_CHR("chardev", VHostUserBlk, chardev), DEFINE_PROP_UINT16("num-queues", VHostUserBlk, num_queues, 1), + DEFINE_PROP_BOOL("auto-num-queues", VHostUserBlk, auto_num_queues, tru= e), DEFINE_PROP_UINT32("queue-size", VHostUserBlk, queue_size, 128), DEFINE_PROP_BIT("config-wce", VHostUserBlk, config_wce, 0, true), DEFINE_PROP_END_OF_LIST(), @@ -514,6 +528,7 @@ static void vhost_user_blk_class_init(ObjectClass *klas= s, void *data) dc->props =3D vhost_user_blk_properties; dc->vmsd =3D &vmstate_vhost_user_blk; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + vdc->get_num_virtqueues =3D vhost_user_blk_get_num_virtqueues; vdc->realize =3D vhost_user_blk_device_realize; vdc->unrealize =3D vhost_user_blk_device_unrealize; vdc->get_config =3D vhost_user_blk_update_config; diff --git a/hw/core/machine.c b/hw/core/machine.c index a33d1e93b1..0d4142c3c8 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -35,6 +35,7 @@ GlobalProperty hw_compat_4_2[] =3D { { "virtio-scsi-device", "seg_max_adjust", "off"}, { "vhost-blk-device", "seg_max_adjust", "off"}, { "vhost-scsi", "auto_num_queues", "off"}, + { "vhost-user-blk", "auto-num-queues", "off"}, { "vhost-user-scsi", "auto_num_queues", "off"}, { "usb-host", "suppress-remote-wake", "off" }, { "usb-redir", "suppress-remote-wake", "off" }, diff --git a/hw/virtio/vhost-user-blk-pci.c b/hw/virtio/vhost-user-blk-pci.c index 1dc834a3ff..328c6a4066 100644 --- a/hw/virtio/vhost-user-blk-pci.c +++ b/hw/virtio/vhost-user-blk-pci.c @@ -53,9 +53,10 @@ static void vhost_user_blk_pci_realize(VirtIOPCIProxy *v= pci_dev, Error **errp) { VHostUserBlkPCI *dev =3D VHOST_USER_BLK_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { - vpci_dev->nvectors =3D dev->vdev.num_queues + 1; + vpci_dev->nvectors =3D vdc->get_num_virtqueues(VIRTIO_DEVICE(vdev)= ) + 1; } =20 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-u= ser-blk.h index 108bfadeeb..09d1fdf722 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -31,6 +31,7 @@ typedef struct VHostUserBlk { int32_t bootindex; struct virtio_blk_config blkcfg; uint16_t num_queues; + bool auto_num_queues; uint32_t queue_size; uint32_t config_wce; struct vhost_dev dev; --=20 2.24.1