add support for dumping cyclegraphs as dot files... also eliminate redundant edges...
authorBrian Demsky <bdemsky@uci.edu>
Fri, 14 Sep 2012 05:04:45 +0000 (22:04 -0700)
committerBrian Demsky <bdemsky@uci.edu>
Fri, 14 Sep 2012 05:04:45 +0000 (22:04 -0700)
config.h
cyclegraph.cc
cyclegraph.h
model.cc
test/rmwprog.c

index 1d0b6380345af93e53a1f166bfc2c661778e3ee1..ab54e3abe68e12e8199976dfb415d188dff54258 100644 (file)
--- a/config.h
+++ b/config.h
@@ -11,6 +11,9 @@
                #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. */
index 26235d651e10ecb5e2178d281048ea6ce5007893..c7bb69b990d801dc026765420e918e35a31f1b0d 100644 (file)
@@ -25,6 +25,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;
 }
@@ -47,8 +50,9 @@ void CycleGraph::addEdge(const ModelAction *from, const ModelAction *to) {
                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 +68,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,19 +104,42 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw) {
        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());
+               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.
@@ -136,8 +164,8 @@ 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<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);
@@ -217,8 +245,12 @@ std::vector<CycleNode *> * 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<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 */
index 81d736962dcb6893c8ef213b9571454c24ac5ea6..c8e8956be10529d194304061f8f90a6c48181181 100644 (file)
@@ -8,7 +8,7 @@
 #include "hashtable.h"
 #include <vector>
 #include <inttypes.h>
-
+#include "config.h"
 #include "mymemory.h"
 
 class CycleNode;
@@ -28,6 +28,9 @@ class CycleGraph {
        void startChanges();
        void commitChanges();
        void rollbackChanges();
+#if SUPPORT_MOD_ORDER_DUMP
+       void dumpGraphToFile(const char * filename);
+#endif
 
        SNAPSHOTALLOC
  private:
@@ -35,6 +38,9 @@ class CycleGraph {
 
        /** @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);
 
@@ -53,10 +59,12 @@ class CycleGraph {
 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();
        };
index 031f6a935ec5701bdf72fdf2bdfe321e70712a28..1712a60a9dd3990efeef26f257467f5bff7d6bb0 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -1184,7 +1184,12 @@ void ModelChecker::print_summary()
        printf("Number of executions: %d\n", num_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");
index 14929ee23b6502403d12f8dda1194b38c233c59e..c3a5ea82fb328b793b967707b2a2c3ec2cb38990 100644 (file)
@@ -17,7 +17,6 @@ void user_main()
        thrd_t t1, t2;
 
        atomic_init(&x, 0);
-
        thrd_create(&t1, (thrd_start_t)&a, NULL);
        thrd_create(&t2, (thrd_start_t)&a, NULL);