From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=52207 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pi7Gd-0003LA-Bz for qemu-devel@nongnu.org; Wed, 26 Jan 2011 10:27:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pi7Fj-0005io-Th for qemu-devel@nongnu.org; Wed, 26 Jan 2011 10:26:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pi7Fj-0005en-Ma for qemu-devel@nongnu.org; Wed, 26 Jan 2011 10:25:47 -0500 Message-ID: <4D403CF3.8080102@redhat.com> Date: Wed, 26 Jan 2011 17:25:39 +0200 From: Avi Kivity 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> In-Reply-To: <1295688567-25496-2-git-send-email-stefanha@linux.vnet.ibm.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: Stefan Hajnoczi Cc: Kevin Wolf , Anthony Liguori , qemu-devel@nongnu.org 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. -- error compiling committee.c: too many arguments to function