]> git.lttng.org Git - userspace-rcu.git/log
userspace-rcu.git
15 months agoPhase 1 of deprecating liburcu-signal
Olivier Dion [Mon, 14 Aug 2023 20:40:30 +0000 (16:40 -0400)] 
Phase 1 of deprecating liburcu-signal

The first phase of liburcu-signal deprecation consists of implementing
it in term of liburcu-mb. In other words, liburcu-signal is identical to
liburcu-mb at the exception of the function symbols and public header
files.

This is done by:

  1) Removing the RCU_SIGNAL specific code in urcu.c

  2) Making the RCU_MB specific code also specific to RCU_SIGNAL in
  urcu.c

  3) Rewriting _urcu_signal_read_unlock_update_and_wakeup to use a
  atomic store with CMM_SEQ_CST instead of a store CMM_RELAXED with
  cmm_barrier() around it. We could keep the explicit barriers, but that
  would require to add some cmm_annotate annotations. Therefore, to be
  less intrusive in a public header file, simply use the CMM_SEQ_CST
  like for the mb flavor.

Change-Id: Ie406f7df2f47da0a9f464df94b968ad9204821f3
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 months agouatomic/generic: Fix redundant declaration warning
Olivier Dion [Mon, 14 Aug 2023 22:57:23 +0000 (18:57 -0400)] 
uatomic/generic: Fix redundant declaration warning

abort(3) was explicitly declared external to avoid including
<stdlib.h>. However, this emit a redundant declaration warning if it was
already declared before including <urcu/uatomic.h>.

Fix this by including <stdlib.h> and not declaring abort().

Change-Id: If9557814c311e2b531e85fec8c41788462338fe4
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 months agotests: Add tests for checking race conditions
Olivier Dion [Thu, 25 May 2023 18:35:57 +0000 (14:35 -0400)] 
tests: Add tests for checking race conditions

These tests do nothing useful except of stress testing a
single-consumer, multiple-producers program on various data structures.

These tests are only meaningful when compiling liburcu with TSAN.

Change-Id: If22b27ed0fb95bf890947fc4e75f923edb5ada8f
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 months agoAdd cmm_emit_legacy_smp_mb()
Olivier Dion [Mon, 29 May 2023 15:21:11 +0000 (11:21 -0400)] 
Add cmm_emit_legacy_smp_mb()

Some public APIs stipulate implicit memory barriers on operations. These
were coherent with the memory model used at that time. However, with the
migration to a memory model closer to the C11 memory model, these memory
barriers are not strictly emitted by the atomic operations in the new
memory model.

Therefore, introducing the `--disable-legacy-mb' configuration
option. By default, liburcu is configured to emit these legacy memory
barriers, thus keeping backward compatibility at the expense of slower
performances. However, users can opt-out by disabling the legacy memory
barriers.

This options is publicly exported in the system configuration header
file and can be overrode manually on a compilation unit basis by
defining `CONFIG_RCU_EMIT_LEGACY_MB' before including any liburcu files.

The usage of this macro requires to re-write atomic operations in term
of the CMM memory model. This is done for the queue and stack APIs.

Change-Id: Ia5ce3b3d8cd1955556ce96fa4408a63aa098a1a6
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 months agourcu/annotate: Add CMM annotation
Olivier Dion [Fri, 31 Mar 2023 17:47:17 +0000 (13:47 -0400)] 
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>
15 months agotests/unit/test_build: Quiet unused return value
Olivier Dion [Wed, 26 Apr 2023 19:36:52 +0000 (15:36 -0400)] 
tests/unit/test_build: Quiet unused return value

Change-Id: Ie5a18e0ccc4b1b5ee85c5bd140561cc2ff9e2fbc
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>
15 months agobenchmark: Use uatomic for accessing global states
Olivier Dion [Fri, 31 Mar 2023 14:53:43 +0000 (10:53 -0400)] 
benchmark: Use uatomic for accessing global states

Global states accesses were protected via memory barriers. Use the
uatomic API with the CMM memory model so that TSAN can understand the
ordering imposed by the synchronization flags.

Change-Id: I1bf5702c5ac470f308c478effe39e424a3158060
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>
15 months agotests: Use uatomic for accessing global states
Olivier Dion [Wed, 29 Mar 2023 19:22:13 +0000 (15:22 -0400)] 
tests: Use uatomic for accessing global states

Global states accesses were protected via memory barriers. Use the
uatomic API with the CMM memory model so that TSAN does not warn about
non-atomic concurrent accesses.

Also, the thread id map mutex must be unlocked after setting the new
created thread id in the map. Otherwise, the new thread could observe an
unset id.

Change-Id: I1ecdc387b3f510621cbc116ad3b95c676f5d659a
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>
15 months agourcu-wait: Fix wait state load/store
Olivier Dion [Thu, 30 Mar 2023 20:09:50 +0000 (16:09 -0400)] 
urcu-wait: Fix wait state load/store

The state of a wait node must be accessed atomically. Also, the action
of busy loading until the teardown state is seen must follow a
CMM_ACQUIRE semantic while storing the teardown must follow a
CMM_RELEASE semantic.

Change-Id: I9cd9cf4cd9ab2081551d7f33c0b1c23c3cf3942f
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>
15 months agoAdd CMM memory model
Olivier Dion [Wed, 29 Mar 2023 18:44:43 +0000 (14:44 -0400)] 
Add CMM memory model

Introducing the CMM memory model with the following new primitives:

  - uatomic_load(addr, memory_order)

  - uatomic_store(addr, value, memory_order)
  - uatomic_and_mo(addr, mask, memory_order)
  - uatomic_or_mo(addr, mask, memory_order)
  - uatomic_add_mo(addr, value, memory_order)
  - uatomic_sub_mo(addr, value, memory_order)
  - uatomic_inc_mo(addr, memory_order)
  - uatomic_dec_mo(addr, memory_order)

  - uatomic_add_return_mo(addr, value, memory_order)
  - uatomic_sub_return_mo(addr, value, memory_order)

  - uatomic_xchg_mo(addr, value, memory_order)

  - uatomic_cmpxchg_mo(addr, old, new,
                       memory_order_success,
                       memory_order_failure)

The CMM memory model reflects the C11 memory model with an additional
CMM_SEQ_CST_FENCE memory order. The memory order can be selected through
the enum cmm_memorder.

* With Atomic Builtins

If configured with atomic builtins, the correspondence between the CMM
memory model and the C11 memory model is a one to one at the exception
of the CMM_SEQ_CST_FENCE memory order which implies the memory order
CMM_SEQ_CST and a thread fence after the operation.

* Without Atomic Builtins

However, if not configured with atomic builtins, the following stipulate
the memory model.

For load operations with uatomic_load(), the memory orders CMM_RELAXED,
CMM_CONSUME, CMM_ACQUIRE, CMM_SEQ_CST and CMM_SEQ_CST_FENCE are
allowed. A barrier may be inserted before and after the load from memory
depending on the memory order:

  - CMM_RELAXED: No barrier
  - CMM_CONSUME: Memory barrier after read
  - CMM_ACQUIRE: Memory barrier after read
  - CMM_SEQ_CST: Memory barriers before and after read
  - CMM_SEQ_CST_FENCE: Memory barriers before and after read

For store operations with uatomic_store(), the memory orders
CMM_RELAXED, CMM_RELEASE, CMM_SEQ_CST and CMM_SEQ_CST_FENCE are
allowed. A barrier may be inserted before and after the store to memory
depending on the memory order:

  - CMM_RELAXED: No barrier
  - CMM_RELEASE: Memory barrier before operation
  - CMM_SEQ_CST: Memory barriers before and after operation
  - CMM_SEQ_CST_FENCE: Memory barriers before and after operation

For load/store operations with uatomic_and_mo(), uatomic_or_mo(),
uatomic_add_mo(), uatomic_sub_mo(), uatomic_inc_mo(), uatomic_dec_mo(),
uatomic_add_return_mo() and uatomic_sub_return_mo(), all memory orders
are allowed. A barrier may be inserted before and after the operation
depending on the memory order:

  - CMM_RELAXED: No barrier
  - CMM_ACQUIRE: Memory barrier after operation
  - CMM_CONSUME: Memory barrier after operation
  - CMM_RELEASE: Memory barrier before operation
  - CMM_ACQ_REL: Memory barriers before and after operation
  - CMM_SEQ_CST: Memory barriers before and after operation
  - CMM_SEQ_CST_FENCE: Memory barriers before and after operation

For the exchange operation uatomic_xchg_mo(), any memory order is
valid. A barrier may be inserted before and after the exchange to memory
depending on the memory order:

  - CMM_RELAXED: No barrier
  - CMM_ACQUIRE: Memory barrier after operation
  - CMM_CONSUME: Memory barrier after operation
  - CMM_RELEASE: Memory barrier before operation
  - CMM_ACQ_REL: Memory barriers before and after operation
  - CMM_SEQ_CST: Memory barriers before and after operation
  - CMM_SEQ_CST_FENCE: Memory barriers before and after operation

For the compare exchange operation uatomic_cmpxchg_mo(), the success
memory order can be anything while the failure memory order cannot be
CMM_RELEASE nor CMM_ACQ_REL and cannot be stronger than the success
memory order. A barrier may be inserted before and after the store to
memory depending on the memory orders:

 Success memory order:

  - CMM_RELAXED: No barrier
  - CMM_ACQUIRE: Memory barrier after operation
  - CMM_CONSUME: Memory barrier after operation
  - CMM_RELEASE: Memory barrier before operation
  - CMM_ACQ_REL: Memory barriers before and after operation
  - CMM_SEQ_CST: Memory barriers before and after operation
  - CMM_SEQ_CST_FENCE: Memory barriers before and after operation

  Barriers after the operations are only emitted if the compare exchange
  succeed.

 Failure memory order:
  - CMM_RELAXED: No barrier
  - CMM_ACQUIRE: Memory barrier after operation
  - CMM_CONSUME: Memory barrier after operation
  - CMM_SEQ_CST: Memory barriers before and after operation
  - CMM_SEQ_CST_FENCE: Memory barriers before and after operation

  Barriers after the operations are only emitted if the compare exchange
  failed.  Barriers before the operation are never emitted by this
  memory order.

Change-Id: I213ba19c84e82a63083f00143a3142ffbdab1d52
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>
15 months agourcu/arch/generic: Use atomic builtins if configured
Olivier Dion [Wed, 29 Mar 2023 18:43:15 +0000 (14:43 -0400)] 
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>
15 months agourcu/compiler: Use atomic builtins if configured
Olivier Dion [Fri, 17 Mar 2023 21:37:51 +0000 (22:37 +0100)] 
urcu/compiler: Use atomic builtins if configured

Use __atomic_signal_fence(__ATOMIC_SEQ_CST) for cmm_barrier() if
configured to use atomic builtins.

Change-Id: Ib168b50f1e97a8da861b92d6882c56db230ebb2c
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>
15 months agoconfigure: Add --enable-compiler-atomic-builtins option
Olivier Dion [Fri, 17 Mar 2023 21:37:49 +0000 (22:37 +0100)] 
configure: Add --enable-compiler-atomic-builtins option

If the toolchain supports atomic builtins and the user ask for 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.

However, they may introduce redundant memory barriers, mainly on
strongly ordered architectures.

Change-Id: Ia8e97112681f744f17816dbc4cbbec805a483331
Co-authored-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agoFix: tests/rcutorture: Put thread offline on busy-wait
Olivier Dion [Fri, 14 Jul 2023 19:51:34 +0000 (15:51 -0400)] 
Fix: tests/rcutorture: Put thread offline on busy-wait

Change-Id: Ic12b7df5d70b474f1e87f0710d3a55e5f906c020
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agotests/regression/rcutorture: Use urcu-wait
Olivier Dion [Fri, 14 Jul 2023 16:49:24 +0000 (12:49 -0400)] 
tests/regression/rcutorture: Use urcu-wait

pthread_cond_wait(3) can have spurious wakeups on some OS. To detect
such spurious wakeup, a global variable is shared between the waiter and
the waker.

We can use urcu-wait instead.

Change-Id: I6a2d2f3c9104ea23df16a7c8ba3557bb5d58306c
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agotests/rcutorture: Factor out thread registration
Olivier Dion [Fri, 14 Jul 2023 17:25:56 +0000 (13:25 -0400)] 
tests/rcutorture: Factor out thread registration

Register the thread once at the begining of the update routine. Put the
thread offline when doing anything that can block.

Change-Id: I345e04ee2ef0b5ba2f065b8a3029dd0e6130037b
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agotests/regression/rcutorture: Add wait state
Olivier Dion [Fri, 14 Jul 2023 16:59:23 +0000 (12:59 -0400)] 
tests/regression/rcutorture: Add wait state

pthread_cond_wait(3) can have spurious wakeups. Fix this by polling a
state associated with the the wait.

Change-Id: Iba034cba5f72ad88388d1b90a6093f4ae9f9beb9
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agourcu-wait: Initialize node in URCU_WAIT_NODE_INIT
Olivier Dion [Fri, 14 Jul 2023 17:09:21 +0000 (13:09 -0400)] 
urcu-wait: Initialize node in URCU_WAIT_NODE_INIT

C++ emits warnings with the URCU_WAIT_NODE_INIT() macro because the
member node is not initialized.

Fix this by initializing the node to null.

Change-Id: I7ee3b35624ef61cab826e3668f111e2483ca3c05
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agoComplete REUSE support
Michael Jeanson [Thu, 6 Jul 2023 15:35:11 +0000 (11:35 -0400)] 
Complete REUSE support

The SPDX identifiers [1] are a legally binding shorthand, which can be
used instead of the full boiler plate text. This is the final 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.

[1] https://spdx.org/ids-how
[2] https://reuse.software/tutorial/

Change-Id: Ia014969f407043d4ac48f4a8f3639c860ca2aafb
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agoextras/abi: license data files under CC-1.0
Michael Jeanson [Wed, 5 Jul 2023 18:20:10 +0000 (14:20 -0400)] 
extras/abi: license data files under CC-1.0

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.

These are generated files, use the CC-1.0 license to make their
licensing clear.

[1] https://spdx.org/ids-how
[2] https://reuse.software/tutorial/

Change-Id: I2ac79f2646ced6c01bce67c1281a2d597ab0d890
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agoexamples: use SPDX identifiers
Michael Jeanson [Wed, 5 Jul 2023 15:17:24 +0000 (11:17 -0400)] 
examples: 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.

Relicense all examples from 'Boehm-GC' to the more well-known and
functionnaly identical 'MIT' license. This is possible since all the
examples were written by Mathieu Desnoyers and only a few trivial fixes
from external contributors were applied over the years.

[1] https://spdx.org/ids-how
[2] https://reuse.software/tutorial/

Change-Id: I052ab4fca0f8979113f3bae3b78982eb30f50c58
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agotests: use SPDX identifiers
Michael Jeanson [Tue, 4 Jul 2023 20:53:30 +0000 (16:53 -0400)] 
tests: 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 test
scripts license as stated in LICENSE, 'GPL-2.0-only'.

[1] https://spdx.org/ids-how
[2] https://reuse.software/tutorial/

Change-Id: I23c23edeffe6f3448ad673034480de46c98b746b
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agosrc: use SPDX identifiers
Michael Jeanson [Tue, 4 Jul 2023 20:53:07 +0000 (16:53 -0400)] 
src: 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.

[1] https://spdx.org/ids-how
[2] https://reuse.software/tutorial/

Change-Id: Ia28ed8c14984ac9acd140ef544fd6e09b96fb03b
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agoPublic headers: use SPDX identifiers
Michael Jeanson [Tue, 4 Jul 2023 20:52:00 +0000 (16:52 -0400)] 
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>
16 months agoBuild system: use SPDX identifiers
Michael Jeanson [Tue, 4 Jul 2023 20:47:07 +0000 (16:47 -0400)] 
Build system: 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 the first 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. If a clear author could be determined from the git
history use it, otherwise use 'EfficiOS Inc.'. For build system files,
use 'MIT', for documentation 'CC-BY-4.0' and for data files 'CC-1.0'.

[1] https://spdx.org/ids-how
[2] https://reuse.software/tutorial/

Change-Id: Ie507130c00b95606dc439616fda4fd9b1d35353d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 months agoFix: urcu-wait: add missing futex.h include
Mathieu Desnoyers [Wed, 5 Jul 2023 15:22:02 +0000 (11:22 -0400)] 
Fix: urcu-wait: add missing futex.h include

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: If33cc980f6f8510b8b7acb7038c2afbdab7699ed

17 months agodoc: update GCC baseline to 4.8
Your Name [Mon, 3 Jul 2023 15:26:24 +0000 (11:26 -0400)] 
doc: update GCC baseline to 4.8

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I7ac0c195bed75b210164e9f7a3cec87cf02ef37e

17 months agodoc: update FreeBSD tested version
Your Name [Mon, 3 Jul 2023 15:18:09 +0000 (11:18 -0400)] 
doc: update FreeBSD tested version

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I263b7c3502995f0df45176f3618b6038f757c0b9

17 months agodoc: Remove Solaris from tested platforms
Your Name [Mon, 3 Jul 2023 15:14:25 +0000 (11:14 -0400)] 
doc: Remove Solaris from tested platforms

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I85d99b928589c2c9943c5023dd86836c7da720f8

17 months agoRevert "compiler.h: Introduce caa_unqual_scalar_typeof"
Mathieu Desnoyers [Mon, 3 Jul 2023 15:21:08 +0000 (11:21 -0400)] 
Revert "compiler.h: Introduce caa_unqual_scalar_typeof"

This reverts commit 67988e204d2c471b24cae61f3f8fedb4f9375034.

_Generic requires C11, but liburcu supports C99.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I3b7c7a629cb9b7417caea4ff30b4844ff3d081e9

17 months agorculfhash: Use caa_container_of_check_null in cds_lfht_entry
Mathieu Desnoyers [Mon, 3 Jul 2023 15:20:27 +0000 (11:20 -0400)] 
rculfhash: Use caa_container_of_check_null in cds_lfht_entry

Use caa_container_of_check_null in cds_lfht_entry to allow removing
caa_unqual_scalar_typeof, which requires C11.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ifd8b05e666b8f1618a823b96a934a2357edb6b36

17 months agocompiler.h: Introduce caa_container_of_check_null
Mathieu Desnoyers [Mon, 3 Jul 2023 15:17:04 +0000 (11:17 -0400)] 
compiler.h: Introduce caa_container_of_check_null

The approach taken by caa_unqual_scalar_typeof requires use of _Generic
which requires full C11 support. Currently liburcu supports C99.
Therefore, this approach is not appropriate for now.

Instead, introduce caa_container_of_check_null which returns NULL if the
ptr is NULL before offsetting by the member offset.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I0ac1cacc67d83bd3dad6fb6cd2e6595190735441

17 months agocompiler.h: Introduce caa_unqual_scalar_typeof
Mathieu Desnoyers [Thu, 22 Jun 2023 13:58:39 +0000 (09:58 -0400)] 
compiler.h: Introduce caa_unqual_scalar_typeof

Allow defining variables and cast with a typeof which removes the
volatile and const qualifiers.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie2ea915a600a69cec3c2ff64209892bf0794cb70

17 months agoAvoid calling caa_container_of on NULL pointer in cds_lfht macros
Mathieu Desnoyers [Thu, 22 Jun 2023 13:59:53 +0000 (09:59 -0400)] 
Avoid calling caa_container_of on NULL pointer in cds_lfht macros

The cds_lfht_for_each_entry and cds_lfht_for_each_entry_duplicate macros
would call caa_container_of() macro on NULL pointer.  This is not a
problem under normal circumstances as the check in the for loop fails
and the loop-statement is not called with invalid (pos) value.

However AddressSanitizer doesn't like that and complains about this:

    runtime error: applying non-zero offset 18446744073709551056 to null pointer

Move the cds_lfht_iter_get_node(iter) != NULL from the cond-expression
of the for loop into both init-clause and iteration-expression as
conditional operator and check for (pos) value in the cond-expression
instead. Introduce the cds_lfht_entry() macro to eliminate code
duplication.

Reported-by: Ondřej Surý <ondrej@sury.org>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I9969c1e0bc0eefc8c90c0d8f17b2927f6a4feb2a

17 months agoFix: revise urcu_read_lock_update() comment
Li-Kuan Ou [Wed, 14 Jun 2023 01:51:48 +0000 (09:51 +0800)] 
Fix: revise urcu_read_lock_update() comment

Read-side critical section nesting is tracked in lower-order bits
and grace-period phase number use a single high-order bit.

Signed-off-by: Li-Kuan Ou <k777k777tw@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I4fc185aa12a367e997fa20bf37793cfb2023c96f

17 months agoFix: uatomic powerpc comment about lwsync
Mathieu Desnoyers [Fri, 9 Jun 2023 14:50:48 +0000 (10:50 -0400)] 
Fix: uatomic powerpc comment about lwsync

lwsync allows prior stores to be reordered against following loads.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I288900d3546779ee80d14a3d8d02c43d7b1c0e8c

17 months agofix: aarch64: allow RHEL7 gcc 4.8.5-11
Michael Jeanson [Mon, 5 Jun 2023 17:58:16 +0000 (13:58 -0400)] 
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>
18 months agoaarch64: Implement caa_cpu_relax as yield instruction
Mathieu Desnoyers [Wed, 31 May 2023 16:05:10 +0000 (12:05 -0400)] 
aarch64: Implement caa_cpu_relax as yield instruction

Use the aarch64 "yield" instruction which has the wanted semantic for
caa_cpu_relax.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I9852ae3170d4cc2207f8120355b51c1d0e5e5506

20 months agofix: warning 'noreturn' function does return on ppc
Michael Jeanson [Thu, 23 Mar 2023 18:23:55 +0000 (14:23 -0400)] 
fix: warning 'noreturn' function does return on ppc

On a ppc64 system with gcc 9.5.0 I get the following error when building
with -O0 :

/usr/include/urcu/uatomic/generic.h: In function 'void _uatomic_link_error()':
/usr/include/urcu/uatomic/generic.h:53:1: warning: 'noreturn' function does return
   53 | }
      | ^

Split the inline function in 2 variants and apply the noreturn attribute
only on the builtin_trap one.

Change-Id: I5ae8e764c4cc27af0463924a653b9eaa9f698c34
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
20 months agoFix: use __noreturn__ for C11-compatibility
Ondřej Surý [Fri, 17 Mar 2023 15:44:10 +0000 (16:44 +0100)] 
Fix: use __noreturn__ for C11-compatibility

The noreturn convenience macro provided by stdnoreturn.h might get
included before urcu headers, use __noreturn__ for better compatibility
with code using <stdnoreturn.h> header.

Signed-off-by: Ondřej Surý <ondrej@sury.org>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
21 months agoAdjust shell scripts to allow Bash in other locations
Brad Smith [Sat, 25 Feb 2023 05:53:06 +0000 (00:53 -0500)] 
Adjust shell scripts to allow Bash in other locations

Linux-based OS for the most part provide Bash and being located in /bin,
but on other OS's the shell would be in another location. Utilize env(1)
and allow it to be located elsewhere.

Signed-off-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I9d4d4a3feaf993754c64b740ea91e42b336ba2b4

21 months agoAdd support for OpenBSD
Brad Smith [Sat, 25 Feb 2023 02:17:16 +0000 (21:17 -0500)] 
Add support for OpenBSD

- Add OpenBSD to syscall compatibility header as appropriate.
- Add function for retrieving the thread id in urcu_get_thread_id().
- Rely on pthread cond variables for futex compatibility.

It builds on all of our archs and fully run time tested on amd64.

Signed-off-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I5cca5962ba3dc3113c9bd12e544b6e6f77dfdb61

21 months agoBump version to 0.15.0-pre
Mathieu Desnoyers [Tue, 14 Feb 2023 15:41:43 +0000 (10:41 -0500)] 
Bump version to 0.15.0-pre

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iabae31adc8a0f2e5dbb9133df4c27d7e1d6d2465

21 months agoVersion 0.14.0 v0.14.0
Mathieu Desnoyers [Tue, 14 Feb 2023 15:25:27 +0000 (10:25 -0500)] 
Version 0.14.0

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I08341ed1ba861cbbe3da03e3b2426bd073169a77

21 months agoFix: urcu-bp: only teardown call-rcu worker in destructor
Mathieu Desnoyers [Mon, 13 Feb 2023 17:24:09 +0000 (12:24 -0500)] 
Fix: urcu-bp: only teardown call-rcu worker in destructor

Do not invoke urcu_call_rcu_exit() every time a reader thread
unregisters from urcu-bp. This causes pthread join hangs observed on
Cygwin.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I4e5c6e06df9966d65f2dcf01bb3281cbfcb05a5b

21 months agoFix: rculfhash: urcu_die() takes positive error value
Mathieu Desnoyers [Sat, 11 Feb 2023 01:29:39 +0000 (20:29 -0500)] 
Fix: rculfhash: urcu_die() takes positive error value

Found by Coverity:

** CID 1504537:  Error handling issues  (NEGATIVE_RETURNS)
/src/rculfhash.c: 1934 in do_auto_resize_destroy_cb()

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I6c130fc18fc36da8d0ed13188cc9415e7ee6104b

21 months agoFix: call_rcu: teardown default call_rcu worker on application exit
Mathieu Desnoyers [Fri, 10 Feb 2023 19:55:24 +0000 (14:55 -0500)] 
Fix: call_rcu: teardown default call_rcu worker on application exit

Teardown the default call_rcu worker thread if there are no queued
callbacks on process exit. This prevents leaking memory.

Here is how an application can ensure graceful teardown of this
worker thread:

- An application queuing call_rcu callbacks should invoke
  rcu_barrier() before it exits.
- When chaining call_rcu callbacks, the number of calls to
  rcu_barrier() on application exit must match at least the maximum
  number of chained callbacks.
- If an application chains callbacks endlessly, it would have to be
  modified to stop chaining callbacks when it detects an application
  exit (e.g. with a flag), and wait for quiescence with rcu_barrier()
  after setting that flag.
- The statements above apply to a library which queues call_rcu
  callbacks, only it needs to invoke rcu_barrier in its library
  destructor.

Fixes: #1317
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I40556bc872d3df58a22fb88a0dbb528ce5c9b4af

21 months agoFix: join worker thread in call_rcu_data_free
Mathieu Desnoyers [Fri, 10 Feb 2023 20:46:04 +0000 (15:46 -0500)] 
Fix: join worker thread in call_rcu_data_free

When freeing the call rcu descriptor, join its associated thread as well
to ensure complete teardown.

Fixes: #1317
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ic522e0466f56deca8bde519e082f3d7f99ec2e7f

21 months agoDocs: clarify grace period polling API
Jérémie Galarneau [Fri, 10 Feb 2023 19:45:39 +0000 (14:45 -0500)] 
Docs: clarify grace period polling API

Reword the existing grace period polling API documentation. The
changes are:

  - Replace "should" by "must" to express obligations,
  - Attempt to clarify "which" grace period the API allows checking for.

Change-Id: Ib3a93faeef7bcdb94ebae2d294d45925e12873a4
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
21 months agoDocument grace period polling in rcu-api.md
Mathieu Desnoyers [Fri, 10 Feb 2023 17:24:44 +0000 (12:24 -0500)] 
Document grace period polling in rcu-api.md

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I74631072d19cbe1212be6d1ab4f08778d59f67dd

21 months agoImplement poll rcu stress test in rcutorture
Mathieu Desnoyers [Fri, 10 Feb 2023 14:08:04 +0000 (09:08 -0500)] 
Implement poll rcu stress test in rcutorture

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I7ee6c78dfc6464494ebb6ee4cbba586c4c57a4bf

21 months agourcu-memb,mb,signal: Implement grace period polling
Mathieu Desnoyers [Thu, 2 Feb 2023 19:32:15 +0000 (14:32 -0500)] 
urcu-memb,mb,signal: Implement grace period polling

Implement a grace period polling mechanism for each urcu flavor. Its use
is documented in README.md.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ibd4642f2821ecd55ce40b9372d2be7ab451f9644

21 months agoFix: auto-resize hash table destroy deadlock
Mathieu Desnoyers [Fri, 3 Feb 2023 19:11:50 +0000 (14:11 -0500)] 
Fix: auto-resize hash table destroy deadlock

Fix a deadlock for auto-resize hash tables when cds_lfht_destroy
is called with RCU read-side lock held.

Example stack track of a hang:

  Thread 2 (Thread 0x7f21ba876700 (LWP 26114)):
  #0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
  #1  0x00007f21beba7aa0 in futex (val3=0, uaddr2=0x0, timeout=0x0, val=-1, op=0, uaddr=0x7f21bedac308 <urcu_memb_gp+8>) at ../include/urcu/futex.h:81
  #2  futex_noasync (timeout=0x0, uaddr2=0x0, val3=0, val=-1, op=0, uaddr=0x7f21bedac308 <urcu_memb_gp+8>) at ../include/urcu/futex.h:90
  #3  wait_gp () at urcu.c:265
  #4  wait_for_readers (input_readers=input_readers@entry=0x7f21ba8751b0, cur_snap_readers=cur_snap_readers@entry=0x0,
      qsreaders=qsreaders@entry=0x7f21ba8751c0) at urcu.c:357
  #5  0x00007f21beba8339 in urcu_memb_synchronize_rcu () at urcu.c:498
  #6  0x00007f21be99f93f in fini_table (last_order=<optimized out>, first_order=13, ht=0x5651cec75400) at rculfhash.c:1489
  #7  _do_cds_lfht_shrink (new_size=<optimized out>, old_size=<optimized out>, ht=0x5651cec75400) at rculfhash.c:2001
  #8  _do_cds_lfht_resize (ht=ht@entry=0x5651cec75400) at rculfhash.c:2023
  #9  0x00007f21be99fa26 in do_resize_cb (work=0x5651e20621a0) at rculfhash.c:2063
  #10 0x00007f21be99dbfd in workqueue_thread (arg=0x5651cec74a00) at workqueue.c:234
  #11 0x00007f21bd7c06db in start_thread (arg=0x7f21ba876700) at pthread_create.c:463
  #12 0x00007f21bd4e961f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

  Thread 1 (Thread 0x7f21bf285300 (LWP 26098)):
  #0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
  #1  0x00007f21be99d8b7 in futex (val3=0, uaddr2=0x0, timeout=0x0, val=-1, op=0, uaddr=0x5651d8b38584) at ../include/urcu/futex.h:81
  #2  futex_async (timeout=0x0, uaddr2=0x0, val3=0, val=-1, op=0, uaddr=0x5651d8b38584) at ../include/urcu/futex.h:113
  #3  futex_wait (futex=futex@entry=0x5651d8b38584) at workqueue.c:135
  #4  0x00007f21be99e2c8 in urcu_workqueue_wait_completion (completion=completion@entry=0x5651d8b38580) at workqueue.c:423
  #5  0x00007f21be99e3f9 in urcu_workqueue_flush_queued_work (workqueue=0x5651cec74a00) at workqueue.c:452
  #6  0x00007f21be9a0c83 in cds_lfht_destroy (ht=0x5651d8b2fcf0, attr=attr@entry=0x0) at rculfhash.c:1906

This deadlock is easy to reproduce when rapidly adding a large number of
entries in the cds_lfht, removing them, and calling cds_lfht_destroy().

The deadlock will occur if the call to cds_lfht_destroy() takes place
while a resize of the hash table is ongoing.

Fix this by moving the teardown of the lfht worker thread to libcds
library destructor, so it does not have to wait on synchronize_rcu from
a resize callback from within a read-side critical section. As a
consequence, the atfork callbacks are left registered within each urcu
flavor for which a resizeable hash table is created until the end of the
executable lifetime.

The other part of the fix is to move the hash table destruction to the
worker thread for auto-resize hash tables. This prevents having to wait
for resize callbacks from RCU read-side critical section. This is
guaranteed by the fact that the worker thread serializes previously
queued resize callbacks before the destroy callback.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: If8b1c3c8063dc7b9846dc5c3fc452efd917eab4d

21 months agoFix building on MSYS2
Christopher Ng [Fri, 3 Feb 2023 12:16:06 +0000 (12:16 +0000)] 
Fix building on MSYS2

Update cygwin libtool config in `configure.ac` to match MSYS2 build
environments as well. MSYS2 is also a Windows build environment that
produces DLLs.

Signed-off-by: Christopher Ng <facboy@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I48ca648123fd40b8003c72c0447c70a8b4bde6d6

23 months agorculfhash: Include rculfhash-internal.h from local directory
Gavin Ray [Mon, 5 Dec 2022 02:07:17 +0000 (02:07 +0000)] 
rculfhash: Include rculfhash-internal.h from local directory

Use double quotes rather than angle brackets to include this local
header file. This fixes build scenarios where the liburcu build is used
from cmake.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iad6c9765ecc409c8df3a659975c97a3c068d5c0a

2 years agoRemove "Darwin" from "should also work on list"
Mathieu Desnoyers [Thu, 10 Nov 2022 15:26:39 +0000 (10:26 -0500)] 
Remove "Darwin" from "should also work on list"

MacOS is already covered in the "tested on" list, and standalone Darwin
is relatively niche (http://www.puredarwin.org/).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie421d99f5992a84f3639e86089b432be21337a9c

2 years agoMerge branch 'adah1972-improve-md'
Mathieu Desnoyers [Tue, 1 Nov 2022 14:58:15 +0000 (10:58 -0400)] 
Merge branch 'adah1972-improve-md'

Change-Id: I7904f3cee368428a21fdd84d07c395e232f5cfdb

2 years agoAdd semicolons at the end of function prototypes
Wu Yongwei [Tue, 1 Nov 2022 14:19:02 +0000 (22:19 +0800)] 
Add semicolons at the end of function prototypes

This pleases the syntax highlighter for multi-line code. Also, other
files already have semicolons.

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
2 years agoWrap a file name in backticks
Wu Yongwei [Tue, 1 Nov 2022 14:17:32 +0000 (22:17 +0800)] 
Wrap a file name in backticks

For consistency.

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
2 years agoWrap command-line options in backticks
Wu Yongwei [Tue, 1 Nov 2022 14:11:02 +0000 (22:11 +0800)] 
Wrap command-line options in backticks

For consistency and visual clarity.

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
2 years agoFix a wrong format
Wu Yongwei [Tue, 1 Nov 2022 14:06:17 +0000 (22:06 +0800)] 
Fix a wrong format

TAB should not be used, and a blank line is necessary.

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
2 years agoWrap URLs in angle brackets
Wu Yongwei [Tue, 1 Nov 2022 13:58:38 +0000 (21:58 +0800)] 
Wrap URLs in angle brackets

Otherwise special symbols (like underscores) may again cause issues in
some Markdown editors.

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
2 years agoFix Markdown issues
Wu Yongwei [Tue, 1 Nov 2022 13:48:24 +0000 (21:48 +0800)] 
Fix Markdown issues

`_`, `<`, and `>` are special characters in Markdown, and need to be
escaped except in code blocks.  So backticks or backslahes are used to
fix the apparent issues, which caused wrong rendering.

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
2 years agoFix: Always check pthread_create for failures
Eric Wong [Sun, 2 Oct 2022 16:13:43 +0000 (12:13 -0400)] 
Fix: Always check pthread_create for failures

pthread_create may fail with EAGAIN (which is no fault of the
programmer), so don't allow the check to be compiled out.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ia2695ea6953b589ac8ab8b444fb668daee06a614

2 years agoDisable signals in URCU background threads
Mathieu Desnoyers [Fri, 23 Sep 2022 17:55:03 +0000 (13:55 -0400)] 
Disable signals in URCU background threads

Applications using signalfd depend on signals being blocked in all
threads of the process, otherwise threads with unblocked signals
can receive them and starve the signalfd.

While some threads in URCU do block signals (e.g. workqueue
worker for rculfhash), the call_rcu, defer_rcu, and rculfhash
partition_resize_helper threads do not.

Always block all signals before creating threads, and only unblock
SIGRCU when registering a urcu-signal thread. Restore the SIGRCU
signal to its pre-registration blocked state on unregistration.

For rculfhash, cds_lfht_worker_init can be removed, because its only
effect is to block all signals except SIGRCU. Blocking all signals is
already done by the workqueue code, and unbloking SIGRCU is now done by
the urcu signal flavor thread regisration.

Co-developed-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: If78346b15bdc287417b992a8963098c6ea0dc7d2

2 years agoFix: futex.h: include headers outside extern C
Mathieu Desnoyers [Wed, 17 Aug 2022 20:41:47 +0000 (16:41 -0400)] 
Fix: futex.h: include headers outside extern C

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ia8aac42e74d1d401cd893a30afb9cbde29a993d5

2 years agoFix: add missing unused attribute to _rcu_dereference
Mathieu Desnoyers [Wed, 17 Aug 2022 19:32:38 +0000 (15:32 -0400)] 
Fix: add missing unused attribute to _rcu_dereference

Reproduced with gcc-8, gcc-10, gcc-11 in O2:

14:39:19 In file included from ../../include/urcu/pointer.h:39,
14:39:19                  from ../../include/urcu-pointer.h:1,
14:39:19                  from ../../include/urcu/rcuhlist.h:30,
14:39:19                  from ../../include/urcu/cds.h:28,
14:39:19                  from test_build.c:30:
14:39:19 test_build.c: In function ‘test_build_rcu_dereference’:
14:39:19 ../../include/urcu/static/pointer.h:102:55: warning: variable ‘_________p0’ set but not used [-Wunused-but-set-variable]
14:39:19   102 |                                         __typeof__(p) _________p0 = { 0 };              \
14:39:19       |                                                       ^~~~~~~~~~~
14:39:19 ../../include/urcu/pointer.h:47:33: note: in expansion of macro ‘_rcu_dereference’
14:39:19    47 | #define rcu_dereference         _rcu_dereference
14:39:19       |                                 ^~~~~~~~~~~~~~~~
14:39:19 test_build.c:133:9: note: in expansion of macro ‘rcu_dereference’
14:39:19   133 |         rcu_dereference(opaque_const);
14:39:19       |         ^~~~~~~~~~~~~~~
14:39:19 mv -f .deps/test_urcu_multiflavor_single_unit_dynlink_cxx-test_urcu_multiflavor_single_unit_cxx.Tpo .deps/test_urcu_multiflavor_single_unit_dynlink_cxx-test_urcu_multiflavor_single_unit_cxx.Po
14:39:19 ../../include/urcu/static/pointer.h:102:55: warning: variable ‘_________p0’ set but not used [-Wunused-but-set-variable]
14:39:19   102 |                                         __typeof__(p) _________p0 = { 0 };              \
14:39:19       |                                                       ^~~~~~~~~~~
14:39:19 ../../include/urcu/pointer.h:47:33: note: in expansion of macro ‘_rcu_dereference’
14:39:19    47 | #define rcu_dereference         _rcu_dereference
14:39:19       |                                 ^~~~~~~~~~~~~~~~
14:39:19 test_build.c:135:9: note: in expansion of macro ‘rcu_dereference’
14:39:19   135 |         rcu_dereference(clear_const);
14:39:19       |         ^~~~~~~~~~~~~~~

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: If3a78c2ec1c3ae0cab1ea5f9d40ede4e30f9bc81

2 years agoFix: change method used by _rcu_dereference to strip type constness
Simon Marchi [Wed, 17 Aug 2022 15:24:25 +0000 (11:24 -0400)] 
Fix: change method used by _rcu_dereference to strip type constness

Commit 1e41ec3b07e4 ("Make temporary variable in _rcu_dereference
non-const") used the trick to add 0 to the pointer passed as a parameter
to the macro to get rid of its constness, should it be const (with the
end goal of avoiding compiler warnings).  This is problematic (as shown
in [1]) if it is a pointer to an opaque type though, as the compiler
cannot perform pointer arithmetic on such a pointer (even though it
wouldn't really need to here, as we add 0).

Change it to use another trick to strip away the constness, that
shouldn't hit this problem.  It was found in the same stackoverflow post
as the original trick [2].  It consists of using a statement expression
like so:

    __typeof__(({ const int foo; foo; }))

The statement expression yields a value of type `int`.  Statement
expressions are extensions to the C language, but we already use them
here.

The test_build* binaries now need to be linked against the urcu library,
otherwise they would be missing the rcu_dereference_sym symbol.

[1] https://lists.lttng.org/pipermail/lttng-dev/2022-August/030247.html
[2] https://stackoverflow.com/a/54016713

Change-Id: Ic73590ef4beaa1832161aa05a6df37e467f85116
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agoFix: remove type constness in URCU_FORCE_CAST's C++ version
Simon Marchi [Wed, 17 Aug 2022 17:11:21 +0000 (13:11 -0400)] 
Fix: remove type constness in URCU_FORCE_CAST's C++ version

The test added by the following patch wouldn't compile, when built
without _LGPL_SOURCE:

      CXX      test_build_dynlink_cxx-test_build_cxx.o
    In file included from ../../include/urcu/arch.h:25,
                     from /home/simark/src/urcu/tests/unit/test_build.c:28,
                     from /home/simark/src/urcu/tests/unit/test_build_cxx.cpp:3:
    /home/simark/src/urcu/tests/unit/test_build.c: In function ‘void test_build_rcu_dereference()’:
    /home/simark/src/urcu/include/urcu/compiler.h:85:42: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
       85 | #define URCU_FORCE_CAST(type, arg)      (reinterpret_cast<type>(arg))
          |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/urcu/include/urcu/pointer.h:71:49: note: in expansion of macro ‘URCU_FORCE_CAST’
       71 |                 __typeof__(p) _________p1 =     URCU_FORCE_CAST(__typeof__(p), \
          |                                                 ^~~~~~~~~~~~~~~
    /home/simark/src/urcu/tests/unit/test_build.c:133:9: note: in expansion of macro ‘rcu_dereference’
      133 |         rcu_dereference(opaque_const);
          |         ^~~~~~~~~~~~~~~

The compiler complains that we do a cast to a const type, equivalent to:

  reinterpret_cast<const int>(arg)

... and that the const is meaningless in this context.

Use std::remove_cv to strip away any const or volatile qualifiers from
the type (using a volatile type would result in the same warning).

Change-Id: I94e79fcccfc2108021752f65977e1548084c646a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agoMove extern "C" down in include/urcu/urcu-bp.h
Simon Marchi [Wed, 17 Aug 2022 16:49:50 +0000 (12:49 -0400)] 
Move extern "C" down in include/urcu/urcu-bp.h

A following patch adds a <type_traits> include in
urcu/compiler.h.  However, compiler.h gets included by urcu/pointer.h,
which gets included by urcu/urcu-bp.h inside an extern "C" scope.
Including the C++ header file <type_traits> inside an extern "C" scope
doesn't work:

    In file included from /home/simark/src/urcu/include/urcu/compiler.h:25,
                     from /home/simark/src/urcu/include/urcu/pointer.h:29,
                     from /home/simark/src/urcu/include/urcu/urcu-bp.h:58,
                     from /home/simark/src/urcu/include/urcu-bp.h:2,
                     from /home/simark/src/urcu/tests/unit/test_urcu_multiflavor-bp.c:28,
                     from /home/simark/src/urcu/tests/unit/test_urcu_multiflavor-bp_cxx.cpp:3:
    /usr/include/c++/12.1.1/type_traits:44:3: error: template with C linkage
       44 |   template<typename _Tp>
          |   ^~~~~~~~
    /home/simark/src/urcu/include/urcu/urcu-bp.h:41:1: note: ‘extern "C"’ linkage started here
       41 | extern "C" {
          | ^~~~~~~~~~

Move the extern "C" in urcu-bp.h down, so that the includes are not
inside it.  Each header file is responsible to use extern "C" where
relevant, and we should avoid including files inside such a scope.

Change-Id: I42bdfa6ab445e8c40f5bcac1c1ae0786d443626c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agofix: ifdef linux specific cpu count compat
Michael Jeanson [Mon, 15 Aug 2022 15:11:54 +0000 (11:11 -0400)] 
fix: ifdef linux specific cpu count compat

Expand the '#ifdef __linux__' block in src/compat-cpu.h to all static
inline functions related to sysfs since they are only useful on Linux
and fail to build on some non-Linux platforms. This issue was reported
on QNX.

The corresponding unit tests have to be skipped on non-Linux platforms.

Thanks to Elad Lahav <e2lahav@gmail.com> for reporting this issue.

Change-Id: I17c88a9a2fb5b9be6cf5325234a18ff40788cd09
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agoAdd unit tests for possible_cpus_array_len
Michael Jeanson [Mon, 1 Aug 2022 15:51:03 +0000 (11:51 -0400)] 
Add unit tests for possible_cpus_array_len

Change-Id: Ida3affbc7021c96bbc8941a96455ef93030c5c96
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agofix: sysconf(_SC_NPROCESSORS_CONF) can be less than max cpu id
Michael Jeanson [Wed, 27 Jul 2022 14:44:00 +0000 (10:44 -0400)] 
fix: sysconf(_SC_NPROCESSORS_CONF) can be less than max cpu id

We rely on sysconf(_SC_NPROCESSORS_CONF) to get the maximum possible
number of CPUs that can be attached to the system for the lifetime of an
application.

As such we expect that the highest possible CPU id would be one less
than the number returned by sysconf(_SC_NPROCESSORS_CONF) which is
unfortunatly not always the case and can vary across libc
implementations and versions.

Glibc up to 2.35 will count the number of "cpuX" directories in
"/sys/devices/system/cpu" which doesn't include CPUS that were
hot-unplugged.

This information is however provided by the Linux kernel in
"/sys/devices/system/cpu/possible" in the form of a mask listing all the
CPUs that could possibly be hot-plugged in the system.

This patch replaces sysconf(_SC_NPROCESSORS_CONF) with an internal
function that first tries parsing the possible CPU mask to extract the
highest possible value and if this fails fallback to the previous
behavior.

Change-Id: I68dfed42ebbab02728a02eeefd4a395a22bb1bea
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agoFix: revise obsolete command in README.md
Shao-Tse Hung [Tue, 2 Aug 2022 17:44:00 +0000 (01:44 +0800)] 
Fix: revise obsolete command in README.md

The obsolete command `make bench` was replaced by `make short_bench` and
`make long_bench` in 2015.  However, this command wasn't revised in
README, so I follow the previous commit and rewrite it.

Signed-off-by: Shao-Tse Hung <ccs100203@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I92fa6cc3937b0a65b0a005ce6bb1fe3d2b3250ab

2 years agoFix: workqueue: remove unused variable "ret"
Mathieu Desnoyers [Mon, 27 Jun 2022 15:22:08 +0000 (11:22 -0400)] 
Fix: workqueue: remove unused variable "ret"

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I57eddb10fd90b680ee71966e6eb6a327d8c51063

2 years agoFix: urcu-qsbr: futex wait: handle spurious futex wakeups
Mathieu Desnoyers [Wed, 22 Jun 2022 20:49:11 +0000 (16:49 -0400)] 
Fix: urcu-qsbr: futex wait: handle spurious futex wakeups

Observed issue
==============

The urcu-qsbr wait_gp() implements a futex wait/wakeup scheme identical to
the workqueue code, which has an issue with spurious wakeups.

A spurious wakeup on wait_gp can cause wait_gp to return with a
urcu_qsbr_gp.futex state of -1, which is unexpected. It would cause the
following loops in wait_for_readers() to decrement the
urcu_qsbr_gp.futex to values below -1, thus actively using CPU as values
will be decremented to very low negative values until it reaches 0
through underflow, or until the input_readers list is found to be empty.
The state is restored to 0 when the input_readers list is found to be
empty, which restores the futex state to a correct state for the
following calls to wait_for_readers().

This issue will cause spurious unexpected high CPU use, but will not
lead to data corruption.

Cause
=====

From futex(5):

       FUTEX_WAIT
              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.

Solution
========

We therefore need to validate whether the value differs from -1 in
user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks
===============

None.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I87f7cd3b02820cefe850c3bdb8da27fb2f9be9b2

2 years agoFix: urcu: futex wait: handle spurious futex wakeups
Mathieu Desnoyers [Wed, 22 Jun 2022 20:34:02 +0000 (16:34 -0400)] 
Fix: urcu: futex wait: handle spurious futex wakeups

Observed issue
==============

The urcu wait_gp() implements a futex wait/wakeup scheme identical to
the workqueue code, which has an issue with spurious wakeups.

A spurious wakeup on wait_gp can cause wait_gp to return with a
rcu_gp.futex state of -1, which is unexpected. It would cause the
following loops in wait_for_readers() to decrement the
rcu_gp.futex to values below -1, thus actively using CPU as values
will be decremented to very low negative values until it reaches 0
through underflow, or until the input_readers list is found to be empty.
The state is restored to 0 when the input_readers list is found to be
empty, which restores the futex state to a correct state for the
following calls to wait_for_readers().

This issue will cause spurious unexpected high CPU use, but will not
lead to data corruption.

Cause
=====

From futex(5):

       FUTEX_WAIT
              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.

Solution
========

We therefore need to validate whether the value differs from -1 in
user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks
===============

None.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I83942e24c32e77395ff25b466f1b1640422b9eb5

2 years agoFix: urcu-wait: futex wait: handle spurious futex wakeups
Mathieu Desnoyers [Wed, 22 Jun 2022 20:44:12 +0000 (16:44 -0400)] 
Fix: urcu-wait: futex wait: handle spurious futex wakeups

Observed issue
==============

The urcu-wait urcu_adaptative_busy_wait() implements a futex wait/wakeup
scheme similar to the workqueue code, which has an issue with spurious
wakeups.

A spurious wakeup on urcu_adaptative_busy_wait can cause
urcu_adaptative_busy_wait to reach label skip_futex_wait with a
wait->state state of URCU_WAIT_WAITING, which is unexpected. It would
cause busy-waiting on URCU_WAIT_TEARDOWN state to start early. The
wait-teardown stage is done with URCU_WAIT_ATTEMPTS active attempts,
following by attempts spaced by 10ms sleeps. I do not expect that these
spurious wakeups will cause user-observable effects other than being
slightly less efficient that it should be.

urcu-wait is used by all urcu flavor's synchronize_rcu() to implement
the grace period batching scheme.

This issue will cause spurious unexpected high CPU use, but will not
lead to data corruption.

Cause
=====

From futex(5):

       FUTEX_WAIT
              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.

Solution
========

We therefore need to validate whether the value differs from
URCU_WAIT_WAITING in user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks
===============

None.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I8e9586597f091efc633f3310a68d18b0bd8de1e0

2 years agoFix: defer_rcu: futex wait: handle spurious futex wakeups
Mathieu Desnoyers [Wed, 22 Jun 2022 20:46:50 +0000 (16:46 -0400)] 
Fix: defer_rcu: futex wait: handle spurious futex wakeups

Observed issue
==============

The urcu-defer wait_defer() implements a futex wait/wakeup scheme identical to
the workqueue code, which has an issue with spurious wakeups.

A spurious wakeup on wait_defer can cause wait_defer to return with a
defer_thread_futex state of -1, which is unexpected. It would cause the
following loops in thr_defer() to decrement the defer_thread_futex to
values below -1, thus actively using CPU as values will be decremented
to very low negative values until it reaches 0 through underflow, or
until callbacks are eventually queued. The state is restored to 0 when
callbacks are found, which restores the futex state to a correct state
for the following calls to wait_defer().

This issue will cause spurious unexpected high CPU use, but will not
lead to data corruption.

Cause
=====

From futex(5):

       FUTEX_WAIT
              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.

Solution
========

We therefore need to validate whether the value differs from -1 in
user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks
===============

None.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id9c104c0bb77cc306f0b8fbf0b924bdda2aaaf4c

2 years agoFix: call_rcu: futex wait: handle spurious futex wakeups
Mathieu Desnoyers [Wed, 22 Jun 2022 20:38:06 +0000 (16:38 -0400)] 
Fix: call_rcu: futex wait: handle spurious futex wakeups

Observed issue
==============

The urcu call_rcu() and rcu_barrier() each implement a futex wait/wakeup
scheme identical to the workqueue code, which has an issue with spurious
wakeups.

* call_rcu

A spurious wakeup on call_rcu_wait can cause call_rcu_wait to return
with a crdp->futex state of -1, which is unexpected. It would cause the
following loops in call_rcu_thread() to decrement the crdp->futex to
values below -1, thus actively using CPU time as values will be
decremented to very low negative values until the futex value underflows
back to 0. The state is *not* restored to 0 when the callback list is
found to be non-empty, so this unexpected state will persist until the
crdp->futex state underflows back to 0, or until the call_rcu_thread is
stopped. What prevents this from having too much user-observable effects
is that the call rcu thread has a 10ms sleep between loops, to favor
batching of callbacks. Therefore, rather than being a purely 100% active
busy-wait, this scenario leads to a busy-wait which is paced by 10ms
sleeps.

Therefore the observed issue will be that the call_rcu_thread will
unexpectedly wake up the CPU each 10ms after this spurious wakeup
happens.

* rcu_barrier

A spurious wakeup on call_rcu_completion_wait can cause
call_rcu_completion_wait to return with a completion->futex state of -1,
which is unexpected. It would cause the following loops in rcu_barrier()
to decrement the completion->futex to values below -1, thus actively
using CPU time as values will be decremented to very low negative values
until either the barrier count reaches 0 or until the futex value
underflows to 0.

Therefore the observed issue will be that rcu_barrier() will
unexpectedly use a lot of CPU time when this spurious wakeup happens.

These issues will cause spurious unexpected high CPU use, but will not
lead to data corruption.

Cause
=====

From futex(5):

       FUTEX_WAIT
              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.

Solution
========

We therefore need to validate whether the value differs from -1 in
user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks
===============

None.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I3e625f1689462f8eb9f1223b5b24b1a754bad324

2 years agoFix: workqueue: futex wait: handle spurious futex wakeups
Mathieu Desnoyers [Wed, 22 Jun 2022 20:28:53 +0000 (16:28 -0400)] 
Fix: workqueue: futex wait: handle spurious futex wakeups

Observed issue
==============

The workqueue thread futex_wait() returns with a workqueue->futex state
of -1, which is unexpected. In this situation, the workqueue thread is
observed to use 99% of CPU as workqueue->futex values are decremented to
very low negative values while the workqueue is empty.

This issue will cause spurious unexpected high CPU use, but will not
lead to data corruption.

Cause
=====

From futex(5):

       FUTEX_WAIT
              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.

Solution
========

We therefore need to validate whether the value differs from -1 in
user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks
===============

None.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id024e7d3b2dab75d30fc01280fd27e5f2d8af0d1

2 years agoFix: Use %lu rather than %ld to print count
yaowenbin1 [Thu, 9 Jun 2022 03:08:25 +0000 (11:08 +0800)] 
Fix: Use %lu rather than %ld to print count

In ht_count_del function, the type of count variable is defined as unsigned long,
so use %lu rather than %ld to print it.

Signed-off-by: yaowenbin1 <yaowenbin1@huawei.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie2701fa0a8170b05532429b34e0f798e6f27139b

2 years agoUpdate ABI definition files
Michael Jeanson [Tue, 12 Apr 2022 20:32:18 +0000 (16:32 -0400)] 
Update ABI definition files

Update all ABI definition files with artefacts built on an Ubuntu 18.04
x86_64 to allow straightforward comparision with artefacts from our CI
system.

Change-Id: I916db6fb3e8a44e36047186ec4519e94acbb5939
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agoBump version current and age
Mathieu Desnoyers [Fri, 22 Apr 2022 18:59:03 +0000 (14:59 -0400)] 
Bump version current and age

The symbol cds_lfht_node_init_deleted was added, so increment both
current and age.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id83f39778cb35871914c86f05a2c36d02d28b7bf

2 years agoalpha: allocate membarrier system call number
Michael Jeanson [Tue, 1 Mar 2022 20:41:53 +0000 (15:41 -0500)] 
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>
2 years agoBump version to 0.14.0-pre
Michael Jeanson [Tue, 12 Apr 2022 19:48:22 +0000 (15:48 -0400)] 
Bump version to 0.14.0-pre

Change-Id: I144d5a982867bf8d17144f679427e6636a0ed483
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agoImproved test framework
Michael Jeanson [Mon, 13 Sep 2021 20:13:44 +0000 (16:13 -0400)] 
Improved test framework

This is based on the babeltrace / librseq test framework with the
objective of standardising across projects.

Regroup all the configure detected values relevant to the test suite in
a single generated file. This file will be automatically sourced by the
test suite in most scenarios but can also be sourced in the shell of a
user.

 * All user overridable variables start with 'URCU_TESTS_'.
 * The priority for variables is :
     Environment -> env.sh -> utils.sh (defaults).
 * A user can source 'env.sh', override some of the values and manually
   run test scripts.
 * The test suite can run without an 'env.sh' file present.

Change-Id: Id94f7085ed1ea0e30207856cf1594ca30585536c
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agorculfhash: introduce cds_lfht_node_init_deleted
Mathieu Desnoyers [Mon, 10 Jan 2022 20:35:53 +0000 (15:35 -0500)] 
rculfhash: introduce cds_lfht_node_init_deleted

Allow initializing lfht node to "removed" state to allow querying
whether the node is published in a hash table before it is added to the
hash table and after it has been removed from the hash table.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I6e364a3ea076f33e34b4c63c7b23be22b35e9bb1

2 years agoFix: changelog: v0.13.0 was released in 2021
Mathieu Desnoyers [Wed, 5 Jan 2022 20:08:17 +0000 (15:08 -0500)] 
Fix: changelog: v0.13.0 was released in 2021

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iab4b54ac1749a40b9a49bede551afdf24d6d3b47

2 years agocleanup: i386 arch detection
Michael Jeanson [Tue, 7 Dec 2021 20:22:23 +0000 (15:22 -0500)] 
cleanup: i386 arch detection

On x86-32, '__i386__' or '__i386' is always defined regardless of the
march / mtune value, simplify the detection code.

Change-Id: Icadabc60554b58d5d2611ec58f3efff9aa067dac
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 years agofix: properly detect 'cmpxchg' on x86-32
Michael Jeanson [Tue, 7 Dec 2021 19:42:26 +0000 (14:42 -0500)] 
fix: properly detect 'cmpxchg' on x86-32

We wrongly assumed that on x86-32 when '__i386__' is defined but none of
'__i486__', '__i586__' or '__i686__' that the target arch is a literal
i386 cpu without the cmpxchg instructions. However, when building with
'-march=core2' we get '__i386__' but none of the others even if the arch
is newer than an i686.

Change the compat code to use the '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4'
builtin define to detect an x86-32 system without the cmpxchg
instructions.

Since this builtin define was introduced in GCC 4.3 and Clang 3.3,
building with older compilers on any x86-32 system will enable the
compat layer regardless of the availability of the instructions.

Change-Id: I8329431e55d778405b2ca7007d90c2c6e5cdd426
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agofix: use urcu-tls compat with c++ compiler
Michael Jeanson [Thu, 18 Nov 2021 20:08:53 +0000 (15:08 -0500)] 
fix: use urcu-tls compat with c++ compiler

  * Initialize all fields of 'struct urcu_tls' to avoid :

    sorry, unimplemented: non-trivial designated initializers not supported

  * Cast void* to proper type pointers to avoid :

    error: invalid conversion from ‘void*’ to ...

Change-Id: I654f924324cda2eaea723f4a0759d706b2a2bf40
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoFix typo
Dimitris Apostolou [Sat, 13 Nov 2021 11:16:03 +0000 (13:16 +0200)] 
Fix typo

Signed-off-by: Dimitris Apostolou <dimitris.apostolou@icloud.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iaefe3b69b228773463fe93b2d9ddd3860caa83a8

3 years agofix: remove autoconf features default value in help message
Michael Jeanson [Fri, 12 Nov 2021 18:13:59 +0000 (13:13 -0500)] 
fix: remove autoconf features default value in help message

The default values of yes|no can be confusing combined with the
--enable / --disable switches of autoconf, remove them from the help
message.

Change-Id: Id9c4036b2fa50e1144a43f68f71a24f0c11434eb
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agofix: add missing pkgconfig file for memb flavour lib
Michael Jeanson [Wed, 22 Sep 2021 20:06:23 +0000 (16:06 -0400)] 
fix: add missing pkgconfig file for memb flavour lib

We ship a pkg-config file for each urcu flavour library except the
latest introduced 'memb'.

Change-Id: If222949941d968f63b07616776440931657aa6db
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoCleanup: Tests: Remove useless pre-C99 compatibility code from tap.h
Mathieu Desnoyers [Tue, 14 Sep 2021 18:13:37 +0000 (14:13 -0400)] 
Cleanup: Tests: Remove useless pre-C99 compatibility code from tap.h

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I02488c88013f6a7c60205219d15850ef8b04271e

3 years agoDocument C99 and C++11 requirement in README.md
Mathieu Desnoyers [Tue, 14 Sep 2021 18:15:41 +0000 (14:15 -0400)] 
Document C99 and C++11 requirement in README.md

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ida30f72f57ce6a501d694c61eb9eb7fb3e3b5be3

3 years agoAlways use '__thread' for Thread local storage except on MSVC
Michael Jeanson [Tue, 14 Sep 2021 14:41:08 +0000 (10:41 -0400)] 
Always use '__thread' for Thread local storage except on MSVC

Use the GCC extension '__thread' [1] for Thread local storage on all C
and C++ compilers except MSVC.

While C11 and C++11 respectively offer '_Thread_local' and
'thread_local' as potentialy faster implementations, they offer no
guarantees of compatibility when used in a library interface which might
be used by both C and C++ client code.

[1] https://gcc.gnu.org/onlinedocs/gcc/Thread-Local.html

Change-Id: If4fe8bcdbda24b21dedf382112bd5c5f836c00c8
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoFix: powerpc32: transparent unions alter calling convention
Mathieu Desnoyers [Mon, 13 Sep 2021 20:57:02 +0000 (16:57 -0400)] 
Fix: powerpc32: transparent unions alter calling convention

On powerpc32, transparent unions have an impact on the calling
convention used for the argument, as they use the calling convention of
the first field of the union rather than the union itself. On powerpc32,
the calling convention for a union is that the register has a pointer to
the union, which differs from the calling convention of its first field
(which is a pointer in this case).

"[...] the argument is passed to the function using the calling
conventions of the first member of the transparent union, not the
calling conventions of the union itself. All members of the union must
have the same machine representation; this is necessary for this
argument passing to work properly." [1]

Therefore, use a transparent union for c++ so c++ compilers can emit
caller code with a compatible stack layout. The "ignored attribute"
warning emitted by clang appears to be only for architectures where the
calling convention is not affected by the presence of transparent union
attribute. Therefore, simply silence this warning.

Link: https://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Type-Attributes.html
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I07182dd4ed37a3f61a226fb199bc98c95f83bd37

3 years agofix: don't use C++ thread_local on MacOs
Michael Jeanson [Thu, 9 Sep 2021 16:11:16 +0000 (12:11 -0400)] 
fix: don't use C++ thread_local on MacOs

Recent versions of Apple's clang++ do support 'thread_local' but the
implementation generates additional helper symbols. This is a problem
when accessing an extern TLS variable in a C++ compile unit that is
provided by a C library that doesn't have those extra symbols.

Fallback to using '__thread' on MacOs.

Change-Id: I87cb5b3c9293f7bf66f7115f453b546dd793a449
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
This page took 0.054133 seconds and 4 git commands to generate.