@cryptotaxi247 / netdata-1 / commits / b8d71e9d9

detect compiler atomic instructions using autoconf

Costa Tsaousis (ktsaou) committed Sep 27, 2016 at 12:47 UTC b8d71e9d940e24ba8f0b2f92dffe6e94d7885872
3 files changed +39 -10
configure.ac
+34 -1
@@ -82,6 +82,7 @@ AC_TYPE_UINT8_T
82 AC_TYPE_UINT16_T
83 AC_TYPE_UINT32_T
84 AC_C_INLINE
85 +AC_FUNC_STRERROR_R
86
87 # https://lists.gnu.org/archive/html/autoconf-commit/2012-12/msg00004.html
88 # AC_C__GENERIC
@@ -112,7 +113,39 @@ fi
113 ])# AC_C__GENERIC
114
115 AC_C__GENERIC
115 -AC_FUNC_STRERROR_R
116 +
117 +# AC_C___ATOMIC
118 +# -------------
119 +# Define HAVE_C___ATOMIC if __atomic works.
120 +AN_IDENTIFIER([__atomic], [AC_C___ATOMIC])
121 +AC_DEFUN([AC_C___ATOMIC],
122 +[AC_CACHE_CHECK([for __atomic], ac_cv_c___atomic,
123 +[AC_COMPILE_IFELSE(
124 + [AC_LANG_SOURCE(
125 + [[int
126 + main (int argc, char **argv)
127 + {
128 + volatile unsigned long ul1 = 1, ul2 = 0, ul3 = 2;
129 + __atomic_compare_exchange(&ul1, &ul2, &ul3, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
130 + __atomic_fetch_add(&ul1, 1, __ATOMIC_SEQ_CST);
131 + __atomic_fetch_sub(&ul3, 1, __ATOMIC_SEQ_CST);
132 + volatile unsigned long long ull1 = 1, ull2 = 0, ull3 = 2;
133 + __atomic_compare_exchange(&ull1, &ull2, &ull3, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
134 + __atomic_fetch_add(&ull1, 1, __ATOMIC_SEQ_CST);
135 + __atomic_fetch_sub(&ull3, 1, __ATOMIC_SEQ_CST);
136 + return 0;
137 + }
138 + ]])],
139 + [ac_cv_c___atomic=yes],
140 + [ac_cv_c___atomic=no])])
141 +if test $ac_cv_c___atomic = yes; then
142 + AC_DEFINE([HAVE_C___ATOMIC], 1,
143 + [Define to 1 if __atomic operations work.])
144 +fi
145 +])# AC_C___ATOMIC
146 +
147 +AC_C___ATOMIC
148 +
149
150 AC_ARG_VAR([MATH_CFLAGS], [C compiler flags for math])
151 AC_ARG_VAR([MATH_LIBS], [linker flags for math])
src/common.h
-4
@@ -60,10 +60,6 @@
60 #include <zlib.h>
61 #endif
62
63 -#ifndef __ATOMIC_SEQ_CST
64 -#define NETDATA_NO_ATOMIC_INSTRUCTIONS 1
65 -#endif
66 -
63 #ifdef __GNUC__
64 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
65
src/global_statistics.c
+5 -5
@@ -25,7 +25,7 @@ void finished_web_request_statistics(uint64_t dt,
25 uint64_t bytes_sent,
26 uint64_t content_size,
27 uint64_t compressed_content_size) {
28 -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS
28 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
29 uint64_t old_web_usec_max = global_statistics.web_usec_max;
30 while(dt > old_web_usec_max)
31 __atomic_compare_exchange(&global_statistics.web_usec_max, &old_web_usec_max, &dt, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
@@ -57,7 +57,7 @@ void finished_web_request_statistics(uint64_t dt,
57 }
58
59 void web_client_connected(void) {
60 -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS
60 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
61 __atomic_fetch_add(&global_statistics.connected_clients, 1, __ATOMIC_SEQ_CST);
62 #else
63 if (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED)
@@ -71,7 +71,7 @@ void web_client_connected(void) {
71 }
72
73 void web_client_disconnected(void) {
74 -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS
74 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
75 __atomic_fetch_sub(&global_statistics.connected_clients, 1, __ATOMIC_SEQ_CST);
76 #else
77 if (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED)
@@ -86,7 +86,7 @@ void web_client_disconnected(void) {
86
87
88 inline void global_statistics_copy(struct global_statistics *gs, uint8_t options) {
89 -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS
89 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
90 gs->connected_clients = __atomic_fetch_add(&global_statistics.connected_clients, 0, __ATOMIC_SEQ_CST);
91 gs->web_requests = __atomic_fetch_add(&global_statistics.web_requests, 0, __ATOMIC_SEQ_CST);
92 gs->web_usec = __atomic_fetch_add(&global_statistics.web_usec, 0, __ATOMIC_SEQ_CST);
@@ -259,4 +259,4 @@ void global_statistics_charts(void) {
259 rrddim_set(stcompression, "savings", compression_ratio);
260
261 rrdset_done(stcompression);
262 -}
\ No newline at end of file
262 +}