From: bdemsky <bdemsky> Date: Wed, 6 Jan 2010 03:12:17 +0000 (+0000) Subject: updates to simulator X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=be0a3efad2942dc6543a37b05cdd07b8ca53971f;p=IRC.git updates to simulator --- diff --git a/Robust/TransSim/Executor.java b/Robust/TransSim/Executor.java index 4c65b400..e8a74959 100644 --- a/Robust/TransSim/Executor.java +++ b/Robust/TransSim/Executor.java @@ -36,14 +36,14 @@ public class Executor { public static int readInt(InputStream is) { try { - int b1=is.read(); - int b2=is.read(); - int b3=is.read(); - int b4=is.read(); - int retval=(b1<<24)|(b2<<16)|(b3<<8)|b4; - if (retval<0) - throw new Error(); - return retval; + int b1=is.read(); + int b2=is.read(); + int b3=is.read(); + int b4=is.read(); + int retval=(b4<<24)|(b3<<16)|(b2<<8)|b1; + if (retval<0) + throw new Error(); + return retval; } catch (Exception e) { throw new Error(); } @@ -59,8 +59,8 @@ public class Executor { long b6=is.read(); long b7=is.read(); long b8=is.read(); - long retval=(b1<<56)|(b2<<48)|(b3<<40)|(b4<<32)| - (b5<<24)|(b6<<16)|(b7<<8)|b8; + long retval=(b8<<56)|(b7<<48)|(b6<<40)|(b5<<32)| + (b4<<24)|(b3<<16)|(b2<<8)|b1; if (retval<0) throw new Error(); return retval; @@ -80,6 +80,7 @@ public class Executor { threads=new ThreadClass[numThreads]; long earliest=-1; for(int i=0;i<numThreads;i++) { + System.out.println("Loading thread "+i+" of "+numThreads); threads[i]=readThread(bir); long inittime=threads[i].trans[0].getTime(0); if (earliest==-1||earliest>inittime) { @@ -104,8 +105,8 @@ public class Executor { public static final int EV_ARRAYWRITE=8; public static final int EV_EXITBARRIER=9; - private Transaction createTransaction(Vector<TEvent> v) { - Transaction t=new Transaction(v.size()); + private Transaction createTransaction(Vector<TEvent> v, boolean started) { + Transaction t=new Transaction(v.size(),started); for(int i=0;i<v.size();i++) { TEvent e=v.get(i); t.setTime(i,e.time); @@ -118,6 +119,9 @@ public class Executor { private ThreadClass readThread(InputStream is) { int numEvents=readInt(is); + long low=-1; + long high=-1; + boolean started=false; Vector<Transaction> transactions=new Vector<Transaction>(); Vector<TEvent> currtrans=null; long starttime=-1; @@ -130,33 +134,40 @@ public class Executor { switch(eventType) { case EV_READ: case EV_WRITE: - object=readInt(is); + object=readInt(is);i++; break; case EV_ARRAYREAD: case EV_ARRAYWRITE: - object=readInt(is); - index=readInt(is); + object=readInt(is);i++; + index=readInt(is);i++; break; default: break; } - long time=readLong(is); + long time=readLong(is);i+=2; + if (low==-1||time<low) + low=time; + if (high==-1||time>high) + high=time; //create dummy first transaction if (firsttime==-1) { - Transaction t=new Transaction(1); + Transaction t=new Transaction(1,started); + t.setEvent(0, Transaction.DELAY); t.setTime(0, time); t.setObject(0, -1); t.setIndex(0, -1); transactions.add(t); firsttime=time; + lasttime=time; } //have read all data in switch(eventType) { case EV_START: starttime=time; currtrans=new Vector<TEvent>(); - if (lasttime!=-1) { - Transaction t=new Transaction(1); + started=true; + if (lasttime!=-1&&lasttime!=time) { + Transaction t=new Transaction(1,started); t.setEvent(0, Transaction.DELAY); t.setTime(0, time-lasttime); t.setObject(0, -1); @@ -183,7 +194,7 @@ public class Executor { TEvent ev=new TEvent(Transaction.DELAY, delta); currtrans.add(ev); lasttime=time; - transactions.add(createTransaction(currtrans)); + transactions.add(createTransaction(currtrans, started)); } break; case EV_ABORT: @@ -195,15 +206,15 @@ public class Executor { break; case EV_ENTERBARRIER: { //Barrier + Transaction t=new Transaction(1, started); + t.setEvent(0, Transaction.BARRIER); if (lasttime!=-1) { - Transaction t=new Transaction(1); - t.setEvent(0, Transaction.DELAY); t.setTime(0, time-lasttime); - t.setObject(0, -1); - t.setIndex(0, -1); - transactions.add(t); } - transactions.add(Transaction.getBarrier()); + t.setObject(0, -1); + t.setIndex(0, -1); + transactions.add(t); + lasttime=time; } break; case EV_EXITBARRIER: { @@ -217,6 +228,7 @@ public class Executor { for(int i=0;i<transactions.size();i++) { tc.setTransaction(i,transactions.get(i)); } + System.out.println(low+" "+high); return tc; } @@ -240,13 +252,17 @@ public class Executor { generateThreads(); } - public int maxTime() { - int maxtime=0; + public long maxTime() { + long maxtime=0; for(int i=0;i<numThreads;i++) { - int time=0; + long time=0; + boolean started=false; for(int j=0;j<getThread(i).numTransactions();j++) { Transaction trans=getThread(i).getTransaction(j); - time+=trans.getTime(trans.numEvents()-1); + if (trans.started) + started=true; + if (started) + time+=trans.getTime(trans.numEvents()-1); } if (time>maxtime) maxtime=time; @@ -295,7 +311,7 @@ public class Executor { private Transaction generateTransaction() { int accesses=getRandom(numAccesses, deltaAccesses); - Transaction t=new Transaction(accesses); + Transaction t=new Transaction(accesses,true); int time=0; int splitpoint=(numObjects*splitobjects)/100; for(int i=0;i<(accesses-1); i++) { @@ -335,7 +351,7 @@ public class Executor { for(int i=0;i<numTransactions;i++) { Transaction trans=generateTransaction(); t.setTransaction(i*2, trans); - Transaction transdelay=new Transaction(1); + Transaction transdelay=new Transaction(1,true); transdelay.setObject(0,Transaction.DELAY); transdelay.setEvent(0,Transaction.DELAY); transdelay.setTime(0, getRandom(nonTrans, deltaNonTrans)); diff --git a/Robust/TransSim/FileSim.java b/Robust/TransSim/FileSim.java new file mode 100644 index 00000000..4f42f551 --- /dev/null +++ b/Robust/TransSim/FileSim.java @@ -0,0 +1,80 @@ +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()); + FlexScheduler ls=new FlexScheduler(e, FlexScheduler.LAZY, null); + ls.start(); + + + + //Kill others at commit + 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.POLITE, null); + ls6.start(); + + + //Karma + FlexScheduler ls7=new FlexScheduler(e, FlexScheduler.KARMA, null); + ls7.start(); + + + ls.join(); + System.out.println("Lazy Time="+ls.getTime()); + System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits()); + + ls4.join(); + System.out.println("Fast Abort="+ls4.getTime()); + System.out.println("Aborts="+ls4.getAborts()+" Commit="+ls4.getCommits()); + + ls5.join(); + System.out.println("Attack Abort="+ls5.getTime()); + System.out.println("Aborts="+ls5.getAborts()+" Commit="+ls5.getCommits()); + + ls6.join(); + System.out.println("Polite Abort="+ls6.getTime()); + System.out.println("Aborts="+ls6.getAborts()+" Commit="+ls6.getCommits()); + + ls7.join(); + System.out.println("Karma Abort="+ls7.getTime()); + System.out.println("Aborts="+ls7.getAborts()+" Commit="+ls7.getCommits()); + ls=null;ls4=null;ls5=null;ls6=null;ls7=null; + + { + //Lock object accesses + FlexScheduler ls2=new FlexScheduler(e, FlexScheduler.LOCK, abortThreshold, abortRatio, deadlockdepth, null); + ls2.start(); + ls2.join(); + System.out.println("Deadlock count="+ls2.getDeadLockCount()); + System.out.println("Lock Abort="+ls2.getTime()); + System.out.println("Aborts="+ls2.getAborts()+" Commit="+ls2.getCommits()); + ls2=null; + } + { + //Lock Commit object accesses + FlexScheduler ls3=new FlexScheduler(e, FlexScheduler.LOCKCOMMIT, abortThreshold, abortRatio, deadlockdepth, null); + ls3.start(); + ls3.join(); + System.out.println("Deadlock count="+ls3.getDeadLockCount()); + System.out.println("LockCommit Abort="+ls3.getTime()); + System.out.println("Aborts="+ls3.getAborts()+" Commit="+ls3.getCommits()); + } + } +} \ No newline at end of file diff --git a/Robust/TransSim/FlexScheduler.java b/Robust/TransSim/FlexScheduler.java index 7690569e..eb7c81e9 100644 --- a/Robust/TransSim/FlexScheduler.java +++ b/Robust/TransSim/FlexScheduler.java @@ -1,6 +1,6 @@ import java.util.*; -public class FlexScheduler { +public class FlexScheduler extends Thread { Executor e; int abortThreshold; int abortRatio; @@ -15,6 +15,10 @@ public class FlexScheduler { this.checkdepth=checkdepth; } + public void run() { + dosim(); + } + public FlexScheduler(Executor e, int policy, Plot p) { this.e=e; barriercount=e.numThreads(); @@ -73,6 +77,7 @@ public class FlexScheduler { int policy; boolean[] aborted; long shorttesttime; + long starttime=-1; Hashtable rdobjmap; Hashtable wrobjmap; int abortcount; @@ -102,7 +107,7 @@ public class FlexScheduler { } public long getTime() { - return shorttesttime; + return shorttesttime-starttime; } //Aborts another thread... @@ -159,21 +164,26 @@ public class FlexScheduler { } } - public void startinitial() { + /* Initializes things and returns number of transactions */ + public int startinitial() { + int tcount=0; for(int i=0;i<e.numThreads();i++) { Transaction trans=e.getThread(i).getTransaction(0); long time=trans.getTime(0); Event ev=new Event(time, trans, 0, i, 0); currentevents[i]=ev; eq.add(ev); + tcount+=e.getThread(i).numTransactions(); } + return tcount; } public void dosim() { long lasttime=0; //start first transactions - startinitial(); - + int numtrans=startinitial(); + System.out.println("Number of transactions="+numtrans); + int tcount=0; while(!eq.isEmpty()) { Event ev=(Event)eq.poll(); if (!ev.isValid()) { @@ -181,12 +191,18 @@ public class FlexScheduler { } Transaction trans=ev.getTransaction(); + int event=ev.getEvent(); long currtime=ev.getTime(); lasttime=currtime; + if (trans.started&&starttime==-1) + starttime=currtime; if (trans.numEvents()==(event+1)) { tryCommit(ev, trans); + tcount++; + if ((tcount%100000)==0) + System.out.println("Attempted "+tcount+"transactions"); } else { enqueueEvent(ev, trans); } @@ -227,6 +243,9 @@ public class FlexScheduler { int op=trans.getEvent(i); //Mark commits to objects if (isLock()&&(op==Transaction.WRITE||op==Transaction.READ)) { + if (object==null) { + System.out.println(op); + } getmapping(object).recordCommit(); } //Check for threads we might cause to abort @@ -333,13 +352,17 @@ public class FlexScheduler { for(Iterator thit=threadstokill.iterator();thit.hasNext();) { Integer thread=(Integer)thit.next(); reschedule(thread, time+r.nextInt(backoff[thread.intValue()])); - backoff[thread.intValue()]*=2; + int dback=backoff[thread.intValue()]*2; + if (dback>0) + backoff[thread.intValue()]=dback; abortcount++; } return true; } else if (policy==POLITE) { reschedule(ev.getThread(), time+r.nextInt(backoff[ev.getThread()])); - backoff[ev.getThread()]*=2; + int dback=backoff[ev.getThread()]*2; + if (dback>0) + backoff[ev.getThread()]=dback; abortcount++; return false; } else if (policy==KARMA) { diff --git a/Robust/TransSim/TEvent.java b/Robust/TransSim/TEvent.java index fec70a98..545bc98b 100644 --- a/Robust/TransSim/TEvent.java +++ b/Robust/TransSim/TEvent.java @@ -1,24 +1,24 @@ public class TEvent { - public int type; + public byte type; public int index; public int oid; public long time; - public TEvent(int type, long time) { + public TEvent(byte type, long time) { this.time=time; this.type=type; this.oid=-1; this.index=-1; } - public TEvent(int type, long time, int oid) { + public TEvent(byte type, long time, int oid) { this.time=time; this.type=type; this.oid=oid; this.index=-1; } - public TEvent(int type, long time, int oid, int index) { + public TEvent(byte type, long time, int oid, int index) { this.time=time; this.type=type; this.oid=oid; diff --git a/Robust/TransSim/Transaction.java b/Robust/TransSim/Transaction.java index 9e352f73..92648b75 100644 --- a/Robust/TransSim/Transaction.java +++ b/Robust/TransSim/Transaction.java @@ -1,8 +1,10 @@ public class Transaction { - int[] events; + byte[] events; int[] objects; int[] indices; - long[] times; + int[] times; + long[] alttimes; + boolean started; public String toString() { String s=""; @@ -18,34 +20,32 @@ public class Transaction { return s; } - public static final int READ=0; - public static final int WRITE=1; - public static final int BARRIER=2; - public static final int DELAY=-1; + public static final byte READ=0; + public static final byte WRITE=1; + public static final byte BARRIER=2; + public static final byte DELAY=-1; - public static Transaction getBarrier() { - Transaction t=new Transaction(1); - t.setEvent(0, BARRIER); - return t; - } - - public Transaction(int size) { - events=new int[size]; + public Transaction(int size,boolean started) { + events=new byte[size]; objects=new int[size]; indices=new int[size]; - times=new long[size]; + times=new int[size]; + this.started=started; } public int numEvents() { return events.length; } - public int getEvent(int index) { + public byte getEvent(int index) { return events[index]; } public long getTime(int index) { - return times[index]; + if (times!=null) + return times[index]; + else + return alttimes[index]; } public int getObject(int index) { @@ -63,12 +63,25 @@ public class Transaction { return new ObjIndex(obj, indices[index]); } - public void setEvent(int index, int val) { + public void setEvent(int index, byte val) { events[index]=val; } public void setTime(int index, long val) { - times[index]=val; + if (times==null) { + alttimes[index]=val; + } else { + int v=(int)val; + if (v==val) { + times[index]=v; + } else { + alttimes=new long[times.length]; + for(int i=0;i<times.length;i++) + alttimes[i]=times[i]; + times=null; + alttimes[index]=val; + } + } } public void setObject(int index, int val) {