From d49c09078cfbb85f565cc59b83ec727bc08b72bf Mon Sep 17 00:00:00 2001 From: weiyu Date: Tue, 21 Apr 2020 15:38:09 -0700 Subject: [PATCH] Define invalid shadow value --- datarace.cc | 33 ++++++++++++++++----------------- datarace.h | 2 ++ librace.cc | 47 ----------------------------------------------- 3 files changed, 18 insertions(+), 64 deletions(-) diff --git a/datarace.cc b/datarace.cc index 8cb0c8fc..8c1f1dda 100644 --- a/datarace.cc +++ b/datarace.cc @@ -756,6 +756,9 @@ static inline void raceCheckRead_firstIt(thread_id_t thread, const void * locati } *shadow = ENCODEOP(threadid, ourClock, id_to_int(writeThread), writeClock) | (shadowval & ATOMICMASK); + + *old_val = shadowval; + *new_val = *shadow; } Exit: if (race) { @@ -764,10 +767,6 @@ Exit: assert_race(race); else model_free(race); } - - - *old_val = shadowval; - *new_val = *shadow; } static inline void raceCheckRead_otherIt(thread_id_t thread, const void * location, uint64_t first_shadowval, uint64_t updated_shadowval) @@ -775,7 +774,7 @@ static inline void raceCheckRead_otherIt(thread_id_t thread, const void * locati uint64_t *shadow = lookupAddressEntry(location); uint64_t shadowval = *shadow; - if (shadowval != 0 && shadowval == first_shadowval) { + if (shadowval == first_shadowval) { *shadow = updated_shadowval; return; } @@ -840,7 +839,7 @@ Exit: void raceCheckRead64(thread_id_t thread, const void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckRead_firstIt(thread, location, &old_shadowval, &new_shadowval); raceCheckRead_otherIt(thread, (const void *)(((uintptr_t)location) + 1), old_shadowval, new_shadowval); @@ -855,7 +854,7 @@ void raceCheckRead64(thread_id_t thread, const void *location) void raceCheckRead32(thread_id_t thread, const void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckRead_firstIt(thread, location, &old_shadowval, &new_shadowval); raceCheckRead_otherIt(thread, (const void *)(((uintptr_t)location) + 1), old_shadowval, new_shadowval); @@ -866,7 +865,7 @@ void raceCheckRead32(thread_id_t thread, const void *location) void raceCheckRead16(thread_id_t thread, const void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckRead_firstIt(thread, location, &old_shadowval, &new_shadowval); raceCheckRead_otherIt(thread, (const void *)(((uintptr_t)location) + 1), old_shadowval, new_shadowval); @@ -875,7 +874,7 @@ void raceCheckRead16(thread_id_t thread, const void *location) void raceCheckRead8(thread_id_t thread, const void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckRead_firstIt(thread, location, &old_shadowval, &new_shadowval); } @@ -932,6 +931,9 @@ static inline void raceCheckWrite_firstIt(thread_id_t thread, void * location, u ShadowExit: *shadow = ENCODEOP(0, 0, threadid, ourClock); + + *old_val = shadowval; + *new_val = *shadow; } Exit: @@ -941,9 +943,6 @@ Exit: assert_race(race); else model_free(race); } - - *old_val = shadowval; - *new_val = *shadow; } static inline void raceCheckWrite_otherIt(thread_id_t thread, void * location, uint64_t first_shadowval, uint64_t updated_shadowval) @@ -951,7 +950,7 @@ static inline void raceCheckWrite_otherIt(thread_id_t thread, void * location, u uint64_t *shadow = lookupAddressEntry(location); uint64_t shadowval = *shadow; - if (shadowval != 0 && shadowval == first_shadowval) { + if (shadowval == first_shadowval) { *shadow = updated_shadowval; return; } @@ -1018,7 +1017,7 @@ Exit: void raceCheckWrite64(thread_id_t thread, void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckWrite_firstIt(thread, location, &old_shadowval, &new_shadowval); raceCheckWrite_otherIt(thread, (void *)(((uintptr_t)location) + 1), old_shadowval, new_shadowval); @@ -1033,7 +1032,7 @@ void raceCheckWrite64(thread_id_t thread, void *location) void raceCheckWrite32(thread_id_t thread, void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckWrite_firstIt(thread, location, &old_shadowval, &new_shadowval); raceCheckWrite_otherIt(thread, (void *)(((uintptr_t)location) + 1), old_shadowval, new_shadowval); @@ -1044,7 +1043,7 @@ void raceCheckWrite32(thread_id_t thread, void *location) void raceCheckWrite16(thread_id_t thread, void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckWrite_firstIt(thread, location, &old_shadowval, &new_shadowval); raceCheckWrite_otherIt(thread, (void *)(((uintptr_t)location) + 1), old_shadowval, new_shadowval); @@ -1053,7 +1052,7 @@ void raceCheckWrite16(thread_id_t thread, void *location) void raceCheckWrite8(thread_id_t thread, void *location) { uint64_t old_shadowval, new_shadowval; - old_shadowval = new_shadowval = 0; + old_shadowval = new_shadowval = INVALIDSHADOWVAL; raceCheckWrite_firstIt(thread, location, &old_shadowval, &new_shadowval); } diff --git a/datarace.h b/datarace.h index a9bc92f6..296118a2 100644 --- a/datarace.h +++ b/datarace.h @@ -111,6 +111,8 @@ bool race_equals(struct DataRace *r1, struct DataRace *r2); */ #define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 7) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<38)) +#define INVALIDSHADOWVAL 0x2ULL + #define MAXTHREADID (THREADMASK-1) #define MAXREADVECTOR (READMASK-1) #define MAXWRITEVECTOR (WRITEMASK-1) diff --git a/librace.cc b/librace.cc index 1d1ebbfc..8ecf2afc 100644 --- a/librace.cc +++ b/librace.cc @@ -108,8 +108,6 @@ void cds_store8(void *addr) return; thread_id_t tid = thread_current()->get_id(); raceCheckWrite8(tid, addr); - -// raceCheckWrite(tid, addr); } void cds_store16(void *addr) @@ -119,9 +117,6 @@ void cds_store16(void *addr) return; thread_id_t tid = thread_current()->get_id(); raceCheckWrite16(tid, addr); - -// raceCheckWrite(tid, addr); -// raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 1)); } void cds_store32(void *addr) @@ -131,13 +126,6 @@ void cds_store32(void *addr) return; thread_id_t tid = thread_current()->get_id(); raceCheckWrite32(tid, addr); - -/* - raceCheckWrite(tid, addr); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 1)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 2)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 3)); -*/ } void cds_store64(void *addr) @@ -147,67 +135,32 @@ void cds_store64(void *addr) return; thread_id_t tid = thread_current()->get_id(); raceCheckWrite64(tid, addr); - -/* - raceCheckWrite(tid, addr); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 1)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 2)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 3)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 4)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 5)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 6)); - raceCheckWrite(tid, (void *)(((uintptr_t)addr) + 7)); -*/ } void cds_load8(const void *addr) { if (!model) return; thread_id_t tid = thread_current()->get_id(); - raceCheckRead8(tid, addr); - -// raceCheckRead(tid, addr); } void cds_load16(const void *addr) { if (!model) return; thread_id_t tid = thread_current()->get_id(); - raceCheckRead16(tid, addr); -// raceCheckRead(tid, addr); -// raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 1)); } void cds_load32(const void *addr) { if (!model) return; thread_id_t tid = thread_current()->get_id(); - raceCheckRead32(tid, addr); -/* - raceCheckRead(tid, addr); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 1)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 2)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 3)); -*/ } void cds_load64(const void *addr) { if (!model) return; thread_id_t tid = thread_current()->get_id(); - raceCheckRead64(tid, addr); -/* - raceCheckRead(tid, addr); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 1)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 2)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 3)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 4)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 5)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 6)); - raceCheckRead(tid, (const void *)(((uintptr_t)addr) + 7)); -*/ } -- 2.34.1