From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z07uf-0006fq-03 for qemu-devel@nongnu.org; Wed, 03 Jun 2015 08:36:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z07uZ-0004DT-U6 for qemu-devel@nongnu.org; Wed, 03 Jun 2015 08:36:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z07uZ-0004D9-OE for qemu-devel@nongnu.org; Wed, 03 Jun 2015 08:36:47 -0400 Message-ID: <556EF398.7040402@redhat.com> Date: Wed, 03 Jun 2015 14:31:20 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1433334080-14912-1-git-send-email-pbonzini@redhat.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] atomics: add explicit compiler fence in __atomic memory barriers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Kevin Wolf , QEMU Developers , uobergfe@redhat.com On 03/06/2015 14:25, Peter Maydell wrote: >> > +/* __atomic_thread_fence does not include a compiler barrier; instead, >> > + * the barrier is part of __atomic_load/__atomic_store's "volatile-like" >> > + * semantics. If smp_wmb() is a no-op, absence of the barrier means that >> > + * the compiler is free to reorder stores on each side of the barrier. >> > + * Add one here, and similarly in smp_rmb() and smp_read_barrier_depends(). >> > + */ >> > +#define smp_wmb() ({ barrier(); __atomic_thread_fence(__ATOMIC_RELEASE); barrier(); }) > The comment says "add one" but the patch is adding two. > An explanation of why you need a barrier on both sides and > can't manage with just one might be helpful. Well, the reason is mostly that I wasn't sure if one is enough. We want to keep the fence in place, and two barriers are firm enough to block it on both sides. If the fence is a no-op, "barrier(); barrier();" is the same as a single compiler barrier. Paolo