From dc255d1dd25f734bc6b1aae2f39418381c0823b5 Mon Sep 17 00:00:00 2001 From: weiyu Date: Fri, 4 Oct 2019 19:02:10 -0700 Subject: [PATCH] Add some methods for WaitObj --- history.cc | 27 +++++++++++++++++++++++++++ history.h | 4 +++- newfuzzer.cc | 14 +------------- waitobj.cc | 29 +++++++++++++++++++++++++++++ waitobj.h | 7 +++++++ 5 files changed, 67 insertions(+), 14 deletions(-) diff --git a/history.cc b/history.cc index 8682da31..93abfbc0 100644 --- a/history.cc +++ b/history.cc @@ -378,6 +378,28 @@ WaitObj * ModelHistory::getWaitObj(thread_id_t tid) return (*thrd_wait_obj)[thread_id]; } +void ModelHistory::add_waiting_thread(thread_id_t self_id, + thread_id_t waiting_for_id, int dist) +{ + WaitObj * self_wait_obj = getWaitObj(self_id); + self_wait_obj->add_waiting_for(waiting_for_id, dist); + + /* Update waited-by relation */ + WaitObj * other_wait_obj = getWaitObj(waiting_for_id); + other_wait_obj->add_waited_by(self_id); +} + +void ModelHistory::remove_waiting_thread(thread_id_t self_id, thread_id_t waiting_for_id) +{ + WaitObj * self_wait_obj = getWaitObj(self_id); + self_wait_obj->remove_waiting_for(waiting_for_id); + + /* Update waited-by relation */ + WaitObj * other_wait_obj = getWaitObj(waiting_for_id); + other_wait_obj->remove_waited_by(self_id); +} + + SnapVector * ModelHistory::getThrdInstActMap(uint32_t func_id) { ASSERT(func_id != 0); @@ -464,6 +486,11 @@ void ModelHistory::print_waiting_threads() thread_id_t tid = int_to_id(i); WaitObj * wait_obj = getWaitObj(tid); wait_obj->print_waiting_for(); + } + + for (unsigned int i = 0; i < execution->get_num_threads();i++) { + thread_id_t tid = int_to_id(i); + WaitObj * wait_obj = getWaitObj(tid); wait_obj->print_waited_by(); } } diff --git a/history.h b/history.h index 2cf93f8a..80307769 100644 --- a/history.h +++ b/history.h @@ -38,8 +38,10 @@ public: void remove_waiting_write(thread_id_t tid); void check_waiting_write(ModelAction * write_act); SnapVector * getThrdWaitingWrite() { return thrd_waiting_write; } - thrd_id_set_t * getWaitingFor(thread_id_t tid); + WaitObj * getWaitObj(thread_id_t tid); + void add_waiting_thread(thread_id_t self_id, thread_id_t waiting_for_id, int dist); + void remove_waiting_thread(thread_id_t self_id, thread_id_t waiting_for_id); SnapVector * getThrdInstActMap(uint32_t func_id); diff --git a/newfuzzer.cc b/newfuzzer.cc index 490ce049..69f1ce14 100644 --- a/newfuzzer.cc +++ b/newfuzzer.cc @@ -295,7 +295,6 @@ void NewFuzzer::find_threads(ModelAction * pending_read) { void * location = pending_read->get_location(); thread_id_t self_id = pending_read->get_tid(); - HashSet waiting_for_threads(64); SnapVector * func_node_list = history->getWrFuncNodes(location); for (uint i = 0; i < func_node_list->size(); i++) { @@ -312,24 +311,13 @@ void NewFuzzer::find_threads(ModelAction * pending_read) int distance = node->compute_distance(target_node); if (distance != -1) { - waiting_for_threads.add(tid); + history->add_waiting_thread(self_id, tid, distance); model_print("thread: %d; distance from node %d to node %d: %d\n", tid, node->get_func_id(), target_node->get_func_id(), distance); } } } - - /* Clear list first */ - WaitObj * wait_obj = history->getWaitObj(self_id); - thrd_id_set_t * waiting_threads = wait_obj->getWaitingFor(); - waiting_threads->reset(); - - HSIterator * it = waiting_for_threads.iterator(); - while (it->hasNext()) { - thread_id_t tid = it->next(); - waiting_threads->add(tid); - } } bool NewFuzzer::shouldWait(const ModelAction * act) diff --git a/waitobj.cc b/waitobj.cc index e9299f59..3aaa632e 100644 --- a/waitobj.cc +++ b/waitobj.cc @@ -7,6 +7,28 @@ WaitObj::WaitObj(thread_id_t tid) : dist_table(32) {} +void WaitObj::add_waiting_for(thread_id_t other, int dist) +{ + waiting_for.add(other); + dist_table.put(other, dist); +} + +void WaitObj::add_waited_by(thread_id_t other) +{ + waited_by.add(other); +} + +void WaitObj::remove_waiting_for(thread_id_t other) +{ + waiting_for.remove(other); + dist_table.remove(other); +} + +void WaitObj::remove_waited_by(thread_id_t other) +{ + waited_by.remove(other); +} + int WaitObj::lookup_dist(thread_id_t other_id) { if (dist_table.contains(other_id)) @@ -15,6 +37,13 @@ int WaitObj::lookup_dist(thread_id_t other_id) return -1; } +void WaitObj::reset() +{ + waiting_for.reset(); + waited_by.reset(); + dist_table.reset(); +} + void WaitObj::print_waiting_for() { if (waiting_for.getSize() == 0) diff --git a/waitobj.h b/waitobj.h index 26f7f1c7..ae7a5fe5 100644 --- a/waitobj.h +++ b/waitobj.h @@ -11,10 +11,17 @@ public: thread_id_t get_tid() { return tid; } + void add_waiting_for(thread_id_t other, int dist); + void add_waited_by(thread_id_t other); + void remove_waiting_for(thread_id_t other); + void remove_waited_by(thread_id_t other); + thrd_id_set_t * getWaitingFor() { return &waiting_for; } thrd_id_set_t * getWaitingBy() { return &waited_by; } int lookup_dist(thread_id_t other_tid); + void reset(); + void print_waiting_for(); void print_waited_by(); -- 2.34.1