Skip to contentSkip to conversation

qapi/misc: Fix missed query-iothreads items

PATCH Superseded Zhang Chen 2 participants 11 messages Dec 29, 2025 – Jan 23

v1 of 20 Superseded Latest is v20 →

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

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

As the struct IOThreadInfo definition:
{ 'struct': 'IOThreadInfo',
'data': {'id': 'str',

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

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

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
author
#2 lore raw

PATCH 3/3 qapi: Add thread_status flag for iothreads

In reply to Zhang Chen

The thread_status depends on struct IOThreadInfo's 'attached': 'bool'. Show in the qmp/hmp CMD with 'attached' or 'detached'.

---
 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 33a88ce205..84b01737cf 100644
@@ -197,6 +197,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, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");
         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 6153ed3d04..2eea920bd2 100644
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attached status
+#            (since 10.3.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,
+#                 'thread_status':"attached",
 #                 'poll-max-ns':0,
 #                 "poll-grow":0,
 #                 "poll-shrink":0,
@@ -126,6 +131,7 @@
 #              {
 #                 "id":"iothread1",
 #                 "thread-id":3135,
+#                 'thread_status':"detached",
 #                 'poll-max-ns':0,
 #                 "poll-grow":0,
 #                 "poll-shrink":0,
Signature · 1 line
2.49.0
#3 lore raw

Re: [PATCH 3/3] qapi: Add thread_status flag for iothreads

Quoted 41 lines · Zhang Chen

The thread_status depends on struct IOThreadInfo's 'attached': 'bool'. Show in the qmp/hmp CMD with 'attached' or 'detached'.

---
 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 33a88ce205..84b01737cf 100644
@@ -197,6 +197,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, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");
         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 6153ed3d04..2eea920bd2 100644

qapi/misc.json line 79

Quoted 4 lines
qapi/misc.json +1 -0
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attached status

What does "attached status" actually mean?

qapi/misc.json line 80

Quoted 1 line
qapi/misc.json +1 -0
+#            (since 10.3.0)

(since 12.0)

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,
+#                 'thread_status':"attached",

I believe this is actually

"attached": true

and ...

qapi/misc.json line 134

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

"attached": false

Recommend to create example output by running a test instead of making it up, because making it up likely screws it up :)

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

Re: [PATCH 3/3] qapi: Add thread_status flag for iothreads

Quoted 42 lines · Markus Armbruster
Quoted 39 lines · Zhang Chen

The thread_status depends on struct IOThreadInfo's 'attached': 'bool'. Show in the qmp/hmp CMD with 'attached' or 'detached'.

---
 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 33a88ce205..84b01737cf 100644
@@ -197,6 +197,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, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");
         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 -1
index 6153ed3d04..2eea920bd2 100644
--- a/qapi/misc.json
Quoted 8 lines

qapi/misc.json line 79

Quoted 6 lines

+++ b/qapi/misc.json

qapi/misc.json +1 -0
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attached status

What does "attached status" actually mean?

This flag means weather the "-object iothread" already been used by a real device.
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.

Quoted 4 lines

qapi/misc.json line 80

Quoted 2 lines
qapi/misc.json +1 -0
+#            (since 10.3.0)

(since 12.0)

OK.

Quoted 21 lines
Quoted 14 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,
+#                 'thread_status':"attached",

I believe this is actually

Quoted 3 lines

"attached": true

and ...

No, I changed it here for readability:

Quoted 2 lines

qapi/misc.json line 127

Quoted 2 lines
qapi/misc.json +2 -0
+        monitor_printf(mon, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");

But if you think ""attached": true" is more direct way, I can change it next version.

Quoted 12 lines

qapi/misc.json line 134

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

"attached": false

Quoted 2 lines

Recommend to create example output by running a test instead of making it up, because making it up likely screws it up :)

Uh.... This output print is the real test in my machine, maybe you missed the previous description.

Thanks
Chen

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

Re: [PATCH 3/3] qapi: Add thread_status flag for iothreads

Quoted 91 lines · Zhang Chen
Quoted 42 lines · Markus Armbruster
Quoted 39 lines · Zhang Chen

The thread_status depends on struct IOThreadInfo's 'attached': 'bool'. Show in the qmp/hmp CMD with 'attached' or 'detached'.

---
 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 33a88ce205..84b01737cf 100644
@@ -197,6 +197,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, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");
         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 -1
index 6153ed3d04..2eea920bd2 100644
--- a/qapi/misc.json
Quoted 8 lines

qapi/misc.json line 79

Quoted 6 lines

+++ b/qapi/misc.json

qapi/misc.json +1 -0
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attached status

What does "attached status" actually mean?

This flag means weather the "-object iothread" already been used by a real device.
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.

Quoted 4 lines

qapi/misc.json line 80

Quoted 2 lines
qapi/misc.json +1 -0
+#            (since 10.3.0)

(since 12.0)

OK.

Quoted 23 lines
Quoted 14 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,
+#                 'thread_status':"attached",

I believe this is actually

"attached": true

Quoted 8 lines
Quoted 1 line

and ...

No, I changed it here for readability:

Quoted 2 lines

qapi/misc.json line 127

Quoted 2 lines
qapi/misc.json +2 -0
+        monitor_printf(mon, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");

But if you think ""attached": true" is more direct way, I can change it next version.

If no other comments, I will keep this part and update to version 2 for this series.

Thanks
Chen

Quoted 27 lines
Quoted 13 lines

qapi/misc.json line 134

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

"attached": false

Quoted 2 lines

Recommend to create example output by running a test instead of making it up, because making it up likely screws it up :)

Uh.... This output print is the real test in my machine, maybe you missed the previous description.

Thanks
Chen

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

Re: [PATCH 3/3] qapi: Add thread_status flag for iothreads

In reply to Zhang Chen
Quoted 52 lines · Zhang Chen
Quoted 42 lines · Markus Armbruster
Quoted 39 lines · Zhang Chen

The thread_status depends on struct IOThreadInfo's 'attached': 'bool'. Show in the qmp/hmp CMD with 'attached' or 'detached'.

---
 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 33a88ce205..84b01737cf 100644
@@ -197,6 +197,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, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");
         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 -1
index 6153ed3d04..2eea920bd2 100644
--- a/qapi/misc.json
Quoted 8 lines

qapi/misc.json line 79

Quoted 6 lines

+++ b/qapi/misc.json

qapi/misc.json +1 -0
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attached status

What does "attached status" actually mean?

Quoted 7 lines

This flag means weather the "-object iothread" already been used by a real device.
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.

Why would a management application or human user want to know this?

The answer should lead us to better doc text.

Quoted 32 lines
Quoted 4 lines

qapi/misc.json line 80

Quoted 2 lines
qapi/misc.json +1 -0
+#            (since 10.3.0)

(since 12.0)

OK.

Quoted 21 lines
Quoted 14 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,
+#                 'thread_status':"attached",

I believe this is actually

Quoted 3 lines

"attached": true

and ...

Quoted 7 lines

No, I changed it here for readability:

Quoted 2 lines

qapi/misc.json line 127

Quoted 2 lines
qapi/misc.json +2 -0
+        monitor_printf(mon, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");

But if you think ""attached": true" is more direct way, I can change it next version.

The example in the doc comment shows QMP. Here's what I see in QMP:

    $ qemu-system-x86_64 -S -display none -qmp stdio -object iothread,id=iot0 -name debug-threads=on
    {"QMP": {"version": {"qemu": {"micro": 50, "minor": 2, "major": 10}, "package": "v10.2.0-521-g05115811fa"}, "capabilities": ["oob"]}}
    {"execute": "qmp_capabilities", "arguments": {"enable": ["oob"]}}
    {"return": {}}
    {"execute": "query-iothreads"}
    {"return": [{"attached": false, "poll-shrink": 0, "thread-id": 4031494, "aio-max-batch": 0, "poll-grow": 0, "poll-max-ns": 32768, "id": "iot0"}]}

This shows "attached": false, not 'thread_status': "attached".

The code you showed applies to HMP:

    $ qemu-system-x86_64 -S -display none -monitor stdio -object iothread,id=iot0 -name debug-threads=on
    QEMU 10.2.50 monitor - type 'help' for more information
    (qemu) info iothreads
    iot0:
      thread_id=4032011
      thread_status=detached
      poll-max-ns=32768
      poll-grow=0
      poll-shrink=0
      aio-max-batch=0

thread_status=detached might be slightly more readable than attached=false, but it could also be confusing to people working with both HMP and QMP. I'd avoid the difference between the two.

Quoted 12 lines
Quoted 12 lines

qapi/misc.json line 134

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

"attached": false

Quoted 5 lines
Quoted 2 lines

Recommend to create example output by running a test instead of making it up, because making it up likely screws it up :)

Uh.... This output print is the real test in my machine, maybe you missed the previous description.

I can't see how QMP could possibly show 'thread_status':"detached:.

Quoted 9 lines

Thanks
Chen

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

Re: [PATCH 3/3] qapi: Add thread_status flag for iothreads

Quoted 63 lines · Markus Armbruster
Quoted 52 lines · Zhang Chen
Quoted 42 lines · Markus Armbruster
Quoted 39 lines · Zhang Chen

The thread_status depends on struct IOThreadInfo's 'attached': 'bool'. Show in the qmp/hmp CMD with 'attached' or 'detached'.

---
 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 33a88ce205..84b01737cf 100644
@@ -197,6 +197,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, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");
         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 -1
index 6153ed3d04..2eea920bd2 100644
--- a/qapi/misc.json
Quoted 8 lines

qapi/misc.json line 79

Quoted 6 lines

+++ b/qapi/misc.json

qapi/misc.json +1 -0
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attached status

What does "attached status" actually mean?

Quoted 7 lines

This flag means weather the "-object iothread" already been used by a real device.
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.

Quoted 1 line

Why would a management application or human user want to know this?

Because some usercases already been changed.
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).

Quoted 3 lines

The answer should lead us to better doc text.

OK, I will add it in next version.

Quoted 64 lines
Quoted 32 lines
Quoted 4 lines

qapi/misc.json line 80

Quoted 2 lines
qapi/misc.json +1 -0
+#            (since 10.3.0)

(since 12.0)

OK.

Quoted 21 lines
Quoted 14 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,
+#                 'thread_status':"attached",

I believe this is actually

Quoted 3 lines

"attached": true

and ...

Quoted 7 lines

No, I changed it here for readability:

Quoted 2 lines

qapi/misc.json line 127

Quoted 2 lines
qapi/misc.json +2 -0
+        monitor_printf(mon, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");

But if you think ""attached": true" is more direct way, I can change it next version.

The example in the doc comment shows QMP. Here's what I see in QMP:

    $ qemu-system-x86_64 -S -display none -qmp stdio -object iothread,id=iot0 -name debug-threads=on
    {"QMP": {"version": {"qemu": {"micro": 50, "minor": 2, "major": 10}, "package": "v10.2.0-521-g05115811fa"}, "capabilities": ["oob"]}}
    {"execute": "qmp_capabilities", "arguments": {"enable": ["oob"]}}
    {"return": {}}
    {"execute": "query-iothreads"}
    {"return": [{"attached": false, "poll-shrink": 0, "thread-id": 4031494, "aio-max-batch": 0, "poll-grow": 0, "poll-max-ns": 32768, "id": "iot0"}]}

This shows "attached": false, not 'thread_status': "attached".

The code you showed applies to HMP:

    $ qemu-system-x86_64 -S -display none -monitor stdio -object iothread,id=iot0 -name debug-threads=on
    QEMU 10.2.50 monitor - type 'help' for more information
    (qemu) info iothreads
    iot0:
      thread_id=4032011
      thread_status=detached
      poll-max-ns=32768
      poll-grow=0
      poll-shrink=0
      aio-max-batch=0
Quoted 3 lines

thread_status=detached might be slightly more readable than attached=false, but it could also be confusing to people working with both HMP and QMP. I'd avoid the difference between the two.

Make sense, I will change it to ""attached": false" style next version.

Thanks
Chen

Quoted 31 lines
Quoted 13 lines
Quoted 13 lines

qapi/misc.json line 134

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

"attached": false

Quoted 5 lines
Quoted 2 lines

Recommend to create example output by running a test instead of making it up, because making it up likely screws it up :)

Uh.... This output print is the real test in my machine, maybe you missed the previous description.

I can't see how QMP could possibly show 'thread_status':"detached:.

Quoted 9 lines

Thanks
Chen

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

Re: [PATCH 3/3] qapi: Add thread_status flag for iothreads

Quoted 64 lines · Zhang Chen
Quoted 63 lines · Markus Armbruster
Quoted 59 lines · Zhang Chen
Quoted 42 lines · Markus Armbruster
Quoted 39 lines · Zhang Chen

The thread_status depends on struct IOThreadInfo's 'attached': 'bool'. Show in the qmp/hmp CMD with 'attached' or 'detached'.

---
 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 33a88ce205..84b01737cf 100644
@@ -197,6 +197,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, "  thread_status=%s" "\n",
+                       value->attached ? "attached" : "detached");
         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 -1
index 6153ed3d04..2eea920bd2 100644
--- a/qapi/misc.json
Quoted 8 lines

qapi/misc.json line 79

Quoted 6 lines

+++ b/qapi/misc.json

qapi/misc.json +1 -0
@@ -76,6 +76,9 @@
 #
 # @thread-id: ID of the underlying host thread
 #
+# @attached: flag to show current iothread attached status

What does "attached status" actually mean?

This flag means weather the "-object iothread" already been used by a real device.
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.

Quoted 8 lines
Quoted 1 line

Why would a management application or human user want to know this?

Because some usercases already been changed.
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).

In your v2, you added a (broken) PATCH 4 that describes @attached as follows:

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.

Should this information go into the QAPI schema, too?

Quoted 4 lines
Quoted 2 lines

The answer should lead us to better doc text.

OK, I will add it in next version.

[...]

#9 lore raw
In reply to Zhang Chen
Quoted 8 lines · Zhang Chen

As the struct IOThreadInfo definition:
{ 'struct': 'IOThreadInfo',
'data': {'id': 'str',

           'thread-id': 'int',
           'poll-max-ns': 'int',
           'poll-grow': 'int',
           'poll-shrink': 'int',
           'aio-max-batch': 'int' } }

Suggest:

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).

Quoted 10 lines
---
 qapi/misc.json | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
qapi/misc.json +0 -0
index 28c641fe2f..6153ed3d04 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':0,

Double quotes, please.

The default value appears to be 32768. Maybe show that?

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':0,

Likewise.

Quoted 6 lines
qapi/misc.json +3 -0
+#                 "poll-grow":0,
+#                 "poll-shrink":0,
+#                 "aio-max-batch":0
 #              }
 #           ]
 #        }
author
#10 lore raw
Quoted 12 lines · Markus Armbruster
Quoted 8 lines · Zhang Chen

As the struct IOThreadInfo definition:
{ 'struct': 'IOThreadInfo',
'data': {'id': 'str',

           'thread-id': 'int',
           'poll-max-ns': 'int',
           'poll-grow': 'int',
           'poll-shrink': 'int',
           'aio-max-batch': 'int' } }
Quoted 8 lines

Suggest:

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).

Nice description! I will rewrite the commit log next version.

Quoted 20 lines
Quoted 11 lines
---
 qapi/misc.json | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
qapi/misc.json +0 -0
index 28c641fe2f..6153ed3d04 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':0,

Double quotes, please.

Quoted 1 line

The default value appears to be 32768. Maybe show that?

Good catch, will fix it next version.

Quoted 12 lines

qapi/misc.json line 129

Quoted 10 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':0,

Likewise.

Yes.

Thanks
Chen

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