Welcome! Log In Create A New Profile

Advanced

[PATCH] Configure: Prefer gcc __atomic builtins instead of older __sync builtins

Debayan Ghosh
December 03, 2017 10:44AM
# HG changeset patch
# User Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
# Date 1511884462 -19800
# Tue Nov 28 21:24:22 2017 +0530
# Node ID 4576e7c90ed42da3af67d90f624b34dd9285a658
# Parent fc0d06224edac2c7cfbfd9a4def478f285d9957b
Configure: Prefer gcc __atomic builtins instead of older __sync builtins

It is desirable to use the newer GCC __atomic builtins when using later
versions of GCC , compared to the legacy __sync atomic builtins.
Ref: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

diff -r fc0d06224eda -r 4576e7c90ed4 auto/cc/conf
--- a/auto/cc/conf Tue Nov 28 13:09:54 2017 +0300
+++ b/auto/cc/conf Tue Nov 28 21:24:22 2017 +0530
@@ -181,12 +181,28 @@
if [ "$NGX_CC_NAME" = "sunc" ]; then
echo "checking for gcc builtin atomic operations ... disabled"
else
- ngx_feature="gcc builtin atomic operations"
+ ngx_feature="gcc builtin new atomic operations"
ngx_feature_name=NGX_HAVE_GCC_ATOMIC
ngx_feature_run=yes
ngx_feature_incs=
ngx_feature_path=
ngx_feature_libs=
+ ngx_feature_test="long n = 0, m = 0;
+ if (!__atomic_compare_exchange_n(&n, &m, 1, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
+ return 1;
+ if (__atomic_fetch_add(&n, 1, __ATOMIC_SEQ_CST) != 1)
+ return 1;
+ if (n != 2)
+ return 1;
+ __atomic_thread_fence(__ATOMIC_ACQUIRE);"
+ . auto/feature
+
+ ngx_feature="gcc builtin sync atomic operations"
+ ngx_feature_name=NGX_HAVE_GCC_SYNC_ATOMIC
+ ngx_feature_run=yes
+ ngx_feature_incs=
+ ngx_feature_path=
+ ngx_feature_libs=
ngx_feature_test="long n = 0;
if (!__sync_bool_compare_and_swap(&n, 0, 1))
return 1;
diff -r fc0d06224eda -r 4576e7c90ed4 src/os/unix/ngx_atomic.h
--- a/src/os/unix/ngx_atomic.h Tue Nov 28 13:09:54 2017 +0300
+++ b/src/os/unix/ngx_atomic.h Tue Nov 28 21:24:22 2017 +0530
@@ -88,9 +88,8 @@
typedef volatile ngx_atomic_uint_t ngx_atomic_t;


-#elif (NGX_HAVE_GCC_ATOMIC)
+#elif (NGX_HAVE_GCC_ATOMIC || NGX_HAVE_GCC_SYNC_ATOMIC)

-/* GCC 4.1 builtin atomic operations */

#define NGX_HAVE_ATOMIC_OPS 1

@@ -105,7 +104,24 @@

typedef volatile ngx_atomic_uint_t ngx_atomic_t;

+#if (NGX_HAVE_GCC_ATOMIC)
+/* Use GCC 5.4 builtin atomic operations */
+static inline ngx_atomic_uint_t
+ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
+ ngx_atomic_uint_t set) {
+ return __atomic_compare_exchange_n(lock, &old, set, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+}

+static inline ngx_atomic_int_t
+ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) {
+ return __atomic_fetch_add(value, add, __ATOMIC_SEQ_CST);
+}
+
+#define ngx_memory_barrier() __atomic_thread_fence(__ATOMIC_ACQUIRE)
+
+#else
+/* Use older gcc sync atomic builtin operations */
#define ngx_atomic_cmp_set(lock, old, set) \
__sync_bool_compare_and_swap(lock, old, set)

@@ -113,6 +129,8 @@
__sync_fetch_and_add(value, add)

#define ngx_memory_barrier() __sync_synchronize()
+#endif
+

#if ( __i386__ || __i386 || __amd64__ || __amd64 )
#define ngx_cpu_pause() __asm__ ("pause")
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Configure: Prefer gcc __atomic builtins instead of older __sync builtins

Debayan Ghosh 753 December 03, 2017 10:44AM

Re: [PATCH] Configure: Prefer gcc __atomic builtins instead of older __sync builtins

Maxim Dounin 217 December 04, 2017 10:06AM

RE: [PATCH] Configure: Prefer gcc __atomic builtins instead of older __sync builtins

debayang.qdt 248 December 04, 2017 11:40AM

Re: [PATCH] Configure: Prefer gcc __atomic builtins instead of older __sync builtins

Maxim Dounin 290 December 04, 2017 04:10PM

RE: [PATCH] Configure: Prefer gcc __atomic builtins instead of older __sync builtins

debayang.qdt 257 December 10, 2017 10:00AM

Re: [PATCH] Configure: Prefer gcc __atomic builtins instead of older __sync builtins

Maxim Dounin 396 December 11, 2017 08:44AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 205
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready