From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buFpj-0008MH-6Y for qemu-devel@nongnu.org; Wed, 12 Oct 2016 05:28:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buFpg-0007ce-1v for qemu-devel@nongnu.org; Wed, 12 Oct 2016 05:28:19 -0400 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:36748) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buFpf-0007cT-R8 for qemu-devel@nongnu.org; Wed, 12 Oct 2016 05:28:15 -0400 Received: by mail-wm0-x235.google.com with SMTP id o81so19666215wma.1 for ; Wed, 12 Oct 2016 02:28:15 -0700 (PDT) References: <1476107947-31430-1-git-send-email-pbonzini@redhat.com> <1476107947-31430-6-git-send-email-pbonzini@redhat.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <1476107947-31430-6-git-send-email-pbonzini@redhat.com> Date: Wed, 12 Oct 2016 10:28:13 +0100 Message-ID: <87wphdor0y.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 5/5] atomic: base mb_read/mb_set on load-acquire and store-release List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, cota@braap.org Paolo Bonzini writes: > This introduces load-acquire and store-release operations in QEMU. > For now, just use them as an implementation detail of atomic_mb_read > and atomic_mb_set. > > Since docs/atomics.txt documents that atomic_mb_read only synchronizes > with an atomic_mb_set of the same variable, we can use the new implementation > everywhere instead of seq-cst loads and stores. > > Signed-off-by: Paolo Bonzini > --- > +/* This is more efficient than a store plus a fence. */ > +#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) > +#define atomic_mb_set(ptr, i) ((void)atomic_xchg(ptr, i)) > +#endif Is this working around a compiler issue? Shouldn't it already be using the best instructions for the constraint? > + > +#ifndef atomic_mb_read > +#define atomic_mb_read(ptr) \ > + atomic_load_acquire(ptr) > +#endif > + > +#ifndef atomic_mb_set > +#define atomic_mb_set(ptr, i) do { \ > + atomic_store_release(ptr, i); \ > + smp_mb(); \ > +} while(0) > +#endif > + > #endif /* QEMU_ATOMIC_H */ -- Alex Bennée