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