Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5cfa8dd

Browse files
committed
Use mutex hint bit in PPC LWARX instructions, where possible.
The hint bit makes for a small but measurable performance improvementin 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 thehint bit will cause an illegal-instruction failure other than by tryingit; but most if not all 64-bit PPC machines should accept it, so followthe 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.
1 parent6b6137e commit5cfa8dd

File tree

5 files changed

+104
-3
lines changed

5 files changed

+104
-3
lines changed

‎configure

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
16351635
This configure script is free software; the Free Software Foundation
16361636
gives unlimited permission to copy, distribute and modify it.
16371637

1638-
Copyright (c) 1996-2011, PostgreSQL Global Development Group
1638+
Copyright (c) 1996-2012, PostgreSQL Global Development Group
16391639
_ACEOF
16401640
exit
16411641
fi
@@ -18207,6 +18207,66 @@ rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
1820718207
conftest$ac_exeext conftest.$ac_ext
1820818208
fi
1820918209

18210+
# On PPC, check if assembler supports LWARX instruction's mutex hint bit
18211+
case $host_cpu in
18212+
ppc*|powerpc*)
18213+
{ $as_echo "$as_me:$LINENO: checking whether assembler supports lwarx hint bit" >&5
18214+
$as_echo_n "checking whether assembler supports lwarx hint bit... " >&6; }
18215+
cat >conftest.$ac_ext <<_ACEOF
18216+
/* confdefs.h. */
18217+
_ACEOF
18218+
cat confdefs.h >>conftest.$ac_ext
18219+
cat >>conftest.$ac_ext <<_ACEOF
18220+
/* end confdefs.h. */
18221+
18222+
int
18223+
main ()
18224+
{
18225+
int a = 0; int *p = &a; int r;
18226+
__asm__ __volatile__ (" lwarx %0,0,%1,1\n" : "=&r"(r) : "r"(p));
18227+
;
18228+
return 0;
18229+
}
18230+
_ACEOF
18231+
rm -f conftest.$ac_objext
18232+
if { (ac_try="$ac_compile"
18233+
case "(($ac_try" in
18234+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
18235+
*) ac_try_echo=$ac_try;;
18236+
esac
18237+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
18238+
$as_echo "$ac_try_echo") >&5
18239+
(eval "$ac_compile") 2>conftest.er1
18240+
ac_status=$?
18241+
grep -v '^ *+' conftest.er1 >conftest.err
18242+
rm -f conftest.er1
18243+
cat conftest.err >&5
18244+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
18245+
(exit $ac_status); } && {
18246+
test -z "$ac_c_werror_flag" ||
18247+
test ! -s conftest.err
18248+
} && test -s conftest.$ac_objext; then
18249+
pgac_cv_have_ppc_mutex_hint=yes
18250+
else
18251+
$as_echo "$as_me: failed program was:" >&5
18252+
sed 's/^/| /' conftest.$ac_ext >&5
18253+
18254+
pgac_cv_have_ppc_mutex_hint=no
18255+
fi
18256+
18257+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
18258+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_have_ppc_mutex_hint" >&5
18259+
$as_echo "$pgac_cv_have_ppc_mutex_hint" >&6; }
18260+
if test x"$pgac_cv_have_ppc_mutex_hint" = xyes ; then
18261+
18262+
cat >>confdefs.h <<\_ACEOF
18263+
#define HAVE_PPC_LWARX_MUTEX_HINT 1
18264+
_ACEOF
18265+
18266+
fi
18267+
;;
18268+
esac
18269+
1821018270
# Check largefile support. You might think this is a system service not a
1821118271
# compiler characteristic, but you'd be wrong. We must check this before
1821218272
# probing existence of related functions such as fseeko, since the largefile

‎configure.in

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,11 +1170,27 @@ if test "$with_krb5" = yes; then
11701170
AC_MSG_CHECKING(for krb5_free_unparsed_name)
11711171
AC_TRY_LINK([#include <krb5.h>],
11721172
[krb5_free_unparsed_name(NULL,NULL);],
1173-
[AC_DEFINE(HAVE_KRB5_FREE_UNPARSED_NAME, 1, [Define to 1 if you have krb5_free_unparsed_name])
1173+
[AC_DEFINE(HAVE_KRB5_FREE_UNPARSED_NAME, 1, [Define to 1 if you have krb5_free_unparsed_name.])
11741174
AC_MSG_RESULT(yes)],
11751175
[AC_MSG_RESULT(no)])
11761176
fi
11771177

1178+
# On PPC, check if assembler supports LWARX instruction's mutex hint bit
1179+
case $host_cpu in
1180+
ppc*|powerpc*)
1181+
AC_MSG_CHECKING([whether assembler supports lwarx hint bit])
1182+
AC_TRY_COMPILE([],
1183+
[int a = 0; int *p = &a; int r;
1184+
__asm__ __volatile__ (" lwarx %0,0,%1,1\n" : "=&r"(r) : "r"(p));],
1185+
[pgac_cv_have_ppc_mutex_hint=yes],
1186+
[pgac_cv_have_ppc_mutex_hint=no])
1187+
AC_MSG_RESULT([$pgac_cv_have_ppc_mutex_hint])
1188+
if test x"$pgac_cv_have_ppc_mutex_hint" = xyes ; then
1189+
AC_DEFINE(HAVE_PPC_LWARX_MUTEX_HINT, 1, [Define to 1 if the assembler supports PPC's LWARX mutex hint bit.])
1190+
fi
1191+
;;
1192+
esac
1193+
11781194
# Check largefile support. You might think this is a system service not a
11791195
# compiler characteristic, but you'd be wrong. We must check this before
11801196
# probing existence of related functions such as fseeko, since the largefile

‎src/include/pg_config.h.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
/* Define to 1 if `text.data' is member of `krb5_error'. */
276276
#undef HAVE_KRB5_ERROR_TEXT_DATA
277277

278-
/* Define to 1 if you have krb5_free_unparsed_name */
278+
/* Define to 1 if you have krb5_free_unparsed_name. */
279279
#undef HAVE_KRB5_FREE_UNPARSED_NAME
280280

281281
/* Define to 1 if `client' is member of `krb5_ticket'. */
@@ -384,6 +384,9 @@
384384
/* Define to 1 if you have the POSIX signal interface. */
385385
#undef HAVE_POSIX_SIGNALS
386386

387+
/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */
388+
#undef HAVE_PPC_LWARX_MUTEX_HINT
389+
387390
/* Define to 1 if you have the `pstat' function. */
388391
#undef HAVE_PSTAT
389392

‎src/include/pg_config_manual.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* for developers.If you edit any of these, be sure to do a *full*
77
* rebuild (and an initdb if noted).
88
*
9+
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
10+
* Portions Copyright (c) 1994, Regents of the University of California
11+
*
912
* src/include/pg_config_manual.h
1013
*------------------------------------------------------------------------
1114
*/
@@ -170,6 +173,21 @@
170173
#definePG_PRINTF_ATTRIBUTE printf
171174
#endif
172175

176+
/*
177+
* On PPC machines, decide whether to use the mutex hint bit in LWARX
178+
* instructions. Setting the hint bit will slightly improve spinlock
179+
* performance on POWER6 and later machines, but does nothing before that,
180+
* and will result in illegal-instruction failures on some pre-POWER4
181+
* machines. By default we use the hint bit when building for 64-bit PPC,
182+
* which should be safe in nearly all cases. You might want to override
183+
* this if you are building 32-bit code for a known-recent PPC machine.
184+
*/
185+
#ifdefHAVE_PPC_LWARX_MUTEX_HINT/* must have assembler support in any case */
186+
#if defined(__ppc64__)|| defined(__powerpc64__)
187+
#defineUSE_PPC_LWARX_MUTEX_HINT
188+
#endif
189+
#endif
190+
173191
/*
174192
*------------------------------------------------------------------------
175193
* The following symbols are for enabling debugging code, not for

‎src/include/storage/s_lock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,11 @@ tas(volatile slock_t *lock)
372372
int_res;
373373

374374
__asm__ __volatile__(
375+
#ifdefUSE_PPC_LWARX_MUTEX_HINT
376+
"lwarx %0,0,%3,1\n"
377+
#else
375378
"lwarx %0,0,%3\n"
379+
#endif
376380
"cmpwi %0,0\n"
377381
"bne 1f\n"
378382
"addi %0,%0,1\n"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp