mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Add a basic atomic ops API abstracting away platform/architecture details.
Several upcoming performance/scalability improvements require atomic operations. This new API avoids the need to splatter compiler and architecture dependent code over all the locations employing atomic ops. For several of the potential usages it'd be problematic to maintain both, a atomics using implementation and one using spinlocks or similar. In all likelihood one of the implementations would not get tested regularly under concurrency. To avoid that scenario the new API provides a automatic fallback of atomic operations to spinlocks. All properties of atomic operations are maintained. This fallback - obviously - isn't as fast as just using atomic ops, but it's not bad either. For one of the future users the atomics ontop spinlocks implementation was actually slightly faster than the old purely spinlock using implementation. That's important because it reduces the fear of regressing older platforms when improving the scalability for new ones. The API, loosely modeled after the C11 atomics support, currently provides 'atomic flags' and 32 bit unsigned integers. If the platform efficiently supports atomic 64 bit unsigned integers those are also provided. To implement atomics support for a platform/architecture/compiler for a type of atomics 32bit compare and exchange needs to be implemented. If available and more efficient native support for flags, 32 bit atomic addition, and corresponding 64 bit operations may also be provided. Additional useful atomic operations are implemented generically ontop of these. The implementation for various versions of gcc, msvc and sun studio have been tested. Additional existing stub implementations for * Intel icc * HUPX acc * IBM xlc are included but have never been tested. These will likely require fixes based on buildfarm and user feedback. As atomic operations also require barriers for some operations the existing barrier support has been moved into the atomics code. Author: Andres Freund with contributions from Oskari Saarenmaa Reviewed-By: Amit Kapila, Robert Haas, Heikki Linnakangas and Álvaro Herrera Discussion: CA+TgmoYBW+ux5-8Ja=Mcyuy8=VXAnVRHp3Kess6Pn3DMXAPAEA@mail.gmail.com, 20131015123303.GH5300@awork2.anarazel.de, 20131028205522.GI20248@awork2.anarazel.de
This commit is contained in:
@@ -309,7 +309,7 @@ tas(volatile slock_t *lock)
|
||||
* than other widths.
|
||||
*/
|
||||
#if defined(__arm__) || defined(__arm) || defined(__aarch64__) || defined(__aarch64)
|
||||
#ifdef HAVE_GCC_INT_ATOMICS
|
||||
#ifdef HAVE_GCC__SYNC_INT32_TAS
|
||||
#define HAS_TEST_AND_SET
|
||||
|
||||
#define TAS(lock) tas(lock)
|
||||
@@ -324,7 +324,7 @@ tas(volatile slock_t *lock)
|
||||
|
||||
#define S_UNLOCK(lock) __sync_lock_release(lock)
|
||||
|
||||
#endif /* HAVE_GCC_INT_ATOMICS */
|
||||
#endif /* HAVE_GCC__SYNC_INT32_TAS */
|
||||
#endif /* __arm__ || __arm || __aarch64__ || __aarch64 */
|
||||
|
||||
|
||||
@@ -889,12 +889,12 @@ typedef int slock_t;
|
||||
|
||||
extern bool s_lock_free_sema(volatile slock_t *lock);
|
||||
extern void s_unlock_sema(volatile slock_t *lock);
|
||||
extern void s_init_lock_sema(volatile slock_t *lock);
|
||||
extern void s_init_lock_sema(volatile slock_t *lock, bool nested);
|
||||
extern int tas_sema(volatile slock_t *lock);
|
||||
|
||||
#define S_LOCK_FREE(lock) s_lock_free_sema(lock)
|
||||
#define S_UNLOCK(lock) s_unlock_sema(lock)
|
||||
#define S_INIT_LOCK(lock) s_init_lock_sema(lock)
|
||||
#define S_INIT_LOCK(lock) s_init_lock_sema(lock, false)
|
||||
#define TAS(lock) tas_sema(lock)
|
||||
|
||||
|
||||
@@ -955,6 +955,7 @@ extern int tas(volatile slock_t *lock); /* in port/.../tas.s, or
|
||||
#define TAS_SPIN(lock) TAS(lock)
|
||||
#endif /* TAS_SPIN */
|
||||
|
||||
extern slock_t dummy_spinlock;
|
||||
|
||||
/*
|
||||
* Platform-independent out-of-line support routines
|
||||
|
Reference in New Issue
Block a user