Skip to contentSkip to conversation

qapi/misc: Fix missed query-iothreads items

PATCH Superseded Zhang Chen 2 participants 8 messages Jan 21 – Jan 24

v2 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
author
#1 lore raw

PATCH v2 2/4 iothread: Introduce a new flag to show iothreads attached status

In reply to Zhang Chen

QEMU Need a flag to show current iothread attached status when hotplug multi iothreads. For example virtio-blk.

---
 include/system/iothread.h | 1 +
 iothread.c                | 5 +++++
 2 files changed, 6 insertions(+)
include/system/iothread.h +1 -0
index e26d13c6c7..3d00474523 100644
@@ -32,6 +32,7 @@ struct IOThread {
     QemuSemaphore init_done_sem; /* is thread init done? */
     bool stopping;              /* has iothread_stop() been called? */
     bool running;               /* should iothread_run() continue? */
+    bool attached;              /* Whether or not attached to device */
     int thread_id;
 
     /* AioContext poll parameters */
iothread.c +5 -0
index caf68e0764..38e38fb44d 100644
@@ -94,6 +94,7 @@ void iothread_stop(IOThread *iothread)
         return;
     }
     iothread->stopping = true;
+    iothread->attached = false;
     aio_bh_schedule_oneshot(iothread->ctx, iothread_stop_bh, iothread);
     qemu_thread_join(&iothread->thread);
 }
@@ -199,6 +200,9 @@ static void iothread_init(EventLoopBase *base, Error **errp)
      */
     iothread_init_gcontext(iothread, thread_name);
 
+    /* Clear iothread attached flag for init gcontext */
+    iothread->attached = false;
+
     iothread_set_aio_context_params(base, &local_error);
     if (local_error) {
         error_propagate(errp, local_error);
@@ -336,6 +340,7 @@ char *iothread_get_id(IOThread *iothread)
 
 AioContext *iothread_get_aio_context(IOThread *iothread)
 {
+    iothread->attached = true;
     return iothread->ctx;
 }
 
Signature · 1 line
2.49.0

Zhang Chen

author
#0 lore raw

PATCH v2 1/4 qapi/misc: Fix missed query-iothreads items

The example is incomplete: it misses members @poll-max-ns, @poll-grow, @poll-shrink, @aio-max-batch. Messed up in commit 5fc00480ab1 (monitor: add poll-* properties into query-iothreads result) and commit 1793ad0247c (iothread: add aio-max-batch parameter).

---
 qapi/misc.json | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
qapi/misc.json +10 -2
index 28c641fe2f..e87994c9d9 100644
@@ -117,11 +117,19 @@
 #     <- { "return": [
 #              {
 #                 "id":"iothread0",
-#                 "thread-id":3134
+#                 "thread-id":3134,
+#                 'poll-max-ns':32768,
+#                 "poll-grow":0,
+#                 "poll-shrink":0,
+#                 "aio-max-batch":0
 #              },
 #              {
 #                 "id":"iothread1",
-#                 "thread-id":3135
+#                 "thread-id":3135,
+#                 'poll-max-ns':32768,
+#                 "poll-grow":0,
+#                 "poll-shrink":0,
+#                 "aio-max-batch":0
 #              }
 #           ]
 #        }
Signature · 1 line
2.49.0
author
#4 lore raw

PATCH v2 4/4 qemu-options: Introduce new flag for iothread

This demand comes from Cloud Native ecosystem.
User want to manage resources more flexible like containers (Kata container). The real workload maybe changed(runc) in the VM without VM reboot, It may need hotplug/unplug different multi disks with multi iothreads to meet high level scheduler's needs(like K8s).

---
 qemu-options.hx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
qemu-options.hx +8 -1
index ec92723f10..9afe9d4ebb 100644
@@ -6352,7 +6352,7 @@ SRST
 
             CN=laptop.example.com,O=Example Home,L=London,ST=London,C=GB
 
-    ``-object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,aio-max-batch=aio-max-batch``
+    ``-object iothread,id=id,attached=attached,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,aio-max-batch=aio-max-batch``
         Creates a dedicated event loop thread that devices can be
         assigned to. This is known as an IOThread. By default device
         emulation happens in vCPU threads or the main event loop thread.
@@ -6376,6 +6376,13 @@ SRST
         for many cases but can be adjusted based on knowledge of the
         workload and/or host device latency.
 
+        The ``attached`` parameter is a flag to show whether the iothread
+        is attached to an actual device(for example virtio-blk). In hotplug
+        scenario, user can add multiple "-object iothread" and multiple
+        devices (like virtio-blk). When user hotunplug the devices can keep
+        the iothreads as a thread pool, following the new hotplug devices can
+        attach to the released iothread.
+
         The ``poll-max-ns`` parameter is the maximum number of
         nanoseconds to busy wait for events. Polling can be disabled by
         setting this value to 0.
Signature · 1 line
2.49.0
author
#2 lore raw

PATCH v2 3/4 qapi: Add attached flag for iothread

In reply to Zhang Chen

The attached flag depends on struct IOThreadInfo's 'attached': 'bool'. It can show whether the iothread is attached to an actual device. Show in the qmp/hmp CMD with "attached": true/false.

---
 iothread.c         | 1 +
 monitor/hmp-cmds.c | 2 ++
 qapi/misc.json     | 6 ++++++
 3 files changed, 9 insertions(+)
iothread.c +1 -0
index 38e38fb44d..fb4898e491 100644
@@ -358,6 +358,7 @@ static int query_one_iothread(Object *object, void *opaque)
     info = g_new0(IOThreadInfo, 1);
     info->id = iothread_get_id(iothread);
     info->thread_id = iothread->thread_id;
+    info->attached = iothread->attached;
     info->poll_max_ns = iothread->poll_max_ns;
     info->poll_grow = iothread->poll_grow;
     info->poll_shrink = iothread->poll_shrink;
monitor/hmp-cmds.c +2 -0
index 5a673cddb2..7463f34bf5 100644
@@ -202,6 +202,8 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
         value = info->value;
         monitor_printf(mon, "%s:\n", value->id);
         monitor_printf(mon, "  thread_id=%" PRId64 "\n", value->thread_id);
+        monitor_printf(mon, "  attached=%s" "\n",
+                       value->attached ? "true" : "false");
         monitor_printf(mon, "  poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
         monitor_printf(mon, "  poll-grow=%" PRId64 "\n", value->poll_grow);
         monitor_printf(mon, "  poll-shrink=%" PRId64 "\n", value->poll_shrink);
qapi/misc.json +6 -0
index e87994c9d9..99ffd45ce5 100644
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attach to device status
+#     (since 12.0)
+#
 # @poll-max-ns: maximum polling time in ns, 0 means polling is
 #     disabled (since 2.9)
 #
@@ -93,6 +96,7 @@
 { 'struct': 'IOThreadInfo',
   'data': {'id': 'str',
            'thread-id': 'int',
+           'attached': 'bool',
            'poll-max-ns': 'int',
            'poll-grow': 'int',
            'poll-shrink': 'int',
@@ -118,6 +122,7 @@
 #              {
 #                 "id":"iothread0",
 #                 "thread-id":3134,
+#                 "attached":false",
 #                 'poll-max-ns':32768,
 #                 "poll-grow":0,
 #                 "poll-shrink":0,
@@ -126,6 +131,7 @@
 #              {
 #                 "id":"iothread1",
 #                 "thread-id":3135,
+#                 "attached":true",
 #                 'poll-max-ns':32768,
 #                 "poll-grow":0,
 #                 "poll-shrink":0,
Signature · 1 line
2.49.0
#6 lore raw
In reply to Zhang Chen
Quoted 17 lines · Zhang Chen

The example is incomplete: it misses members @poll-max-ns, @poll-grow, @poll-shrink, @aio-max-batch. Messed up in commit 5fc00480ab1 (monitor: add poll-* properties into query-iothreads result) and commit 1793ad0247c (iothread: add aio-max-batch parameter).

---
 qapi/misc.json | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
qapi/misc.json +0 -0
index 28c641fe2f..e87994c9d9 100644

qapi/misc.json line 121

Quoted 6 lines
qapi/misc.json +2 -1
@@ -117,11 +117,19 @@
 #     <- { "return": [
 #              {
 #                 "id":"iothread0",
-#                 "thread-id":3134
+#                 "thread-id":3134,
+#                 'poll-max-ns':32768,

Double quotes, please.

qapi/misc.json line 129

Quoted 9 lines
qapi/misc.json +5 -1
+#                 "poll-grow":0,
+#                 "poll-shrink":0,
+#                 "aio-max-batch":0
 #              },
 #              {
 #                 "id":"iothread1",
-#                 "thread-id":3135
+#                 "thread-id":3135,
+#                 'poll-max-ns':32768,

Likewise.

qapi/misc.json line 135

Quoted 6 lines
qapi/misc.json +3 -0
+#                 "poll-grow":0,
+#                 "poll-shrink":0,
+#                 "aio-max-batch":0
 #              }
 #           ]
 #        }

Easiest way to avoid such mistakes is to copy actual QMP output.

#3 lore raw

Re: [PATCH V2 3/4] qapi: Add attached flag for iothread

In reply to Zhang Chen
Quoted 42 lines · Zhang Chen

The attached flag depends on struct IOThreadInfo's 'attached': 'bool'. It can show whether the iothread is attached to an actual device. Show in the qmp/hmp CMD with "attached": true/false.

---
 iothread.c         | 1 +
 monitor/hmp-cmds.c | 2 ++
 qapi/misc.json     | 6 ++++++
 3 files changed, 9 insertions(+)
iothread.c +1 -0
index 38e38fb44d..fb4898e491 100644
@@ -358,6 +358,7 @@ static int query_one_iothread(Object *object, void *opaque)
     info = g_new0(IOThreadInfo, 1);
     info->id = iothread_get_id(iothread);
     info->thread_id = iothread->thread_id;
+    info->attached = iothread->attached;
     info->poll_max_ns = iothread->poll_max_ns;
     info->poll_grow = iothread->poll_grow;
     info->poll_shrink = iothread->poll_shrink;
monitor/hmp-cmds.c +2 -0
index 5a673cddb2..7463f34bf5 100644
@@ -202,6 +202,8 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
         value = info->value;
         monitor_printf(mon, "%s:\n", value->id);
         monitor_printf(mon, "  thread_id=%" PRId64 "\n", value->thread_id);
+        monitor_printf(mon, "  attached=%s" "\n",
+                       value->attached ? "true" : "false");
         monitor_printf(mon, "  poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
         monitor_printf(mon, "  poll-grow=%" PRId64 "\n", value->poll_grow);
         monitor_printf(mon, "  poll-shrink=%" PRId64 "\n", value->poll_shrink);
qapi/misc.json +0 -0
index e87994c9d9..99ffd45ce5 100644

qapi/misc.json line 80

Quoted 5 lines
qapi/misc.json +2 -0
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attach to device status
+#     (since 12.0)

We started to talk about improving the description in review of v1. Let's continue there.

Quoted 13 lines
qapi/misc.json +2 -0
+#
 # @poll-max-ns: maximum polling time in ns, 0 means polling is
 #     disabled (since 2.9)
 #
@@ -93,6 +96,7 @@
 { 'struct': 'IOThreadInfo',
   'data': {'id': 'str',
            'thread-id': 'int',
+           'attached': 'bool',
            'poll-max-ns': 'int',
            'poll-grow': 'int',
            'poll-shrink': 'int',

qapi/misc.json line 125

Quoted 4 lines
qapi/misc.json +1 -0
@@ -118,6 +122,7 @@
 #              {
 #                 "id":"iothread0",
 #                 "thread-id":3134,
+#                 "attached":false",

Invalid JSON. Drop the last ".

qapi/misc.json line 134

Quoted 8 lines
qapi/misc.json +1 -0
 #                 'poll-max-ns':32768,
 #                 "poll-grow":0,
 #                 "poll-shrink":0,
@@ -126,6 +131,7 @@
 #              {
 #                 "id":"iothread1",
 #                 "thread-id":3135,
+#                 "attached":true",

Likewise.

Quoted 3 lines
qapi/misc.json +0 -0
 #                 'poll-max-ns':32768,
 #                 "poll-grow":0,
 #                 "poll-shrink":0,
#5 lore raw

Re: [PATCH V2 4/4] qemu-options: Introduce new flag for iothread

In reply to Zhang Chen
Quoted 28 lines · Zhang Chen

This demand comes from Cloud Native ecosystem.
User want to manage resources more flexible like containers (Kata container). The real workload maybe changed(runc) in the VM without VM reboot, It may need hotplug/unplug different multi disks with multi iothreads to meet high level scheduler's needs(like K8s).

---
 qemu-options.hx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
qemu-options.hx +1 -1
index ec92723f10..9afe9d4ebb 100644
@@ -6352,7 +6352,7 @@ SRST
 
             CN=laptop.example.com,O=Example Home,L=London,ST=London,C=GB
 
-    ``-object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,aio-max-batch=aio-max-batch``
+    ``-object iothread,id=id,attached=attached,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,aio-max-batch=aio-max-batch``
         Creates a dedicated event loop thread that devices can be
         assigned to. This is known as an IOThread. By default device
         emulation happens in vCPU threads or the main event loop thread.
@@ -6376,6 +6376,13 @@ SRST
         for many cases but can be adjusted based on knowledge of the
         workload and/or host device latency.
 

qemu-options.hx SRST · line 6388

Quoted 10 lines
qemu-options.hx +7 -0
+        The ``attached`` parameter is a flag to show whether the iothread
+        is attached to an actual device(for example virtio-blk). In hotplug
+        scenario, user can add multiple "-object iothread" and multiple
+        devices (like virtio-blk). When user hotunplug the devices can keep
+        the iothreads as a thread pool, following the new hotplug devices can
+        attach to the released iothread.
+
         The ``poll-max-ns`` parameter is the maximum number of
         nanoseconds to busy wait for events. Polling can be disabled by
         setting this value to 0.

You're documenting something that does not exist:

    $ qemu-system-aarch64 -object iothread,id=iot0,attached=off
    upstream-qemu: -object iothread,id=iot0,attached=off: Invalid parameter 'attached'

The properties of iothread objects are defined in type IothreadProperties in qapi/qom.json.

author
#7 lore raw
In reply to Markus Armbruster
Quoted 40 lines · Markus Armbruster
Quoted 17 lines · Zhang Chen

The example is incomplete: it misses members @poll-max-ns, @poll-grow, @poll-shrink, @aio-max-batch. Messed up in commit 5fc00480ab1 (monitor: add poll-* properties into query-iothreads result) and commit 1793ad0247c (iothread: add aio-max-batch parameter).

---
 qapi/misc.json | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
qapi/misc.json +0 -0
index 28c641fe2f..e87994c9d9 100644

qapi/misc.json line 121

Quoted 6 lines
qapi/misc.json +2 -1
@@ -117,11 +117,19 @@
 #     <- { "return": [
 #              {
 #                 "id":"iothread0",
-#                 "thread-id":3134
+#                 "thread-id":3134,
+#                 'poll-max-ns':32768,

Double quotes, please.

qapi/misc.json line 129

Quoted 9 lines
qapi/misc.json +5 -1
+#                 "poll-grow":0,
+#                 "poll-shrink":0,
+#                 "aio-max-batch":0
 #              },
 #              {
 #                 "id":"iothread1",
-#                 "thread-id":3135
+#                 "thread-id":3135,
+#                 'poll-max-ns':32768,

Likewise.

Quoted 9 lines

qapi/misc.json line 135

Quoted 6 lines
qapi/misc.json +3 -0
+#                 "poll-grow":0,
+#                 "poll-shrink":0,
+#                 "aio-max-batch":0
 #              }
 #           ]
 #        }

Easiest way to avoid such mistakes is to copy actual QMP output.

Oh, sorry to typo for this series... Will fix it with double check.

Thanks
Chen

Quoted 1 line