Atomic operations for fast SMP synchronization. More...
Classes | |
| struct | PLMD::thread_mpi::tMPI_Atomic |
| Atomic operations datatype. More... | |
| struct | PLMD::thread_mpi::tMPI_Atomic_ptr |
| Atomic pointer type equivalent to tMPI_Atomic_t. More... | |
Namespaces | |
| namespace | PLMD |
| Fast (possibly busy-wait-based) barrier type. | |
| namespace | PLMD::thread_mpi |
Macros | |
| #define | TMPI_ATOMIC_HAVE_NATIVE_ADD_RETURN |
| #define | TMPI_ATOMIC_HAVE_NATIVE_FETCH_ADD |
| #define | TMPI_ATOMIC_HAVE_NATIVE_SPINLOCK |
| #define | TMPI_ATOMIC_HAVE_NATIVE_SWAP |
| #define | tMPI_Atomic_memory_barrier() |
| Memory barrier operation. | |
| #define | tMPI_Atomic_memory_barrier_acq() |
| Memory barrier operation with acquire semantics. | |
| #define | tMPI_Atomic_memory_barrier_rel() |
| Memory barrier operation with release semantics. | |
| #define | TMPI_HAVE_ACQ_REL_BARRIERS |
| #define | TMPI_NO_ATOMICS |
| Indicates that no support for atomic operations is present. | |
| #define | TMPI_SPINLOCK_INITIALIZER |
| Spinlock static initializer. | |
Typedefs | |
| typedef struct PLMD::thread_mpi::tMPI_Atomic_ptr | PLMD::thread_mpi::tMPI_Atomic_ptr_t |
| Atomic pointer type equivalent to tMPI_Atomic_t. | |
| typedef struct PLMD::thread_mpi::tMPI_Atomic | PLMD::thread_mpi::tMPI_Atomic_t |
| Atomic operations datatype. | |
| typedef struct tMPI_Spinlock * | PLMD::thread_mpi::tMPI_Spinlock_t |
| Spinlock. | |
Atomic operations for fast SMP synchronization.
This file defines atomic integer operations and spinlocks for fast synchronization in performance-critical regions.
In general, the best option is to use functions without explicit locking, e.g. tMPI_Atomic_fetch_add() or tMPI_Atomic_cas().
Depending on the architecture/compiler, these operations may either be provided as functions or macros; be aware that those macros may reference their arguments repeatedly, possibly leading to multiply evaluated code with side effects: be careful with what you use as arguments.
Not all architectures support atomic operations though inline assembly, and even if they do it might not be implemented here. In that case we use a fallback mutex implementation, so you can always count on the function interfaces working.
Don't use spinlocks in non-performance-critical regions like file I/O. Since they always spin busy they would waste CPU cycles instead of properly yielding to a computation thread while waiting for the disk.
Finally, note that all our spinlock operations are defined to return 0 if initialization or locking completes successfully. This is the opposite of some other implementations, but the same standard as used for pthread mutexes. So, if e.g. are trying to lock a spinlock, you will have gotten the lock if the return value is 0.
tMPI_Spinlock_islocked(x) obviously still returns 1 if the lock is locked, and 0 if it is available, though...
| #define TMPI_ATOMIC_HAVE_NATIVE_ADD_RETURN |
| #define TMPI_ATOMIC_HAVE_NATIVE_FETCH_ADD |
| #define TMPI_ATOMIC_HAVE_NATIVE_SPINLOCK |
| #define TMPI_ATOMIC_HAVE_NATIVE_SWAP |
| #define tMPI_Atomic_memory_barrier | ( | ) |
Memory barrier operation.
Modern CPUs rely heavily on out-of-order execution, and one common feature is that load/stores might be reordered. Also, when using inline assembly the compiler might already have loaded the variable we are changing into a register, so any update to memory won't be visible.
This command creates a memory barrier, i.e. all memory results before it in the code should be visible to all memory operations after it - the CPU cannot propagate load/stores across it.
This barrier is a full barrier: all load and store operations of instructions before it are completed, while all load and store operations that are in instructions after it won't be done before this barrier.
| #define tMPI_Atomic_memory_barrier_acq | ( | ) |
Memory barrier operation with acquire semantics.
This barrier is a barrier with acquire semantics: the terminology comes from its common use after acquiring a lock: all load/store instructions after this barrier may not be re-ordered to happen before this barrier.
| #define tMPI_Atomic_memory_barrier_rel | ( | ) |
Memory barrier operation with release semantics.
This barrier is a barrier with release semantics: the terminology comes from its common use before releasing a lock: all load/store instructions before this barrier may not be re-ordered to happen after this barrier.
| #define TMPI_HAVE_ACQ_REL_BARRIERS |
| #define TMPI_NO_ATOMICS |
Indicates that no support for atomic operations is present.
| #define TMPI_SPINLOCK_INITIALIZER |
Spinlock static initializer.
This is used for static spinlock initialization, and has the same properties as TMPI_THREAD_MUTEX_INITIALIZER has for mutexes. This is only for inlining in the tMPI_Thread.h header file. Whether it is 0, 1, or something else when unlocked depends on the platform. Don't assume anything about it. It might even be a mutex when using the fallback implementation!
Hosted by GitHub
|
1.13.2
|