Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932912AbdCFTqc (ORCPT ); Mon, 6 Mar 2017 14:46:32 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:49699 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932487AbdCFTis (ORCPT ); Mon, 6 Mar 2017 14:38:48 -0500 From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Elena Reshetova , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Wang Nan Subject: [PATCH 07/35] tools include: Provide gcc based cmpxchg fallback for !x86 Date: Mon, 6 Mar 2017 16:37:57 -0300 Message-Id: <20170306193825.24011-8-acme@kernel.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170306193825.24011-1-acme@kernel.org> References: <20170306193825.24011-1-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1365 Lines: 38 From: Arnaldo Carvalho de Melo We've been using an atomic_t implementation subset based on the gcc builtin functions for a while, now, with refcount.h we need cmpxchg(), use gcc's __sync_val_compare_and_swap() for that. Cc: Adrian Hunter Cc: David Ahern Cc: Elena Reshetova Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-b9zovyxgpa0c4vi3nm0kjo97@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/include/asm-generic/atomic-gcc.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/include/asm-generic/atomic-gcc.h b/tools/include/asm-generic/atomic-gcc.h index 2ba78c9f5701..5e9738f97bf3 100644 --- a/tools/include/asm-generic/atomic-gcc.h +++ b/tools/include/asm-generic/atomic-gcc.h @@ -60,4 +60,12 @@ static inline int atomic_dec_and_test(atomic_t *v) return __sync_sub_and_fetch(&v->counter, 1) == 0; } +#define cmpxchg(ptr, oldval, newval) \ + __sync_val_compare_and_swap(ptr, oldval, newval) + +static inline int atomic_cmpxchg(atomic_t *v, int oldval, int newval) +{ + return cmpxchg(&(v)->counter, oldval, newval); +} + #endif /* __TOOLS_ASM_GENERIC_ATOMIC_H */ -- 2.9.3