adding a test case
[IRC.git] / Robust / TransSim / FlexScheduler.java
index 8fc77ce98b4f4698dfd2cef8063f7e18c59ab0b8..1ce1d2d081a0c81d53dab6f8a96a8dfa97906fb4 100644 (file)
@@ -51,6 +51,9 @@ public class FlexScheduler extends Thread {
     }
   }
 
+  int lowid=0;
+  int countlow=0;
+
   Plot p;
   Series serCommit;
   Series serStart;
@@ -82,10 +85,45 @@ public class FlexScheduler extends Thread {
   public static final int ATTACKTIME=12;
   public static final int ATTACKTHREAD=13;
 
+  public static String getName(int policy) {
+    switch (policy) {
+    case LAZY:
+      return new String("LAZY");
+    case COMMIT:
+      return new String("COMMIT");
+    case ATTACK:
+      return new String("ATTACK");
+    case SUICIDE:
+      return new String("TIMID");
+    case TIMESTAMP:
+      return new String("TIMESTAMP");
+    case LOCK:
+      return new String("LOCK");
+    case LOCKCOMMIT:
+      return new String("LOCKCOMMIT");
+    case RANDOM:
+      return new String("RANDOM");
+    case KARMA:
+      return new String("KARMA");
+    case POLITE:
+      return new String("POLITE");
+    case ERUPTION:
+      return new String("ERUPTION");
+    case THREAD:
+      return new String("THREAD");
+    case ATTACKTIME:
+      return new String("ATTACKTIME");
+    case ATTACKTHREAD:
+      return new String("ATTACKTHREAD");
+    }
+    return null;
+  }
+
   PriorityQueue eq;
   int policy;
   boolean[] aborted;
   long shorttesttime;
+  long earliesttime=-1;
   long starttime=-1;
   Hashtable rdobjmap;
   Hashtable wrobjmap;
@@ -124,6 +162,10 @@ public class FlexScheduler extends Thread {
     return commitcount;
   }
 
+  public long getEarliestTime() {
+    return earliesttime-starttime;
+  }
+
   public long getTime() {
     return shorttesttime-starttime;
   }
@@ -147,9 +189,11 @@ public class FlexScheduler extends Thread {
     int eIndex=e.getEvent();
     long eTime=e.getTime();
     long timeleft=eTime-currtime;
-    long totaltime=0;
-    for(int i=0;i<=eIndex;i++)
-      totaltime+=trans.getTime(i);
+    if (e.isStalled()) {
+      stallcycles-=timeleft; //this time is no longer stalled...back it out
+      timeleft=0;//if the event is stalled, we already waited this time...
+    }
+    long totaltime=trans.getTime(eIndex);
     totaltime-=timeleft;//subtract off time to the next event
     abortedcycles+=totaltime;
   }
@@ -179,6 +223,7 @@ public class FlexScheduler extends Thread {
   public void stall(Event ev, long time, long delay) {
     stallcycles+=delay;
     ev.setTime(time+delay);
+    ev.setStall();
     eq.add(ev);
   }
 
@@ -274,6 +319,16 @@ public class FlexScheduler extends Thread {
     //ready to commit this one
     long currtime=ev.getTime();
     releaseObjects(trans, ev.getThread(), currtime);
+
+    if (ev.getThread()==lowid) {
+      countlow++;
+      if (countlow==4) {
+       countlow=0;
+       lowid++;
+       if (lowid==e.numThreads())
+         lowid=0;
+      }
+    }
     
     //See if we have been flagged as aborted for the lazy case
     boolean abort=aborted[ev.getThread()];
@@ -363,6 +418,9 @@ public class FlexScheduler extends Thread {
       Event nev=new Event(currtime+nexttrans.getTime(0), nexttrans, 0, ev.getThread(), nexttransnum);
       currentevents[ev.getThread()]=nev;
       eq.add(nev);
+    } else {
+      if (earliesttime==-1)
+       earliesttime=currtime;
     }
   }
 
@@ -381,6 +439,14 @@ public class FlexScheduler extends Thread {
       return conflictset;
   }
 
+
+  int normalize(int tid) {
+    int newtid=tid-lowid;
+    if (newtid<0)
+      newtid+=e.numThreads();
+    return newtid;
+  }
+
   public Set wrConflictSet(int thread, ObjIndex obj) {
     HashSet conflictset=new HashSet();
     if (rdobjmap.containsKey(obj)) {
@@ -565,11 +631,11 @@ public class FlexScheduler extends Thread {
        Integer thread=(Integer)thit.next();
        Event other=currentevents[thread.intValue()];
        int eventnum=other.getEvent();
-       long otid=thread.intValue();
+       long otid=normalize(thread.intValue());
        if (tid>otid)
          tid=otid;
       }
-      if (ev.getThread()>tid) {
+      if (normalize(ev.getThread())>tid) {
        //kill ourself
        timewasted(ev.getThread(), time);
        reschedule(ev.getThread(), time, 0);
@@ -813,6 +879,15 @@ public class FlexScheduler extends Thread {
     Transaction t;
     int threadid;
     int transnum;
+    boolean stalled;
+
+    public boolean isStalled() {
+      return stalled;
+    }
+
+    public void setStall() {
+      stalled=true;
+    }
 
     public void makeInvalid() {
       valid=false;