Skip to content

Commit

Permalink
ck_ec: event count with optimistic OS-level blocking (#133)
Browse files Browse the repository at this point in the history
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
pkhuong authored and sbahra committed Dec 3, 2018
1 parent 21d3e31 commit a16642f
Show file tree
Hide file tree
Showing 18 changed files with 3,411 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ regressions/ck_cc/validate/ck_cc_nobuiltin
regressions/ck_cohort/benchmark/ck_cohort.LATENCY
regressions/ck_cohort/benchmark/ck_cohort.THROUGHPUT
regressions/ck_cohort/validate/validate
regressions/ck_ec/benchmark/ck_ec
regressions/ck_ec/validate/ck_ec_smoke_test
regressions/ck_ec/validate/prop_test_slow_wakeup
regressions/ck_ec/validate/prop_test_timeutil_add
regressions/ck_ec/validate/prop_test_timeutil_add_ns
regressions/ck_ec/validate/prop_test_timeutil_cmp
regressions/ck_ec/validate/prop_test_timeutil_scale
regressions/ck_ec/validate/prop_test_value
regressions/ck_ec/validate/prop_test_wakeup
regressions/ck_epoch/validate/ck_epoch_call
regressions/ck_epoch/validate/ck_epoch_poll
regressions/ck_epoch/validate/ck_epoch_section
Expand Down
945 changes: 945 additions & 0 deletions include/ck_ec.h

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions regressions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ DIR=array \
bytelock \
cc \
cohort \
ec \
epoch \
fifo \
hp \
Expand Down Expand Up @@ -71,6 +72,8 @@ all:
$(MAKE) -C ./ck_pflock/benchmark all
$(MAKE) -C ./ck_hp/validate all
$(MAKE) -C ./ck_hp/benchmark all
$(MAKE) -C ./ck_ec/validate all
$(MAKE) -C ./ck_ec/benchmark all

clean:
$(MAKE) -C ./ck_array/validate clean
Expand Down Expand Up @@ -119,6 +122,8 @@ clean:
$(MAKE) -C ./ck_pflock/benchmark clean
$(MAKE) -C ./ck_hp/validate clean
$(MAKE) -C ./ck_hp/benchmark clean
$(MAKE) -C ./ck_ec/validate clean
$(MAKE) -C ./ck_ec/benchmark clean

check: all
rc=0; \
Expand Down
18 changes: 18 additions & 0 deletions regressions/ck_ec/benchmark/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: check clean distribution

OBJECTS=ck_ec

all: $(OBJECTS)

ck_ec: ck_ec.c ../../../include/ck_ec.h
$(CC) $(CFLAGS) ../../../src/ck_ec.c -o ck_ec ck_ec.c

check: all
./ck_ec $(CORES) 1

clean:
rm -rf *~ *.o $(OBJECTS) *.dSYM *.exe

include ../../../build/regressions.build
CFLAGS+=-D_GNU_SOURCE

Loading

0 comments on commit a16642f

Please sign in to comment.