* [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items
@ 2026-01-26 9:44 Zhang Chen
2026-01-26 9:44 ` [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status Zhang Chen
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Zhang Chen @ 2026-01-26 9:44 UTC (permalink / raw)
To: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
Cc: Zhang Chen, qemu-stable
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..1f5062df2a 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,
+# "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
# }
# ]
# }
--
2.49.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status
2026-01-26 9:44 [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items Zhang Chen
@ 2026-01-26 9:44 ` Zhang Chen
2026-02-05 16:11 ` Stefan Hajnoczi
2026-01-26 9:44 ` [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread Zhang Chen
2026-02-04 12:53 ` [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items Markus Armbruster
2 siblings, 1 reply; 11+ messages in thread
From: Zhang Chen @ 2026-01-26 9:44 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] 11+ messages in thread
* [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
2026-01-26 9:44 [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-01-26 9:44 ` [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status Zhang Chen
@ 2026-01-26 9:44 ` Zhang Chen
2026-02-04 12:58 ` Markus Armbruster
2026-02-05 16:25 ` Stefan Hajnoczi
2026-02-04 12:53 ` [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items Markus Armbruster
2 siblings, 2 replies; 11+ messages in thread
From: Zhang Chen @ 2026-01-26 9:44 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 | 12 ++++++++++++
3 files changed, 15 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 1f5062df2a..cb865d6e48 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -76,6 +76,15 @@
#
# @thread-id: ID of the underlying host thread
#
+# @attached: The attached parameter is a flag indicating whether
+# the IOThread is currently associated with an active device
+# (e.g., virtio-blk). In hotplug scenarios, users can
+# pre-allocate multiple iothread objects to serve as a persistent
+# thread pool. When a device is hot-unplugged, the corresponding
+# IOThread is released but remains available, allowing subsequent
+# hot-plugged devices to attach to and reuse the existing thread.
+# (since 12.0)
+#
# @poll-max-ns: maximum polling time in ns, 0 means polling is
# disabled (since 2.9)
#
@@ -93,6 +102,7 @@
{ 'struct': 'IOThreadInfo',
'data': {'id': 'str',
'thread-id': 'int',
+ 'attached': 'bool',
'poll-max-ns': 'int',
'poll-grow': 'int',
'poll-shrink': 'int',
@@ -118,6 +128,7 @@
# {
# "id":"iothread0",
# "thread-id":3134,
+# "attached":false,
# "poll-max-ns":32768,
# "poll-grow":0,
# "poll-shrink":0,
@@ -126,6 +137,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] 11+ messages in thread
* Re: [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items
2026-01-26 9:44 [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-01-26 9:44 ` [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status Zhang Chen
2026-01-26 9:44 ` [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread Zhang Chen
@ 2026-02-04 12:53 ` Markus Armbruster
2 siblings, 0 replies; 11+ messages in thread
From: Markus Armbruster @ 2026-02-04 12:53 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>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
2026-01-26 9:44 ` [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread Zhang Chen
@ 2026-02-04 12:58 ` Markus Armbruster
2026-02-05 2:49 ` Zhang Chen
2026-02-05 16:25 ` Stefan Hajnoczi
1 sibling, 1 reply; 11+ messages in thread
From: Markus Armbruster @ 2026-02-04 12:58 UTC (permalink / raw)
To: Zhang Chen; +Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake
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>
[...]
> diff --git a/qapi/misc.json b/qapi/misc.json
> index 1f5062df2a..cb865d6e48 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -76,6 +76,15 @@
> #
> # @thread-id: ID of the underlying host thread
> #
> +# @attached: The attached parameter is a flag indicating whether
> +# the IOThread is currently associated with an active device
"the iothread" for consistency with other doc text.
> +# (e.g., virtio-blk). In hotplug scenarios, users can
I'd drop the comma.
> +# pre-allocate multiple iothread objects to serve as a persistent
> +# thread pool. When a device is hot-unplugged, the corresponding
> +# IOThread is released but remains available, allowing subsequent
> +# hot-plugged devices to attach to and reuse the existing thread.
> +# (since 12.0)
(since 11.0)
> +#
> # @poll-max-ns: maximum polling time in ns, 0 means polling is
> # disabled (since 2.9)
> #
> @@ -93,6 +102,7 @@
> { 'struct': 'IOThreadInfo',
> 'data': {'id': 'str',
> 'thread-id': 'int',
> + 'attached': 'bool',
> 'poll-max-ns': 'int',
> 'poll-grow': 'int',
> 'poll-shrink': 'int',
> @@ -118,6 +128,7 @@
> # {
> # "id":"iothread0",
> # "thread-id":3134,
> +# "attached":false,
> # "poll-max-ns":32768,
> # "poll-grow":0,
> # "poll-shrink":0,
> @@ -126,6 +137,7 @@
> # {
> # "id":"iothread1",
> # "thread-id":3135,
> +# "attached":true,
> # "poll-max-ns":32768,
> # "poll-grow":0,
> # "poll-shrink":0,
With that
Acked-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
2026-02-04 12:58 ` Markus Armbruster
@ 2026-02-05 2:49 ` Zhang Chen
2026-02-05 6:55 ` Markus Armbruster
0 siblings, 1 reply; 11+ messages in thread
From: Zhang Chen @ 2026-02-05 2:49 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake
On Wed, Feb 4, 2026 at 8:58 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> 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>
>
> [...]
>
> > diff --git a/qapi/misc.json b/qapi/misc.json
> > index 1f5062df2a..cb865d6e48 100644
> > --- a/qapi/misc.json
> > +++ b/qapi/misc.json
> > @@ -76,6 +76,15 @@
> > #
> > # @thread-id: ID of the underlying host thread
> > #
> > +# @attached: The attached parameter is a flag indicating whether
> > +# the IOThread is currently associated with an active device
>
> "the iothread" for consistency with other doc text.
OK.
>
> > +# (e.g., virtio-blk). In hotplug scenarios, users can
>
> I'd drop the comma.
OK.
>
> > +# pre-allocate multiple iothread objects to serve as a persistent
> > +# thread pool. When a device is hot-unplugged, the corresponding
> > +# IOThread is released but remains available, allowing subsequent
> > +# hot-plugged devices to attach to and reuse the existing thread.
> > +# (since 12.0)
>
> (since 11.0)
OK.
>
> > +#
> > # @poll-max-ns: maximum polling time in ns, 0 means polling is
> > # disabled (since 2.9)
> > #
> > @@ -93,6 +102,7 @@
> > { 'struct': 'IOThreadInfo',
> > 'data': {'id': 'str',
> > 'thread-id': 'int',
> > + 'attached': 'bool',
> > 'poll-max-ns': 'int',
> > 'poll-grow': 'int',
> > 'poll-shrink': 'int',
> > @@ -118,6 +128,7 @@
> > # {
> > # "id":"iothread0",
> > # "thread-id":3134,
> > +# "attached":false,
> > # "poll-max-ns":32768,
> > # "poll-grow":0,
> > # "poll-shrink":0,
> > @@ -126,6 +137,7 @@
> > # {
> > # "id":"iothread1",
> > # "thread-id":3135,
> > +# "attached":true,
> > # "poll-max-ns":32768,
> > # "poll-grow":0,
> > # "poll-shrink":0,
>
> With that
> Acked-by: Markus Armbruster <armbru@redhat.com>
Thanks for review, could you please take a look at the 2/3 patch in this series?
[RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads
attached status
If have some issues, I can fix it in the next version.
Thanks
Chen
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
2026-02-05 2:49 ` Zhang Chen
@ 2026-02-05 6:55 ` Markus Armbruster
0 siblings, 0 replies; 11+ messages in thread
From: Markus Armbruster @ 2026-02-05 6:55 UTC (permalink / raw)
To: Zhang Chen
Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake, Stefan Hajnoczi
Zhang Chen <zhangckid@gmail.com> writes:
> Thanks for review, could you please take a look at the 2/3 patch in this series?
> [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads
> attached status
> If have some issues, I can fix it in the next version.
Stefan, maybe?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status
2026-01-26 9:44 ` [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status Zhang Chen
@ 2026-02-05 16:11 ` Stefan Hajnoczi
2026-02-06 3:20 ` Zhang Chen
0 siblings, 1 reply; 11+ messages in thread
From: Stefan Hajnoczi @ 2026-02-05 16:11 UTC (permalink / raw)
To: Zhang Chen
Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
On Mon, Jan 26, 2026 at 4:52 AM Zhang Chen <zhangckid@gmail.com> wrote:
>
> 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;
> }
This patch will still report attached = true after all users have gone
away. A reference counting API is needed because IOThread users can
come and go (e.g. device hot unplug or block exports being removed).
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
2026-01-26 9:44 ` [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread Zhang Chen
2026-02-04 12:58 ` Markus Armbruster
@ 2026-02-05 16:25 ` Stefan Hajnoczi
2026-02-06 3:47 ` Zhang Chen
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Hajnoczi @ 2026-02-05 16:25 UTC (permalink / raw)
To: Zhang Chen
Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
On Mon, Jan 26, 2026 at 4:52 AM Zhang Chen <zhangckid@gmail.com> wrote:
>
> 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.
I mentioned that a ref/unref API is needed in my reply to Patch 2/3.
The API could look like:
void iothread_ref(IOThread *iothread, const char *holder);
And the holder string is added to a list inside iothread. That way the
monitor commands can report an actual list of holders rather than just
true/false:
attached = ["/qom/path/to/virtio-blk-0", "/qom/path/to/block/export/nbd-0"]
The QOM path would be a useful string to use as a unique identifier.
>
> Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> ---
> iothread.c | 1 +
> monitor/hmp-cmds.c | 2 ++
> qapi/misc.json | 12 ++++++++++++
> 3 files changed, 15 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 1f5062df2a..cb865d6e48 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -76,6 +76,15 @@
> #
> # @thread-id: ID of the underlying host thread
> #
> +# @attached: The attached parameter is a flag indicating whether
> +# the IOThread is currently associated with an active device
> +# (e.g., virtio-blk). In hotplug scenarios, users can
> +# pre-allocate multiple iothread objects to serve as a persistent
> +# thread pool. When a device is hot-unplugged, the corresponding
> +# IOThread is released but remains available, allowing subsequent
> +# hot-plugged devices to attach to and reuse the existing thread.
> +# (since 12.0)
How is this supposed to work since Patch 2 does not support hot unplug
(attached remains true)?
I'm also curious what the use case for this property is. First I
thought it's for debugging, but based on this documentation it sounds
like maybe you want to use it to avoid having to keep track of which
IOThreads are used in a management tool?
> +#
> # @poll-max-ns: maximum polling time in ns, 0 means polling is
> # disabled (since 2.9)
> #
> @@ -93,6 +102,7 @@
> { 'struct': 'IOThreadInfo',
> 'data': {'id': 'str',
> 'thread-id': 'int',
> + 'attached': 'bool',
> 'poll-max-ns': 'int',
> 'poll-grow': 'int',
> 'poll-shrink': 'int',
> @@ -118,6 +128,7 @@
> # {
> # "id":"iothread0",
> # "thread-id":3134,
> +# "attached":false,
> # "poll-max-ns":32768,
> # "poll-grow":0,
> # "poll-shrink":0,
> @@ -126,6 +137,7 @@
> # {
> # "id":"iothread1",
> # "thread-id":3135,
> +# "attached":true,
> # "poll-max-ns":32768,
> # "poll-grow":0,
> # "poll-shrink":0,
> --
> 2.49.0
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status
2026-02-05 16:11 ` Stefan Hajnoczi
@ 2026-02-06 3:20 ` Zhang Chen
0 siblings, 0 replies; 11+ messages in thread
From: Zhang Chen @ 2026-02-06 3:20 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
On Fri, Feb 6, 2026 at 12:11 AM Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> On Mon, Jan 26, 2026 at 4:52 AM Zhang Chen <zhangckid@gmail.com> wrote:
> >
> > 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;
> > }
>
> This patch will still report attached = true after all users have gone
> away. A reference counting API is needed because IOThread users can
> come and go (e.g. device hot unplug or block exports being removed).
>
Make sense. I will add another "int attached_count" in the struct
IOThread next version.
Thanks
Chen
> Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
2026-02-05 16:25 ` Stefan Hajnoczi
@ 2026-02-06 3:47 ` Zhang Chen
0 siblings, 0 replies; 11+ messages in thread
From: Zhang Chen @ 2026-02-06 3:47 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: qemu-devel, Dr . David Alan Gilbert, Eric Blake,
Markus Armbruster
On Fri, Feb 6, 2026 at 12:25 AM Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> On Mon, Jan 26, 2026 at 4:52 AM Zhang Chen <zhangckid@gmail.com> wrote:
> >
> > 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.
>
> I mentioned that a ref/unref API is needed in my reply to Patch 2/3.
> The API could look like:
>
> void iothread_ref(IOThread *iothread, const char *holder);
>
> And the holder string is added to a list inside iothread. That way the
> monitor commands can report an actual list of holders rather than just
> true/false:
>
> attached = ["/qom/path/to/virtio-blk-0", "/qom/path/to/block/export/nbd-0"]
>
> The QOM path would be a useful string to use as a unique identifier.
OK, this looks more specific.
I will try to add it next version.
>
> >
> > Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> > ---
> > iothread.c | 1 +
> > monitor/hmp-cmds.c | 2 ++
> > qapi/misc.json | 12 ++++++++++++
> > 3 files changed, 15 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 1f5062df2a..cb865d6e48 100644
> > --- a/qapi/misc.json
> > +++ b/qapi/misc.json
> > @@ -76,6 +76,15 @@
> > #
> > # @thread-id: ID of the underlying host thread
> > #
> > +# @attached: The attached parameter is a flag indicating whether
> > +# the IOThread is currently associated with an active device
> > +# (e.g., virtio-blk). In hotplug scenarios, users can
> > +# pre-allocate multiple iothread objects to serve as a persistent
> > +# thread pool. When a device is hot-unplugged, the corresponding
> > +# IOThread is released but remains available, allowing subsequent
> > +# hot-plugged devices to attach to and reuse the existing thread.
> > +# (since 12.0)
>
> How is this supposed to work since Patch 2 does not support hot unplug
> (attached remains true)?
Will fix it next version.
>
> I'm also curious what the use case for this property is. First I
> thought it's for debugging, but based on this documentation it sounds
> like maybe you want to use it to avoid having to keep track of which
> IOThreads are used in a management tool?
Debugging is a use case, but more is for some cloud-native use
cases(like kata container).
The VM life cycle may not sync with the real workload(container
running in the VM),
As we know, elastic computing focuses on the dynamic management of resources.
So this series try to optimize hotplug/unplug path by keep the iothread pool.
After the previous task, the management tool need to unplug a virtio-blk device,
When the next task comes, the managent tool need API to check which
iothread in idle state,
and attach some iothreads to another hot plug virtio-blk device.
Thanks
Chen
>
> > +#
> > # @poll-max-ns: maximum polling time in ns, 0 means polling is
> > # disabled (since 2.9)
> > #
> > @@ -93,6 +102,7 @@
> > { 'struct': 'IOThreadInfo',
> > 'data': {'id': 'str',
> > 'thread-id': 'int',
> > + 'attached': 'bool',
> > 'poll-max-ns': 'int',
> > 'poll-grow': 'int',
> > 'poll-shrink': 'int',
> > @@ -118,6 +128,7 @@
> > # {
> > # "id":"iothread0",
> > # "thread-id":3134,
> > +# "attached":false,
> > # "poll-max-ns":32768,
> > # "poll-grow":0,
> > # "poll-shrink":0,
> > @@ -126,6 +137,7 @@
> > # {
> > # "id":"iothread1",
> > # "thread-id":3135,
> > +# "attached":true,
> > # "poll-max-ns":32768,
> > # "poll-grow":0,
> > # "poll-shrink":0,
> > --
> > 2.49.0
> >
> >
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-02-06 3:48 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-26 9:44 [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-01-26 9:44 ` [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status Zhang Chen
2026-02-05 16:11 ` Stefan Hajnoczi
2026-02-06 3:20 ` Zhang Chen
2026-01-26 9:44 ` [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread Zhang Chen
2026-02-04 12:58 ` Markus Armbruster
2026-02-05 2:49 ` Zhang Chen
2026-02-05 6:55 ` Markus Armbruster
2026-02-05 16:25 ` Stefan Hajnoczi
2026-02-06 3:47 ` Zhang Chen
2026-02-04 12:53 ` [RESEND PATCH V3 1/3] qapi/misc: Fix missed query-iothreads items Markus Armbruster
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.