[PATCH v3] iothread: Set the GSource "name" field

Fabiano Rosas posted 1 patch 1 year, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230905180359.14083-1-farosas@suse.de
iothread.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
[PATCH v3] iothread: Set the GSource "name" field
Posted by Fabiano Rosas 1 year, 2 months ago
Having a name in the source helps with debugging core dumps when one
might not have access to TLS data to cross-reference AioContexts with
their addresses.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
v3:
used const
v2:
used g_autofree where appropriate
---
 iothread.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/iothread.c b/iothread.c
index b41c305bd9..b753286414 100644
--- a/iothread.c
+++ b/iothread.c
@@ -138,12 +138,14 @@ static void iothread_instance_finalize(Object *obj)
     qemu_sem_destroy(&iothread->init_done_sem);
 }
 
-static void iothread_init_gcontext(IOThread *iothread)
+static void iothread_init_gcontext(IOThread *iothread, const char *thread_name)
 {
     GSource *source;
+    g_autofree char *name = g_strdup_printf("%s aio-context", thread_name);
 
     iothread->worker_context = g_main_context_new();
     source = aio_get_g_source(iothread_get_aio_context(iothread));
+    g_source_set_name(source, name);
     g_source_attach(source, iothread->worker_context);
     g_source_unref(source);
     iothread->main_loop = g_main_loop_new(iothread->worker_context, TRUE);
@@ -180,7 +182,7 @@ static void iothread_init(EventLoopBase *base, Error **errp)
 {
     Error *local_error = NULL;
     IOThread *iothread = IOTHREAD(base);
-    char *thread_name;
+    g_autofree char *thread_name = NULL;
 
     iothread->stopping = false;
     iothread->running = true;
@@ -189,11 +191,14 @@ static void iothread_init(EventLoopBase *base, Error **errp)
         return;
     }
 
+    thread_name = g_strdup_printf("IO %s",
+                        object_get_canonical_path_component(OBJECT(base)));
+
     /*
      * Init one GMainContext for the iothread unconditionally, even if
      * it's not used
      */
-    iothread_init_gcontext(iothread);
+    iothread_init_gcontext(iothread, thread_name);
 
     iothread_set_aio_context_params(base, &local_error);
     if (local_error) {
@@ -206,11 +211,8 @@ static void iothread_init(EventLoopBase *base, Error **errp)
     /* This assumes we are called from a thread with useful CPU affinity for us
      * to inherit.
      */
-    thread_name = g_strdup_printf("IO %s",
-                        object_get_canonical_path_component(OBJECT(base)));
     qemu_thread_create(&iothread->thread, thread_name, iothread_run,
                        iothread, QEMU_THREAD_JOINABLE);
-    g_free(thread_name);
 
     /* Wait for initialization to complete */
     while (iothread->thread_id == -1) {
-- 
2.35.3
Re: [PATCH v3] iothread: Set the GSource "name" field
Posted by Stefan Hajnoczi 1 year, 2 months ago
On Tue, Sep 05, 2023 at 03:03:59PM -0300, Fabiano Rosas wrote:
> Having a name in the source helps with debugging core dumps when one
> might not have access to TLS data to cross-reference AioContexts with
> their addresses.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
> v3:
> used const
> v2:
> used g_autofree where appropriate
> ---
>  iothread.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)

Thanks, applied to my monitor-drain_call_rcu tree:
https://gitlab.com/stefanha/qemu/commits/monitor-drain_call_rcu

Stefan
Re: [PATCH v3] iothread: Set the GSource "name" field
Posted by Stefan Hajnoczi 1 year, 2 months ago
On Tue, 5 Sept 2023 at 16:57, Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> On Tue, Sep 05, 2023 at 03:03:59PM -0300, Fabiano Rosas wrote:
> > Having a name in the source helps with debugging core dumps when one
> > might not have access to TLS data to cross-reference AioContexts with
> > their addresses.
> >
> > Signed-off-by: Fabiano Rosas <farosas@suse.de>
> > ---
> > v3:
> > used const
> > v2:
> > used g_autofree where appropriate
> > ---
> >  iothread.c | 14 ++++++++------
> >  1 file changed, 8 insertions(+), 6 deletions(-)
>
> Thanks, applied to my monitor-drain_call_rcu tree:
> https://gitlab.com/stefanha/qemu/commits/monitor-drain_call_rcu

That should have been https://gitlab.com/stefanha/qemu/-/commits/block. :)

Stefan
Re: [PATCH v3] iothread: Set the GSource "name" field
Posted by Philippe Mathieu-Daudé 1 year, 2 months ago
On 5/9/23 20:03, Fabiano Rosas wrote:
> Having a name in the source helps with debugging core dumps when one
> might not have access to TLS data to cross-reference AioContexts with
> their addresses.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
> v3:
> used const
> v2:
> used g_autofree where appropriate
> ---
>   iothread.c | 14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>