From 5e7a1a00c4645f90d860274e2f25c33992c2ad86 Mon Sep 17 00:00:00 2001 From: Brian Demsky Date: Thu, 20 Jun 2019 13:29:33 -0700 Subject: [PATCH] Optimizations --- Makefile | 3 --- execution.cc | 41 +++++++++++++++++++++-------------------- execution.h | 5 ++--- fuzzer.cc | 2 +- fuzzer.h | 2 +- main.cc | 2 +- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 7c73b9ba..b62e72a9 100644 --- a/Makefile +++ b/Makefile @@ -36,9 +36,6 @@ README.html: README.md malloc.o: malloc.c $(CC) -fPIC -c malloc.c -DMSPACES -DONLY_MSPACES -DHAVE_MMAP=0 $(CPPFLAGS) -Wno-unused-variable -futex.o: futex.cc - $(CXX) -fPIC -c futex.cc -std=c++11 $(CPPFLAGS) - %.o : %.cc $(CXX) -MMD -MF .$@.d -fPIC -c $< $(CPPFLAGS) diff --git a/execution.cc b/execution.cc index 99f86195..8b718ba5 100644 --- a/execution.cc +++ b/execution.cc @@ -109,18 +109,6 @@ static SnapVector * get_safe_ptr_vect_action(HashTable *wrv = obj_thrd_map.get(obj); - if (wrv==NULL) - return NULL; - unsigned int thread=id_to_int(tid); - if (thread < wrv->size()) - return &(*wrv)[thread]; - else - return NULL; -} - /** @return a thread ID for a new Thread */ thread_id_t ModelExecution::get_next_id() { @@ -272,7 +260,7 @@ bool ModelExecution::is_complete_execution() const * @param rf_set is the set of model actions we can possibly read from * @return True if processing this read updates the mo_graph. */ -void ModelExecution::process_read(ModelAction *curr, SnapVector * rf_set) +void ModelExecution::process_read(ModelAction *curr, SnapVector * rf_set) { SnapVector * priorset = new SnapVector(); while(true) { @@ -374,8 +362,10 @@ bool ModelExecution::process_mutex(ModelAction *curr) } case ATOMIC_NOTIFY_ONE: { action_list_t *waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location()); - Thread * thread = fuzzer->selectNotify(waiters); - scheduler->wake(thread); + if (waiters->size() != 0) { + Thread * thread = fuzzer->selectNotify(waiters); + scheduler->wake(thread); + } break; } @@ -685,7 +675,7 @@ ModelAction * ModelExecution::check_current_action(ModelAction *curr) if (!second_part_of_rmw && curr->get_type() != NOOP) add_action_to_lists(curr); - SnapVector * rf_set = NULL; + SnapVector * rf_set = NULL; /* Build may_read_from set for newly-created actions */ if (newly_explored && curr->is_read()) rf_set = build_may_read_from(curr); @@ -1313,7 +1303,7 @@ bool valequals(uint64_t val1, uint64_t val2, int size) { * @param curr is the current ModelAction that we are exploring; it must be a * 'read' operation. */ -SnapVector * ModelExecution::build_may_read_from(ModelAction *curr) +SnapVector * ModelExecution::build_may_read_from(ModelAction *curr) { SnapVector *thrd_lists = obj_thrd_map.get(curr->get_location()); unsigned int i; @@ -1324,7 +1314,7 @@ SnapVector * ModelExecution::build_may_read_from(ModelAction *cu if (curr->is_seqcst()) last_sc_write = get_last_seq_cst_write(curr); - SnapVector * rf_set = new SnapVector(); + SnapVector * rf_set = new SnapVector(); /* Iterate over all threads */ for (i = 0;i < thrd_lists->size();i++) { @@ -1332,10 +1322,21 @@ SnapVector * ModelExecution::build_may_read_from(ModelAction *cu action_list_t *list = &(*thrd_lists)[i]; action_list_t::reverse_iterator rit; for (rit = list->rbegin();rit != list->rend();rit++) { - ModelAction *act = *rit; + const ModelAction *act = *rit; /* Only consider 'write' actions */ - if (!act->is_write() || act == curr) + if (!act->is_write()) { + if (act != curr && act->is_read() && act->happens_before(curr)) { + const ModelAction *tmp = act->get_reads_from(); + if (((unsigned int) id_to_int(tmp->get_tid()))==i) + act = tmp; + else + break; + } else + continue; + } + + if (act == curr) continue; /* Don't consider more than one seq_cst write if we are a seq_cst read. */ diff --git a/execution.h b/execution.h index b78837fc..990a7a8a 100644 --- a/execution.h +++ b/execution.h @@ -84,7 +84,6 @@ public: ModelAction * get_parent_action(thread_id_t tid) const; bool isfeasibleprefix() const; - action_list_t * get_actions_on_obj(void * obj, thread_id_t tid) const; ModelAction * get_last_action(thread_id_t tid) const; bool check_action_enabled(ModelAction *curr); @@ -127,7 +126,7 @@ private: bool next_execution(); ModelAction * check_current_action(ModelAction *curr); bool initialize_curr_action(ModelAction **curr); - void process_read(ModelAction *curr, SnapVector * rf_set); + void process_read(ModelAction *curr, SnapVector * rf_set); void process_write(ModelAction *curr); bool process_fence(ModelAction *curr); bool process_mutex(ModelAction *curr); @@ -141,7 +140,7 @@ private: ModelAction * get_last_seq_cst_write(ModelAction *curr) const; ModelAction * get_last_seq_cst_fence(thread_id_t tid, const ModelAction *before_fence) const; ModelAction * get_last_unlock(ModelAction *curr) const; - SnapVector * build_may_read_from(ModelAction *curr); + SnapVector * build_may_read_from(ModelAction *curr); ModelAction * process_rmw(ModelAction *curr); bool r_modification_order(ModelAction *curr, const ModelAction *rf, SnapVector *priorset); diff --git a/fuzzer.cc b/fuzzer.cc index 9ad61c3c..3a3f9883 100644 --- a/fuzzer.cc +++ b/fuzzer.cc @@ -3,7 +3,7 @@ #include "threads-model.h" #include "model.h" -int Fuzzer::selectWrite(ModelAction *read, SnapVector * rf_set) { +int Fuzzer::selectWrite(ModelAction *read, SnapVector * rf_set) { int random_index = random() % rf_set->size(); return random_index; } diff --git a/fuzzer.h b/fuzzer.h index 6cf1efba..691477bd 100644 --- a/fuzzer.h +++ b/fuzzer.h @@ -7,7 +7,7 @@ class Fuzzer { public: Fuzzer() {} - int selectWrite(ModelAction *read, SnapVector* rf_set); + int selectWrite(ModelAction *read, SnapVector* rf_set); Thread * selectThread(Node *n, int * threadlist, int numthreads); Thread * selectNotify(action_list_t * waiters); MEMALLOC diff --git a/main.cc b/main.cc index dd0722b9..7ce43cbf 100644 --- a/main.cc +++ b/main.cc @@ -208,5 +208,5 @@ int main(int argc, char **argv) redirect_output(); /* Let's jump in quickly and start running stuff */ - snapshot_system_init(10000, 1024, 1024, 4000, &model_main); + snapshot_system_init(10000, 1024, 1024, 40000, &model_main); } -- 2.34.1