add a data structure to store the values read by last read actions of each thread...
authorweiyu <weiyuluo1232@gmail.com>
Fri, 19 Jul 2019 00:14:44 +0000 (17:14 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Fri, 19 Jul 2019 00:14:44 +0000 (17:14 -0700)
funcnode.cc
funcnode.h
history.cc

index ce91815f7c8ac2ff860f22287a5e8b649465ce31..d45c8a8fe1136027a97027fcb029fe3f420c66ff 100644 (file)
@@ -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<uint64_t> * read_vals = loc_thrd_read_map.get(location);
+       if (read_vals == NULL) {
+               read_vals = new ModelVector<uint64_t>();
+               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<void *>::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<void *>::iterator it;
+       for (it = read_locations.begin(); it != read_locations.end(); it++) {
+               ModelVector<uint64_t> * 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);
+       }
 }
index 51f19f0cce65812a9771c60e796093357e024911..2a7061d6b810a4708fd4779f526f1bb37da64487 100644 (file)
@@ -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<void *, func_inst_list_mt *, uintptr_t, 4, model_malloc, model_calloc, model_free> reads_by_loc;
+       /* Store the values read by atomic read actions per thread for each memory location */
+       HashTable<void *, ModelVector<uint64_t> *, uintptr_t, 4, model_malloc, model_calloc, model_free> loc_thrd_read_map;
+       ModelList<void *> read_locations;
 };
index fc71b9f2136d5815e2a2fdedfeec721ba31143bf..d3e36c6a37b7aaac6dd1ed02c98278b1b70020d6 100644 (file)
@@ -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 */