Add multi-parameter tasks support in Scheduling Simulator
authorjzhou <jzhou>
Mon, 19 May 2008 22:45:02 +0000 (22:45 +0000)
committerjzhou <jzhou>
Mon, 19 May 2008 22:45:02 +0000 (22:45 +0000)
Robust/src/Analysis/Scheduling/CoreSimulator.java
Robust/src/Analysis/Scheduling/ObjectSimulator.java
Robust/src/Analysis/Scheduling/ScheduleAnalysis.java
Robust/src/Analysis/Scheduling/ScheduleNode.java
Robust/src/Analysis/Scheduling/ScheduleSimulator.java
Robust/src/Analysis/Scheduling/SchedulingUtil.java
Robust/src/Analysis/Scheduling/TaskSimulator.java
Robust/src/Analysis/Scheduling/TransTaskSimulator.java
Robust/src/Main/Main.java

index 9c4a56d931767d8f2a3f644b61149e6366de0f54..e3f3f332a949ca83457ea3aa32d13848b3ad41c4 100644 (file)
@@ -5,7 +5,6 @@ import java.util.Queue;
 import java.util.Vector;
 
 import Analysis.TaskStateAnalysis.FlagState;
-import IR.ClassDescriptor;
 import IR.TaskDescriptor;
 
 public class CoreSimulator {
@@ -13,6 +12,7 @@ public class CoreSimulator {
     RuntimeSchedule rSchedule;
     TaskSimulator rtask;
     Hashtable<FlagState, Queue<Integer>> targetCSimulator;
+    Hashtable<FlagState, Vector<Integer>> allyCSimulator;
     Hashtable<FlagState, FlagState> targetFState;
     int coreNum;
     int activeTime;
@@ -63,11 +63,21 @@ public class CoreSimulator {
        return targetCSimulator.get(fstate);
     }
 
-    public void setTargetCSimulator(
-       Hashtable<FlagState, Queue<Integer>> targetCSimulator) {
+    public void setTargetCSimulator(Hashtable<FlagState, Queue<Integer>> targetCSimulator) {
         this.targetCSimulator = targetCSimulator;
     }
     
+    public Vector<Integer> getAllyCores(FlagState fstate) {
+       if(allyCSimulator == null) {
+           return null;
+       }
+       return allyCSimulator.get(fstate);
+    }
+
+    public void setAllyCSimulator(Hashtable<FlagState, Vector<Integer>> allyCSimulator) {
+        this.allyCSimulator = allyCSimulator;
+    }
+    
     public FlagState getTargetFState(FlagState fstate) {
        if(targetFState == null) {
            return null;
@@ -108,7 +118,16 @@ public class CoreSimulator {
            return;
        }
        for(int i = 0; i < this.tasks.size(); i++) {
-           this.tasks.elementAt(i).enquePara(newObj);
+           this.tasks.elementAt(i).enquePara(newObj, null, 0, true);
+       }
+    }
+    
+    public void addObject(ObjectSimulator newObj, FlagState fs, int version) {
+       if(this.tasks == null) {
+           return;
+       }
+       for(int i = 0; i < this.tasks.size(); i++) {
+           this.tasks.elementAt(i).enquePara(newObj, fs, version, false);
        }
     }
     
@@ -119,14 +138,36 @@ public class CoreSimulator {
        Vector<Queue<ObjectSimulator>> paraQueues = this.rtask.getParaQueues();
        for(int i = 0; i < paraQueues.size(); i++) {
            ObjectSimulator obj = paraQueues.elementAt(i).poll();
+           obj.setHold(false);
            boolean remove = false;
            if((this.targetFState != null) && (this.targetFState.containsKey(obj.getCurrentFS()))) {
                if(transObjs == null) {
                    transObjs = new Vector<ObjectSimulator>();
                }
-               transObjs.add(obj);
+               if(!transObjs.contains(obj)) {
+                   transObjs.add(obj);
+               }
                remove = true;
            }
+           // check if this object becoming shared or not
+           Vector<Integer> allycores = this.getAllyCores(obj.getCurrentFS());
+           if(allycores != null) {
+               obj.setShared(true);
+               for(int k = 0; k < allycores.size(); ++k) {
+                   Integer allyCore = allycores.elementAt(k);
+                   /*if(allyCore == coreNum) {
+                       remove = false;
+                   } else {*/
+                       if(transObjs == null) {
+                           transObjs = new Vector<ObjectSimulator>();
+                       }
+                       if(!transObjs.contains(obj)) {
+                           transObjs.add(obj);
+                       }
+                       remove = false; 
+                   //}
+               }
+           }
            for(int j = 0; j < this.tasks.size(); j++) {
                this.tasks.elementAt(j).refreshPara(obj, remove);
            }
index 08462a32bfa6737eed1e80dc1515aadb6a27deaf..6c78c7f4fabd7140de986ee7e8a599e7382214eb 100644 (file)
@@ -8,12 +8,18 @@ public class ObjectSimulator {
     ClassDescriptor cd;
     FlagState currentFS;
     boolean changed;
+    boolean shared;
+    boolean hold;
+    int version;
     
     public ObjectSimulator(ClassDescriptor cd, FlagState currentFS) {
        super();
        this.cd = cd;
        this.currentFS = currentFS;
        this.changed = true;
+       this.shared = false;
+       this.hold = false;
+       this.version = 0;
     }
     
     public void applyEdge(FEdge fedge) {
@@ -47,5 +53,28 @@ public class ObjectSimulator {
        changed = true;
         this.currentFS = currentFS;
     }
-    
+
+    public boolean isHold() {
+        return hold;
+    }
+
+    public void setHold(boolean hold) {
+        this.hold = hold;
+    }
+
+    public boolean isShared() {
+        return shared;
+    }
+
+    public void setShared(boolean shared) {
+        this.shared = shared;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void increaseVersion() {
+        this.version++;
+    }
 }
\ No newline at end of file
index ac476561225262b150af6c9c3397628b3f2b1a16..bdb05a75858f64c1b0d2f2bc9d092bb99c14b028 100644 (file)
@@ -443,9 +443,11 @@ public class ScheduleAnalysis {
                scheduleEdges.remove(se);
                // As se has been changed into an internal edge inside a ScheduleNode, 
                // change the source and target of se from original ScheduleNodes into ClassNodes.
-               se.setTarget(se.getTargetCNode());
-               se.setSource(se.getSourceCNode());
-               se.getTargetCNode().addEdge(se);
+               if(se.getType() == ScheduleEdge.NEWEDGE) {
+                   se.setTarget(se.getTargetCNode());
+                   se.setSource(se.getSourceCNode());
+                   se.getTargetCNode().addEdge(se);
+               }
            } else {
                // clone the whole ScheduleNode lists starting with se's target
                for(int j = 1; j < repeat; j++ ) {
@@ -786,9 +788,11 @@ public class ScheduleAnalysis {
                scheduleEdges.removeElement(se);
                // As se has been changed into an internal edge inside a ScheduleNode, 
                // change the source and target of se from original ScheduleNodes into ClassNodes.
-               se.setTarget(se.getTargetCNode());
-               se.setSource(se.getSourceCNode());
-               se.getTargetCNode().addEdge(se);
+               if(se.getType() == ScheduleEdge.NEWEDGE) {
+                   se.setTarget(se.getTargetCNode());
+                   se.setSource(se.getSourceCNode());
+                   se.getTargetCNode().addEdge(se);
+               }
            } else {
                handleScheduleEdge(se, true);
            }
@@ -984,10 +988,6 @@ public class ScheduleAnalysis {
                        }
                        break;
                    }
-                   /*case ScheduleEdge.ASSOCEDGE: {
-                       //TODO
-                       +
-                   }*/
                    }
                    tmpSchedule.addChildCores(targetcore);
                    if((targetcore.intValue() != j) && (!ancestorCores[targetcore.intValue()].contains((Integer.valueOf(j))))) {
@@ -1009,10 +1009,6 @@ public class ScheduleAnalysis {
                        tmpSchedule.addTargetCore(se.getFstate(), j, se.getTargetFState());
                        break;
                    }
-                   /*case ScheduleEdge.ASSOCEDGE: {
-                       //TODO
-                       +
-                   }*/
                    }
                }
                scheduling.add(tmpSchedule);
@@ -1091,11 +1087,6 @@ public class ScheduleAnalysis {
                se = new ScheduleEdge(ctarget, "transmit", sse.getFstate(), sse.getType(), gid);//new ScheduleEdge(ctarget, "transmit", sse.getClassDescriptor(), false, gid);
                break;
            }
-           /*case ScheduleEdge.ASSOCEDGE: {
-               //TODO
-               se = new ScheduleEdge(ctarget, "associate", sse.getFstate(), sse.getType(), gid);//new ScheduleEdge(ctarget, "transmit", sse.getClassDescriptor(), false, gid);
-               break;
-           }*/
            }
            se.setSourceCNode(sourcecn2cn.get(sse.getSourceCNode()));
            se.setTargetCNode(targetcn2cn.get(sse.getTargetCNode()));
@@ -1134,10 +1125,6 @@ public class ScheduleAnalysis {
                }
                break;
            }
-           /*case ScheduleEdge.ASSOCEDGE: {
-               // TODO
-               +
-           }*/
            }
            result.removeElement(sEdge.getTarget());
            if(ScheduleEdge.NEWEDGE == sEdge.getType()) {
index f4f09dce81b06bef5f6874f8df9206c6b348b205..32c875c26feac8f4ef32a7673d12e92f45755cb8 100644 (file)
@@ -310,12 +310,6 @@ public class ScheduleNode extends GraphNode implements Cloneable{
        if(ScheduleEdge.TRANSEDGE == se.getType()) {
            sn.removeInedge(se);
            this.removeEdge(se);
-           Iterator it_edges = sn.edges();
-           while(it_edges.hasNext()) {
-               ScheduleEdge tse = (ScheduleEdge)it_edges.next();
-               tse.setSource(this);
-               this.edges.addElement(tse);
-           }
 
            // merge the split ClassNode of same class
            FlagState sfs = se.getFstate();
@@ -357,6 +351,18 @@ public class ScheduleNode extends GraphNode implements Cloneable{
                }
            }
            
+           // redirect external ScheduleEdges to this ScheduleNode
+           // and scn if it is originally from tcn
+           Iterator it_edges = sn.edges();
+           while(it_edges.hasNext()) {
+               ScheduleEdge tse = (ScheduleEdge)it_edges.next();
+               tse.setSource(this);
+               if(tse.getSourceCNode().equals(tcn)) {
+               tse.setSourceCNode(scn);
+               }
+               this.edges.addElement(tse);
+           }
+           
            targetSEdges = null;
            
            // As all tasks inside one ScheduleNode are executed sequentially,
index 56882385fa2901e5174d697f71042f02b6ebfb89..6a4ddf5806718efc642a07b02355cdc8e1f8b45e 100644 (file)
@@ -117,6 +117,7 @@ public class ScheduleSimulator {
             CoreSimulator cs = this.cores.elementAt(temp.getCoreNum());
             cs.deployTasks(temp.getTasks());
             cs.setTargetCSimulator(temp.getTargetCoreTable());
+            cs.setAllyCSimulator(temp.getAllyCoreTable());
             cs.setTargetFState(temp.getTargetFStateTable());
         }
         // inject a Startup Object to each core
@@ -204,8 +205,11 @@ public class ScheduleSimulator {
                    TransTaskSimulator tmptask = (TransTaskSimulator)task;
                    // add ADDOBJ task to targetCore
                    int targetCoreNum = tmptask.getTargetCoreNum();
-                   ObjectSimulator nobj = tmptask.refreshTask();
-                   this.cores.elementAt(targetCoreNum).addObject(nobj);
+                   ObjectInfo objinfo = tmptask.refreshTask();
+                   ObjectSimulator nobj = objinfo.obj;
+                   FlagState fs = objinfo.fs;
+                   int version = objinfo.version;
+                   this.cores.elementAt(targetCoreNum).addObject(nobj, fs, version);
                    action = new Action(targetCoreNum, Action.ADDOBJ, 1, nobj.getCd());
                    cp.addAction(action);
                    if(!tmptask.isFinished()) {
@@ -225,81 +229,131 @@ public class ScheduleSimulator {
                } else {
                    CoreSimulator cs = task.getCs();
                    int coreNum = cs.getCoreNum();
-                   Hashtable<Integer, Queue<ObjectSimulator>> transObjQueues = new Hashtable<Integer, Queue<ObjectSimulator>>();
-                   if(task.getCurrentRun().getNewObjs() == null) {
-                       action = new Action(coreNum, Action.TASKFINISH);
-                       action.setTd(cs.getRtask().getTd());
-                   } else {
-                       action = new Action(coreNum, Action.TFWITHOBJ);
-                       action.setTd(cs.getRtask().getTd());
-                       Vector<ObjectSimulator> nobjs = task.getCurrentRun().getNewObjs();
-                       //Schedule schedule = this.scheduling.elementAt(coreNum);
-                       for(int j = 0; j < nobjs.size(); j++) {
-                           ObjectSimulator nobj = nobjs.elementAt(j);
-                           action.addNewObj(nobj.getCd(), Integer.valueOf(1));
-                           // send the new object to target core according to pre-decide scheduling
-                           Queue<Integer> cores = cs.getTargetCores(nobj.getCurrentFS());
-                           if(cores == null) {
-                               // this obj will reside on this core
-                               cs.addObject(nobj);
-                           } else {
-                               Integer targetCore = cores.poll();
-                               if(targetCore == coreNum) {
+                   if(task.getCurrentRun().getExetype() == 0) {
+                       Hashtable<Integer, Queue<ObjectInfo>> transObjQueues = new Hashtable<Integer, Queue<ObjectInfo>>();
+                       if(task.getCurrentRun().getNewObjs() == null) {
+                           action = new Action(coreNum, Action.TASKFINISH);
+                           action.setTd(cs.getRtask().getTd());
+                       } else {
+                           action = new Action(coreNum, Action.TFWITHOBJ);
+                           action.setTd(cs.getRtask().getTd());
+                           Vector<ObjectSimulator> nobjs = task.getCurrentRun().getNewObjs();
+                           //Schedule schedule = this.scheduling.elementAt(coreNum);
+                           for(int j = 0; j < nobjs.size(); j++) {
+                               ObjectSimulator nobj = nobjs.elementAt(j);
+                               action.addNewObj(nobj.getCd(), Integer.valueOf(1));
+                               // send the new object to target core according to pre-decide scheduling
+                               Queue<Integer> cores = cs.getTargetCores(nobj.getCurrentFS());
+                               if(cores == null) {
                                    // this obj will reside on this core
                                    cs.addObject(nobj);
                                } else {
-                                   if(!transObjQueues.containsKey(targetCore)) {
-                                       transObjQueues.put(targetCore, new LinkedList<ObjectSimulator>());
+                                   Integer targetCore = cores.poll();
+                                   if(targetCore == coreNum) {
+                                       // this obj will reside on this core
+                                       cs.addObject(nobj);
+                                   } else {
+                                       if(!transObjQueues.containsKey(targetCore)) {
+                                           transObjQueues.put(targetCore, new LinkedList<ObjectInfo>());
+                                       }
+                                       Queue<ObjectInfo> tmpqueue = transObjQueues.get(targetCore);
+                                       tmpqueue.add(new ObjectInfo(nobj));
+                                   }
+                                   // enqueue this core again
+                                   cores.add(targetCore);
+                               }
+                               // check if this object becoming shared or not
+                               Vector<Integer> allycores = cs.getAllyCores(nobj.getCurrentFS());
+                               if(allycores != null) {
+                                   nobj.setShared(true);
+                                   for(int k = 0; k < allycores.size(); ++k) {
+                                       Integer allyCore = allycores.elementAt(k);
+                                       if(allyCore == coreNum) {
+                                           cs.addObject(nobj);
+                                       } else {
+                                           if(!transObjQueues.containsKey(allyCore)) {
+                                               transObjQueues.put(allyCore, new LinkedList<ObjectInfo>());
+                                           }
+                                           Queue<ObjectInfo> tmpqueue = transObjQueues.get(allyCore);
+                                           ObjectInfo nobjinfo = new ObjectInfo(nobj);
+                                           if(!tmpqueue.contains(nobjinfo)) {
+                                               tmpqueue.add(nobjinfo);
+                                           }
+                                       }
                                    }
-                                   Queue<ObjectSimulator> tmpqueue = transObjQueues.get(targetCore);
-                                   tmpqueue.add(nobj);
                                }
-                               // enqueue this core again
-                               cores.add(targetCore);
                            }
                        }
-                   }
-                   cp.addAction(action);
-                   Vector<ObjectSimulator> transObjs = cs.finishTask();
-                   if(transObjs != null) {
-                       for(int j = 0; j < transObjs.size(); j++) {
-                           ObjectSimulator tobj = transObjs.elementAt(j);
-                           // send the object to target core according to pre-decide scheduling
-                           Queue<Integer> cores = cs.getTargetCores(tobj.getCurrentFS());
-                           tobj.setCurrentFS(cs.getTargetFState(tobj.getCurrentFS()));
-                           if(cores == null) {
-                               // this obj will reside on this core
-                               cs.addObject(tobj);
-                           } else {
-                               Integer targetCore = cores.peek();
-                               if(targetCore == coreNum) {
+                       cp.addAction(action);
+                       Vector<ObjectSimulator> transObjs = cs.finishTask();
+                       if(transObjs != null) {
+                           for(int j = 0; j < transObjs.size(); j++) {
+                               ObjectSimulator tobj = transObjs.elementAt(j);
+                               // send the object to target core according to pre-decide scheduling
+                               Queue<Integer> cores = cs.getTargetCores(tobj.getCurrentFS());
+                               tobj.setCurrentFS(cs.getTargetFState(tobj.getCurrentFS()));
+                               if(cores == null) {
                                    // this obj will reside on this core
                                    cs.addObject(tobj);
                                } else {
-                                   if(!transObjQueues.containsKey(targetCore)) {
-                                       transObjQueues.put(targetCore, new LinkedList<ObjectSimulator>());
+                                   Integer targetCore = cores.peek();
+                                   if(targetCore == coreNum) {
+                                       // this obj will reside on this core
+                                       cs.addObject(tobj);
+                                   } else {
+                                       if(!transObjQueues.containsKey(targetCore)) {
+                                           transObjQueues.put(targetCore, new LinkedList<ObjectInfo>());
+                                       }
+                                       Queue<ObjectInfo> tmpqueue = transObjQueues.get(targetCore);
+                                       tmpqueue.add(new ObjectInfo(tobj));
+                                   }
+                               }
+                               // check if this object becoming shared or not
+                               Vector<Integer> allycores = cs.getAllyCores(tobj.getCurrentFS());
+                               if(allycores != null) {
+                                   tobj.setShared(true);
+                                   for(int k = 0; k < allycores.size(); ++k) {
+                                       Integer allyCore = allycores.elementAt(k);
+                                       if(allyCore == coreNum) {
+                                           cs.addObject(tobj);
+                                       } else {
+                                           if(!transObjQueues.containsKey(allyCore)) {
+                                               transObjQueues.put(allyCore, new LinkedList<ObjectInfo>());
+                                           }
+                                           Queue<ObjectInfo> tmpqueue = transObjQueues.get(allyCore);
+                                           ObjectInfo nobjinfo = new ObjectInfo(tobj);
+                                           if(!tmpqueue.contains(nobjinfo)) {
+                                               tmpqueue.add(nobjinfo);
+                                           }
+                                       }
                                    }
-                                   Queue<ObjectSimulator> tmpqueue = transObjQueues.get(targetCore);
-                                   tmpqueue.add(tobj);
                                }
                            }
                        }
-                   }
-                   // add 'transport' tasks
-                   Iterator it_entries = transObjQueues.entrySet().iterator();
-                   while(it_entries.hasNext()) {
-                       Entry<Integer, Queue<ObjectSimulator>> tmpentry = (Entry<Integer, Queue<ObjectSimulator>>)it_entries.next();
-                       Integer tmpCoreNum = tmpentry.getKey();
-                       Queue<ObjectSimulator> nobjs = tmpentry.getValue();
-                       TransTaskSimulator tmptask = new TransTaskSimulator(cs, tmpCoreNum, nobjs);
-                       this.tasks.add(tmptask);
-                   }
-                   // Choose a new task for this core
-                   TaskSimulator newTask = cs.process();
-                   if(newTask != null) {
-                       this.tasks.add(newTask);
-                       // add a TASKSTART action into this checkpoint
-                       action = new Action(coreNum, Action.TASKSTART);
+                       // add 'transport' tasks
+                       Iterator it_entries = transObjQueues.entrySet().iterator();
+                       while(it_entries.hasNext()) {
+                           Entry<Integer, Queue<ObjectInfo>> tmpentry = (Entry<Integer, Queue<ObjectInfo>>)it_entries.next();
+                           Integer tmpCoreNum = tmpentry.getKey();
+                           Queue<ObjectInfo> nobjs = tmpentry.getValue();
+                           TransTaskSimulator tmptask = new TransTaskSimulator(cs, tmpCoreNum, nobjs);
+                           this.tasks.add(tmptask);
+                       }
+                       // Choose a new task for this core
+                       TaskSimulator newTask = cs.process();
+                       if(newTask != null) {
+                           this.tasks.add(newTask);
+                           // add a TASKSTART action into this checkpoint
+                           action = new Action(coreNum, Action.TASKSTART);
+                           action.setTd(cs.getRtask().getTd());
+                           cp.addAction(action);
+                       }
+                   } else if (task.getCurrentRun().getExetype() == 1) {
+                       action = new Action(coreNum, Action.TASKABORT);
+                       action.setTd(cs.getRtask().getTd());
+                       cp.addAction(action);
+                   } else if (task.getCurrentRun().getExetype() == 2) {
+                       action = new Action(coreNum, Action.TASKREMOVE);
                        action.setTd(cs.getRtask().getTd());
                        cp.addAction(action);
                    }
@@ -347,6 +401,8 @@ public class ScheduleSimulator {
        public static final int TASKFINISH = 1;
        public static final int TFWITHOBJ = 2;
        public static final int TASKSTART = 3;
+       public static final int TASKABORT = 4;
+       public static final int TASKREMOVE = 5;
        
        private int coreNum;
        private int type;
index 7978f579377b1723bcf10621510402f840a68d11..b9e561ed35e6c6f08dfccca074f840195d7cb9ee 100644 (file)
@@ -423,6 +423,38 @@ public class SchedulingUtil {
                        isTaskFinish[cNum] = false;
                        break;
                    }
+                   case Action.TASKABORT: {
+                       if(!isfirst) {
+                           tmpLabel.append("\\n");
+                       }
+                       tmpLabel.append("<" + taction.getTd().getSymbol() + ">aborts;");
+                       if(!(lastTaskNodes[cNum].equals("first")) &&
+                               !(lastTaskNodes[cNum].equals(tmpTaskNode))) {
+                           output.print("\t");
+                           output.println(lastTaskNodes[cNum] + "->" + tmpTaskNode);
+                           lastTaskNodes[cNum] = tmpTaskNode;
+                           isTaskFinish[cNum] = true;
+                       } else {
+                           throw new Exception("Error: unexpected task aborts");
+                       }
+                       break;
+                   }
+                   case Action.TASKREMOVE: {
+                       if(!isfirst) {
+                           tmpLabel.append("\\n");
+                       }
+                       tmpLabel.append("<" + taction.getTd().getSymbol() + ">removes;");
+                       if(!(lastTaskNodes[cNum].equals("first")) &&
+                               !(lastTaskNodes[cNum].equals(tmpTaskNode))) {
+                           output.print("\t");
+                           output.println(lastTaskNodes[cNum] + "->" + tmpTaskNode);
+                           lastTaskNodes[cNum] = tmpTaskNode;
+                           isTaskFinish[cNum] = true;
+                       } else {
+                           throw new Exception("Error: unexpected task remove");
+                       }
+                       break;
+                   }
                    }
                }
                Enumeration<String> keys = tmpTaskNodes.keys();
index c34b9583e52230b89b78975fd6912e131874c07a..4e502e843e933b807271702cff4fa7b0d3080d36 100644 (file)
@@ -1,5 +1,6 @@
 package Analysis.Scheduling;
 
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Queue;
@@ -16,6 +17,7 @@ import IR.Tree.FlagExpressionNode;
 public class TaskSimulator {
     TaskDescriptor td;
     Vector<Queue<ObjectSimulator>> paraQueues;
+    Hashtable<ObjectSimulator, Integer> objVersionTbl;
     ExeResult currentRun;
     CoreSimulator cs;
     boolean finish;
@@ -23,6 +25,9 @@ public class TaskSimulator {
     public class ExeResult {
        int finishTime;
        Vector<ObjectSimulator> newObjs;
+       int exetype; // 0--normal executing
+                    // 1--abort due to fail on grabbing locks
+                    // 2--out of date task
        
        public ExeResult() {
            finishTime = 0;
@@ -48,13 +53,21 @@ public class TaskSimulator {
            
            this.newObjs.add(newObj);
        }
-       
+
+       public int getExetype() {
+           return exetype;
+       }
+
+       public void setExetype(int exetype) {
+           this.exetype = exetype;
+       }
     }
     
     public TaskSimulator(TaskDescriptor td, CoreSimulator cs) {
        super();
        this.td = td;
        this.paraQueues = null;
+       this.objVersionTbl = null;
        this.currentRun = null;
        this.cs = cs;
        this.finish = true;
@@ -75,8 +88,16 @@ public class TaskSimulator {
     public Vector<Queue<ObjectSimulator>> getParaQueues() {
         return paraQueues;
     }
+    
+    public Hashtable<ObjectSimulator, Integer> getObjVersionTbl() {
+        return objVersionTbl;
+    }
+    
+    public int getObjVersion(ObjectSimulator os) {
+       return this.objVersionTbl.get(os).intValue();
+    }
 
-    public void enquePara(ObjectSimulator obj) {
+    public void enquePara(ObjectSimulator obj, FlagState fs, int version, boolean inherent) {
        ClassDescriptor cd = obj.getCd();
        int paraNum = td.numParameters();
        for(int i = 0; i < paraNum; i++) {
@@ -84,7 +105,11 @@ public class TaskSimulator {
            if(cd.equals(para.getType().getClassDesc())) {
                // check if the status is right
                FlagExpressionNode fen = td.getFlag(para);
-               if(SchedulingUtil.isTaskTrigger_flag(fen, obj.getCurrentFS())) {
+               FlagState cfs = fs;
+               if(inherent) {
+                   cfs = obj.getCurrentFS();
+               }
+               if(SchedulingUtil.isTaskTrigger_flag(fen, cfs)) {
                    if(this.paraQueues == null) {
                        this.paraQueues = new Vector<Queue<ObjectSimulator>>();
                        for(int j = 0; j < paraNum; j++) {
@@ -94,7 +119,17 @@ public class TaskSimulator {
                    if(this.paraQueues.elementAt(i) == null) {
                        this.paraQueues.setElementAt(new LinkedList<ObjectSimulator>(), i);
                    }
-                   this.paraQueues.elementAt(i).add(obj);
+                   if(this.objVersionTbl == null) {
+                       this.objVersionTbl = new Hashtable<ObjectSimulator, Integer>();
+                   }
+                   if(!this.paraQueues.elementAt(i).contains(obj)) {
+                       this.paraQueues.elementAt(i).add(obj);
+                       if(inherent) {
+                           this.objVersionTbl.put(obj, obj.getVersion());
+                       } else {
+                           this.objVersionTbl.put(obj, version);
+                       }
+                   }
                }
            }
        }
@@ -109,8 +144,9 @@ public class TaskSimulator {
                if(remove) {
                    if((this.paraQueues != null) &&
                            (this.paraQueues.elementAt(i) != null)  && 
-                           (this.paraQueues.elementAt(i).contains(obj))){
+                           (this.paraQueues.elementAt(i).contains(obj))) {
                        this.paraQueues.elementAt(i).remove(obj);
+                       this.objVersionTbl.remove(obj);
                    }
                } else {
                    // check if the status is right
@@ -126,11 +162,16 @@ public class TaskSimulator {
                            this.paraQueues.setElementAt(new LinkedList<ObjectSimulator>(), i);
                        }
                        this.paraQueues.elementAt(i).add(obj);
+                       if(this.objVersionTbl == null) {
+                           this.objVersionTbl = new Hashtable<ObjectSimulator, Integer>();
+                       }
+                       this.objVersionTbl.put(obj, obj.getVersion());
                    } else {
                        if((this.paraQueues != null) &&
                                (this.paraQueues.elementAt(i) != null)  && 
                                (this.paraQueues.elementAt(i).contains(obj))){
                            this.paraQueues.elementAt(i).remove(obj);
+                           this.objVersionTbl.remove(obj);
                        }
                    }
                }
@@ -155,12 +196,57 @@ public class TaskSimulator {
        //    1.the result, i.e. the result FlagState reached by each parameter.
        //    2.the finish time
        //    3.any new objects
+       
+       // First check if all the parameters are still available.
+       // For shared objects, need to first grab the lock and also check if the version is right
        for(int i = 0; i < paraQueues.size(); i++) {
            ObjectSimulator tpara = paraQueues.elementAt(i).peek();
+           if(tpara.isShared()) {
+               if(tpara.isHold()) {
+                   // shared object held by other tasks
+                   finishTime = 1; // TODO currenly assume the effort on requesting locks are only 1
+                   this.currentRun.setFinishTime(finishTime);
+                   this.currentRun.setExetype(1);
+                   paraQueues.elementAt(i).poll();
+                   paraQueues.elementAt(i).add(tpara);
+                   for(int j = 0; j < i; ++j) {
+                       tpara = this.paraQueues.elementAt(j).poll();
+                       if(tpara.isShared() && tpara.isHold()) {
+                           tpara.setHold(false);
+                       }
+                       this.paraQueues.elementAt(j).add(tpara);
+                   }
+                   return;
+               } else if (tpara.getVersion() != this.objVersionTbl.get(tpara)) {
+                   // shared object has been updated and no longer fitted to this task
+                   finishTime = 1; // TODO currenly assume the effort on requesting locks are only 1
+                   this.currentRun.setFinishTime(finishTime);
+                   this.currentRun.setExetype(2);
+                   paraQueues.elementAt(i).poll();
+                   // remove this object from the remaining parameter queues
+                   for(int j = i + 1; j < paraQueues.size(); j++) {
+                       paraQueues.elementAt(j).remove(tpara);
+                   }
+                   for(int j = 0; j < i; ++j) {
+                       tpara = this.paraQueues.elementAt(j).poll();
+                       if(tpara.isShared() && tpara.isHold()) {
+                           tpara.setHold(false);
+                       }
+                       this.paraQueues.elementAt(j).add(tpara);
+                   }
+                   return;
+               } else {
+                   tpara.setHold(true);
+               }
+           }
            // remove this object from the remaining parameter queues
            for(int j = i + 1; j < paraQueues.size(); j++) {
                paraQueues.elementAt(j).remove(tpara);
            }
+       }
+       for(int i = 0; i < paraQueues.size(); i++) {
+           ObjectSimulator tpara = paraQueues.elementAt(i).peek();
+           
            FlagState tfstate = tpara.getCurrentFS();
            FEdge toexecute = tfstate.process(td);
            finishTime += toexecute.getExeTime();
@@ -183,9 +269,11 @@ public class TaskSimulator {
            //FlagState tFState = (FlagState)toexecute.getTarget();
            //tpara.setCurrentFS(tFState);
            tpara.applyEdge(toexecute);
+           tpara.increaseVersion();
        }
        finishTime /= paraQueues.size();
        this.currentRun.setFinishTime(finishTime);
+       this.currentRun.setExetype(0);
     }
     
     public void updateFinishTime(int time) {
index 767d24df17d24748d0c189f956049c71d107bd84..19bf74cb5c54b828fd365bc82fb77c2842aaa467 100644 (file)
@@ -4,9 +4,9 @@ import java.util.Queue;
 \r
 public class TransTaskSimulator extends TaskSimulator {\r
     private int targetCoreNum;\r
-    private Queue<ObjectSimulator> newObjs;\r
+    private Queue<ObjectInfo> newObjs;\r
 \r
-    public TransTaskSimulator(CoreSimulator cs, int targetCoreNum, Queue<ObjectSimulator> nobjs) {\r
+    public TransTaskSimulator(CoreSimulator cs, int targetCoreNum, Queue<ObjectInfo> nobjs) {\r
        super(null, cs);\r
        this.targetCoreNum = targetCoreNum;\r
        this.newObjs = nobjs;\r
@@ -17,10 +17,10 @@ public class TransTaskSimulator extends TaskSimulator {
            this.currentRun = new ExeResult();\r
        }\r
 \r
-       this.currentRun.finishTime = 1 * sizeof(this.newObjs.peek().getCd());\r
+       this.currentRun.finishTime = 1 * sizeof(this.newObjs.peek().obj.getCd());\r
     }\r
     \r
-    public ObjectSimulator refreshTask() {\r
+    public ObjectInfo refreshTask() {\r
        return this.newObjs.poll();\r
     }\r
     \r
index 81c719c4ae36c72df4643751dd00127d0c772ba2..a46cca8253f35ac80d147011014c73325ee38ee4 100644 (file)
@@ -338,9 +338,9 @@ public class Main {
              scheduleAnalysis.schedule();
              
              //simulate these schedulings
-             //ScheduleSimulator scheduleSimulator = new ScheduleSimulator(scheduleAnalysis.getCoreNum(), state, ta);
+             ScheduleSimulator scheduleSimulator = new ScheduleSimulator(scheduleAnalysis.getCoreNum(), state, ta);
              Iterator it_scheduling = scheduleAnalysis.getSchedulingsIter();
-             /*int index = 0;
+             int index = 0;
              Vector<Integer> selectedScheduling = new Vector<Integer>();
              int processTime = Integer.MAX_VALUE;
              while(it_scheduling.hasNext()) {
@@ -360,7 +360,7 @@ public class Main {
              for(int i = 0; i < selectedScheduling.size(); i++) {
                  System.out.print(selectedScheduling.elementAt(i) + ", ");
              }
-             System.out.println();*/
+             System.out.println();
              
              /*ScheduleSimulator scheduleSimulator = new ScheduleSimulator(4, state, ta);
              Vector<Schedule> scheduling = new Vector<Schedule>();