X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=datarace.h;h=34bfd4067dc99ad591a21d1ca621ca5498f0ff67;hp=b2f709911ecff2274596ed11f7c5338365ee57e7;hb=25d73096cfc14c655f94b01bb235cc5efd1d5696;hpb=620c53f1b91d3f9b51424ff57c652d247f6fbaac diff --git a/datarace.h b/datarace.h index b2f70991..34bfd406 100644 --- a/datarace.h +++ b/datarace.h @@ -2,11 +2,14 @@ * @brief Data race detection code. */ -#ifndef DATARACE_H +#ifndef __DATARACE_H__ +#define __DATARACE_H__ + #include "config.h" #include -#include "clockvector.h" -#include +#include "modeltypes.h" +#include "classlist.h" +#include "hashset.h" struct ShadowTable { void * array[65536]; @@ -18,7 +21,7 @@ struct ShadowBaseTable { struct DataRace { /* Clock and thread associated with first action. This won't change in - response to synchronization. */ + response to synchronization. */ thread_id_t oldthread; modelclock_t oldclock; @@ -26,60 +29,99 @@ struct DataRace { bool isoldwrite; /* Model action associated with second action. This could change as - a result of synchronization. */ + a result of synchronization. */ ModelAction *newaction; /* Record whether this is a write, so we can tell the user. */ bool isnewwrite; /* Address of data race. */ - void *address; + const void *address; + void * backtrace[64]; + int numframes; }; #define MASK16BIT 0xffff void initRaceDetector(); -void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock); -void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock); -void checkDataRaces(); -void printRace(struct DataRace *race); - -extern std::vector unrealizedraces; - -/** Basic encoding idea: - * (void *) Either: - * (1) points to a full record or - * - * (2) encodes the information in a 64 bit word. Encoding is as - * follows: lowest bit set to 1, next 8 bits are read thread id, next - * 23 bits are read clock vector, next 8 bites are write thread id, - * next 23 bits are write clock vector. */ +void raceCheckWrite(thread_id_t thread, void *location); +void atomraceCheckWrite(thread_id_t thread, void *location); +void raceCheckRead(thread_id_t thread, const void *location); + +void atomraceCheckRead(thread_id_t thread, const void *location); +void recordWrite(thread_id_t thread, void *location); +void recordCalloc(void *location, size_t size); +void assert_race(struct DataRace *race); +bool hasNonAtomicStore(const void *location); +void setAtomicStoreFlag(const void *location); +void getStoreThreadAndClock(const void *address, thread_id_t * thread, modelclock_t * clock); + +void raceCheckRead8(thread_id_t thread, const void *location); +void raceCheckRead16(thread_id_t thread, const void *location); +void raceCheckRead32(thread_id_t thread, const void *location); +void raceCheckRead64(thread_id_t thread, const void *location); + +void raceCheckWrite8(thread_id_t thread, const void *location); +void raceCheckWrite16(thread_id_t thread, const void *location); +void raceCheckWrite32(thread_id_t thread, const void *location); +void raceCheckWrite64(thread_id_t thread, const void *location); + +#ifdef COLLECT_STAT +void print_normal_accesses(); +#endif +/** + * @brief A record of information for detecting data races + */ struct RaceRecord { modelclock_t *readClock; thread_id_t *thread; - int capacity; - int numReads; + int numReads : 31; + int isAtomic : 1; thread_id_t writeThread; modelclock_t writeClock; }; +unsigned int race_hash(struct DataRace *race); +bool race_equals(struct DataRace *r1, struct DataRace *r2); + #define INITCAPACITY 4 #define ISSHORTRECORD(x) ((x)&0x1) -#define THREADMASK 0xff +#define THREADMASK 0x3f #define RDTHREADID(x) (((x)>>1)&THREADMASK) -#define READMASK 0x07fffff -#define READVECTOR(x) (((x)>>9)&READMASK) +#define READMASK 0x1ffffff +#define READVECTOR(x) (((x)>>7)&READMASK) #define WRTHREADID(x) (((x)>>32)&THREADMASK) #define WRITEMASK READMASK -#define WRITEVECTOR(x) (((x)>>40)&WRITEMASK) - -#define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 9) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<40)) +#define WRITEVECTOR(x) (((x)>>38)&WRITEMASK) + +#define ATOMICMASK (0x1ULL << 63) +#define NONATOMICMASK ~(0x1ULL << 63) + +/** + * The basic encoding idea is that (void *) either: + * -# points to a full record (RaceRecord) or + * -# encodes the information in a 64 bit word. Encoding is as + * follows: + * - lowest bit set to 1 + * - next 6 bits are read thread id + * - next 25 bits are read clock vector + * - next 6 bits are write thread id + * - next 25 bits are write clock vector + * - highest bit is 1 if the write is from an atomic + */ +#define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 7) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<38)) #define MAXTHREADID (THREADMASK-1) #define MAXREADVECTOR (READMASK-1) #define MAXWRITEVECTOR (WRITEMASK-1) -#endif + +#define INVALIDSHADOWVAL 0x2ULL +#define CHECKBOUNDARY(location, bits) ((((uintptr_t)location & MASK16BIT) + bits) <= MASK16BIT) + +typedef HashSet RaceSet; + +#endif /* __DATARACE_H__ */