11 /** @brief Constructor */
12 ModelHistory::ModelHistory() :
13 func_counter(1), /* function id starts with 1 */
21 void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
23 //model_print("thread %d entering func %d\n", tid, func_id);
24 uint id = id_to_int(tid);
25 SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
26 SnapVector< SnapList<action_list_t *> *> *
27 thrd_func_act_lists = model->get_execution()->get_thrd_func_act_lists();
29 if ( thrd_func_list->size() <= id ) {
30 uint oldsize = thrd_func_list->size();
31 thrd_func_list->resize( id + 1 );
32 for (uint i = oldsize; i < id + 1; i++) {
33 new (&(*thrd_func_list)[i]) func_id_list_t();
34 // push 0 as a dummy function id to a void seg fault
35 (*thrd_func_list)[i].push_back(0);
38 thrd_func_act_lists->resize( id + 1 );
39 for (uint i = oldsize; i < id + 1; i++) {
40 (*thrd_func_act_lists)[i] = new SnapList<action_list_t *>();
44 SnapList<action_list_t *> * func_act_lists = (*thrd_func_act_lists)[id];
46 (*thrd_func_list)[id].push_back(func_id);
47 func_act_lists->push_back( new action_list_t() );
49 if ( func_nodes.size() <= func_id )
50 resize_func_nodes( func_id + 1 );
53 /* @param func_id a non-zero value */
54 void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid)
56 uint32_t id = id_to_int(tid);
57 SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
58 SnapVector< SnapList<action_list_t *> *> *
59 thrd_func_act_lists = model->get_execution()->get_thrd_func_act_lists();
61 SnapList<action_list_t *> * func_act_lists = (*thrd_func_act_lists)[id];
62 uint32_t last_func_id = (*thrd_func_list)[id].back();
64 if (last_func_id == func_id) {
65 FuncNode * func_node = func_nodes[func_id];
66 func_node->clear_read_map(tid);
68 // model_print("hello function %s and thread %d\n", func_node->get_func_name(), tid);
69 action_list_t * curr_act_list = func_act_lists->back();
70 func_node->update_tree(curr_act_list);
72 (*thrd_func_list)[id].pop_back();
73 func_act_lists->pop_back();
75 model_print("trying to exit with a wrong function id\n");
76 model_print("--- last_func: %d, func_id: %d\n", last_func_id, func_id);
78 //model_print("thread %d exiting func %d\n", tid, func_id);
81 void ModelHistory::resize_func_nodes(uint32_t new_size)
83 uint32_t old_size = func_nodes.size();
85 if ( old_size < new_size )
86 func_nodes.resize(new_size);
88 for (uint32_t id = old_size;id < new_size;id++) {
89 const char * func_name = func_map_rev[id];
90 FuncNode * func_node = new FuncNode();
91 func_node->set_func_id(id);
92 func_node->set_func_name(func_name);
93 func_nodes[id] = func_node;
97 void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
99 /* return if thread i has not entered any function or has exited
100 from all functions */
101 SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
103 uint32_t id = id_to_int(tid);
104 if ( thrd_func_list->size() <= id )
107 /* get the function id that thread i is currently in */
108 uint32_t func_id = (*thrd_func_list)[id].back();
112 else if ( func_nodes.size() <= func_id )
113 resize_func_nodes( func_id + 1 );
115 FuncNode * func_node = func_nodes[func_id];
117 /* do not care about actions without a position */
118 if (act->get_position() == NULL)
122 func_node->store_read(act, tid);
125 add_to_write_history(act->get_location(), act->get_write_value());
128 /* return the FuncNode given its func_id */
129 FuncNode * ModelHistory::get_func_node(uint32_t func_id)
131 if (func_nodes.size() <= func_id) // this node has not been added to func_nodes
134 return func_nodes[func_id];
137 uint64_t ModelHistory::query_last_read(void * location, thread_id_t tid)
139 SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
140 uint32_t id = id_to_int(tid);
142 ASSERT( thrd_func_list->size() > id );
143 uint32_t func_id = (*thrd_func_list)[id].back();
144 FuncNode * func_node = func_nodes[func_id];
146 uint64_t last_read_val = 0xdeadbeef;
147 if (func_node != NULL) {
148 last_read_val = func_node->query_last_read(location, tid);
151 return last_read_val;
154 void ModelHistory::add_to_write_history(void * location, uint64_t write_val)
156 write_set_t * write_set = write_history.get(location);
158 if (write_set == NULL) {
159 write_set = new write_set_t();
160 write_history.put(location, write_set);
163 write_set->add(write_val);
164 write_locations.add(location);
167 void ModelHistory::print_write()
171 void ModelHistory::print_func_node()
173 /* function id starts with 1 */
174 for (uint32_t i = 1; i < func_nodes.size(); i++) {
175 FuncNode * func_node = func_nodes[i];
177 func_inst_list_mt * entry_insts = func_node->get_entry_insts();
178 model_print("function %s has entry actions\n", func_node->get_func_name());
180 mllnode<FuncInst*>* it;
181 for (it = entry_insts->begin();it != NULL;it=it->getNext()) {
182 FuncInst *inst = it->getVal();
183 model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position());
186 func_inst_list_mt * inst_list = funcNode->get_inst_list();
188 model_print("function %s has following actions\n", funcNode->get_func_name());
189 func_inst_list_mt::iterator it;
190 for (it = inst_list->begin(); it != inst_list->end(); it++) {
191 FuncInst *inst = *it;
192 model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position());