Received: from eggs.gnu.org ([2001:4830:134:3::10]:44993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buFs2-0001x2-9O for qemu-devel@nongnu.org; Wed, 12 Oct 2016 05:30:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buFs0-0008JU-M6 for qemu-devel@nongnu.org; Wed, 12 Oct 2016 05:30:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54722) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buFs0-0008J9-88 for qemu-devel@nongnu.org; Wed, 12 Oct 2016 05:30:40 -0400 References: <1476107947-31430-1-git-send-email-pbonzini@redhat.com> <1476107947-31430-6-git-send-email-pbonzini@redhat.com> <87wphdor0y.fsf@linaro.org> From: Paolo Bonzini Message-ID: <0f87c30a-b7e3-a421-5341-aeceb9de7026@redhat.com> Date: Wed, 12 Oct 2016 11:30:34 +0200 MIME-Version: 1.0 In-Reply-To: <87wphdor0y.fsf@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: =?UTF-8?Q?Alex_Benn=c3=a9e?= Cc: qemu-devel@nongnu.org, cota@braap.org On 12/10/2016 11:28, Alex Benn=C3=A9e wrote: >=20 > Paolo Bonzini writes: >=20 >> 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 impleme= ntation >> everywhere instead of seq-cst loads and stores. >> >> Signed-off-by: Paolo Bonzini >> --- > >=20 >> +/* 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 >=20 > Is this working around a compiler issue? Shouldn't it already be using > the best instructions for the constraint? Store release + memory barrier can be compiled into a seqcst store, and is more efficient if you have a single instruction for that purpose, but I don't know of any compiler that does it. Paolo >> + >> +#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 */ >=20 >=20 > -- > Alex Benn=C3=A9e >=20