From: weiyu Date: Mon, 8 Jul 2019 23:32:55 +0000 (-0700) Subject: add a new data structure in execution.h, which is used by history.cc to link FuncInsts X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=abb082e1c2672bb79b6c590adfb12c6de5b2f215;p=c11tester.git add a new data structure in execution.h, which is used by history.cc to link FuncInsts --- diff --git a/execution.cc b/execution.cc index e7ef8135..17767419 100644 --- a/execution.cc +++ b/execution.cc @@ -66,7 +66,9 @@ ModelExecution::ModelExecution(ModelChecker *m, Scheduler *scheduler, NodeStack node_stack(node_stack), priv(new struct model_snapshot_members ()), mo_graph(new CycleGraph()), - fuzzer(new Fuzzer()) + fuzzer(new Fuzzer()), + thrd_func_list(), + thrd_func_inst_lists() { /* Initialize a model-checker thread, for special ModelActions */ model_thread = new Thread(get_next_id()); diff --git a/execution.h b/execution.h index 0a36d31c..f79b2f9e 100644 --- a/execution.h +++ b/execution.h @@ -108,6 +108,7 @@ public: ModelAction * check_current_action(ModelAction *curr); SnapVector * get_thrd_func_list() { return &thrd_func_list; } + SnapVector< SnapList *> * get_thrd_func_inst_lists() { return &thrd_func_inst_lists; } SNAPSHOTALLOC private: @@ -210,9 +211,19 @@ private: /* thrd_func_list stores a list of function ids for each thread. * Each element in thrd_func_list stores the functions that - * thread i has entered and yet to exit from */ + * thread i has entered and yet to exit from + * + * This data structure is handled by ModelHistory + */ SnapVector< func_id_list_t * > thrd_func_list; + /* Keeps track of atomic actions that thread i has performed in some + * function. Index of SnapVector is thread id. SnapList simulates + * the call stack. + * + * This data structure is handled by ModelHistory + */ + SnapVector< SnapList< func_inst_list_t *> *> thrd_func_inst_lists; }; #endif /* __EXECUTION_H__ */ diff --git a/history.cc b/history.cc index c896511e..7452c5c1 100644 --- a/history.cc +++ b/history.cc @@ -2,10 +2,12 @@ #include "history.h" #include "action.h" #include "funcnode.h" +#include "common.h" #include "model.h" #include "execution.h" + /** @brief Constructor */ ModelHistory::ModelHistory() : func_counter(0), /* function id starts with 0 */ @@ -19,29 +21,50 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) //model_print("thread %d entering func %d\n", tid, func_id); uint32_t id = id_to_int(tid); SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector< SnapList *> * + thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); - if ( thrd_func_list->size() <= id ) + if ( thrd_func_list->size() <= id ) { thrd_func_list->resize( id + 1 ); + thrd_func_inst_lists->resize( id + 1 ); + } func_id_list_t * func_list = thrd_func_list->at(id); + SnapList * func_inst_lists = thrd_func_inst_lists->at(id); if (func_list == NULL) { func_list = new func_id_list_t(); thrd_func_list->at(id) = func_list; } + if (func_inst_lists == NULL) { + func_inst_lists = new SnapList< func_inst_list_t *>(); + thrd_func_inst_lists->at(id) = func_inst_lists; + } + func_list->push_back(func_id); + func_inst_lists->push_back( new func_inst_list_t() ); } void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) { + uint32_t id = id_to_int(tid); SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector< SnapList *> * + thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); + + func_id_list_t * func_list = thrd_func_list->at(id); + SnapList * func_inst_lists = thrd_func_inst_lists->at(id); - func_id_list_t * func_list = thrd_func_list->at( id_to_int(tid) ); uint32_t last_func_id = func_list->back(); if (last_func_id == func_id) { func_list->pop_back(); + + func_inst_list_t * curr_inst_list = func_inst_lists->back(); + link_insts(curr_inst_list); + + func_inst_lists->pop_back(); } else { model_print("trying to exit with a wrong function id\n"); model_print("--- last_func: %d, func_id: %d\n", last_func_id, func_id); @@ -54,6 +77,8 @@ void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) /* return if thread i has not entered any function or has exited from all functions */ SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector< SnapList *> * + thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); uint32_t id = id_to_int(tid); if ( thrd_func_list->size() <= id ) @@ -63,6 +88,8 @@ void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) /* get the function id that thread i is currently in */ func_id_list_t * func_list = thrd_func_list->at(id); + SnapList * func_inst_lists = thrd_func_inst_lists->at(id); + uint32_t func_id = func_list->back(); if ( func_atomics.size() <= func_id ) @@ -78,20 +105,50 @@ void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) func_atomics[func_id] = func_node; } - func_node->add_action(act); + FuncInst * inst = func_node->get_or_add_action(act); + if (inst != NULL) { + func_inst_list_t * curr_inst_list = func_inst_lists->back(); + + ASSERT(curr_inst_list != NULL); + curr_inst_list->push_back(inst); + } +} + +/* Link FuncInsts in a list - add one FuncInst to another's predecessors and successors */ +void ModelHistory::link_insts(func_inst_list_t * inst_list) +{ + if (inst_list == NULL) + return; + + func_inst_list_t::iterator it = inst_list->begin(); + func_inst_list_t::iterator prev = inst_list->end(); + it++; + + while (it != inst_list->end()) { + prev = it; + prev--; + + FuncInst * prev_inst = *prev; + FuncInst * curr_inst = *it; + + prev_inst->add_succ(curr_inst); + curr_inst->add_pred(prev_inst); + + it++; + } } void ModelHistory::print() { for (uint32_t i = 0; i < func_atomics.size(); i++ ) { FuncNode * funcNode = func_atomics[i]; - func_inst_list_t * inst_list = funcNode->get_inst_list(); + func_inst_list_mt * inst_list = funcNode->get_inst_list(); if (funcNode == NULL) continue; model_print("function %s has following actions\n", funcNode->get_func_name()); - func_inst_list_t::iterator it; + func_inst_list_mt::iterator it; for (it = inst_list->begin(); it != inst_list->end(); it++) { FuncInst *inst = *it; model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position()); diff --git a/history.h b/history.h index 0b523b23..b6707f9f 100644 --- a/history.h +++ b/history.h @@ -21,6 +21,7 @@ public: ModelVector * getFuncAtomics() { return &func_atomics; } + void link_insts(func_inst_list_t * inst_list); void print(); MEMALLOC