From be0a3efad2942dc6543a37b05cdd07b8ca53971f Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 6 Jan 2010 03:12:17 +0000 Subject: [PATCH] updates to simulator --- Robust/TransSim/Executor.java | 80 ++++++++++++++++++------------ Robust/TransSim/FileSim.java | 80 ++++++++++++++++++++++++++++++ Robust/TransSim/FlexScheduler.java | 37 +++++++++++--- Robust/TransSim/TEvent.java | 8 +-- Robust/TransSim/Transaction.java | 51 ++++++++++++------- 5 files changed, 194 insertions(+), 62 deletions(-) create mode 100644 Robust/TransSim/FileSim.java 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;iinittime) { @@ -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 v) { - Transaction t=new Transaction(v.size()); + private Transaction createTransaction(Vector v, boolean started) { + Transaction t=new Transaction(v.size(),started); for(int i=0;i transactions=new Vector(); Vector 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||timehigh) + 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(); - 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;imaxtime) 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;i0) + 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