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