this.abortRatio=abortRatio;
this.checkdepth=checkdepth;
}
-
+
public void run() {
dosim();
}
public static final int POLITE=9;
public static final int ERUPTION=10;
public static final int THREAD=11;
+ public static final int ATTACKTIME=12;
+ public static final int ATTACKTHREAD=13;
PriorityQueue eq;
int policy;
Hashtable wrobjmap;
int abortcount;
int commitcount;
+ long backoffcycles;
+ long stallcycles;
+ long abortedcycles;
Event[] currentevents;
Random r;
int[] backoff;
boolean[] blocked;
public boolean isEager() {
- return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE||policy==ERUPTION||policy==THREAD;
+ return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE||policy==ERUPTION||policy==THREAD||policy==ATTACKTIME||policy==ATTACKTHREAD;
}
public boolean countObjects() {
return shorttesttime-starttime;
}
+ public long getStallTime() {
+ return stallcycles;
+ }
+
+ public long getBackoffTime() {
+ return backoffcycles;
+ }
+
//Aborts another thread...
- public void reschedule(int currthread, long time) {
+ public void reschedule(int currthread, long currtime, long backofftime) {
+ long time=currtime+backofftime;
+ backoffcycles+=backofftime;
currentevents[currthread].makeInvalid();
if (threadinfo[currthread].isStalled()) {
//remove from waiter list
}
//Aborts another thread...
- public void stall(Event ev, long time) {
- ev.setTime(time);
+ public void stall(Event ev, long time, long delay) {
+ stallcycles+=delay;
+ ev.setTime(time+delay);
eq.add(ev);
}
-
private void releaseObjects(Transaction trans, int currthread, long time) {
//remove all events
for(int i=0;i<trans.numEvents();i++) {
}
//Reset our backoff counter
threadinfo[ev.getThread()].priority=0;
+ threadinfo[ev.getThread()].aborted=false;
backoff[ev.getThread()]=BACKOFFSTART;
retrycount[ev.getThread()]=0;
transferred[ev.getThread()]=0;
serAbort.addPoint(currtime, threadid);
} else if (policy==COMMIT||policy==LOCKCOMMIT) {
//abort it immediately
- reschedule(threadid, currtime);
+ reschedule(threadid, currtime, 0);
abortcount++;
}
}
//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) {
int dback=backoff[thread]*2;
if (dback>0)
backoff[thread]=dback;
- stall(ev, time+r.nextInt(backoff[thread]));
+ stall(ev, time, r.nextInt(backoff[thread]));
return false;
} else {
//abort other transactions
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
- reschedule(thread, time);
+ reschedule(thread, time, 0);
abortcount++;
}
return true;
threadinfo[ev.getThread()].priority--;
retrycount[ev.getThread()]++;
int rtime=r.nextInt(3000);
- stall(ev, time+rtime);
- stalltime+=rtime;
+ stall(ev, time, rtime);
return false;
} else {
//we win
if (dback>0)
backoff[thread]=dback;
int atime=r.nextInt(backoff[thread]);
- reschedule(thread, time+atime);
- aborttime+=atime;
+ reschedule(thread, time, atime);
abortcount++;
}
return true;
threadinfo[ev.getThread()].priority--;
//stall for a little while
int rtime=r.nextInt(3000);
- stall(ev, time+rtime);
- stalltime+=rtime;
+ stall(ev, time, rtime);
int ourpriority=threadinfo[ev.getThread()].priority;
ourpriority-=transferred[ev.getThread()];
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
if (dback>0)
backoff[thread]=dback;
int atime=r.nextInt(backoff[thread]);
- reschedule(thread, time+atime);
- aborttime+=atime;
+ reschedule(thread, time, atime);
abortcount++;
}
return true;
retrycount[ev.getThread()]=0;
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
- reschedule(thread, time);
+ reschedule(thread, time, 0);
abortcount++;
}
return true;
int stalltime=(1<<(retry-1))*12;
if (stalltime<0)
stalltime=1<<30;
- stall(ev, time+r.nextInt(stalltime));
+ stall(ev, time, r.nextInt(stalltime));
return false;
}
} else if (policy==ATTACK) {
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
- reschedule(thread, time+r.nextInt(backoff[thread.intValue()]));
+ reschedule(thread, time, r.nextInt(backoff[thread.intValue()]));
int dback=backoff[thread.intValue()]*2;
if (dback>0)
backoff[thread.intValue()]=dback;
}
return true;
} else if (policy==SUICIDE) {
- reschedule(ev.getThread(), time+r.nextInt(backoff[ev.getThread()]));
+ reschedule(ev.getThread(), time, r.nextInt(backoff[ev.getThread()]));
int dback=backoff[ev.getThread()]*2;
if (dback>0)
backoff[ev.getThread()]=dback;
}
if (opponenttime>ev.getTransaction().getTime(ev.getEvent())) {
//kill ourself
- reschedule(ev.getThread(), time+r.nextInt(backoff[ev.getThread()]));
+ reschedule(ev.getThread(), time, 0);
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()]));
+ reschedule(thread, time, 0);
abortcount++;
}
return true;
}
- } else if (policy==TIMESTAMP) {
- long opponenttime=0;
+ } 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 otime=other.getTransaction().getTime(other.getEvent());
- if (otime>opponenttime)
- opponenttime=otime;
+ long otid=thread.intValue();
+ if (tid>otid)
+ tid=otid;
}
- if (opponenttime>ev.getTransaction().getTime(ev.getEvent())) {
+ if (ev.getThread()>tid) {
//kill ourself
- reschedule(ev.getThread(), time+r.nextInt(backoff[ev.getThread()]));
+ reschedule(ev.getThread(), time, 0);
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()]));
+ reschedule(thread, time, 0);
abortcount++;
}
return true;
}
- } else if (policy==THREAD) {
- long tid=1000;
-
+ } else if (policy==ATTACKTIME) {
+ boolean timebased=false;
+ int tev=ev.getThread();
+ timebased|=threadinfo[tev].aborted;
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;
+ timebased|=threadinfo[thread.intValue()].aborted;
}
- if (ev.getThread()>tid) {
- //kill ourself
- reschedule(ev.getThread(), time+r.nextInt(backoff[ev.getThread()]));
- abortcount++;
- return false;
+ if (timebased) {
+ 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, 0);
+ threadinfo[ev.getThread()].aborted=true;
+ abortcount++;
+ return false;
+ } else {
+ //kill the opponents
+ for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+ Integer thread=(Integer)thit.next();
+ reschedule(thread, time, 0);
+ threadinfo[thread.intValue()].aborted=true;
+ abortcount++;
+ }
+ return true;
+ }
} else {
- //kill the opponents
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
- reschedule(thread, time+r.nextInt(backoff[thread.intValue()]));
+ reschedule(thread, time, 0);
+ threadinfo[thread.intValue()].aborted=true;
abortcount++;
}
- return true;
+ return true;
+ }
+ } else if (policy==ATTACKTHREAD) {
+ boolean threadbased=false;
+ int tev=ev.getThread();
+ threadbased|=threadinfo[tev].aborted;
+ for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+ Integer thread=(Integer)thit.next();
+ threadbased|=threadinfo[thread.intValue()].aborted;
+ }
+ if (threadbased) {
+ long opponentthr=1000;
+
+ for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+ Integer thread=(Integer)thit.next();
+ Event other=currentevents[thread.intValue()];
+ int eventnum=other.getEvent();
+ long othr=thread.intValue();
+ if (othr<opponentthr)
+ opponentthr=othr;
+ }
+ if (opponentthr<tev) {
+ //kill ourself
+ reschedule(ev.getThread(), time, 0);
+ threadinfo[ev.getThread()].aborted=true;
+ abortcount++;
+ return false;
+ } else {
+ //kill the opponents
+ for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+ Integer thread=(Integer)thit.next();
+ reschedule(thread, time, 0);
+ threadinfo[thread.intValue()].aborted=true;
+ abortcount++;
+ }
+ return true;
+ }
+ } else {
+ for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
+ Integer thread=(Integer)thit.next();
+ reschedule(thread, time, 0);
+ threadinfo[thread.intValue()].aborted=true;
+ abortcount++;
+ }
+ return true;
}
}
-
//Not eager
return true;
}
int numThreads=20;
int numTrans=40;
int deltaTrans=0;
- int numObjects=200;
+ int numObjects=400;
int numAccesses=20;
- int deltaAccesses=0;
- int readPercent=0;
+ int deltaAccesses=3;
+ int readPercent=80; //80 percent read
//time for operation
int delay=20;
int deltaDelay=4;
int nonTrans=20;
int deltaNonTrans=4;
//split objects
- int splitobjects=200;//10 percent of objects special
- int splitaccesses=100;//40 percent of accesses to special objects
- int readPercentSecond=30;//20 percent of accesses are reads
+ int splitobjects=100;//100 percent normal objects
+ int splitaccesses=100;//100 percent access to normal objects
+ int readPercentSecond=80;//20 percent of accesses are reads
int abortThreshold=0; //need 4 aborts to declare risky
int abortRatio=0;//need 40% aborts vs commits to declare risky
int deadlockdepth=10;
Plot p=new Plot("plot");
+ Plot pa=new Plot("plotabort");
- for(int i=1;i<30;i++) {
+ for(int i=1;i<40;i++) {
System.out.println("i="+i);
numThreads=i;
Executor e=new Executor(numThreads, numTrans, deltaTrans, numObjects, numAccesses, deltaAccesses, readPercent, delay, deltaDelay, nonTrans, deltaNonTrans, splitobjects, splitaccesses, readPercentSecond);
System.out.println("Lazy Time="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("LAZY").addPoint(i, ls.getTime());
-
+ pa.getSeries("LAZY").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Lock object accesses
ls=new FlexScheduler(e, FlexScheduler.LOCK, abortThreshold, abortRatio, deadlockdepth, null);
System.out.println("Lock Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("LOCK").addPoint(i, ls.getTime());
+ pa.getSeries("LOCK").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Lock Commit object accesses
ls=new FlexScheduler(e, FlexScheduler.LOCKCOMMIT, abortThreshold, abortRatio, deadlockdepth, null);
System.out.println("LockCommit Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("LOCKCOMMIT").addPoint(i, ls.getTime());
+ pa.getSeries("LOCKCOMMIT").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Kill others at commit
ls=new FlexScheduler(e, FlexScheduler.COMMIT, null);
System.out.println("Fast Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("COMMIT").addPoint(i, ls.getTime());
-
+ pa.getSeries("COMMIT").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
+
//Eager attack
ls=new FlexScheduler(e, FlexScheduler.ATTACK, null);
ls.dosim();
System.out.println("Attack Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("ATTACK").addPoint(i, ls.getTime());
+ pa.getSeries("ATTACK").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Eager polite
ls=new FlexScheduler(e, FlexScheduler.SUICIDE, null);
System.out.println("Suicide Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("SUICIDE").addPoint(i, ls.getTime());
+ pa.getSeries("SUICIDE").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Karma
ls=new FlexScheduler(e, FlexScheduler.TIMESTAMP, null);
System.out.println("Timestamp Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("TIMESTAMP").addPoint(i, ls.getTime());
+ pa.getSeries("TIMESTAMP").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Karma
ls=new FlexScheduler(e, FlexScheduler.RANDOM, null);
System.out.println("Random Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("RANDOM").addPoint(i, ls.getTime());
+ pa.getSeries("RANDOM").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Karma
ls=new FlexScheduler(e, FlexScheduler.KARMA, null);
System.out.println("Karma Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("KARMA").addPoint(i, ls.getTime());
+ pa.getSeries("KARMA").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Karma
ls=new FlexScheduler(e, FlexScheduler.POLITE, null);
System.out.println("Polit Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("POLITE").addPoint(i, ls.getTime());
+ pa.getSeries("POLITE").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
//Karma
ls=new FlexScheduler(e, FlexScheduler.ERUPTION, null);
System.out.println("Eruption Abort="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
p.getSeries("ERUPTION").addPoint(i, ls.getTime());
+ pa.getSeries("ERUPTION").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
+
+
+ //Karma
+ ls=new FlexScheduler(e, FlexScheduler.THREAD, null);
+ ls.dosim();
+ System.out.println("ThreadPriority Abort="+ls.getTime());
+ System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+ p.getSeries("THPRIORITY").addPoint(i, ls.getTime());
+ pa.getSeries("THPRIORITY").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
+
+
+ //attack time
+ ls=new FlexScheduler(e, FlexScheduler.ATTACKTIME, null);
+ ls.dosim();
+ System.out.println("ThreadPriority Abort="+ls.getTime());
+ System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+ p.getSeries("ATTACKTIME").addPoint(i, ls.getTime());
+ pa.getSeries("ATTACKTIME").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
+
+
+ //attack thread
+ ls=new FlexScheduler(e, FlexScheduler.ATTACKTHREAD, null);
+ ls.dosim();
+ System.out.println("ThreadPriority Abort="+ls.getTime());
+ System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+ p.getSeries("ATTACKTHREAD").addPoint(i, ls.getTime());
+ pa.getSeries("ATTACKTHREAD").addPoint(i, 100.0*((double)ls.getAborts())/((double)(ls.getAborts()+ls.getCommits())));
// Scheduler s=new Scheduler(e, besttime);
//s.dosim();
//System.out.println("Optimal Time="+s.getTime());
}
p.close();
+ pa.close();
}
}
\ No newline at end of file