ppc.h: use mftb on ppc Older versions of GNU as do not support mftbl. The issue affects Darwin PowerPC, as well as some older versions of NetBSD and Linux. Since mftb is equivalent and universally understood, just use that. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: I098b70fa8bb077143d2d658835586b6b059b879f
Add LoongArch support This commit completes LoongArch support. LoongArch supports byte and short atomic operations, and defines UATOMIC_HAS_ATOMIC_BYTE and UATOMIC_HAS_ATOMIC_SHORT. Signed-off-by: Wang Jing <wangjing@loongson.cn> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: I335e654939bfc90994275f2a4fad550c95f3eba4
urcu/annotate: Add CMM annotation The CMM annotation is highly experimental and not meant to be used by user for now, even though it is exposed in the public API since some parts of the liburcu public API require those annotations. The main primitive is the cmm_annotate_t which denotes a group of memory operations associated with a memory barrier. A group follows a state machine, starting from the `CMM_ANNOTATE_VOID' state. The following are the only valid transitions: CMM_ANNOTATE_VOID -> CMM_ANNOTATE_MB (acquire & release MB) CMM_ANNOTATE_VOID -> CMM_ANNOTATE_LOAD (acquire memory) CMM_ANNOTATE_LOAD -> CMM_ANNOTATE_MB (acquire MB) The macro `cmm_annotate_define(name)' can be used to create an annotation object on the stack. The rest of the `cmm_annotate_*' macros can be used to change the state of the group after validating that the transition is allowed. Some of these macros also inject TSAN annotations to help it understand the flow of events in the program since it does not currently support thread fence. Sometime, a single memory access does not need to be associated with a group. In the case, the acquire/release macros variant without the `group' infix can be used to annotate memory accesses. Note that TSAN can not be used on the liburcu-signal flavor. This is because TSAN hijacks calls to sigaction(3) and places its own handler that will deliver the signal to the application at a synchronization point. Thus, the usage of TSAN on the signal flavor is undefined behavior. However, there's at least one known behavior which is a deadlock between readers that want to unregister them-self by locking the `rcu_registry_lock' while a synchronize RCU is made on the writer side which has already locked that mutex until all the registered readers execute a memory barrier in a signal handler defined by liburcu-signal. However, TSAN will not call the registered handler while waiting on the mutex. Therefore, the writer spin infinitely on pthread_kill(3p) because the reader simply never complete the handshake. See the deadlock minimal reproducer below. Deadlock reproducer: ``` #include <poll.h> #include <signal.h> #include <pthread.h> #define SIGURCU SIGUSR1 static pthread_mutex_t rcu_registry_lock = PTHREAD_MUTEX_INITIALIZER; static int need_mb = 0; static void *reader_side(void *nil) { (void) nil; pthread_mutex_lock(&rcu_registry_lock); pthread_mutex_unlock(&rcu_registry_lock); return NULL; } static void writer_side(pthread_t reader) { __atomic_store_n(&need_mb, 1, __ATOMIC_RELEASE); while (__atomic_load_n(&need_mb, __ATOMIC_ACQUIRE)) { pthread_kill(reader, SIGURCU); (void) poll(NULL, 0, 1); } pthread_mutex_unlock(&rcu_registry_lock); pthread_join(reader, NULL); } static void sigrcu_handler(int signo, siginfo_t *siginfo, void *context) { (void) signo; (void) siginfo; (void) context; __atomic_store_n(&need_mb, 0, __ATOMIC_SEQ_CST); } static void install_signal(void) { struct sigaction act; act.sa_sigaction = sigrcu_handler; act.sa_flags = SA_SIGINFO | SA_RESTART; sigemptyset(&act.sa_mask); (void) sigaction(SIGURCU, &act, NULL); } int main(void) { pthread_t th; install_signal(); pthread_mutex_lock(&rcu_registry_lock); pthread_create(&th, NULL, reader_side, NULL); writer_side(th); return 0; } ``` Change-Id: I9c234bb311cc0f82ea9dbefdf4fee07047ab93f9 Co-authored-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Olivier Dion <odion@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu/arch/generic: Use atomic builtins if configured If configured to use atomic builtins, implement SMP memory barriers in term of atomic builtins if the architecture does not implement its own version. Change-Id: Iddc4283606e0fce572e104d2d3f03b5c0d9926fb Co-authored-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Olivier Dion <odion@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Public headers: use SPDX identifiers The SPDX identifiers [1] are a legally binding shorthand, which can be used instead of the full boiler plate text. This is another step towards implementing the full REUSE spec [2] to help with copyright and licensing audits and compliance. This will reduce a lot a manual work required for the licensing audit required in Debian on each update. For files that lacked copyright and licensing information, I used the following guidelines. Use the author from the git history and the main project license 'LGPL-2.1-or-later'. [1] https://spdx.org/ids-how [2] https://reuse.software/tutorial/ Change-Id: I31928c81be4821cca29b905d8a0a06de9bd0e1ec Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
fix: aarch64: allow RHEL7 gcc 4.8.5-11 The patch for GCC upstream bug 63293[1] was backported in RHEL7 gcc 4.8.5-11 package, allow building with this version. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293 Change-Id: Ib5d8ef3c292a691167c5c4834c1e0bfdfe5b56b3 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
alpha: allocate membarrier system call number The membarrier syscall has been allocated in Linux 4.13, allocate its number in our architecture header if the system headers don't allocate it. Change-Id: Iebb77b94bf803a7a8b7ebd9f4124219f386334ae Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
fix: clock_gettime on macOs Newer version of macOs have an implementation of clock_gettime() that requires additionnal setup, move the platform specific code first so it is always used. Change-Id: I12fcdeff6c0ae59bc1a13f4e2cd7f4ebcedfc253 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
aarch64: blacklist gcc prior to 5.1 Linux aarch64 requires GCC 5.1 or better because prior versions perform unsafe access to deallocated stack. Some Linux distributions may have backported the fix, but it was never released into earlier upstream gcc versions. Link: https://lwn.net/Articles/842122/ Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Use DMB only on ARMv7 Remove the configure time CONFIG_RCU_ARM_HAVE_DMB option and replace it by compile time detection based on the ARM ISA version. This makes sure we unconditionnaly use the DMB instruction only on ARMv7 where it's part of the baseline ISA. This will change the behavior on ARMv6 platform that possibly have this instruction but it was probably already broken since we use the 'ISH' option which doesn't seem to be valid on this ISA. This will also allow sharing headers in a multi-arch environment and reduce the build system complexity. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Cc: Jason Wessel <jason.wessel@windriver.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: I8e56ada55148d8e0f198c3d2e741ea414de5fef2
Blacklist GCC 4.4.0, 4.4.1 and 4.4.2 on ARM GCC added __sync_synchronize() in 4.4.0 but it was broken on ARM until 4.4.3, see the GCC bug report for more details : https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42263 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: I629e3c8b4baaccb34b2311e220f30d0ad8b69a19
Static arch and uatomic headers Replace the somewhat hackish symlinking of architecture specific headers at configure time with compile time detection using compiler defines. This would allow sharing headers in a multi-arch environment and reduce the build system complexity. Change-Id: I4900a18dab70bb0e51d1a8500581a445acd44cdf Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ARM32: use dmb ish (inner shareable domain) for smp barriers Based on https://gcc.gnu.org/ml/gcc-patches/2014-11/msg01272.html: From: Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>: "Hans Boehm pointed out that we were using dmb sy instead of dmb ish. Given that the ARM-ARM says that the inner shareability domain is really the one that contains all PE's controlled by a single hypervisor or operating system, it would be safe to replace all dmb sy's with dmb ish's. " Keep full system barriers for cmm_mb()/cmm_rmb()/cmm_wmb(). Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cleanup: Re-organise source dir Re-organise the sources, add a top level "src" and "include" dir and move relevant files. Disable autotools automated includes and define them manually. This fixes problems with collision of header names with system headers. Include the autoconf config.h in the default includes and remove it where it's explicitely included. Remove _GNU_SOURCE defines since it's detected at configure for platforms that requires it and added to the config.h. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>