X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=datarace.cc;h=1cc407bb991889545210f54ec313ae84c49cf412;hp=5a23d82d5d97d865f486a9ebbd2913b93e9230f9;hb=50b95c3747f4fe79b2ab1a1a6fc303224e16e418;hpb=2db2ef3b8bdabacc7784fd5a4e7e7520f1cd2298 diff --git a/datarace.cc b/datarace.cc index 5a23d82..1cc407b 100644 --- a/datarace.cc +++ b/datarace.cc @@ -1,22 +1,22 @@ #include "datarace.h" +#include "model.h" #include "threads.h" #include #include struct ShadowTable *root; +std::vector unrealizedraces; /** This function initialized the data race detector. */ - void initRaceDetector() { root=(struct ShadowTable *) calloc(sizeof(struct ShadowTable),1); } -/** This function looks up the entry in the shadow table corresponding - to a given address.*/ - +/** This function looks up the entry in the shadow table corresponding to a + * given address.*/ static uint64_t * lookupAddressEntry(void * address) { struct ShadowTable *currtable=root; -#ifdef BIT48 +#if BIT48 currtable=(struct ShadowTable *) currtable->array[(((uintptr_t)address)>>32)&MASK16BIT]; if (currtable==NULL) { currtable=(struct ShadowTable *) (root->array[(((uintptr_t)address)>>32)&MASK16BIT]=calloc(sizeof(struct ShadowTable),1)); @@ -49,7 +49,6 @@ static bool clock_may_race(ClockVector *clock1, thread_id_t tid1, * Expands a record from the compact form to the full form. This is * necessary for multiple readers or for very large thread ids or time * stamps. */ - static void expandRecord(uint64_t * shadow) { uint64_t shadowval=*shadow; @@ -74,15 +73,60 @@ static void expandRecord(uint64_t * shadow) { } /** This function is called when we detect a data race.*/ +static void reportDataRace(thread_id_t oldthread, modelclock_t oldclock, bool isoldwrite, ModelAction *newaction, bool isnewwrite, void *address) { + struct DataRace * race=(struct DataRace *)malloc(sizeof(struct DataRace)); + race->oldthread=oldthread; + race->oldclock=oldclock; + race->isoldwrite=isoldwrite; + race->newaction=newaction; + race->isnewwrite=isnewwrite; + race->address=address; + unrealizedraces.push_back(race); + + /* If the race is realized, bail out now. */ + if (checkDataRaces()) { + model->set_assert(); + model->switch_to_master(NULL); + } +} -static void reportDataRace() { - printf("The reportDataRace method should report useful things about this datarace!\n"); +/** This function goes through the list of unrealized data races, + * removes the impossible ones, and print the realized ones. */ + +bool checkDataRaces() { + if (model->isfeasibleprefix()) { + /* Prune the non-racing unrealized dataraces */ + unsigned int i,newloc=0; + for(i=0;inewaction->get_cv(), race->newaction->get_tid(), race->oldclock, race->oldthread)) { + unrealizedraces[newloc++]=race; + } + } + if (newloc!=i) + unrealizedraces.resize(newloc); + + if (unrealizedraces.size()!=0) { + /* We have an actual realized race. */ + for(i=0;iaddress); + printf("Initial access: thread %u clock %u, iswrite %u\n",race->oldthread,race->oldclock, race->isoldwrite); + printf("Second access: thread %u clock %u, iswrite %u\n", race->newaction->get_tid(), race->newaction->get_seq_number() , race->isnewwrite); +} -void fullRaceCheckWrite(thread_id_t thread, uint64_t * shadow, ClockVector *currClock) { +/** This function does race detection for a write on an expanded record. */ +void fullRaceCheckWrite(thread_id_t thread, void *location, uint64_t * shadow, ClockVector *currClock) { struct RaceRecord * record=(struct RaceRecord *) (*shadow); /* Check for datarace against last read. */ @@ -96,7 +140,7 @@ void fullRaceCheckWrite(thread_id_t thread, uint64_t * shadow, ClockVector *curr if (clock_may_race(currClock, thread, readClock, readThread)) { /* We have a datarace */ - reportDataRace(); + reportDataRace(readThread, readClock, false, model->get_parent_action(thread), true, location); } } @@ -107,7 +151,7 @@ void fullRaceCheckWrite(thread_id_t thread, uint64_t * shadow, ClockVector *curr if (clock_may_race(currClock, thread, writeClock, writeThread)) { /* We have a datarace */ - reportDataRace(); + reportDataRace(writeThread, writeClock, true, model->get_parent_action(thread), true, location); } record->numReads=0; @@ -116,16 +160,14 @@ void fullRaceCheckWrite(thread_id_t thread, uint64_t * shadow, ClockVector *curr record->writeClock=ourClock; } -/** This function does race detection on a write. - */ - +/** This function does race detection on a write. */ void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock) { uint64_t * shadow=lookupAddressEntry(location); uint64_t shadowval=*shadow; /* Do full record */ if (shadowval!=0&&!ISSHORTRECORD(shadowval)) { - fullRaceCheckWrite(thread, shadow, currClock); + fullRaceCheckWrite(thread, location, shadow, currClock); return; } @@ -135,7 +177,7 @@ void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock) /* Thread ID is too large or clock is too large. */ if (threadid > MAXTHREADID || ourClock > MAXWRITEVECTOR) { expandRecord(shadow); - fullRaceCheckWrite(thread, shadow, currClock); + fullRaceCheckWrite(thread, location, shadow, currClock); return; } @@ -146,7 +188,7 @@ void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock) if (clock_may_race(currClock, thread, readClock, readThread)) { /* We have a datarace */ - reportDataRace(); + reportDataRace(readThread, readClock, false, model->get_parent_action(thread), true, location); } /* Check for datarace against last write. */ @@ -156,15 +198,13 @@ void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock) if (clock_may_race(currClock, thread, writeClock, writeThread)) { /* We have a datarace */ - reportDataRace(); + reportDataRace(writeThread, writeClock, true, model->get_parent_action(thread), true, location); } *shadow = ENCODEOP(0, 0, threadid, ourClock); } -/** This function does race detection on a read for an expanded - * record. */ - -void fullRaceCheckRead(thread_id_t thread, uint64_t * shadow, ClockVector *currClock) { +/** This function does race detection on a read for an expanded record. */ +void fullRaceCheckRead(thread_id_t thread, void *location, uint64_t * shadow, ClockVector *currClock) { struct RaceRecord * record=(struct RaceRecord *) (*shadow); /* Check for datarace against last write. */ @@ -174,7 +214,7 @@ void fullRaceCheckRead(thread_id_t thread, uint64_t * shadow, ClockVector *currC if (clock_may_race(currClock, thread, writeClock, writeThread)) { /* We have a datarace */ - reportDataRace(); + reportDataRace(writeThread, writeClock, true, model->get_parent_action(thread), false, location); } /* Shorten vector when possible */ @@ -222,14 +262,13 @@ void fullRaceCheckRead(thread_id_t thread, uint64_t * shadow, ClockVector *currC } /** This function does race detection on a read. */ - void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock) { uint64_t * shadow=lookupAddressEntry(location); uint64_t shadowval=*shadow; /* Do full record */ if (shadowval!=0&&!ISSHORTRECORD(shadowval)) { - fullRaceCheckRead(thread, shadow, currClock); + fullRaceCheckRead(thread, location, shadow, currClock); return; } @@ -239,7 +278,7 @@ void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock) { /* Thread ID is too large or clock is too large. */ if (threadid > MAXTHREADID || ourClock > MAXWRITEVECTOR) { expandRecord(shadow); - fullRaceCheckRead(thread, shadow, currClock); + fullRaceCheckRead(thread, location, shadow, currClock); return; } @@ -250,7 +289,7 @@ void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock) { if (clock_may_race(currClock, thread, writeClock, writeThread)) { /* We have a datarace */ - reportDataRace(); + reportDataRace(writeThread, writeClock, true, model->get_parent_action(thread), false, location); } modelclock_t readClock = READVECTOR(shadowval); @@ -259,9 +298,9 @@ void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock) { if (clock_may_race(currClock, thread, readClock, readThread)) { /* We don't subsume this read... Have to expand record. */ expandRecord(shadow); - fullRaceCheckRead(thread, shadow, currClock); + fullRaceCheckRead(thread, location, shadow, currClock); return; } - *shadow = ENCODEOP(writeThread, writeClock, threadid, ourClock); + *shadow = ENCODEOP(threadid, ourClock, id_to_int(writeThread), writeClock); }