From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94048C33CB1 for ; Thu, 16 Jan 2020 11:01:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A23F20730 for ; Thu, 16 Jan 2020 11:01:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QnJEG0LN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A23F20730 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is2tf-0007nd-RG for qemu-devel@archiver.kernel.org; Thu, 16 Jan 2020 06:01:07 -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 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= 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) 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-Type: text/plain; charset=US-ASCII 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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