add new contention manager
authorbdemsky <bdemsky>
Mon, 11 Jan 2010 08:14:02 +0000 (08:14 +0000)
committerbdemsky <bdemsky>
Mon, 11 Jan 2010 08:14:02 +0000 (08:14 +0000)
Robust/TransSim/FileSim.java
Robust/TransSim/FlexScheduler.java

index 05bee9a734bb2358d2b707000331b35cd954267e..4154e7725feda503d838b08ea5bf45f667eb743a 100644 (file)
@@ -69,6 +69,7 @@ public class FileSim {
     ls9.join();
     System.out.println("Karma Abort="+ls9.getTime());
     System.out.println("Aborts="+ls9.getAborts()+" Commit="+ls9.getCommits());
+    System.out.println("atime="+ls9.aborttime+" stalltime="+ls9.stalltime);
     ls9=null;
 
     ls10.join();
@@ -78,9 +79,21 @@ public class FileSim {
 
     ls11.join();
     System.out.println("Eruption Abort="+ls11.getTime());
+    System.out.println("atime="+ls11.aborttime+" stalltime="+ls11.stalltime);
     System.out.println("Aborts="+ls11.getAborts()+" Commit="+ls11.getCommits());
   }
 
+  public static void p4(Executor e) throws Exception {
+    FlexScheduler ls9=new FlexScheduler(e, FlexScheduler.THREAD, null);
+    ls9.start();
+
+    ls9.join();
+    System.out.println("Karma Abort="+ls9.getTime());
+    System.out.println("Aborts="+ls9.getAborts()+" Commit="+ls9.getCommits());
+    System.out.println("atime="+ls9.aborttime+" stalltime="+ls9.stalltime);
+    ls9=null;
+  }
+
   public static void main(String[] args) throws Exception {
     //time between transactions
     //split objects
@@ -99,5 +112,7 @@ public class FileSim {
       p2(e);
     if (args.length==1||args[1].equals("3"))
       p3(e);
+    if (args.length==1||args[1].equals("4"))
+      p4(e);
   }
 }
\ No newline at end of file
index c635882ab992794d27b7fdd8885d247b2fcc65b0..d1d9ef02881d9f4dec2dd1d595f0b6a4661c71bd 100644 (file)
@@ -78,6 +78,7 @@ public class FlexScheduler extends Thread {
   public static final int KARMA=8;
   public static final int POLITE=9;
   public static final int ERUPTION=10;
+  public static final int THREAD=11;
 
   PriorityQueue eq;
   int policy;
@@ -99,7 +100,7 @@ public class FlexScheduler extends Thread {
   boolean[] blocked;
 
   public boolean isEager() {
-    return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE||policy==ERUPTION;
+    return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE||policy==ERUPTION||policy==THREAD;
   }
 
   public boolean countObjects() {
@@ -367,6 +368,9 @@ public class FlexScheduler extends Thread {
   //Takes as parameter -- current transaction read event ev, conflicting
   //set of threads, and the current time
   //Returning false causes current transaction not continue to be scheduled
+  long stalltime=0;
+  long aborttime=0;
+
 
   public boolean handleConflicts(Event ev, Set threadstokill, long time) {
     if (policy==RANDOM) {
@@ -399,7 +403,9 @@ public class FlexScheduler extends Thread {
        //stall for a little while
        threadinfo[ev.getThread()].priority--;
        retrycount[ev.getThread()]++;
-       stall(ev, time+r.nextInt(3000));
+       int rtime=r.nextInt(3000);
+       stall(ev, time+rtime);
+       stalltime+=rtime;
        return false;
       } else {
        //we win
@@ -408,7 +414,9 @@ public class FlexScheduler extends Thread {
          int dback=backoff[thread]*2;
          if (dback>0)
            backoff[thread]=dback;
-         reschedule(thread, time+r.nextInt(backoff[thread]));
+         int atime=r.nextInt(backoff[thread]);
+         reschedule(thread, time+atime);
+         aborttime+=atime;
          abortcount++;
        }
        return true;
@@ -425,7 +433,9 @@ public class FlexScheduler extends Thread {
        //we lose
        threadinfo[ev.getThread()].priority--;
        //stall for a little while
-       stall(ev, time+r.nextInt(3000));
+       int rtime=r.nextInt(3000);
+       stall(ev, time+rtime);
+       stalltime+=rtime;
        int ourpriority=threadinfo[ev.getThread()].priority;
        ourpriority-=transferred[ev.getThread()];
        for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
@@ -443,7 +453,9 @@ public class FlexScheduler extends Thread {
          int dback=backoff[thread]*2;
          if (dback>0)
            backoff[thread]=dback;
-         reschedule(thread, time+r.nextInt(backoff[thread]));
+         int atime=r.nextInt(backoff[thread]);
+         reschedule(thread, time+atime);
+         aborttime+=atime;
          abortcount++;
        }
        return true;
@@ -508,8 +520,59 @@ public class FlexScheduler extends Thread {
        }
        return true;    
       }
+    } else if (policy==TIMESTAMP) {
+      long opponenttime=0;
+
+      for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+       Integer thread=(Integer)thit.next();
+       Event other=currentevents[thread.intValue()];
+       int eventnum=other.getEvent();
+       long otime=other.getTransaction().getTime(other.getEvent());
+       if (otime>opponenttime)
+         opponenttime=otime;
+      }
+      if (opponenttime>ev.getTransaction().getTime(ev.getEvent())) {
+       //kill ourself
+       reschedule(ev.getThread(), time+r.nextInt(backoff[ev.getThread()]));
+       abortcount++;
+       return false;
+      } else {
+       //kill the opponents
+       for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+         Integer thread=(Integer)thit.next();
+         reschedule(thread, time+r.nextInt(backoff[thread.intValue()]));
+         abortcount++;
+       }
+       return true;    
+      }
+    } else if (policy==THREAD) {
+      long tid=1000;
+
+      for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+       Integer thread=(Integer)thit.next();
+       Event other=currentevents[thread.intValue()];
+       int eventnum=other.getEvent();
+       long otid=thread.intValue();
+       if (tid>otid)
+         tid=otid;
+      }
+      if (ev.getThread()>tid) {
+       //kill ourself
+       reschedule(ev.getThread(), time+r.nextInt(backoff[ev.getThread()]));
+       abortcount++;
+       return false;
+      } else {
+       //kill the opponents
+       for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+         Integer thread=(Integer)thit.next();
+         reschedule(thread, time+r.nextInt(backoff[thread.intValue()]));
+         abortcount++;
+       }
+       return true;    
+      }
     }
 
+
     //Not eager
     return true;
   }