From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XuMKU-0004qD-Er for qemu-devel@nongnu.org; Fri, 28 Nov 2014 09:15:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XuMKL-0005dK-AR for qemu-devel@nongnu.org; Fri, 28 Nov 2014 09:15:26 -0500 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:59009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XuMKL-0005d8-4V for qemu-devel@nongnu.org; Fri, 28 Nov 2014 09:15:17 -0500 Received: by mail-wi0-f177.google.com with SMTP id l15so11365489wiw.16 for ; Fri, 28 Nov 2014 06:15:16 -0800 (PST) Sender: Paolo Bonzini Message-ID: <54788370.603@redhat.com> Date: Fri, 28 Nov 2014 15:15:12 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <20141128124748.GK13631@stefanha-thinkpad.redhat.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] Qemu coroutine behaviour on blocking send(3) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Iwan Budi Kusnanto , Stefan Hajnoczi Cc: qemu-devel@nongnu.org On 28/11/2014 14:46, Iwan Budi Kusnanto wrote: > On Fri, Nov 28, 2014 at 7:47 PM, Stefan Hajnoczi 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