X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=cyclegraph.cc;h=ead70ae6b38c2c687ab34c30db9659d57b68e110;hp=26235d651e10ecb5e2178d281048ea6ce5007893;hb=5f861ebe39567a3bf01635bb7343ed8a8e26803f;hpb=76205f5d9b62f73ea01f7e55765a043a8333a455 diff --git a/cyclegraph.cc b/cyclegraph.cc index 26235d65..ead70ae6 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -1,9 +1,12 @@ #include "cyclegraph.h" #include "action.h" #include "common.h" +#include "promise.h" +#include "model.h" /** Initializes a CycleGraph object. */ CycleGraph::CycleGraph() : + discovered(new HashTable(16)), hasCycles(false), oldCycles(false), hasRMWViolation(false), @@ -25,6 +28,9 @@ CycleNode * CycleGraph::getNode(const ModelAction *action) { if (node==NULL) { node=new CycleNode(action); actionToNode.put(action, node); +#if SUPPORT_MOD_ORDER_DUMP + nodeList.push_back(node); +#endif } return node; } @@ -42,13 +48,18 @@ void CycleGraph::addEdge(const ModelAction *from, const ModelAction *to) { CycleNode *fromnode=getNode(from); CycleNode *tonode=getNode(to); + if (!hasCycles) { + // Reflexive edges are cycles + hasCycles = (from == to); + } if (!hasCycles) { // Check for Cycles hasCycles=checkReachable(tonode, fromnode); } - rollbackvector.push_back(fromnode); - fromnode->addEdge(tonode); + if (fromnode->addEdge(tonode)) + rollbackvector.push_back(fromnode); + CycleNode * rmwnode=fromnode->getRMW(); @@ -64,8 +75,9 @@ void CycleGraph::addEdge(const ModelAction *from, const ModelAction *to) { // Check for Cycles hasCycles=checkReachable(tonode, rmwnode); } - rollbackvector.push_back(rmwnode); - rmwnode->addEdge(tonode); + + if (rmwnode->addEdge(tonode)) + rollbackvector.push_back(rmwnode); } } @@ -99,20 +111,54 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw) { for(unsigned int i=0;isize();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) { + // Reflexive edges are cycles + hasCycles = (from == rmw); + } 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::dumpNodes(FILE *file) { + for (unsigned int i=0;i * 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;jsize();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()); + } + } +} + +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); + dumpNodes(file); + fprintf(file,"}\n"); + fclose(file); +} +#endif + /** * Checks whether one ModelAction can reach another. * @param from The ModelAction from which to begin exploration @@ -136,11 +182,11 @@ bool CycleGraph::checkReachable(const ModelAction *from, const ModelAction *to) * @return True, @a from can reach @a to; otherwise, false */ bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) { - std::vector queue; - HashTable discovered; + std::vector > queue; + discovered->reset(); queue.push_back(from); - discovered.put(from, from); + discovered->put(from, from); while(!queue.empty()) { CycleNode * node=queue.back(); queue.pop_back(); @@ -149,8 +195,35 @@ bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) { for(unsigned int i=0;igetEdges()->size();i++) { CycleNode *next=(*node->getEdges())[i]; - if (!discovered.contains(next)) { - discovered.put(next,next); + if (!discovered->contains(next)) { + discovered->put(next,next); + queue.push_back(next); + } + } + } + return false; +} + +bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) { + std::vector > queue; + discovered->reset(); + CycleNode *from = actionToNode.get(fromact); + + + queue.push_back(from); + discovered->put(from, from); + while(!queue.empty()) { + CycleNode * node=queue.back(); + queue.pop_back(); + + if (promise->increment_threads(node->getAction()->get_tid())) { + return true; + } + + for(unsigned int i=0;igetEdges()->size();i++) { + CycleNode *next=(*node->getEdges())[i]; + if (!discovered->contains(next)) { + discovered->put(next,next); queue.push_back(next); } } @@ -217,8 +290,12 @@ std::vector * CycleNode::getEdges() { * 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