From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:32795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QL9YD-0008Vr-Vu for qemu-devel@nongnu.org; Sat, 14 May 2011 03:46:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QL9YC-0002qV-Ip for qemu-devel@nongnu.org; Sat, 14 May 2011 03:46:13 -0400 Received: from mtagate4.uk.ibm.com ([194.196.100.164]:50387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QL9YC-0002qP-A5 for qemu-devel@nongnu.org; Sat, 14 May 2011 03:46:12 -0400 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate4.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p4E7kAS2016409 for ; Sat, 14 May 2011 07:46:10 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4E7k0WR2445358 for ; Sat, 14 May 2011 08:46:10 +0100 Received: from d06av07.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4E7jxfO001696 for ; Sat, 14 May 2011 01:46:00 -0600 Date: Sat, 14 May 2011 08:45:46 +0100 From: Stefan Hajnoczi Message-ID: <20110514074546.GA11489@stefanha-thinkpad.localdomain> References: <1305278792-20933-1-git-send-email-stefanha@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 0/4] Coroutines for better asynchronous programming List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corentin Chary Cc: Kevin Wolf , Paolo Bonzini , Anthony Liguori , qemu-devel@nongnu.org, Blue Swirl On Sat, May 14, 2011 at 08:55:40AM +0200, Corentin Chary wrote: > On Fri, May 13, 2011 at 11:26 AM, Stefan Hajnoczi > wrote: > > QEMU is event-driven and suffers when blocking operations are perform= ed because > > VM execution may be stopped until the operation completes. =A0Therefo= re many > > operations that could block are performed asynchronously and a callba= ck is > > invoked when the operation has completed. =A0This allows QEMU to cont= inue > > executing while the operation is pending. > > > > The downside to callbacks is that they split up code into many smalle= r > > functions, each of which is a single step in a state machine that qui= ckly > > becomes complex and hard to understand. =A0Callback functions also re= sult in lots > > of noise as variables are packed and unpacked into temporary structs = that pass > > state to the callback function. > > > > This patch series introduces coroutines as a solution for writing asy= nchronous > > code while still having a nice sequential control flow. =A0The semant= ics are > > explained in the first patch. =A0The second patch adds automated test= s. > > > > A nice feature of coroutines is that it is relatively easy to take sy= nchronous > > code and lift it into a coroutine to make it asynchronous. =A0Work ha= s been done > > to move qcow2 request processing into coroutines and thereby make it > > asynchronous (today qcow2 will perform synchronous metadata accesses)= . =A0This > > qcow2 work is still ongoing and not quite ready for mainline yet. > > > > Coroutines are also being used for virtfs (virtio-9p) so I have submi= tted this > > patch now because virtfs patches that depend on coroutines are being = published. > > > > Other areas of QEMU that could take advantage of coroutines include t= he VNC > > server, migration, and qemu-tools. >=20 > Hum, the VNC server is already threaded, how would coroutines help ? > Do you plan to rewrite the server using coroutines instead of threads > ? The main control flow in the VNC server is a state-machine. Imagine a VNC session running as sequential code in a coroutine instead of being broken up across callbacks. I think it would be easier to follow although rewriting it now may not be worth the effort unless significant future VNC work is planned for the future. Stefan