From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:59461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QV0ZQ-0007nx-8b for qemu-devel@nongnu.org; Fri, 10 Jun 2011 08:12:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QV0ZN-0006K6-QS for qemu-devel@nongnu.org; Fri, 10 Jun 2011 08:12:12 -0400 Received: from mail-vw0-f45.google.com ([209.85.212.45]:60324) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QV0ZN-0006Jz-Gq for qemu-devel@nongnu.org; Fri, 10 Jun 2011 08:12:09 -0400 Received: by vws17 with SMTP id 17so2391653vws.4 for ; Fri, 10 Jun 2011 05:12:08 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <871uz2eyda.fsf@linux.vnet.ibm.com> References: <1307641266-7726-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> <871uz2eyda.fsf@linux.vnet.ibm.com> Date: Fri, 10 Jun 2011 13:12:08 +0100 Message-ID: From: Stefan Hajnoczi Content-Type: text/plain; charset=ISO-8859-1 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: "Aneesh Kumar K.V" Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Fri, Jun 10, 2011 at 12:09 PM, Aneesh Kumar K.V wrote: > On Fri, 10 Jun 2011 11:24:20 +0100, Stefan Hajnoczi = wrote: >> 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 >> > >> > =A0Makefile.objs =A0 =A0 =A0 | =A0 =A05 ++ >> > =A0configure =A0 =A0 =A0 =A0 =A0 | =A0 18 +++++ >> > =A0coroutine-gthread.c | =A0172 ++++++++++++++++++++++++++++++++++++++= +++++++++++++ >> > =A03 files changed, 195 insertions(+), 0 deletions(-) >> > =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-t= hread-posix.o >> > =A0###################################################################= #### >> > =A0# coroutines >> > =A0coroutine-obj-y =3D qemu-coroutine.o qemu-coroutine-lock.o >> > +ifeq ($(CONFIG_UCONTEXT_COROUTINE),y) >> > =A0coroutine-obj-$(CONFIG_POSIX) +=3D coroutine-ucontext.o >> > +else >> > +coroutine-obj-$(CONFIG_POSIX) +=3D coroutine-gthread.o >> > +endif >> > =A0coroutine-obj-$(CONFIG_WIN32) +=3D coroutine-win32.o >> > >> > + >> > =A0###################################################################= #### >> > =A0# block-obj-y is code used by both qemu system emulation and qemu-i= mg >> > >> > 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 >> > =A0fi >> > >> > =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 >> > + =A0 =A0ucontext_coroutine=3Dyes >> > +fi >> > + >> > + >> > + >> > +########################################## >> > =A0# End of CC checks >> > =A0# After here, no more $cc or $ld runs >> > >> > @@ -3031,6 +3045,10 @@ if test "$rbd" =3D "yes" ; then >> > =A0 echo "CONFIG_RBD=3Dy" >> $config_host_mak >> > =A0fi >> > >> > +if test "$ucontext_coroutine" =3D "yes" ; then >> > + =A0echo "CONFIG_UCONTEXT_COROUTINE=3Dy" >> $config_host_mak >> > +fi >> > + >> > =A0# USB host support >> > =A0case "$usb" in >> > =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 @@ >> > +/* >> >> A summary of the purpose of this file would be nice. >> >> > + * >> > + * Copyright (C) 2006 =A0Anthony Liguori >> > + * Copyright (C) 2011 =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. =A0See the GN= U >> > + * 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 Softwar= e >> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA =A00= 2110-1301 USA >> >> The URL is preferred over the postal address: >> >> =A0* You should have received a copy of the GNU Lesser General Public >> =A0* License along with this library; if not, see >> =A0. > > inherited that header from gtk-vnc version of original file >> >> > + */ >> > + >> > +#include "qemu-common.h" >> > +#include "qemu-coroutine-int.h" >> > +#include > > Will fix. > >> >> It's good practice to include system headers first unless you are >> explicitly setting a magic #define to affect the system header. >> >> > + >> > +typedef struct { >> > + =A0 =A0Coroutine qemu_co; >> > + =A0 =A0GThread *thread; >> > + =A0 =A0gboolean runnable; >> > +} CoroutineGthread; >> > + >> > +typedef struct { >> > + =A0 =A0/** Currently executing coroutine */ >> > + =A0 =A0CoroutineGthread *current; >> > + >> > + =A0 =A0/** The default coroutine */ >> > + =A0 =A0CoroutineGthread leader; >> > +} CoroutineThreadState; >> > + >> > +static GCond *run_cond; >> > +static GMutex *run_lock; >> > +static pthread_key_t thread_state_key; >> >> Why pthread_key_t instead of GStaticPrivate? > > No specific reason other than I was not aware of GStaticPrivate. It would be worth using that to avoid mixing GThread and pthreads unnecessarily. I still need to look at the rest of this patch so don't worry about sending v2 yet. Stefan