public class FileSim {
- public static void main(String[] args) throws Exception {
- //time between transactions
- //split objects
- int splitobjects=100;//10 percent of objects special
- int splitaccesses=100;//40 percent of accesses to special objects
- int abortThreshold=0; //need 4 aborts to declare risky
- int abortRatio=0;//need 40% aborts vs commits to declare risky
- int deadlockdepth=10;
-
- String filename=args[0];
- Executor e=new Executor(filename);
- System.out.println(e.maxTime());
+ public static void p1(Executor e) throws Exception {
FlexScheduler ls=new FlexScheduler(e, FlexScheduler.LAZY, null);
ls.start();
FlexScheduler ls4=new FlexScheduler(e, FlexScheduler.COMMIT, null);
ls4.start();
- //Eager attack
FlexScheduler ls5=new FlexScheduler(e, FlexScheduler.ATTACK, null);
ls5.start();
- //Eager polite
- FlexScheduler ls6=new FlexScheduler(e, FlexScheduler.SUICIDE, null);
- ls6.start();
-
- //Karma
- FlexScheduler ls7=new FlexScheduler(e, FlexScheduler.TIMESTAMP, null);
- ls7.start();
-
- //Random
- FlexScheduler ls8=new FlexScheduler(e, FlexScheduler.RANDOM, null);
- ls8.start();
-
- //Random
- FlexScheduler ls9=new FlexScheduler(e, FlexScheduler.KARMA, null);
- ls9.start();
-
- //Random
- FlexScheduler ls10=new FlexScheduler(e, FlexScheduler.POLITE, null);
- ls10.start();
-
- //Random
- FlexScheduler ls11=new FlexScheduler(e, FlexScheduler.ERUPTION, null);
- ls11.start();
-
ls.join();
System.out.println("Lazy Time="+ls.getTime());
System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+ ls=null;
ls4.join();
System.out.println("Fast Abort="+ls4.getTime());
System.out.println("Aborts="+ls4.getAborts()+" Commit="+ls4.getCommits());
+ ls4=null;
ls5.join();
System.out.println("Attack Abort="+ls5.getTime());
System.out.println("Aborts="+ls5.getAborts()+" Commit="+ls5.getCommits());
+ ls5=null;
+ }
+
+ public static void p2(Executor e) throws Exception {
+ FlexScheduler ls6=new FlexScheduler(e, FlexScheduler.SUICIDE, null);
+ ls6.start();
+
+ FlexScheduler ls7=new FlexScheduler(e, FlexScheduler.TIMESTAMP, null);
+ ls7.start();
+
+ FlexScheduler ls8=new FlexScheduler(e, FlexScheduler.RANDOM, null);
+ ls8.start();
+
ls6.join();
System.out.println("Suicide Abort="+ls6.getTime());
System.out.println("Aborts="+ls6.getAborts()+" Commit="+ls6.getCommits());
+ ls6=null;
ls7.join();
System.out.println("Timestamp Abort="+ls7.getTime());
System.out.println("Aborts="+ls7.getAborts()+" Commit="+ls7.getCommits());
+ ls7=null;
ls8.join();
System.out.println("Random Abort="+ls8.getTime());
System.out.println("Aborts="+ls8.getAborts()+" Commit="+ls8.getCommits());
+ ls8=null;
+ }
+
+ public static void p3(Executor e) throws Exception {
+ FlexScheduler ls9=new FlexScheduler(e, FlexScheduler.KARMA, null);
+ ls9.start();
+
+ FlexScheduler ls10=new FlexScheduler(e, FlexScheduler.POLITE, null);
+ ls10.start();
+
+ FlexScheduler ls11=new FlexScheduler(e, FlexScheduler.ERUPTION, null);
+ ls11.start();
+
+
ls9.join();
System.out.println("Karma Abort="+ls9.getTime());
System.out.println("Aborts="+ls9.getAborts()+" Commit="+ls9.getCommits());
+ ls9=null;
ls10.join();
System.out.println("Polite Abort="+ls10.getTime());
System.out.println("Aborts="+ls10.getAborts()+" Commit="+ls10.getCommits());
+ ls10=null;
ls11.join();
System.out.println("Eruption Abort="+ls11.getTime());
System.out.println("Aborts="+ls11.getAborts()+" Commit="+ls11.getCommits());
}
+
+ public static void main(String[] args) throws Exception {
+ //time between transactions
+ //split objects
+ int splitobjects=100;//10 percent of objects special
+ int splitaccesses=100;//40 percent of accesses to special objects
+ int abortThreshold=0; //need 4 aborts to declare risky
+ int abortRatio=0;//need 40% aborts vs commits to declare risky
+ int deadlockdepth=10;
+
+ String filename=args[0];
+ Executor e=new Executor(filename);
+ System.out.println(e.maxTime());
+ if (args.length==1||args[1].equals("1"))
+ p1(e);
+ if (args.length==1||args[1].equals("2"))
+ p2(e);
+ if (args.length==1||args[1].equals("3"))
+ p3(e);
+ }
}
\ No newline at end of file
eq=new PriorityQueue();
backoff=new int[e.numThreads()];
retrycount=new int[e.numThreads()];
+ transferred=new int[e.numThreads()];
objtoinfo=new Hashtable();
threadinfo=new ThreadInfo[e.numThreads()];
blocked=new boolean[e.numThreads()];
Random r;
int[] backoff;
int[] retrycount;
+ int[] transferred;
Hashtable objtoinfo;
ThreadInfo[] threadinfo;
boolean[] blocked;
public boolean isEager() {
- return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE;
+ return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE||policy==ERUPTION;
}
public boolean countObjects() {
tryCommit(ev, trans);
tcount++;
if ((tcount%100000)==0)
- System.out.println("Attempted "+tcount+"transactions");
+ System.out.println("Attempted "+tcount+"transactions "+policy);
} else {
enqueueEvent(ev, trans);
}
boolean abort=aborted[ev.getThread()];
aborted[ev.getThread()]=false;
if (!abort) {
- //if it is a transaction, increment comit count
+ //if it is a transaction, increment commit count
if (trans.numEvents()>1||trans.getEvent(0)!=Transaction.DELAY) {
- threadinfo[ev.getThread()].priority=0;
commitcount++;
if (serCommit!=null) {
serCommit.addPoint(ev.getTime(),ev.getThread());
}
}
//Reset our backoff counter
+ threadinfo[ev.getThread()].priority=0;
backoff[ev.getThread()]=BACKOFFSTART;
retrycount[ev.getThread()]=0;
+ transferred[ev.getThread()]=0;
//abort the other threads
for(int i=0;i<trans.numEvents();i++) {
boolean b=r.nextBoolean();
if (b) {
//delay
- stall(ev, time+r.nextInt(200));
+ int thread=ev.getThread();
+ int dback=backoff[thread]*2;
+ if (dback>0)
+ backoff[thread]=dback;
+ stall(ev, time+r.nextInt(backoff[thread]));
return false;
} else {
//abort other transactions
}
} else if (policy==KARMA) {
int maxpriority=0;
- //abort other transactions
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
if (threadinfo[thread].priority>maxpriority)
maxpriority=threadinfo[thread].priority;
}
- if (maxpriority>threadinfo[ev.getThread()].priority) {
- //we lose
- threadinfo[ev.getThread()].priority++;
+ if (maxpriority>(threadinfo[ev.getThread()].priority+retrycount[ev.getThread()])) {
//stall for a little while
- stall(ev, time+20);
+ threadinfo[ev.getThread()].priority--;
+ retrycount[ev.getThread()]++;
+ stall(ev, time+r.nextInt(3000));
return false;
} else {
//we win
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
- reschedule(thread, time);
+ int dback=backoff[thread]*2;
+ if (dback>0)
+ backoff[thread]=dback;
+ reschedule(thread, time+r.nextInt(backoff[thread]));
abortcount++;
}
return true;
if (threadinfo[thread].priority>maxpriority)
maxpriority=threadinfo[thread].priority;
}
- if (maxpriority>threadinfo[ev.getThread()].priority) {
+ if (maxpriority>(threadinfo[ev.getThread()].priority+retrycount[ev.getThread()])) {
//we lose
+ threadinfo[ev.getThread()].priority--;
//stall for a little while
- stall(ev, time);
+ stall(ev, time+r.nextInt(3000));
int ourpriority=threadinfo[ev.getThread()].priority;
+ ourpriority-=transferred[ev.getThread()];
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
- threadinfo[thread].priority+=ourpriority;;
+ threadinfo[thread].priority+=ourpriority;
}
+ transferred[ev.getThread()]=threadinfo[ev.getThread()].priority;
+ retrycount[ev.getThread()]++;
+
return false;
} else {
//we win
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
- reschedule(thread, time);
+ int dback=backoff[thread]*2;
+ if (dback>0)
+ backoff[thread]=dback;
+ reschedule(thread, time+r.nextInt(backoff[thread]));
abortcount++;
}
return true;
}
} else if (policy==POLITE) {
- int retry=retrycount[ev.getThread()]++;
- if (retry==22) {
+ int retry=(++retrycount[ev.getThread()]);
+ if (retry>=22) {
+ retrycount[ev.getThread()]=0;
for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
Integer thread=(Integer)thit.next();
reschedule(thread, time);
- int dback=backoff[thread.intValue()]*2;
- if (dback>0)
- backoff[thread.intValue()]=dback;
abortcount++;
}
return true;
} else {
//otherwise stall
- stall(ev, time+r.nextInt((1<<retry)*12));
+ int stalltime=(1<<(retry-1))*12;
+ if (stalltime<0)
+ stalltime=1<<30;
+ stall(ev, time+r.nextInt(stalltime));
return false;
}
} else if (policy==ATTACK) {
//do eager contention management
Set conflicts=rdConflictSet(ev.getThread(), object);
if (conflicts!=null) {
- if (!handleConflicts(ev, conflicts, currtime))
+ if (!handleConflicts(ev, conflicts, currtime)) {
+ ((Set)rdobjmap.get(object)).remove(new Integer(ev.getThread()));
return;
+ }
}
}
} else if (operation==Transaction.WRITE) {
if (isEager()) {
Set conflicts=wrConflictSet(ev.getThread(), object);
if (conflicts!=null) {
- if (!handleConflicts(ev, conflicts, currtime))
+ if (!handleConflicts(ev, conflicts, currtime)) {
+ ((Set)wrobjmap.get(object)).remove(new Integer(ev.getThread()));
return;
+ }
}
}
} else if (operation==Transaction.BARRIER) {
}
return;
}
-
+ retrycount[ev.getThread()]=0;
+ transferred[ev.getThread()]=0;
//enqueue the next event
long deltatime=trans.getTime(event+1)-trans.getTime(event);
Event nev=new Event(deltatime+currtime, trans, event+1, ev.getThread(), ev.getTransNum());