fixed some bugs
authorbdemsky <bdemsky>
Mon, 14 Sep 2009 08:41:16 +0000 (08:41 +0000)
committerbdemsky <bdemsky>
Mon, 14 Sep 2009 08:41:16 +0000 (08:41 +0000)
support more scheduling policies

Robust/TransSim/Executor.java
Robust/TransSim/FlexScheduler.java
Robust/TransSim/Scheduler.java
Robust/TransSim/ThreadClass.java
Robust/TransSim/TransSim.java
Robust/TransSim/Transaction.java

index ab85935b52432a47bf605f667431e4c9aedd21d5..0707eed262466b5a471086451cfa50ee526a31f4 100644 (file)
@@ -15,6 +15,15 @@ public class Executor {
   Random r;
   ThreadClass[] threads;
 
+  public String toString() {
+    String s="";
+    for(int i=0;i<numThreads;i++)
+      s+=threads[i].toString();
+
+    return s;
+  }
+
+
   public Executor(int numThreads, int numTrans, int deltaTrans, int numObjects, int numAccesses, int deltaAccesses, int readPercent, int delay, int deltaDelay, int nonTrans, int deltaNonTrans) {
     this.numThreads=numThreads;
     this.numTrans=numTrans;
@@ -89,7 +98,7 @@ public class Executor {
     int accesses=getRandom(numAccesses, deltaAccesses);
     Transaction t=new Transaction(accesses);
     int time=0;
-    for(int i=0;i<accesses; i++) {
+    for(int i=0;i<(accesses-1); i++) {
       boolean isRead=r.nextInt(100)<readPercent;
       time+=getRandom(delay, deltaDelay);
       int object=r.nextInt(numObjects);
@@ -100,6 +109,11 @@ public class Executor {
       else
        t.setEvent(i, Transaction.WRITE);
     }
+    t.setEvent(accesses-1, Transaction.DELAY);
+    t.setObject(accesses-1, Transaction.DELAY);
+    time+=getRandom(delay, deltaDelay);
+    t.setTime(accesses-1, time);
+
     return t;
   }
 
index 974ee8a1e7d0a6a55c887aadd22256592a5f6ba9..6e19ba250e05a0099211784a3c21bd5b0e32561a 100644 (file)
@@ -199,6 +199,11 @@ public class FlexScheduler {
       if (threadid.intValue()!=thread)
        conflictset.add(threadid);
     }
+    for(Iterator it=((Set)wrobjmap.get(obj)).iterator();it.hasNext();) {
+      Integer threadid=(Integer)it.next();
+      if (threadid.intValue()!=thread)
+       conflictset.add(threadid);
+    }
     if (conflictset.isEmpty())
       return null;
     else
@@ -341,7 +346,16 @@ public class FlexScheduler {
 
     public int compareTo(Object o) {
       Event e=(Event)o;
-      return time-e.time;
+      int delta=time-e.time;
+      if (delta!=0)
+       return delta;
+      if (((getEvent()+1)==getTransaction().numEvents())&&
+         (e.getEvent()+1)!=e.getTransaction().numEvents())
+       return -1;
+      if (((getEvent()+1)!=getTransaction().numEvents())&&
+         (e.getEvent()+1)==e.getTransaction().numEvents())
+       return 1;
+      return 0;
     }
   }
 
index b050913013c0f3912439494546a238ec4c1679d8..ae04fa89842b630f63881953fd0505318f79dc22 100644 (file)
@@ -79,7 +79,8 @@ public class Scheduler {
          int newstart=lastwr[step][evobject]-evtime;
          if (newstart>starttime)
            starttime=newstart;
-         newstart=lastrd[step][evobject]-evtime;
+
+         newstart=lastrd[step][evobject]-trans.getTime(trans.numEvents()-1);
          if (newstart>starttime)
            starttime=newstart;
          break;
@@ -175,6 +176,7 @@ public class Scheduler {
       
       if (!lgood||step==lastEvent) {
        //go backwards
+       step--;
        for(;step>=0;step--) {
          //check for delay transaction...just skip them
          Transaction oldtrans=e.getThread(turn[step]).getTransaction(schedule[0][turn[step]]-schedule[step][turn[step]]);
@@ -183,19 +185,8 @@ public class Scheduler {
          
          iturn=turn[step]+1;
          for(;iturn<e.numThreads();iturn++) {
-           if (schedule[step][iturn]>0) {
-             if (step==0)
-               break;
-             
-             int lastturn=turn[step-1];
-             if (iturn<lastturn) {
-               Transaction trans1=e.getThread(lastturn).getTransaction(schedule[0][iturn]-schedule[step][iturn]);
-               Transaction trans2=e.getThread(iturn).getTransaction(schedule[0][lastturn]-schedule[step-1][lastturn]);
-               if (checkConflicts(trans1, trans2))
-                 break;
-             } else
-               break;
-           }
+           if (schedule[step][iturn]>0)
+             break;
          }
          if (iturn<e.numThreads()) {
            //found something to iterate
index c9e0a54e07deddba1ad86574e8106a6bdc0581bd..2675b429a5f3277e6c5a06d22e326f08dbeaecf7 100644 (file)
@@ -1,5 +1,14 @@
 public class ThreadClass {
   Transaction[] trans;
+
+  public String toString() {
+    String s="Thread\n";
+    for(int i=0;i<trans.length;i++) {
+      s+="Transaction "+i+"\n";
+      s+=trans[i].toString();
+    }
+    return s;
+  }
   
   public ThreadClass(int numTrans) {
     trans=new Transaction[numTrans];
index 1c63d7bb1c104d6ae9ad0b8b4b2038395bb94ec7..0e27a9a736b8bdd943181c16c2affc84ea1c4566 100644 (file)
@@ -1,60 +1,73 @@
 public class TransSim {
   public static void main(String[] args) {
-    int numThreads=4;
-    int numTrans=8;
+    int numThreads=32;
+    int numTrans=100;
     int deltaTrans=0;
-    int numObjects=10;
-    int numAccesses=4;
-    int deltaAccesses=2;
-    int readPercent=50;
+    int numObjects=500;
+    int numAccesses=20;
+    int deltaAccesses=5;
+    int readPercent=30;
     //time for operation
     int delay=20;
     int deltaDelay=4;
     //time between transactions
     int nonTrans=20;
     int deltaNonTrans=4;
-    Executor e=new Executor(numThreads, numTrans, deltaTrans, numObjects, numAccesses, deltaAccesses, readPercent, delay, deltaDelay, nonTrans, deltaNonTrans);
-    System.out.println(e.maxTime());
-    FlexScheduler ls=new FlexScheduler(e, FlexScheduler.LAZY);
-    ls.dosim();
-    System.out.println("Lazy Time="+ls.getTime());
-    System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
-    int besttime=ls.getTime();
 
-    //Kill others at commit
-    ls=new FlexScheduler(e, FlexScheduler.COMMIT);
-    ls.dosim();
-    System.out.println("Fast Abort="+ls.getTime());
-    System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
-    if (ls.getTime()<besttime)
-      besttime=ls.getTime();
+    long tlazy=0, tcommit=0, tattack=0, tpolite=0, tkarma=0;
+    for(int i=0;i<100;i++) {
+      Executor e=new Executor(numThreads, numTrans, deltaTrans, numObjects, numAccesses, deltaAccesses, readPercent, delay, deltaDelay, nonTrans, deltaNonTrans);
+      System.out.println(e.maxTime());
+      FlexScheduler ls=new FlexScheduler(e, FlexScheduler.LAZY);
+      ls.dosim();
+      System.out.println("Lazy Time="+ls.getTime());
+      System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+      int besttime=ls.getTime();
+      tlazy+=ls.getTime();
 
-    //Eager attack
-    ls=new FlexScheduler(e, FlexScheduler.ATTACK);
-    ls.dosim();
-    System.out.println("Attack Abort="+ls.getTime());
-    System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
-    if (ls.getTime()<besttime)
-      besttime=ls.getTime();
+      //Kill others at commit
+      ls=new FlexScheduler(e, FlexScheduler.COMMIT);
+      ls.dosim();
+      System.out.println("Fast Abort="+ls.getTime());
+      System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+      if (ls.getTime()<besttime)
+       besttime=ls.getTime();
+      tcommit+=ls.getTime();
+      
+      //Eager attack
+      ls=new FlexScheduler(e, FlexScheduler.ATTACK);
+      ls.dosim();
+      System.out.println("Attack Abort="+ls.getTime());
+      System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+      if (ls.getTime()<besttime)
+       besttime=ls.getTime();
+      tattack+=ls.getTime();      
 
-    //Eager polite
-    ls=new FlexScheduler(e, FlexScheduler.POLITE);
-    ls.dosim();
-    System.out.println("Polite Abort="+ls.getTime());
-    System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
-    if (ls.getTime()<besttime)
-      besttime=ls.getTime();
-    
-    //Karma
-    ls=new FlexScheduler(e, FlexScheduler.KARMA);
-    ls.dosim();
-    System.out.println("Karma Abort="+ls.getTime());
-    System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
-    if (ls.getTime()<besttime)
-      besttime=ls.getTime();
+      //Eager polite
+      ls=new FlexScheduler(e, FlexScheduler.POLITE);
+      ls.dosim();
+      System.out.println("Polite Abort="+ls.getTime());
+      System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+      if (ls.getTime()<besttime)
+       besttime=ls.getTime();
+      tpolite+=ls.getTime();      
 
-    Scheduler s=new Scheduler(e, besttime);
-    s.dosim();
-    System.out.println("Optimal Time="+s.getTime());
+      //Karma
+      ls=new FlexScheduler(e, FlexScheduler.KARMA);
+      ls.dosim();
+      System.out.println("Karma Abort="+ls.getTime());
+      System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+      if (ls.getTime()<besttime)
+       besttime=ls.getTime();
+      tkarma+=ls.getTime();
+      //    Scheduler s=new Scheduler(e, besttime);
+      //s.dosim();
+      //System.out.println("Optimal Time="+s.getTime());
+    }
+    System.out.println("lazy="+tlazy);
+    System.out.println("commit="+tcommit);
+    System.out.println("attack="+tattack);
+    System.out.println("polite="+tpolite);
+    System.out.println("karma="+tkarma);
   }
 }
\ No newline at end of file
index 2f7f5e738b5b167e9a602c34034c9f574eddd9e8..05f89d398b8079a1b6c59c4354fdefb5a451630f 100644 (file)
@@ -3,6 +3,20 @@ public class Transaction {
   int[] objects;
   int[] times;
 
+  public String toString() {
+    String s="";
+    for(int i=0;i<numEvents();i++) {
+      if (events[i]==READ)
+       s+="Read";
+      else if(events[i]==WRITE)
+       s+="Write";
+      else 
+       s+="Delay";
+      s+=" on "+objects[i]+" at "+times[i]+"\n";
+    }
+    return s;
+  }
+
   public static final int READ=0;
   public static final int WRITE=1;
   public static final int DELAY=-1;