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