Received: from eggs.gnu.org ([2001:4830:134:3::10]:43475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5XkG-0000yj-Sa for qemu-devel@nongnu.org; Wed, 25 May 2016 08:17:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5XkB-0005na-LV for qemu-devel@nongnu.org; Wed, 25 May 2016 08:17:03 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:34429) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5XkA-0005nT-ON for qemu-devel@nongnu.org; Wed, 25 May 2016 08:16:59 -0400 Received: by mail-wm0-x244.google.com with SMTP id n129so14844435wmn.1 for ; Wed, 25 May 2016 05:16:58 -0700 (PDT) Sender: Paolo Bonzini References: <1464120374-8950-1-git-send-email-cota@braap.org> <1464120374-8950-3-git-send-email-cota@braap.org> From: Paolo Bonzini Message-ID: <2668174b-abe5-5301-690f-8f199426a02e@redhat.com> Date: Wed, 25 May 2016 14:16:56 +0200 MIME-Version: 1.0 In-Reply-To: <1464120374-8950-3-git-send-email-cota@braap.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 2/3] atomics: emit an smp_read_barrier_depends() barrier only for Sparc and Thread Sanitizer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , QEMU Developers , MTTCG Devel Cc: =?UTF-8?Q?Alex_Benn=c3=a9e?= , Richard Henderson , Sergey Fedorov On 24/05/2016 22:06, Emilio G. Cota wrote: > For correctness, smp_read_barrier_depends() is only required to > emit a barrier on Sparc hosts. However, we are currently emitting > a consume fence unconditionally. Let's say why this is suboptimal: ... and most compilers currently treat consume and acquire fences as equivalent. Likewise, let's add a comment like this: +/* Most compilers currently treat consume and acquire the same, but really + * no processors except Alpha need a barrier here. Leave it in if + * using Thread Sanitizer to avoid warnings, otherwise optimize it away. + */ If okay I can do the change myself. Thanks, Paolo > > Fix it by keeping the consume fence if we're compiling with Thread > Sanitizer, since this might help prevent false warnings. Otherwise, > only emit the barrier for Sparc hosts. Note that we still guarantee > that smp_read_barrier_depends() is a compiler barrier. > > Signed-off-by: Emilio G. Cota > --- > include/qemu/atomic.h | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h > index 5bc4d6c..4a4f2fb 100644 > --- a/include/qemu/atomic.h > +++ b/include/qemu/atomic.h > @@ -36,7 +36,14 @@ > #define smp_wmb() ({ barrier(); __atomic_thread_fence(__ATOMIC_RELEASE); barrier(); }) > #define smp_rmb() ({ barrier(); __atomic_thread_fence(__ATOMIC_ACQUIRE); barrier(); }) > > +#if defined(__SANITIZE_THREAD__) > #define smp_read_barrier_depends() ({ barrier(); __atomic_thread_fence(__ATOMIC_CONSUME); barrier(); }) > +#elsif defined(__alpha__) > +#define smp_read_barrier_depends() asm volatile("mb":::"memory") > +#else > +#define smp_read_barrier_depends() barrier() > +#endif > + > > /* Weak atomic operations prevent the compiler moving other > * loads/stores past the atomic operation load/store. However there is >