From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Ib4-0004ZL-AI for qemu-devel@nongnu.org; Tue, 24 May 2016 16:06:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5Iax-0004f0-NG for qemu-devel@nongnu.org; Tue, 24 May 2016 16:06:33 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:49230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Iav-0004d1-EP for qemu-devel@nongnu.org; Tue, 24 May 2016 16:06:27 -0400 From: "Emilio G. Cota" Date: Tue, 24 May 2016 16:06:14 -0400 Message-Id: <1464120374-8950-4-git-send-email-cota@braap.org> In-Reply-To: <1464120374-8950-1-git-send-email-cota@braap.org> References: <1464120374-8950-1-git-send-email-cota@braap.org> Subject: [Qemu-devel] [PATCH v2 3/3] atomics: do not emit consume barrier for atomic_rcu_read List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers , MTTCG Devel Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Richard Henderson , Sergey Fedorov Currently we emit a consume-load in atomic_rcu_read. This is overkill for non-Sparc hosts, and is only useful to make things easier for Thread Sanitizer, which as far as I understand works best without explicit fences. The appended leaves the consume-load in atomic_rcu_read when compiling with Thread Sanitizer enabled, and resorts to a relaxed load + smp_read_barrier_depends otherwise. On an RMO host architecture, such as aarch64, the performance improvement of this change is easily measurable. For instance, qht-bench performs an atomic_rcu_read on every lookup. Performance before and after applying this patch: $ tests/qht-bench -d 5 -n 1 Before: 9.78 MT/s After: 10.96 MT/s Signed-off-by: Emilio G. Cota --- include/qemu/atomic.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 4a4f2fb..c5b6c8d 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -63,13 +63,20 @@ __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \ } while(0) -/* Atomic RCU operations imply weak memory barriers */ +#ifdef __SANITIZE_THREAD__ +#define atomic_rcu_read__nocheck(ptr, valptr) \ + __atomic_load(ptr, valptr, __ATOMIC_CONSUME); +#else +#define atomic_rcu_read__nocheck(ptr, valptr) \ + __atomic_load(ptr, valptr, __ATOMIC_RELAXED); \ + smp_read_barrier_depends(); +#endif #define atomic_rcu_read(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ typeof(*ptr) _val; \ - __atomic_load(ptr, &_val, __ATOMIC_CONSUME); \ + atomic_rcu_read__nocheck(ptr, &_val); \ _val; \ }) -- 2.5.0