Permalink
Browse files

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...
pkhuong authored and sbahra committed Dec 3, 2018
1 parent 21d3e31 commit a16642f95c048c65d47107205a2cfc70d099dbd6
@@ -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

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -6,6 +6,7 @@ DIR=array \
bytelock \
cc \
cohort \
ec \
epoch \
fifo \
hp \
@@ -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
@@ -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; \
@@ -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

Oops, something went wrong.

0 comments on commit a16642f

Please sign in to comment.