return act;
}
-
/**
* Processes a read model action.
* @param curr is the read model action to process.
ASSERT(curr);
/* Process this action in ModelHistory for records*/
- model->get_history()->process_action( curr, curr_thrd->get_id() );
+ model->get_history()->process_action( curr, curr->get_tid() );
if (curr_thrd->is_blocked() || curr_thrd->is_complete())
scheduler->remove_thread(curr_thrd);
HashTable<pthread_mutex_t *, cdsc::snapmutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
ModelAction * check_current_action(ModelAction *curr);
- SnapVector<func_id_list_t *> * get_thrd_func_list() { return &thrd_func_list; }
+ 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
*
* This data structure is handled by ModelHistory
*/
- SnapVector< func_id_list_t * > thrd_func_list;
+ 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
bool FuncInst::is_read() const
{
- return type == ATOMIC_READ || type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS;
+ return type == ATOMIC_READ || type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS; /* type == ATOMIC_RMW ? */
}
+
+bool FuncInst::is_write() const
+{
+ return type == ATOMIC_WRITE || type == ATOMIC_RMW || type == ATOMIC_INIT || type == ATOMIC_UNINIT || type == NONATOMIC_WRITE;
+}
+
+#ifndef __FUNCINST_H__
+#define __FUNCINST_H__
+
#include "action.h"
#include "hashtable.h"
func_inst_list_mt * get_succs() { return &successors; }
bool is_read() const;
+ bool is_write() const;
MEMALLOC
private:
func_inst_list_mt predecessors;
func_inst_list_mt successors;
};
+
+#endif /* __FUNCINST_H__ */
+
#include "funcnode.h"
+#include "predicate.h"
FuncNode::FuncNode() :
func_inst_map(),
void * location = act->get_location();
uint64_t read_from_val = act->get_reads_from_value();
- if (thrd_read_map.size() <= tid)
+ /* resize and initialize */
+ uint32_t old_size = thrd_read_map.size();
+ if (old_size <= tid) {
thrd_read_map.resize(tid + 1);
-
- read_map_t * read_map = thrd_read_map[tid];
- if (read_map == NULL) {
- read_map = new read_map_t();
- thrd_read_map[tid] = read_map;
+ for (uint32_t i = old_size; i < tid + 1; i++)
+ thrd_read_map[i] = new read_map_t();
}
+ read_map_t * read_map = thrd_read_map[tid];
read_map->put(location, read_from_val);
/* Store the memory locations where atomic reads happen */
read_locations.push_back(location);
}
-uint64_t FuncNode::query_last_read(ModelAction * act, uint32_t tid)
+uint64_t FuncNode::query_last_read(void * location, uint32_t tid)
{
if (thrd_read_map.size() <= tid)
return 0xdeadbeef;
read_map_t * read_map = thrd_read_map[tid];
- void * location = act->get_location();
/* last read value not found */
if ( !read_map->contains(location) )
thrd_read_map[tid]->reset();
}
+void FuncNode::generate_predicate(FuncInst *func_inst)
+{
+
+}
+
/* @param tid thread id
* Print the values read by the last read actions for each memory location
*/
+#ifndef __FUNCNODE_H__
+#define __FUNCNODE_H__
+
#include "action.h"
#include "funcinst.h"
#include "hashtable.h"
-class ModelAction;
-
typedef ModelList<FuncInst *> func_inst_list_mt;
typedef HashTable<void *, uint64_t, uintptr_t, 4, model_malloc, model_calloc, model_free> read_map_t;
void link_insts(func_inst_list_t * inst_list);
void store_read(ModelAction * act, uint32_t tid);
- uint64_t query_last_read(ModelAction * act, uint32_t tid);
+ uint64_t query_last_read(void * location, uint32_t tid);
void clear_read_map(uint32_t tid);
+ /* 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);
MEMALLOC
ModelVector<read_map_t *> thrd_read_map;
ModelList<void *> read_locations;
};
+
+#endif /* __FUNCNODE_H__ */
func_counter(1), /* function id starts with 1 */
func_map(),
func_map_rev(),
- func_nodes()
+ func_nodes(),
+ write_history()
{}
void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
{
//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<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();
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);
+ (*thrd_func_list)[id].push_back(func_id);
func_inst_lists->push_back( new func_inst_list_t() );
if ( func_nodes.size() <= func_id )
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<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);
-
- uint32_t last_func_id = func_list->back();
+ uint32_t last_func_id = (*thrd_func_list)[id].back();
if (last_func_id == func_id) {
FuncNode * func_node = func_nodes[func_id];
func_inst_list_t * curr_inst_list = func_inst_lists->back();
func_node->link_insts(curr_inst_list);
- func_list->pop_back();
+ (*thrd_func_list)[id].pop_back();
func_inst_lists->pop_back();
} else {
model_print("trying to exit with a wrong function id\n");
{
/* 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<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 )
return;
- else if (thrd_func_list->at(id) == NULL)
- return;
/* get the function id that thread i is currently in */
- func_id_list_t * func_list = thrd_func_list->at(id);
+ uint32_t func_id = (*thrd_func_list)[id].back();
SnapList<func_inst_list_t *> * func_inst_lists = thrd_func_inst_lists->at(id);
- uint32_t func_id = func_list->back();
-
if ( func_nodes.size() <= func_id )
resize_func_nodes( func_id + 1 );
// if (inst->is_read())
// func_node->store_read(act, tid);
+ if (inst->is_write())
+ 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();
ASSERT(curr_inst_list != NULL);
return func_nodes[func_id];
}
+uint64_t ModelHistory::query_last_read(void * location, thread_id_t tid)
+{
+ SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
+ uint32_t id = id_to_int(tid);
+
+ ASSERT( thrd_func_list->size() > id );
+ uint32_t func_id = (*thrd_func_list)[id].back();
+ FuncNode * func_node = func_nodes[func_id];
+
+ uint64_t last_read_val = 0xdeadbeef;
+ if (func_node != NULL) {
+ last_read_val = func_node->query_last_read(location, tid);
+ }
+
+ return last_read_val;
+}
+
+void ModelHistory::add_to_write_history(void * location, uint64_t write_val)
+{
+ if ( !write_history.contains(location) )
+ write_history.put(location, new write_set_t() );
+
+ write_set_t * write_set = write_history.get(location);
+ write_set->add(write_val);
+}
+
void ModelHistory::print()
{
/* function id starts with 1 */
+#ifndef __HISTORY_H__
+#define __HISTORY_H__
+
#include "stl-model.h"
#include "common.h"
#include "hashtable.h"
+#include "hashset.h"
#include "threads-model.h"
+typedef HashSet<uint64_t, uint64_t, 4, model_malloc, model_calloc, model_free> write_set_t;
+
class ModelHistory {
public:
ModelHistory();
ModelVector<FuncNode *> * getFuncNodes() { return &func_nodes; }
FuncNode * get_func_node(uint32_t func_id);
+ uint64_t query_last_read(void * location, thread_id_t tid);
+
+ void add_to_write_history(void * location, uint64_t write_val);
void print();
ModelVector<const char *> func_map_rev;
ModelVector<FuncNode *> func_nodes;
+ HashTable<void *, write_set_t *, uintptr_t, 4, model_malloc, model_calloc, model_free> write_history;
};
+
+#endif /* __HISTORY_H__ */
--- /dev/null
+#include "predicate.h"
+
+inline bool operator==(const predicate_expr& expr_A, const predicate_expr& expr_B)
+{
+ if (expr_A.token != expr_B.token)
+ return false;
+
+ if (expr_A.token == EQUALITY && expr_A.location != expr_B.location)
+ return false;
+
+ if (expr_A.value != expr_B.value)
+ return false;
+
+ return true;
+}
+
+void Predicate::add_predicate(predicate_expr predicate)
+{
+ ModelList<predicate_expr>::iterator it;
+ for (it = predicates.begin(); it != predicates.end(); it++) {
+ if (predicate == *it)
+ return;
+ }
+
+ predicates.push_back(predicate);
+}
--- /dev/null
+#include "funcinst.h"
+
+typedef enum predicate_token {
+ EQUALITY, NULLITY
+} token_t;
+
+/* If token is EQUALITY, then the predicate asserts whether
+ * this load should read the same value as the last value
+ * read at memory location specified in predicate_expr.
+ */
+struct predicate_expr {
+ token_t token;
+ void * location;
+ bool value;
+};
+
+class Predicate {
+public:
+ Predicate();
+ ~Predicate();
+
+ FuncInst * get_func_inst() { return func_inst; }
+ ModelList<predicate_expr> * get_predicates() { return &predicates; }
+ void add_predicate(predicate_expr predicate);
+
+ MEMALLOC
+private:
+ FuncInst * func_inst;
+ /* may have multiple precicates */
+ ModelList<predicate_expr> predicates;
+};