From patchwork Fri Feb 19 21:02:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Lo=C3=AFc_Minier?= X-Patchwork-Id: 45882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2B743B7067 for ; Sat, 20 Feb 2010 08:20:04 +1100 (EST) Received: from localhost ([127.0.0.1]:38204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nia5k-0002G8-Ds for incoming@patchwork.ozlabs.org; Fri, 19 Feb 2010 16:08:52 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NiZzw-0000Vk-HZ for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:52 -0500 Received: from [199.232.76.173] (port=41347 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NiZzv-0000VN-Ul for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:51 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NiZzu-0004vx-6E for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:51 -0500 Received: from duck.dooz.org ([194.146.227.125]:37078) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NiZzt-0004v3-M7 for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:49 -0500 Received: from bee.dooz.org (serris.dooz.org [88.166.229.232]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by duck.dooz.org (Postfix) with ESMTP id 3A6F9C809C; Fri, 19 Feb 2010 22:02:47 +0100 (CET) Received: by bee.dooz.org (Postfix, from userid 1000) id 967E08B6; Fri, 19 Feb 2010 22:02:44 +0100 (CET) From: =?UTF-8?q?Lo=C3=AFc=20Minier?= To: qemu-devel@nongnu.org Date: Fri, 19 Feb 2010 22:02:39 +0100 Message-Id: <1266613360-23069-1-git-send-email-lool@dooz.org> X-Mailer: git-send-email 1.7.0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: =?UTF-8?q?Lo=C3=AFc=20Minier?= Subject: [Qemu-devel] [PATCH 1/2] Detect and use GCC atomic builtins for locking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org --- configure | 17 +++++++++++++++++ qemu-lock.h | 13 +++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/configure b/configure index 0a84b0e..b33f045 100755 --- a/configure +++ b/configure @@ -1823,6 +1823,20 @@ if compile_prog "" ""; then fi ########################################## +# check if we have gcc atomic built-ins +gcc_atomic_builtins=no +cat > $TMPC << EOF +int main(void) { + int i; + __sync_lock_test_and_set(&i, 1); + __sync_lock_release(&i); +} +EOF +if compile_prog "" ""; then + gcc_atomic_builtins=yes +fi + +########################################## # check if we have fdatasync fdatasync=no @@ -2168,6 +2182,9 @@ fi if test "$gcc_attribute_warn_unused_result" = "yes" ; then echo "CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT=y" >> $config_host_mak fi +if test "$gcc_atomic_builtins" = "yes" ; then + echo "CONFIG_GCC_ATOMIC_BUILTINS=y" >> $config_host_mak +fi if test "$fdatasync" = "yes" ; then echo "CONFIG_FDATASYNC=y" >> $config_host_mak fi diff --git a/qemu-lock.h b/qemu-lock.h index 9a3e6ac..5c8eb34 100644 --- a/qemu-lock.h +++ b/qemu-lock.h @@ -33,6 +33,14 @@ #else +#ifdef CONFIG_GCC_ATOMIC_BUILTINS +typedef int spinlock_t; + +#define SPIN_LOCK_UNLOCKED 0 + +#define resetlock(p) __sync_lock_release((p)) +#else /* CONFIG_GCC_ATOMIC_BUILTINS */ + #if defined(__hppa__) typedef int spinlock_t[4]; @@ -56,7 +64,11 @@ static inline void resetlock (spinlock_t *p) } #endif +#endif /* !CONFIG_GCC_ATOMIC_BUILTINS */ +#ifdef CONFIG_GCC_ATOMIC_BUILTINS +#define testandset(p) __sync_lock_test_and_set((p), 1) +#else /* CONFIG_GCC_ATOMIC_BUILTINS */ #if defined(_ARCH_PPC) static inline int testandset (int *p) { @@ -213,6 +225,7 @@ static inline int testandset (int *p) #else #error unimplemented CPU support #endif +#endif /* !CONFIG_GCC_ATOMIC_BUILTINS */ #if defined(CONFIG_USER_ONLY) static inline void spin_lock(spinlock_t *lock)