*.swo
*.so
*~
+*.dot
# files in this directory
/tags
return type == ATOMIC_RMWC;
}
+bool ModelAction::is_fence() const
+{
+ return type == ATOMIC_FENCE;
+}
+
bool ModelAction::is_initialization() const
{
return type == ATOMIC_INIT;
case ATOMIC_RMW:
type_str = "atomic rmw";
break;
+ case ATOMIC_FENCE:
+ type_str = "fence";
+ break;
case ATOMIC_RMWR:
type_str = "atomic rmwr";
break;
ATOMIC_RMWR, /**< The read part of an atomic RMW action */
ATOMIC_RMW, /**< The write part of an atomic RMW action */
ATOMIC_RMWC, /**< Convert an atomic RMW action into a READ */
- ATOMIC_INIT /**< Initialization of an atomic object (e.g.,
+ ATOMIC_INIT, /**< Initialization of an atomic object (e.g.,
* atomic_init()) */
+ ATOMIC_FENCE
} action_type_t;
/* Forward declaration */
bool is_rmwr() const;
bool is_rmwc() const;
bool is_rmw() const;
+ bool is_fence() const;
bool is_initialization() const;
bool is_acquire() const;
bool is_release() const;
void model_rmwc_action(void *obj, memory_order ord) {
model->switch_to_master(new ModelAction(ATOMIC_RMWC, ord, obj));
}
+
+/** Issues a fence operation. */
+void model_fence_action(memory_order ord) {
+ model->switch_to_master(new ModelAction(ATOMIC_FENCE, ord, NULL));
+}
uint64_t model_rmwr_action(void *obj, memory_order ord);
void model_rmw_action(void *obj, memory_order ord, uint64_t val);
void model_rmwc_action(void *obj, memory_order ord);
+void model_fence_action(memory_order ord);
#if __cplusplus
#endif
*/
+/** Turn on support for dumping cyclegraphs as dot files at each
+ * printed summary.*/
+#define SUPPORT_MOD_ORDER_DUMP 0
/** Do we have a 48 bit virtual address (64 bit machine) or 32 bit addresses.
* Set to 1 for 48-bit, 0 for 32-bit. */
if (node==NULL) {
node=new CycleNode(action);
actionToNode.put(action, node);
+#if SUPPORT_MOD_ORDER_DUMP
+ nodeList.push_back(node);
+#endif
}
return node;
}
hasCycles=checkReachable(tonode, fromnode);
}
- rollbackvector.push_back(fromnode);
- fromnode->addEdge(tonode);
+ if (fromnode->addEdge(tonode))
+ rollbackvector.push_back(fromnode);
+
CycleNode * rmwnode=fromnode->getRMW();
// Check for Cycles
hasCycles=checkReachable(tonode, rmwnode);
}
- rollbackvector.push_back(rmwnode);
- rmwnode->addEdge(tonode);
+
+ if (rmwnode->addEdge(tonode))
+ rollbackvector.push_back(rmwnode);
}
}
for(unsigned int i=0;i<edges->size();i++) {
CycleNode * tonode=(*edges)[i];
if (tonode!=rmwnode) {
- rollbackvector.push_back(rmwnode);
- rmwnode->addEdge(tonode);
+ if (rmwnode->addEdge(tonode))
+ rollbackvector.push_back(rmwnode);
}
}
- rollbackvector.push_back(fromnode);
+
if (!hasCycles) {
// With promises we could be setting up a cycle here if we aren't
// careful...avoid it..
hasCycles=checkReachable(rmwnode, fromnode);
}
- fromnode->addEdge(rmwnode);
+ if(fromnode->addEdge(rmwnode))
+ rollbackvector.push_back(fromnode);
+}
+
+#if SUPPORT_MOD_ORDER_DUMP
+void CycleGraph::dumpGraphToFile(const char *filename) {
+ char buffer[200];
+ sprintf(buffer, "%s.dot",filename);
+ FILE *file=fopen(buffer, "w");
+ fprintf(file, "digraph %s {\n",filename);
+ for(unsigned int i=0;i<nodeList.size();i++) {
+ CycleNode *cn=nodeList[i];
+ std::vector<CycleNode *> * edges=cn->getEdges();
+ const ModelAction *action=cn->getAction();
+ fprintf(file, "N%u [label=\"%u, T%u\"];\n",action->get_seq_number(),action->get_seq_number(), action->get_tid());
+ if (cn->getRMW()!=NULL) {
+ fprintf(file, "N%u -> N%u[style=dotted];\n", action->get_seq_number(), cn->getRMW()->getAction()->get_seq_number());
+ }
+ for(unsigned int j=0;j<edges->size();j++) {
+ CycleNode *dst=(*edges)[j];
+ const ModelAction *dstaction=dst->getAction();
+ fprintf(file, "N%u -> N%u;\n", action->get_seq_number(), dstaction->get_seq_number());
+ }
+ }
+ fprintf(file,"}\n");
+ fclose(file);
}
+#endif
/**
* Checks whether one ModelAction can reach another.
* @return True, @a from can reach @a to; otherwise, false
*/
bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) {
- std::vector<CycleNode *> queue;
- HashTable<CycleNode *, CycleNode *, uintptr_t, 4> discovered;
+ std::vector<CycleNode *, MyAlloc<CycleNode *> > queue;
+ HashTable<CycleNode *, CycleNode *, uintptr_t, 4, MYMALLOC, MYCALLOC, MYFREE> discovered;
queue.push_back(from);
discovered.put(from, from);
* Adds an edge from this CycleNode to another CycleNode.
* @param node The node to which we add a directed edge
*/
-void CycleNode::addEdge(CycleNode *node) {
+bool CycleNode::addEdge(CycleNode *node) {
+ for(unsigned int i=0;i<edges.size();i++)
+ if (edges[i]==node)
+ return false;
edges.push_back(node);
+ return true;
}
/** @returns the RMW CycleNode that reads from the current CycleNode */
#include "hashtable.h"
#include <vector>
#include <inttypes.h>
-
+#include "config.h"
#include "mymemory.h"
class CycleNode;
void startChanges();
void commitChanges();
void rollbackChanges();
+#if SUPPORT_MOD_ORDER_DUMP
+ void dumpGraphToFile(const char * filename);
+#endif
SNAPSHOTALLOC
private:
/** @brief A table for mapping ModelActions to CycleNodes */
HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
+#if SUPPORT_MOD_ORDER_DUMP
+ std::vector<CycleNode *> nodeList;
+#endif
bool checkReachable(CycleNode *from, CycleNode *to);
class CycleNode {
public:
CycleNode(const ModelAction *action);
- void addEdge(CycleNode * node);
+ bool addEdge(CycleNode * node);
std::vector<CycleNode *> * getEdges();
bool setRMW(CycleNode *);
CycleNode* getRMW();
+ const ModelAction * getAction() {return action;};
+
void popEdge() {
edges.pop_back();
};
else { model_rmwc_action((void *)__p__, __x__); *__q__ = __t__; __r__ = false;} \
__r__; })
-//TODO
#define _ATOMIC_FENCE_( __a__, __x__ ) \
-({ ;})
-
+ ({ model_fence_action(__x__);})
+
#define ATOMIC_CHAR_LOCK_FREE 1
#define ATOMIC_CHAR16_T_LOCK_FREE 1
/* Initialize default scheduler */
scheduler(new Scheduler()),
num_executions(0),
+ num_feasible_executions(0),
params(params),
diverge(NULL),
action_trace(new action_list_t()),
DBG();
num_executions++;
+ if (isfinalfeasible())
+ num_feasible_executions++;
if (isfinalfeasible() || DBG_ENABLED())
print_summary();
}
/**
- * Updates the mo_graph with the constraints imposed from the current read.
+ * Updates the mo_graph with the constraints imposed from the current
+ * read.
+ *
+ * Basic idea is the following: Go through each other thread and find
+ * the lastest action that happened before our read. Two cases:
+ *
+ * (1) The action is a write => that write must either occur before
+ * the write we read from or be the write we read from.
+ *
+ * (2) The action is a read => the write that that action read from
+ * must occur before the write we read from or be the same write.
+ *
* @param curr The current action. Must be a read.
* @param rf The action that curr reads from. Must be a write.
* @return True if modification order edges were added; false otherwise
return added;
}
-/** Updates the mo_graph with the constraints imposed from the current read. */
+/** This method fixes up the modification order when we resolve a
+ * promises. The basic problem is that actions that occur after the
+ * read curr could not property add items to the modification order
+ * for our read.
+ *
+ * So for each thread, we find the earliest item that happens after
+ * the read curr. This is the item we have to fix up with additional
+ * constraints. If that action is write, we add a MO edge between
+ * the Action rf and that action. If the action is a read, we add a
+ * MO edge between the Action rf, and whatever the read accessed.
+ *
+ * @param curr is the read ModelAction that we are fixing up MO edges for.
+ * @param rf is the write ModelAction that curr reads from.
+ *
+ */
+
void ModelChecker::post_r_modification_order(ModelAction *curr, const ModelAction *rf)
{
std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
/**
* Updates the mo_graph with the constraints imposed from the current write.
+ *
+ * Basic idea is the following: Go through each other thread and find
+ * the lastest action that happened before our write. Two cases:
+ *
+ * (1) The action is a write => that write must occur before
+ * the current write
+ *
+ * (2) The action is a read => the write that that action read from
+ * must occur before the current write.
+ *
+ * This method also handles two other issues:
+ *
+ * (I) Sequential Consistency: Making sure that if the current write is
+ * seq_cst, that it occurs after the previous seq_cst write.
+ *
+ * (II) Sending the write back to non-synchronizing reads.
+ *
* @param curr The current action. Must be a write.
* @return True if modification order edges were added; false otherwise
*/
if (read->is_rmw()) {
mo_graph->addRMWEdge(write, read);
}
+ //First fix up the modification order for actions that happened
+ //before the read
r_modification_order(read, write);
+ //Next fix up the modification order for actions that happened
+ //after the read.
post_r_modification_order(read, write);
promises->erase(promises->begin() + promise_index);
resolved = true;
{
printf("\n");
printf("Number of executions: %d\n", num_executions);
+ printf("Number of feasible executions: %d\n", num_feasible_executions);
printf("Total nodes created: %d\n", node_stack->get_total_nodes());
+#if SUPPORT_MOD_ORDER_DUMP
scheduler->print();
+ char buffername[100];
+ sprintf(buffername, "exec%u",num_executions);
+ mo_graph->dumpGraphToFile(buffername);
+#endif
if (!isfinalfeasible())
printf("INFEASIBLE EXECUTION!\n");
bool has_asserted() {return asserted;}
void reset_asserted() {asserted=false;}
int num_executions;
+ int num_feasible_executions;
bool promises_expired();
const model_params params;
thrd_t t1, t2;
atomic_init(&x, 0);
-
thrd_create(&t1, (thrd_start_t)&a, NULL);
thrd_create(&t2, (thrd_start_t)&a, NULL);