X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=scanalysis.cc;h=6fc1e0810e88013005eb64b93a92de22b6d3a20f;hp=e6cbddc71e4f01f70f176e7c63ad5917c25888b2;hb=e79a7cd8e9c85d37a5d5c2a81ca14b1017b1b305;hpb=b756884bdc8b22457243b76982cf10dc4598f927 diff --git a/scanalysis.cc b/scanalysis.cc index e6cbddc..6fc1e08 100644 --- a/scanalysis.cc +++ b/scanalysis.cc @@ -3,18 +3,75 @@ #include "threads-model.h" #include "clockvector.h" #include "execution.h" +#include -SCAnalysis::SCAnalysis(const ModelExecution *execution) : + +SCAnalysis::SCAnalysis() : cvmap(), cyclic(false), badrfset(), lastwrmap(), threadlists(1), - execution(execution) + execution(NULL), + print_always(false), + print_buggy(true), + print_nonsc(false), + time(false), + stats((struct sc_statistics *)model_calloc(1, sizeof(struct sc_statistics))) { } SCAnalysis::~SCAnalysis() { + delete(stats); +} + +void SCAnalysis::setExecution(ModelExecution * execution) { + this->execution=execution; +} + +const char * SCAnalysis::name() { + const char * name = "SC"; + return name; +} + +void SCAnalysis::finish() { + if (time) + model_print("Elapsed time in usec %llu\n", stats->elapsedtime); + model_print("SC count: %u\n", stats->sccount); + model_print("Non-SC count: %u\n", stats->nonsccount); + model_print("Total actions: %llu\n", stats->actions); + unsigned long long actionperexec=(stats->actions)/(stats->sccount+stats->nonsccount); + model_print("Actions per execution: %llu\n", actionperexec); +} + +bool SCAnalysis::option(char * opt) { + if (strcmp(opt, "verbose")==0) { + print_always=true; + return false; + } else if (strcmp(opt, "buggy")==0) { + return false; + } else if (strcmp(opt, "quiet")==0) { + print_buggy=false; + return false; + } else if (strcmp(opt, "nonsc")==0) { + print_nonsc=true; + return false; + } else if (strcmp(opt, "time")==0) { + time=true; + return false; + } else if (strcmp(opt, "help") != 0) { + model_print("Unrecognized option: %s\n", opt); + } + + model_print("SC Analysis options\n"); + model_print("verbose -- print all feasible executions\n"); + model_print("buggy -- print only buggy executions (default)\n"); + model_print("nonsc -- print non-sc execution\n"); + model_print("quiet -- print nothing\n"); + model_print("time -- time execution of scanalysis\n"); + model_print("\n"); + + return true; } void SCAnalysis::print_list(action_list_t *list) { @@ -30,7 +87,7 @@ void SCAnalysis::print_list(action_list_t *list) { model_print("BRF "); act->print(); if (badrfset.contains(act)) { - model_print("Desired Rf: %u \n",badrfset.get(act)->get_seq_number()); + model_print("Desired Rf: %u \n", badrfset.get(act)->get_seq_number()); } } hash = hash ^ (hash << 3) ^ ((*it)->hash()); @@ -40,17 +97,36 @@ void SCAnalysis::print_list(action_list_t *list) { } void SCAnalysis::analyze(action_list_t *actions) { + + struct timeval start; + struct timeval finish; + if (time) + gettimeofday(&start, NULL); action_list_t *list = generateSC(actions); check_rf(list); - print_list(list); + if (print_always || (print_buggy && execution->have_bug_reports())|| (print_nonsc && cyclic)) + print_list(list); + if (time) { + gettimeofday(&finish, NULL); + stats->elapsedtime+=((finish.tv_sec*1000000+finish.tv_usec)-(start.tv_sec*1000000+start.tv_usec)); + } + update_stats(); +} + +void SCAnalysis::update_stats() { + if (cyclic) { + stats->nonsccount++; + } else { + stats->sccount++; + } } void SCAnalysis::check_rf(action_list_t *list) { for (action_list_t::iterator it = list->begin(); it != list->end(); it++) { const ModelAction *act = *it; if (act->is_read()) { - if (act->get_reads_from()!=lastwrmap.get(act->get_location())) - badrfset.put(act,lastwrmap.get(act->get_location())); + if (act->get_reads_from() != lastwrmap.get(act->get_location())) + badrfset.put(act, lastwrmap.get(act->get_location())); } if (act->is_write()) lastwrmap.put(act->get_location(), act); @@ -58,11 +134,11 @@ void SCAnalysis::check_rf(action_list_t *list) { } bool SCAnalysis::merge(ClockVector *cv, const ModelAction *act, const ModelAction *act2) { - ClockVector * cv2=cvmap.get(act2); - if (cv2==NULL) + ClockVector *cv2 = cvmap.get(act2); + if (cv2 == NULL) return true; if (cv2->getClock(act->get_tid()) >= act->get_seq_number() && act->get_seq_number() != 0) { - cyclic=true; + cyclic = true; //refuse to introduce cycles into clock vectors return false; } @@ -178,6 +254,8 @@ ModelAction * SCAnalysis::pruneArray(ModelAction **array,int count) { action_list_t * SCAnalysis::generateSC(action_list_t *list) { int numactions=buildVectors(list); + stats->actions+=numactions; + computeCV(list); action_list_t *sclist = new action_list_t(); @@ -332,7 +410,7 @@ bool SCAnalysis::processRead(ModelAction *read, ClockVector *cv) { write -rf-> R => write2 -sc-> write */ if (cv->synchronized_since(write2)) { - changed |= writecv==NULL || merge(writecv, write, write2); + changed |= writecv == NULL || merge(writecv, write, write2); break; } }