virtio-blk: add iothread-vq-mapping parameter
cover virtio-blk: add iothread-vq-mapping parameter
This is a preview of the iothread-vq-mapping parameter that assigns virtqueues to IOThreads. The syntax is implemented but multiple IOThreads are not actually supported yet. The purpose of this RFC is to reach agreement on the syntax and to prepare for libvirt support.
virtio-blk and virtio-scsi devices will need a way to specify the mapping between IOThreads and virtqueues. At the moment all virtqueues are assigned to a single IOThread or the main loop. This single thread can be a CPU bottleneck, so it is necessary to allow finer-grained assignment to spread the load.
This series introduces command-line syntax for the new iothread-vq-mapping property is as follows:
--device '{"driver":"virtio-blk-pci","iothread-vq-mapping":[{"iothread":"iothread0","vqs":[0,1,2]},...]},...'
IOThreads are specified by name and virtqueues are specified by 0-based index.
It will be common to simply assign virtqueues round-robin across a set of IOThreads. A convenient syntax that does not require specifying individual virtqueue indices is available:
--device '{"driver":"virtio-blk-pci","iothread-vq-mapping":[{"iothread":"iothread0"},{"iothread":"iothread1"},...]},...'
There is no way to reassign virtqueues at runtime and I expect that to be a very rare requirement.
Perhaps libvirt only needs to support round-robin because specifying individual virtqueues is very specific and probably only useful for low-level performance investigation. The libvirt domain XML syntax for this could be:
<driver name='qemu' type='qcow2'>
<iothreads>
<iothread id="1"/>
<iothread id="2"/>
<iothread id="3"/>
</iothreads>
...</driver>
and that would generate this QEMU command-line snippet:
"iothread-vq-mapping":[{"iothread":"iothread1"},{"iothread":"iothread2"},{"iothread":"iothread3"}]
Note that JSON --device syntax is required for the iothread-vq-mapping parameter because it's non-scalar.
What do you think?
Stefan Hajnoczi (3):
qdev-properties: alias all object class properties
qdev: add IOThreadVirtQueueMappingList property type
virtio-blk: add iothread-vq-mapping parameter
qapi/virtio.json | 30 +++++++++++ include/hw/qdev-properties-system.h | 4 ++ include/hw/virtio/virtio-blk.h | 2 + hw/block/virtio-blk.c | 78 +++++++++++++++++++++++++++++ hw/core/qdev-properties-system.c | 47 +++++++++++++++++ hw/core/qdev-properties.c | 18 ++++--- 6 files changed, 171 insertions(+), 8 deletions(-)
Signature · 1 line
2.39.0
RFC 1/3 qdev-properties: alias all object class properties
qdev_alias_all_properties() aliases a DeviceState's qdev properties onto an Object. This is used for VirtioPCIProxy types so that --device virtio-blk-pci has properties of its embedded --device virtio-blk-device object.
Currently this function is implemented using qdev properties. Change the function to use QOM object class properties instead. This works because qdev properties create QOM object class properties, but it also catches any QOM object class-only properties that have no qdev properties.
This change ensures that properties of devices are shown with --device foo,\? even if they are QOM object class properties.
--- hw/core/qdev-properties.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
hw/core/qdev-properties.c +10 -8
@@ -959,16 +959,18 @@ void device_class_set_props(DeviceClass *dc, Property *props)void qdev_alias_all_properties (DeviceState *target,Object *source) {ObjectClass *class; -Property *prop; +ObjectPropertyIterator iter; +ObjectProperty *prop; class =object_get_class (OBJECT (target)); -do { -DeviceClass *dc =DEVICE_CLASS (class); -for (prop = dc->props_; prop && prop->name; prop++) { -object_property_add_alias (source, prop->name, -OBJECT (target), prop->name); +object_class_property_iter_init (&iter, class); +while ((prop =object_property_iter_next (&iter))) { +if (object_property_find (source, prop->name)) { +continue ;/* skip duplicate properties */ } - class =object_class_get_parent (class); - }while (class !=object_class_by_name (TYPE_DEVICE )); + +object_property_add_alias (source, prop->name, +OBJECT (target), prop->name); + } }
Signature · 1 line
2.39.0
RFC 2/3 qdev: add IOThreadVirtQueueMappingList property type
In reply to Stefan Hajnoczivirtio-blk and virtio-scsi devices will need a way to specify the mapping between IOThreads and virtqueues. At the moment all virtqueues are assigned to a single IOThread or the main loop. This single thread can be a CPU bottleneck, so it is necessary to allow finer-grained assignment to spread the load.
Introduce DEFINE_PROP_IOTHREAD_VQ_MAPPING_LIST() so devices can take a parameter that maps virtqueues to IOThreads. The command-line syntax for this new property is as follows:
--device '{"driver":"foo","iothread-vq-mapping":[{"iothread":"iothread0","vqs":[0,1,2]},...]}'
IOThreads are specified by name and virtqueues are specified by 0-based index.
It will be common to simply assign virtqueues round-robin across a set of IOThreads. A convenient syntax that does not require specifying individual virtqueue indices is available:
--device '{"driver":"foo","iothread-vq-mapping":[{"iothread":"iothread0"},{"iothread":"iothread1"},...]}'
--- qapi/virtio.json | 30 ++++++++++++++++++ include/hw/qdev-properties-system.h | 4 +++ hw/core/qdev-properties-system.c | 47 +++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
qapi/virtio.json +30 -0
@@ -952,3 +952,33 @@ 'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' }, 'returns': 'VirtioQueueElement', 'features': [ 'unstable' ] } + +## +# @IOThreadVirtQueueMapping: +# +# Describes the subset of virtqueues assigned to an IOThread. +# +# @iothread: the id of IOThread object +# @vqs: an optional array of virtqueue indices that will be handled by this +# IOThread. When absent, virtqueues are assigned round-robin across all +# IOThreadVirtQueueMappings provided. Either all +# IOThreadVirtQueueMappings must have @vqs or none of them must have it. +# +# Since: 8.0 +# +## + +{ 'struct': 'IOThreadVirtQueueMapping', + 'data': { 'iothread': 'str', '*vqs': ['uint16'] } } + +## +# @IOThreadVirtQueueMappings: +# +# IOThreadVirtQueueMapping list. This struct is not actually used but the +# IOThreadVirtQueueMappingList type it generates is! +# +# Since: 8.0 +## + +{ 'struct': 'IOThreadVirtQueueMappings', + 'data': { 'mappings': ['IOThreadVirtQueueMapping'] } }
include/hw/qdev-properties-system.h +4 -0
@@ -22,6 +22,7 @@ extern const PropertyInfo qdev_prop_audiodev;extern const PropertyInfo qdev_prop_off_auto_pcibar;extern const PropertyInfo qdev_prop_pcie_link_speed;extern const PropertyInfo qdev_prop_pcie_link_width; +extern const PropertyInfo qdev_prop_iothread_vq_mapping_list;#define DEFINE_PROP_PCI_DEVFN (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
@@ -73,5 +74,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width;#define DEFINE_PROP_UUID_NODEFAULT (_name, _state, _field) \ DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID) +#define DEFINE_PROP_IOTHREAD_VQ_MAPPING_LIST (_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_iothread_vq_mapping_list, \ + IOThreadVirtQueueMappingList *)#endif
hw/core/qdev-properties-system.c +47 -0
56 lines not on this page · raw message
Signature · 1 line
2.39.0
RFC 3/3 virtio-blk: add iothread-vq-mapping parameter
In reply to Stefan HajnocziAdd the iothread-vq-mapping parameter to assign virtqueues to IOThreads.
Note that this commit simply adds the VirtIOBlock->iothread_vq_mapping_list field but does not use it yet. The block layer doesn't support multi-queue yet, so we cannot safely process virtqueues from multiple IOThreads at this time.
--- include/hw/virtio/virtio-blk.h | 2 + hw/block/virtio-blk.c | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)
include/hw/virtio/virtio-blk.h +2 -0
@@ -21,6 +21,7 @@#include "sysemu/block-backend.h" #include "sysemu/block-ram-registrar.h" #include "qom/object.h" +#include "qapi/qapi-types-virtio.h" #define TYPE_VIRTIO_BLK "virtio-blk-device"OBJECT_DECLARE_SIMPLE_TYPE (VirtIOBlock,VIRTIO_BLK )
@@ -37,6 +38,7 @@ struct VirtIOBlkConf {BlockConf conf;IOThread *iothread; +IOThreadVirtQueueMappingList *iothread_vq_mapping_list;char *serial;uint32_t request_merging;uint16_t num_queues;
hw/block/virtio-blk.c +78 -0
102 lines not on this page · raw message
Signature · 1 line
2.39.0
Quoted 32 lines · Stefan Hajnoczi
This is a preview of the iothread-vq-mapping parameter that assigns virtqueues to IOThreads. The syntax is implemented but multiple IOThreads are not actually supported yet. The purpose of this RFC is to reach agreement on the syntax and to prepare for libvirt support.
virtio-blk and virtio-scsi devices will need a way to specify the mapping between IOThreads and virtqueues. At the moment all virtqueues are assigned to a single IOThread or the main loop. This single thread can be a CPU bottleneck, so it is necessary to allow finer-grained assignment to spread the load.
This series introduces command-line syntax for the new iothread-vq-mapping property is as follows:
--device '{"driver":"virtio-blk-pci","iothread-vq-mapping":[{"iothread":"iothread0","vqs":[0,1,2]},...]},...'
IOThreads are specified by name and virtqueues are specified by 0-based index.
It will be common to simply assign virtqueues round-robin across a set of IOThreads. A convenient syntax that does not require specifying individual virtqueue indices is available:
--device '{"driver":"virtio-blk-pci","iothread-vq-mapping":[{"iothread":"iothread0"},{"iothread":"iothread1"},...]},...'
There is no way to reassign virtqueues at runtime and I expect that to be a very rare requirement.
Perhaps libvirt only needs to support round-robin because specifying individual virtqueues is very specific and probably only useful for low-level performance investigation. The libvirt domain XML syntax for this could be:
Quoted 8 lines
<driver name='qemu' type='qcow2'>
<iothreads> <iothread id="1"/> <iothread id="2"/> <iothread id="3"/> </iothreads> ...</driver>
Just for completeness, this how disk XML looks now:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' queues='4' iothread='1'/>
<source file='/tmp/data.qcow'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/></disk>
It corresponds to the following cmd line:
-blockdev '{"driver":"file","filename":"/tmp/data.qcow","node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"qcow2","file":"libvirt-3-storage"}' \
-device '{"driver":"virtio-blk-pci","iothread":"iothread1","num-queues":4,"bus":"pci.0","addr":"0x3","drive":"libvirt-3-format","id":"virtio-disk0","bootindex":1}' \We already have @iothread attribute, so inventing an <iothread/> subelement is a bit misleading, because if users query which disk uses iothreads, they need to change their XPATH. Currently they can get away with:
//disk[driver/@iothread]/source/@file
but I guess for backwards compatibility, we can put the first iothread ID into the attribute, e.g.:
<driver iothread="2">
<iothread>
<iothread id="2"/>
<iothread id="4"/>
</iothread></driver>
We've done something similar, when introducing multiple listen addresses for VNC.
Now, an iothread is actually a thread pool. I guess we will never ever need to assign individual threads from the pool to queues, right?
Michal
Quoted 72 lines · Michal Prívozník
Quoted 32 lines · Stefan Hajnoczi
This is a preview of the iothread-vq-mapping parameter that assigns virtqueues to IOThreads. The syntax is implemented but multiple IOThreads are not actually supported yet. The purpose of this RFC is to reach agreement on the syntax and to prepare for libvirt support.
virtio-blk and virtio-scsi devices will need a way to specify the mapping between IOThreads and virtqueues. At the moment all virtqueues are assigned to a single IOThread or the main loop. This single thread can be a CPU bottleneck, so it is necessary to allow finer-grained assignment to spread the load.
This series introduces command-line syntax for the new iothread-vq-mapping property is as follows:
--device '{"driver":"virtio-blk-pci","iothread-vq-mapping":[{"iothread":"iothread0","vqs":[0,1,2]},...]},...'
IOThreads are specified by name and virtqueues are specified by 0-based index.
It will be common to simply assign virtqueues round-robin across a set of IOThreads. A convenient syntax that does not require specifying individual virtqueue indices is available:
--device '{"driver":"virtio-blk-pci","iothread-vq-mapping":[{"iothread":"iothread0"},{"iothread":"iothread1"},...]},...'
There is no way to reassign virtqueues at runtime and I expect that to be a very rare requirement.
Perhaps libvirt only needs to support round-robin because specifying individual virtqueues is very specific and probably only useful for low-level performance investigation. The libvirt domain XML syntax for this could be:
Quoted 8 lines
<driver name='qemu' type='qcow2'>
<iothreads> <iothread id="1"/> <iothread id="2"/> <iothread id="3"/> </iothreads> ...</driver>
Just for completeness, this how disk XML looks now:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' queues='4' iothread='1'/> <source file='/tmp/data.qcow'/> <target dev='vda' bus='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/></disk>
It corresponds to the following cmd line:
-blockdev '{"driver":"file","filename":"/tmp/data.qcow","node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"qcow2","file":"libvirt-3-storage"}' \ -device '{"driver":"virtio-blk-pci","iothread":"iothread1","num-queues":4,"bus":"pci.0","addr":"0x3","drive":"libvirt-3-format","id":"virtio-disk0","bootindex":1}' \We already have @iothread attribute, so inventing an <iothread/> subelement is a bit misleading, because if users query which disk uses iothreads, they need to change their XPATH. Currently they can get away with:
//disk[driver/@iothread]/source/@file
but I guess for backwards compatibility, we can put the first iothread ID into the attribute, e.g.:
<driver iothread="2">
<iothread> <iothread id="2"/> <iothread id="4"/> </iothread>
Quoted 8 lines
</driver>
We've done something similar, when introducing multiple listen addresses for VNC.
Now, an iothread is actually a thread pool. I guess we will never ever need to assign individual threads from the pool to queues, right?
QEMU will have the ability to assign an individual virtqueue to a specific IOThread.
At the moment I believe no one will need that much control. Users probably just want to round-robin threads for virtio-blk and virtio-scsi devices.
I think it's fine for libvirt domain XML to only support round-robin for virtio-blk and virtio-scsi.
Stefan