virtio-pci: enable blk and scsi multi-queue by default
v6 cover virtio-pci: enable blk and scsi multi-queue by default
v6:
* Rebased onto QEMU 5.1 and added the now-necessary machine compat opts.
v4:
* Sorry for the long delay. I considered replacing this series with a simpler approach. Real hardware ships with a fixed number of queues (e.g. 128). The equivalent can be done in QEMU too. That way we don't need to magically si=
ze
num_queues. In the end I decided against this approach because the Linux virtio_blk.ko and virtio_scsi.ko guest drivers unconditionally initialized all available queues until recently (it was written with num_queues=3Dnum_vcpus in mind). It doesn't make sense for a 1 CPU guest to bring up 128 virtqueues (waste of resources and possibly weird performance effects with blk-mq).
* Honor maximum number of MSI-X vectors and virtqueues [Daniel Berrange]
* Update commit descriptions to mention maximum MSI-X vector and virtqueue caps [Raphael]
v3:
* Introduce virtio_pci_optimal_num_queues() helper to enforce VIRTIO_QUEUE_M=
AX
in one place
* Use VIRTIO_SCSI_VQ_NUM_FIXED constant in all cases [Cornelia]
* Update hw/core/machine.c compat properties for QEMU 5.0 [Michael]
v3:
* Add new performance results that demonstrate the scalability
* Mention that this is PCI-specific [Cornelia]
v2:
* Let the virtio-DEVICE-pci device select num-queues because the optimal multi-queue configuration may differ between virtio-pci, virtio-mmio, and virtio-ccw [Cornelia]
Enabling multi-queue on virtio-pci storage devices improves performance on SMP guests because the completion interrupt is handled on the vCPU that submitted the I/O request. This avoids IPIs inside the guest.
Note that performance is unchanged in these cases:
1. Uniprocessor guests. They don't have IPIs.
2. Application threads might be scheduled on the sole vCPU that handles completion interrupts purely by chance. (This is one reason why benchmark results can vary noticably between runs.)
3. Users may bind the application to the vCPU that handles completion interrupts.
Set the number of queues to the number of vCPUs by default on virtio-blk and virtio-scsi PCI devices. Older machine types continue to default to 1 queue for live migration compatibility.
Random read performance:
IOPS
q=3D1 78k
q=3D32 104k +33%
Boot time:
Duration
q=3D1 51s
q=3D32 1m41s +98%
Guest configuration: 32 vCPUs, 101 virtio-blk-pci disks
Previously measured results on a 4 vCPU guest were also positive but showed a smaller 1-4% performance improvement. They are no longer valid because significant event loop optimizations have been merged.
Peter Maydell (1):
Open 5.2 development tree
Stefan Hajnoczi (6):
hw: add 5.2 machine types and 5.1 compat options
virtio-pci: add virtio_pci_optimal_num_queues() helper
virtio-scsi: introduce a constant for fixed virtqueues
virtio-scsi-pci: default num_queues to -smp N
virtio-blk-pci: default num_queues to -smp N
vhost-user-blk-pci: default num_queues to -smp N
hw/virtio/virtio-pci.h | 9 +++++++++ include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ include/hw/virtio/vhost-user-blk.h | 2 ++ include/hw/virtio/virtio-blk.h | 2 ++ include/hw/virtio/virtio-scsi.h | 5 +++++ hw/arm/virt.c | 9 ++++++++- hw/block/vhost-user-blk.c | 6 +++++- hw/block/virtio-blk.c | 6 +++++- hw/core/machine.c | 9 +++++++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 ++++++++++++- hw/i386/pc_q35.c | 13 +++++++++++- hw/ppc/spapr.c | 15 ++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 ++++++++++++- hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 5 +++-- hw/scsi/virtio-scsi.c | 13 ++++++++---- hw/virtio/vhost-scsi-pci.c | 9 +++++++-- hw/virtio/vhost-user-blk-pci.c | 4 ++++ hw/virtio/vhost-user-scsi-pci.c | 9 +++++++-- hw/virtio/virtio-blk-pci.c | 7 ++++++- hw/virtio/virtio-pci.c | 32 ++++++++++++++++++++++++++++++ hw/virtio/virtio-scsi-pci.c | 9 +++++++-- VERSION | 2 +- 25 files changed, 184 insertions(+), 23 deletions(-)
--=20
2.26.2
PATCH v6 1/7 Open 5.2 development tree
From: Peter Maydell <[email protected]>
--- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
VERSION +1 -1
@@ -1 +1 @@ -5.1.0 +5.1.50
Signature · 1 line
2.26.2
Re: [PATCH v6 1/7] Open 5.2 development tree
Quoted 16 lines · Stefan Hajnoczi
From: Peter Maydell <[email protected]>
Signed-off-by Peter Maydell <[email protected]>--- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)VERSION +1
-1@@ -1 +1 @@ -5.1.0 +5.1.50Signature · 1 line
2.26.2
This patch was sent by accident, please skip it when applying the series. Git should do that automatically.
Stefan
PATCH v6 2/7 hw: add 5.2 machine types and 5.1 compat options
In reply to Stefan Hajnocziarm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)
include/hw/boards.h +3 -0
@@ -319,6 +319,9 @@ struct MachineState { } \ type_init(machine_initfn##_register_types) +extern GlobalProperty hw_compat_5_1[]; +extern const size_t hw_compat_5_1_len; +extern GlobalProperty hw_compat_5_0[];extern const size_t hw_compat_5_0_len;
include/hw/i386/pc.h +3 -0
@@ -193,6 +193,9 @@ void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid,const CPUArchIdList *apic_ids,GArray *entry); +extern GlobalProperty pc_compat_5_1[]; +extern const size_t pc_compat_5_1_len; +extern GlobalProperty pc_compat_5_0[];extern const size_t pc_compat_5_0_len;
hw/arm/virt.c +8 -1
@@ -2546,10 +2546,17 @@ static void machvirt_machine_init(void) }type_init (machvirt_machine_init); +static void virt_machine_5_2_options (MachineClass *mc) +{ +} +DEFINE_VIRT_MACHINE_AS_LATEST(5, 2) +static void virt_machine_5_1_options (MachineClass *mc) { +virt_machine_5_2_options (mc); +compat_props_add (mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); } -DEFINE_VIRT_MACHINE_AS_LATEST(5, 1) +DEFINE_VIRT_MACHINE(5, 1)static void virt_machine_5_0_options (MachineClass *mc) {
hw/core/machine.c +4 -0
@@ -28,6 +28,10 @@#include "hw/mem/nvdimm.h" #include "migration/vmstate.h" +GlobalProperty hw_compat_5_1[] = { +}; +const size_t hw_compat_5_1_len =G_N_ELEMENTS (hw_compat_5_1); +GlobalProperty hw_compat_5_0[] = { {"pci-host-bridge" ,"x-config-reg-migration-enabled" ,"off" }, {"virtio-balloon-device" ,"page-poison" ,"false" },
hw/i386/pc.c +4 -0
@@ -97,6 +97,10 @@#include "fw_cfg.h" #include "trace.h" +GlobalProperty pc_compat_5_1[] = { +}; +const size_t pc_compat_5_1_len =G_N_ELEMENTS (pc_compat_5_1); +GlobalProperty pc_compat_5_0[] = { };const size_t pc_compat_5_0_len =G_N_ELEMENTS (pc_compat_5_0);
hw/i386/pc_piix.c +13 -1
@@ -426,7 +426,7 @@ static void pc_i440fx_machine_options(MachineClass *m)machine_class_allow_dynamic_sysbus_dev (m,TYPE_VMBUS_BRIDGE ); } -static void pc_i440fx_5_1_machine_options (MachineClass *m) +static void pc_i440fx_5_2_machine_options (MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_machine_options (m);
@@ -435,6 +435,18 @@ static void pc_i440fx_5_1_machine_options(MachineClass *m) pcmc->default_cpu_version =1 ; } +DEFINE_I440FX_MACHINE (v5_2,"pc-i440fx-5.2" ,NULL , + pc_i440fx_5_2_machine_options); + +static void pc_i440fx_5_1_machine_options (MachineClass *m) +{ +pc_i440fx_machine_options (m); + m->alias =NULL ; + m->is_default = false; +compat_props_add (m->compat_props, hw_compat_5_1, hw_compat_5_1_len); +compat_props_add (m->compat_props, pc_compat_5_1, pc_compat_5_1_len); +} +DEFINE_I440FX_MACHINE (v5_1,"pc-i440fx-5.1" ,NULL , pc_i440fx_5_1_machine_options);
hw/i386/pc_q35.c +12 -1
@@ -353,7 +353,7 @@ static void pc_q35_machine_options(MachineClass *m) m->max_cpus =288 ; } -static void pc_q35_5_1_machine_options (MachineClass *m) +static void pc_q35_5_2_machine_options (MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_machine_options (m);
@@ -361,6 +361,17 @@ static void pc_q35_5_1_machine_options(MachineClass *m) pcmc->default_cpu_version =1 ; } +DEFINE_Q35_MACHINE (v5_2,"pc-q35-5.2" ,NULL , + pc_q35_5_2_machine_options); + +static void pc_q35_5_1_machine_options (MachineClass *m) +{ +pc_q35_machine_options (m); + m->alias =NULL ; +compat_props_add (m->compat_props, hw_compat_5_1, hw_compat_5_1_len); +compat_props_add (m->compat_props, pc_compat_5_1, pc_compat_5_1_len); +} +DEFINE_Q35_MACHINE (v5_1,"pc-q35-5.1" ,NULL , pc_q35_5_1_machine_options);
hw/ppc/spapr.c +13 -2
@@ -4579,15 +4579,26 @@ static void spapr_machine_latest_class_options(MachineClass *mc) } \ type_init(spapr_machine_register_##suffix) +/* +* pseries-5.2 +*/ +static void spapr_machine_5_2_class_options(MachineClass *mc) +{ +/* Defaults for the latest behaviour inherited from the base class */ +} + +DEFINE_SPAPR_MACHINE(5_2, "5.2", true); +/* * pseries-5.1 */ static void spapr_machine_5_1_class_options (MachineClass *mc) { -/* Defaults for the latest behaviour inherited from the base class */ +spapr_machine_5_2_class_options (mc); +compat_props_add (mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); } -DEFINE_SPAPR_MACHINE(5_1, "5.1", true); +DEFINE_SPAPR_MACHINE(5_1, "5.1", false);/* * pseries-5.0
hw/s390x/s390-virtio-ccw.c +13 -1
@@ -801,14 +801,26 @@ bool css_migration_enabled(void) } \ type_init(ccw_machine_register_##suffix) +static void ccw_machine_5_2_instance_options(MachineState *machine) +{ +} + +static void ccw_machine_5_2_class_options (MachineClass *mc) +{ +} +DEFINE_CCW_MACHINE(5_2, "5.2", true); +static void ccw_machine_5_1_instance_options (MachineState *machine) { +ccw_machine_5_2_instance_options (machine); }static void ccw_machine_5_1_class_options (MachineClass *mc) { +ccw_machine_5_2_class_options (mc); +compat_props_add (mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); } -DEFINE_CCW_MACHINE(5_1, "5.1", true); +DEFINE_CCW_MACHINE(5_1, "5.1", false);static void ccw_machine_5_0_instance_options (MachineState *machine) {
Signature · 1 line
2.26.2
Re: [PATCH v6 2/7] hw: add 5.2 machine types and 5.1 compat options
Quoted 5 lines · On Tue, 18 Aug 2020 15:33:43 +0100 Stefan Hajnoczi <[email protected]> wrote:
arm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 11 lines
--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)
https://lore.kernel.org/qemu-devel/[email protected]/
is already out there :)
Re: [PATCH v6 2/7] hw: add 5.2 machine types and 5.1 compat options
Quoted 20 lines · On Tue, 18 Aug 2020 17:11:32 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 5 lines · On Tue, 18 Aug 2020 15:33:43 +0100 Stefan Hajnoczi <[email protected]> wrote:
arm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
Signed-off-by Stefan Hajnoczi <[email protected]>Quoted 11 lines
--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)
Quoted 2 lines
https://lore.kernel.org/qemu-devel/[email protected]/
is already out there :)
That one doesn't apply anymore (or I did something wrong when applying it),
but Stefan's version applies cleanly
Quoted 2 lines
Re: [PATCH v6 2/7] hw: add 5.2 machine types and 5.1 compat options
Quoted 23 lines · On Wed, 19 Aug 2020 14:54:25 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 20 lines · On Tue, 18 Aug 2020 17:11:32 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 16 lines · On Tue, 18 Aug 2020 15:33:43 +0100 Stefan Hajnoczi <[email protected]> wrote:
arm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)
Quoted 6 lines
Quoted 2 lines
https://lore.kernel.org/qemu-devel/[email protected]/
is already out there :)That one doesn't apply anymore (or I did something wrong when applying it),
but Stefan's version applies cleanly
Seems that there were some changes afterwards. I'd prefer to just respin mine, though.
Re: [PATCH v6 2/7] hw: add 5.2 machine types and 5.1 compat options
In reply to Cornelia HuckQuoted 20 lines · Cornelia Huck
Quoted 5 lines · On Tue, 18 Aug 2020 15:33:43 +0100 Stefan Hajnoczi <[email protected]> wrote:
arm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
Signed-off-by Stefan Hajnoczi <[email protected]>Quoted 11 lines
--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)
Quoted 2 lines
https://lore.kernel.org/qemu-devel/[email protected]/
is already out there :)
You're too quick! :)
Next time I'll write a script and monitor qemu.git for the release tag so I can be first!!!!!!111
Stefan
Re: [PATCH v6 2/7] hw: add 5.2 machine types and 5.1 compat options
Quoted 21 lines · Stefan Hajnoczi
Quoted 20 lines · Cornelia Huck
Quoted 16 lines · On Tue, 18 Aug 2020 15:33:43 +0100 Stefan Hajnoczi <[email protected]> wrote:
arm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)
Quoted 7 lines
Quoted 2 lines
https://lore.kernel.org/qemu-devel/[email protected]/
is already out there :)You're too quick! :)
Next time I'll write a script and monitor qemu.git for the release tag so I can be first!!!!!!111
You're joking, but a template patch or some other automatism that opens the next development tree *BY* introducing new machine types would be nothing to frown at.
Another option would be for Peter to delay opening up the next development tree until he could immediately merge a patch with the new machine types (posted by whoever, near the end of the HFF or something).
Thanks
Laszlo
Re: [PATCH v6 2/7] hw: add 5.2 machine types and 5.1 compat options
Quoted 30 lines · Laszlo Ersek
Quoted 21 lines · Stefan Hajnoczi
Quoted 20 lines · Cornelia Huck
Quoted 16 lines · On Tue, 18 Aug 2020 15:33:43 +0100 Stefan Hajnoczi <[email protected]> wrote:
arm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)Quoted 7 lines
Quoted 2 lines
https://lore.kernel.org/qemu-devel/[email protected]/
is already out there :)You're too quick! :)
Next time I'll write a script and monitor qemu.git for the release tag so I can be first!!!!!!111
Quoted 7 lines
You're joking, but a template patch or some other automatism that opens the next development tree *BY* introducing new machine types would be nothing to frown at.
Another option would be for Peter to delay opening up the next development tree until he could immediately merge a patch with the new machine types (posted by whoever, near the end of the HFF or something).
Or this can be the "Open the tree for development" first patch :)
Quoted 5 lines
Thanks
Laszlo
Re: [PATCH v6 2/7] hw: add 5.2 machine types and 5.1 compat options
In reply to Stefan HajnocziQuoted 5 lines · On Tue, 18 Aug 2020 15:33:43 +0100 Stefan Hajnoczi <[email protected]> wrote:
arm, i386, ppc, and s390x have versioned machine types and associated compatibility options. Introduce new ones now that QEMU 5.1 has been released.
Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 211 lines
--- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 4 ++++ hw/i386/pc.c | 4 ++++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- 9 files changed, 73 insertions(+), 6 deletions(-)include/hw/boards.h +3
-0@@ -319,6 +319,9 @@ struct MachineState { } \ type_init(machine_initfn##_register_types) +extern GlobalProperty hw_compat_5_1[]; +extern const size_t hw_compat_5_1_len; +extern GlobalProperty hw_compat_5_0[];extern const size_t hw_compat_5_0_len;include/hw/i386/pc.h +3
-0@@ -193,6 +193,9 @@ void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid,const CPUArchIdList *apic_ids,GArray *entry); +extern GlobalProperty pc_compat_5_1[]; +extern const size_t pc_compat_5_1_len; +extern GlobalProperty pc_compat_5_0[];extern const size_t pc_compat_5_0_len;hw/arm/virt.c +8
-1@@ -2546,10 +2546,17 @@ static void machvirt_machine_init(void) }type_init (machvirt_machine_init); +static void virt_machine_5_2_options (MachineClass *mc) +{ +} +DEFINE_VIRT_MACHINE_AS_LATEST(5, 2) +static void virt_machine_5_1_options (MachineClass *mc) { +virt_machine_5_2_options (mc); +compat_props_add (mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); } -DEFINE_VIRT_MACHINE_AS_LATEST(5, 1) +DEFINE_VIRT_MACHINE(5, 1)static void virt_machine_5_0_options (MachineClass *mc) {hw/core/machine.c +4
-0@@ -28,6 +28,10 @@#include "hw/mem/nvdimm.h" #include "migration/vmstate.h" +GlobalProperty hw_compat_5_1[] = { +}; +const size_t hw_compat_5_1_len =G_N_ELEMENTS (hw_compat_5_1); +GlobalProperty hw_compat_5_0[] = { {"pci-host-bridge" ,"x-config-reg-migration-enabled" ,"off" }, {"virtio-balloon-device" ,"page-poison" ,"false" },hw/i386/pc.c +4
-0@@ -97,6 +97,10 @@#include "fw_cfg.h" #include "trace.h" +GlobalProperty pc_compat_5_1[] = { +}; +const size_t pc_compat_5_1_len =G_N_ELEMENTS (pc_compat_5_1); +GlobalProperty pc_compat_5_0[] = { };const size_t pc_compat_5_0_len =G_N_ELEMENTS (pc_compat_5_0);hw/i386/pc_piix.c +13
-1@@ -426,7 +426,7 @@ static void pc_i440fx_machine_options(MachineClass *m)machine_class_allow_dynamic_sysbus_dev (m,TYPE_VMBUS_BRIDGE ); } -static void pc_i440fx_5_1_machine_options (MachineClass *m) +static void pc_i440fx_5_2_machine_options (MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_machine_options (m);@@ -435,6 +435,18 @@ static void pc_i440fx_5_1_machine_options(MachineClass *m) pcmc->default_cpu_version =1 ; } +DEFINE_I440FX_MACHINE (v5_2,"pc-i440fx-5.2" ,NULL , + pc_i440fx_5_2_machine_options); + +static void pc_i440fx_5_1_machine_options (MachineClass *m) +{ +pc_i440fx_machine_options (m); + m->alias =NULL ; + m->is_default = false; +compat_props_add (m->compat_props, hw_compat_5_1, hw_compat_5_1_len); +compat_props_add (m->compat_props, pc_compat_5_1, pc_compat_5_1_len); +} +DEFINE_I440FX_MACHINE (v5_1,"pc-i440fx-5.1" ,NULL , pc_i440fx_5_1_machine_options);hw/i386/pc_q35.c +12
-1@@ -353,7 +353,7 @@ static void pc_q35_machine_options(MachineClass *m) m->max_cpus =288 ; } -static void pc_q35_5_1_machine_options (MachineClass *m) +static void pc_q35_5_2_machine_options (MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_machine_options (m);@@ -361,6 +361,17 @@ static void pc_q35_5_1_machine_options(MachineClass *m) pcmc->default_cpu_version =1 ; } +DEFINE_Q35_MACHINE (v5_2,"pc-q35-5.2" ,NULL , + pc_q35_5_2_machine_options); + +static void pc_q35_5_1_machine_options (MachineClass *m) +{ +pc_q35_machine_options (m); + m->alias =NULL ; +compat_props_add (m->compat_props, hw_compat_5_1, hw_compat_5_1_len); +compat_props_add (m->compat_props, pc_compat_5_1, pc_compat_5_1_len); +} +DEFINE_Q35_MACHINE (v5_1,"pc-q35-5.1" ,NULL , pc_q35_5_1_machine_options);hw/ppc/spapr.c +13
-2@@ -4579,15 +4579,26 @@ static void spapr_machine_latest_class_options(MachineClass *mc) } \ type_init(spapr_machine_register_##suffix) +/* +* pseries-5.2 +*/ +static void spapr_machine_5_2_class_options(MachineClass *mc) +{ +/* Defaults for the latest behaviour inherited from the base class */ +} + +DEFINE_SPAPR_MACHINE(5_2, "5.2", true); +/* * pseries-5.1 */ static void spapr_machine_5_1_class_options (MachineClass *mc) { -/* Defaults for the latest behaviour inherited from the base class */ +spapr_machine_5_2_class_options (mc); +compat_props_add (mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); } -DEFINE_SPAPR_MACHINE(5_1, "5.1", true); +DEFINE_SPAPR_MACHINE(5_1, "5.1", false);/* * pseries-5.0 hw/s390x/s390-virtio-ccw.c +10
-0@@ -801,14 +801,26 @@ bool css_migration_enabled(void) } \ type_init(ccw_machine_register_##suffix) +static void ccw_machine_5_2_instance_options(MachineState *machine) +{ +} + +static void ccw_machine_5_2_class_options (MachineClass *mc) +{ +} +DEFINE_CCW_MACHINE(5_2, "5.2", true); +static void ccw_machine_5_1_instance_options (MachineState *machine) { +ccw_machine_5_2_instance_options (machine); }
hw/s390x/s390-virtio-ccw.c bool css_migration_enabled(void) · line 826
Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +3
-1static void ccw_machine_5_1_class_options (MachineClass *mc) { +ccw_machine_5_2_class_options (mc); +compat_props_add (mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); } -DEFINE_CCW_MACHINE(5_1, "5.1", true); +DEFINE_CCW_MACHINE(5_1, "5.1", false);static void ccw_machine_5_0_instance_options (MachineState *machine) {
i
PATCH v6 3/7 virtio-pci: add virtio_pci_optimal_num_queues() helper
In reply to Stefan HajnocziMulti-queue devices achieve the best performance when each vCPU has a dedicated queue. This ensures that virtqueue used notifications are handled on the same vCPU that submitted virtqueue buffers. When another vCPU handles the the notification an IPI will be necessary to wake the submission vCPU and this incurs a performance overhead.
Provide a helper function that virtio-pci devices will use in later patches to automatically select the optimal number of queues.
The function handles guests with large numbers of CPUs by limiting the number of queues to fit within the following constraints:
1. The maximum number of MSI-X vectors.
2. The maximum number of virtqueues.
--- hw/virtio/virtio-pci.h | 9 +++++++++ hw/virtio/virtio-pci.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
hw/virtio/virtio-pci.h +9 -0
@@ -243,4 +243,13 @@ typedef struct VirtioPCIDeviceTypeInfo {/* Register virtio-pci type(s). @t must be static. */ void virtio_pci_types_register (const VirtioPCIDeviceTypeInfo *t); +/** +* virtio_pci_optimal_num_queues: +* @fixed_queues: number of queues that are always present +* +* Returns: The optimal number of queues for a multi-queue device, excluding +* @fixed_queues. +*/ +unsigned virtio_pci_optimal_num_queues (unsigned fixed_queues); +#endif
hw/virtio/virtio-pci.c +32 -0
@@ -19,6 +19,7 @@#include "exec/memop.h" #include "standard-headers/linux/virtio_pci.h" +#include "hw/boards.h" #include "hw/virtio/virtio.h" #include "migration/qemu-file-types.h" #include "hw/pci/pci.h"
@@ -2058,6 +2059,37 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)g_free (base_name); } +unsigned virtio_pci_optimal_num_queues (unsigned fixed_queues) +{ +/* +* 1:1 vq to vCPU mapping is ideal because the same vCPU that submitted +* virtqueue buffers can handle their completion. When a different vCPU +* handles completion it may need to IPI the vCPU that submitted the +* request and this adds overhead. +* +* Virtqueues consume guest RAM and MSI-X vectors. This is wasteful in +* guests with very many vCPUs and a device that is only used by a few +* vCPUs. Unfortunately optimizing that case requires manual pinning inside +* the guest, so those users might as well manually set the number of +* queues. There is no upper limit that can be applied automatically and +* doing so arbitrarily would result in a sudden performance drop once the +* threshold number of vCPUs is exceeded. +*/ +unsigned num_queues = current_machine->smp.cpus; + +/* +* The maximum number of MSI-X vectors is PCI_MSIX_FLAGS_QSIZE + 1, but the +* config change interrupt and the fixed virtqueues must be taken into +* account too. +*/ + num_queues =MIN (num_queues,PCI_MSIX_FLAGS_QSIZE - fixed_queues); + +/* +* There is a limit to how many virtqueues a device can have. +*/ +return MIN (num_queues,VIRTIO_QUEUE_MAX - fixed_queues); +} +/* virtio-pci-bus */ static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
Signature · 1 line
2.26.2
PATCH v6 4/7 virtio-scsi: introduce a constant for fixed virtqueues
In reply to Stefan HajnocziThe 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.
--- include/hw/virtio/virtio-scsi.h | 3 +++ hw/scsi/vhost-user-scsi.c | 2 +- hw/scsi/virtio-scsi.c | 7 ++++--- hw/virtio/vhost-scsi-pci.c | 3 ++- hw/virtio/vhost-user-scsi-pci.c | 3 ++- hw/virtio/virtio-scsi-pci.c | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-)
include/hw/virtio/virtio-scsi.h +3 -0
@@ -36,6 +36,9 @@#define VIRTIO_SCSI_MAX_TARGET 255#define VIRTIO_SCSI_MAX_LUN 16383 +/* 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 ;
hw/scsi/vhost-user-scsi.c +1 -1
@@ -114,7 +114,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) goto free_virtio; } - vsc->dev.nvqs =2 + vs->conf.num_queues; + vsc->dev.nvqs =VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vq_index =0 ; vsc->dev.backend_features =0 ;
hw/scsi/virtio-scsi.c +4 -3
@@ -191,7 +191,7 @@ static void virtio_scsi_save_request(QEMUFile *f, SCSIRequest *sreq)VirtIOSCSIReq *req = sreq->hba_private;VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (req->dev);VirtIODevice *vdev =VIRTIO_DEVICE (req->dev); -uint32_t n =virtio_get_queue_index (req->vq) -2 ; +uint32_t n =virtio_get_queue_index (req->vq) -VIRTIO_SCSI_VQ_NUM_FIXED ;assert (n < vs->conf.num_queues);qemu_put_be32s (f, &n);
@@ -892,10 +892,11 @@ void virtio_scsi_common_realize(DeviceState *dev, sizeof(VirtIOSCSIConfig));if (s->conf.num_queues ==0 || - s->conf.num_queues >VIRTIO_QUEUE_MAX -2 ) { + s->conf.num_queues >VIRTIO_QUEUE_MAX -VIRTIO_SCSI_VQ_NUM_FIXED ) {error_setg (errp,"Invalid number of queues (= %" 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 ; }
hw/virtio/vhost-scsi-pci.c +2 -1
@@ -50,7 +50,8 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues +3 ; + vpci_dev->nvectors = vs->conf.num_queues + +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/vhost-user-scsi-pci.c +2 -1
@@ -56,7 +56,8 @@ static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues +3 ; + vpci_dev->nvectors = vs->conf.num_queues + +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/virtio-scsi-pci.c +2 -1
@@ -51,7 +51,8 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)char *bus_name;if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues +3 ; + vpci_dev->nvectors = vs->conf.num_queues + +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }/*
Signature · 1 line
2.26.2
PATCH v6 5/7 virtio-scsi-pci: default num_queues to -smp N
In reply to Stefan HajnocziAutomatically size the number of virtio-scsi-pci, vhost-scsi-pci, and vhost-user-scsi-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping 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. The maximum number of MSI-X vectors and virtqueues limit are respected.
--- include/hw/virtio/virtio-scsi.h | 2 ++ hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 3 ++- hw/scsi/virtio-scsi.c | 6 +++++- hw/virtio/vhost-scsi-pci.c | 10 +++++++--- hw/virtio/vhost-user-scsi-pci.c | 10 +++++++--- hw/virtio/virtio-scsi-pci.c | 10 +++++++--- 8 files changed, 35 insertions(+), 12 deletions(-)
include/hw/virtio/virtio-scsi.h +2 -0
@@ -39,6 +39,8 @@/* Number of virtqueues that are always present */ #define VIRTIO_SCSI_VQ_NUM_FIXED 2 +#define VIRTIO_SCSI_AUTO_NUM_QUEUES UINT32_MAX +typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq ;typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp ;typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq ;
hw/core/machine.c +3 -0
@@ -29,6 +29,9 @@#include "migration/vmstate.h" GlobalProperty hw_compat_5_1[] = { + {"vhost-scsi" ,"num_queues" ,"1" }, + {"vhost-user-scsi" ,"num_queues" ,"1" }, + {"virtio-scsi-device" ,"num_queues" ,"1" }, };const size_t hw_compat_5_1_len =G_N_ELEMENTS (hw_compat_5_1);
hw/scsi/vhost-scsi.c +2 -1
@@ -270,7 +270,8 @@ static Property vhost_scsi_properties[] = {DEFINE_PROP_STRING ("vhostfd" , VirtIOSCSICommon, conf.vhostfd),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_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSICommon, conf.virtqueue_size,128 ), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSICommon, conf.seg_max_adjust,
hw/scsi/vhost-user-scsi.c +2 -1
@@ -162,7 +162,8 @@ static void vhost_user_scsi_unrealize(DeviceState *dev)static Property vhost_user_scsi_properties[] = {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_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSICommon, conf.virtqueue_size,128 ), DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors,
hw/scsi/virtio-scsi.c +5 -1
@@ -891,6 +891,9 @@ void virtio_scsi_common_realize(DeviceState *dev,virtio_init (vdev,"virtio-scsi" ,VIRTIO_ID_SCSI ,sizeof (VirtIOSCSIConfig)); +if (s->conf.num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + s->conf.num_queues =1 ; + }if (s->conf.num_queues ==0 || s->conf.num_queues >VIRTIO_QUEUE_MAX -VIRTIO_SCSI_VQ_NUM_FIXED ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
@@ -964,7 +967,8 @@ static void virtio_scsi_device_unrealize(DeviceState *dev) }static Property virtio_scsi_properties[] = { -DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSI, parent_obj.conf.num_queues,1 ), +DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSI, parent_obj.conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSI, parent_obj.conf.virtqueue_size,256 ), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSI,
hw/virtio/vhost-scsi-pci.c +7 -3
@@ -47,11 +47,15 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VHostSCSIPCI *dev =VHOST_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf; + +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/vhost-user-scsi-pci.c +7 -3
@@ -53,11 +53,15 @@ static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VHostUserSCSIPCI *dev =VHOST_USER_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf; + +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
hw/virtio/virtio-scsi-pci.c +7 -3
@@ -46,13 +46,17 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOSCSIPCI *dev =VIRTIO_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);DeviceState *proxy =DEVICE (vpci_dev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;char *bus_name; +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }/*
Signature · 1 line
2.26.2
Re: [PATCH v6 5/7] virtio-scsi-pci: default num_queues to -smp N
Quoted 10 lines · On Tue, 18 Aug 2020 15:33:46 +0100 Stefan Hajnoczi <[email protected]> wrote:
Automatically size the number of virtio-scsi-pci, vhost-scsi-pci, and vhost-user-scsi-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping 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. The maximum number of MSI-X vectors and virtqueues limit are respected.
Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 10 lines
--- include/hw/virtio/virtio-scsi.h | 2 ++ hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 3 ++- hw/scsi/virtio-scsi.c | 6 +++++- hw/virtio/vhost-scsi-pci.c | 10 +++++++--- hw/virtio/vhost-user-scsi-pci.c | 10 +++++++--- hw/virtio/virtio-scsi-pci.c | 10 +++++++--- 8 files changed, 35 insertions(+), 12 deletions(-)
Re: [PATCH v6 5/7] virtio-scsi-pci: default num_queues to -smp N
In reply to Stefan HajnocziQuoted 11 lines · Stefan Hajnoczi
Automatically size the number of virtio-scsi-pci, vhost-scsi-pci, and vhost-user-scsi-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping 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. The maximum number of MSI-X vectors and virtqueues limit are respected.
Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 164 lines
--- include/hw/virtio/virtio-scsi.h | 2 ++ hw/core/machine.c | 3 +++ hw/scsi/vhost-scsi.c | 3 ++- hw/scsi/vhost-user-scsi.c | 3 ++- hw/scsi/virtio-scsi.c | 6 +++++- hw/virtio/vhost-scsi-pci.c | 10 +++++++--- hw/virtio/vhost-user-scsi-pci.c | 10 +++++++--- hw/virtio/virtio-scsi-pci.c | 10 +++++++--- 8 files changed, 35 insertions(+), 12 deletions(-)include/hw/virtio/virtio-scsi.h +2
-0@@ -39,6 +39,8 @@/* Number of virtqueues that are always present */ #define VIRTIO_SCSI_VQ_NUM_FIXED 2 +#define VIRTIO_SCSI_AUTO_NUM_QUEUES UINT32_MAX +typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq ;typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp ;typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq ;hw/core/machine.c +3
-0@@ -29,6 +29,9 @@#include "migration/vmstate.h" GlobalProperty hw_compat_5_1[] = { + {"vhost-scsi" ,"num_queues" ,"1" }, + {"vhost-user-scsi" ,"num_queues" ,"1" }, + {"virtio-scsi-device" ,"num_queues" ,"1" }, };const size_t hw_compat_5_1_len =G_N_ELEMENTS (hw_compat_5_1);hw/scsi/vhost-scsi.c +2
-1@@ -270,7 +270,8 @@ static Property vhost_scsi_properties[] = {DEFINE_PROP_STRING ("vhostfd" , VirtIOSCSICommon, conf.vhostfd),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_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSICommon, conf.virtqueue_size,128 ), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSICommon, conf.seg_max_adjust,hw/scsi/vhost-user-scsi.c +2
-1@@ -162,7 +162,8 @@ static void vhost_user_scsi_unrealize(DeviceState *dev)static Property vhost_user_scsi_properties[] = {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_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSICommon, conf.virtqueue_size,128 ), DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors,hw/scsi/virtio-scsi.c +5
-1@@ -891,6 +891,9 @@ void virtio_scsi_common_realize(DeviceState *dev,virtio_init (vdev,"virtio-scsi" ,VIRTIO_ID_SCSI ,sizeof (VirtIOSCSIConfig)); +if (s->conf.num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + s->conf.num_queues =1 ; + }if (s->conf.num_queues ==0 || s->conf.num_queues >VIRTIO_QUEUE_MAX -VIRTIO_SCSI_VQ_NUM_FIXED ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "@@ -964,7 +967,8 @@ static void virtio_scsi_device_unrealize(DeviceState *dev) }static Property virtio_scsi_properties[] = { -DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSI, parent_obj.conf.num_queues,1 ), +DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSI, parent_obj.conf.num_queues, +VIRTIO_SCSI_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("virtqueue_size" , VirtIOSCSI, parent_obj.conf.virtqueue_size,256 ), DEFINE_PROP_BOOL("seg_max_adjust", VirtIOSCSI,hw/virtio/vhost-scsi-pci.c +7
-3@@ -47,11 +47,15 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VHostSCSIPCI *dev =VHOST_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf; + +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);hw/virtio/vhost-user-scsi-pci.c +7
-3@@ -53,11 +53,15 @@ static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VHostUserSCSIPCI *dev =VHOST_USER_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf; + +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);hw/virtio/virtio-scsi-pci.c +7
-4@@ -46,13 +46,17 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOSCSIPCI *dev =VIRTIO_SCSI_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); -VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (vdev);DeviceState *proxy =DEVICE (vpci_dev); +VirtIOSCSIConf *conf = &dev->vdev.parent_obj.conf;char *bus_name; +if (conf->num_queues ==VIRTIO_SCSI_AUTO_NUM_QUEUES ) { + conf->num_queues = +virtio_pci_optimal_num_queues (VIRTIO_SCSI_VQ_NUM_FIXED ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = vs->conf.num_queues + -VIRTIO_SCSI_VQ_NUM_FIXED +1 ; + vpci_dev->nvectors = conf->num_queues +VIRTIO_SCSI_VQ_NUM_FIXED +1 ; }/* -- 2.26.2
PATCH v6 6/7 virtio-blk-pci: default num_queues to -smp N
In reply to Stefan HajnocziAutomatically size the number of virtio-blk-pci request virtqueues to match the number of vCPUs. Other transports continue to default to 1 request virtqueue.
A 1:1 virtqueue:vCPU mapping 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. The maximum number of MSI-X vectors and virtqueues limit are respected.
Performance improves from 78k to 104k IOPS on a 32 vCPU guest with 101 virtio-blk-pci devices (ioengine=libaio, iodepth=1, bs=4k, rw=randread with NVMe storage).
--- include/hw/virtio/virtio-blk.h | 2 ++ hw/block/virtio-blk.c | 6 +++++- hw/core/machine.c | 1 + hw/virtio/virtio-blk-pci.c | 7 ++++++- 4 files changed, 14 insertions(+), 2 deletions(-)
include/hw/virtio/virtio-blk.h +2 -0
@@ -30,6 +30,8 @@ struct virtio_blk_inhdrunsigned char status; }; +#define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX +struct VirtIOBlkConf {BlockConf conf;
hw/block/virtio-blk.c +5 -1
@@ -1147,6 +1147,9 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)error_setg (errp,"Device needs media, but drive is empty" );return ; } +if (conf->num_queues ==VIRTIO_BLK_AUTO_NUM_QUEUES ) { + conf->num_queues =1 ; + }if (!conf->num_queues) {error_setg (errp,"num-queues property must be larger than 0" );return ;
@@ -1281,7 +1284,8 @@ static Property virtio_blk_properties[] = {#endif DEFINE_PROP_BIT ("request-merging" , VirtIOBlock, conf.request_merging,0 , true), -DEFINE_PROP_UINT16 ("num-queues" , VirtIOBlock, conf.num_queues,1 ), +DEFINE_PROP_UINT16 ("num-queues" , VirtIOBlock, conf.num_queues, +VIRTIO_BLK_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT16 ("queue-size" , VirtIOBlock, conf.queue_size,256 ),DEFINE_PROP_BOOL ("seg-max-adjust" , VirtIOBlock, conf.seg_max_adjust, true), DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD,
hw/core/machine.c +1 -0
@@ -31,6 +31,7 @@GlobalProperty hw_compat_5_1[] = { {"vhost-scsi" ,"num_queues" ,"1" }, {"vhost-user-scsi" ,"num_queues" ,"1" }, + {"virtio-blk-device" ,"num-queues" ,"1" }, {"virtio-scsi-device" ,"num_queues" ,"1" }, };const size_t hw_compat_5_1_len =G_N_ELEMENTS (hw_compat_5_1);
hw/virtio/virtio-blk-pci.c +6 -1
@@ -50,9 +50,14 @@ static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) {VirtIOBlkPCI *dev =VIRTIO_BLK_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); +VirtIOBlkConf *conf = &dev->vdev.conf; + +if (conf->num_queues ==VIRTIO_BLK_AUTO_NUM_QUEUES ) { + conf->num_queues =virtio_pci_optimal_num_queues (0 ); + }if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { - vpci_dev->nvectors = dev->vdev.conf.num_queues +1 ; + vpci_dev->nvectors = conf->num_queues +1 ; }qdev_realize (vdev,BUS (&vpci_dev->bus), errp);
Signature · 1 line
2.26.2
PATCH v6 7/7 vhost-user-blk-pci: default num_queues to -smp N
In reply to Stefan HajnocziAutomatically 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. The maximum number of MSI-X vectors and virtqueues limit are respected.
--- include/hw/virtio/vhost-user-blk.h | 2 ++ hw/block/vhost-user-blk.c | 6 +++++- hw/core/machine.c | 1 + hw/virtio/vhost-user-blk-pci.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-)
include/hw/virtio/vhost-user-blk.h +2 -0
@@ -25,6 +25,8 @@#define VHOST_USER_BLK (obj) \ OBJECT_CHECK(VHostUserBlk, (obj), TYPE_VHOST_USER_BLK) +#define VHOST_USER_BLK_AUTO_NUM_QUEUES UINT16_MAX + typedef struct VHostUserBlk { VirtIODevice parent_obj; CharBackend chardev;
hw/block/vhost-user-blk.c +5 -1
@@ -420,6 +420,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)return ; } +if (s->num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + s->num_queues =1 ; + }if (!s->num_queues || s->num_queues >VIRTIO_QUEUE_MAX ) {error_setg (errp,"vhost-user-blk: invalid number of IO queues" );return ;
@@ -531,7 +534,8 @@ static const VMStateDescription vmstate_vhost_user_blk = {static Property vhost_user_blk_properties[] = {DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), -DEFINE_PROP_UINT16 ("num-queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT16 ("num-queues" , VHostUserBlk, num_queues, +VHOST_USER_BLK_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("queue-size" , VHostUserBlk, queue_size,128 ),DEFINE_PROP_BIT ("config-wce" , VHostUserBlk, config_wce,0 , true),DEFINE_PROP_END_OF_LIST (),
hw/core/machine.c +1 -0
@@ -30,6 +30,7 @@GlobalProperty hw_compat_5_1[] = { {"vhost-scsi" ,"num_queues" ,"1" }, + {"vhost-user-blk" ,"num-queues" ,"1" }, {"vhost-user-scsi" ,"num_queues" ,"1" }, {"virtio-blk-device" ,"num-queues" ,"1" }, {"virtio-scsi-device" ,"num_queues" ,"1" },
hw/virtio/vhost-user-blk-pci.c +4 -0
@@ -54,6 +54,10 @@ static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VHostUserBlkPCI *dev =VHOST_USER_BLK_PCI (vpci_dev);DeviceState *vdev =DEVICE (&dev->vdev); +if (dev->vdev.num_queues ==VHOST_USER_BLK_AUTO_NUM_QUEUES ) { + dev->vdev.num_queues =virtio_pci_optimal_num_queues (0 ); + } +if (vpci_dev->nvectors ==DEV_NVECTORS_UNSPECIFIED ) { vpci_dev->nvectors = dev->vdev.num_queues +1 ; }
Signature · 1 line
2.26.2