Zhang Chen <[email protected]> writes:
> On Thu, Jan 8, 2026 at 8:12 PM Markus Armbruster <[email protected]> wrote:
>>
>> Zhang Chen <[email protected]> writes:
>>
>> > The thread_status depends on struct IOThreadInfo's
>> > 'attached': 'bool'. Show in the qmp/hmp CMD with
>> > 'attached' or 'detached'.
>> >
>> > Signed-off-by: Zhang Chen <[email protected]>
>> > ---
>> > 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 33a88ce205..84b01737cf 100644
>> > --- a/monitor/hmp-cmds.c
>> > +++ b/monitor/hmp-cmds.c
>> > @@ -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);
>> > diff --git a/qapi/misc.json b/qapi/misc.json
>> > index 6153ed3d04..2eea920bd2 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 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.
Why would a management application or human user want to know this?
The answer should lead us to better doc text.
>>
>> > +# (since 10.3.0)
>>
>> (since 12.0)
>
> OK.
>
>>
>> > +#
>> > # @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",
>>
>> I believe this is actually
>>
>> "attached": true
>>
>> and ...
>
> No, I changed it here for readability:
>
>> > + 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.
>>
>> > # '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 :)
>
> 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:.
>
> Thanks
> Chen
>
>>
>> > # 'poll-max-ns':0,
>> > # "poll-grow":0,
>> > # "poll-shrink":0,
>>