From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751794AbbH1Csx (ORCPT ); Thu, 27 Aug 2015 22:48:53 -0400 Received: from mail-ig0-f181.google.com ([209.85.213.181]:33818 "EHLO mail-ig0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751652AbbH1Csv (ORCPT ); Thu, 27 Aug 2015 22:48:51 -0400 From: Boqun Feng To: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Peter Zijlstra , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Will Deacon , "Paul E. McKenney" , Waiman Long , Boqun Feng Subject: [RFC 2/5] atomics: introduce arch_atomic_op_{acquire,release,fence} helpers Date: Fri, 28 Aug 2015 10:48:16 +0800 Message-Id: <1440730099-29133-3-git-send-email-boqun.feng@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1440730099-29133-1-git-send-email-boqun.feng@gmail.com> References: <1440730099-29133-1-git-send-email-boqun.feng@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some architectures may have their special barriers for acquire, release and fence semantics, general memory barriers(smp_mb__*_atomic()) in __atomic_op_*() may be too strong, so arch_atomic_op_*() helpers are introduced for architectures to provide their own version helpers to build different variants based on _relaxed variants. Signed-off-by: Boqun Feng --- include/linux/atomic.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/atomic.h b/include/linux/atomic.h index 00a5763..622255b 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h @@ -34,20 +34,33 @@ * The idea here is to build acquire/release variants by adding explicit * barriers on top of the relaxed variant. In the case where the relaxed * variant is already fully ordered, no additional barriers are needed. + * + * Besides, if an arch has a special barrier for acquire/release, it could + * implement its own arch_atomic_op_* and use the same framework for building + * variants */ +#ifndef arch_atomic_op_acquire #define __atomic_op_acquire(op, args...) \ ({ \ typeof(op##_relaxed(args)) __ret = op##_relaxed(args); \ smp_mb__after_atomic(); \ __ret; \ }) +#else +#define __atomic_op_acquire arch_atomic_op_acquire +#endif +#ifndef arch_atomic_op_release #define __atomic_op_release(op, args...) \ ({ \ smp_mb__before_atomic(); \ op##_relaxed(args); \ }) +#else +#define __atomic_op_release arch_atomic_op_release +#endif +#ifndef arch_atomic_op_fence #define __atomic_op_fence(op, args...) \ ({ \ typeof(op##_relaxed(args)) __ret; \ @@ -56,6 +69,9 @@ smp_mb__after_atomic(); \ __ret; \ }) +#else +#define __atomic_op_fence arch_atomic_op_fence +#endif /* atomic_add_return_relaxed */ #ifndef atomic_add_return_relaxed -- 2.5.0