ModelAction * check_current_action(ModelAction *curr);
SnapVector<func_id_list_t *> * get_thrd_func_list() { return &thrd_func_list; }
+ SnapVector< SnapList<func_inst_list_t *> *> * get_thrd_func_inst_lists() { return &thrd_func_inst_lists; }
SNAPSHOTALLOC
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__ */
#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 */
//model_print("thread %d entering func %d\n", tid, func_id);
uint32_t id = id_to_int(tid);
SnapVector<func_id_list_t *> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+ SnapVector< SnapList<func_inst_list_t *> *> *
+ 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_list_t *> * 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<func_id_list_t *> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+ SnapVector< SnapList<func_inst_list_t *> *> *
+ 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_list_t *> * 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);
/* return if thread i has not entered any function or has exited
from all functions */
SnapVector<func_id_list_t *> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+ SnapVector< SnapList<func_inst_list_t *> *> *
+ 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 )
/* get the function id that thread i is currently in */
func_id_list_t * func_list = thrd_func_list->at(id);
+ SnapList<func_inst_list_t *> * func_inst_lists = thrd_func_inst_lists->at(id);
+
uint32_t func_id = func_list->back();
if ( func_atomics.size() <= func_id )
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());