Patchwork eventfd: making it rhread safe

login
register
mail settings
Submitter Alexey Kardashevskiy
Date July 1, 2012, 7:48 p.m.
Message ID <4FF0A980.4070903@ozlabs.ru>
Download mbox | patch
Permalink /patch/168458/
State New
Headers show

Comments

Alexey Kardashevskiy - July 1, 2012, 7:48 p.m.
QEMU uses IO handlers to run select() in the main loop. The handlers list is managed by qemu_set_fd_handler() helper which works fine when called from the main thread as it is called not when select() is waiting.

However sometime we need to update the handlers list from another thread. For that the main loop's select() needs to be restarted with the updated list.

The patch adds the qemu_notify_event() call to interrupt select() and make wrapping code to restart select() with the updated IO handlers list.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

---
 iohandler.c |    1 +
 1 file changed, 1 insertion(+)
Alexey Kardashevskiy - July 9, 2012, 3:10 a.m.
Ping?

On 02/07/12 05:48, Alexey Kardashevskiy wrote:
> QEMU uses IO handlers to run select() in the main loop. The handlers list is managed by qemu_set_fd_handler() helper which works fine when called from the main thread as it is called not when select() is waiting.
> 
> However sometime we need to update the handlers list from another thread. For that the main loop's select() needs to be restarted with the updated list.
> 
> The patch adds the qemu_notify_event() call to interrupt select() and make wrapping code to restart select() with the updated IO handlers list.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> ---
>  iohandler.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/iohandler.c b/iohandler.c
> index 3c74de6..dea4355 100644
> --- a/iohandler.c
> +++ b/iohandler.c
> @@ -77,6 +77,7 @@ int qemu_set_fd_handler2(int fd,
>          ioh->fd_write = fd_write;
>          ioh->opaque = opaque;
>          ioh->deleted = 0;
> +        qemu_notify_event();
>      }
>      return 0;
>  }
>
Alexey Kardashevskiy - July 18, 2012, 8:25 a.m.
Ping again?


On 09/07/12 13:10, Alexey Kardashevskiy wrote:
> Ping?
> 
> On 02/07/12 05:48, Alexey Kardashevskiy wrote:
>> QEMU uses IO handlers to run select() in the main loop. The handlers list is managed by qemu_set_fd_handler() helper which works fine when called from the main thread as it is called not when select() is waiting.
>>
>> However sometime we need to update the handlers list from another thread. For that the main loop's select() needs to be restarted with the updated list.
>>
>> The patch adds the qemu_notify_event() call to interrupt select() and make wrapping code to restart select() with the updated IO handlers list.
>>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>>
>> ---
>>  iohandler.c |    1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/iohandler.c b/iohandler.c
>> index 3c74de6..dea4355 100644
>> --- a/iohandler.c
>> +++ b/iohandler.c
>> @@ -77,6 +77,7 @@ int qemu_set_fd_handler2(int fd,
>>          ioh->fd_write = fd_write;
>>          ioh->opaque = opaque;
>>          ioh->deleted = 0;
>> +        qemu_notify_event();
>>      }
>>      return 0;
>>  }
>>
> 
>
Michael S. Tsirkin - July 18, 2012, 11:47 a.m.
On Mon, Jul 02, 2012 at 05:48:16AM +1000, Alexey Kardashevskiy wrote:
>Subject: Re: [PATCH] eventfd: making it rhread safe

typo in the subject

> QEMU uses IO handlers to run select() in the main loop. The handlers list is managed by qemu_set_fd_handler() helper which works fine when called from the main thread as it is called not when select() is waiting.

git commit logs should break lines at 70-80 chars.
Sometimes people go beyond that a bit. But 214 chars is not reasonable.

> However sometime we need to update the handlers list from another thread.

Want to be more specific?

> For that the main loop's select() needs to be restarted with the updated list.
> 
> The patch adds the qemu_notify_event() call to interrupt select() and make wrapping code to restart select() with the updated IO handlers list.

What does 'and make wrapping code' mean?

> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Does this fix any bugs? If yes commit log should mention this.

> ---
>  iohandler.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/iohandler.c b/iohandler.c
> index 3c74de6..dea4355 100644
> --- a/iohandler.c
> +++ b/iohandler.c
> @@ -77,6 +77,7 @@ int qemu_set_fd_handler2(int fd,
>          ioh->fd_write = fd_write;
>          ioh->opaque = opaque;
>          ioh->deleted = 0;
> +        qemu_notify_event();
>      }
>      return 0;
>  }
> -- 
> 1.7.10

Patch

diff --git a/iohandler.c b/iohandler.c
index 3c74de6..dea4355 100644
--- a/iohandler.c
+++ b/iohandler.c
@@ -77,6 +77,7 @@  int qemu_set_fd_handler2(int fd,
         ioh->fd_write = fd_write;
         ioh->opaque = opaque;
         ioh->deleted = 0;
+        qemu_notify_event();
     }
     return 0;
 }