1
1

Add support for OSX builtin atomics.

OSX atomic support is disabled by default. Enable with --enable-osx-builtin-atomics.

Fixes trac:2120

This commit was SVN r29568.

The following Trac tickets were found above:
  Ticket 2120 --> https://svn.open-mpi.org/trac/ompi/ticket/2120
Этот коммит содержится в:
Nathan Hjelm 2013-10-30 17:48:15 +00:00
родитель 598571649a
Коммит b922cd1583
4 изменённых файлов: 227 добавлений и 1 удалений

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

@ -761,11 +761,18 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
[AC_HELP_STRING([--enable-builtin-atomics],
[Enable use of __sync builtin atomics (default: disabled)])])
AC_ARG_ENABLE([osx-builtin-atomics],
[AC_HELP_STRING([--enable-osx-builtin-atomics],
[Enable use of OSX builtin atomics (default: disabled)])])
if 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])
elif test "$enable_osx_builtin_atomics" = "yes" ; then
AC_CHECK_HEADER([libkern/OSAtomic.h],[ompi_cv_asm_arch="OSX_BUILTIN"],
[AC_MSG_ERROR([OSX builtin atomics requested but not found.])])
else
OMPI_CHECK_ASM_PROC
OMPI_CHECK_ASM_TEXT
@ -978,7 +985,7 @@ AC_DEFUN([OMPI_ASM_FIND_FILE], [
AC_REQUIRE([AC_PROG_GREP])
AC_REQUIRE([AC_PROG_FGREP])
if test "$ompi_cv_asm_arch" != "WINDOWS" -a "$ompi_cv_asm_arch" != "SYNC_BUILTIN" ; then
if test "$ompi_cv_asm_arch" != "WINDOWS" -a "$ompi_cv_asm_arch" != "SYNC_BUILTIN" -a "$ompi_cv_asm_arch" != "OSX_BUILTIN" ; then
AC_CHECK_PROG([PERL], [perl], [perl])
# see if we have a pre-built one already

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

@ -163,6 +163,8 @@ typedef struct opal_atomic_lock_t opal_atomic_lock_t;
#include "opal/sys/sparcv9/atomic.h"
#elif OPAL_ASSEMBLY_ARCH == OMPI_SYNC_BUILTIN
#include "opal/sys/sync_builtin/atomic.h"
#elif OPAL_ASSEMBLY_ARCH == OMPI_OSX_BUILTIN
#include "opal/sys/osx/atomic.h"
#endif
#ifndef DOXYGEN

24
opal/include/opal/sys/osx/Makefile.am Обычный файл
Просмотреть файл

@ -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-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) 2013 Los Alamos National Security, LLC. 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/osx/atomic.h

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

@ -0,0 +1,193 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2010 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) 2007 Sun Microsystems, Inc. All rights reserverd.
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OMPI_SYS_ARCH_ATOMIC_H
#define OMPI_SYS_ARCH_ATOMIC_H 1
#include <libkern/OSAtomic.h>
#if OPAL_WANT_SMP_LOCKS
#define MB() OSMemoryBarrier
#else
#define MB()
#endif
/**********************************************************************
*
* Define constants for OSX/iOS
*
*********************************************************************/
#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
#define OPAL_HAVE_ATOMIC_CMPSET_32 1
#define OPAL_HAVE_ATOMIC_CMPSET_64 1
#define OPAL_HAVE_ATOMIC_MATH_32 1
#define OPAL_HAVE_ATOMIC_MATH_64 1
#define OPAL_HAVE_ATOMIC_ADD_32 1
#define OPAL_HAVE_ATOMIC_ADD_64 1
#define OPAL_HAVE_ATOMIC_SUB_32 1
#define OPAL_HAVE_ATOMIC_SUB_64 1
#define OPAL_HAVE_ATOMIC_SPINLOCKS 1
/**********************************************************************
*
* Memory Barriers
*
*********************************************************************/
static inline void opal_atomic_mb(void)
{
MB();
}
static inline void opal_atomic_rmb(void)
{
MB();
}
static inline void opal_atomic_wmb(void)
{
MB();
}
/**********************************************************************
*
* Atomic math operations
*
*********************************************************************/
static inline int opal_atomic_cmpset_32( volatile int32_t *addr,
int32_t oldval, int32_t newval)
{
#if OPAL_WANT_SMP_LOCKS
return OSAtomicCompareAndSwap32Barrier(oldval, newval, addr);
#else
return OSAtomicCompareAndSwap32(oldval, newval, addr);
#endif
}
#define opal_atomic_cmpset_acq_32 opal_atomic_cmpset_32
#define opal_atomic_cmpset_rel_32 opal_atomic_cmpset_32
static inline int opal_atomic_cmpset_64( volatile int64_t *addr,
int64_t oldval, int64_t newval)
{
#if OPAL_WANT_SMP_LOCKS
return OSAtomicCompareAndSwap64Barrier(oldval, newval, addr);
#else
return OSAtomicCompareAndSwap64(oldval, newval, addr);
#endif
}
#define opal_atomic_cmpset_acq_64 opal_atomic_cmpset_64
#define opal_atomic_cmpset_rel_64 opal_atomic_cmpset_64
/**
* atomic_add - add integer to atomic variable
* @i: integer value to add
* @v: pointer of type int
*
* Atomically adds @i to @v.
*/
static inline int32_t opal_atomic_add_32(volatile int32_t* v, int i)
{
#if OPAL_WANT_SMP_LOCKS
return OSAtomicAdd32Barrier (i, v);
#else
return OSAtomicAdd32 (i, v);
#endif
}
/**
* atomic_add - add integer to atomic variable
* @i: integer value to add
* @v: pointer of type int
*
* Atomically adds @i to @v.
*/
static inline int64_t opal_atomic_add_64(volatile int64_t* v, int64_t i)
{
#if OPAL_WANT_SMP_LOCKS
return OSAtomicAdd64Barrier (i, v);
#else
return OSAtomicAdd64 (i, v);
#endif
}
/**
* atomic_sub - subtract the atomic variable
* @i: integer value to subtract
* @v: pointer of type int
*
* Atomically subtracts @i from @v.
*/
static inline int32_t opal_atomic_sub_32(volatile int32_t* v, int i)
{
#if OPAL_WANT_SMP_LOCKS
return OSAtomicAdd32Barrier (-i, v);
#else
return OSAtomicAdd32 (-i, v);
#endif
}
/**
* atomic_sub - subtract the atomic variable
* @i: integer value to subtract
* @v: pointer of type int
*
* Atomically subtracts @i from @v.
*/
static inline int64_t opal_atomic_sub_64(volatile int64_t* v, int64_t i)
{
#if OPAL_WANT_SMP_LOCKS
return OSAtomicAdd64Barrier (-i, v);
#else
return OSAtomicAdd64 (-i, v);
#endif
}
static inline void opal_atomic_init(opal_atomic_lock_t* lock, int32_t value)
{
lock->u.lock = OS_SPINLOCK_INIT;
if (value) {
OSSpinLockLock (&lock->u.lock);
}
}
static inline int opal_atomic_trylock(opal_atomic_lock_t *lock)
{
return !OSSpinLockTry (&lock->u.lock);
}
static inline void opal_atomic_lock(opal_atomic_lock_t *lock)
{
OSSpinLockLock (&lock->u.lock);
}
static inline void opal_atomic_unlock(opal_atomic_lock_t *lock)
{
OSSpinLockUnlock (&lock->u.lock);
}
#endif /* ! OMPI_SYS_ARCH_ATOMIC_H */