Version 0.11.4
[userspace-rcu.git] / README.md
CommitLineData
d589a916
PP
1Userspace RCU Implementation
2============================
3
4by Mathieu Desnoyers and Paul E. McKenney
5
6
7Building
8--------
9
10 ./bootstrap # skip if using tarball
11 ./configure
12 make
13 make install
14 ldconfig
15
16Hints:
17
18 - Forcing 32-bit build:
19
20 CFLAGS="-m32 -g -O2" ./configure
21
22 - Forcing 64-bit build:
23
24 CFLAGS="-m64 -g -O2" ./configure
25
26 - Forcing a 32-bit build with 386 backward compatibility:
27
28 CFLAGS="-m32 -g -O2" ./configure --host=i386-pc-linux-gnu
29
30 - Forcing a 32-bit build for Sparcv9 (typical for Sparc v9)
31
32 CFLAGS="-m32 -Wa,-Av9a -g -O2" ./configure
33
34
35Architectures supported
36-----------------------
37
38Currently, the following architectures are supported:
39
f328865f
MD
40 - x86 (i386, i486, i586, i686)
41 - amd64 / x86_64
d589a916
PP
42 - PowerPC 32/64
43 - S390, S390x
44 - ARM 32/64
45 - MIPS
859050b3 46 - NIOS2
d589a916
PP
47 - Alpha
48 - ia64
49 - Sparcv9 32/64
50 - Tilera
51 - hppa/PA-RISC
f328865f
MD
52 - m68k
53 - RISC-V
54
55Tested on:
56
57 - Linux all architectures
58 - FreeBSD 8.2/8.3/9.0/9.1/10.0 i386/amd64
59 - Solaris 10/11 i386
60 - Cygwin i386/amd64
61 - MacOSX amd64
d589a916 62
d589a916
PP
63Should also work on:
64
65 - Android
66 - NetBSD 5
67 - OpenBSD
68 - Darwin
69
70(more testing needed before claiming support for these OS).
71
72Linux ARM depends on running a Linux kernel 2.6.15 or better, GCC 4.4 or
73better.
74
75The GCC compiler versions 3.3, 3.4, 4.0, 4.1, 4.2, 4.3, 4.4 and 4.5 are
76supported, with the following exceptions:
77
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.
589965c3
MD
89 - Linux aarch64 depends on GCC 5.1 or better because prior versions
90 perform unsafe access to deallocated stack.
d589a916
PP
91
92Clang version 3.0 (based on LLVM 3.0) is supported.
93
94Building on MacOS X (Darwin) requires a work-around for processor
95detection:
96
97 - 32-bit:
98
99 ./configure --build=i686-apple-darwin11
100
101 - 64-bit:
102
103 ./configure --build=x86_64-apple-darwin11
104
105For developers using the Git tree:
106
107This source tree is based on the autotools suite from GNU to simplify
108portability. Here are some things you should have on your system in order to
109compile the git repository tree :
110
111 - GNU autotools (automake >=1.10, autoconf >=2.50, autoheader >=2.50)
112 (make sure your system wide `automake` points to a recent version!)
113 - GNU Libtool >=2.2
114 (for more information, go to http://www.gnu.org/software/autoconf/)
115
116If you get the tree from the repository, you will need to use the `bootstrap`
117script in the root of the tree. It calls all the GNU tools needed to prepare
118the tree configuration.
119
120Test scripts provided in the `tests/` directory of the source tree depend
121on `bash` and the `seq` program.
122
123
124API
125---
126
127See the relevant API documentation files in `doc/`. The APIs provided by
128Userspace RCU are, by prefix:
129
dcb9c05a 130 - `rcu_`: Read-Copy Update (see [`doc/rcu-api.md`](doc/rcu-api.md))
d589a916
PP
131 - `cmm_`: Concurrent Memory Model
132 - `caa_`: Concurrent Architecture Abstraction
133 - `cds_`: Concurrent Data Structures
dcb9c05a 134 (see [`doc/cds-api.md`](doc/cds-api.md))
d589a916 135 - `uatomic_`: Userspace Atomic
dcb9c05a 136 (see [`doc/uatomic-api.md`](doc/uatomic-api.md))
d589a916
PP
137
138
139Quick start guide
140-----------------
141
142### Usage of all urcu libraries:
143
144 - Define `_LGPL_SOURCE` (only) if your code is LGPL or GPL compatible
145 before including the `urcu.h` or `urcu-qsbr.h` header. If your application
146 is distributed under another license, function calls will be generated
147 instead of inlines, so your application can link with the library.
148 - Linking with one of the libraries below is always necessary even for
149 LGPL and GPL applications.
150 - Define `URCU_INLINE_SMALL_FUNCTIONS` before including Userspace RCU
151 headers if you want Userspace RCU to inline small functions (10
152 lines or less) into the application. It can be used by applications
153 distributed under any kind of license, and does *not* make the
154 application a derived work of Userspace RCU.
155
156Those small inlined functions are guaranteed to match the library
157content as long as the library major version is unchanged.
158Therefore, the application *must* be compiled with headers matching
159the library major version number. Applications using
160`URCU_INLINE_SMALL_FUNCTIONS` may be unable to use debugging
161features of Userspace RCU without being recompiled.
162
f328865f
MD
163There are multiple flavors of liburcu available:
164
165 - `memb`,
166 - `qsbr`,
167 - `mb`,
168 - `signal`,
169 - `bp`.
170
171The API members start with the prefix "urcu_<flavor>_", where
172<flavor> is the chosen flavor name.
173
d589a916 174
f328865f 175### Usage of `liburcu-memb`
d589a916 176
f328865f
MD
177 1. `#include <urcu/urcu-memb.h>`
178 2. Link the application with `-lurcu-memb`
d589a916
PP
179
180This is the preferred version of the library, in terms of
181grace-period detection speed, read-side speed and flexibility.
182Dynamically detects kernel support for `sys_membarrier()`. Falls back
183on `urcu-mb` scheme if support is not present, which has slower
d8d9a340
MD
184read-side. Use the --disable-sys-membarrier-fallback configure option
185to disable the fall back, thus requiring `sys_membarrier()` to be
186available. This gives a small speedup when `sys_membarrier()` is
187supported by the kernel, and aborts in the library constructor if not
188supported.
d589a916
PP
189
190
191### Usage of `liburcu-qsbr`
192
f328865f 193 1. `#include <urcu/urcu-qsbr.h>`
d589a916
PP
194 2. Link with `-lurcu-qsbr`
195
196The QSBR flavor of RCU needs to have each reader thread executing
197`rcu_quiescent_state()` periodically to progress. `rcu_thread_online()`
198and `rcu_thread_offline()` can be used to mark long periods for which
199the threads are not active. It provides the fastest read-side at the
200expense of more intrusiveness in the application code.
201
202
203### Usage of `liburcu-mb`
204
f328865f
MD
205 1. `#include <urcu/urcu-mb.h>`
206 2. Link with `-lurcu-mb`
d589a916
PP
207
208This version of the urcu library uses memory barriers on the writer
209and reader sides. This results in faster grace-period detection, but
210results in slower reads.
211
212
213### Usage of `liburcu-signal`
214
f328865f
MD
215 1. `#include <urcu/urcu-signal.h>`
216 2. Link the application with `-lurcu-signal`
d589a916
PP
217
218Version of the library that requires a signal, typically `SIGUSR1`. Can
219be overridden with `-DSIGRCU` by modifying `Makefile.build.inc`.
220
221
222### Usage of `liburcu-bp`
223
f328865f 224 1. `#include <urcu/urcu-bp.h>`
d589a916
PP
225 2. Link with `-lurcu-bp`
226
227The BP library flavor stands for "bulletproof". It is specifically
228designed to help tracing library to hook on applications without
f328865f
MD
229requiring to modify these applications. `urcu_bp_init()`,
230`urcu_bp_register_thread()` and `urcu_bp_unregister_thread()` all become
231nops. The state is dealt with by the library internally at the expense
232of read-side and write-side performance.
d589a916
PP
233
234
235### Initialization
236
237Each thread that has reader critical sections (that uses
f328865f
MD
238`urcu_<flavor>_read_lock()`/`urcu_<flavor>_read_unlock()` must first
239register to the URCU library. This is done by calling
240`urcu_<flavor>_register_thread()`. Unregistration must be performed
241before exiting the thread by using `urcu_<flavor>_unregister_thread()`.
d589a916
PP
242
243
244### Reading
245
246Reader critical sections must be protected by locating them between
f328865f
MD
247calls to `urcu_<flavor>_read_lock()` and `urcu_<flavor>_read_unlock()`.
248Inside that lock, `rcu_dereference()` may be called to read an RCU
249protected pointer.
d589a916
PP
250
251
252### Writing
253
254`rcu_assign_pointer()` and `rcu_xchg_pointer()` may be called anywhere.
f328865f
MD
255After, `urcu_<flavor>_synchronize_rcu()` must be called. When it
256returns, the old values are not in usage anymore.
d589a916
PP
257
258
259### Usage of `liburcu-defer`
260
f328865f 261 - Follow instructions for either `liburcu-memb`, `liburcu-qsbr`,
d589a916
PP
262 `liburcu-mb`, `liburcu-signal`, or `liburcu-bp` above.
263 The `liburcu-defer` functionality is pulled into each of
264 those library modules.
f328865f
MD
265 - Provides `urcu_<flavor>_defer_rcu()` primitive to enqueue delayed
266 callbacks. Queued callbacks are executed in batch periodically after
267 a grace period. Do _not_ use `urcu_<flavor>_defer_rcu()` within a
268 read-side critical section, because it may call
269 `urcu_<flavor>_synchronize_rcu()` if the thread queue is full. This
270 can lead to deadlock or worse.
271 - Requires that `urcu_<flavor>_defer_barrier()` must be called in
272 library destructor if a library queues callbacks and is expected to
273 be unloaded with `dlclose()`.
d589a916
PP
274
275Its API is currently experimental. It may change in future library releases.
276
277
278### Usage of `urcu-call-rcu`
279
f328865f 280 - Follow instructions for either `liburcu-memb`, `liburcu-qsbr`,
d589a916
PP
281 `liburcu-mb`, `liburcu-signal`, or `liburcu-bp` above.
282 The `urcu-call-rcu` functionality is pulled into each of
283 those library modules.
f328865f
MD
284 - Provides the `urcu_<flavor>_call_rcu()` primitive to enqueue delayed
285 callbacks in a manner similar to `urcu_<flavor>_defer_rcu()`, but
286 without ever delaying for a grace period. On the other hand,
287 `urcu_<flavor>_call_rcu()`'s best-case overhead is not quite as good
288 as that of `urcu_<flavor>_defer_rcu()`.
289 - Provides `urcu_<flavor>_call_rcu()` to allow asynchronous handling
290 of RCU grace periods. A number of additional functions are provided
291 to manage the helper threads used by `urcu_<flavor>_call_rcu()`, but
292 reasonable defaults are used if these additional functions are not
293 invoked. See [`doc/rcu-api.md`](doc/rcu-api.md) in userspace-rcu
294 documentation for more details.
d589a916
PP
295
296
297### Being careful with signals
298
f328865f 299The `liburcu-signal` library uses signals internally. The signal handler is
d589a916
PP
300registered with the `SA_RESTART` flag. However, these signals may cause
301some non-restartable system calls to fail with `errno = EINTR`. Care
302should be taken to restart system calls manually if they fail with this
303error. A list of non-restartable system calls may be found in
f328865f 304`signal(7)`.
d589a916
PP
305
306Read-side critical sections are allowed in a signal handler,
f328865f 307except those setup with `sigaltstack(2)`, with `liburcu-memb` and
d589a916 308`liburcu-mb`. Be careful, however, to disable these signals
f328865f
MD
309between thread creation and calls to `urcu_<flavor>_register_thread()`,
310because a signal handler nesting on an unregistered thread would not be
311allowed to call `urcu_<flavor>_read_lock()`.
d589a916
PP
312
313Read-side critical sections are _not_ allowed in a signal handler with
314`liburcu-qsbr`, unless signals are disabled explicitly around each
f328865f
MD
315`urcu_qsbr_quiescent_state()` calls, when threads are put offline and around
316calls to `urcu_qsbr_synchronize_rcu()`. Even then, we do not recommend it.
d589a916
PP
317
318
319### Interaction with mutexes
320
321One must be careful to do not cause deadlocks due to interaction of
f328865f
MD
322`urcu_<flavor>_synchronize_rcu()` and RCU read-side with mutexes. If
323`urcu_<flavor>_synchronize_rcu()` is called with a mutex held, this
324mutex (or any mutex which has this mutex in its dependency chain) should
325not be acquired from within a RCU read-side critical section.
d589a916
PP
326
327This is especially important to understand in the context of the
328QSBR flavor: a registered reader thread being "online" by
329default should be considered as within a RCU read-side critical
330section unless explicitly put "offline". Therefore, if
f328865f
MD
331`urcu_qsbr_synchronize_rcu()` is called with a mutex held, this mutex,
332as well as any mutex which has this mutex in its dependency chain should
333only be taken when the RCU reader thread is "offline" (this can be
334performed by calling `urcu_qsbr_thread_offline()`).
d589a916
PP
335
336
337### Interaction with `fork()`
338
339Special care must be taken for applications performing `fork()` without
340any following `exec()`. This is caused by the fact that Linux only clones
341the thread calling `fork()`, and thus never replicates any of the other
342parent thread into the child process. Most `liburcu` implementations
343require that all registrations (as reader, `defer_rcu` and `call_rcu`
344threads) should be released before a `fork()` is performed, except for the
345rather common scenario where `fork()` is immediately followed by `exec()` in
346the child process. The only implementation not subject to that rule is
347`liburcu-bp`, which is designed to handle `fork()` by calling
f328865f
MD
348`urcu_bp_before_fork`, `urcu_bp_after_fork_parent` and
349`urcu_bp_after_fork_child`.
350
351Applications that use `urcu_<flavor>_call_rcu()` and that `fork()`
352without doing an immediate `exec()` must take special action. The
353parent must invoke `urcu_<flavor>_call_rcu_before_fork()` before the
354`fork()` and `urcu_<flavor>_call_rcu_after_fork_parent()` after the
355`fork()`. The child process must invoke
356`urcu_<flavor>_call_rcu_after_fork_child()`. Even though these three
357APIs are suitable for passing to `pthread_atfork()`, use of
358`pthread_atfork()` is **STRONGLY DISCOURAGED** for programs calling the
359glibc memory allocator (`malloc()`, `calloc()`, `free()`, ...) within
360`urcu_<flavor>_call_rcu` callbacks. This is due to limitations in the
361way glibc memory allocator handles calls to the memory allocator from
362concurrent threads while the `pthread_atfork()` handlers are executing.
d589a916
PP
363
364Combining e.g.:
365
f328865f
MD
366 - call to `free()` from callbacks executed within
367 `urcu_<flavor>_call_rcu` worker threads,
368 - executing `urcu_<flavor>_call_rcu` atfork handlers within the glibc
369 pthread atfork mechanism,
d589a916
PP
370
371will sometimes trigger interesting process hangs. This usually
372hangs on a memory allocator lock within glibc.
373
374
375### Thread Local Storage (TLS)
376
377Userspace RCU can fall back on `pthread_getspecific()` to emulate
378TLS variables on systems where it is not available. This behavior
379can be forced by specifying `--disable-compiler-tls` as configure
380argument.
381
382
d4e640c0 383### Usage of `DEBUG_RCU` & `--enable-rcu-debug`
d589a916 384
d4e640c0
JR
385By default the library is configured with internal debugging
386self-checks disabled.
387
388For always-on debugging self-checks:
389 ./configure --enable-rcu-debug
390
391For fine grained enabling of debugging self-checks, build
64cd023f 392userspace-rcu with DEBUG_RCU defined and compile dependent
d4e640c0
JR
393applications with DEBUG_RCU defined when necessary.
394
395Warning: Enabling this feature result in a performance penalty.
d589a916
PP
396
397
398### Usage of `DEBUG_YIELD`
399
400`DEBUG_YIELD` is used to add random delays in the code for testing
401purposes.
402
403
404### SMP support
405
406By default the library is configured to use synchronization primitives
407adequate for SMP systems. On uniprocessor systems, support for SMP
408systems can be disabled with:
409
410 ./configure --disable-smp-support
411
412theoretically yielding slightly better performance.
413
414
d7c76f85
MD
415### Usage of `--enable-cds-lfht-iter-debug`
416
417By default the library is configured with extra debugging checks for
418lock-free hash table iterator traversal disabled.
419
420Building liburcu with --enable-cds-lfht-iter-debug and rebuilding
421application to match the ABI change allows finding cases where the hash
422table iterator is re-purposed to be used on a different hash table while
423still being used to iterate on a hash table.
424
425This option alters the rculfhash ABI. Make sure to compile both library
426and application with matching configuration.
427
428
d589a916
PP
429Make targets
430------------
431
432In addition to the usual `make check` target, Userspace RCU features
433`make regtest` and `make bench` targets:
434
435 - `make check`: short tests, meant to be run when rebuilding or
436 porting Userspace RCU.
437 - `make regtest`: long (many hours) test, meant to be run when
438 modifying Userspace RCU or porting it to a new architecture or
439 operating system.
440 - `make bench`: long (many hours) benchmarks.
441
442
bff8f20a
MD
443Known issues
444------------
445
446There is an application vs library compatibility issue between
447applications built using Userspace RCU 0.10 headers linked against
448Userspace RCU 0.11 or 0.12 shared objects. The problem occurs as
449follows:
450
451 - An application executable is built with _LGPL_SOURCE defined, includes
452 any of the Userspace RCU 0.10 urcu flavor headers, and is built
453 without the -fpic compiler option.
454
455 - The Userspace RCU 0.10 library shared objects are updated to 0.11
456 or 0.12 without rebuilding the application.
457
458 - The application will hang, typically when RCU grace period
459 (synchronize_rcu) is invoked.
460
461Some possible work-arounds for this are:
462
463 - Rebuild the application against Userspace RCU 0.11+.
464
465 - Rebuild the application with -fpic.
466
467 - Upgrade Userspace RCU to 0.13+ without installing 0.11 nor 0.12.
468
469
d589a916
PP
470Contacts
471--------
472
473You can contact the maintainers on the following mailing list:
dcb9c05a 474`lttng-dev@lists.lttng.org`.
This page took 0.049406 seconds and 4 git commands to generate.