* [PATCH V2 2/4] iothread: Introduce a new flag to show iothreads attached status
2026-01-21 6:41 [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items Zhang Chen
@ 2026-01-21 6:41 ` Zhang Chen
2026-01-21 6:41 ` [PATCH V2 3/4] qapi: Add attached flag for iothread Zhang Chen
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Zhang Chen @ 2026-01-21 6:41 UTC (permalink / raw)
To: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
Cc: Zhang Chen
QEMU Need a flag to show current iothread attached status
when hotplug multi iothreads. For example virtio-blk.
Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
include/system/iothread.h | 1 +
iothread.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/include/system/iothread.h b/include/system/iothread.h
index e26d13c6c7..3d00474523 100644
--- a/include/system/iothread.h
+++ b/include/system/iothread.h
@@ -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 */
diff --git a/iothread.c b/iothread.c
index caf68e0764..38e38fb44d 100644
--- a/iothread.c
+++ b/iothread.c
@@ -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;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH V2 3/4] qapi: Add attached flag for iothread
2026-01-21 6:41 [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-01-21 6:41 ` [PATCH V2 2/4] iothread: Introduce a new flag to show iothreads attached status Zhang Chen
@ 2026-01-21 6:41 ` Zhang Chen
2026-01-23 12:57 ` Markus Armbruster
2026-01-21 6:41 ` [PATCH V2 4/4] qemu-options: Introduce new " Zhang Chen
2026-01-23 12:51 ` [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items Markus Armbruster
3 siblings, 1 reply; 8+ messages in thread
From: Zhang Chen @ 2026-01-21 6:41 UTC (permalink / raw)
To: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
Cc: 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.
Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
iothread.c | 1 +
monitor/hmp-cmds.c | 2 ++
qapi/misc.json | 6 ++++++
3 files changed, 9 insertions(+)
diff --git a/iothread.c b/iothread.c
index 38e38fb44d..fb4898e491 100644
--- a/iothread.c
+++ b/iothread.c
@@ -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;
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 5a673cddb2..7463f34bf5 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -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);
diff --git a/qapi/misc.json b/qapi/misc.json
index e87994c9d9..99ffd45ce5 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -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,
--
2.49.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH V2 3/4] qapi: Add attached flag for iothread
2026-01-21 6:41 ` [PATCH V2 3/4] qapi: Add attached flag for iothread Zhang Chen
@ 2026-01-23 12:57 ` Markus Armbruster
0 siblings, 0 replies; 8+ messages in thread
From: Markus Armbruster @ 2026-01-23 12:57 UTC (permalink / raw)
To: Zhang Chen
Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
Zhang Chen <zhangckid@gmail.com> writes:
> 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.
>
> Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> ---
> iothread.c | 1 +
> monitor/hmp-cmds.c | 2 ++
> qapi/misc.json | 6 ++++++
> 3 files changed, 9 insertions(+)
>
> diff --git a/iothread.c b/iothread.c
> index 38e38fb44d..fb4898e491 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -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;
> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
> index 5a673cddb2..7463f34bf5 100644
> --- a/monitor/hmp-cmds.c
> +++ b/monitor/hmp-cmds.c
> @@ -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);
> diff --git a/qapi/misc.json b/qapi/misc.json
> index e87994c9d9..99ffd45ce5 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -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.
> +#
> # @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",
Invalid JSON. Drop the last ".
> # 'poll-max-ns':32768,
> # "poll-grow":0,
> # "poll-shrink":0,
> @@ -126,6 +131,7 @@
> # {
> # "id":"iothread1",
> # "thread-id":3135,
> +# "attached":true",
Likewise.
> # 'poll-max-ns':32768,
> # "poll-grow":0,
> # "poll-shrink":0,
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH V2 4/4] qemu-options: Introduce new flag for iothread
2026-01-21 6:41 [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-01-21 6:41 ` [PATCH V2 2/4] iothread: Introduce a new flag to show iothreads attached status Zhang Chen
2026-01-21 6:41 ` [PATCH V2 3/4] qapi: Add attached flag for iothread Zhang Chen
@ 2026-01-21 6:41 ` Zhang Chen
2026-01-23 13:04 ` Markus Armbruster
2026-01-23 12:51 ` [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items Markus Armbruster
3 siblings, 1 reply; 8+ messages in thread
From: Zhang Chen @ 2026-01-21 6:41 UTC (permalink / raw)
To: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
Cc: 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).
Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
qemu-options.hx | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/qemu-options.hx b/qemu-options.hx
index ec92723f10..9afe9d4ebb 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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.
--
2.49.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH V2 4/4] qemu-options: Introduce new flag for iothread
2026-01-21 6:41 ` [PATCH V2 4/4] qemu-options: Introduce new " Zhang Chen
@ 2026-01-23 13:04 ` Markus Armbruster
0 siblings, 0 replies; 8+ messages in thread
From: Markus Armbruster @ 2026-01-23 13:04 UTC (permalink / raw)
To: Zhang Chen; +Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake
Zhang Chen <zhangckid@gmail.com> writes:
> 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).
>
> Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> ---
> qemu-options.hx | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index ec92723f10..9afe9d4ebb 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -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.
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items
2026-01-21 6:41 [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items Zhang Chen
` (2 preceding siblings ...)
2026-01-21 6:41 ` [PATCH V2 4/4] qemu-options: Introduce new " Zhang Chen
@ 2026-01-23 12:51 ` Markus Armbruster
2026-01-24 13:48 ` Zhang Chen
3 siblings, 1 reply; 8+ messages in thread
From: Markus Armbruster @ 2026-01-23 12:51 UTC (permalink / raw)
To: Zhang Chen; +Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake, qemu-stable
Zhang Chen <zhangckid@gmail.com> writes:
> 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).
>
> cc: qemu-stable@nongnu.org
>
> Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> ---
> qapi/misc.json | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/qapi/misc.json b/qapi/misc.json
> index 28c641fe2f..e87994c9d9 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -117,11 +117,19 @@
> # <- { "return": [
> # {
> # "id":"iothread0",
> -# "thread-id":3134
> +# "thread-id":3134,
> +# 'poll-max-ns':32768,
Double quotes, please.
> +# "poll-grow":0,
> +# "poll-shrink":0,
> +# "aio-max-batch":0
> # },
> # {
> # "id":"iothread1",
> -# "thread-id":3135
> +# "thread-id":3135,
> +# 'poll-max-ns':32768,
Likewise.
> +# "poll-grow":0,
> +# "poll-shrink":0,
> +# "aio-max-batch":0
> # }
> # ]
> # }
Easiest way to avoid such mistakes is to copy actual QMP output.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items
2026-01-23 12:51 ` [PATCH V2 1/4] qapi/misc: Fix missed query-iothreads items Markus Armbruster
@ 2026-01-24 13:48 ` Zhang Chen
0 siblings, 0 replies; 8+ messages in thread
From: Zhang Chen @ 2026-01-24 13:48 UTC (permalink / raw)
To: Markus Armbruster
Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake, qemu-stable
[-- Attachment #1: Type: text/plain, Size: 1741 bytes --]
On Fri, Jan 23, 2026, 8:51 PM Markus Armbruster <armbru@redhat.com> wrote:
> Zhang Chen <zhangckid@gmail.com> writes:
>
> > 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).
> >
> > cc: qemu-stable@nongnu.org
> >
> > Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> > ---
> > qapi/misc.json | 12 ++++++++++--
> > 1 file changed, 10 insertions(+), 2 deletions(-)
> >
> > diff --git a/qapi/misc.json b/qapi/misc.json
> > index 28c641fe2f..e87994c9d9 100644
> > --- a/qapi/misc.json
> > +++ b/qapi/misc.json
> > @@ -117,11 +117,19 @@
> > # <- { "return": [
> > # {
> > # "id":"iothread0",
> > -# "thread-id":3134
> > +# "thread-id":3134,
> > +# 'poll-max-ns':32768,
>
> Double quotes, please.
>
> > +# "poll-grow":0,
> > +# "poll-shrink":0,
> > +# "aio-max-batch":0
> > # },
> > # {
> > # "id":"iothread1",
> > -# "thread-id":3135
> > +# "thread-id":3135,
> > +# 'poll-max-ns':32768,
>
> Likewise.
>
> > +# "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
>
[-- Attachment #2: Type: text/html, Size: 3202 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread