From: weiyu Date: Fri, 31 Jan 2020 01:28:35 +0000 (-0800) Subject: Complete the transfer of deletions of some actions X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=527eb9241e1b39b6ad4125a71b951d445d4e251e Complete the transfer of deletions of some actions --- diff --git a/action.cc b/action.cc index 89a61b74..ee980b87 100644 --- a/action.cc +++ b/action.cc @@ -41,7 +41,7 @@ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, trace_ref(NULL), thrdmap_ref(NULL), action_ref(NULL), - func_act_ref(NULL), + func_ref_count(0), value(value), type(type), original_type(ATOMIC_NOP), @@ -78,7 +78,7 @@ ModelAction::ModelAction(action_type_t type, memory_order order, uint64_t value, trace_ref(NULL), thrdmap_ref(NULL), action_ref(NULL), - func_act_ref(NULL), + func_ref_count(0), value(value), type(type), original_type(ATOMIC_NOP), @@ -114,7 +114,7 @@ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, trace_ref(NULL), thrdmap_ref(NULL), action_ref(NULL), - func_act_ref(NULL), + func_ref_count(0), value(value), type(type), original_type(ATOMIC_NOP), @@ -154,7 +154,7 @@ ModelAction::ModelAction(action_type_t type, const char * position, memory_order trace_ref(NULL), thrdmap_ref(NULL), action_ref(NULL), - func_act_ref(NULL), + func_ref_count(0), value(value), type(type), original_type(ATOMIC_NOP), @@ -195,7 +195,7 @@ ModelAction::ModelAction(action_type_t type, const char * position, memory_order trace_ref(NULL), thrdmap_ref(NULL), action_ref(NULL), - func_act_ref(NULL), + func_ref_count(0), value(value), type(type), original_type(ATOMIC_NOP), diff --git a/action.h b/action.h index 67c1ae81..f792de21 100644 --- a/action.h +++ b/action.h @@ -200,11 +200,13 @@ public: void setTraceRef(sllnode *ref) { trace_ref = ref; } void setThrdMapRef(sllnode *ref) { thrdmap_ref = ref; } void setActionRef(sllnode *ref) { action_ref = ref; } - void setFuncActRef(void *ref) { func_act_ref = ref; } sllnode * getTraceRef() { return trace_ref; } sllnode * getThrdMapRef() { return thrdmap_ref; } sllnode * getActionRef() { return action_ref; } - void * getFuncActRef() { return func_act_ref; } + + void incr_func_ref_count() { func_ref_count++; } + void decr_func_ref_count() { if (func_ref_count > 0) func_ref_count--; } + uint32_t get_func_ref_count() { return func_ref_count; } SNAPSHOTALLOC private: @@ -243,7 +245,9 @@ private: sllnode * trace_ref; sllnode * thrdmap_ref; sllnode * action_ref; - void * func_act_ref; + + /** @brief Number of read actions that are reading from this store */ + uint32_t func_ref_count; /** @brief The value written (for write or RMW; undefined for read) */ uint64_t value; diff --git a/execution.cc b/execution.cc index 999a58f0..bfb93278 100644 --- a/execution.cc +++ b/execution.cc @@ -1813,7 +1813,7 @@ void ModelExecution::collectActions() { // Only delete this action if not being using by ModelHistory. // Otherwise, the deletion of action is deferred. - if (act->getFuncActRef() == NULL) { + if (act->get_func_ref_count() == 0) { delete act; continue; } @@ -1855,7 +1855,7 @@ void ModelExecution::collectActions() { if (islastact) { fixupLastAct(act); } - if (act->getFuncActRef() == NULL) { + if (act->get_func_ref_count() == 0) { delete act; continue; } @@ -1866,7 +1866,7 @@ void ModelExecution::collectActions() { if (islastact) { fixupLastAct(act); } - if (act->getFuncActRef() == NULL) { + if (act->get_func_ref_count() == 0) { delete act; continue; } diff --git a/funcnode.cc b/funcnode.cc index 4172f417..691b2f69 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -177,6 +177,7 @@ void FuncNode::update_tree(action_list_t * act_list) return; HashTable * write_history = history->getWriteHistory(); + HashSet write_actions; /* build inst_list from act_list for later processing */ func_inst_list_t inst_list; @@ -185,10 +186,13 @@ void FuncNode::update_tree(action_list_t * act_list) for (sllnode * it = act_list->begin();it != NULL;it = it->getNext()) { ModelAction * act = it->getVal(); + // Use the original action type and decrement ref count + // so that actions may be deleted by Execution::collectActions if (act->get_original_type() != ATOMIC_NOP && act->get_swap_flag() == false) act->use_original_type(); - // Remove func_act_ref so that actions can be deleted by Execution::collectActions + act->decr_read_ref_count(); + if (act->is_read()) { // For every read or rmw actions in this list, the reads_from was marked, and not deleted. // So it is safe to call get_reads_from @@ -196,9 +200,8 @@ void FuncNode::update_tree(action_list_t * act_list) if (rf->get_original_type() != ATOMIC_NOP && rf->get_swap_flag() == false) rf->use_original_type(); - rf->setFuncActRef(NULL); + rf->decr_read_ref_count(); } - act->setFuncActRef(NULL); FuncInst * func_inst = get_inst(act); void * loc = act->get_location(); @@ -244,10 +247,22 @@ void FuncNode::update_tree(action_list_t * act_list) // Revert back action types and free for (sllnode * it = act_list->begin(); it != NULL;) { ModelAction * act = it->getVal(); - // Do iteration early in case we delete act + // Do iteration early in case we delete read actions it = it->getNext(); - // Revert back action types for actions whose types have been changed. + // Collect write actions and reads_froms + if (act->is_read()) { + if (act->is_rmw()) { + write_actions.add(act); + } + + ModelAction * rf = act->get_reads_from(); + write_actions.add(rf); + } else if (act->is_write()) { + write_actions.add(act); + } + + // Revert back action types if (act->is_read()) { ModelAction * rf = act->get_reads_from(); if (rf->get_swap_flag() == true) @@ -257,11 +272,10 @@ void FuncNode::update_tree(action_list_t * act_list) if (act->get_swap_flag() == true) act->use_original_type(); - if (act->is_free()) { - // TODO - } else if (act->is_read()) { + // Free read actions + if (act->is_read()) { if (act->is_rmw()) { - // reads_from can not be READY_FREE + // Do nothing. Its reads_from can not be READY_FREE } else { ModelAction *rf = act->get_reads_from(); if (rf->is_free()) { @@ -272,6 +286,16 @@ void FuncNode::update_tree(action_list_t * act_list) } } + // Free write actions if possible + HSIterator * it = write_actions.iterator(); + while (it->hasNext()) { + ModelAction * act = it->next(); + + if (act->is_free() && act->get_read_ref_count() == 0) + delete act; + } + delete it; + // print_predicate_tree(); } diff --git a/history.cc b/history.cc index d5179332..3fe570b2 100644 --- a/history.cc +++ b/history.cc @@ -181,15 +181,13 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) return; /* Add to curr_inst_list */ - act->setFuncActRef(curr_act_list->add_back(act)); + curr_act_list->push_back(act); + + // Increment ref count for every action and reads_froms + act->incr_read_ref_count(); if (act->is_read()) { ModelAction * rf = act->get_reads_from(); - void * func_act_ref = rf->getFuncActRef(); - if (func_act_ref == WRITE_REFERENCED) { - // do nothing - } else if (func_act_ref == NULL) { - rf->setFuncActRef(WRITE_REFERENCED); - } + rf->incr_read_ref_count(); } FuncNode * func_node = func_nodes[func_id];