Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C11 #18

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

C11 #18

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
00e513f
partway through implementing OPA using C11
jeffhammond Mar 3, 2014
ccd1d28
finish off impl of existing features; removed emulation. need to add…
jeffhammond Mar 3, 2014
9bb6bd5
implement the rest of the operations found in opa_unsafe.h
jeffhammond Mar 4, 2014
13711b7
choose C11 atomics before anything else (besides unsafe)
jeffhammond Mar 4, 2014
bfc8973
add some configure magic for C11 impl
jeffhammond Mar 4, 2014
8e6dc9d
fix a pass-by-val/ref bug and add a bunch of explicit casts for void*…
jeffhammond Mar 4, 2014
2df6376
remove incorrect casting
jeffhammond Mar 4, 2014
df0d39c
add FIXME related to CAS
jeffhammond Mar 4, 2014
298e0d6
resolve issues with CAS return value by resorting to not-actually-ato…
jeffhammond Mar 5, 2014
4e7aa02
learned about returning old value in expected but not able to get cor…
jeffhammond Mar 5, 2014
320d966
add c11 test to automake and git
jeffhammond Mar 18, 2014
9eedd62
fix cas impl. expected holds old val either way.
jeffhammond Mar 18, 2014
689920a
fix bugs in C11 implementation
jeffhammond Sep 4, 2016
6c88ee1
workaround ATOMIC_*_LOCK_FREE bug in Clang
jeffhammond Sep 4, 2016
cf1cb55
Updated trac URLs
Jun 27, 2014
e0a3ea1
Updated contact information in COPYRIGHT
Jun 27, 2014
d2f8908
add Travis script
jeffhammond Sep 4, 2016
af1a04c
declare pthread_yield
jeffhammond Sep 19, 2016
95d36c7
older GCC doesn't understand C11
jeffhammond Sep 19, 2016
56f5547
soft fail on missing C11
jeffhammond Sep 20, 2016
4c2e187
remove notifications
Apr 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .travis-install-autotools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/sh

set +e
set -x

os=`uname`
TRAVIS_ROOT="$1"

case "$os" in
Darwin)
set +e # do not fail on error
brew update
brew info autoconf automake libtool
brew install autoconf automake libtool
brew upgrade autoconf automake libtool
which glibtool
which glibtoolize
glibtool --version
ln -s `which glibtool` ${TRAVIS_ROOT}/bin/libtool
ln -s `which glibtoolize` ${TRAVIS_ROOT}/bin/libtoolize
set -e # restore fail on error
;;
Linux)
MAKE_JNUM=2
M4_VERSION=1.4.17
LIBTOOL_VERSION=2.4.6
AUTOCONF_VERSION=2.69
AUTOMAKE_VERSION=1.15

cd ${TRAVIS_ROOT}
TOOL=m4
TDIR=${TOOL}-${M4_VERSION}
FILE=${TDIR}.tar.gz
BIN=${TRAVIS_ROOT}/bin/${TOOL}
if [ -f ${FILE} ] ; then
echo ${FILE} already exists! Using existing copy.
else
wget http://ftp.gnu.org/gnu/${TOOL}/${FILE}
fi
if [ -d ${TDIR} ] ; then
echo ${TDIR} already exists! Using existing copy.
else
echo Unpacking ${FILE}
tar -xzf ${FILE}
fi
if [ -f ${BIN} ] ; then
echo ${BIN} already exists! Skipping build.
else
cd ${TRAVIS_ROOT}/${TDIR}
./configure CC=cc --prefix=${TRAVIS_ROOT} && make -j ${MAKE_JNUM} && make install
if [ "x$?" != "x0" ] ; then
echo FAILURE 1
exit
fi
fi

cd ${TRAVIS_ROOT}
TOOL=libtool
TDIR=${TOOL}-${LIBTOOL_VERSION}
FILE=${TDIR}.tar.gz
BIN=${TRAVIS_ROOT}/bin/${TOOL}
if [ ! -f ${FILE} ] ; then
wget http://ftp.gnu.org/gnu/${TOOL}/${FILE}
else
echo ${FILE} already exists! Using existing copy.
fi
if [ ! -d ${TDIR} ] ; then
echo Unpacking ${FILE}
tar -xzf ${FILE}
else
echo ${TDIR} already exists! Using existing copy.
fi
if [ -f ${BIN} ] ; then
echo ${BIN} already exists! Skipping build.
else
cd ${TRAVIS_ROOT}/${TDIR}
./configure CC=cc --prefix=${TRAVIS_ROOT} M4=${TRAVIS_ROOT}/bin/m4 && make -j ${MAKE_JNUM} && make install
if [ "x$?" != "x0" ] ; then
echo FAILURE 2
exit
fi
fi

cd ${TRAVIS_ROOT}
TOOL=autoconf
TDIR=${TOOL}-${AUTOCONF_VERSION}
FILE=${TDIR}.tar.gz
BIN=${TRAVIS_ROOT}/bin/${TOOL}
if [ ! -f ${FILE} ] ; then
wget http://ftp.gnu.org/gnu/${TOOL}/${FILE}
else
echo ${FILE} already exists! Using existing copy.
fi
if [ ! -d ${TDIR} ] ; then
echo Unpacking ${FILE}
tar -xzf ${FILE}
else
echo ${TDIR} already exists! Using existing copy.
fi
if [ -f ${BIN} ] ; then
echo ${BIN} already exists! Skipping build.
else
cd ${TRAVIS_ROOT}/${TDIR}
./configure CC=cc --prefix=${TRAVIS_ROOT} M4=${TRAVIS_ROOT}/bin/m4 && make -j ${MAKE_JNUM} && make install
if [ "x$?" != "x0" ] ; then
echo FAILURE 3
exit
fi
fi

cd ${TRAVIS_ROOT}
TOOL=automake
TDIR=${TOOL}-${AUTOMAKE_VERSION}
FILE=${TDIR}.tar.gz
BIN=${TRAVIS_ROOT}/bin/${TOOL}
if [ ! -f ${FILE} ] ; then
wget http://ftp.gnu.org/gnu/${TOOL}/${FILE}
else
echo ${FILE} already exists! Using existing copy.
fi
if [ ! -d ${TDIR} ] ; then
echo Unpacking ${FILE}
tar -xzf ${FILE}
else
echo ${TDIR} already exists! Using existing copy.
fi
if [ -f ${BIN} ] ; then
echo ${BIN} already exists! Skipping build.
else
cd ${TRAVIS_ROOT}/${TDIR}
./configure CC=cc --prefix=${TRAVIS_ROOT} M4=${TRAVIS_ROOT}/bin/m4 && make -j ${MAKE_JNUM} && make install
if [ "x$?" != "x0" ] ; then
echo FAILURE 4
exit
fi
fi
;;
esac

49 changes: 49 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
sudo: false
language: c
os:
- linux
- osx
compiler:
- gcc
- clang
env:
matrix:
- OPA_CFLAGS=-std=c89
- OPA_CFLAGS=-std=c99
- OPA_CFLAGS=-std=c11
- OPA_CFLAGS=-std=gnu89
- OPA_CFLAGS=-std=gnu99
- OPA_CFLAGS=-std=gnu11
matrix:
allow_failures:
- os: linux
compiler: gcc
env: OPA_CFLAGS=-std=c11
- os: linux
compiler: gcc
env: OPA_CFLAGS=-std=gnu11
addons:
apt:
sources:
- ubuntu-toolchain-r-test
# clang-3.8 comes from this
- llvm-toolchain-precise
packages:
- gcc-4.9
- gcc-5
- gcc-6
- clang-3.8
install:
- export WORKING_DIRECTORY=$PWD
- mkdir -p $WORKING_DIRECTORY/deps
- export PATH=$WORKING_DIRECTORY/deps/bin:$PATH
- sh .travis-install-autotools.sh $WORKING_DIRECTORY/deps
before_script:
- ./autogen.sh
script:
- ./configure CFLAGS=$OPA_CFLAGS
- make
- make check
after_failure:
- echo "Sad panda"
- find . -name config.log -exec cat {} ";"
3 changes: 1 addition & 2 deletions COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ Permission is hereby granted to use, reproduce, prepare derivative works, and
to redistribute to others. This software was authored by:

Argonne National Laboratory Group
D. Goodell: (630) 252-6082; FAX: (630) 252-5986; e-mail: [email protected]
D. Buntinas: (630) 252-7928; FAX: (630) 252-5986; e-mail: [email protected]
Mathematics and Computer Science Division
Argonne National Laboratory, Argonne IL 60439
Contact: [email protected]


GOVERNMENT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ derived from work on the MPICH2 project.

Project documentation and bug tracking can be found at:

https://trac.mcs.anl.gov/projects/openpa/
https://trac.mpich.org/projects/openpa/

If you would like to email questions or discuss topics related to OpenPA
you can send mail to [email protected].
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

AC_PREREQ(2.62)

AC_INIT([OpenPA], [1.0.4], [https://trac.mcs.anl.gov/projects/openpa/newticket])
AC_INIT([OpenPA], [1.0.4], [https://trac.mpich.org/projects/openpa/newticket])
dnl Set the directory that contains support scripts such as install-sh and
dnl config.guess. It also contains autoconf macro files.
AC_CONFIG_AUX_DIR(confdb)
Expand Down Expand Up @@ -341,6 +341,7 @@ dnl without AC_TRY_RUN().
OPA_TRY_PRIMITIVE_HEADER([opa_gcc_sicortex.h], [GCC_AND_SICORTEX_ASM], [gcc SiCortex atomics])
fi

OPA_TRY_PRIMITIVE_HEADER([opa_c11_atomics.h], [C11_ATOMICS], [C11 atomics])
OPA_TRY_PRIMITIVE_HEADER([opa_gcc_intrinsics.h], [GCC_INTRINSIC_ATOMICS], [gcc atomic intrinsics])
OPA_TRY_PRIMITIVE_HEADER([opa_nt_intrinsics.h], [NT_INTRINSICS], [Windows NT atomic intrinsics])
OPA_TRY_PRIMITIVE_HEADER([opa_sun_atomic_ops.h], [SUN_ATOMIC_OPS], [Sun atomic operations library])
Expand Down
6 changes: 4 additions & 2 deletions src/opa_primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@
#if defined(OPA_USE_UNSAFE_PRIMITIVES)
/* comes first to permit user overrides in the style of NDEBUG */
#include "primitives/opa_unsafe.h"
#elif defined(OPA_HAVE_GCC_AND_POWERPC_ASM)
#elif defined(OPA_HAVE_C11_ATOMICS)
#include "primitives/opa_c11_atomics.h"
#elif defined(OPA_HAVE_GCC_AND_POWERPC_ASM)
#include "primitives/opa_gcc_ppc.h"
#elif defined(OPA_HAVE_GCC_AND_ARM_ASM)
#elif defined(OPA_HAVE_GCC_AND_ARM_ASM)
#include "primitives/opa_gcc_arm.h"
#elif defined(OPA_HAVE_GCC_X86_32_64)
#include "primitives/opa_gcc_intel_32_64.h"
Expand Down
146 changes: 146 additions & 0 deletions src/primitives/opa_c11_atomics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* (C) 2014 by Argonne National Laboratory, Leadership Computing Facility.
* See COPYRIGHT in top-level directory.
*/

/* FIXME needs to be converted to new style functions with OPA_int_t/OPA_ptr_t-types */
#ifndef OPA_C11_ATOMICS_H_INCLUDED
#define OPA_C11_ATOMICS_H_INCLUDED

#ifdef __STDC_NO_ATOMICS__
#error stdatomic header is not available.
#else
#include <stdatomic.h>
#endif

/* Clang 3.x has a bug in stdatomic.h, wherein there is an extra _T
* in the following macros. It is fixed in Clang 4.x. */
#if !defined(ATOMIC_INT_LOCK_FREE) && !defined(ATOMIC_INT_T_LOCK_FREE)
#error atomic_int is not lock-free.
#else
typedef atomic_int OPA_int_t;
#endif

#if !defined(ATOMIC_POINTER_LOCK_FREE) && !defined(ATOMIC_POINTER_T_LOCK_FREE)
#error atomic_pointer is not lock-free.
#else
/* TODO Is this really the right type to use here? */
#include <stdint.h>
typedef atomic_intptr_t OPA_ptr_t;
#endif

#define OPA_INT_T_INITIALIZER(val_) ATOMIC_VAR_INIT(val_)
#define OPA_PTR_T_INITIALIZER(val_) ATOMIC_VAR_INIT(val_)

static _opa_inline int OPA_load_int(OPA_int_t *ptr)
{
return atomic_load_explicit(ptr, memory_order_relaxed);
}

static _opa_inline void OPA_store_int(OPA_int_t *ptr, int val)
{
atomic_store_explicit(ptr, val, memory_order_relaxed);
}

static _opa_inline void *OPA_load_ptr(OPA_ptr_t *ptr)
{
return (void*)atomic_load_explicit(ptr, memory_order_relaxed);
}

static _opa_inline void OPA_store_ptr(OPA_ptr_t *ptr, void *val)
{
atomic_store_explicit(ptr, (intptr_t)val, memory_order_relaxed);
}

static _opa_inline int OPA_load_acquire_int(OPA_int_t *ptr)
{
return atomic_load_explicit(ptr, memory_order_acquire);
}

static _opa_inline void OPA_store_release_int(OPA_int_t *ptr, int val)
{
atomic_store_explicit(ptr, val, memory_order_release);
}

static _opa_inline void *OPA_load_acquire_ptr(OPA_ptr_t *ptr)
{
return (void*)atomic_load_explicit(ptr, memory_order_acquire);
}

static _opa_inline void OPA_store_release_ptr(OPA_ptr_t *ptr, void *val)
{
atomic_store_explicit(ptr, (intptr_t)val, memory_order_release);
}

static _opa_inline void OPA_add_int(OPA_int_t *ptr, int val)
{
atomic_fetch_add_explicit(ptr, val, memory_order_relaxed);
}

static _opa_inline int OPA_fetch_and_add_int(OPA_int_t *ptr, int val)
{
return atomic_fetch_add_explicit(ptr, val, memory_order_relaxed);
}

static _opa_inline int OPA_fetch_and_decr_int(OPA_int_t *ptr)
{
return atomic_fetch_add_explicit(ptr, -1, memory_order_relaxed);
}

static _opa_inline int OPA_fetch_and_incr_int(OPA_int_t *ptr)
{
return atomic_fetch_add_explicit(ptr, 1, memory_order_relaxed);
}

static _opa_inline void OPA_incr_int(OPA_int_t *ptr)
{
atomic_fetch_add_explicit(ptr, 1, memory_order_relaxed);
}

static _opa_inline void OPA_decr_int(OPA_int_t *ptr)
{
atomic_fetch_add_explicit(ptr, -1, memory_order_relaxed);
}

static _opa_inline int OPA_decr_and_test_int(OPA_int_t *ptr)
{
return (1 == atomic_fetch_add_explicit(ptr, -1, memory_order_relaxed));
}

/* Dave Goodell says weak is fine. OpenPA does not expect strong. */

#include <stdbool.h>

static _opa_inline void *OPA_cas_ptr(OPA_ptr_t *ptr, void *comparand, void *swaperand)
{
atomic_compare_exchange_strong_explicit(ptr, (intptr_t*)&comparand, (intptr_t)swaperand, memory_order_relaxed, memory_order_relaxed);
return comparand;
}

static _opa_inline int OPA_cas_int(OPA_int_t *ptr, int comparand, int swaperand)
{
atomic_compare_exchange_strong_explicit(ptr, &comparand, swaperand, memory_order_relaxed, memory_order_relaxed);
return comparand;
}

static _opa_inline void *OPA_swap_ptr(OPA_ptr_t *ptr, void *val)
{
return (void*)atomic_exchange_explicit(ptr, (intptr_t)val, memory_order_relaxed);
}

static _opa_inline int OPA_swap_int(OPA_int_t *ptr, int val)
{
return atomic_exchange_explicit(ptr, val, memory_order_relaxed);
}

/* Dave says that read/write don't match acq/rel perfectly so we use heavy hammer. */
#define OPA_write_barrier() atomic_thread_fence(memory_order_acq_rel);
#define OPA_read_barrier() atomic_thread_fence(memory_order_acq_rel);
#define OPA_read_write_barrier() atomic_thread_fence(memory_order_acq_rel);
/* FYI: According to C11 7.17.4.2 NOTE 2, atomic_signal_fence acts as
* a compiler barrier. Note sure how memory_order affects this. */
#define OPA_compiler_barrier() atomic_signal_fence(memory_order_acq_rel);

#endif /* OPA_C11_ATOMICS_H_INCLUDED */
Loading