[lttng-dev] [PATCH 01/11] configure: Add --disable-atomic-builtins option

Olivier Dion odion at efficios.com
Mon May 15 16:17:08 EDT 2023


By default, if the toolchain supports atomic builtins, use them for the
uatomic API. This requires that the toolchains used to compile the
library and the user application supports such builtins.

The advantage of using these builtins is that they are well known
synchronization primitives by several tools such as TSAN.

Change-Id: Ia8e97112681f744f17816dbc4cbbec805a483331
Co-authored-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
Signed-off-by: Olivier Dion <odion at efficios.com>
---
 README.md    | 11 +++++++++++
 configure.ac | 26 ++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/README.md b/README.md
index ba5bb08..6ce96c9 100644
--- a/README.md
+++ b/README.md
@@ -429,6 +429,17 @@ still being used to iterate on a hash table.
 This option alters the rculfhash ABI. Make sure to compile both library
 and application with matching configuration.
 
+### Usage of `--disable-atomic-builtins`
+
+By default, the configure script will check if the toolchain supports atomic
+builtins. If so, then the RCU memory model is implemented using the atomic
+builtins of the toolchain.
+
+Building liburcu with `--disable-atomic-builtins` force to use the legacy
+internal implementations for atomic accesses.
+
+This option is useful if for example the atomic builtins for a given toolchain
+version is known to be broken or to be inefficient.
 
 Make targets
 ------------
diff --git a/configure.ac b/configure.ac
index 909cf1d..4450a31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -230,6 +230,11 @@ AE_FEATURE([rcu-debug], [Enable internal debugging self-checks. Introduces a per
 AE_FEATURE_DEFAULT_DISABLE
 AE_FEATURE([cds-lfht-iter-debug], [Enable extra debugging checks for lock-free hash table iterator traversal. Alters the rculfhash ABI. Make sure to compile both library and application with matching configuration.])
 
+# toolchain atomic builtins
+# Enabled by default
+AE_FEATURE_DEFAULT_ENABLE
+AE_FEATURE([atomic-builtins], [Disable the usage of toolchain atomic builtins.])
+
 # When given, add -Werror to WARN_CFLAGS and WARN_CXXFLAGS.
 # Disabled by default
 AE_FEATURE_DEFAULT_DISABLE
@@ -259,6 +264,23 @@ AE_IF_FEATURE_ENABLED([cds-lfht-iter-debug], [
   AC_DEFINE([CONFIG_CDS_LFHT_ITER_DEBUG], [1], [Enable extra debugging checks for lock-free hash table iterator traversal. Alters the rculfhash ABI. Make sure to compile both library and application with matching configuration.])
 ])
 
+AE_IF_FEATURE_ENABLED([atomic-builtins], [
+  AC_COMPILE_IFELSE(
+	[AC_LANG_PROGRAM(
+		[[int x, y;]],
+		[[__atomic_store_n(&x, 0, __ATOMIC_RELAXED);
+		  __atomic_load_n(&x, __ATOMIC_RELAXED);
+		  y = __atomic_exchange_n(&x, 1, __ATOMIC_RELAXED);
+		  __atomic_compare_exchange_n(&x, &y, 0, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
+		  __atomic_add_fetch(&x, 1, __ATOMIC_RELAXED);
+		  __atomic_sub_fetch(&x, 1, __ATOMIC_RELAXED);
+		  __atomic_and_fetch(&x, 0x01, __ATOMIC_RELAXED);
+		  __atomic_or_fetch(&x, 0x01, __ATOMIC_RELAXED);
+		  __atomic_thread_fence(__ATOMIC_RELAXED);
+		  __atomic_signal_fence(__ATOMIC_RELAXED);]])],
+	[AC_DEFINE([CONFIG_RCU_USE_ATOMIC_BUILTINS], [1], [Use compiler atomic builtins.])],
+	[AE_FEATURE_DISABLE(atomic-builtins)])
+])
 
 ##                                                                          ##
 ## Set automake variables for optional feature conditionnals in Makefile.am ##
@@ -361,6 +383,10 @@ PPRINT_PROP_BOOL([Internal debugging], $value)
 AE_IS_FEATURE_ENABLED([cds-lfht-iter-debug]) && value=1 || value=0
 PPRINT_PROP_BOOL([Lock-free HT iterator debugging], $value)
 
+# atomic builtins enabled/disabled
+AE_IS_FEATURE_ENABLED([atomic-builtins]) && value=1 || value=0
+PPRINT_PROP_BOOL([Use toolchain atomic builtins], $value)
+
 PPRINT_PROP_BOOL([Multi-flavor support], 1)
 
 report_bindir="`eval eval echo $bindir`"
-- 
2.39.2



More information about the lttng-dev mailing list