* [Qemu-devel] Qemu coroutine behaviour on blocking send(3)
@ 2014-11-28 6:50 Iwan Budi Kusnanto
2014-11-28 6:55 ` Iwan Budi Kusnanto
0 siblings, 1 reply; 5+ messages in thread
From: Iwan Budi Kusnanto @ 2014-11-28 6:50 UTC (permalink / raw)
To: qemu-devel
Hi all,
I just found about coroutine in Qemu and it looks good for my use case.
I have a question about this.
I found this
"Coroutines are cooperatively scheduled threads of control. There is
no preemption timer that switches between coroutines periodically,
instead switching between coroutines is always explicit. Coroutines
run until termination or an explicit yield."
at http://blog.vmsplice.net/2014/01/coroutines-in-qemu-basics.html
How about the case where we do blocking send(3) on socket?
Regards,
--
Iwan Budi Kusnanto
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Qemu coroutine behaviour on blocking send(3)
2014-11-28 6:50 [Qemu-devel] Qemu coroutine behaviour on blocking send(3) Iwan Budi Kusnanto
@ 2014-11-28 6:55 ` Iwan Budi Kusnanto
2014-11-28 12:47 ` Stefan Hajnoczi
0 siblings, 1 reply; 5+ messages in thread
From: Iwan Budi Kusnanto @ 2014-11-28 6:55 UTC (permalink / raw)
To: qemu-devel
I meant, does the coroutine will do yield internally when it get
blocked on send(3)?
On Fri, Nov 28, 2014 at 1:50 PM, Iwan Budi Kusnanto <ibk@labhijau.net> wrote:
> Hi all,
>
> I just found about coroutine in Qemu and it looks good for my use case.
> I have a question about this.
> I found this
> "Coroutines are cooperatively scheduled threads of control. There is
> no preemption timer that switches between coroutines periodically,
> instead switching between coroutines is always explicit. Coroutines
> run until termination or an explicit yield."
> at http://blog.vmsplice.net/2014/01/coroutines-in-qemu-basics.html
>
> How about the case where we do blocking send(3) on socket?
>
> Regards,
>
> --
> Iwan Budi Kusnanto
--
Iwan Budi Kusnanto
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Qemu coroutine behaviour on blocking send(3)
2014-11-28 6:55 ` Iwan Budi Kusnanto
@ 2014-11-28 12:47 ` Stefan Hajnoczi
2014-11-28 13:46 ` Iwan Budi Kusnanto
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-11-28 12:47 UTC (permalink / raw)
To: Iwan Budi Kusnanto; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 678 bytes --]
On Fri, Nov 28, 2014 at 01:55:00PM +0700, Iwan Budi Kusnanto wrote:
> I meant, does the coroutine will do yield internally when it get
> blocked on send(3)?
No. In general, QEMU will use non-blocking file descriptors so the
blocking case does not apply. (You can't use blocking file descriptors
in an event loop without a risk of blocking the entire event loop.)
There is qemu_co_send(), which attempts the non-blocking send(2) and
yields on EAGAIN.
block/sheepdog.c and nbd.c both use this function. It's a little ugly
because the caller must add/remove the socket write fd handler function
so that the coroutine is re-entered when the fd becomes writable again.
Stefan
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Qemu coroutine behaviour on blocking send(3)
2014-11-28 12:47 ` Stefan Hajnoczi
@ 2014-11-28 13:46 ` Iwan Budi Kusnanto
2014-11-28 14:15 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Iwan Budi Kusnanto @ 2014-11-28 13:46 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-devel
On Fri, Nov 28, 2014 at 7:47 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Fri, Nov 28, 2014 at 01:55:00PM +0700, Iwan Budi Kusnanto wrote:
>> I meant, does the coroutine will do yield internally when it get
>> blocked on send(3)?
>
> No. In general, QEMU will use non-blocking file descriptors so the
> blocking case does not apply. (You can't use blocking file descriptors
> in an event loop without a risk of blocking the entire event loop.)
>
> There is qemu_co_send(), which attempts the non-blocking send(2) and
> yields on EAGAIN.
>
> block/sheepdog.c and nbd.c both use this function. It's a little ugly
> because the caller must add/remove the socket write fd handler function
> so that the coroutine is re-entered when the fd becomes writable again.
>
> Stefan
Thanks Stefan, it really helps.
--
Iwan Budi Kusnanto
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Qemu coroutine behaviour on blocking send(3)
2014-11-28 13:46 ` Iwan Budi Kusnanto
@ 2014-11-28 14:15 ` Paolo Bonzini
0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-11-28 14:15 UTC (permalink / raw)
To: Iwan Budi Kusnanto, Stefan Hajnoczi; +Cc: qemu-devel
On 28/11/2014 14:46, Iwan Budi Kusnanto wrote:
> On Fri, Nov 28, 2014 at 7:47 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>> On Fri, Nov 28, 2014 at 01:55:00PM +0700, Iwan Budi Kusnanto wrote:
>>> I meant, does the coroutine will do yield internally when it get
>>> blocked on send(3)?
>>
>> No. In general, QEMU will use non-blocking file descriptors so the
>> blocking case does not apply. (You can't use blocking file descriptors
>> in an event loop without a risk of blocking the entire event loop.)
>>
>> There is qemu_co_send(), which attempts the non-blocking send(2) and
>> yields on EAGAIN.
>>
>> block/sheepdog.c and nbd.c both use this function. It's a little ugly
>> because the caller must add/remove the socket write fd handler function
>> so that the coroutine is re-entered when the fd becomes writable again.
>
> Thanks Stefan, it really helps.
I'll add that outgoing migration _does_ use blocking file descriptors.
But it runs in a separate thread and does not use coroutines.
Incoming migration, instead, uses coroutines, because it is not as
performance-intensive as outgoing migration and it's a bit easier to not
worry about thread-safety.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-11-28 14:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-28 6:50 [Qemu-devel] Qemu coroutine behaviour on blocking send(3) Iwan Budi Kusnanto
2014-11-28 6:55 ` Iwan Budi Kusnanto
2014-11-28 12:47 ` Stefan Hajnoczi
2014-11-28 13:46 ` Iwan Budi Kusnanto
2014-11-28 14:15 ` 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).