#include "threads-model.h"
#include "clockvector.h"
#include "execution.h"
+#include <sys/time.h>
-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);
+}
+
+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) {
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());
}
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);
}
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;
}
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;
}
}