2 * @brief Data race detection code.
8 #include "modeltypes.h"
11 /* Forward declaration */
19 struct ShadowBaseTable {
20 uint64_t array[65536];
24 /* Clock and thread associated with first action. This won't change in
25 response to synchronization. */
27 thread_id_t oldthread;
28 modelclock_t oldclock;
29 /* Record whether this is a write, so we can tell the user. */
32 /* Model action associated with second action. This could change as
33 a result of synchronization. */
34 ModelAction *newaction;
35 /* Record whether this is a write, so we can tell the user. */
38 /* Address of data race. */
42 #define MASK16BIT 0xffff
44 void initRaceDetector();
45 void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock);
46 void raceCheckRead(thread_id_t thread, const void *location, ClockVector *currClock);
47 bool checkDataRaces();
48 void assert_race(struct DataRace *race);
50 extern SnapVector<struct DataRace *> unrealizedraces;
53 * @brief A record of information for detecting data races
56 modelclock_t *readClock;
60 thread_id_t writeThread;
61 modelclock_t writeClock;
64 #define INITCAPACITY 4
66 #define ISSHORTRECORD(x) ((x)&0x1)
68 #define THREADMASK 0xff
69 #define RDTHREADID(x) (((x)>>1)&THREADMASK)
70 #define READMASK 0x07fffff
71 #define READVECTOR(x) (((x)>>9)&READMASK)
73 #define WRTHREADID(x) (((x)>>32)&THREADMASK)
75 #define WRITEMASK READMASK
76 #define WRITEVECTOR(x) (((x)>>40)&WRITEMASK)
79 * The basic encoding idea is that (void *) either:
80 * -# points to a full record (RaceRecord) or
81 * -# encodes the information in a 64 bit word. Encoding is as
83 * - lowest bit set to 1
84 * - next 8 bits are read thread id
85 * - next 23 bits are read clock vector
86 * - next 8 bits are write thread id
87 * - next 23 bits are write clock vector
89 #define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 9) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<40))
91 #define MAXTHREADID (THREADMASK-1)
92 #define MAXREADVECTOR (READMASK-1)
93 #define MAXWRITEVECTOR (WRITEMASK-1)