qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] 答复: Re: [PATCH] qemu-iothread: IOThread supports the GMainContext eventloop
@ 2017-08-10  9:17 wang.yong155
  2017-08-10  9:52 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: wang.yong155 @ 2017-08-10  9:17 UTC (permalink / raw)
  To: pbonzini
  Cc: stefanha, famz, jasowang, wang.guang55, zhangchen.fnst,
	zhang.zhanghailiang, lizhijian, qemu-devel

>Nice.  Just a note, I think an iothread should have its own (optional)

>GMainContext accessed with iothread_get_g_main_context(iothread).  When

>you call it for the first time, the iothread:

>

>1) creates a GMainContext

>

>2) adds the AioContext as a GSource in the GMainContext

>

>3) asks iothread_run to switch from the AioContext loop to the

>GMainContext loop

>

>

>To simplify thread-safety:

>

>1) the GMainContext can be wrapped with a GOnce

>

>2) the GOnce callback can leave steps 2 and 3 to a bottom half.

>

Thanks, I will submit a patch v2.




WangYong






原始邮件



发件人: <pbonzini@redhat.com>
收件人:王勇10170530
抄送人: <stefanha@redhat.com> <famz@redhat.com> <jasowang@redhat.com>王广10165992 <zhangchen.fnst@cn.fujitsu.com> <zhang.zhanghailiang@huawei.com> <lizhijian@cn.fujitsu.com> <qemu-devel@nongnu.org>
日 期 :2017年08月10日 16:51
主 题 :Re: [PATCH] qemu-iothread: IOThread supports the GMainContext eventloop







----- Original Message -----
> From: "Wang yong" <wang.yong155@zte.com.cn>
> To: pbonzini@redhat.com, stefanha@redhat.com, famz@redhat.com, jasowang@redhat.com
> Cc: "wang yong155" <wang.yong155@zte.com.cn>, "wang guang55" <wang.guang55@zte.com.cn>, "zhangchen fnst"
> <zhangchen.fnst@cn.fujitsu.com>, "zhang zhanghailiang" <zhang.zhanghailiang@huawei.com>, lizhijian@cn.fujitsu.com,
> qemu-devel@nongnu.org
> Sent: Friday, August 11, 2017 2:29:15 AM
> Subject: [PATCH] qemu-iothread: IOThread supports the GMainContext event loop
> 
> From: Wang Yong<wang.yong155@zte.com.cn>
> 
> IOThread uses AioContext event loop and does not run a GMainContext.
> Therefore,chardev cannot work in IOThread,such as the chardev is
> used for colo-compare packets reception.
> 
> This patch makes the IOThread run the GMainContext event loop,
> chardev and IOThread can work together.
> 
> Signed-off-by: Wang Yong<wang.yong155@zte.com.cn>
> Signed-off-by: Wang Guang<wang.guang55@zte.com.cn>

Nice.  Just a note, I think an iothread should have its own (optional)
GMainContext accessed with iothread_get_g_main_context(iothread).  When
you call it for the first time, the iothread:

1) creates a GMainContext

2) adds the AioContext as a GSource in the GMainContext

3) asks iothread_run to switch from the AioContext loop to the
GMainContext loop


To simplify thread-safety:

1) the GMainContext can be wrapped with a GOnce

2) the GOnce callback can leave steps 2 and 3 to a bottom half.

Paolo

> ---
>  include/sysemu/iothread.h |  1 +
>  iothread.c                | 13 +++++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h
> index e6da1a4..ffe4e8a 100644
> --- a/include/sysemu/iothread.h
> +++ b/include/sysemu/iothread.h
> @@ -24,6 +24,7 @@ typedef struct {
>  
>      QemuThread thread
>      AioContext *ctx
> +    GMainLoop *loop
>      QemuMutex init_done_lock
>      QemuCond init_done_cond    /* is thread initialization done? */
>      bool stopping
> diff --git a/iothread.c b/iothread.c
> index beeb870..b6f3c3c 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -46,6 +46,7 @@ AioContext *qemu_get_current_aio_context(void)
>  static void *iothread_run(void *opaque)
>  {
>      IOThread *iothread = opaque
> +    GMainContext *context
>  
>      rcu_register_thread()
>  
> @@ -57,6 +58,15 @@ static void *iothread_run(void *opaque)
>  
>      while (!atomic_read(&iothread->stopping)) {
>          aio_poll(iothread->ctx, true)
> +
> +        context = iothread->ctx->source.context
> +        if (context) {
> +            iothread->loop = g_main_loop_new(context, TRUE)
> +            g_main_loop_run(iothread->loop)
> +
> +            g_main_loop_unref(iothread->loop)
> +            g_main_context_unref(context)
> +        }
>      }
>  
>      rcu_unregister_thread()
> @@ -72,6 +82,9 @@ static int iothread_stop(Object *object, void *opaque)
>          return 0
>      }
>      iothread->stopping = true
> +    if (iothread->loop) {
> +        g_main_loop_quit(iothread->loop)
> +    }
>      aio_notify(iothread->ctx)
>      qemu_thread_join(&iothread->thread)
>      return 0
> --
> 1.8.3.1
> 
> 
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] 答复: Re: [PATCH] qemu-iothread: IOThread supports the GMainContext eventloop
  2017-08-10  9:17 [Qemu-devel] 答复: Re: [PATCH] qemu-iothread: IOThread supports the GMainContext eventloop wang.yong155
@ 2017-08-10  9:52 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2017-08-10  9:52 UTC (permalink / raw)
  To: wang.yong155
  Cc: lizhijian, famz, zhang.zhanghailiang, zhangchen.fnst,
	wang.guang55, jasowang, qemu-devel, stefanha

On 10/08/2017 11:17, wang.yong155@zte.com.cn wrote:
>> Nice.  Just a note, I think an iothread should have its own (optional)
> 
>> GMainContext accessed with iothread_get_g_main_context(iothread).  When
> 
>> you call it for the first time, the iothread:
> 
>>
> 
>> 1) creates a GMainContext
> 
>>
> 
>> 2) adds the AioContext as a GSource in the GMainContext
> 
>>
> 
>> 3) asks iothread_run to switch from the AioContext loop to the
> 
>> GMainContext loop
> 
>>
> 
>>
> 
>> To simplify thread-safety:
> 
>>
> 
>> 1) the GMainContext can be wrapped with a GOnce
> 
>>
> 
>> 2) the GOnce callback can leave steps 2 and 3 to a bottom half.
> 
>>
> 
> Thanks, I will submit a patch v2.
> 
> 
> 
> 
> WangYong
> 
> 
> 
> 
> 
> 
> 原始邮件
> 
> 
> 
> 发件人: <pbonzini@redhat.com>
> 收件人:王勇10170530
> 抄送人: <stefanha@redhat.com> <famz@redhat.com> <jasowang@redhat.com>王广10165992 <zhangchen.fnst@cn.fujitsu.com> <zhang.zhanghailiang@huawei.com> <lizhijian@cn.fujitsu.com> <qemu-devel@nongnu.org>
> 日 期 :2017年08月10日 16:51
> 主 题 :Re: [PATCH] qemu-iothread: IOThread supports the GMainContext eventloop
> 
> 
> 
> 
> 
> 
> 
> ----- Original Message -----
>> From: "Wang yong" <wang.yong155@zte.com.cn>
>> To: pbonzini@redhat.com, stefanha@redhat.com, famz@redhat.com, jasowang@redhat.com
>> Cc: "wang yong155" <wang.yong155@zte.com.cn>, "wang guang55" <wang.guang55@zte.com.cn>, "zhangchen fnst"
>> <zhangchen.fnst@cn.fujitsu.com>, "zhang zhanghailiang" <zhang.zhanghailiang@huawei.com>, lizhijian@cn.fujitsu.com,
>> qemu-devel@nongnu.org
>> Sent: Friday, August 11, 2017 2:29:15 AM
>> Subject: [PATCH] qemu-iothread: IOThread supports the GMainContext event loop
>>
>> From: Wang Yong<wang.yong155@zte.com.cn>
>>
>> IOThread uses AioContext event loop and does not run a GMainContext.
>> Therefore,chardev cannot work in IOThread,such as the chardev is
>> used for colo-compare packets reception.
>>
>> This patch makes the IOThread run the GMainContext event loop,
>> chardev and IOThread can work together.
>>
>> Signed-off-by: Wang Yong<wang.yong155@zte.com.cn>
>> Signed-off-by: Wang Guang<wang.guang55@zte.com.cn>
> 
> Nice.  Just a note, I think an iothread should have its own (optional)
> GMainContext accessed with iothread_get_g_main_context(iothread).  When
> you call it for the first time, the iothread:
> 
> 1) creates a GMainContext
> 
> 2) adds the AioContext as a GSource in the GMainContext
> 
> 3) asks iothread_run to switch from the AioContext loop to the
> GMainContext loop
> 
> 
> To simplify thread-safety:
> 
> 1) the GMainContext can be wrapped with a GOnce
> 
> 2) the GOnce callback can leave steps 2 and 3 to a bottom half.

Thanks.  Another thing, please add a call to
g_main_context_push_thread_default() and
g_main_context_pop_thread_default().

Thanks,

Paolo

>> ---
>>  include/sysemu/iothread.h |  1 +
>>  iothread.c                | 13 +++++++++++++
>>  2 files changed, 14 insertions(+)
>>
>> diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h
>> index e6da1a4..ffe4e8a 100644
>> --- a/include/sysemu/iothread.h
>> +++ b/include/sysemu/iothread.h
>> @@ -24,6 +24,7 @@ typedef struct {
>>  
>>      QemuThread thread
>>      AioContext *ctx
>> +    GMainLoop *loop
>>      QemuMutex init_done_lock
>>      QemuCond init_done_cond    /* is thread initialization done? */
>>      bool stopping
>> diff --git a/iothread.c b/iothread.c
>> index beeb870..b6f3c3c 100644
>> --- a/iothread.c
>> +++ b/iothread.c
>> @@ -46,6 +46,7 @@ AioContext *qemu_get_current_aio_context(void)
>>  static void *iothread_run(void *opaque)
>>  {
>>      IOThread *iothread = opaque
>> +    GMainContext *context
>>  
>>      rcu_register_thread()
>>  
>> @@ -57,6 +58,15 @@ static void *iothread_run(void *opaque)
>>  
>>      while (!atomic_read(&iothread->stopping)) {
>>          aio_poll(iothread->ctx, true)
>> +
>> +        context = iothread->ctx->source.context
>> +        if (context) {
>> +            iothread->loop = g_main_loop_new(context, TRUE)
>> +            g_main_loop_run(iothread->loop)
>> +
>> +            g_main_loop_unref(iothread->loop)
>> +            g_main_context_unref(context)
>> +        }
>>      }
>>  
>>      rcu_unregister_thread()
>> @@ -72,6 +82,9 @@ static int iothread_stop(Object *object, void *opaque)
>>          return 0
>>      }
>>      iothread->stopping = true
>> +    if (iothread->loop) {
>> +        g_main_loop_quit(iothread->loop)
>> +    }
>>      aio_notify(iothread->ctx)
>>      qemu_thread_join(&iothread->thread)
>>      return 0
>> --
>> 1.8.3.1
>>
>>
>>
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-10  9:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-10  9:17 [Qemu-devel] 答复: Re: [PATCH] qemu-iothread: IOThread supports the GMainContext eventloop wang.yong155
2017-08-10  9:52 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).