[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 4/4] iothread: push gcontext earlier in the thre
From: |
Marc-André Lureau |
Subject: |
Re: [Qemu-devel] [PATCH 4/4] iothread: push gcontext earlier in the thread_fn |
Date: |
Fri, 22 Feb 2019 07:37:02 +0100 |
Hi
On Fri, Feb 22, 2019 at 4:14 AM Peter Xu <address@hidden> wrote:
>
> We were pushing the context until right before running the gmainloop.
> Now since we have everything unconditionally, we can move this
> earlier.
>
> One benefit is that now it's done even before init_done_sem, so as
> long as the iothread user calls iothread_create() and completes, we
> know that the thread stack is ready.
>
This will change the default context in the iothread, for code running
there. This may not be a good idea. Until now, only sources dispatched
from iothread_get_g_main_context() would have default context
associated to it.
I don't know if the current behaviour is intentional, but it has some
logic. With this change, you may create hidden races, by changing the
default context of sources to the iothread.
> Signed-off-by: Peter Xu <address@hidden>
> ---
> iothread.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/iothread.c b/iothread.c
> index 9abdbace66..7b7cba5d04 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -53,7 +53,7 @@ static void *iothread_run(void *opaque)
> IOThread *iothread = opaque;
>
> rcu_register_thread();
> -
> + g_main_context_push_thread_default(iothread->worker_context);
> my_iothread = iothread;
> iothread->thread_id = qemu_get_thread_id();
> qemu_sem_post(&iothread->init_done_sem);
> @@ -66,12 +66,11 @@ static void *iothread_run(void *opaque)
> * changed in previous aio_poll()
> */
> if (iothread->running && atomic_read(&iothread->run_gcontext)) {
> - g_main_context_push_thread_default(iothread->worker_context);
> g_main_loop_run(iothread->main_loop);
> - g_main_context_pop_thread_default(iothread->worker_context);
> }
> }
>
> + g_main_context_pop_thread_default(iothread->worker_context);
> rcu_unregister_thread();
> return NULL;
> }
> --
> 2.17.1
>
- Re: [Qemu-devel] [PATCH 1/4] iothread: replace init_done_cond with a semaphore, (continued)
Re: [Qemu-devel] [PATCH 1/4] iothread: replace init_done_cond with a semaphore, Stefan Hajnoczi, 2019/02/27
[Qemu-devel] [PATCH 3/4] iothread: create main loop unconditionally, Peter Xu, 2019/02/21
[Qemu-devel] [PATCH 2/4] iothread: create the gcontext onconditionally, Peter Xu, 2019/02/21
[Qemu-devel] [PATCH 4/4] iothread: push gcontext earlier in the thread_fn, Peter Xu, 2019/02/21
- Re: [Qemu-devel] [PATCH 4/4] iothread: push gcontext earlier in the thread_fn,
Marc-André Lureau <=
Re: [Qemu-devel] [PATCH 0/4] iothread: create gcontext unconditionally, Paolo Bonzini, 2019/02/22