Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 54AB610AC4D3 for ; Sat, 7 Jan 2012 06:30:21 -0400 (AST) Received: from [213.9.93.70] (helo=mail.piware.de) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RjTXV-0001Bw-0t for pgsql-bugs@postgresql.org; Sat, 07 Jan 2012 10:30:22 +0000 Received: from localhost.localdomain (p549B331C.dip.t-dialin.net [84.155.51.28]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Martin Pitt (ThinkPad)", Issuer "piware CA" (verified OK)) by mail.piware.de (Postfix) with ESMTPS id 612631517A61 for ; Sat, 7 Jan 2012 11:28:22 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 1000) id C9E52209CD; Sat, 7 Jan 2012 11:30:02 +0100 (CET) Date: Sat, 7 Jan 2012 11:30:02 +0100 From: Martin Pitt To: pgsql-bugs@postgresql.org Subject: [PATCH v3] Use CC atomic builtins on ARM Message-ID: <20120107103002.GB2822@piware.de> Mail-Followup-To: pgsql-bugs@postgresql.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mSxgbZZZvrAyzONB" Content-Disposition: inline In-Reply-To: <5642.1324482916@sss.pgh.pa.us> <23930.1324433689@sss.pgh.pa.us> User-Agent: Mutt/1.5.21 (2010-09-15) X-Host-Lookup-Failed: Reverse DNS lookup failed for 213.9.93.70 (failed) X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201201/44 X-Sequence-Number: 32111 --mSxgbZZZvrAyzONB Content-Type: multipart/mixed; boundary="GPJrCs/72TxItFYR" Content-Disposition: inline --GPJrCs/72TxItFYR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Tom, all, happy new year everyone! Tom Lane [2011-12-20 21:14 -0500]: > So I'm thinking that removing the swpb ASM option is not such a good > idea. We could possibly test for __sync_lock_test_and_set first, and > only use swpb if we're on ARM and don't have the builtin. Tom Lane [2011-12-21 10:55 -0500]: > Yeah, that was another thing I found worrisome while googling: there > were a disturbingly large number of claims that __sync_lock_test_and_set > and/or __sync_lock_release were flat-out broken on various combinations > of gcc version and platform. After reading that, there is no way at all > that I'd accept your original patch to use these functions everywhere. >=20 > For the moment I'm inclined to consider using these functions *only* on > ARM, so as to limit our exposure to such bugs. That would also limit > the risk of using an inappropriate choice of lock width. OK, fair enough. New patch attached, which does exactly this now. Third time is the charm! Thanks, Martin --=20 Martin Pitt | http://www.piware.de Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org) --GPJrCs/72TxItFYR Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="01-armel-tas.patch" Content-Transfer-Encoding: quoted-printable Description: Use gcc/intel cc builtin atomic operations for test-and-set on= ARM, if available (http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Buil= tins.html). The existing PostgreSQL implementation does not work on thumb2. Author: Martin Pitt Index: postgresql-9.1-9.1.2/configure.in =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- postgresql-9.1-9.1.2.orig/configure.in 2011-12-01 22:47:20.000000000 +0= 100 +++ postgresql-9.1-9.1.2/configure.in 2012-01-07 10:10:51.153609202 +0100 @@ -1522,6 +1522,18 @@ AC_SUBST(LDAP_LIBS_FE) AC_SUBST(LDAP_LIBS_BE) =20 +# gcc and intel compiler provide builtin functions for atomic test-and-set +AC_MSG_CHECKING([whether the C compiler provides atomic builtins]) +AC_TRY_LINK([], [int lock =3D 0; __sync_lock_test_and_set(&lock, 1); __syn= c_lock_release(&lock);], + [have_cc_atomics=3D"yes"], + [have_cc_atomics=3D"no"] +) +if test "$have_cc_atomics" =3D yes; then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_CC_ATOMICS, 1, [Define to 1 if compiler provides atomic b= uiltins]) +else + AC_MSG_RESULT(no) +fi =20 # This test makes sure that run tests work at all. Sometimes a shared # library is found by the linker, but the runtime linker can't find it. Index: postgresql-9.1-9.1.2/configure =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- postgresql-9.1-9.1.2.orig/configure 2011-12-01 22:47:20.000000000 +0100 +++ postgresql-9.1-9.1.2/configure 2012-01-07 10:10:51.177609204 +0100 @@ -23602,6 +23602,69 @@ =20 =20 =20 +# gcc and intel compiler provide builtin functions for atomic test-and-set +{ $as_echo "$as_me:$LINENO: checking whether the C compiler provides atomi= c builtins" >&5 +$as_echo_n "checking whether the C compiler provides atomic builtins... " = >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +int lock =3D 0; __sync_lock_test_and_set(&lock, 1); __sync_lock_release(&l= ock); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try=3D"$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=3D\$ac_try;; + *) ac_try_echo=3D$ac_try;; +esac +eval ac_try_echo=3D"\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=3D$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? =3D $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" =3D yes || + $as_test_x conftest$ac_exeext + }; then + have_cc_atomics=3D"yes" +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + have_cc_atomics=3D"no" + +fi + +rm -rf conftest.dSYM +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test "$have_cc_atomics" =3D yes; then + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_CC_ATOMICS 1 +_ACEOF + +else + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } +fi =20 # This test makes sure that run tests work at all. Sometimes a shared # library is found by the linker, but the runtime linker can't find it. Index: postgresql-9.1-9.1.2/src/include/pg_config.h.in =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- postgresql-9.1-9.1.2.orig/src/include/pg_config.h.in 2011-12-01 22:47:2= 0.000000000 +0100 +++ postgresql-9.1-9.1.2/src/include/pg_config.h.in 2012-01-07 10:10:51.657= 609229 +0100 @@ -87,6 +87,9 @@ /* Define to 1 if you have the `cbrt' function. */ #undef HAVE_CBRT =20 +/* Define to 1 if compiler provides atomic builtins */ +#undef HAVE_CC_ATOMICS + /* Define to 1 if you have the `class' function. */ #undef HAVE_CLASS =20 Index: postgresql-9.1-9.1.2/src/include/storage/s_lock.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- postgresql-9.1-9.1.2.orig/src/include/storage/s_lock.h 2011-12-01 22:47= :20.000000000 +0100 +++ postgresql-9.1-9.1.2/src/include/storage/s_lock.h 2012-01-07 10:15:38.2= 85623102 +0100 @@ -255,10 +255,25 @@ #if defined(__arm__) || defined(__arm) #define HAS_TEST_AND_SET =20 -typedef unsigned char slock_t; - #define TAS(lock) tas(lock) =20 +#ifdef HAVE_CC_ATOMICS +typedef int slock_t; /* Note: must use int; char fails on some boards */ + +/* Use compiler provided atomic builtins (gcc/Intel), which work on curren= t ARM + * cores/thumb2 */ +static __inline__ int +tas(volatile slock_t *lock) +{ + return __sync_lock_test_and_set (lock, 1); +} + +#define S_UNLOCK(lock) __sync_lock_release(lock) + +#else +typedef unsigned char slock_t; + +/* Note: does not work with thumb2 */ static __inline__ int tas(volatile slock_t *lock) { @@ -271,6 +286,7 @@ : "memory"); return (int) _res; } +#endif =20 #endif /* __arm__ */ =20 --GPJrCs/72TxItFYR-- --mSxgbZZZvrAyzONB Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBCAAGBQJPCB6qAAoJEPmIJawmtHufCnkP/i7UGilX+6b/2kRW05URYv8b C2K/5oy7qg1N2HrUtHwfxn79DIObD1w5TnQAy04PgSyV4rtV5DvpktQGE1hbec1+ 6oqRwBVhrLvzf0yz2Nzo9qqVuOL+THZ3GWVwj8vRGI7Ne88X0oOH2BsV6bbZW8cR OtPkzp6XIjCPXQwo388cL7IMSewheRb6qaRUG6YmNiA1USu8gQMgFN5620NGvtL0 7YmGM5W4oGYNBv8qwyJGquJeYAOGS3fkTGbM6H0WCGARsxyJY1aDR9C+yIBH19WZ di3YbQBCF23Uou8EfVK0xDHkrF68BD1PCqWCX9Y6ETPAD+0orCp4JyNDO28UlOX2 CadrV48Bh4wXCM8kpHCZNfPnfyuxnCerzS8H8ZpB0C0olU1XSA1JW/sCpgUUtiFR Wosu3D6I9yzBtJ9XJNCTnOPyQt+zaaDEkVgnd4qhuU7BwF4WLo48eVapGQ41EZvs ZVvyRN/dpVR3ucXRzK+IokEzdN5JTLlxrFcM1IRAKw8n0czlY/ZKBKpHTNeSM+/e v/T4vusHMogfdyOOQxOtOboaV3XsJOy3eCRktc3HV05eLmcmCBoBMdvhuPHi7N5E Sydydt9gYzgMrJGws6qQYXM3Cb2GD57VeFN/vPysQ8V2E0tCrxs1nDLlqlwdsP6C 9ggHp/nhrDLHf14UEW0F =WzEG -----END PGP SIGNATURE----- --mSxgbZZZvrAyzONB--