From 2ddb5d2c8170fe40d0f056d86e98f22c87c8c722 Mon Sep 17 00:00:00 2001 From: weiyu Date: Wed, 9 Oct 2019 15:09:42 -0700 Subject: [PATCH] Some edits --- hashtable.h | 3 +++ history.cc | 26 ++++++++++++++++++-------- waitobj.cc | 39 +++++++++++++++++---------------------- waitobj.h | 2 +- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/hashtable.h b/hashtable.h index c9da5aad..4758999a 100644 --- a/hashtable.h +++ b/hashtable.h @@ -284,6 +284,9 @@ public: return size; } + bool isEmpty() { + return size == 0; + } /** * @brief Check whether the table contains a value for the given key diff --git a/history.cc b/history.cc index 9969c016..2ad4c1a9 100644 --- a/history.cc +++ b/history.cc @@ -153,8 +153,6 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) thrd_func_act_lists = execution->get_thrd_func_act_lists(); uint32_t thread_id = id_to_int(tid); - uint32_t func_id = (*thrd_func_list)[thread_id].back(); - /* Return if thread tid has not entered any function that contains atomics */ if ( thrd_func_list->size() <= thread_id ) return; @@ -179,23 +177,25 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) check_waiting_write(act); } + uint32_t func_id = (*thrd_func_list)[thread_id].back(); + /* The following does not care about actions that are not inside * any function that contains atomics or actions without a position */ if (func_id == 0 || act->get_position() == NULL) return; SnapList * func_act_lists = (*thrd_func_act_lists)[thread_id]; + /* The list of actions that thread tid has taken in its current function */ action_list_t * curr_act_list = func_act_lists->back(); - ASSERT(curr_act_list != NULL); if (skip_action(act, curr_act_list)) return; - FuncNode * func_node = func_nodes[func_id]; - /* Add to curr_inst_list */ curr_act_list->push_back(act); + + FuncNode * func_node = func_nodes[func_id]; func_node->add_inst(act); if (act->is_read()) { @@ -460,6 +460,8 @@ SnapVector * ModelHistory::getThrdInstActMap(uint32_t func_id) bool ModelHistory::skip_action(ModelAction * act, SnapList * curr_act_list) { + ASSERT(curr_act_list != NULL); + bool second_part_of_rmw = act->is_rmwc() || act->is_rmw(); modelclock_t curr_seq_number = act->get_seq_number(); @@ -514,7 +516,7 @@ void ModelHistory::monitor_waiting_thread(uint32_t func_id, thread_id_t tid) } } -void monitor_waiting_thread_counter(thread_id_t tid) +void ModelHistory::monitor_waiting_thread_counter(thread_id_t tid) { WaitObj * wait_obj = getWaitObj(tid); thrd_id_set_t * waited_by = wait_obj->getWaitedBy(); @@ -528,8 +530,16 @@ void monitor_waiting_thread_counter(thread_id_t tid) bool expire = other_wait_obj->incr_counter(tid); if (expire) { - // TODO: complete - expire_threads.push_back(tid); + wait_obj->remove_waited_by(waited_by_id); + other_wait_obj->remove_waiting_for(tid); + + thrd_id_set_t * other_waiting_for = other_wait_obj->getWaitingFor(); + if ( other_waiting_for->isEmpty() ) { + // model_print("\tthread %d waits for nobody, wake up\n", self_id); + ModelExecution * execution = model->get_execution(); + Thread * thread = execution->get_thread(waited_by_id); + execution->getFuzzer()->notify_paused_thread(thread); + } } } } diff --git a/waitobj.cc b/waitobj.cc index 5a1bc12f..692f0203 100644 --- a/waitobj.cc +++ b/waitobj.cc @@ -54,7 +54,10 @@ bool WaitObj::remove_waiting_for_node(thread_id_t other, FuncNode * node) /* The thread has no nodes to reach */ if (target_nodes->isEmpty()) { + int index = id_to_int(other); + thrd_action_counters[index] = 0; waiting_for.remove(other); + return true; } @@ -64,11 +67,17 @@ bool WaitObj::remove_waiting_for_node(thread_id_t other, FuncNode * node) /* Stop waiting for the thread */ void WaitObj::remove_waiting_for(thread_id_t other) { - // TODO: clear dist_map or not? waiting_for.remove(other); + // TODO: clear dist_map or not? + /* dist_map_t * dist_map = getDistMap(other); + dist_map->reset(); */ + node_set_t * target_nodes = getTargetNodes(other); target_nodes->reset(); + + int index = id_to_int(other); + thrd_action_counters[index] = 0; } void WaitObj::remove_waited_by(thread_id_t other) @@ -119,24 +128,6 @@ node_set_t * WaitObj::getTargetNodes(thread_id_t tid) return thrd_target_nodes[thread_id]; } -/* -SnapVector WaitObj::incr_waiting_for_counter() -{ - SnapVector expire_thrds; - - thrd_id_set_iter * iter = waiting_for.iterator(); - while (iter->hasNext()) { - thread_id_t waiting_for_id = iter->next(); - bool expire = incr_counter(waiting_for_id); - - if (expire) { - expire_thrds.push_back(waiting_for_id); - } - } - - return expire_thrds; -}*/ - /** * Increment action counter for thread tid * @return true if the counter for tid expires @@ -151,7 +142,6 @@ bool WaitObj::incr_counter(thread_id_t tid) } thrd_action_counters[thread_id]++; - if (thrd_action_counters[thread_id] > 1000) return true; @@ -164,9 +154,14 @@ void WaitObj::clear_waiting_for() while (iter->hasNext()) { thread_id_t tid = iter->next(); int index = id_to_int(tid); - thrd_target_nodes[index]->reset(); + thrd_action_counters[index] = 0; + /* thrd_dist_maps are not reset because distances - * will be overwritten when node targets are added */ + * will be overwritten when node targets are added + * thrd_dist_maps[index]->reset(); */ + + node_set_t * target_nodes = getTargetNodes(tid); + target_nodes->reset(); } waiting_for.reset(); diff --git a/waitobj.h b/waitobj.h index c15fb21f..36d95796 100644 --- a/waitobj.h +++ b/waitobj.h @@ -18,6 +18,7 @@ public: void add_waiting_for(thread_id_t other, FuncNode * node, int dist); void add_waited_by(thread_id_t other); bool remove_waiting_for_node(thread_id_t other, FuncNode * node); + void remove_waiting_for(thread_id_t other); void remove_waited_by(thread_id_t other); thrd_id_set_t * getWaitingFor() { return &waiting_for; } @@ -27,7 +28,6 @@ public: int lookup_dist(thread_id_t tid, FuncNode * target); bool incr_counter(thread_id_t tid); - // SnapVector incr_waiting_for_counter(); void clear_waiting_for(); -- 2.34.1