From: bdemsky Date: Mon, 11 Jan 2010 08:14:02 +0000 (+0000) Subject: add new contention manager X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=48a05610ad917bea356f4978e17553d915bb15e8;p=IRC.git add new contention manager --- diff --git a/Robust/TransSim/FileSim.java b/Robust/TransSim/FileSim.java index 05bee9a7..4154e772 100644 --- a/Robust/TransSim/FileSim.java +++ b/Robust/TransSim/FileSim.java @@ -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 diff --git a/Robust/TransSim/FlexScheduler.java b/Robust/TransSim/FlexScheduler.java index c635882a..d1d9ef02 100644 --- a/Robust/TransSim/FlexScheduler.java +++ b/Robust/TransSim/FlexScheduler.java @@ -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; }