mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Add a basic atomic ops API abstracting away platform/architecture details.
Several upcoming performance/scalability improvements require atomic operations. This new API avoids the need to splatter compiler and architecture dependent code over all the locations employing atomic ops. For several of the potential usages it'd be problematic to maintain both, a atomics using implementation and one using spinlocks or similar. In all likelihood one of the implementations would not get tested regularly under concurrency. To avoid that scenario the new API provides a automatic fallback of atomic operations to spinlocks. All properties of atomic operations are maintained. This fallback - obviously - isn't as fast as just using atomic ops, but it's not bad either. For one of the future users the atomics ontop spinlocks implementation was actually slightly faster than the old purely spinlock using implementation. That's important because it reduces the fear of regressing older platforms when improving the scalability for new ones. The API, loosely modeled after the C11 atomics support, currently provides 'atomic flags' and 32 bit unsigned integers. If the platform efficiently supports atomic 64 bit unsigned integers those are also provided. To implement atomics support for a platform/architecture/compiler for a type of atomics 32bit compare and exchange needs to be implemented. If available and more efficient native support for flags, 32 bit atomic addition, and corresponding 64 bit operations may also be provided. Additional useful atomic operations are implemented generically ontop of these. The implementation for various versions of gcc, msvc and sun studio have been tested. Additional existing stub implementations for * Intel icc * HUPX acc * IBM xlc are included but have never been tested. These will likely require fixes based on buildfarm and user feedback. As atomic operations also require barriers for some operations the existing barrier support has been moved into the atomics code. Author: Andres Freund with contributions from Oskari Saarenmaa Reviewed-By: Amit Kapila, Robert Haas, Heikki Linnakangas and Álvaro Herrera Discussion: CA+TgmoYBW+ux5-8Ja=Mcyuy8=VXAnVRHp3Kess6Pn3DMXAPAEA@mail.gmail.com, 20131015123303.GH5300@awork2.anarazel.de, 20131028205522.GI20248@awork2.anarazel.de
This commit is contained in:
274
configure
vendored
274
configure
vendored
@ -802,6 +802,7 @@ enable_nls
|
||||
with_pgport
|
||||
enable_rpath
|
||||
enable_spinlocks
|
||||
enable_atomics
|
||||
enable_debug
|
||||
enable_profiling
|
||||
enable_coverage
|
||||
@ -1470,6 +1471,7 @@ Optional Features:
|
||||
--disable-rpath do not embed shared library search path in
|
||||
executables
|
||||
--disable-spinlocks do not use spinlocks
|
||||
--disable-atomics do not use atomic operations
|
||||
--enable-debug build with debugging symbols (-g)
|
||||
--enable-profiling build with profiling enabled
|
||||
--enable-coverage build with coverage testing instrumentation
|
||||
@ -3145,6 +3147,33 @@ fi
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Atomic operations
|
||||
#
|
||||
|
||||
|
||||
# Check whether --enable-atomics was given.
|
||||
if test "${enable_atomics+set}" = set; then :
|
||||
enableval=$enable_atomics;
|
||||
case $enableval in
|
||||
yes)
|
||||
:
|
||||
;;
|
||||
no)
|
||||
:
|
||||
;;
|
||||
*)
|
||||
as_fn_error $? "no argument expected for --enable-atomics option" "$LINENO" 5
|
||||
;;
|
||||
esac
|
||||
|
||||
else
|
||||
enable_atomics=yes
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#
|
||||
# --enable-debug adds -g to compiler flags
|
||||
#
|
||||
@ -8349,6 +8378,17 @@ $as_echo "$as_me: WARNING:
|
||||
*** Not using spinlocks will cause poor performance." >&2;}
|
||||
fi
|
||||
|
||||
if test "$enable_atomics" = yes; then
|
||||
|
||||
$as_echo "#define HAVE_ATOMICS 1" >>confdefs.h
|
||||
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
|
||||
*** Not using atomic operations will cause poor performance." >&5
|
||||
$as_echo "$as_me: WARNING:
|
||||
*** Not using atomic operations will cause poor performance." >&2;}
|
||||
fi
|
||||
|
||||
if test "$with_gssapi" = yes ; then
|
||||
if test "$PORTNAME" != "win32"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gss_init_sec_context" >&5
|
||||
@ -9123,7 +9163,7 @@ fi
|
||||
done
|
||||
|
||||
|
||||
for ac_header in crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h poll.h pwd.h sys/ioctl.h sys/ipc.h sys/poll.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/socket.h sys/sockio.h sys/tas.h sys/time.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
|
||||
for ac_header in atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h poll.h pwd.h sys/ioctl.h sys/ipc.h sys/poll.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/socket.h sys/sockio.h sys/tas.h sys/time.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
|
||||
do :
|
||||
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
||||
@ -12154,40 +12194,6 @@ fi
|
||||
done
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin locking functions" >&5
|
||||
$as_echo_n "checking for builtin locking functions... " >&6; }
|
||||
if ${pgac_cv_gcc_int_atomics+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int lock = 0;
|
||||
__sync_lock_test_and_set(&lock, 1);
|
||||
__sync_lock_release(&lock);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
pgac_cv_gcc_int_atomics="yes"
|
||||
else
|
||||
pgac_cv_gcc_int_atomics="no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_int_atomics" >&5
|
||||
$as_echo "$pgac_cv_gcc_int_atomics" >&6; }
|
||||
if test x"$pgac_cv_gcc_int_atomics" = x"yes"; then
|
||||
|
||||
$as_echo "#define HAVE_GCC_INT_ATOMICS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
# Lastly, restore full LIBS list and check for readline/libedit symbols
|
||||
LIBS="$LIBS_including_readline"
|
||||
|
||||
@ -13711,6 +13717,204 @@ _ACEOF
|
||||
fi
|
||||
|
||||
|
||||
# Check for various atomic operations now that we have checked how to declare
|
||||
# 64bit integers.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin __sync char locking functions" >&5
|
||||
$as_echo_n "checking for builtin __sync char locking functions... " >&6; }
|
||||
if ${pgac_cv_gcc_sync_char_tas+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
char lock = 0;
|
||||
__sync_lock_test_and_set(&lock, 1);
|
||||
__sync_lock_release(&lock);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
pgac_cv_gcc_sync_char_tas="yes"
|
||||
else
|
||||
pgac_cv_gcc_sync_char_tas="no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_sync_char_tas" >&5
|
||||
$as_echo "$pgac_cv_gcc_sync_char_tas" >&6; }
|
||||
if test x"$pgac_cv_gcc_sync_char_tas" = x"yes"; then
|
||||
|
||||
$as_echo "#define HAVE_GCC__SYNC_CHAR_TAS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin __sync int32 locking functions" >&5
|
||||
$as_echo_n "checking for builtin __sync int32 locking functions... " >&6; }
|
||||
if ${pgac_cv_gcc_sync_int32_tas+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int lock = 0;
|
||||
__sync_lock_test_and_set(&lock, 1);
|
||||
__sync_lock_release(&lock);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
pgac_cv_gcc_sync_int32_tas="yes"
|
||||
else
|
||||
pgac_cv_gcc_sync_int32_tas="no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_sync_int32_tas" >&5
|
||||
$as_echo "$pgac_cv_gcc_sync_int32_tas" >&6; }
|
||||
if test x"$pgac_cv_gcc_sync_int32_tas" = x"yes"; then
|
||||
|
||||
$as_echo "#define HAVE_GCC__SYNC_INT32_TAS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin __sync int32 atomic operations" >&5
|
||||
$as_echo_n "checking for builtin __sync int32 atomic operations... " >&6; }
|
||||
if ${pgac_cv_gcc_sync_int32_cas+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int val = 0;
|
||||
__sync_val_compare_and_swap(&val, 0, 37);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
pgac_cv_gcc_sync_int32_cas="yes"
|
||||
else
|
||||
pgac_cv_gcc_sync_int32_cas="no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_sync_int32_cas" >&5
|
||||
$as_echo "$pgac_cv_gcc_sync_int32_cas" >&6; }
|
||||
if test x"$pgac_cv_gcc_sync_int32_cas" = x"yes"; then
|
||||
|
||||
$as_echo "#define HAVE_GCC__SYNC_INT32_CAS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin __sync int64 atomic operations" >&5
|
||||
$as_echo_n "checking for builtin __sync int64 atomic operations... " >&6; }
|
||||
if ${pgac_cv_gcc_sync_int64_cas+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
PG_INT64_TYPE lock = 0;
|
||||
__sync_val_compare_and_swap(&lock, 0, (PG_INT64_TYPE) 37);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
pgac_cv_gcc_sync_int64_cas="yes"
|
||||
else
|
||||
pgac_cv_gcc_sync_int64_cas="no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_sync_int64_cas" >&5
|
||||
$as_echo "$pgac_cv_gcc_sync_int64_cas" >&6; }
|
||||
if test x"$pgac_cv_gcc_sync_int64_cas" = x"yes"; then
|
||||
|
||||
$as_echo "#define HAVE_GCC__SYNC_INT64_CAS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin __atomic int32 atomic operations" >&5
|
||||
$as_echo_n "checking for builtin __atomic int32 atomic operations... " >&6; }
|
||||
if ${pgac_cv_gcc_atomic_int32_cas+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int val = 0;
|
||||
int expect = 0;
|
||||
__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
pgac_cv_gcc_atomic_int32_cas="yes"
|
||||
else
|
||||
pgac_cv_gcc_atomic_int32_cas="no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_atomic_int32_cas" >&5
|
||||
$as_echo "$pgac_cv_gcc_atomic_int32_cas" >&6; }
|
||||
if test x"$pgac_cv_gcc_atomic_int32_cas" = x"yes"; then
|
||||
|
||||
$as_echo "#define HAVE_GCC__ATOMIC_INT32_CAS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin __atomic int64 atomic operations" >&5
|
||||
$as_echo_n "checking for builtin __atomic int64 atomic operations... " >&6; }
|
||||
if ${pgac_cv_gcc_atomic_int64_cas+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
PG_INT64_TYPE val = 0;
|
||||
PG_INT64_TYPE expect = 0;
|
||||
__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
pgac_cv_gcc_atomic_int64_cas="yes"
|
||||
else
|
||||
pgac_cv_gcc_atomic_int64_cas="no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_atomic_int64_cas" >&5
|
||||
$as_echo "$pgac_cv_gcc_atomic_int64_cas" >&6; }
|
||||
if test x"$pgac_cv_gcc_atomic_int64_cas" = x"yes"; then
|
||||
|
||||
$as_echo "#define HAVE_GCC__ATOMIC_INT64_CAS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
if test "$PORTNAME" != "win32"
|
||||
then
|
||||
|
Reference in New Issue
Block a user