qapi/misc: Fix missed query-iothreads items
PATCH RESEND v3 1/3 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
@@ -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
PATCH RESEND v3 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
@@ -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
@@ -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
Re: [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status
Quoted 45 lines · 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 <[email protected]>--- include/system/iothread.h | 1 + iothread.c | 5 +++++ 2 files changed, 6 insertions(+)include/system/iothread.h +1
-0@@ -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 +4
-0@@ -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);
iothread.c char *iothread_get_id(IOThread *iothread) · line 345
Quoted 6 lines
iothread.c +1
-0@@ -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
Re: [RESEND PATCH V3 2/3] iothread: Introduce a new flag to show iothreads attached status
Quoted 48 lines · Stefan Hajnoczi
Quoted 46 lines · 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 <[email protected]>--- include/system/iothread.h | 1 + iothread.c | 5 +++++ 2 files changed, 6 insertions(+)include/system/iothread.h +1
-0@@ -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 +4
-0@@ -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)
Quoted 10 lines
iothread.c char *iothread_get_id(IOThread *iothread) · line 345
Quoted 5 lines
iothread.c +1
-0AioContext *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
Quoted 1 line
Stefan
PATCH RESEND v3 3/3 qapi: Add attached flag for iothread
In reply to Zhang ChenThe 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 | 12 ++++++++++++ 3 files changed, 15 insertions(+)
iothread.c +1 -0
@@ -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
@@ -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 +12 -0
@@ -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,
Signature · 1 line
2.49.0
Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
Quoted 6 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.
Signed-off-by Zhang Chen <[email protected]>
[...]
qapi/misc.json line 80
Quoted 10 lines
qapi/misc.json +2
-0@@ -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.
qapi/misc.json line 81
Quoted 1 line
qapi/misc.json +1
-0+# (e.g., virtio-blk). In hotplug scenarios, users can
I'd drop the comma.
qapi/misc.json line 86
Quoted 5 lines
qapi/misc.json +5
-0+# 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)
Quoted 21 lines
qapi/misc.json +3
-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,
qapi/misc.json line 143
Quoted 7 lines
qapi/misc.json +1
-0@@ -126,6 +137,7 @@ # { # "id":"iothread1", # "thread-id":3135, +# "attached":true, # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0,
With that
Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
Quoted 12 lines · Markus Armbruster
Quoted 6 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.
Signed-off-by Zhang Chen <[email protected]>[...]
Quoted 12 lines
qapi/misc.json line 80
Quoted 10 lines
qapi/misc.json +2
-0@@ -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.
Quoted 4 lines
qapi/misc.json line 81
Quoted 2 lines
qapi/misc.json +1
-0+# (e.g., virtio-blk). In hotplug scenarios, users canI'd drop the comma.
OK.
Quoted 8 lines
qapi/misc.json line 86
Quoted 6 lines
qapi/misc.json +5
-0+# 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.
Quoted 31 lines
Quoted 22 lines
qapi/misc.json +3
-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,qapi/misc.json line 143
Quoted 7 lines
qapi/misc.json +1
-0@@ -126,6 +137,7 @@ # { # "id":"iothread1", # "thread-id":3135, +# "attached":true, # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0,With that
Quoted 1 line
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
Quoted 1 line
Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
Quoted 4 lines · Zhang Chen
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?
Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
In reply to Zhang ChenQuoted 5 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.
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.
Quoted 39 lines
Signed-off-by Zhang Chen <[email protected]>--- iothread.c | 1 + monitor/hmp-cmds.c | 2 ++ qapi/misc.json | 12 ++++++++++++ 3 files changed, 15 insertions(+)iothread.c +1
-0@@ -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@@ -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@@ -76,6 +76,15 @@ #
qapi/misc.json line 86
Quoted 10 lines
qapi/misc.json +8
-0# @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?
Quoted 32 lines
qapi/misc.json +4
-1+# # @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
Re: [RESEND PATCH V3 3/3] qapi: Add attached flag for iothread
Quoted 13 lines · Stefan Hajnoczi
Quoted 5 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.
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);
Quoted 7 lines
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.
Quoted 45 lines
Quoted 45 lines
Signed-off-by Zhang Chen <[email protected]>--- iothread.c | 1 + monitor/hmp-cmds.c | 2 ++ qapi/misc.json | 12 ++++++++++++ 3 files changed, 15 insertions(+)iothread.c +1
-0@@ -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@@ -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 +3
-0@@ -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
Quoted 8 lines
qapi/misc.json line 86
Quoted 5 lines
qapi/misc.json +5
-0+# 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.
Quoted 5 lines
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
Quoted 33 lines
Quoted 33 lines
qapi/misc.json +4
-1+# # @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
Quoted 8 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 commit1793ad0247c(iothread: add aio-max-batch parameter).Signed-off-by Zhang Chen <[email protected]>