From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=41336 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pi8Ae-0006yz-FU for qemu-devel@nongnu.org; Wed, 26 Jan 2011 11:24:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pi8Ad-0001H3-4J for qemu-devel@nongnu.org; Wed, 26 Jan 2011 11:24:36 -0500 Received: from e2.ny.us.ibm.com ([32.97.182.142]:54134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pi8Ad-0001Gl-0d for qemu-devel@nongnu.org; Wed, 26 Jan 2011 11:24:35 -0500 Received: from d01dlp02.pok.ibm.com (d01dlp02.pok.ibm.com [9.56.224.85]) by e2.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p0QG6qap008728 for ; Wed, 26 Jan 2011 11:06:56 -0500 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 0DA304DE8848 for ; Wed, 26 Jan 2011 11:17:56 -0500 (EST) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0QGLR2u345498 for ; Wed, 26 Jan 2011 11:21:27 -0500 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0QGLRg2020637 for ; Wed, 26 Jan 2011 11:21:27 -0500 Message-ID: <4D4049FF.5090406@linux.vnet.ibm.com> Date: Wed, 26 Jan 2011 10:21:19 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [RFC][PATCH 01/12] coroutine: Add gtk-vnc coroutines library References: <1295688567-25496-1-git-send-email-stefanha@linux.vnet.ibm.com> <1295688567-25496-2-git-send-email-stefanha@linux.vnet.ibm.com> <4D403CF3.8080102@redhat.com> <4D40450B.3070705@linux.vnet.ibm.com> <4D404846.3050400@redhat.com> In-Reply-To: <4D404846.3050400@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , qemu-devel@nongnu.org On 01/26/2011 10:13 AM, Avi Kivity wrote: > On 01/26/2011 06:00 PM, Anthony Liguori wrote: >> On 01/26/2011 09:25 AM, Avi Kivity wrote: >>> On 01/22/2011 11:29 AM, Stefan Hajnoczi wrote: >>>> Asynchronous image format code is becoming very complex. Let's try >>>> using coroutines to write sequential code without callbacks but use >>>> coroutines to switch stacks under the hood. >>>> >>>> >>>> + >>>> +int cc_swap(struct continuation *from, struct continuation *to) >>>> +{ >>>> + to->exited = 0; >>>> + if (getcontext(&to->last) == -1) >>>> + return -1; >>>> + else if (to->exited == 0) >>>> + to->exited = 1; >>>> + else if (to->exited == 1) >>>> + return 1; >>>> + >>>> + return swapcontext(&from->uc,&to->uc); >>>> +} >>> >>> swapcontext() is very slow, involving the fpu and a syscall. >>> >>> A nice trick I've used in the past is to use getcontext/makecontext >>> for the initial setup and setjmp/longjmp for switching. Of course >>> this can be done later, as an optimization. >> >> Yeah, there are further optimizations that can be had but really, >> it's not important here. In fact, I'd rather start with the threaded >> version just because it's far more portable than ucontext. >> > > What do you mean by threaded version? http://git.gnome.org/browse/gtk-vnc/tree/src/coroutine_gthread.c Regards, Anthony Liguori