Define invalid shadow value
authorweiyu <weiyuluo1232@gmail.com>
Tue, 21 Apr 2020 22:38:09 +0000 (15:38 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Tue, 21 Apr 2020 22:38:09 +0000 (15:38 -0700)
datarace.cc
datarace.h
librace.cc

index 8cb0c8fc4bfac7b2467012956943f13abb3d08b3..8c1f1ddae6fa54e8bcfbcba3a3d3e12f6d40d84e 100644 (file)
@@ -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);
 }
index a9bc92f6625d30c54a2a50da995b543085471079..296118a2d6b305c3dad1da850e338a9c67983b94 100644 (file)
@@ -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)
index 1d1ebbfc49338b06e6a9980ecd08faf08c35e615..8ecf2afc1daa90db43fb692e76ed8c6c58a90210 100644 (file)
@@ -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));
-*/
 }