From 7b00825b34d57a9ae4db2a46b5c77f46753e1749 Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Thu, 19 Nov 2015 13:07:25 -0800 Subject: [PATCH] edits --- benchmark/chase-lev-deque-bugfix/deque.c | 126 +++++++++++++---------- benchmark/chase-lev-deque-bugfix/deque.h | 6 +- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/benchmark/chase-lev-deque-bugfix/deque.c b/benchmark/chase-lev-deque-bugfix/deque.c index 3ad32af..4fc9ff3 100644 --- a/benchmark/chase-lev-deque-bugfix/deque.c +++ b/benchmark/chase-lev-deque-bugfix/deque.c @@ -25,35 +25,30 @@ int take(Deque *q) { /** @Begin @Commit_point_define_check: true - @Label: Take_Read_Bottom + @Label: TakeReadBottom @End */ Array *a = (Array *) atomic_load_explicit(&q->array, memory_order_relaxed); - /** - //@Begin - @Commit_point_define_check: true - @Label: Take_Read_Array - @End - */ atomic_store_explicit(&q->bottom, b, memory_order_relaxed); /**** SPEC (sequential) (testcase1.c) ****/ atomic_thread_fence(memory_order_seq_cst); size_t t = atomic_load_explicit(&q->top, memory_order_relaxed); - /** - //@Begin - @Commit_point_define_check: t != b - @Label: Take_Read_Top - @End - */ int x; if (t <= b) { + /** + @Begin + @Commit_point_clear: true + @Label: TakeClear1 + @End + */ + /* Non-empty queue. */ int size = atomic_load_explicit(&a->size,memory_order_relaxed); x = atomic_load_explicit(&a->buffer[b % size], memory_order_relaxed); /** - //@Begin - @Commit_point_define_check: t != b - @Label: Take_Read_Buffer + @Begin + @Commit_point_define_check: true + @Label: TakeReadBuffer @End */ if (t == b) { @@ -61,20 +56,21 @@ int take(Deque *q) { //FIXME: weaken the following seq_cst causes no spec problem bool succ = atomic_compare_exchange_strong_explicit(&q->top, &t, t + 1, memory_order_seq_cst, memory_order_relaxed); - /** - //@Begin - @Commit_point_define_check: succ - @Label: Take_CAS_Top - @End - */ - - /** - @Begin - @Additional_ordering_point_define_check: true - @Label: Take_Additional_Point - @End - */ if (!succ) { + /** + @Begin + @Commit_point_clear: true + @Label: TakeClear2 + @End + */ + + /** + @Begin + @Commit_point_define_check: true + @Label: TakeReadTop + @End + */ + /* Failed race. */ x = EMPTY; } @@ -96,6 +92,14 @@ void resize(Deque *q) { size_t bottom=atomic_load_explicit(&q->bottom, memory_order_relaxed); atomic_store_explicit(&new_a->size, new_size, memory_order_relaxed); size_t i; + + // Initialize the whole new array to turn off the CDSChecker UL error + // Check if CDSSpec checker can catch this bug + /* + for(i=0; i < new_size; i++) { + atomic_store_explicit(&new_a->buffer[i % new_size], atomic_load_explicit(&a->buffer[i % size], memory_order_relaxed), memory_order_relaxed); + } + */ for(i=top; i < bottom; i++) { atomic_store_explicit(&new_a->buffer[i % new_size], atomic_load_explicit(&a->buffer[i % size], memory_order_relaxed), memory_order_relaxed); } @@ -119,32 +123,18 @@ void push(Deque *q, int x) { // CDSSpec can actually detect the same bug if we avoid the UL error //Bug in paper...should have next line... a = (Array *) atomic_load_explicit(&q->array, memory_order_relaxed); - /** - //@Begin - @Commit_point_define_check: true - @Label: Push_Read_Array - @End - */ } int size = atomic_load_explicit(&a->size, memory_order_relaxed); atomic_store_explicit(&a->buffer[b % size], x, memory_order_relaxed); - /** - //@Begin - @Commit_point_define_check: true - @Label: Push_Update_Buffer - @End - */ - /**** SPEC (Sync) (run with -u100 to avoid the uninitialized bug) ****/ - atomic_thread_fence(memory_order_release); - // Watch out!!! We need to specifiy the fence as the commit point because - // the synchronization in C11 actually is established at the fence. /** @Begin @Commit_point_define_check: true - @Label: Push_Update_Bottom + @Label: PushUpdateBuffer @End */ + /**** UL & SPEC (Sync) (run with -u100 to avoid the uninitialized bug) ****/ + atomic_thread_fence(memory_order_release); atomic_store_explicit(&q->bottom, b + 1, memory_order_relaxed); } @@ -158,33 +148,55 @@ int steal(Deque *q) { //Watch out: actually on need to be an acquire (don't count it) // An old bug size_t t = atomic_load_explicit(&q->top, memory_order_acquire); - //FIXME: remove the fence causes no error and fewer executions.. - atomic_thread_fence(memory_order_seq_cst); - /**** SPEC & UL ****/ - size_t b = atomic_load_explicit(&q->bottom, memory_order_acquire); /** @Begin - @Commit_point_define_check: true - @Label: Steal_Read_Bottom + @Commit_point_define_check: true + @Label: StealReadTop1 @End */ + //FIXME: remove the fence causes no error and fewer executions.. + atomic_thread_fence(memory_order_seq_cst); + /**** SPEC & UL ****/ + size_t b = atomic_load_explicit(&q->bottom, memory_order_acquire); + int x = EMPTY; if (t < b) { + /** + @Begin + @Commit_point_clear: true + @Label: StealClear1 + @End + */ + /* Non-empty queue. */ /**** detected UL ****/ Array *a = (Array *) atomic_load_explicit(&q->array, memory_order_acquire); int size = atomic_load_explicit(&a->size, memory_order_relaxed); x = atomic_load_explicit(&a->buffer[t % size], memory_order_relaxed); - /**** SPEC (sequential) ****/ - bool succ = atomic_compare_exchange_strong_explicit(&q->top, &t, t + 1, - memory_order_seq_cst, memory_order_relaxed); /** @Begin - @Additional_ordering_point_define_check: true - @Label: Steal_Additional_Point + @Commit_point_define_check: true + @Label: StealReadBuffer @End */ + /**** SPEC (sequential) ****/ + bool succ = atomic_compare_exchange_strong_explicit(&q->top, &t, t + 1, + memory_order_seq_cst, memory_order_relaxed); if (!succ) { + /** + @Begin + @Commit_point_clear: true + @Label: StealClear2 + @End + */ + + /** + @Begin + @Commit_point_define_check: true + @Label: StealReadTop2 + @End + */ + /* Failed race. */ return ABORT; } diff --git a/benchmark/chase-lev-deque-bugfix/deque.h b/benchmark/chase-lev-deque-bugfix/deque.h index 82560f1..e652f22 100644 --- a/benchmark/chase-lev-deque-bugfix/deque.h +++ b/benchmark/chase-lev-deque-bugfix/deque.h @@ -53,7 +53,7 @@ void resize(Deque *q); /** @Begin @Interface: Take - @Commit_point_set: Take_Read_Bottom | Take_Additional_Point + @Commit_point_set: TakeReadBottom | TakeReadBuffer | TakeReadTop @ID: succ(__RET__) ? __RET__ : DEFAULT_CALL_ID @Action: int elem = 0; @@ -70,7 +70,7 @@ int take(Deque *q); /** @Begin @Interface: Push - @Commit_point_set: Push_Update_Bottom + @Commit_point_set: PushUpdateBuffer @ID: x @Action: push_back(__deque, x); @@ -82,7 +82,7 @@ void push(Deque *q, int x); /** @Begin @Interface: Steal - @Commit_point_set: Steal_Read_Bottom | Steal_Additional_Point + @Commit_point_set: StealReadTop1 | StealReadTop2 | StealReadBuffer @ID: succ(__RET__) ? __RET__ : DEFAULT_CALL_ID @Action: int elem = 0; -- 2.34.1