1
1

Add (optional/last ditch effort) support for GCC/Intel __sync_ builtin atomic

operations.  Much easier than adding support for a new architecture.

This commit was SVN r25498.
Этот коммит содержится в:
Brian Barrett 2011-11-23 04:25:41 +00:00
родитель 9b59d8de6f
Коммит 86f555121c
8 изменённых файлов: 217 добавлений и 3 удалений

Просмотреть файл

@ -19,7 +19,7 @@ Copyright (c) 2006-2010 Los Alamos National Security, LLC. All rights
reserved.
Copyright (c) 2006-2010 Cisco Systems, Inc. All rights reserved.
Copyright (c) 2006-2010 Voltaire, Inc. All rights reserved.
Copyright (c) 2006-2010 Sandia National Laboratories. All rights reserved.
Copyright (c) 2006-2011 Sandia National Laboratories. All rights reserved.
Copyright (c) 2006-2010 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
Copyright (c) 2006-2010 The University of Houston. All rights reserved.

Просмотреть файл

@ -19,6 +19,17 @@ dnl $HEADER$
dnl
AC_DEFUN([OPAL_CHECK_SYNC_BUILTINS], [
AC_MSG_CHECKING([for __sync builtin atomics])
AC_TRY_COMPILE([], [__sync_synchronize()],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])
])
dnl #################################################################
dnl
dnl OMPI_CHECK_ASM_TEXT
@ -841,8 +852,21 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
AC_DEFINE_UNQUOTED([OPAL_WANT_SMP_LOCKS], [$want_smp_locks],
[whether we want to have smp locks in atomic ops or not])
AC_ARG_ENABLE([builtin-atomics],
[AC_HELP_STRING([--enable-builtin-atomics],
[Enable use of __sync builtin atomics (default: disabled)])])
if test "$ompi_cv_c_compiler_vendor" = "microsoft" ; then
ompi_cv_asm_arch="WINDOWS"
elif test "$enable_builtin_atomics" = "yes" ; then
OPAL_CHECK_SYNC_BUILTINS([ompi_cv_asm_arch="SYNC_BUILTIN"],
[AC_MSG_ERROR([__sync builtin atomics requested but not found.])])
AC_DEFINE([OPAL_C_GCC_INLINE_ASSEMBLY], [1],
[Whether C compiler supports GCC style inline assembly])
m4_ifdef([project_ompi],
[AS_IF([test "$WANT_MPI_CXX_SUPPORT" = "1"],
[AC_DEFINE([OMPI_CXX_GCC_INLINE_ASSEMBLY], [1],
[Whether C++ compiler supports GCC style inline assembly])])])
else
OMPI_CHECK_ASM_PROC
OMPI_CHECK_ASM_TEXT
@ -946,10 +970,19 @@ AC_MSG_ERROR([Can not continue.])
;;
*)
AC_MSG_ERROR([No atomic primitives available for $host])
OPAL_CHECK_SYNC_BUILTINS([ompi_cv_asm_arch="SYNC_BUILTIN"],
[AC_MSG_ERROR([No atomic primitives available for $host])])
;;
esac
if test "$ompi_cv_asm_arch" = "SYNC_BUILTIN" ; then
AC_DEFINE([OPAL_C_GCC_INLINE_ASSEMBLY], [1],
[Whether C compiler supports GCC style inline assembly])
m4_ifdef([project_ompi],
[AS_IF([test "$WANT_MPI_CXX_SUPPORT" = "1"],
[AC_DEFINE([OMPI_CXX_GCC_INLINE_ASSEMBLY], [1],
[Whether C++ compiler supports GCC style inline assembly])])])
else
AC_DEFINE_UNQUOTED([OPAL_ASM_SUPPORT_64BIT],
[$OPAL_ASM_SUPPORT_64BIT],
[Whether we can do 64bit assembly operations or not. Should not be used outside of the assembly header files])
@ -1004,6 +1037,7 @@ AC_MSG_ERROR([Can not continue.])
AC_DEFINE_UNQUOTED([OPAL_ASSEMBLY_FORMAT], ["$OPAL_ASSEMBLY_FORMAT"],
[Format of assembly file])
AC_SUBST([OPAL_ASSEMBLY_FORMAT])
fi # if ompi_cv_asm_arch = SYNC_BUILTIN
fi # if cv_c_compiler_vendor = microsoft
result="OMPI_$ompi_cv_asm_arch"
@ -1032,7 +1066,7 @@ AC_DEFUN([OMPI_ASM_FIND_FILE], [
AC_REQUIRE([AC_PROG_GREP])
AC_REQUIRE([AC_PROG_FGREP])
if test "$ompi_cv_asm_arch" != "WINDOWS" ; then
if test "$ompi_cv_asm_arch" != "WINDOWS" -a "$ompi_cv_asm_arch" != "SYNC_BUILTIN" ; then
AC_CHECK_PROG([PERL], [perl], [perl])
# see if we have a pre-built one already

Просмотреть файл

@ -10,6 +10,7 @@
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
@ -34,3 +35,4 @@ include opal/sys/mips/Makefile.am
include opal/sys/powerpc/Makefile.am
include opal/sys/sparcv9/Makefile.am
include opal/sys/win32/Makefile.am
include opal/sys/sync_builtin/Makefile.am

Просмотреть файл

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -37,6 +38,7 @@
#define OMPI_SPARCV9_64 0062
#define OMPI_MIPS 0070
#define OMPI_ARM 0100
#define OMPI_SYNC_BUILTIN 0200
/* Formats */
#define OMPI_DEFAULT 1000 /* standard for given architecture */

Просмотреть файл

@ -10,6 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -168,6 +169,8 @@ typedef struct opal_atomic_lock_t opal_atomic_lock_t;
#include "opal/sys/sparcv9/atomic.h"
#elif OPAL_ASSEMBLY_ARCH == OMPI_SPARCV9_64
#include "opal/sys/sparcv9/atomic.h"
#elif OPAL_ASSEMBLY_ARCH == OMPI_SYNC_BUILTIN
#include "opal/sys/sync_builtin/atomic.h"
#endif
#ifndef DOXYGEN
@ -180,6 +183,12 @@ typedef struct opal_atomic_lock_t opal_atomic_lock_t;
#ifndef OPAL_HAVE_ATOMIC_CMPSET_64
#define OPAL_HAVE_ATOMIC_CMPSET_64 0
#endif
#ifndef OPAL_HAVE_ATOMIC_SWAP_32
#define OPAL_HAVE_ATOMIC_SWAP_32 0
#endif
#ifndef OPAL_HAVE_ATOMIC_SWAP_64
#define OPAL_HAVE_ATOMIC_SWAP_64 0
#endif
#endif /* DOXYGEN */
/**********************************************************************

Просмотреть файл

@ -0,0 +1,24 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2009 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# This makefile.am does not stand on its own - it is included from opal/include/Makefile.am
headers += \
opal/sys/sync_builtin/atomic.h \
opal/sys/sync_builtin/timer.h

116
opal/include/opal/sys/sync_builtin/atomic.h Обычный файл
Просмотреть файл

@ -0,0 +1,116 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OMPI_SYS_ARCH_ATOMIC_H
#define OMPI_SYS_ARCH_ATOMIC_H 1
/**********************************************************************
*
* Memory Barriers
*
*********************************************************************/
#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
static inline void opal_atomic_mb(void)
{
__sync_synchronize();
}
static inline void opal_atomic_rmb(void)
{
__sync_synchronize();
}
static inline void opal_atomic_wmb(void)
{
__sync_synchronize();
}
/**********************************************************************
*
* Atomic math operations
*
*********************************************************************/
#define OPAL_HAVE_ATOMIC_CMPSET_32 1
static inline int opal_atomic_cmpset_acq_32( volatile int32_t *addr,
int32_t oldval, int32_t newval)
{
return __sync_bool_compare_and_swap(addr, oldval, newval);
}
static inline int opal_atomic_cmpset_rel_32( volatile int32_t *addr,
int32_t oldval, int32_t newval)
{
return __sync_bool_compare_and_swap(addr, oldval, newval);}
static inline int opal_atomic_cmpset_32( volatile int32_t *addr,
int32_t oldval, int32_t newval)
{
return __sync_bool_compare_and_swap(addr, oldval, newval);
}
#define OPAL_HAVE_ATOMIC_MATH_32 1
#define OPAL_HAVE_ATOMIC_ADD_32 1
static inline int32_t opal_atomic_add_32(volatile int32_t *addr, int32_t delta)
{
return __sync_fetch_and_add(addr, delta);
}
#define OPAL_HAVE_ATOMIC_SUB_32 1
static inline int32_t opal_atomic_sub_32(volatile int32_t *addr, int32_t delta)
{
return __sync_fetch_and_sub(addr, delta);
}
#define OPAL_HAVE_ATOMIC_CMPSET_64 1
static inline int opal_atomic_cmpset_acq_64( volatile int64_t *addr,
int64_t oldval, int64_t newval)
{
return __sync_bool_compare_and_swap(addr, oldval, newval);
}
static inline int opal_atomic_cmpset_rel_64( volatile int64_t *addr,
int64_t oldval, int64_t newval)
{
return __sync_bool_compare_and_swap(addr, oldval, newval);}
static inline int opal_atomic_cmpset_64( volatile int64_t *addr,
int64_t oldval, int64_t newval)
{
return __sync_bool_compare_and_swap(addr, oldval, newval);
}
#define OPAL_HAVE_ATOMIC_MATH_64 1
#define OPAL_HAVE_ATOMIC_ADD_64 1
static inline int64_t opal_atomic_add_64(volatile int64_t *addr, int64_t delta)
{
return __sync_fetch_and_add(addr, delta);
}
#define OPAL_HAVE_ATOMIC_SUB_64 1
static inline int64_t opal_atomic_sub_64(volatile int64_t *addr, int64_t delta)
{
return __sync_fetch_and_sub(addr, delta);
}
#endif /* ! OMPI_SYS_ARCH_ATOMIC_H */

27
opal/include/opal/sys/sync_builtin/timer.h Обычный файл
Просмотреть файл

@ -0,0 +1,27 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OMPI_SYS_ARCH_TIMER_H
#define OMPI_SYS_ARCH_TIMER_H 1
typedef long opal_timer_t;
#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0
#endif /* ! OMPI_SYS_ARCH_TIMER_H */