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