Received: from eggs.gnu.org ([2001:4830:134:3::10]:36557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1abp-0001T7-Ng for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:04:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1abl-00058i-Lo for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:04:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1abl-00058X-GE for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:04:13 -0400 References: <20161021115442.18420-1-alex.bennee@linaro.org> From: Paolo Bonzini Message-ID: <1776cd73-bfa5-8af8-5d76-34d9760a1664@redhat.com> Date: Tue, 1 Nov 2016 16:04:07 +0100 MIME-Version: 1.0 In-Reply-To: <20161021115442.18420-1-alex.bennee@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] cpus: make qemu_mutex_iothread_locked() understand co-routines List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , stefanha@redhat.com Cc: qemu-devel@nongnu.org, Peter Crosthwaite , Richard Henderson On 21/10/2016 13:54, Alex Benn=C3=A9e wrote: > There is a slight wart when checking for the state of the BQL when usin= g > GThread base co-routines (which we keep for ThreadSanitizer runs). Whil= e > the main-loop holds the BQL it is suspended until the co-routine > completes however the co-routines run in a separate thread so checking > the TLS variable could be wrong. >=20 > We fix this by expanding the check to include qemu_in_coroutine() for > GThread based builds. As it is not used for production builds I'm not > overly worried about any performance impact which should be negligible > anyway. >=20 > Signed-off-by: Alex Benn=C3=A9e > Cc: Stefan Hajnoczi This is wrong unfortunately. It is possible to run coroutines outside the BQL (e.g. with -device virtio-blk,iothread=3Dfoo). Do you know exactly why TSAN has no love for coroutines? Paolo > --- > configure | 3 +++ > cpus.c | 13 +++++++++++++ > 2 files changed, 16 insertions(+) >=20 > diff --git a/configure b/configure > index 91a14c1..97b89fb 100755 > --- a/configure > +++ b/configure > @@ -5461,6 +5461,9 @@ if test "$rbd" =3D "yes" ; then > fi > =20 > echo "CONFIG_COROUTINE_BACKEND=3D$coroutine" >> $config_host_mak > +if test "$coroutine" =3D "gthread" ; then > + echo "CONFIG_COROUTINE_GTHREAD=3D1" >> $config_host_mak > +fi > if test "$coroutine_pool" =3D "yes" ; then > echo "CONFIG_COROUTINE_POOL=3D1" >> $config_host_mak > else > diff --git a/cpus.c b/cpus.c > index 0c18a9f..a3e189a 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -49,6 +49,10 @@ > #include "hw/nmi.h" > #include "sysemu/replay.h" > =20 > +#ifdef CONFIG_COROUTINE_GTHREAD > +#include "qemu/coroutine.h" > +#endif > + > #ifndef _WIN32 > #include "qemu/compatfd.h" > #endif > @@ -1422,9 +1426,18 @@ bool qemu_in_vcpu_thread(void) > =20 > static __thread bool iothread_locked =3D false; > =20 > +/* > + * There is a slight wart when using gthread based co-routines. Here > + * the BQL is held by the main-thread which is suspended until the > + * co-routines complete. > + */ > bool qemu_mutex_iothread_locked(void) > { > +#ifdef CONFIG_COROUTINE_GTHREAD > + return iothread_locked || qemu_in_coroutine(); > +#else > return iothread_locked; > +#endif > } > =20 > void qemu_mutex_lock_iothread(void) >=20