[PATCH V5 09/13] monitor: Update tracking iothread users with holder name

Zhang Chen posted 13 patches 1 month, 1 week ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, John Levon <john.levon@nutanix.com>, Thanos Makatos <thanos.makatos@nutanix.com>, "Cédric Le Goater" <clg@redhat.com>, David Hildenbrand <david@kernel.org>, "Dr. David Alan Gilbert" <dave@treblig.org>, Markus Armbruster <armbru@redhat.com>, Zhang Chen <zhangckid@gmail.com>, Li Zhijian <lizhijian@fujitsu.com>, Jason Wang <jasowang@redhat.com>, Eric Blake <eblake@redhat.com>
There is a newer version of this series
[PATCH V5 09/13] monitor: Update tracking iothread users with holder name
Posted by Zhang Chen 1 month, 1 week ago
Because of monitor create own iothread, and use the
iothread suspend/resume with bh handler and chardev handler.
The QOM lifecycle is hard to track. Update the legacy usage
of "iothread_get_aio_context()" and "iothread_put_aio_context()".

Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
 monitor/monitor.c | 4 ++--
 monitor/qmp.c     | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/monitor/monitor.c b/monitor/monitor.c
index 1273eb7260..5da3c05e8d 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -547,7 +547,7 @@ int monitor_suspend(Monitor *mon)
          * Kick I/O thread to make sure this takes effect.  It'll be
          * evaluated again in prepare() of the watch object.
          */
-        aio_notify(iothread_get_aio_context(mon_iothread));
+        aio_notify(iothread_get_aio_context(mon_iothread, NULL));
     }
 
     trace_monitor_suspend(mon, 1);
@@ -582,7 +582,7 @@ void monitor_resume(Monitor *mon)
         AioContext *ctx;
 
         if (mon->use_io_thread) {
-            ctx = iothread_get_aio_context(mon_iothread);
+            ctx = iothread_get_aio_context(mon_iothread, NULL);
         } else {
             ctx = qemu_get_aio_context();
         }
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 687019811f..93d0328dcd 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -544,12 +544,13 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
          * handling between the main thread and the I/O thread.
          */
         remove_listener_fd_in_watch(chr);
+
         /*
          * We can't call qemu_chr_fe_set_handlers() directly here
          * since chardev might be running in the monitor I/O
          * thread.  Schedule a bottom half.
          */
-        aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
+        aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread, NULL),
                                 monitor_qmp_setup_handlers_bh, mon);
         /* The bottom half will add @mon to @mon_list */
     } else {
-- 
2.49.0
Re: [PATCH V5 09/13] monitor: Update tracking iothread users with holder name
Posted by Stefan Hajnoczi 1 month ago
On Thu, Mar 05, 2026 at 10:24:55PM +0800, Zhang Chen wrote:
> Because of monitor create own iothread, and use the
> iothread suspend/resume with bh handler and chardev handler.
> The QOM lifecycle is hard to track. Update the legacy usage
> of "iothread_get_aio_context()" and "iothread_put_aio_context()".

As mentioned in the prevoius patch, this feature needs to be implemented
fully in order to merged. If only half of it works, then it's not a
feature that users can rely on.

Stefan
Re: [PATCH V5 09/13] monitor: Update tracking iothread users with holder name
Posted by Zhang Chen 1 month ago
On Mon, Mar 9, 2026 at 4:57 PM Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> On Thu, Mar 05, 2026 at 10:24:55PM +0800, Zhang Chen wrote:
> > Because of monitor create own iothread, and use the
> > iothread suspend/resume with bh handler and chardev handler.
> > The QOM lifecycle is hard to track. Update the legacy usage
> > of "iothread_get_aio_context()" and "iothread_put_aio_context()".
>
> As mentioned in the prevoius patch, this feature needs to be implemented
> fully in order to merged. If only half of it works, then it's not a
> feature that users can rely on.

Sure, I will try to implement it as the original iothread get/put design.

Hi Markus and Dave,  do you have any suggestion for how to track the
monitor iothread QOM lifecycle?
Need to do iothread_get/put each time when monitor_suspend/resume ?

Thanks
Chen

>
> Stefan