aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-01-01 22:39:59 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-01-02 00:02:00 -0500
commit5cfa8dd3007d7e953c6a03b0fa2215d97c581b0c (patch)
tree39ee2902ec30be8467b91a25f3f02c7a89f70507 /src
parent6b6137e4efebcd767a349099b3e048fbc7755cca (diff)
downloadpostgresql-5cfa8dd3007d7e953c6a03b0fa2215d97c581b0c.tar.gz
postgresql-5cfa8dd3007d7e953c6a03b0fa2215d97c581b0c.zip
Use mutex hint bit in PPC LWARX instructions, where possible.
The hint bit makes for a small but measurable performance improvement in access to contended spinlocks. On the other hand, some PPC chips give an illegal-instruction failure. There doesn't seem to be a completely bulletproof way to tell whether the hint bit will cause an illegal-instruction failure other than by trying it; but most if not all 64-bit PPC machines should accept it, so follow the Linux kernel's lead and assume it's okay to use it in 64-bit builds. Of course we must also check whether the assembler accepts the command, since even with a recent CPU the toolchain could be old. Patch by Manabu Ori, significantly modified by me.
Diffstat (limited to 'src')
-rw-r--r--src/include/pg_config.h.in5
-rw-r--r--src/include/pg_config_manual.h18
-rw-r--r--src/include/storage/s_lock.h4
3 files changed, 26 insertions, 1 deletions
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index ef467b73866..e1b7fea49fc 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -275,7 +275,7 @@
/* Define to 1 if `text.data' is member of `krb5_error'. */
#undef HAVE_KRB5_ERROR_TEXT_DATA
-/* Define to 1 if you have krb5_free_unparsed_name */
+/* Define to 1 if you have krb5_free_unparsed_name. */
#undef HAVE_KRB5_FREE_UNPARSED_NAME
/* Define to 1 if `client' is member of `krb5_ticket'. */
@@ -384,6 +384,9 @@
/* Define to 1 if you have the POSIX signal interface. */
#undef HAVE_POSIX_SIGNALS
+/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */
+#undef HAVE_PPC_LWARX_MUTEX_HINT
+
/* Define to 1 if you have the `pstat' function. */
#undef HAVE_PSTAT
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index ac434fabbc4..810be27e813 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -6,6 +6,9 @@
* for developers. If you edit any of these, be sure to do a *full*
* rebuild (and an initdb if noted).
*
+ * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
* src/include/pg_config_manual.h
*------------------------------------------------------------------------
*/
@@ -171,6 +174,21 @@
#endif
/*
+ * On PPC machines, decide whether to use the mutex hint bit in LWARX
+ * instructions. Setting the hint bit will slightly improve spinlock
+ * performance on POWER6 and later machines, but does nothing before that,
+ * and will result in illegal-instruction failures on some pre-POWER4
+ * machines. By default we use the hint bit when building for 64-bit PPC,
+ * which should be safe in nearly all cases. You might want to override
+ * this if you are building 32-bit code for a known-recent PPC machine.
+ */
+#ifdef HAVE_PPC_LWARX_MUTEX_HINT /* must have assembler support in any case */
+#if defined(__ppc64__) || defined(__powerpc64__)
+#define USE_PPC_LWARX_MUTEX_HINT
+#endif
+#endif
+
+/*
*------------------------------------------------------------------------
* The following symbols are for enabling debugging code, not for
* controlling user-visible features or resource limits.
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 98c12db3ab3..cc67be81eb3 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -372,7 +372,11 @@ tas(volatile slock_t *lock)
int _res;
__asm__ __volatile__(
+#ifdef USE_PPC_LWARX_MUTEX_HINT
+" lwarx %0,0,%3,1 \n"
+#else
" lwarx %0,0,%3 \n"
+#endif
" cmpwi %0,0 \n"
" bne 1f \n"
" addi %0,%0,1 \n"