urcu.git
20 months agoVersion 0.12.4 v0.12.4
Mathieu Desnoyers [Thu, 18 Aug 2022 19:40:59 +0000 (15:40 -0400)] 
Version 0.12.4

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

20 months agoRevert "Fix: remove type constness in URCU_FORCE_CAST's C++ version"
Mathieu Desnoyers [Thu, 18 Aug 2022 14:15:48 +0000 (10:15 -0400)] 
Revert "Fix: remove type constness in URCU_FORCE_CAST's C++ version"

This reverts commit fa85464bb1e600910e24350188341be223621ba7.

This adds a dependency on c++11, which is not present in the stable-0.12
branch README.md file.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
20 months 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

20 months 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

20 months 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.

[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>
20 months 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>
20 months 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>
20 months 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.

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>
20 months 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>
20 months 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

21 months 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

21 months 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

21 months 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

21 months 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

21 months 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

21 months 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

21 months 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

22 months 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 agoVersion 0.12.3 v0.12.3
Mathieu Desnoyers [Wed, 5 Jan 2022 19:58:58 +0000 (14:58 -0500)] 
Version 0.12.3

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

2 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>
2 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>
2 years agoMake temporary variable in _rcu_dereference non-const
Simon Marchi [Fri, 30 Jul 2021 03:06:11 +0000 (23:06 -0400)] 
Make temporary variable in _rcu_dereference non-const

When building the lttng-tools project with Ubuntu's gcc 11, I get the
following error:

      CC       agent.lo
    In file included from /tmp/lttng/include/urcu/arch.h:25,
                     from /tmp/lttng/include/urcu/uatomic.h:23,
                     from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/agent.c:11:
    /home/simark/src/lttng-tools/src/bin/lttng-sessiond/agent.c: In function ‘agent_update’:
    /tmp/lttng/include/urcu/static/pointer.h:96:33: error: argument 2 of ‘__atomic_load’ discards ‘const’ qualifier [-Werror=incompatible-pointer-types]
       96 |                                 __atomic_load(&(p), &_________p1, __ATOMIC_CONSUME);    \
          |                                 ^~~~~~~~~~~~~
    /tmp/lttng/include/urcu/compiler.h:69:70: note: in definition of macro ‘caa_container_of’
       69 |                 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
          |                                                                      ^~~
    /tmp/lttng/include/urcu/rculist.h:87:20: note: in expansion of macro ‘cds_list_entry’
       87 |         for (pos = cds_list_entry(rcu_dereference((head)->next), __typeof__(*(pos)), member); \
          |                    ^~~~~~~~~~~~~~
    /tmp/lttng/include/urcu/pointer.h:47:33: note: in expansion of macro ‘_rcu_dereference’
       47 | #define rcu_dereference         _rcu_dereference
          |                                 ^~~~~~~~~~~~~~~~
    /tmp/lttng/include/urcu/rculist.h:87:35: note: in expansion of macro ‘rcu_dereference’
       87 |         for (pos = cds_list_entry(rcu_dereference((head)->next), __typeof__(*(pos)), member); \
          |                                   ^~~~~~~~~~~~~~~
    /home/simark/src/lttng-tools/src/bin/lttng-sessiond/agent.c:1551:9: note: in expansion of macro ‘cds_list_for_each_entry_rcu’
     1551 |         cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node) {
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~

This is because the pointer passed to _rcu_dereference is const (the
pointer itself is const, IIUC, not necessarily the data it points to),
so the temporary _________p1 is also declared as const.  We therefore
can't pass a non-const pointer to it to a function that modifies it.

I applied the trick found here [1] with success to get rid of the
constness of the variable.  With this change, lttng-tools compiles
successfully with gcc 11.

There may be other spots in the headers where this would be needed, but
it is hard to spot them.  I think we would need to write some test file
that pass const pointers to all macros of the API and see if they
compile.

[1] https://stackoverflow.com/a/18067745

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ib43efa7674ecea99cec1c3fffae86829b44a97e5

2 years agoFix: x86 and s390: uatomic __hp() macro C++ support
Mathieu Desnoyers [Wed, 16 Jun 2021 14:03:48 +0000 (10:03 -0400)] 
Fix: x86 and s390: uatomic __hp() macro C++ support

C++ does not allow defining types in cast. Therefore, define the types
with typedef and use them in the __hp() macro.

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

2 years agoFix: x86 and s390: uatomic __hp() macro clang support
Mathieu Desnoyers [Tue, 15 Jun 2021 20:00:28 +0000 (16:00 -0400)] 
Fix: x86 and s390: uatomic __hp() macro clang support

The __hp macro should receive contant size arguments to support clang,
which does not implement VLA support.

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

2 years agoFix: x86 and s390 uatomic: __hp() macro warning with gcc 11
Mathieu Desnoyers [Tue, 15 Jun 2021 19:28:24 +0000 (15:28 -0400)] 
Fix: x86 and s390 uatomic: __hp() macro warning with gcc 11

The __hp() macro used in the x86 and s390 uatomic code generates the
following warning with gcc-11:

In file included from ../include/urcu/uatomic.h:27,
                 from ../include/urcu/static/wfcqueue.h:35,
                 from ../include/urcu/wfcqueue.h:133,
                 from workqueue.c:39:
workqueue.c: In function ‘workqueue_thread’:
../include/urcu/uatomic/x86.h:155:17: warning: array subscript ‘struct __uatomic_dummy[0]’ is partly outside array bounds of ‘struct cds_wfcq_tail[1]’ [-Warray-bounds]
  155 |                 __asm__ __volatile__(
      |                 ^~~~~~~
workqueue.c:184:38: note: while referencing ‘cbs_tmp_tail’
  184 |                 struct cds_wfcq_tail cbs_tmp_tail;
      |                                      ^~~~~~~~~~~~

The (previously undocumented) reason for this macro is to allow passing the
"void *" parameter as "m" or "+m" operand to the inline assembly. That
motivation was explained in commit 53b8ed6836363 ("s390 uatomic arch fix").

The out of bound access is detected by gcc because struct
__uatomic_dummy's length is quite large: an array of 10 unsigned long,
which is larger than the size pointed to by the void pointer.

So rather than using a fixed-size type, cast to a structure containing
an array of characters of a size matching the @addr input argument.

While we are at it and digging out git archeology, properly document the
__hp() macro for posterity.

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

2 years agoDocument known ABI issue in README.md
Mathieu Desnoyers [Thu, 3 Jun 2021 18:30:40 +0000 (14:30 -0400)] 
Document known ABI issue in README.md

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

2 years agofix: clock_gettime on macOs
Michael Jeanson [Fri, 7 May 2021 15:34:33 +0000 (11:34 -0400)] 
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>
2 years agoFix: rculist header: use parenthesis around macro parameters
Mathieu Desnoyers [Tue, 20 Apr 2021 20:24:26 +0000 (16:24 -0400)] 
Fix: rculist header: use parenthesis around macro parameters

The coding style followed across liburcu is to use parenthesis around
macro parameters when it would otherwise lead to unexpected results due
to priority of operators. Fix rculist.h to follow this coding style.

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

2 years agoFix: rcuhlist header: use parenthesis around macro parameters
Mathieu Desnoyers [Tue, 20 Apr 2021 20:21:53 +0000 (16:21 -0400)] 
Fix: rcuhlist header: use parenthesis around macro parameters

The coding style followed across liburcu is to use parenthesis around
macro parameters when it would otherwise lead to unexpected results due
to priority of operators. Fix rcuhlist.h to follow this coding style.

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

2 years agoFix: hlist header: use parenthesis around macro parameters
Mathieu Desnoyers [Tue, 20 Apr 2021 20:20:44 +0000 (16:20 -0400)] 
Fix: hlist header: use parenthesis around macro parameters

The coding style followed across liburcu is to use parenthesis around
macro parameters when it would otherwise lead to unexpected results due
to priority of operators. Fix hlist.h to follow this coding style.

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

2 years agoFix: list.h: use parenthesis around macro parameters, caa_container_of()
Mathieu Desnoyers [Tue, 20 Apr 2021 20:15:39 +0000 (16:15 -0400)] 
Fix: list.h: use parenthesis around macro parameters, caa_container_of()

The coding style followed across liburcu is to use parenthesis around
macro parameters when it would otherwise lead to unexpected results due
to priority of operators. Fix list.h to follow this coding style.

Use caa_container_of() for cds_list_entry rather than open-code the
pointer arithmetic.

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

2 years agoFix: hlist iteration relies on undefined behavior
Mathieu Desnoyers [Tue, 20 Apr 2021 20:07:54 +0000 (16:07 -0400)] 
Fix: hlist iteration relies on undefined behavior

Comparing an offset from an object with NULL is undefined behavior
and the compiler may assume that this is never true.

This is indeed what is observed with gcc-10 miscompiling
cds_hlist_for_each_entry_rcu_2().

Fix this by introducing cds_hlist_entry_safe() rather than open-coding
the NULL check comparisons, and move cds_hlist_for_each_entry_2()
and cds_hlist_for_each_entry_safe_2() to this scheme as well.

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

3 years agoFix: use __atomic_load() rather than atomic load explicit
Mathieu Desnoyers [Mon, 19 Apr 2021 15:21:52 +0000 (11:21 -0400)] 
Fix: use __atomic_load() rather than atomic load explicit

Use __atomic_load (gcc extension) rather than atomic load explict
(C11/C++11) for rcu_dereference because it does not require the input
type to be _Atomic. This fixes a regression with clang introduced by
commit 380f4b19052 ("Fix: use atomic load memory_order_consume for
rcu_dereference on C11/C++11").

Note that the cmm_smp_read_barrier_depends is removed when using
__ATOMIC_CONSUME because their memory ordering effect is redundant.

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

3 years agoFix: use atomic load memory_order_consume for rcu_dereference on C11/C++11
Mathieu Desnoyers [Fri, 16 Apr 2021 20:22:54 +0000 (16:22 -0400)] 
Fix: use atomic load memory_order_consume for rcu_dereference on C11/C++11

Using volatile accesses for rcu_dereference may cause compiler LTO to
generate incorrectly ordered code starting from C11/C++11.

Link: https://lists.lttng.org/pipermail/lttng-dev/2021-April/029937.html
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agofix: warnings on non-Linux platforms
Michael Jeanson [Wed, 14 Apr 2021 14:14:37 +0000 (10:14 -0400)] 
fix: warnings on non-Linux platforms

Add the relevent attributes in non-Linux wrapper code.

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

3 years agofix: HAVE_SCHED_SETAFFINITY is not defined
Michael Jeanson [Tue, 13 Apr 2021 20:19:06 +0000 (16:19 -0400)] 
fix: HAVE_SCHED_SETAFFINITY is not defined

Use '#ifdef' instead of '#if' to test if HAVE_SCHED_SETAFFINITY is
defined. Both work but using '#if' on an undefined macro will generate a
warning with '-Wundef'.

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

3 years agoAdd git review config to stable branch
Michael Jeanson [Thu, 15 Apr 2021 14:14:18 +0000 (10:14 -0400)] 
Add git review config to stable branch

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

3 years agofix: include 'sys/endian.h' on FreeBSD
Michael Jeanson [Wed, 14 Apr 2021 15:01:57 +0000 (11:01 -0400)] 
fix: include 'sys/endian.h' on FreeBSD

We need to include 'sys/endian.h' on FreeBSD to use BYTE_ORDER.

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

3 years agocleanup: explicitly mark unused parameters (-Wunused-parameter)
Michael Jeanson [Thu, 1 Apr 2021 18:39:01 +0000 (14:39 -0400)] 
cleanup: explicitly mark unused parameters (-Wunused-parameter)

Add the 'unused' attribute to function parameters that are unused to
allow turning on -Wunused-parameter and distinguish unused parameters
that are actual errors.

Change-Id: Ie585e37f9d38718543a31aee2e7ab3428cdfd0a5
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agofix: shadowed local variable (-Wshadow)
Michael Jeanson [Thu, 1 Apr 2021 17:46:18 +0000 (13:46 -0400)] 
fix: shadowed local variable (-Wshadow)

Rename local variables that are shadowed by global variables.

Change-Id: Ic60e880cb6e98d6111e6b747d9668731a156e4fa
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agocleanup: all functions have declarations (-Wmissing-prototypes)
Michael Jeanson [Thu, 1 Apr 2021 17:13:48 +0000 (13:13 -0400)] 
cleanup: all functions have declarations (-Wmissing-prototypes)

Make sure that all non-static functions have a declaration.

Change-Id: Ie1596ad4ba876183862e51508c8bd7fc0451fc5e
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoImport libtap from babeltrace
Michael Jeanson [Thu, 1 Apr 2021 15:48:43 +0000 (11:48 -0400)] 
Import libtap from babeltrace

Import the fixes to our local copy of libtap from the babeltrace
repository. This will allow enabling stricter compiler warnings down the
line.

Change-Id: I557ad39345dfaf6a08219109a5790d1bf12abb78
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoVersion 0.12.2 v0.12.2
Mathieu Desnoyers [Wed, 17 Feb 2021 19:54:01 +0000 (14:54 -0500)] 
Version 0.12.2

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agofix: exclude clang from GCC version blacklists
Michael Jeanson [Mon, 25 Jan 2021 18:36:24 +0000 (13:36 -0500)] 
fix: exclude clang from GCC version blacklists

URCU_GCC_VERSION is used to blacklist specific GCC versions with known
bugs, clang also defines these macros to an equivalent GCC version it
claims to support, so exclude it.

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

3 years agoaarch64: blacklist gcc prior to 5.1
Mathieu Desnoyers [Fri, 22 Jan 2021 20:27:35 +0000 (15:27 -0500)] 
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>
3 years agoFix: configure: support Autoconf 2.70
Jérémie Galarneau [Mon, 11 Jan 2021 21:49:22 +0000 (16:49 -0500)] 
Fix: configure: support Autoconf 2.70

The newly-released autoconf 2.70 introduces a number of breaking
changes [1] and is being rolled-out by some distros.

Amongst those changes, the AC_PROG_CC_STDC macro is marked as obsolete
and was merged into AC_PROG_CC, which we already use. On 2.70, this
results in a warning which we handle as an error.

A version check is added to invoke the AC_PROG_CC_STDC macro only when
running a pre-2.70 version of autoconf, fixing the issue.

Also, the AX_PTHREAD macro makes use of the $as_echo built-in shell
variable which no longer exists in 2.70. A patch was submitted to the
GNU Autoconf archive in March, but there have been no signs of life
given since then [2].

As such, our local copy is updated to the latest version and the patch
(which looks fairly straight-forward / safe) is applied. This should
minimize changes once we go back to an "official" version of the macro.

[1] https://lwn.net/Articles/839395/
[2] https://savannah.gnu.org/patch/?9906

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id57ad87e63c2d398e3d8b81129f9b867b878e01f

3 years agofix: bump tests thread limit to 4096
Michael Jeanson [Wed, 9 Dec 2020 17:05:31 +0000 (12:05 -0500)] 
fix: bump tests thread limit to 4096

Machines with more than 128 CPUs are becomming more common. A
future-proof fix here would be to dynamically allocate the array, but in
the meantime bump the limit to 4096 to fix the problem on a 160 CPUs
ppc64el system where this was reported.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ib3cb5d8cb4515e6f626be33c2685fa38cb081782

3 years agocleanup: Improve wording of CONFIG_RCU_DEBUG description
Michael Jeanson [Tue, 17 Nov 2020 20:22:46 +0000 (15:22 -0500)] 
cleanup: Improve wording of CONFIG_RCU_DEBUG description

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agofix: explicitly include urcu/config.h in files using CONFIG_RCU_ defines
Michael Jeanson [Tue, 17 Nov 2020 20:22:24 +0000 (15:22 -0500)] 
fix: explicitly include urcu/config.h in files using CONFIG_RCU_ defines

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoFix typo in README.md
Shuo Wang [Mon, 16 Nov 2020 12:24:46 +0000 (20:24 +0800)] 
Fix typo in README.md

Signed-off-by: Shuo Wang <wangshuo47@huawei.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agofix: add -lurcu-common to pkg-config libs for each flavor
Michael Jeanson [Fri, 30 Oct 2020 19:39:56 +0000 (15:39 -0400)] 
fix: add -lurcu-common to pkg-config libs for each flavor

The urcu-common library contains common code like the write-free queue
and compat code, each urcu flavor library is dynamicly linked with it.

Most but not all toolchains will automatically link an executable with a
transitive depency of an explicitly linked library if said binary uses a
symbol from the transitive dependency.

Since this behavior is not present in all toolchains, add
'-lurcu-common' to the 'Libs' field of each flavors pkg-config file so
that executables using symbols from urcu-common can be reliably linked
using pkg-config.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agocall_rcu: Fix race between rcu_barrier() and call_rcu_data_free()
Paul E. McKenney [Thu, 22 Oct 2020 22:30:21 +0000 (15:30 -0700)] 
call_rcu: Fix race between rcu_barrier() and call_rcu_data_free()

The current code can lose RCU callbacks at shutdown time, which can
result in hangs.  This lossage can happen as follows:

o       A thread invokes call_rcu_data_free(), which executes up through
        the wake_call_rcu_thread().  At this point, the call_rcu_data
        structure has been drained of callbacks, but is still on the
        call_rcu_data_list.  Note that this thread does not hold the
        call_rcu_mutex.

o       Another thread invokes rcu_barrier(), which traverses the
        call_rcu_data_list under the protection of call_rcu_mutex,
        a list which still includes the above newly drained structure.
        This thread therefore adds a callback to the newly drained
        call_rcu_data structure.  It then releases call_rcu_mutex and
        enters a mystifying loop that does futex stuff.

o       The first thread finishes executing call_rcu_data_free(),
        which acquires call_rcu_mutex just long enough to remove the
        newly drained call_rcu_data structure from call_rcu_data_list.
        Which causes one of the rcu_barrier() invocation's callbacks to
        be leaked.

o       The second thread's rcu_barrier() invocation never returns
        resulting in a hang.

This commit therefore changes call_rcu_data_free() to acquire
call_rcu_mutex before checking the call_rcu_data structure for callbacks.
In the case where there are no callbacks, call_rcu_mutex is held across
both the check and the removal from call_rcu_data_list, thus preventing
rcu_barrier() from adding a callback in the meantime.  In the case where
there are callbacks, call_rcu_mutex must be momentarily dropped across
the call to get_default_call_rcu_data(), which can itself acquire
call_rcu_mutex.  This momentary drop is not a problem because any
callbacks that rcu_barrier() might queue during that period of time will
be moved to the default call_rcu_data structure, and the lock will be
held across the full time including moving those callbacks and removing
the call_rcu_data structure that was passed into call_rcu_data_free()
from call_rcu_data_list.

With this fix, a several-hundred-CPU test successfully completes more
than 5,000 executions.  Without this fix, it fails within a few tens
of executions.  Although the failures happen more quickly on larger
systems, in theory this could happen on a single-CPU system, courtesy
of preemption.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: <lttng-dev@lists.lttng.org>
Cc: <linux-kernel@vger.kernel.org>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoVersion 0.12.1 v0.12.1
Mathieu Desnoyers [Wed, 22 Apr 2020 12:51:41 +0000 (08:51 -0400)] 
Version 0.12.1

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 years agoFix: tls-compat.h exposes compiler-dependent public configuration
Mathieu Desnoyers [Mon, 20 Apr 2020 15:30:49 +0000 (11:30 -0400)] 
Fix: tls-compat.h exposes compiler-dependent public configuration

Exposing the storage class chosen by ax_tls.m4 in a public header is
a bad idea, because if a recent gcc is used when configuring
liburcu, thus detecting C11, it will choose _Thread_local. Then, if an
external project uses urcu/tls-compat.h with an older gcc (e.g. 4.8),
it will fail to build, because that storage class is unknown, and
__thread should be used instead.

Therefore, use a preprocessor conditional on __cplusplus to detect C++11
(and use thread_local). Else, the STDC version is used to select
_Thread_local. Else check if _MSC_VER is defined to select
__declspec(thread), or else rely on __thread as fallback.

Remove ax_tls.m4 because it is now unused.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: tap array subscript has type char warning
Mathieu Desnoyers [Fri, 10 Apr 2020 12:30:54 +0000 (08:30 -0400)] 
Fix: tap array subscript has type char warning

On architectures where "char" is signed, it should be cast to unsigned
char before being passed as parameter to isdigit or isspace. Based on
their man page:

       These  functions  check  whether  c,  which  must  have the value of an
       unsigned char or EOF, falls into a certain character class according to
       the  specified  locale.

Passing a signed char as parameter is invalid if the values fall into
the negative range of the signed char.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoVersion 0.12.0 v0.12.0
Mathieu Desnoyers [Thu, 9 Apr 2020 18:44:10 +0000 (14:44 -0400)] 
Version 0.12.0

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agotls-compat.h: introduce DEFINE_URCU_TLS_INIT
Mathieu Desnoyers [Thu, 9 Apr 2020 15:26:31 +0000 (11:26 -0400)] 
tls-compat.h: introduce DEFINE_URCU_TLS_INIT

DEFINE_URCU_TLS() cannot be used in this way for !CONFIG_RCU_TLS:

  DEFINE_URCU_TLS(ino_t, cached_net_ns) = NS_INO_UNINITIALIZED;

Introduce a new DEFINE_URCU_TLS_INIT which allows expressing a nonzero
intial value:

  DEFINE_URCU_TLS_INIT(ino_t, cached_net_ns, NS_INO_UNINITIALIZED);

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoUse _umtx_op for futex on FreeBSD
Alex Xu [Tue, 28 Jan 2020 01:17:22 +0000 (20:17 -0500)] 
Use _umtx_op for futex on FreeBSD

Tested with "make check", "make regtest" and a knotd slave.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoAdd FreeBSD, DragonFly to syscall-compat.h
Alex Xu [Mon, 27 Jan 2020 20:08:29 +0000 (15:08 -0500)] 
Add FreeBSD, DragonFly to syscall-compat.h

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agourcu-bp: perform thread registration on urcu_bp_register_thread
Mathieu Desnoyers [Fri, 22 Nov 2019 16:02:36 +0000 (11:02 -0500)] 
urcu-bp: perform thread registration on urcu_bp_register_thread

Some real-time use-cases (e.g. Xenomai) require to perform urcu-bp
thread registration early in the thread life-time before it starts
performing real-time tasks.

Currently, this can be achieved by issuing a urcu_bp_read_lock() and
urcu_bp_read_unlock() pair, or by using urcu_bp_read_ongoing(), while in
the initialization phrase.

However, it seems natural to expect that calling urcu_bp_register_thread()
would have the side effect to perform the lazy thread registration
immediately rather than being a no-op.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoRequire automake >= 1.12
Michael Jeanson [Thu, 7 Nov 2019 18:39:44 +0000 (13:39 -0500)] 
Require automake >= 1.12

The test suite LOG_DRIVER statement requires that automake >= 1.12 be used
during bootstrap.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agocds_lfht_is_node_deleted parameter can be marked const
Jérémie Galarneau [Mon, 28 Oct 2019 19:24:36 +0000 (15:24 -0400)] 
cds_lfht_is_node_deleted parameter can be marked const

Mark the cds_lfht_node pointer parameter of cds_lfht_is_node_deleted
as const. The fact that this parameter is mutable makes it harder to
use liburcu in const-correct code.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: provide errno as argument to urcu_die()
Mathieu Desnoyers [Thu, 19 Sep 2019 14:10:31 +0000 (10:10 -0400)] 
Fix: provide errno as argument to urcu_die()

commit 1a990de3add "Fix: rculfhash worker needs to unblock to SIGRCU"
provides "ret" (-1) as argument to urcu_die(), but should rather provide
errno.

Reported by Coverity:

** CID 1405700:  Error handling issues  (NEGATIVE_RETURNS) /src/rculfhash.c: 2171 in cds_lfht_worker_init()

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: rculfhash worker needs to unblock to SIGRCU
hewenliang [Tue, 17 Sep 2019 14:59:18 +0000 (10:59 -0400)] 
Fix: rculfhash worker needs to unblock to SIGRCU

In urcu-signal flavor, call_rcu_thread calls synchronize_rcu which
will send SIGRCU signal to all registed threads, and then loops to
wait need_mb to be cleared. However, the registed workqueue_thread
does not process the SIGRCU signal, and never clear the need_mb.
Based on above, call_rcu_thread and workqueue_thread will wait
forever for completion of the grace period: call_rcu_thread which holds
the rcu_registry_lock, waits for workqueue_thread to do cmm_smp_mb.
While workqueue thread never does cmm_smp_mb because of signal blocking,
and it will eventually wait to get rcu_registry_lock in do_resize_cb.

The phenomenon is as follows, which is easy to be triggered:

(gdb) t 2
[Switching to thread 2 (Thread 0xffff83c3b080 (LWP 27116))]
0  0x0000ffff845296c4 in poll () from /lib64/libc.so.6
(gdb) bt
0 0x0000ffff845296c4 in poll () from /lib64/libc.so.6
1 0x0000ffff8461b93c in force_mb_all_readers () at urcu.c:241
2 0x0000ffff8461c748 in smp_mb_master () at urcu.c:249
3 urcu_signal_synchronize_rcu () at urcu.c:445
4 0x0000ffff8461d004 in call_rcu_thread  at urcu-call-rcu-impl.h:364
5 0x0000ffff845eb8bc in start_thread () from /lib64/libpthread.so.0
6 0x0000ffff845335cc in thread_start () from /lib64/libc.so.6
(gdb) t 3
[Switching to thread 3 (Thread 0xffff8443c080 (LWP 27191))]
0 0x0000ffff845f51c4 in __lll_lock_wait () from /lib64/libpthread.so.0
(gdb) bt
0 0x0000ffff845f51c4 in __lll_lock_wait () from /lib64/libpthread.so.0
1 0x0000ffff845ee048 in pthread_mutex_lock () from /lib64/libpthread.so.0
2 0x0000ffff8461b814 in mutex_lock ( <rcu_registry_lock>) at urcu.c:157
3 0x0000ffff8461b9e4 in urcu_signal_unregister_thread () at urcu.c:564
4 0x0000ffff8463e62c in do_resize_cb (work=0x11e2e790) at rculfhash.c:2042
5 0x0000ffff8463c940 in workqueue_thread (arg=0x11e1d260) at workqueue.c:228
6 0x0000ffff845eb8bc in start_thread () from /lib64/libpthread.so.0
7 0x0000ffff845335cc in thread_start () from /lib64/libc.so.6

So we should not block SIGRCU in workqueue thread to avoid blocking
forever in the grace period awaiting on the worker thread when using
urcu-signal flavor.

Signed-off-by: hewenliang <hewenliang4@huawei.com>
Co-developed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
4 years agoCleanup: test_perthreadlock_timing: handle pthread mutex errors
Mathieu Desnoyers [Tue, 4 Jun 2019 19:09:53 +0000 (15:09 -0400)] 
Cleanup: test_perthreadlock_timing: handle pthread mutex errors

Found by Coverity:
CID 1357055 (#1 of 1): Unchecked return value (CHECKED_RETURN)
4. check_return: Calling pthread_mutex_lock without checking return value
(as is done elsewhere 44 out of 48 times).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: SONAME bump to 6.1.0
Michael Jeanson [Mon, 3 Jun 2019 20:36:43 +0000 (16:36 -0400)] 
Fix: SONAME bump to 6.1.0

In commit d6c78161aed9b2d550ce201b0a8cd5b3ee515ac8 we bumped the 'age'
part of the library version with the intention of keeping the same major
SONAME because we only introduced new symbols. However by bumping the
'age' and not the 'current' we substracted 1 to the major SONAME which
we did not intend. Seems like we missed this in testing.

Fix it by bumping the 'current' to end up with an SONAME of 6.1.0 which
is what we originally intended.

From the libtool manual for reference :

  Programs using the previous version may use the new version as drop-in
  replacement, but programs using the new version may use APIs not present
  in the previous one. In other words, a program linking against the new
  version may fail with “unresolved symbols” if linking against the old
  version at runtime: set revision to 0, bump current and age.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoCleanup: remove unused variable from configure.ac check
Mathieu Desnoyers [Mon, 27 May 2019 16:38:38 +0000 (12:38 -0400)] 
Cleanup: remove unused variable from configure.ac check

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: urcu/futex.h: users of struct timespec should include time.h
Mathieu Desnoyers [Mon, 27 May 2019 15:50:20 +0000 (11:50 -0400)] 
Fix: urcu/futex.h: users of struct timespec should include time.h

Fixes: #1187
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoVersion 0.11.0 v0.11.0
Mathieu Desnoyers [Mon, 6 May 2019 20:24:29 +0000 (16:24 -0400)] 
Version 0.11.0

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoBump library version to 6:0:1
Mathieu Desnoyers [Mon, 6 May 2019 19:50:28 +0000 (15:50 -0400)] 
Bump library version to 6:0:1

Public symbol were added between 0.10 and 0.11.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoCleanup: update code layout to fix old gcc warning
Mathieu Desnoyers [Mon, 6 May 2019 13:56:19 +0000 (09:56 -0400)] 
Cleanup: update code layout to fix old gcc warning

Some CI jobs show:

urcu-pointer.o
13:46:22 In file included from urcu.c:49:0:
13:46:22 urcu-wait.h:70:9: warning: missing initializer for field 'lock' of 'struct cds_wfs_stack' [-Wmissing-field-initializers]
13:46:22   struct urcu_wait_queue name = URCU_WAIT_QUEUE_HEAD_INIT(name)
13:46:22          ^
13:46:22 urcu.c:150:8: note: in expansion of macro 'DEFINE_URCU_WAIT_QUEUE'
13:46:22  static DEFINE_URCU_WAIT_QUEUE(gp_waiters);
13:46:22         ^
13:46:22 In file included from urcu-wait.h:27:0,
13:46:22                  from urcu.c:49:
13:46:22 ../include/urcu/wfstack.h:92:18: note: 'lock' declared here
13:46:22   pthread_mutex_t lock;
13:46:22

Change code layout so not to confuse old gcc.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: typo CPPLAGS in examples Makefile
Michael Jeanson [Mon, 22 Apr 2019 16:04:04 +0000 (12:04 -0400)] 
Fix: typo CPPLAGS in examples Makefile

Overriding CPPFLAGS throught the environment was ignored for the
examples.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoHarmonize pprint macro across projects
Michael Jeanson [Tue, 16 Apr 2019 20:41:45 +0000 (16:41 -0400)] 
Harmonize pprint macro across projects

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoCheck for TLS support after CC detection
Michael Jeanson [Tue, 16 Apr 2019 17:48:00 +0000 (13:48 -0400)] 
Check for TLS support after CC detection

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoUpdate macros from the autotools archive
Michael Jeanson [Tue, 16 Apr 2019 17:47:59 +0000 (13:47 -0400)] 
Update macros from the autotools archive

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agotap-driver.sh: flush stdout after each test result
Michael Jeanson [Thu, 14 Mar 2019 15:35:39 +0000 (11:35 -0400)] 
tap-driver.sh: flush stdout after each test result

This is useful in a CI system where stdout is fully buffered and you
look at the console output to see which test is hanging.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoUpdate dead link in lgpl-relicensing.txt
Michael Jeanson [Thu, 7 Mar 2019 20:53:54 +0000 (15:53 -0500)] 
Update dead link in lgpl-relicensing.txt

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoAdd multiflavor compat identifiers
Michael Jeanson [Mon, 28 Jan 2019 16:56:02 +0000 (11:56 -0500)] 
Add multiflavor compat identifiers

This will maintain buildtime compatibility with softwares like lttng-ust
that used the prior undocumented multiflavor API.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoCleanup: missing sign compare fixes
Michael Jeanson [Wed, 19 Dec 2018 16:44:57 +0000 (11:44 -0500)] 
Cleanup: missing sign compare fixes

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoCleanup: enable signed/unsigned compare compiler warning
Michael Jeanson [Tue, 18 Dec 2018 19:21:22 +0000 (14:21 -0500)] 
Cleanup: enable signed/unsigned compare compiler warning

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoCleanup: compiler warning on 32-bit architectures
Michael Jeanson [Mon, 17 Dec 2018 20:23:14 +0000 (15:23 -0500)] 
Cleanup: compiler warning on 32-bit architectures

Replace a runtime test for 64-bit arch by a preprocessor test to
fix this compiler warning on 32-bit archs :

  comparison is always true due to limited range of data type [-Wtype-limits]

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoconfig.h.in: rename CONFIG_RCU_MULTIFLAVOR to CONFIG_RCU_HAVE_MULTIFLAVOR
Mathieu Desnoyers [Thu, 13 Dec 2018 20:48:12 +0000 (15:48 -0500)] 
config.h.in: rename CONFIG_RCU_MULTIFLAVOR to CONFIG_RCU_HAVE_MULTIFLAVOR

Considering that this config option cannot be selected by
configure, and is just exposing the capabilities of liburcu,
use the "HAVE" semantic.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agorculfhash: implement iterator debugging config option
Mathieu Desnoyers [Thu, 13 Dec 2018 02:15:32 +0000 (21:15 -0500)] 
rculfhash: implement iterator debugging config option

Building liburcu with --enable-cds-lfht-iter-debug and rebuilding
application to match the ABI change allows finding cases where the
hash table iterator is re-purposed to be used on a different hash
table while still being used to iterate on a hash table.

This is a common programming mistake that happens often enough
to justify creating a debugging mode to track this automatically.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: examples silent rules on Solaris
Michael Jeanson [Wed, 12 Dec 2018 20:30:59 +0000 (15:30 -0500)] 
Fix: examples silent rules on Solaris

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoAdd missing fall through annotations
Michael Jeanson [Wed, 12 Dec 2018 20:01:39 +0000 (15:01 -0500)] 
Add missing fall through annotations

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: symbol aliases with TLS compat
Michael Jeanson [Wed, 12 Dec 2018 20:01:38 +0000 (15:01 -0500)] 
Fix: symbol aliases with TLS compat

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoPort: no symbols aliases on MacOS
Michael Jeanson [Wed, 12 Dec 2018 20:01:37 +0000 (15:01 -0500)] 
Port: no symbols aliases on MacOS

There is no equivalent to symbols aliases on MacOS, this will
unfortunatly break the ABI for SONAME(6) and will require a rebuild of
client applications.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoAdd -Wextra to CFLAGS
Michael Jeanson [Fri, 30 Nov 2018 19:28:51 +0000 (14:28 -0500)] 
Add -Wextra to CFLAGS

Edited by Mathieu Desnoyers:

Use /* fall through */ rather than __attribute__((fallthrough)) to
stay compatible with clang and gcc < 7. The fallthrough attribute
was introduced in gcc 7.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoAdd silent mode to examples Makefiles
Michael Jeanson [Fri, 30 Nov 2018 23:06:45 +0000 (18:06 -0500)] 
Add silent mode to examples Makefiles

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agodoc: update examples to API changes
Mathieu Desnoyers [Thu, 29 Nov 2018 20:59:18 +0000 (15:59 -0500)] 
doc: update examples to API changes

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agotest multiflavor single compile unit
Mathieu Desnoyers [Fri, 30 Nov 2018 19:20:33 +0000 (14:20 -0500)] 
test multiflavor single compile unit

Test multiple liburcu flavors within a compile unit.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoUpdate README following API changes
Mathieu Desnoyers [Thu, 29 Nov 2018 20:49:11 +0000 (15:49 -0500)] 
Update README following API changes

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoUse new header locations for includes from urcu code
Mathieu Desnoyers [Fri, 30 Nov 2018 22:19:44 +0000 (17:19 -0500)] 
Use new header locations for includes from urcu code

This also moves urcu/static/urcu-pointer.h to urcu/static/pointer.h.
Considering that it is not meant to be included directly by library
users, it should not cause any problem.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoUpdate call-rcu.h and defer.h comments and include guards
Mathieu Desnoyers [Fri, 30 Nov 2018 22:08:13 +0000 (17:08 -0500)] 
Update call-rcu.h and defer.h comments and include guards

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agorculfqueue.h: do not include urcu-call-rcu.h
Mathieu Desnoyers [Fri, 30 Nov 2018 21:59:18 +0000 (16:59 -0500)] 
rculfqueue.h: do not include urcu-call-rcu.h

urcu-call-rcu.h is included by rculfhqueue.h only for struct rcu_head
forward declaration, but as a result the urcu flavor needs to be chosen
beforehand, and therefore prevents using rculfqueue.h with multiple
urcu flavors in a given compile unit.

Remove that include and do a forward declaration of struct rcu_head
instead.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agorculfhash: support use with multiple flavors per compile unit
Mathieu Desnoyers [Fri, 30 Nov 2018 21:34:03 +0000 (16:34 -0500)] 
rculfhash: support use with multiple flavors per compile unit

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agorculfhash: do not include urcu-call-rcu.h from public API
Mathieu Desnoyers [Fri, 30 Nov 2018 21:22:08 +0000 (16:22 -0500)] 
rculfhash: do not include urcu-call-rcu.h from public API

This include is not needed, and because of it rculfhash needs to be
included after the RCU flavor is chosen.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoRefactor liburcu to support many flavors per compile unit
Mathieu Desnoyers [Wed, 28 Nov 2018 17:07:09 +0000 (12:07 -0500)] 
Refactor liburcu to support many flavors per compile unit

This refactoring keeps the prior use of liburcu "map" APIs unchanged.
However, it introduces the following new APIs:

Each urcu flavor is now available as its own header:

include/urcu/urcu-memb.h
include/urcu/urcu-mb.h
include/urcu/urcu-signal.h
include/urcu/urcu-bp.h
include/urcu/urcu-qsbr.h

The installed urcu headers that were not under the urcu/ subdirectory
are moved there:

include/urcu-call-rcu.h -> include/urcu/call-rcu.h
include/urcu-defer.h -> include/urcu/defer.h
include/urcu-flavor.h -> include/urcu/flavor.h
include/urcu-pointer.h -> include/urcu/pointer.h
include/urcu-bp.h -> include/urcu/urcu-bp.h
include/urcu.h -> include/urcu/urcu.h
include/urcu-qsbr.h -> include/urcu/urcu-qsbr.h

The liburcu "map" API is now only available for use when URCU_API_MAP is
defined before including the liburcu flavor headers.

The old headers are now placeholders defining URCU_API_MAP and including
the new headers for backward compatibility:

include/urcu-bp.h
include/urcu-call-rcu.h
include/urcu-defer.h
include/urcu-flavor.h
include/urcu-pointer.h
include/urcu-qsbr.h
include/urcu.h

The header include/urcu/urcu.h now includes the right header between the
memb, signal, or mb flavors based on the compiler defines.

The symbol names of liburcu flavors are cleaned up, favoring the
following hierarchy:

urcu_<flavor name>_...

This is an ABI-breaking change, however the previous symbols name were
kept as aliases to maintain backward compatibility. They will be removed
when the next SONAME bump occurs.

The new liburcu-memb.so shared object is introduced, properly
namespacing this flavor. It is a duplicate of the previous liburcu.so,
which is kept around for backward compatibility.

The new URCU_API_MAP macro is introduced, controlling whether the
urcu API "mapping" should stay defined after inclusion of the flavor
headers. Users wishing to use the prior urcu API should either
explicitly define URCU_API_MAP before including the urcu/urcu*.h flavor
headers, or include the flavor header files from the include toplevel
directory, which are placeholders for backward compatibility. Use of
many urcu flavors within the same _LGPL_SOURCE compile unit should not
use the "map" APIs.

Internally, the "map" header files are split into one header per
flavor. The include guards are removed, so their effect can be
applied more than once. A new include/urcu/map/clear.h header is
introduced, which undefines the mappings at the end of the flavor
header if URCU_API_MAP is not set.

The new APIs namespaced for each urcu flavor is the recommended way to
use liburcu. We can expect the prior APIs to eventually become
deprecated over time.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: only wait if work queue is empty in real-time mode
Jérémie Galarneau [Fri, 7 Dec 2018 22:06:39 +0000 (17:06 -0500)] 
Fix: only wait if work queue is empty in real-time mode

Unconditionally waiting for 10 ms after the completion of every batch
of jobs of the work queue in real-time mode appears to be a behaviour
inherited from the call-rcu thread.

While this is a fair trade-off in the context of call-rcu, it is less
evident that it is desirable in the context of a general-purpose
work queue. Waiting when work is available artificially degrades the
latency characteristics of the work queue.

If a workqueue user even need the explicit delay for batching (e.g. if
a call-rcu implementation would ever use the workqueue worker thread),
it can add it within the worker_before_wait_fct callback received as
argument from workqueue creation.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: don't wait after completion of a work queue job batch
Jérémie Galarneau [Fri, 7 Dec 2018 22:06:38 +0000 (17:06 -0500)] 
Fix: don't wait after completion of a work queue job batch

As indicated in the previous patch of this series, waiting on
completion of a job batch from the work queue artificially increases
the latency of the work queue.

The previous patch removed the wait that is performed when the
work queue is observed to be empty and was observed as the cause of a
performance problem.

It is likely that waiting when the queue is observed to be non-empty
is similarly unintended. Note that I have not observed such a problem
myself.

If a workqueue user even need the explicit delay for batching (e.g. if
a call-rcu implementation would ever use the workqueue worker thread),
it can add it within the worker_before_wait_fct callback received as
argument from workqueue creation.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
This page took 0.048935 seconds and 4 git commands to generate.