Please sign in to comment.
ck_ec: event count with optimistic OS-level blocking (#133)
ck_ec implements 32- and (on 64 bit platforms) 64- bit event counts. Event counts let us easily integrate OS-level blocking (e.g., futexes) in lock-free protocols. Waking up waiters only locks in the OS kernel, and does not happen at all when no waiter is blocked. Waiters only block conditionally, if the event count's value is still equal to some prior value. ck_ec supports multiple producers (wakers) and consumers (waiters), and, on x86-TSO, has a more efficient specialisation for single producer mode. In the latter mode, the overhead compared to a version counter is on the order of 2-3 cycles and 1-2 instructions, in the fast path. The slow path, when there are threads blocked on the event count, consists of one additional atomic instruction and a futex syscall. Similarly, the fast path for consumers, when an update comes quickly, has no overhead compared to spinning on a read-only counter. After a few thousand cycles, consumers (waiters) enter the slow path with one atomic instruction and a few blocking syscalls. The single-producer specialisation requires the x86-TSO memory model, x86's non-atomic read-modify-write instructions, and, ideally a futex-like OS abstraction. On !x86/x86_64 platforms, single producer increments fall back to the multiple producer code path. Fixes #79
- Loading branch information...
Showing with 3,411 additions and 0 deletions.
- +9 −0 .gitignore
- +945 −0 include/ck_ec.h
- +5 −0 regressions/Makefile
- +18 −0 regressions/ck_ec/benchmark/Makefile
- +484 −0 regressions/ck_ec/benchmark/ck_ec.c
- +55 −0 regressions/ck_ec/validate/Makefile
- +450 −0 regressions/ck_ec/validate/ck_ec_smoke_test.c
- +95 −0 regressions/ck_ec/validate/fuzz_harness.h
- +110 −0 regressions/ck_ec/validate/prop_test_slow_wakeup.c
- +101 −0 regressions/ck_ec/validate/prop_test_timeutil_add.c
- +88 −0 regressions/ck_ec/validate/prop_test_timeutil_add_ns.c
- +99 −0 regressions/ck_ec/validate/prop_test_timeutil_cmp.c
- +41 −0 regressions/ck_ec/validate/prop_test_timeutil_scale.c
- +150 −0 regressions/ck_ec/validate/prop_test_value.c
- +193 −0 regressions/ck_ec/validate/prop_test_wakeup.c
- +4 −0 src/Makefile.in
- +414 −0 src/ck_ec.c
- +150 −0 src/ck_ec_timeutil.h
|@@ -0,0 +1,18 @@|
|.PHONY: check clean distribution|
|ck_ec: ck_ec.c ../../../include/ck_ec.h|
|$(CC) $(CFLAGS) ../../../src/ck_ec.c -o ck_ec ck_ec.c|
|./ck_ec $(CORES) 1|
|rm -rf *~ *.o $(OBJECTS) *.dSYM *.exe|
Oops, something went wrong.