All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Zhang Chen <zhangckid@gmail.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	 "Dr . David Alan Gilbert" <dave@treblig.org>,
	 Eric Blake <eblake@redhat.com>,
	 "Michael S . Tsirkin" <mst@redhat.com>,
	 Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [PATCH V8 07/15] monitor: Update tracking iothread users with holder
Date: Tue, 02 Jun 2026 19:20:24 +0200	[thread overview]
Message-ID: <87qzmorh9j.fsf@pond.sub.org> (raw)
In-Reply-To: <20260529213321.96271-8-zhangckid@gmail.com> (Zhang Chen's message of "Sat, 30 May 2026 05:33:13 +0800")

Zhang Chen <zhangckid@gmail.com> writes:

> Based on monitor ID tracking iothread users with holder.
> Introduce the AioContext in the Monitor struct to avoid repeated calls to
> iothread_get_aio_context()

iothread_get_aio_context(iothread) returns iothread->ctx.  I doubt
avoiding the call is worth the complexity yet another variable adds.

>                            and ensure symmetrical ref/unref during
> monitor lifecycle.

What do you mean by that?

> Signed-off-by: Zhang Chen <zhangckid@gmail.com>
> ---
>  monitor/monitor-internal.h |  3 +++
>  monitor/monitor.c          | 20 ++++++++++++++++++--
>  monitor/qmp.c              |  3 ++-
>  3 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
> index 2060311b03..92d7630921 100644
> --- a/monitor/monitor-internal.h
> +++ b/monitor/monitor-internal.h
> @@ -127,6 +127,9 @@ struct Monitor {
>      guint out_watch;
>      int mux_out;
>      int reset_seen;
> +
> +    /* iothread context */
> +    AioContext *ctx;
>  };
>  
>  struct MonitorHMP {
> diff --git a/monitor/monitor.c b/monitor/monitor.c
> index dafb4ad8b0..7eec6f967d 100644
> --- a/monitor/monitor.c
> +++ b/monitor/monitor.c
> @@ -529,7 +529,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(mon->ctx);
>      }
>  
>      trace_monitor_suspend(mon, 1);
> @@ -564,7 +564,7 @@ void monitor_resume(Monitor *mon)
>          AioContext *ctx;
>  
>          if (mon->use_io_thread) {
> -            ctx = iothread_get_aio_context(mon_iothread);
> +            ctx = mon->ctx;
>          } else {
>              ctx = qemu_get_aio_context();
>          }
> @@ -612,6 +612,12 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
>  {
>      if (use_io_thread && !mon_iothread) {
>          monitor_iothread_init();
> +
> +        IOThreadHolder holder = {
> +            .type = IO_THREAD_HOLDER_KIND_MONITOR_NAME,
> +            .u.monitor_name.monitor_name = (char *)mon->id,
> +        };
> +        mon->ctx = iothread_ref_and_get_aio_context(mon_iothread, &holder);
>      }
>      qemu_mutex_init(&mon->mon_lock);
>      mon->is_qmp = is_qmp;
> @@ -631,6 +637,16 @@ void monitor_data_destroy(Monitor *mon)
>      }
>      g_string_free(mon->outbuf, true);
>      qemu_mutex_destroy(&mon->mon_lock);
> +
> +    if (mon->ctx && mon_iothread) {
> +        IOThreadHolder holder = {
> +            .type = IO_THREAD_HOLDER_KIND_MONITOR_NAME,
> +            .u.monitor_name.monitor_name = (char *)mon->id,
> +        };
> +
> +        iothread_put_aio_context(mon_iothread, &holder);
> +        mon->ctx = NULL;
> +    }
>  }
>  
>  void monitor_cleanup(void)
> diff --git a/monitor/qmp.c b/monitor/qmp.c
> index b210850a15..b67674aef3 100644
> --- a/monitor/qmp.c
> +++ b/monitor/qmp.c
> @@ -565,7 +565,8 @@ void monitor_init_qmp(Chardev *chr, bool pretty, const char *id, Error **errp)
>           * 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),
> +        Monitor *mon_p = &mon->common;
> +        aio_bh_schedule_oneshot(mon_p->ctx,
>                                  monitor_qmp_setup_handlers_bh, mon);
>          /* The bottom half will add @mon to @mon_list */
>      } else {

The patch does two things:

(1) Replace iothread_get_aio_context(mon_iothread) by mon->ctx.

(2) Call iothread_ref_and_get_aio_context() / iothread_put_aio_context().

I challenged (1).  If we decide we want it, I'll ask you to split the
patch.



  reply	other threads:[~2026-06-02 17:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29 21:33 [PATCH V8 00/15] iothread: Support tracking and querying IOThread holders Zhang Chen
2026-05-29 21:33 ` [PATCH V8 01/15] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-05-29 21:33 ` [PATCH V8 02/15] iothread: introduce iothread_ref/unref to track attached devices Zhang Chen
2026-06-02 11:29   ` Markus Armbruster
2026-05-29 21:33 ` [PATCH V8 03/15] iothread: tracking iothread users with holder name Zhang Chen
2026-05-29 21:33 ` [PATCH V8 04/15] iothread: introduce iothread_unsafe_get_aio_context() Zhang Chen
2026-05-29 21:33 ` [PATCH V8 05/15] block/export: track IOThread reference in BlockExport Zhang Chen
2026-05-29 21:33 ` [PATCH V8 06/15] monitor: assign unique default ID to anonymous monitors Zhang Chen
2026-06-02 17:02   ` Markus Armbruster
2026-06-04  9:57     ` Zhang Chen
2026-05-29 21:33 ` [PATCH V8 07/15] monitor: Update tracking iothread users with holder Zhang Chen
2026-06-02 17:20   ` Markus Armbruster [this message]
2026-06-04 10:16     ` Zhang Chen
2026-05-29 21:33 ` [PATCH V8 08/15] virtio-vq-mapping: track iothread-vq-mapping references using device path Zhang Chen
2026-05-29 21:33 ` [PATCH V8 09/15] virtio: use iothread_get/put_aio_context for thread pinning Zhang Chen
2026-05-29 21:33 ` [PATCH V8 10/15] net/colo: track IOThread references using path-based holder Zhang Chen
2026-05-29 21:33 ` [PATCH V8 11/15] virtio-balloon: Update tracking iothread users with holder Zhang Chen
2026-05-29 21:33 ` [PATCH V8 12/15] vfio-user/proxy: Update tracking iothread users with holder name Zhang Chen
2026-05-29 21:33 ` [PATCH V8 13/15] xen-block: " Zhang Chen
2026-05-29 21:33 ` [PATCH V8 14/15] qapi: examine IOThread attachment status via query-iothreads Zhang Chen
2026-06-02 17:34   ` Markus Armbruster
2026-06-04 11:49     ` Zhang Chen
2026-05-29 21:33 ` [PATCH V8 15/15] iothread: simplify API by merging iothread_get_aio_context variants Zhang Chen
2026-06-02 17:41   ` Markus Armbruster
2026-06-04 11:53     ` Zhang Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87qzmorh9j.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=dave@treblig.org \
    --cc=eblake@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=zhangckid@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.