From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:56153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUzbM-0006Zd-3b for qemu-devel@nongnu.org; Fri, 10 Jun 2011 07:10:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUzbJ-00054c-SA for qemu-devel@nongnu.org; Fri, 10 Jun 2011 07:10:07 -0400 Received: from e4.ny.us.ibm.com ([32.97.182.144]:59697) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUzbJ-000536-Dz for qemu-devel@nongnu.org; Fri, 10 Jun 2011 07:10:05 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by e4.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p5AAmdNt027727 for ; Fri, 10 Jun 2011 06:48:39 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5ABA3AV827616 for ; Fri, 10 Jun 2011 07:10:03 -0400 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 p5ABA2rC020129 for ; Fri, 10 Jun 2011 07:10:03 -0400 From: "Aneesh Kumar K.V" In-Reply-To: References: <1307641266-7726-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Date: Fri, 10 Jun 2011 16:39:53 +0530 Message-ID: <871uz2eyda.fsf@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] coroutine: Implement coroutines using gthread List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Fri, 10 Jun 2011 11:24:20 +0100, Stefan Hajnoczi wr= ote: > On Thu, Jun 9, 2011 at 6:41 PM, Aneesh Kumar K.V > wrote: > > On platforms that doesn't support makecontext use gthread > > based coroutine implementation. > > > > Signed-off-by: Aneesh Kumar K.V > > --- > > > > NOTE: Tested on linux with force compliation of coroutine-gthread.c > > > > =C2=A0Makefile.objs =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A05 ++ > > =C2=A0configure =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 18 +++++ > > =C2=A0coroutine-gthread.c | =C2=A0172 +++++++++++++++++++++++++++++++++= ++++++++++++++++++ > > =C2=A03 files changed, 195 insertions(+), 0 deletions(-) > > =C2=A0create mode 100644 coroutine-gthread.c > > > > diff --git a/Makefile.objs b/Makefile.objs > > index 0f1d7df..d354d3c 100644 > > --- a/Makefile.objs > > +++ b/Makefile.objs > > @@ -13,9 +13,14 @@ oslib-obj-$(CONFIG_POSIX) +=3D oslib-posix.o qemu-th= read-posix.o > > =C2=A0#################################################################= ###### > > =C2=A0# coroutines > > =C2=A0coroutine-obj-y =3D qemu-coroutine.o qemu-coroutine-lock.o > > +ifeq ($(CONFIG_UCONTEXT_COROUTINE),y) > > =C2=A0coroutine-obj-$(CONFIG_POSIX) +=3D coroutine-ucontext.o > > +else > > +coroutine-obj-$(CONFIG_POSIX) +=3D coroutine-gthread.o > > +endif > > =C2=A0coroutine-obj-$(CONFIG_WIN32) +=3D coroutine-win32.o > > > > + > > =C2=A0#################################################################= ###### > > =C2=A0# block-obj-y is code used by both qemu system emulation and qemu= -img > > > > diff --git a/configure b/configure > > index 980914a..529d8c4 100755 > > --- a/configure > > +++ b/configure > > @@ -2568,6 +2568,20 @@ if test "$trace_backend" =3D "dtrace"; then > > =C2=A0fi > > > > =C2=A0########################################## > > +# check if we have makecontext > > + > > +ucontext_coroutine=3Dno > > +cat > $TMPC << EOF > > +#include > > +int main(void) { makecontext(0, 0, 0); } > > +EOF > > +if compile_prog "" "" ; then > > + =C2=A0 =C2=A0ucontext_coroutine=3Dyes > > +fi > > + > > + > > + > > +########################################## > > =C2=A0# End of CC checks > > =C2=A0# After here, no more $cc or $ld runs > > > > @@ -3031,6 +3045,10 @@ if test "$rbd" =3D "yes" ; then > > =C2=A0 echo "CONFIG_RBD=3Dy" >> $config_host_mak > > =C2=A0fi > > > > +if test "$ucontext_coroutine" =3D "yes" ; then > > + =C2=A0echo "CONFIG_UCONTEXT_COROUTINE=3Dy" >> $config_host_mak > > +fi > > + > > =C2=A0# USB host support > > =C2=A0case "$usb" in > > =C2=A0linux) > > diff --git a/coroutine-gthread.c b/coroutine-gthread.c > > new file mode 100644 > > index 0000000..37e5a16 > > --- /dev/null > > +++ b/coroutine-gthread.c > > @@ -0,0 +1,172 @@ > > +/* >=20 > A summary of the purpose of this file would be nice. >=20 > > + * > > + * Copyright (C) 2006 =C2=A0Anthony Liguori > > + * Copyright (C) 2011 =C2=A0Aneesh Kumar K.V > > + * > > + * This library is free software; you can redistribute it and/or > > + * modify it under the terms of the GNU Lesser General Public > > + * License as published by the Free Software Foundation; either > > + * version 2.0 of the License, or (at your option) any later version. > > + * > > + * This library is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =C2=A0See the = GNU > > + * Lesser General Public License for more details. > > + * > > + * You should have received a copy of the GNU Lesser General Public > > + * License along with this library; if not, write to the Free Software > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA =C2= =A002110-1301 USA >=20 > The URL is preferred over the postal address: >=20 > * You should have received a copy of the GNU Lesser General Public > * License along with this library; if not, see > . inherited that header from gtk-vnc version of original file >=20 > > + */ > > + > > +#include "qemu-common.h" > > +#include "qemu-coroutine-int.h" > > +#include Will fix. >=20 > It's good practice to include system headers first unless you are > explicitly setting a magic #define to affect the system header. >=20 > > + > > +typedef struct { > > + =C2=A0 =C2=A0Coroutine qemu_co; > > + =C2=A0 =C2=A0GThread *thread; > > + =C2=A0 =C2=A0gboolean runnable; > > +} CoroutineGthread; > > + > > +typedef struct { > > + =C2=A0 =C2=A0/** Currently executing coroutine */ > > + =C2=A0 =C2=A0CoroutineGthread *current; > > + > > + =C2=A0 =C2=A0/** The default coroutine */ > > + =C2=A0 =C2=A0CoroutineGthread leader; > > +} CoroutineThreadState; > > + > > +static GCond *run_cond; > > +static GMutex *run_lock; > > +static pthread_key_t thread_state_key; >=20 > Why pthread_key_t instead of GStaticPrivate? No specific reason other than I was not aware of GStaticPrivate.=20 >=20 > I've followed the main control flow once but am going to review in > more detail to make sure. >=20 Thanks. -aneesh