Documentation ¶
Index ¶
- Constants
- func HLESpinCountLock(val, attempts *int32)
- func HLESpinLock(val *int32)
- func HLETryLock(val *int32) int32
- func HLEUnlock(val *int32)
- func Lock1XCHG32(val *int32) (old int32)
- func Lock1XCHG64(val *int64) (old int64)
- func Lock1XCHG8(val *int8) (old int8)
- func Mfence()
- func Pause()
- func SetAndFence32(val *int32)
- func SpinCountLock(val, attempts *int32)
- func SpinLock(val *int32)
- func SpinLockAtomics(val *int32)
- type AtomicContext
- type LockedContext
- type RTMContext
- type SpinHLEMutex
- type SpinMutex
- type SpinMutexASM
- type SpinMutexBasic
Constants ¶
const LockAttempts = int32(200)
LockAttempts sets how many times the spin loop is willing to try to fetching the lock.
Variables ¶
This section is empty.
Functions ¶
func HLESpinCountLock ¶
func HLESpinCountLock(val, attempts *int32)
HLESpinCountLock tries to set val to 1 at most attempts times using Intel HLE. It is implemented as a spin lock that decrements attempts for each attempt. The spin operation makes use of the PAUSE and XACQUIRE LOCK XCHG instructions. If attempts is 0 when the function returns, the lock was not acquired and the spin lock gave up. Please note that attempts must be greater 0 when called.
func HLESpinLock ¶
func HLESpinLock(val *int32)
HLESpinLock repeatedly tries to set val to 1 using Intel HLE and XCHG. It is implemented as a spin lock that makes use of the PAUSE and LOCK XCHG instructions. Please note that this function will never return unless the lock is acquired. This means a deadlock will occur if the holder of the lock is descheduled by the goruntime. Please use HLESpinCountLock to limit the spins and manually invoke runtime.Gosched periodically, insted.
func HLETryLock ¶
HLETryLock attempts only once to acquire the lock by writing a 1 to val using HLE primitives. This function returns a 0 if the lock was acquired.
func HLEUnlock ¶
func HLEUnlock(val *int32)
HLEUnlock writes a 0 to val to indicate the lock has been released using HLE primitives
func Lock1XCHG32 ¶
Lock1XCHG32 will atomically write 1 to val while returning the old value. The size of val must be 32 bits.
func Lock1XCHG64 ¶
Lock1XCHG64 will atomically write 1 to val while returning the old value. The size of val must be 64 bits.
func Lock1XCHG8 ¶
Lock1XCHG8 will atomically write 1 to val while returning the old value. The size of val must be 8 bits.
func SetAndFence32 ¶
func SetAndFence32(val *int32)
SetAndFence32 writes a 1 to val and asserts an MFENCE.
func SpinCountLock ¶
func SpinCountLock(val, attempts *int32)
SpinCountLock implements a basic spin lock that tries to acquire the lock only attempts times. It assumes the lock has been acquired when it successfully writes a 1 to val, while the original value was 0. This implementation spins on a read only and then uses the XCHG instruction in order to claim the lock. The loop makes use of the PAUSE hint instruction.
func SpinLock ¶
func SpinLock(val *int32)
SpinLock implements a basic spin lock that waits forever until the lock can be acquired. It assumes the lock has been acquired when it successfully writes a 1 to val, while the original value was 0. This implementation spins on a read only and then uses the XCHG instruction in order to claim the lock. The loop makes use of the PAUSE hint instruction.
func SpinLockAtomics ¶
func SpinLockAtomics(val *int32)
SpinLockAtomics implements a very basic spin forever style lock that uses the built in atomics.SwapInt32 function in order to claim the lock.
Types ¶
type AtomicContext ¶
type AtomicContext interface { // Atomic will execute commiter exactly once per call in a manor that // appears to be atomic with respect to other commiters launched from this // AtomicContext. Atomic(commiter func()) }
AtomicContext is the interface provided by a synchronization primitive that is capable of running a functions in an atomic context.
type LockedContext ¶
type LockedContext struct {
// contains filtered or unexported fields
}
LockedContext provides an AtomicContext that utilizes any sync.Locker.
func NewLockedContext ¶
func NewLockedContext(lock sync.Locker) *LockedContext
NewLockedContext creates a LockedContext that uses lock as the sync method.
func (*LockedContext) Atomic ¶
func (c *LockedContext) Atomic(commiter func())
Atomic executes commiter atomically with respect to other commiters launched from this context.
type RTMContext ¶
type RTMContext struct {
// contains filtered or unexported fields
}
RTMContext holds the shared state for the fallback path if the RTM transaction fails
func NewRTMContex ¶
func NewRTMContex(l sync.Locker) *RTMContext
NewRTMContex creates an AtomicContext that tries to use Intel RTM, but can fallback to using the provided sync.Locker.
func NewRTMContexDefault ¶
func NewRTMContexDefault() *RTMContext
NewRTMContexDefault creates an AtomicContext that tries to use Intel RTM, but can fallback to using the native sync.Mutex.
func (*RTMContext) Atomic ¶
func (r *RTMContext) Atomic(commiter func())
Atomic executes the commiter in an atomic fasion.
func (*RTMContext) CapacityAborts ¶
func (r *RTMContext) CapacityAborts() uint64
CapacityAborts returns the number of aborts that were due to cache capacity. If you see lots of capacity aborts, this means the commiter function if touching too many memory locations and is unlikely to be reaping any gains from using an RTMContext.
type SpinHLEMutex ¶
type SpinHLEMutex int32
SpinHLEMutex is sync.Mutex replacement that uses HLE
func (*SpinHLEMutex) Lock ¶
func (m *SpinHLEMutex) Lock()
func (*SpinHLEMutex) Unlock ¶
func (m *SpinHLEMutex) Unlock()
type SpinMutexASM ¶
type SpinMutexASM int32
func (*SpinMutexASM) Lock ¶
func (m *SpinMutexASM) Lock()
func (*SpinMutexASM) Unlock ¶
func (m *SpinMutexASM) Unlock()
type SpinMutexBasic ¶
type SpinMutexBasic struct {
// contains filtered or unexported fields
}
func (*SpinMutexBasic) Lock ¶
func (m *SpinMutexBasic) Lock()
func (*SpinMutexBasic) Unlock ¶
func (m *SpinMutexBasic) Unlock()
Directories ¶
Path | Synopsis |
---|---|
This is a contrived benchmark that caters to transactional memory primitives.
|
This is a contrived benchmark that caters to transactional memory primitives. |
This simple program prints the name of the cpu and if it supports Intel RTM and HLE.
|
This simple program prints the name of the cpu and if it supports Intel RTM and HLE. |