From fe17b6c9357f53f65ea08db43634cb5432f89ef0 Mon Sep 17 00:00:00 2001 From: weiyu Date: Mon, 29 Jul 2019 17:43:58 -0700 Subject: [PATCH] move write_history to funcnode.cc and do experiment --- funcnode.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- funcnode.h | 8 +++++++- history.cc | 25 ++++++++++--------------- history.h | 4 ++-- 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/funcnode.cc b/funcnode.cc index 4c49f2c3..2da1f66d 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -6,7 +6,8 @@ FuncNode::FuncNode() : inst_list(), entry_insts(), thrd_read_map(), - read_locations() + write_history(), + write_locations() {} /* Check whether FuncInst with the same type, position, and location @@ -125,7 +126,7 @@ void FuncNode::store_read(ModelAction * act, uint32_t tid) read_map->put(location, read_from_val); /* Store the memory locations where atomic reads happen */ - read_locations.add(location); + // read_locations.add(location); } uint64_t FuncNode::query_last_read(void * location, uint32_t tid) @@ -155,6 +156,19 @@ void FuncNode::clear_read_map(uint32_t tid) thrd_read_map[tid]->reset(); } +void FuncNode::add_to_write_history(void * location, uint64_t write_val) +{ + write_set_t * write_set = write_history.get(location); + + if (write_set == NULL) { + write_set = new write_set_t(); + write_history.put(location, write_set); + } + + write_set->add(write_val); + write_locations.add(location); +} + void FuncNode::generate_predicate(FuncInst *func_inst) { @@ -165,10 +179,9 @@ void FuncNode::generate_predicate(FuncInst *func_inst) */ void FuncNode::print_last_read(uint32_t tid) { -/* ASSERT(thrd_read_map.size() > tid); read_map_t * read_map = thrd_read_map[tid]; - +/* ModelList::iterator it; for (it = read_locations.begin();it != read_locations.end();it++) { if ( !read_map->contains(*it) ) @@ -179,3 +192,32 @@ void FuncNode::print_last_read(uint32_t tid) } */ } + +void FuncNode::print_write() +{ + HSIterator * iter; + HSIterator * write_iter; + iter = write_locations.iterator(); + + if (write_locations.getSize() > 10) { + while (iter->hasNext()) { + void * location = iter->next(); + write_set_t * write_set = write_history.get(location); + +// model_print("location: %p contains %d writes\n", location, write_set->getSize()); + if (write_set->getSize() > 5) { + model_print("location %p has writes: ", location); + write_iter = write_set->iterator(); + + while (write_iter->hasNext()) { + uint64_t val = write_iter->next(); + model_print("%lx ", val); + } + model_print("\n"); + } + } + } else { + model_print("\n"); + } + delete iter; +} diff --git a/funcnode.h b/funcnode.h index d2d3c427..b8562d3e 100644 --- a/funcnode.h +++ b/funcnode.h @@ -8,6 +8,7 @@ typedef ModelList func_inst_list_mt; typedef HashTable read_map_t; +typedef HashSet write_set_t; class FuncNode { public: @@ -31,10 +32,13 @@ public: uint64_t query_last_read(void * location, uint32_t tid); void clear_read_map(uint32_t tid); + void add_to_write_history(void * location, uint64_t write_val); + /* TODO: generate EQUALITY or NULLITY predicate based on write_history in history.cc */ void generate_predicate(FuncInst * func_inst); void print_last_read(uint32_t tid); + void print_write(); MEMALLOC private: @@ -54,7 +58,9 @@ private: /* Store the values read by atomic read actions per memory location for each thread */ ModelVector thrd_read_map; - HashSet read_locations; + + HashTable write_history; + HashSet write_locations; }; #endif /* __FUNCNODE_H__ */ diff --git a/history.cc b/history.cc index a60dfa6b..3d6599b4 100644 --- a/history.cc +++ b/history.cc @@ -13,8 +13,7 @@ ModelHistory::ModelHistory() : func_counter(1), /* function id starts with 1 */ func_map(), func_map_rev(), - func_nodes(), - write_history() + func_nodes() {} void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) @@ -120,7 +119,7 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) func_node->store_read(act, tid); if (inst->is_write()) - add_to_write_history(act->get_location(), act->get_write_value()); + func_node->add_to_write_history(act->get_location(), act->get_write_value()); /* add to curr_inst_list */ func_inst_list_t * curr_inst_list = func_inst_lists->back(); @@ -154,22 +153,19 @@ uint64_t ModelHistory::query_last_read(void * location, thread_id_t tid) return last_read_val; } -void ModelHistory::add_to_write_history(void * location, uint64_t write_val) +void ModelHistory::print_write() { - write_set_t * write_set = write_history.get(location); - - if (write_set == NULL) { - write_set = new write_set_t(); - write_history.put(location, write_set); + for (uint32_t i = 1; i < func_nodes.size(); i++) { + FuncNode * func_node = func_nodes[i]; + model_print("function id: %d, name: %s --- ", i, func_node->get_func_name()); + func_node->print_write(); } - - write_set->add(write_val); } -void ModelHistory::print() +void ModelHistory::print_func_node() { /* function id starts with 1 */ - for (uint32_t i = 1;i < func_nodes.size();i++) { + for (uint32_t i = 1; i < func_nodes.size(); i++) { FuncNode * func_node = func_nodes[i]; func_inst_list_mt * entry_insts = func_node->get_entry_insts(); @@ -180,7 +176,6 @@ void ModelHistory::print() FuncInst *inst = *it; model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position()); } - /* func_inst_list_mt * inst_list = funcNode->get_inst_list(); @@ -190,6 +185,6 @@ void ModelHistory::print() 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 4457750e..0179d10b 100644 --- a/history.h +++ b/history.h @@ -32,7 +32,8 @@ public: void add_to_write_history(void * location, uint64_t write_val); - void print(); + void print_write(); + void print_func_node(); MEMALLOC private: @@ -44,7 +45,6 @@ private: ModelVector func_map_rev; ModelVector func_nodes; - HashTable write_history; }; #endif /* __HISTORY_H__ */ -- 2.34.1