From: jzhou Date: Mon, 19 May 2008 22:45:02 +0000 (+0000) Subject: Add multi-parameter tasks support in Scheduling Simulator X-Git-Tag: preEdgeChange~84 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7fbe9cf2767b8be5994064d18ba53c7c7c20ed57;p=IRC.git Add multi-parameter tasks support in Scheduling Simulator --- diff --git a/Robust/src/Analysis/Scheduling/CoreSimulator.java b/Robust/src/Analysis/Scheduling/CoreSimulator.java index 9c4a56d9..e3f3f332 100644 --- a/Robust/src/Analysis/Scheduling/CoreSimulator.java +++ b/Robust/src/Analysis/Scheduling/CoreSimulator.java @@ -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> targetCSimulator; + Hashtable> allyCSimulator; Hashtable targetFState; int coreNum; int activeTime; @@ -63,11 +63,21 @@ public class CoreSimulator { return targetCSimulator.get(fstate); } - public void setTargetCSimulator( - Hashtable> targetCSimulator) { + public void setTargetCSimulator(Hashtable> targetCSimulator) { this.targetCSimulator = targetCSimulator; } + public Vector getAllyCores(FlagState fstate) { + if(allyCSimulator == null) { + return null; + } + return allyCSimulator.get(fstate); + } + + public void setAllyCSimulator(Hashtable> 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> 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(); } - transObjs.add(obj); + if(!transObjs.contains(obj)) { + transObjs.add(obj); + } remove = true; } + // check if this object becoming shared or not + Vector 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(); + } + 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); } diff --git a/Robust/src/Analysis/Scheduling/ObjectSimulator.java b/Robust/src/Analysis/Scheduling/ObjectSimulator.java index 08462a32..6c78c7f4 100644 --- a/Robust/src/Analysis/Scheduling/ObjectSimulator.java +++ b/Robust/src/Analysis/Scheduling/ObjectSimulator.java @@ -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 diff --git a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java index ac476561..bdb05a75 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java +++ b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java @@ -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()) { diff --git a/Robust/src/Analysis/Scheduling/ScheduleNode.java b/Robust/src/Analysis/Scheduling/ScheduleNode.java index f4f09dce..32c875c2 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleNode.java +++ b/Robust/src/Analysis/Scheduling/ScheduleNode.java @@ -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, diff --git a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java index 56882385..6a4ddf58 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java +++ b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java @@ -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> transObjQueues = new Hashtable>(); - 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 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 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> transObjQueues = new Hashtable>(); + 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 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 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()); + 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()); + } + Queue 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 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()); + } + Queue tmpqueue = transObjQueues.get(allyCore); + ObjectInfo nobjinfo = new ObjectInfo(nobj); + if(!tmpqueue.contains(nobjinfo)) { + tmpqueue.add(nobjinfo); + } + } } - Queue tmpqueue = transObjQueues.get(targetCore); - tmpqueue.add(nobj); } - // enqueue this core again - cores.add(targetCore); } } - } - cp.addAction(action); - Vector 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 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 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 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()); + 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()); + } + Queue tmpqueue = transObjQueues.get(targetCore); + tmpqueue.add(new ObjectInfo(tobj)); + } + } + // check if this object becoming shared or not + Vector 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()); + } + Queue tmpqueue = transObjQueues.get(allyCore); + ObjectInfo nobjinfo = new ObjectInfo(tobj); + if(!tmpqueue.contains(nobjinfo)) { + tmpqueue.add(nobjinfo); + } + } } - Queue tmpqueue = transObjQueues.get(targetCore); - tmpqueue.add(tobj); } } } - } - // add 'transport' tasks - Iterator it_entries = transObjQueues.entrySet().iterator(); - while(it_entries.hasNext()) { - Entry> tmpentry = (Entry>)it_entries.next(); - Integer tmpCoreNum = tmpentry.getKey(); - Queue 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> tmpentry = (Entry>)it_entries.next(); + Integer tmpCoreNum = tmpentry.getKey(); + Queue 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; diff --git a/Robust/src/Analysis/Scheduling/SchedulingUtil.java b/Robust/src/Analysis/Scheduling/SchedulingUtil.java index 7978f579..b9e561ed 100644 --- a/Robust/src/Analysis/Scheduling/SchedulingUtil.java +++ b/Robust/src/Analysis/Scheduling/SchedulingUtil.java @@ -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 keys = tmpTaskNodes.keys(); diff --git a/Robust/src/Analysis/Scheduling/TaskSimulator.java b/Robust/src/Analysis/Scheduling/TaskSimulator.java index c34b9583..4e502e84 100644 --- a/Robust/src/Analysis/Scheduling/TaskSimulator.java +++ b/Robust/src/Analysis/Scheduling/TaskSimulator.java @@ -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> paraQueues; + Hashtable objVersionTbl; ExeResult currentRun; CoreSimulator cs; boolean finish; @@ -23,6 +25,9 @@ public class TaskSimulator { public class ExeResult { int finishTime; Vector 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> getParaQueues() { return paraQueues; } + + public Hashtable 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>(); 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(), i); } - this.paraQueues.elementAt(i).add(obj); + if(this.objVersionTbl == null) { + this.objVersionTbl = new Hashtable(); + } + 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(), i); } this.paraQueues.elementAt(i).add(obj); + if(this.objVersionTbl == null) { + this.objVersionTbl = new Hashtable(); + } + 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) { diff --git a/Robust/src/Analysis/Scheduling/TransTaskSimulator.java b/Robust/src/Analysis/Scheduling/TransTaskSimulator.java index 767d24df..19bf74cb 100644 --- a/Robust/src/Analysis/Scheduling/TransTaskSimulator.java +++ b/Robust/src/Analysis/Scheduling/TransTaskSimulator.java @@ -4,9 +4,9 @@ import java.util.Queue; public class TransTaskSimulator extends TaskSimulator { private int targetCoreNum; - private Queue newObjs; + private Queue newObjs; - public TransTaskSimulator(CoreSimulator cs, int targetCoreNum, Queue nobjs) { + public TransTaskSimulator(CoreSimulator cs, int targetCoreNum, Queue nobjs) { super(null, cs); this.targetCoreNum = targetCoreNum; this.newObjs = nobjs; @@ -17,10 +17,10 @@ public class TransTaskSimulator extends TaskSimulator { this.currentRun = new ExeResult(); } - this.currentRun.finishTime = 1 * sizeof(this.newObjs.peek().getCd()); + this.currentRun.finishTime = 1 * sizeof(this.newObjs.peek().obj.getCd()); } - public ObjectSimulator refreshTask() { + public ObjectInfo refreshTask() { return this.newObjs.poll(); } diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 81c719c4..a46cca82 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -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 selectedScheduling = new Vector(); 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 scheduling = new Vector();