1 Userspace RCU Implementation
2 ============================
4 by Mathieu Desnoyers and Paul E. McKenney
10 ./bootstrap # skip if using tarball
18 - Forcing 32-bit build:
20 CFLAGS="-m32 -g -O2" ./configure
22 - Forcing 64-bit build:
24 CFLAGS="-m64 -g -O2" ./configure
26 - Forcing a 32-bit build with 386 backward compatibility:
28 CFLAGS="-m32 -g -O2" ./configure --host=i386-pc-linux-gnu
30 - Forcing a 32-bit build for Sparcv9 (typical for Sparc v9)
32 CFLAGS="-m32 -Wa,-Av9a -g -O2" ./configure
35 Architectures supported
36 -----------------------
38 Currently, the following architectures are supported:
40 - x86 (i386, i486, i586, i686)
57 - Linux all architectures
58 - FreeBSD 8.2/8.3/9.0/9.1/10.0 i386/amd64
70 (more testing needed before claiming support for these OS).
72 Linux ARM depends on running a Linux kernel 2.6.15 or better, GCC 4.4 or
75 The GCC compiler versions 3.3, 3.4, 4.0, 4.1, 4.2, 4.3, 4.4 and 4.5 are
76 supported, with the following exceptions:
78 - GCC 3.3 and 3.4 have a bug that prevents them from generating volatile
79 accesses to offsets in a TLS structure on 32-bit x86. These versions are
80 therefore not compatible with `liburcu` on x86 32-bit
81 (i386, i486, i586, i686).
82 The problem has been reported to the GCC community:
83 http://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg281255.html
84 - GCC 3.3 cannot match the "xchg" instruction on 32-bit x86 build.
85 See http://kerneltrap.org/node/7507
86 - Alpha, ia64 and ARM architectures depend on GCC 4.x with atomic builtins
87 support. For ARM this was introduced with GCC 4.4:
88 http://gcc.gnu.org/gcc-4.4/changes.html.
90 Clang version 3.0 (based on LLVM 3.0) is supported.
92 Building on MacOS X (Darwin) requires a work-around for processor
97 ./configure --build=i686-apple-darwin11
101 ./configure --build=x86_64-apple-darwin11
103 For developers using the Git tree:
105 This source tree is based on the autotools suite from GNU to simplify
106 portability. Here are some things you should have on your system in order to
107 compile the git repository tree :
109 - GNU autotools (automake >=1.10, autoconf >=2.50, autoheader >=2.50)
110 (make sure your system wide `automake` points to a recent version!)
112 (for more information, go to http://www.gnu.org/software/autoconf/)
114 If you get the tree from the repository, you will need to use the `bootstrap`
115 script in the root of the tree. It calls all the GNU tools needed to prepare
116 the tree configuration.
118 Test scripts provided in the `tests/` directory of the source tree depend
119 on `bash` and the `seq` program.
125 See the relevant API documentation files in `doc/`. The APIs provided by
126 Userspace RCU are, by prefix:
128 - `rcu_`: Read-Copy Update (see [`doc/rcu-api.md`](doc/rcu-api.md))
129 - `cmm_`: Concurrent Memory Model
130 - `caa_`: Concurrent Architecture Abstraction
131 - `cds_`: Concurrent Data Structures
132 (see [`doc/cds-api.md`](doc/cds-api.md))
133 - `uatomic_`: Userspace Atomic
134 (see [`doc/uatomic-api.md`](doc/uatomic-api.md))
140 ### Usage of all urcu libraries:
142 - Define `_LGPL_SOURCE` (only) if your code is LGPL or GPL compatible
143 before including the `urcu.h` or `urcu-qsbr.h` header. If your application
144 is distributed under another license, function calls will be generated
145 instead of inlines, so your application can link with the library.
146 - Linking with one of the libraries below is always necessary even for
147 LGPL and GPL applications.
148 - Define `URCU_INLINE_SMALL_FUNCTIONS` before including Userspace RCU
149 headers if you want Userspace RCU to inline small functions (10
150 lines or less) into the application. It can be used by applications
151 distributed under any kind of license, and does *not* make the
152 application a derived work of Userspace RCU.
154 Those small inlined functions are guaranteed to match the library
155 content as long as the library major version is unchanged.
156 Therefore, the application *must* be compiled with headers matching
157 the library major version number. Applications using
158 `URCU_INLINE_SMALL_FUNCTIONS` may be unable to use debugging
159 features of Userspace RCU without being recompiled.
161 There are multiple flavors of liburcu available:
169 The API members start with the prefix "urcu_<flavor>_", where
170 <flavor> is the chosen flavor name.
173 ### Usage of `liburcu-memb`
175 1. `#include <urcu/urcu-memb.h>`
176 2. Link the application with `-lurcu-memb`
178 This is the preferred version of the library, in terms of
179 grace-period detection speed, read-side speed and flexibility.
180 Dynamically detects kernel support for `sys_membarrier()`. Falls back
181 on `urcu-mb` scheme if support is not present, which has slower
182 read-side. Use the --disable-sys-membarrier-fallback configure option
183 to disable the fall back, thus requiring `sys_membarrier()` to be
184 available. This gives a small speedup when `sys_membarrier()` is
185 supported by the kernel, and aborts in the library constructor if not
189 ### Usage of `liburcu-qsbr`
191 1. `#include <urcu/urcu-qsbr.h>`
192 2. Link with `-lurcu-qsbr`
194 The QSBR flavor of RCU needs to have each reader thread executing
195 `rcu_quiescent_state()` periodically to progress. `rcu_thread_online()`
196 and `rcu_thread_offline()` can be used to mark long periods for which
197 the threads are not active. It provides the fastest read-side at the
198 expense of more intrusiveness in the application code.
201 ### Usage of `liburcu-mb`
203 1. `#include <urcu/urcu-mb.h>`
204 2. Link with `-lurcu-mb`
206 This version of the urcu library uses memory barriers on the writer
207 and reader sides. This results in faster grace-period detection, but
208 results in slower reads.
211 ### Usage of `liburcu-signal`
213 1. `#include <urcu/urcu-signal.h>`
214 2. Link the application with `-lurcu-signal`
216 Version of the library that requires a signal, typically `SIGUSR1`. Can
217 be overridden with `-DSIGRCU` by modifying `Makefile.build.inc`.
220 ### Usage of `liburcu-bp`
222 1. `#include <urcu/urcu-bp.h>`
223 2. Link with `-lurcu-bp`
225 The BP library flavor stands for "bulletproof". It is specifically
226 designed to help tracing library to hook on applications without
227 requiring to modify these applications. `urcu_bp_init()`, and
228 `urcu_bp_unregister_thread()` all become nops, whereas calling
229 `urcu_bp_register_thread()` becomes optional. The state is dealt with by
230 the library internally at the expense of read-side and write-side
236 Each thread that has reader critical sections (that uses
237 `urcu_<flavor>_read_lock()`/`urcu_<flavor>_read_unlock()` must first
238 register to the URCU library. This is done by calling
239 `urcu_<flavor>_register_thread()`. Unregistration must be performed
240 before exiting the thread by using `urcu_<flavor>_unregister_thread()`.
245 Reader critical sections must be protected by locating them between
246 calls to `urcu_<flavor>_read_lock()` and `urcu_<flavor>_read_unlock()`.
247 Inside that lock, `rcu_dereference()` may be called to read an RCU
253 `rcu_assign_pointer()` and `rcu_xchg_pointer()` may be called anywhere.
254 After, `urcu_<flavor>_synchronize_rcu()` must be called. When it
255 returns, the old values are not in usage anymore.
258 ### Usage of `liburcu-defer`
260 - Follow instructions for either `liburcu-memb`, `liburcu-qsbr`,
261 `liburcu-mb`, `liburcu-signal`, or `liburcu-bp` above.
262 The `liburcu-defer` functionality is pulled into each of
263 those library modules.
264 - Provides `urcu_<flavor>_defer_rcu()` primitive to enqueue delayed
265 callbacks. Queued callbacks are executed in batch periodically after
266 a grace period. Do _not_ use `urcu_<flavor>_defer_rcu()` within a
267 read-side critical section, because it may call
268 `urcu_<flavor>_synchronize_rcu()` if the thread queue is full. This
269 can lead to deadlock or worse.
270 - Requires that `urcu_<flavor>_defer_barrier()` must be called in
271 library destructor if a library queues callbacks and is expected to
272 be unloaded with `dlclose()`.
274 Its API is currently experimental. It may change in future library releases.
277 ### Usage of `urcu-call-rcu`
279 - Follow instructions for either `liburcu-memb`, `liburcu-qsbr`,
280 `liburcu-mb`, `liburcu-signal`, or `liburcu-bp` above.
281 The `urcu-call-rcu` functionality is pulled into each of
282 those library modules.
283 - Provides the `urcu_<flavor>_call_rcu()` primitive to enqueue delayed
284 callbacks in a manner similar to `urcu_<flavor>_defer_rcu()`, but
285 without ever delaying for a grace period. On the other hand,
286 `urcu_<flavor>_call_rcu()`'s best-case overhead is not quite as good
287 as that of `urcu_<flavor>_defer_rcu()`.
288 - Provides `urcu_<flavor>_call_rcu()` to allow asynchronous handling
289 of RCU grace periods. A number of additional functions are provided
290 to manage the helper threads used by `urcu_<flavor>_call_rcu()`, but
291 reasonable defaults are used if these additional functions are not
292 invoked. See [`doc/rcu-api.md`](doc/rcu-api.md) in userspace-rcu
293 documentation for more details.
296 ### Being careful with signals
298 The `liburcu-signal` library uses signals internally. The signal handler is
299 registered with the `SA_RESTART` flag. However, these signals may cause
300 some non-restartable system calls to fail with `errno = EINTR`. Care
301 should be taken to restart system calls manually if they fail with this
302 error. A list of non-restartable system calls may be found in
305 Read-side critical sections are allowed in a signal handler,
306 except those setup with `sigaltstack(2)`, with `liburcu-memb` and
307 `liburcu-mb`. Be careful, however, to disable these signals
308 between thread creation and calls to `urcu_<flavor>_register_thread()`,
309 because a signal handler nesting on an unregistered thread would not be
310 allowed to call `urcu_<flavor>_read_lock()`.
312 Read-side critical sections are _not_ allowed in a signal handler with
313 `liburcu-qsbr`, unless signals are disabled explicitly around each
314 `urcu_qsbr_quiescent_state()` calls, when threads are put offline and around
315 calls to `urcu_qsbr_synchronize_rcu()`. Even then, we do not recommend it.
318 ### Interaction with mutexes
320 One must be careful to do not cause deadlocks due to interaction of
321 `urcu_<flavor>_synchronize_rcu()` and RCU read-side with mutexes. If
322 `urcu_<flavor>_synchronize_rcu()` is called with a mutex held, this
323 mutex (or any mutex which has this mutex in its dependency chain) should
324 not be acquired from within a RCU read-side critical section.
326 This is especially important to understand in the context of the
327 QSBR flavor: a registered reader thread being "online" by
328 default should be considered as within a RCU read-side critical
329 section unless explicitly put "offline". Therefore, if
330 `urcu_qsbr_synchronize_rcu()` is called with a mutex held, this mutex,
331 as well as any mutex which has this mutex in its dependency chain should
332 only be taken when the RCU reader thread is "offline" (this can be
333 performed by calling `urcu_qsbr_thread_offline()`).
336 ### Interaction with `fork()`
338 Special care must be taken for applications performing `fork()` without
339 any following `exec()`. This is caused by the fact that Linux only clones
340 the thread calling `fork()`, and thus never replicates any of the other
341 parent thread into the child process. Most `liburcu` implementations
342 require that all registrations (as reader, `defer_rcu` and `call_rcu`
343 threads) should be released before a `fork()` is performed, except for the
344 rather common scenario where `fork()` is immediately followed by `exec()` in
345 the child process. The only implementation not subject to that rule is
346 `liburcu-bp`, which is designed to handle `fork()` by calling
347 `urcu_bp_before_fork`, `urcu_bp_after_fork_parent` and
348 `urcu_bp_after_fork_child`.
350 Applications that use `urcu_<flavor>_call_rcu()` and that `fork()`
351 without doing an immediate `exec()` must take special action. The
352 parent must invoke `urcu_<flavor>_call_rcu_before_fork()` before the
353 `fork()` and `urcu_<flavor>_call_rcu_after_fork_parent()` after the
354 `fork()`. The child process must invoke
355 `urcu_<flavor>_call_rcu_after_fork_child()`. Even though these three
356 APIs are suitable for passing to `pthread_atfork()`, use of
357 `pthread_atfork()` is **STRONGLY DISCOURAGED** for programs calling the
358 glibc memory allocator (`malloc()`, `calloc()`, `free()`, ...) within
359 `urcu_<flavor>_call_rcu` callbacks. This is due to limitations in the
360 way glibc memory allocator handles calls to the memory allocator from
361 concurrent threads while the `pthread_atfork()` handlers are executing.
365 - call to `free()` from callbacks executed within
366 `urcu_<flavor>_call_rcu` worker threads,
367 - executing `urcu_<flavor>_call_rcu` atfork handlers within the glibc
368 pthread atfork mechanism,
370 will sometimes trigger interesting process hangs. This usually
371 hangs on a memory allocator lock within glibc.
374 ### Thread Local Storage (TLS)
376 Userspace RCU can fall back on `pthread_getspecific()` to emulate
377 TLS variables on systems where it is not available. This behavior
378 can be forced by specifying `--disable-compiler-tls` as configure
382 ### Usage of `DEBUG_RCU` & `--enable-rcu-debug`
384 By default the library is configured with internal debugging
385 self-checks disabled.
387 For always-on debugging self-checks:
388 ./configure --enable-rcu-debug
390 For fine grained enabling of debugging self-checks, build
391 userspace-rcu with DEBUG_RCU defined and compile dependent
392 applications with DEBUG_RCU defined when necessary.
394 Warning: Enabling this feature result in a performance penalty.
397 ### Usage of `DEBUG_YIELD`
399 `DEBUG_YIELD` is used to add random delays in the code for testing
405 By default the library is configured to use synchronization primitives
406 adequate for SMP systems. On uniprocessor systems, support for SMP
407 systems can be disabled with:
409 ./configure --disable-smp-support
411 theoretically yielding slightly better performance.
414 ### Usage of `--enable-cds-lfht-iter-debug`
416 By default the library is configured with extra debugging checks for
417 lock-free hash table iterator traversal disabled.
419 Building liburcu with --enable-cds-lfht-iter-debug and rebuilding
420 application to match the ABI change allows finding cases where the hash
421 table iterator is re-purposed to be used on a different hash table while
422 still being used to iterate on a hash table.
424 This option alters the rculfhash ABI. Make sure to compile both library
425 and application with matching configuration.
431 In addition to the usual `make check` target, Userspace RCU features
432 `make regtest` and `make bench` targets:
434 - `make check`: short tests, meant to be run when rebuilding or
435 porting Userspace RCU.
436 - `make regtest`: long (many hours) test, meant to be run when
437 modifying Userspace RCU or porting it to a new architecture or
439 - `make bench`: long (many hours) benchmarks.
445 You can contact the maintainers on the following mailing list:
446 `lttng-dev@lists.lttng.org`.