Skip to contentSkip to conversation

virtio-blk: add iothread-vq-mapping parameter

PATCH Applied Stefan Hajnoczi 2 participants 12 messages Dec 20, 2023 – Jan 19, 2024

lore
Share & tools
lore
#0 lore raw

v4 cover virtio-blk: add iothread-vq-mapping parameter

v4:
- Use DummyVirtioForceArrays naming in QAPI schema [Markus]
v3:
- Rebased onto Kevin's block branch
- Add StringOutputVisitor "<omitted>" patch to fix "info qtree" crash
- Fix QAPI schema formatting [Markus]
- Eliminate unnecessary local variable in get_iothread_vq_mapping_list() [Markus]

virtio-blk and virtio-scsi devices 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. With this series applied, "pidstat -t 1" shows that guests with -smp 2 or higher are able to exploit multiple IOThreads.

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.

Note that JSON --device syntax is required for the iothread-vq-mapping parameter because it's non-scalar.

Based-on: 81e69329d6a4018f4b37d15b6fc845fbe585a93b (https://repo.or.cz/qemu/kevin.git block)

Stefan Hajnoczi (4):
qdev-properties: alias all object class properties
string-output-visitor: show structs as "<omitted>"
qdev: add IOThreadVirtQueueMappingList property type
virtio-blk: add iothread-vq-mapping parameter

 qapi/virtio.json                     |  29 +++++
 hw/block/dataplane/virtio-blk.h      |   3 +
 include/hw/qdev-properties-system.h  |   5 +
 include/hw/virtio/virtio-blk.h       |   2 +
 include/qapi/string-output-visitor.h |   6 +-
 hw/block/dataplane/virtio-blk.c      | 155 ++++++++++++++++++++-------
 hw/block/virtio-blk.c                |  92 +++++++++++++---
 hw/core/qdev-properties-system.c     |  46 ++++++++
 hw/core/qdev-properties.c            |  18 ++--
 qapi/string-output-visitor.c         |  16 +++
 10 files changed, 311 insertions(+), 61 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/4 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
index 840006e953..7d6fa726fd 100644
@@ -1076,16 +1076,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.43.0
Reviewed-by on v4 1/4
#2 lore raw

Re: [PATCH v4 1/4] qdev-properties: alias all object class properties

Am 20.12.2023 um 14:47 hat Stefan Hajnoczi geschrieben:

Quoted 10 lines

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.

Quoted 4 lines

This change ensures that properties of devices are shown with --device foo,\? even if they are QOM object class properties.

We should also update the comment to refer to properties in general rather than just qdev properties. I can squash in the following hunk.

Kevin

include/hw/qdev-properties.h +2 -2
index 25743a29a0..09aa04ca1e 100644
@@ -230,8 +230,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop);
  * @target: Device which has properties to be aliased
  * @source: Object to add alias properties to
  *
- * Add alias properties to the @source object for all qdev properties on
- * the @target DeviceState.
+ * Add alias properties to the @source object for all properties on the @target
+ * DeviceState.
  *
  * This is useful when @target is an internal implementation object
  * owned by @source, and you want to expose all the properties of that
#3 lore raw

Re: [PATCH v4 1/4] qdev-properties: alias all object class properties

Quoted 14 lines · Kevin Wolf

Am 20.12.2023 um 14:47 hat Stefan Hajnoczi geschrieben:

Quoted 13 lines

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.

Quoted 6 lines
Quoted 1 line

We should also update the comment to refer to properties in general rather than just qdev properties. I can squash in the following hunk.

Please go ahead. Thank you!

Stefan

Quoted 16 lines
include/hw/qdev-properties.h +2 -2
index 25743a29a0..09aa04ca1e 100644
@@ -230,8 +230,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop);
  * @target: Device which has properties to be aliased
  * @source: Object to add alias properties to
  *
- * Add alias properties to the @source object for all qdev properties on
- * the @target DeviceState.
+ * Add alias properties to the @source object for all properties on the @target
+ * DeviceState.
  *
  * This is useful when @target is an internal implementation object
  * owned by @source, and you want to expose all the properties of that
#4 lore raw

PATCH v4 2/4 string-output-visitor: show structs as "<omitted>"

In reply to Stefan Hajnoczi

StringOutputVisitor crashes when it visits a struct because ->start_struct() is NULL.

Show "<omitted>" instead of crashing. This is necessary because the virtio-blk-pci iothread-vq-mapping parameter that I'd like to introduce soon is a list of IOThreadMapping structs.

This patch is a quick fix to solve the crash, but the long-term solution is replacing StringOutputVisitor with something that can handle the full gamut of values in QEMU.

---
 include/qapi/string-output-visitor.h |  6 +++---
 qapi/string-output-visitor.c         | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)
include/qapi/string-output-visitor.h +3 -3
index 268dfe9986..b1ee473b30 100644
@@ -26,9 +26,9 @@ typedef struct StringOutputVisitor StringOutputVisitor;
  * If everything else succeeds, pass @result to visit_complete() to
  * collect the result of the visit.
  *
- * The string output visitor does not implement support for visiting
- * QAPI structs, alternates, null, or arbitrary QTypes.  It also
- * requires a non-null list argument to visit_start_list().
+ * The string output visitor does not implement support for alternates, null,
+ * or arbitrary QTypes.  Struct fields are not shown.  It also requires a
+ * non-null list argument to visit_start_list().
  */
 Visitor *string_output_visitor_new(bool human, char **result);
 
qapi/string-output-visitor.c +16 -0
index c0cb72dbe4..f0c1dea89e 100644
@@ -292,6 +292,20 @@ static bool print_type_null(Visitor *v, const char *name, QNull **obj,
     return true;
 }
 
+static bool start_struct(Visitor *v, const char *name, void **obj,
+                         size_t size, Error **errp)
+{
+    return true;
+}
+
+static void end_struct(Visitor *v, void **obj)
+{
+    StringOutputVisitor *sov = to_sov(v);
+
+    /* TODO actually print struct fields */
+    string_output_set(sov, g_strdup("<omitted>"));
+}
+
 static bool
 start_list(Visitor *v, const char *name, GenericList **list, size_t size,
            Error **errp)
@@ -379,6 +393,8 @@ Visitor *string_output_visitor_new(bool human, char **result)
     v->visitor.type_str = print_type_str;
     v->visitor.type_number = print_type_number;
     v->visitor.type_null = print_type_null;
+    v->visitor.start_struct = start_struct;
+    v->visitor.end_struct = end_struct;
     v->visitor.start_list = start_list;
     v->visitor.next_list = next_list;
     v->visitor.end_list = end_list;
Signature · 1 line
2.43.0
#5 lore raw

PATCH v4 3/4 qdev: add IOThreadVirtQueueMappingList property type

In reply to Stefan Hajnoczi

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.

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                    | 29 ++++++++++++++++++
 include/hw/qdev-properties-system.h |  5 ++++
 hw/core/qdev-properties-system.c    | 46 +++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+)
qapi/virtio.json +29 -0
index e6dcee7b83..19c7c36e36 100644
@@ -928,3 +928,32 @@
   '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: 9.0
+##
+
+{ 'struct': 'IOThreadVirtQueueMapping',
+  'data': { 'iothread': 'str', '*vqs': ['uint16'] } }
+
+##
+# @DummyVirtioForceArrays:
+#
+# Not used by QMP; hack to let us use IOThreadVirtQueueMappingList internally
+#
+# Since: 9.0
+##
+
+{ 'struct': 'DummyVirtioForceArrays',
+  'data': { 'unused-iothread-vq-mapping': ['IOThreadVirtQueueMapping'] } }
include/hw/qdev-properties-system.h +5 -0
index 91f7a2452d..06c359c190 100644
@@ -24,6 +24,7 @@ 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_cpus390entitlement;
+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)
@@ -82,4 +83,8 @@ extern const PropertyInfo qdev_prop_cpus390entitlement;
     DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_cpus390entitlement, \
                        CpuS390Entitlement)
 
+#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 +46 -0

55 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

PATCH v4 4/4 virtio-blk: add iothread-vq-mapping parameter

In reply to Stefan Hajnoczi

Add the iothread-vq-mapping parameter to assign virtqueues to IOThreads. Store the vq:AioContext mapping in the new struct VirtIOBlockDataPlane->vq_aio_context[] field and refactor the code to use the per-vq AioContext instead of the BlockDriverState's AioContext.

Reimplement --device virtio-blk-pci,iothread= and non-IOThread mode by assigning all virtqueues to the IOThread and main loop's AioContext in vq_aio_context[], respectively.

The comment in struct VirtIOBlockDataPlane about EventNotifiers is stale. Remove it.

---
 hw/block/dataplane/virtio-blk.h |   3 +
 include/hw/virtio/virtio-blk.h  |   2 +
 hw/block/dataplane/virtio-blk.c | 155 ++++++++++++++++++++++++--------
 hw/block/virtio-blk.c           |  92 ++++++++++++++++---
 4 files changed, 202 insertions(+), 50 deletions(-)
hw/block/dataplane/virtio-blk.h +3 -0
index 5e18bb99ae..1a806fe447 100644
@@ -28,4 +28,7 @@ void virtio_blk_data_plane_notify(VirtIOBlockDataPlane *s, VirtQueue *vq);
 int virtio_blk_data_plane_start(VirtIODevice *vdev);
 void virtio_blk_data_plane_stop(VirtIODevice *vdev);
 
+void virtio_blk_data_plane_detach(VirtIOBlockDataPlane *s);
+void virtio_blk_data_plane_attach(VirtIOBlockDataPlane *s);
+
 #endif /* HW_DATAPLANE_VIRTIO_BLK_H */
include/hw/virtio/virtio-blk.h +2 -0
index 9881009c22..5e4091e4da 100644
@@ -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/dataplane/virtio-blk.c +117 -38

231 lines not on this page · raw message

hw/block/virtio-blk.c +80 -12

138 lines not on this page · raw message

Signature · 1 line
2.43.0
#7 lore raw

Am 20.12.2023 um 14:47 hat Stefan Hajnoczi geschrieben:

Quoted 5 lines

Add the iothread-vq-mapping parameter to assign virtqueues to IOThreads. Store the vq:AioContext mapping in the new struct VirtIOBlockDataPlane->vq_aio_context[] field and refactor the code to use the per-vq AioContext instead of the BlockDriverState's AioContext.

Quoted 8 lines

Reimplement --device virtio-blk-pci,iothread= and non-IOThread mode by assigning all virtqueues to the IOThread and main loop's AioContext in vq_aio_context[], respectively.

The comment in struct VirtIOBlockDataPlane about EventNotifiers is stale. Remove it.

I'm looking at virtio_blk_dma_restart_cb/bh(). It seems to run all queued requests in the iothread of the first vq, but when the requests complete, they will push the result to their original vq.

Do we know that the dataplane isn't started and won't be started until the requests complete? (I wouldn't expect so, because then moving to the AioContext of the BlockBackend wouldn't have been necessary either.) Or is there another reason why this is safe?

Kevin

#8 lore raw
Quoted 15 lines · Kevin Wolf

Am 20.12.2023 um 14:47 hat Stefan Hajnoczi geschrieben:

Quoted 5 lines

Add the iothread-vq-mapping parameter to assign virtqueues to IOThreads. Store the vq:AioContext mapping in the new struct VirtIOBlockDataPlane->vq_aio_context[] field and refactor the code to use the per-vq AioContext instead of the BlockDriverState's AioContext.

Quoted 8 lines

Reimplement --device virtio-blk-pci,iothread= and non-IOThread mode by assigning all virtqueues to the IOThread and main loop's AioContext in vq_aio_context[], respectively.

The comment in struct VirtIOBlockDataPlane about EventNotifiers is stale. Remove it.

Quoted 8 lines

I'm looking at virtio_blk_dma_restart_cb/bh(). It seems to run all queued requests in the iothread of the first vq, but when the requests complete, they will push the result to their original vq.

Do we know that the dataplane isn't started and won't be started until the requests complete? (I wouldn't expect so, because then moving to the AioContext of the BlockBackend wouldn't have been necessary either.) Or is there another reason why this is safe?

You are right. I overlooked this. I'll send a patch to make s->rq multi-queue safe.

Stefan

#9 lore raw
In reply to Stefan Hajnoczi

Am 20.12.2023 um 14:47 hat Stefan Hajnoczi geschrieben:

Quoted 15 lines

Add the iothread-vq-mapping parameter to assign virtqueues to IOThreads. Store the vq:AioContext mapping in the new struct VirtIOBlockDataPlane->vq_aio_context[] field and refactor the code to use the per-vq AioContext instead of the BlockDriverState's AioContext.

Reimplement --device virtio-blk-pci,iothread= and non-IOThread mode by assigning all virtqueues to the IOThread and main loop's AioContext in vq_aio_context[], respectively.

The comment in struct VirtIOBlockDataPlane about EventNotifiers is stale. Remove it.

hw/block/dataplane/virtio-blk.c int virtio_blk_data_plane_start(VirtIODevice *vdev) · line 246

Quoted 10 lines
hw/block/dataplane/virtio-blk.c +2 -1
@@ -177,19 +238,13 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
 
     trace_virtio_blk_data_plane_start(s);
 
-    r = blk_set_aio_context(s->conf->conf.blk, s->ctx, &local_err);
+    r = blk_set_aio_context(s->conf->conf.blk, s->vq_aio_context[0],
+                            &local_err);
     if (r < 0) {
         error_report_err(local_err);
         goto fail_aio_context;
     }

This doesn't really have to be an error any more, we'll just submit I/O from any thread we want no matter what the home AioContext of the BlockBackend is.

So the only effect the blk_set_aio_context() has is that other users of the image try to submit their requests from the same iothread as the first virtqueue in the hope that this performs a bit better (maybe less lock contention or whatever the idea was?)

Quoted 11 lines
hw/block/dataplane/virtio-blk.c +0 -7
-    /* Kick right away to begin processing requests already in vring */
-    for (i = 0; i < nvqs; i++) {
-        VirtQueue *vq = virtio_get_queue(s->vdev, i);
-
-        event_notifier_set(virtio_queue_get_host_notifier(vq));
-    }
-
     /*
      * These fields must be visible to the IOThread when it processes the
      * virtqueue, otherwise it will think dataplane has not started yet.

hw/block/dataplane/virtio-blk.c int virtio_blk_data_plane_start(VirtIODevice *vdev) · line 267

Quoted 8 lines
hw/block/dataplane/virtio-blk.c +3 -1
@@ -206,8 +261,12 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
     if (!blk_in_drain(s->conf->conf.blk)) {
         for (i = 0; i < nvqs; i++) {
             VirtQueue *vq = virtio_get_queue(s->vdev, i);
+            AioContext *ctx = s->vq_aio_context[i];
 
-            virtio_queue_aio_attach_host_notifier(vq, s->ctx);
+            /* Kick right away to begin processing requests already in vring */
+            event_notifier_set(virtio_queue_get_host_notifier(vq));

The old code did this also for blk_in_drain() == true. Why don't we need it there any more? Should the 'if' move inside the loop just around attaching the notifier?

hw/block/dataplane/virtio-blk.c int virtio_blk_data_plane_start(VirtIODevice *vdev) · line 272

Quoted 4 lines
hw/block/dataplane/virtio-blk.c +1 -0
+            virtio_queue_aio_attach_host_notifier(vq, ctx);
         }
     }
     return 0;

Kevin

#10 lore raw
Quoted 31 lines · Kevin Wolf

Am 20.12.2023 um 14:47 hat Stefan Hajnoczi geschrieben:

Quoted 15 lines

Add the iothread-vq-mapping parameter to assign virtqueues to IOThreads. Store the vq:AioContext mapping in the new struct VirtIOBlockDataPlane->vq_aio_context[] field and refactor the code to use the per-vq AioContext instead of the BlockDriverState's AioContext.

Reimplement --device virtio-blk-pci,iothread= and non-IOThread mode by assigning all virtqueues to the IOThread and main loop's AioContext in vq_aio_context[], respectively.

The comment in struct VirtIOBlockDataPlane about EventNotifiers is stale. Remove it.

hw/block/dataplane/virtio-blk.c int virtio_blk_data_plane_start(VirtIODevice *vdev) · line 246

Quoted 10 lines
hw/block/dataplane/virtio-blk.c +2 -1
@@ -177,19 +238,13 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
 
     trace_virtio_blk_data_plane_start(s);
 
-    r = blk_set_aio_context(s->conf->conf.blk, s->ctx, &local_err);
+    r = blk_set_aio_context(s->conf->conf.blk, s->vq_aio_context[0],
+                            &local_err);
     if (r < 0) {
         error_report_err(local_err);
         goto fail_aio_context;
     }

This doesn't really have to be an error any more, we'll just submit I/O from any thread we want no matter what the home AioContext of the BlockBackend is.

Quoted 4 lines

So the only effect the blk_set_aio_context() has is that other users of the image try to submit their requests from the same iothread as the first virtqueue in the hope that this performs a bit better (maybe less lock contention or whatever the idea was?)

Yes, I'll change this.

Quoted 16 lines
Quoted 16 lines
hw/block/dataplane/virtio-blk.c +1 -7
-    /* Kick right away to begin processing requests already in vring */
-    for (i = 0; i < nvqs; i++) {
-        VirtQueue *vq = virtio_get_queue(s->vdev, i);
-
-        event_notifier_set(virtio_queue_get_host_notifier(vq));
-    }
-
     /*
      * These fields must be visible to the IOThread when it processes the
      * virtqueue, otherwise it will think dataplane has not started yet.
@@ -206,8 +261,12 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
     if (!blk_in_drain(s->conf->conf.blk)) {
         for (i = 0; i < nvqs; i++) {
             VirtQueue *vq = virtio_get_queue(s->vdev, i);
+            AioContext *ctx = s->vq_aio_context[i];
 
Quoted 7 lines

hw/block/dataplane/virtio-blk.c int virtio_blk_data_plane_start(VirtIODevice *vdev) · line 267

Quoted 3 lines
hw/block/dataplane/virtio-blk.c +2 -1
-            virtio_queue_aio_attach_host_notifier(vq, s->ctx);
+            /* Kick right away to begin processing requests already in vring */
+            event_notifier_set(virtio_queue_get_host_notifier(vq));

The old code did this also for blk_in_drain() == true. Why don't we need it there any more? Should the 'if' move inside the loop just around attaching the notifier?

The answer is I'm not 100% sure. Your suggestion is safer, I'll do that.

Stefan

Applied
#11 lore raw
In reply to Stefan Hajnoczi

Am 20.12.2023 um 14:47 hat Stefan Hajnoczi geschrieben:

Quoted 29 lines

v4:
- Use DummyVirtioForceArrays naming in QAPI schema [Markus]
v3:
- Rebased onto Kevin's block branch
- Add StringOutputVisitor "<omitted>" patch to fix "info qtree" crash
- Fix QAPI schema formatting [Markus]
- Eliminate unnecessary local variable in get_iothread_vq_mapping_list() [Markus]

virtio-blk and virtio-scsi devices 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. With this series applied, "pidstat -t 1" shows that guests with -smp 2 or higher are able to exploit multiple IOThreads.

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"},...]},...'

Quoted 7 lines

There is no way to reassign virtqueues at runtime and I expect that to be a very rare requirement.

Note that JSON --device syntax is required for the iothread-vq-mapping parameter because it's non-scalar.

Based-on: 81e69329d6a4018f4b37d15b6fc845fbe585a93b (https://repo.or.cz/qemu/kevin.git block)

Thanks, applied to the block branch. We agreed off-list that the remaining problems can be fixed in follow-up patches.

Kevin