From: weiyu Date: Fri, 19 Jul 2019 00:14:44 +0000 (-0700) Subject: add a data structure to store the values read by last read actions of each thread... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9270d9d61d990f6b73cc2e6657aa19d36b0ea1e5;p=c11tester.git add a data structure to store the values read by last read actions of each thread for each memory location --- diff --git a/funcnode.cc b/funcnode.cc index ce91815f..d45c8a8f 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -39,8 +39,6 @@ FuncInst * FuncNode::get_or_add_action(ModelAction *act) func_inst = new FuncInst(act, this); inst->get_collisions()->push_back(func_inst); inst_list.push_back(func_inst); // delete? - if (func_inst->is_read()) - group_reads_by_loc(func_inst); return func_inst; } @@ -49,12 +47,10 @@ FuncInst * FuncNode::get_or_add_action(ModelAction *act) } FuncInst * func_inst = new FuncInst(act, this); + func_inst_map.put(position, func_inst); inst_list.push_back(func_inst); - if (func_inst->is_read()) - group_reads_by_loc(func_inst); - return func_inst; } @@ -72,29 +68,51 @@ void FuncNode::add_entry_inst(FuncInst * inst) entry_insts.push_back(inst); } -/* group atomic read actions by memory location */ -void FuncNode::group_reads_by_loc(FuncInst * inst) +/* Store the values read by atomic read actions into loc_thrd_read_map */ +void FuncNode::store_read(ModelAction * act, uint32_t tid) { - ASSERT(inst); - if ( !inst->is_read() ) - return; + ASSERT(act); - void * location = inst->get_location(); + void * location = act->get_location(); + uint64_t read_from_val = act->get_reads_from_value(); - func_inst_list_mt * reads; - if ( !reads_by_loc.contains(location) ) { - reads = new func_inst_list_mt(); - reads->push_back(inst); - reads_by_loc.put(location, reads); - return; + ModelVector * read_vals = loc_thrd_read_map.get(location); + if (read_vals == NULL) { + read_vals = new ModelVector(); + loc_thrd_read_map.put(location, read_vals); } - reads = reads_by_loc.get(location); - func_inst_list_mt::iterator it; - for (it = reads->begin(); it != reads->end(); it++) { - if (inst == *it) - return; + if (read_vals->size() <= tid) { + read_vals->resize(tid + 1); + } + read_vals->at(tid) = read_from_val; + + /* Store keys of loc_thrd_read_map into read_locations */ + bool push_loc = true; + ModelList::iterator it; + for (it = read_locations.begin(); it != read_locations.end(); it++) { + if (location == *it) { + push_loc = false; + break; + } } - reads->push_back(inst); + if (push_loc) + read_locations.push_back(location); +} + +/* @param tid thread id + * Print the values read by the last read actions per memory location + */ +void FuncNode::print_last_read(uint32_t tid) +{ + ModelList::iterator it; + for (it = read_locations.begin(); it != read_locations.end(); it++) { + ModelVector * read_vals = loc_thrd_read_map.get(*it); + if (read_vals->size() <= tid) + break; + + int64_t read_val = read_vals->at(tid); + model_print("last read of thread %d at %p: 0x%x\n", tid, *it, read_val); + } } diff --git a/funcnode.h b/funcnode.h index 51f19f0c..2a7061d6 100644 --- a/funcnode.h +++ b/funcnode.h @@ -23,7 +23,8 @@ public: func_inst_list_mt * get_entry_insts() { return &entry_insts; } void add_entry_inst(FuncInst * inst); - void group_reads_by_loc(FuncInst * inst); + void store_read(ModelAction * act, uint32_t tid); + void print_last_read(uint32_t tid); MEMALLOC private: @@ -44,6 +45,7 @@ private: /* possible entry atomic actions in this function */ func_inst_list_mt entry_insts; - /* group atomic read actions by memory location */ - HashTable reads_by_loc; + /* Store the values read by atomic read actions per thread for each memory location */ + HashTable *, uintptr_t, 4, model_malloc, model_calloc, model_free> loc_thrd_read_map; + ModelList read_locations; }; diff --git a/history.cc b/history.cc index fc71b9f2..d3e36c6a 100644 --- a/history.cc +++ b/history.cc @@ -108,12 +108,16 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) /* add corresponding FuncInst to func_node and curr_inst_list*/ 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); - } + if (inst == NULL) + return; + + if (inst->is_read()) + func_node->store_read(act, tid); + + 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 */