Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb64d92f

Browse files
committed
Add a basic atomic ops API abstracting away platform/architecture details.
Several upcoming performance/scalability improvements require atomicoperations. This new API avoids the need to splatter compiler andarchitecture dependent code over all the locations employing atomicops.For several of the potential usages it'd be problematic to maintainboth, a atomics using implementation and one using spinlocks orsimilar. In all likelihood one of the implementations would not gettested regularly under concurrency. To avoid that scenario the new APIprovides a automatic fallback of atomic operations to spinlocks. Allproperties of atomic operations are maintained. This fallback -obviously - isn't as fast as just using atomic ops, but it's not badeither. For one of the future users the atomics ontop spinlocksimplementation was actually slightly faster than the old purelyspinlock using implementation. That's important because it reduces thefear of regressing older platforms when improving the scalability fornew ones.The API, loosely modeled after the C11 atomics support, currentlyprovides 'atomic flags' and 32 bit unsigned integers. If the platformefficiently supports atomic 64 bit unsigned integers those are alsoprovided.To implement atomics support for a platform/architecture/compiler fora type of atomics 32bit compare and exchange needs to beimplemented. If available and more efficient native support for flags,32 bit atomic addition, and corresponding 64 bit operations may alsobe provided. Additional useful atomic operations are implementedgenerically ontop of these.The implementation for various versions of gcc, msvc and sun studio havebeen tested. Additional existing stub implementations for* Intel icc* HUPX acc* IBM xlcare included but have never been tested. These will likely requirefixes based on buildfarm and user feedback.As atomic operations also require barriers for some operations theexisting barrier support has been moved into the atomics code.Author: Andres Freund with contributions from Oskari SaarenmaaReviewed-By: Amit Kapila, Robert Haas, Heikki Linnakangas and Álvaro HerreraDiscussion: CA+TgmoYBW+ux5-8Ja=Mcyuy8=VXAnVRHp3Kess6Pn3DMXAPAEA@mail.gmail.com, 20131015123303.GH5300@awork2.anarazel.de, 20131028205522.GI20248@awork2.anarazel.de
1 parent9111d46 commitb64d92f

31 files changed

+2816
-208
lines changed

‎config/c-compiler.m4

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,101 @@ if test x"$Ac_cachevar" = x"yes"; then
300300
fi
301301
undefine([Ac_cachevar])dnl
302302
])# PGAC_PROG_CC_LDFLAGS_OPT
303+
304+
# PGAC_HAVE_GCC__SYNC_CHAR_TAS
305+
# -------------------------
306+
# Check if the C compiler understands __sync_lock_test_and_set(char),
307+
# and define HAVE_GCC__SYNC_CHAR_TAS
308+
#
309+
# NB: There are platforms where test_and_set is available but compare_and_swap
310+
# is not, so test this separately.
311+
# NB: Some platforms only do 32bit tas, others only do 8bit tas. Test both.
312+
AC_DEFUN([PGAC_HAVE_GCC__SYNC_CHAR_TAS],
313+
[AC_CACHE_CHECK(forbuiltin__synccharlockingfunctions,pgac_cv_gcc_sync_char_tas,
314+
[AC_TRY_LINK([],
315+
[char lock = 0;
316+
__sync_lock_test_and_set(&lock, 1);
317+
__sync_lock_release(&lock);],
318+
[pgac_cv_gcc_sync_char_tas="yes"],
319+
[pgac_cv_gcc_sync_char_tas="no"])])
320+
if test x"$pgac_cv_gcc_sync_char_tas" = x"yes"; then
321+
AC_DEFINE(HAVE_GCC__SYNC_CHAR_TAS,1,[Define to 1 if you have __sync_lock_test_and_set(char *) and friends.])
322+
fi])# PGAC_HAVE_GCC__SYNC_CHAR_TAS
323+
324+
# PGAC_HAVE_GCC__SYNC_INT32_TAS
325+
# -------------------------
326+
# Check if the C compiler understands __sync_lock_test_and_set(),
327+
# and define HAVE_GCC__SYNC_INT32_TAS
328+
AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_TAS],
329+
[AC_CACHE_CHECK(forbuiltin__syncint32lockingfunctions,pgac_cv_gcc_sync_int32_tas,
330+
[AC_TRY_LINK([],
331+
[int lock = 0;
332+
__sync_lock_test_and_set(&lock, 1);
333+
__sync_lock_release(&lock);],
334+
[pgac_cv_gcc_sync_int32_tas="yes"],
335+
[pgac_cv_gcc_sync_int32_tas="no"])])
336+
if test x"$pgac_cv_gcc_sync_int32_tas" = x"yes"; then
337+
AC_DEFINE(HAVE_GCC__SYNC_INT32_TAS,1,[Define to 1 if you have __sync_lock_test_and_set(int *) and friends.])
338+
fi])# PGAC_HAVE_GCC__SYNC_INT32_TAS
339+
340+
# PGAC_HAVE_GCC__SYNC_INT32_CAS
341+
# -------------------------
342+
# Check if the C compiler understands __sync_compare_and_swap() for 32bit
343+
# types, and define HAVE_GCC__SYNC_INT32_CAS if so.
344+
AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_CAS],
345+
[AC_CACHE_CHECK(forbuiltin__syncint32atomicoperations,pgac_cv_gcc_sync_int32_cas,
346+
[AC_TRY_LINK([],
347+
[int val = 0;
348+
__sync_val_compare_and_swap(&val, 0, 37);],
349+
[pgac_cv_gcc_sync_int32_cas="yes"],
350+
[pgac_cv_gcc_sync_int32_cas="no"])])
351+
if test x"$pgac_cv_gcc_sync_int32_cas" = x"yes"; then
352+
AC_DEFINE(HAVE_GCC__SYNC_INT32_CAS,1,[Define to 1 if you have __sync_compare_and_swap(int *, int, int).])
353+
fi])# PGAC_HAVE_GCC__SYNC_INT32_CAS
354+
355+
# PGAC_HAVE_GCC__SYNC_INT64_CAS
356+
# -------------------------
357+
# Check if the C compiler understands __sync_compare_and_swap() for 64bit
358+
# types, and define HAVE_GCC__SYNC_INT64_CAS if so.
359+
AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT64_CAS],
360+
[AC_CACHE_CHECK(forbuiltin__syncint64atomicoperations,pgac_cv_gcc_sync_int64_cas,
361+
[AC_TRY_LINK([],
362+
[PG_INT64_TYPE lock = 0;
363+
__sync_val_compare_and_swap(&lock, 0, (PG_INT64_TYPE) 37);],
364+
[pgac_cv_gcc_sync_int64_cas="yes"],
365+
[pgac_cv_gcc_sync_int64_cas="no"])])
366+
if test x"$pgac_cv_gcc_sync_int64_cas" = x"yes"; then
367+
AC_DEFINE(HAVE_GCC__SYNC_INT64_CAS,1,[Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64).])
368+
fi])# PGAC_HAVE_GCC__SYNC_INT64_CAS
369+
370+
# PGAC_HAVE_GCC__ATOMIC_INT32_CAS
371+
# -------------------------
372+
# Check if the C compiler understands __atomic_compare_exchange_n() for 32bit
373+
# types, and define HAVE_GCC__ATOMIC_INT32_CAS if so.
374+
AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT32_CAS],
375+
[AC_CACHE_CHECK(forbuiltin__atomicint32atomicoperations,pgac_cv_gcc_atomic_int32_cas,
376+
[AC_TRY_LINK([],
377+
[int val = 0;
378+
int expect = 0;
379+
__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);],
380+
[pgac_cv_gcc_atomic_int32_cas="yes"],
381+
[pgac_cv_gcc_atomic_int32_cas="no"])])
382+
if test x"$pgac_cv_gcc_atomic_int32_cas" = x"yes"; then
383+
AC_DEFINE(HAVE_GCC__ATOMIC_INT32_CAS,1,[Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int).])
384+
fi])# PGAC_HAVE_GCC__ATOMIC_INT32_CAS
385+
386+
# PGAC_HAVE_GCC__ATOMIC_INT64_CAS
387+
# -------------------------
388+
# Check if the C compiler understands __atomic_compare_exchange_n() for 64bit
389+
# types, and define HAVE_GCC__ATOMIC_INT64_CAS if so.
390+
AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT64_CAS],
391+
[AC_CACHE_CHECK(forbuiltin__atomicint64atomicoperations,pgac_cv_gcc_atomic_int64_cas,
392+
[AC_TRY_LINK([],
393+
[PG_INT64_TYPE val = 0;
394+
PG_INT64_TYPE expect = 0;
395+
__atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);],
396+
[pgac_cv_gcc_atomic_int64_cas="yes"],
397+
[pgac_cv_gcc_atomic_int64_cas="no"])])
398+
if test x"$pgac_cv_gcc_atomic_int64_cas" = x"yes"; then
399+
AC_DEFINE(HAVE_GCC__ATOMIC_INT64_CAS,1,[Define to 1 if you have __atomic_compare_exchange_n(int64 *, int *, int64).])
400+
fi])# PGAC_HAVE_GCC__ATOMIC_INT64_CAS

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp