From: jzhou Date: Tue, 15 Jul 2008 21:40:15 +0000 (+0000) Subject: make multicore version PERT benchmark work on RAW(without interruption) X-Git-Tag: preEdgeChange~67 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4a9f8ad0f03a075a27f19abf1c01ffcdff53e34f;p=IRC.git make multicore version PERT benchmark work on RAW(without interruption) --- diff --git a/Robust/src/Analysis/Scheduling/CoreSimulator.java b/Robust/src/Analysis/Scheduling/CoreSimulator.java index e3f3f332..cc1763e4 100644 --- a/Robust/src/Analysis/Scheduling/CoreSimulator.java +++ b/Robust/src/Analysis/Scheduling/CoreSimulator.java @@ -80,7 +80,7 @@ public class CoreSimulator { public FlagState getTargetFState(FlagState fstate) { if(targetFState == null) { - return null; + return fstate; } return targetFState.get(fstate); } @@ -155,17 +155,13 @@ public class CoreSimulator { 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; - //} + if(transObjs == null) { + transObjs = new Vector(); + } + if(!transObjs.contains(obj)) { + transObjs.add(obj); + } + remove = false; } } for(int j = 0; j < this.tasks.size(); j++) { diff --git a/Robust/src/Analysis/Scheduling/ObjectSimulator.java b/Robust/src/Analysis/Scheduling/ObjectSimulator.java index 6c78c7f4..4c92e296 100644 --- a/Robust/src/Analysis/Scheduling/ObjectSimulator.java +++ b/Robust/src/Analysis/Scheduling/ObjectSimulator.java @@ -44,12 +44,6 @@ public class ObjectSimulator { } public void setCurrentFS(FlagState currentFS) { - /*if(!this.currentFS.equals(currentFS)) { - changed = true; - this.currentFS = currentFS; - } else { - changed = false; - }*/ changed = true; this.currentFS = currentFS; } diff --git a/Robust/src/Analysis/Scheduling/Schedule.java b/Robust/src/Analysis/Scheduling/Schedule.java index 246fb2ab..a04c629b 100644 --- a/Robust/src/Analysis/Scheduling/Schedule.java +++ b/Robust/src/Analysis/Scheduling/Schedule.java @@ -14,9 +14,7 @@ public class Schedule { private int coreNum; private Vector tasks; private Hashtable> targetCores; - private Hashtable targetFState; - private Vector ancestorCores; - private Vector childCores; + private Hashtable targetFState; // only affected by transimit edges private Hashtable> allyCores; private Hashtable> td2fs; @@ -26,7 +24,6 @@ public class Schedule { this.tasks = null; this.targetCores = null; this.targetFState = null; - this.ancestorCores = null; this.allyCores = null; this.td2fs = null; } @@ -79,17 +76,15 @@ public class Schedule { return this.td2fs.get(td); } - public void addTargetCore(FlagState fstate, Integer targetCore/*, Integer num*/) { + public void addTargetCore(FlagState fstate, Integer targetCore) { if(this.targetCores == null) { this.targetCores = new Hashtable>(); } if(!this.targetCores.containsKey(fstate)) { this.targetCores.put(fstate, new LinkedList()); } - //if(!this.targetCores.get(fstate).contains(targetCore)) { - this.targetCores.get(fstate).add(targetCore); // there may have some duplicate items, - // which reflects probabilities. - //} + this.targetCores.get(fstate).add(targetCore); // there may have some duplicate items, + // which reflects probabilities. } public void addTargetCore(FlagState fstate, Integer targetCore, FlagState tfstate) { @@ -99,18 +94,14 @@ public class Schedule { if(!this.targetCores.containsKey(fstate)) { this.targetCores.put(fstate, new LinkedList()); } - //if(!this.targetCores.get(fstate).contains(targetCore)) { - this.targetCores.get(fstate).add(targetCore); - //} + this.targetCores.get(fstate).add(targetCore); if(this.targetFState == null) { this.targetFState = new Hashtable(); } - //if(!this.targetFState.containsKey(fstate)) { - this.targetFState.put(fstate, tfstate); - //} + this.targetFState.put(fstate, tfstate); } - public void addAllyCore(FlagState fstate, Integer targetCore/*, Integer num*/) { + public void addAllyCore(FlagState fstate, Integer targetCore) { if(this.allyCores == null) { this.allyCores = new Hashtable>(); } @@ -119,7 +110,7 @@ public class Schedule { } if((this.coreNum != targetCore.intValue()) && (!this.allyCores.get(fstate).contains(targetCore))) { this.allyCores.get(fstate).add(targetCore); // there may have some duplicate items, - // which reflects probabilities. + // which reflects probabilities. } } @@ -146,54 +137,5 @@ public class Schedule { if(!this.tasks.contains(task)) { this.tasks.add(task); } - } - - public Vector getAncestorCores() { - return ancestorCores; - } - - public void setAncestorCores(Vector ancestorCores) { - this.ancestorCores = ancestorCores; - } - - public void addAncestorCores(Integer ancestorCore) { - if(this.ancestorCores == null) { - this.ancestorCores = new Vector(); - } - if((ancestorCore.intValue() != this.coreNum) && (!this.ancestorCores.contains(ancestorCore))) { - this.ancestorCores.addElement(ancestorCore); - } - } - - public int ancestorCoresNum() { - if(this.ancestorCores == null) { - return 0; - } - return this.ancestorCores.size(); - } - - public Vector getChildCores() { - return childCores; - } - - public void setChildCores(Vector childCores) { - this.childCores = childCores; - } - - public void addChildCores(Integer childCore) { - if(this.childCores == null) { - this.childCores = new Vector(); - } - if((childCore.intValue() != this.coreNum) && (!this.childCores.contains(childCore))) { - this.childCores.addElement(childCore); - } - } - - public int childCoresNum() { - if(this.childCores == null) { - return 0; - } - return this.childCores.size(); - } - + } } \ No newline at end of file diff --git a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java index bdb05a75..a48cd871 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java +++ b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java @@ -160,43 +160,6 @@ public class ScheduleAnalysis { } } cdToCNodes = null; - - // Create 'associate' edges between the ScheduleNodes. - /*Iterator it_tasks = (Iterator)state.getTaskSymbolTable().getDescriptorsIterator(); - while(it_tasks.hasNext()) { - TaskDescriptor td = it_tasks.next(); - int numParams = td.numParameters(); - if(!(numParams > 1)) { - // single parameter task - continue; - } - ClassNode[] cNodes = new ClassNode[numParams]; - for(i = 0; i < numParams; ++i) { - cNodes[i] = this.cd2ClassNode.get(td.getParamType(i).getClassDesc()); - } - Vector fev = (Vector)taskanalysis.getFEdgesFromTD(td); - // for each fedge associated to this td, create an associate ScheduleEdge - // from the ClassNode containg this FEdge to every other ClassNode representing - // other parameters. - for(i = 0; i < fev.size(); ++i) { - FEdge tmpfe = fev.elementAt(i); - for(int j = 0; j < numParams; ++j) { - if(j == tmpfe.getIndex()) { - continue; - } - FlagState fs = (FlagState)tmpfe.getSource(); - ScheduleEdge se = new ScheduleEdge(cNodes[j].getScheduleNode(), "associate", fs, ScheduleEdge.ASSOCEDGE, 0); - se.setFEdge(tmpfe); - se.setSourceCNode(cNodes[i]); - se.setTargetCNode(cNodes[j]); - // targetFState is always null - cNodes[i].getScheduleNode().addAssociateSEdge(se); - // scheduleEdges only holds new/transmit edges - //scheduleEdges.add(se); - fs.addAlly(se); - } - } - }*/ // Break down the 'cycle's try { @@ -211,9 +174,6 @@ public class ScheduleAnalysis { // Remove fake 'new' edges for(i = 0; i < scheduleEdges.size(); i++) { - /*if(ScheduleEdge.NEWEDGE != scheduleEdges.elementAt(i).getType()) { - continue; - }*/ ScheduleEdge se = (ScheduleEdge)scheduleEdges.elementAt(i); if((0 == se.getNewRate()) || (0 == se.getProbability())) { scheduleEdges.removeElement(se); @@ -487,12 +447,6 @@ public class ScheduleAnalysis { se.setNewRate(tse.getNewRate()); break; } - /*case ScheduleEdge.ASSOCEDGE: { - se = new ScheduleEdge(csNode, "associate", tse.getFstate(), tse.getType(), 0); - se.setProbability(tse.getProbability()); - se.setNewRate(tse.getNewRate()); - break; - }*/ default: { throw new Exception("Error: not valid ScheduleEdge here"); } @@ -506,37 +460,11 @@ public class ScheduleAnalysis { scheduleEdges.add(se); } inedges = null; - - // in associate ScheduleEdgs - /*inedges = ((ScheduleNode)sEdge.getTarget()).getInAssociateSEdges(); - for(i = 0; i < inedges.size(); i++) { - ScheduleEdge tse = (ScheduleEdge)inedges.elementAt(i); - ScheduleEdge se; - switch(tse.getType()) { - case ScheduleEdge.ASSOCEDGE: { - se = new ScheduleEdge(csNode, "associate", tse.getFstate(), tse.getType(), 0); - se.setProbability(tse.getProbability()); - se.setNewRate(tse.getNewRate()); - break; - } - default: { - throw new Exception("Error: not valid ScheduleEdge here"); - } - } - se.setSourceCNode(tse.getSourceCNode()); - se.setTargetCNode(cn2cn.get(tse.getTargetCNode())); - se.setFEdge(tse.getFEdge()); - se.setTargetFState(tse.getTargetFState()); - se.setIsclone(true); - ((ScheduleNode)tse.getSource()).addAssociateSEdge(se); - } - inedges = null;*/ } else { sEdge.getTarget().removeInedge(sEdge); sEdge.setTarget(csNode); csNode.getInedgeVector().add(sEdge); sEdge.setTargetCNode(cn2cn.get(sEdge.getTargetCNode())); - //sEdge.setTargetFState(null); sEdge.setIsclone(true); } @@ -576,10 +504,6 @@ public class ScheduleAnalysis { se = new ScheduleEdge(tSNode, "transmit", tse.getFstate(), tse.getType(), 0); break; } - /*case ScheduleEdge.ASSOCEDGE: { - se = new ScheduleEdge(tSNode, "associate", tse.getFstate(), tse.getType(), 0); - break; - }*/ default: { throw new Exception("Error: not valid ScheduleEdge here"); } @@ -597,32 +521,6 @@ public class ScheduleAnalysis { tocn2cn = null; edges = null; } - - // associate ScheduleEdges - /*for(int j = 0; j < origins.size(); ++j) { - ScheduleNode osNode = origins.elementAt(i); - Vector edges = osNode.getAssociateSEdges(); - ScheduleNode csNode = sn2sn.get(osNode); - for(i = 0; i < edges.size(); i++) { - ScheduleEdge tse = (ScheduleEdge)edges.elementAt(i); - assert(tse.getType() == ScheduleEdge.ASSOCEDGE); - ScheduleNode tSNode = (ScheduleNode)tse.getTarget(); - if(origins.contains(tSNode)) { - tSNode = sn2sn.get(tSNode); - } - ScheduleEdge se = new ScheduleEdge(tSNode, "associate", tse.getFstate(), tse.getType(), 0); - se.setSourceCNode(cn2cn.get(tse.getSourceCNode())); - se.setTargetCNode(tocn2cn.get(tse.getTargetCNode())); - se.setFEdge(tse.getFEdge()); - se.setTargetFState(tse.getTargetFState()); - se.setProbability(tse.getProbability()); - se.setNewRate(tse.getNewRate()); - se.setIsclone(true); - csNode.addAssociateSEdge(se); - } - tocn2cn = null; - edges = null; - }*/ toClone = null; clone = null; @@ -642,13 +540,6 @@ public class ScheduleAnalysis { throw new Exception("Error: ClassNode's inedges more than one!"); } if(inedges.size() > 0) { - /*ScheduleEdge sEdge = null; - for(int i = 0; i < inedges.size(); ++i) { - sEdge = (ScheduleEdge)inedges.elementAt(i); - if(sEdge.getType() == ScheduleEdge.NEWEDGE) { - break; - } - }*/ ScheduleEdge sEdge = (ScheduleEdge)inedges.elementAt(0); cNode = (ClassNode)sEdge.getSource(); exeTime += cNode.getFlagStates().elementAt(0).getExeTime(); @@ -913,11 +804,6 @@ public class ScheduleAnalysis { int startupcore = 0; boolean setstartupcore = false; Schedule startup = null; - Vector leafcores = new Vector(); - Vector[] ancestorCores = new Vector[this.coreNum]; - for(j = 0; j < ancestorCores.length; ++j) { - ancestorCores[j] = new Vector(); - } for(j = 0; j < scheduleGraph.size(); j++) { Schedule tmpSchedule = new Schedule(j); ScheduleNode sn = scheduleGraph.elementAt(j); @@ -931,14 +817,16 @@ public class ScheduleAnalysis { while(it_edges.hasNext()) { TaskDescriptor td = ((FEdge)it_edges.next()).getTask(); tmpSchedule.addTask(td); + if(!td2cores.containsKey(td)) { + td2cores.put(td, new Vector()); + } + Vector tmpcores = td2cores.get(td); + if(!tmpcores.contains(tmpSchedule)) { + tmpcores.add(tmpSchedule); + } + // if the FlagState can be fed to some multi-param tasks, + // need to record corresponding ally cores later if(td.numParameters() > 1) { - if(!td2cores.containsKey(td)) { - td2cores.put(td, new Vector()); - } - Vector tmpcores = td2cores.get(td); - if(!tmpcores.contains(tmpSchedule)) { - tmpcores.add(tmpSchedule); - } tmpSchedule.addFState4TD(td, fs); } if(td.getParamType(0).getClassDesc().getSymbol().equals(TypeUtil.StartupClass)) { @@ -953,12 +841,6 @@ public class ScheduleAnalysis { // For each of the ScheduleEdge out of this ScheduleNode, add the target ScheduleNode into the queue inside sn Iterator it_edges = sn.edges(); - if(!it_edges.hasNext()) { - // leaf core, considered as ancestor of startup core - if(!leafcores.contains(Integer.valueOf(j))) { - leafcores.addElement(Integer.valueOf(j)); - } - } while(it_edges.hasNext()) { ScheduleEdge se = (ScheduleEdge)it_edges.next(); ScheduleNode target = (ScheduleNode)se.getTarget(); @@ -989,10 +871,6 @@ public class ScheduleAnalysis { break; } } - tmpSchedule.addChildCores(targetcore); - if((targetcore.intValue() != j) && (!ancestorCores[targetcore.intValue()].contains((Integer.valueOf(j))))) { - ancestorCores[targetcore.intValue()].addElement(Integer.valueOf(j)); - } } it_edges = sn.getScheduleEdgesIterator(); while(it_edges.hasNext()) { @@ -1013,33 +891,56 @@ public class ScheduleAnalysis { } scheduling.add(tmpSchedule); } - - leafcores.removeElement(Integer.valueOf(startupcore)); - ancestorCores[startupcore] = leafcores; + int number = this.coreNum; if(scheduling.size() < number) { number = scheduling.size(); } - for(j = 0; j < number; ++j) { - scheduling.elementAt(j).setAncestorCores(ancestorCores[j]); - } // set up all the associate ally cores - if(multiparamtds.size() > 0) { - Object[] tds = (td2cores.keySet().toArray()); - for(j = 0; j < tds.length; ++j) { - TaskDescriptor td = (TaskDescriptor)tds[j]; + if(multiparamtds.size() > 0) { + for(j = 0; j < multiparamtds.size(); ++j) { + TaskDescriptor td = multiparamtds.elementAt(j); + Vector fes = (Vector)this.taskanalysis.getFEdgesFromTD(td); Vector cores = td2cores.get(td); - if(cores.size() == 1) { - continue; - } for(int k = 0; k < cores.size(); ++k) { Schedule tmpSchedule = cores.elementAt(k); - Vector tmpfss = tmpSchedule.getFStates4TD(td); - for(int h = 0; h < tmpfss.size(); ++h) { - for(int l = 0; l < cores.size(); ++l) { - if(l != k) { - tmpSchedule.addAllyCore(tmpfss.elementAt(h), cores.elementAt(l).getCoreNum()); + + for(int h = 0; h < fes.size(); ++h) { + FEdge tmpfe = fes.elementAt(h); + FlagState tmpfs = (FlagState)tmpfe.getTarget(); + Vector tmptds = new Vector(); + if((tmpSchedule.getTargetCoreTable() == null) || (!tmpSchedule.getTargetCoreTable().contains(tmpfs))) { + // add up all possible cores' info + Iterator it_edges = tmpfs.edges(); + while(it_edges.hasNext()) { + TaskDescriptor tmptd = ((FEdge)it_edges.next()).getTask(); + if(!tmptds.contains(tmptd)) { + tmptds.add(tmptd); + Vector tmpcores = td2cores.get(tmptd); + for(int m = 0; m < tmpcores.size(); ++m) { + if(m != tmpSchedule.getCoreNum()) { + // if the FlagState can be fed to some multi-param tasks, + // need to record corresponding ally cores later + if(tmptd.numParameters() > 1) { + tmpSchedule.addAllyCore(tmpfs, tmpcores.elementAt(m).getCoreNum()); + } else { + tmpSchedule.addTargetCore(tmpfs, tmpcores.elementAt(m).getCoreNum()); + } + } + } + } + } + } + } + + if(cores.size() > 1) { + Vector tmpfss = tmpSchedule.getFStates4TD(td); + for(int h = 0; h < tmpfss.size(); ++h) { + for(int l = 0; l < cores.size(); ++l) { + if(l != k) { + tmpSchedule.addAllyCore(tmpfss.elementAt(h), cores.elementAt(l).getCoreNum()); + } } } } diff --git a/Robust/src/Analysis/Scheduling/ScheduleEdge.java b/Robust/src/Analysis/Scheduling/ScheduleEdge.java index 6797079e..1c4a52b3 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleEdge.java +++ b/Robust/src/Analysis/Scheduling/ScheduleEdge.java @@ -11,7 +11,6 @@ public class ScheduleEdge extends Edge { public final static int NEWEDGE = 0; public final static int TRANSEDGE = 1; - public final static int ASSOCEDGE = 2; protected int uid; protected int gid; @@ -21,9 +20,8 @@ public class ScheduleEdge extends Edge { protected final FlagState fstate; protected int type; // 0--new edge: indicate creating new objects // 1--transmit edge: indicate transimitting an existing object - // 2-- associate edge: indicate association with another object in that they are both parameters of one task - - protected FlagState targetFState; // associate edge's targetFState is always null + + protected FlagState targetFState; private ClassNode sourceCNode; private ClassNode targetCNode; @@ -132,7 +130,6 @@ public class ScheduleEdge extends Edge { public void setTargetCNode(ClassNode targetCNode) { this.targetCNode = targetCNode; - //this.targetCNode.getInedgeVector().addElement(this); this.transTime = targetCNode.getTransTime(); } diff --git a/Robust/src/Analysis/Scheduling/ScheduleNode.java b/Robust/src/Analysis/Scheduling/ScheduleNode.java index 32c875c2..ba8363f0 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleNode.java +++ b/Robust/src/Analysis/Scheduling/ScheduleNode.java @@ -16,8 +16,6 @@ public class ScheduleNode extends GraphNode implements Cloneable{ private Vector classNodes; Vector scheduleEdges; - private Vector associateEdges; - private Vector inassociateEdges; private int executionTime; @@ -31,8 +29,6 @@ public class ScheduleNode extends GraphNode implements Cloneable{ this.executionTime = -1; this.classNodes = null; this.scheduleEdges = null; - this.associateEdges = new Vector(); - this.inassociateEdges = new Vector(); } public ScheduleNode(ClassNode cn, int gid) { @@ -43,8 +39,6 @@ public class ScheduleNode extends GraphNode implements Cloneable{ this.classNodes.add(cn); this.addEdge(cn.getEdgeVector()); this.executionTime = -1; - this.associateEdges = new Vector(); - this.inassociateEdges = new Vector(); } public int getuid() { @@ -90,37 +84,6 @@ public class ScheduleNode extends GraphNode implements Cloneable{ scheduleEdges = null; } - public Vector getAssociateSEdges() { - return this.associateEdges; - } - - public Iterator getAssociateSEdgesIterator() { - return this.associateEdges.iterator(); - } - - public void addAssociateSEdge(ScheduleEdge se) { - assert(ScheduleEdge.ASSOCEDGE == se.getType()); - - this.associateEdges.addElement(se); - se.setSource(this); - ScheduleNode tonode=(ScheduleNode)se.getTarget(); - tonode.addInAssociateSEdge(se); - } - - public Vector getInAssociateSEdges() { - return this.inassociateEdges; - } - - public Iterator getInAssociateSEdgesIterator() { - return this.inassociateEdges.iterator(); - } - - public void addInAssociateSEdge(ScheduleEdge se) { - assert(ScheduleEdge.ASSOCEDGE == se.getType()); - - this.inassociateEdges.addElement(se); - } - public int getExeTime() { if(this.executionTime == -1) { try { @@ -225,11 +188,6 @@ public class ScheduleNode extends GraphNode implements Cloneable{ se.setNewRate(temp.getNewRate()); break; } - case ScheduleEdge.ASSOCEDGE: { - //TODO - se = new ScheduleEdge(o, "associate", temp.getFstate(), ScheduleEdge.ASSOCEDGE, gid); - break; - } } se.setSourceCNode(cn2cn.get(temp.getSourceCNode())); se.setTargetCNode(cn2cn.get(temp.getTargetCNode())); @@ -244,44 +202,8 @@ public class ScheduleNode extends GraphNode implements Cloneable{ tcns = null; tses = null; - /*Vector assses = new Vector(); - for(i = 0; i < this.scheduleEdges.size(); i++) { - ScheduleEdge temp = this.scheduleEdges.elementAt(i); - - assert(ScheduleEdge.ASSOCEDGE == temp.getType()); - ScheduleEdge se = new ScheduleEdge(o, "associate", temp.getFstate(), ScheduleEdge.ASSOCEDGE, gid); - se.setSourceCNode(cn2cn.get(temp.getSourceCNode())); - se.setTargetCNode(cn2cn.get(temp.getTargetCNode())); - se.setTransTime(temp.getTransTime()); - se.setFEdge(temp.getFEdge()); - se.setTargetFState(temp.getTargetFState()); - se.setIsclone(true); - assses.add(se); - } - o.associateEdges = assses; - assses = null; - - Vector assses = new Vector(); - for(i = 0; i < this.scheduleEdges.size(); i++) { - ScheduleEdge temp = this.scheduleEdges.elementAt(i); - - assert(ScheduleEdge.ASSOCEDGE == temp.getType()); - ScheduleEdge se = new ScheduleEdge(o, "associate", temp.getFstate(), ScheduleEdge.ASSOCEDGE, gid); - se.setSourceCNode(cn2cn.get(temp.getSourceCNode())); - se.setTargetCNode(cn2cn.get(temp.getTargetCNode())); - se.setTransTime(temp.getTransTime()); - se.setFEdge(temp.getFEdge()); - se.setTargetFState(temp.getTargetFState()); - se.setIsclone(true); - assses.add(se); - } - o.associateEdges = assses; - assses = null;*/ - o.inedges = new Vector(); o.edges = new Vector(); - o.associateEdges = new Vector(); - o.inassociateEdges = new Vector(); return o; } diff --git a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java index 6a4ddf58..5e899b29 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java +++ b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java @@ -238,7 +238,6 @@ public class ScheduleSimulator { 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)); diff --git a/Robust/src/Analysis/Scheduling/SchedulingUtil.java b/Robust/src/Analysis/Scheduling/SchedulingUtil.java index b9e561ed..bfa84075 100644 --- a/Robust/src/Analysis/Scheduling/SchedulingUtil.java +++ b/Robust/src/Analysis/Scheduling/SchedulingUtil.java @@ -121,7 +121,6 @@ public class SchedulingUtil { } output.print(" -> "); - //if(se.getTargetFState() == null) { if(se.isclone()) { if(se.getTargetCNode().isclone()) { output.print(se.getTargetCNode().getLabel()); @@ -154,7 +153,6 @@ public class SchedulingUtil { } output.print(" -> "); - //if(se.getTargetFState() == null) { if(se.isclone()) { if(se.getTargetCNode().isclone()) { output.print(se.getTargetCNode().getLabel()); @@ -190,7 +188,6 @@ public class SchedulingUtil { Vector namers=new Vector(); namers.add(new Namer()); namers.add(new Allocations()); - //namers.add(new TaskEdges()); Iterator it = nodes.iterator(); while (it.hasNext()) { @@ -316,7 +313,6 @@ public class SchedulingUtil { } Vector actions = tcp.getActions(); Hashtable tmpTaskNodes = new Hashtable(); - //Vector sortedttnodes = new Vector(); for(int i = 0; i < actions.size(); i++) { Action taction = actions.elementAt(i); int cNum = taction.getCoreNum(); @@ -326,16 +322,6 @@ public class SchedulingUtil { if(!tmpTaskNodes.containsKey(tmpTaskNode)) { tmpTaskNodes.put(tmpTaskNode, new StringBuffer(tnode + ":")); isfirst = true; - /*int length = sortedttnodes.size(); - int k = length; - for(; k > 0; k--) { - String tmptnode = sortedttnodes.elementAt(k-1); - int tcorenum = Integer.parseInt(tmptnode.substring(tmptnode.indexOf("core") + 4, tmptnode.length() - 1)); - if(tcorenum < cNum) { - break; - } - } - sortedttnodes.add(k, tmpTaskNode);*/ } tmpLabel = tmpTaskNodes.get(tmpTaskNode); switch(taction.getType()){ @@ -364,11 +350,12 @@ public class SchedulingUtil { tmpLabel.append("\\n"); } tmpLabel.append("<" + taction.getTd().getSymbol() + ">finishes;"); - if(!(lastTaskNodes[cNum].equals("first")) && - !(lastTaskNodes[cNum].equals(tmpTaskNode))) { - output.print("\t"); - output.println(lastTaskNodes[cNum] + "->" + tmpTaskNode); - lastTaskNodes[cNum] = tmpTaskNode; + if(!(lastTaskNodes[cNum].equals("first"))) { + if(!(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 finish"); @@ -465,10 +452,6 @@ public class SchedulingUtil { } output.print("\t"); output.print("{rank=same; rankdir=LR; " + tnode + "; "); - /*for(int k = 0; k < sortedttnodes.size(); k++) { - output.print(sortedttnodes.elementAt(k)); - output.print("; "); - }*/ keys = tmpTaskNodes.keys(); while(keys.hasMoreElements()) { String tmpTaskNode = keys.nextElement(); @@ -477,17 +460,10 @@ public class SchedulingUtil { } output.println("}"); output.print("\t"); - /*output.print(tnode + "->"); - for(int k = 0; k < sortedttnodes.size() - 1; k++) { - output.print(sortedttnodes.elementAt(k) + "->"); - } - output.println(sortedttnodes.lastElement() + " [style=dashed];");*/ } output.print("\t"); - //output.println("node [shape=point, color=blue];"); output.print("\t"); output.println("\"Time\"->" + timeNodes.elementAt(0) + "[style=invis];"); - //for(j = 0; j < timeNodes.size() - 1; j++) { for(j = 0; j < time; j++) { output.print(j + "->"); } diff --git a/Robust/src/Analysis/Scheduling/TaskSimulator.java b/Robust/src/Analysis/Scheduling/TaskSimulator.java index 4e502e84..626d42ec 100644 --- a/Robust/src/Analysis/Scheduling/TaskSimulator.java +++ b/Robust/src/Analysis/Scheduling/TaskSimulator.java @@ -266,8 +266,6 @@ public class TaskSimulator { } } } - //FlagState tFState = (FlagState)toexecute.getTarget(); - //tpara.setCurrentFS(tFState); tpara.applyEdge(toexecute); tpara.increaseVersion(); } diff --git a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java index 34b7603a..c9787e32 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java +++ b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java @@ -364,10 +364,21 @@ public class FlagState extends GraphNode implements Cloneable { Iterator it = this.edges(); if(it.hasNext()) { FEdge fe = (FEdge)it.next(); - if(fe.getExeTime() == -1) { - throw new Exception("Error: Uninitiate FEdge!"); + while((fe != null) && (fe.getTarget().equals(this))) { + if(it.hasNext()) { + fe = (FEdge)it.next(); + } else { + fe = null; + } + } + if(fe == null) { + this.executeTime = 0; + } else { + if(fe.getExeTime() == -1) { + throw new Exception("Error: Uninitiate FEdge!"); + } + this.executeTime = fe.getExeTime() + ((FlagState)fe.getTarget()).getExeTime(); } - this.executeTime = fe.getExeTime() + ((FlagState)fe.getTarget()).getExeTime(); } else { this.executeTime = 0; } diff --git a/Robust/src/ClassLibrary/System.java b/Robust/src/ClassLibrary/System.java index 124f3174..00f129a1 100644 --- a/Robust/src/ClassLibrary/System.java +++ b/Robust/src/ClassLibrary/System.java @@ -13,6 +13,8 @@ public class System { } public static native void exit(int status); + + public static native void printI(int status); public static native void clearPrefetchCache(); } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index fe3dc9a9..1856fde7 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -37,7 +37,6 @@ public class BuildCode { public static int flagcount = 0; Virtual virtualcalls; TypeUtil typeutil; - //private int maxtaskparams=0; protected int maxtaskparams=0; private int maxcount=0; ClassDescriptor[] cdarray; @@ -304,11 +303,10 @@ public class BuildCode { * objets and array that stores supertype and then the code for * the Java methods.. */ - //private void outputMethods(PrintWriter outmethod) { protected void outputMethods(PrintWriter outmethod) { outmethod.println("#include \"methodheaders.h\""); outmethod.println("#include \"virtualtable.h\""); - outmethod.println("#include "); + outmethod.println("#include \"runtime.h\""); if (state.DSM) { outmethod.println("#include \"localobjects.h\""); } @@ -359,7 +357,6 @@ public class BuildCode { } } - //private void outputStructs(PrintWriter outstructs) { protected void outputStructs(PrintWriter outstructs) { outstructs.println("#ifndef STRUCTDEFS_H"); outstructs.println("#define STRUCTDEFS_H"); @@ -402,7 +399,6 @@ public class BuildCode { } } - //private void outputClassDeclarations(PrintWriter outclassdefs) { protected void outputClassDeclarations(PrintWriter outclassdefs) { if (state.THREAD||state.DSM) outclassdefs.println("#include "); @@ -621,8 +617,7 @@ public class BuildCode { /** The buildVirtualTables method outputs the virtual dispatch * tables for methods. */ - - //private void buildVirtualTables(PrintWriter outvirtual) { + protected void buildVirtualTables(PrintWriter outvirtual) { Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); while(classit.hasNext()) { @@ -763,7 +758,6 @@ public class BuildCode { * These objects tell the compiler which temps need to be * allocated. */ - //private void generateTempStructs(FlatMethod fm, LocalityBinding lb) { protected void generateTempStructs(FlatMethod fm, LocalityBinding lb) { MethodDescriptor md=fm.getMethod(); TaskDescriptor task=fm.getTask(); @@ -971,7 +965,6 @@ public class BuildCode { /* Map flags to integers consistently between inherited * classes. */ - //private void mapFlags(ClassDescriptor cn) { protected void mapFlags(ClassDescriptor cn) { ClassDescriptor sp=cn.getSuperDesc(); if (sp!=null) @@ -1006,7 +999,6 @@ public class BuildCode { * passed in (when PRECISE GC is enabled) and (2) function * prototypes for the methods */ - //private void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout) { protected void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout) { /* Output class structure */ classdefout.println("struct "+cn.getSafeSymbol()+" {"); @@ -1342,7 +1334,6 @@ public class BuildCode { /** This method assigns labels to FlatNodes */ - //private Hashtable assignLabels(FlatMethod fm) { protected Hashtable assignLabels(FlatMethod fm) { HashSet tovisit=new HashSet(); HashSet visited=new HashSet(); @@ -1376,7 +1367,6 @@ public class BuildCode { /** Generate text string that corresponds to the TempDescriptor td. */ - //private String generateTemp(FlatMethod fm, TempDescriptor td, LocalityBinding lb) { protected String generateTemp(FlatMethod fm, TempDescriptor td, LocalityBinding lb) { MethodDescriptor md=fm.getMethod(); TaskDescriptor task=fm.getTask(); @@ -1396,7 +1386,6 @@ public class BuildCode { throw new Error(); } - //private void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) { protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) { switch(fn.kind()) { case FKind.FlatAtomicEnterNode: @@ -1911,7 +1900,9 @@ public class BuildCode { } else if (status==LocalityAnalysis.EITHER) { //Code is reading from a null pointer output.println("if ("+generateTemp(fm, ffn.getSrc(),lb)+") {"); + output.println("#ifndef RAW"); output.println("printf(\"BIG ERROR\\n\");exit(-1);}"); + output.println("#endif"); //This should throw a suitable null pointer error output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); } else @@ -1963,7 +1954,9 @@ public class BuildCode { } else if (statusdst.equals(LocalityAnalysis.EITHER)) { //writing to a null...bad output.println("if ("+dst+") {"); + output.println("#ifndef RAW"); output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}"); + output.println("#endif"); if (srcglobal) output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=srcoid;"); else @@ -2006,7 +1999,9 @@ public class BuildCode { } else if (status==LocalityAnalysis.EITHER) { //Code is reading from a null pointer output.println("if ("+generateTemp(fm, fen.getSrc(),lb)+") {"); + output.println("#ifndef RAW"); output.println("printf(\"BIG ERROR\\n\");exit(-1);}"); + output.println("#endif"); //This should throw a suitable null pointer error output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); } else @@ -2095,10 +2090,6 @@ public class BuildCode { output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+fn.getType().getClassDesc().getId()+");"); } } - if(state.MULTICORE) { - output.println(" " + generateTemp(fm,fn.getDst(),lb)+"->isolate = 1;"); - output.println(" " + generateTemp(fm,fn.getDst(),lb)+"->version = 0;"); - } if (state.DSM && locality.getAtomic(lb).get(fn).intValue()>0&&!fn.isGlobal()) { String revertptr=generateTemp(fm, reverttable.get(lb),lb); output.println("trans->revertlist="+revertptr+";"); @@ -2193,7 +2184,6 @@ public class BuildCode { } } - //private void generateFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) { protected void generateFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) { output.println("if (!"+generateTemp(fm, fcb.getTest(),lb)+") goto "+label+";"); } @@ -2384,11 +2374,6 @@ public class BuildCode { ormask=((Integer)flagortable.get(temp)).intValue(); if (flagandtable.containsKey(temp)) andmask=((Integer)flagandtable.get(temp)).intValue(); - /*if (ffan.getTaskType()==FlatFlagActionNode.NEWOBJECT) { - output.println("flagorandinit("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); - } else { - output.println("flagorand("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); - }*/ generateFlagOrAnd(ffan, fm, lb, temp, output, ormask, andmask); generateObjectDistribute(ffan, fm, lb, temp, output); } diff --git a/Robust/src/IR/Flat/BuildCodeMultiCore.java b/Robust/src/IR/Flat/BuildCodeMultiCore.java index 8665dfdd..3598ebd4 100644 --- a/Robust/src/IR/Flat/BuildCodeMultiCore.java +++ b/Robust/src/IR/Flat/BuildCodeMultiCore.java @@ -33,10 +33,10 @@ public class BuildCodeMultiCore extends BuildCode { int coreNum; Schedule currentSchedule; Hashtable[] fsate2qnames; - //String objqs4startupprefix= "objqueuearray4startup"; - //String objqs4socketprefix= "objqueuearray4socket"; String objqarrayprefix= "objqueuearray4class"; String objqueueprefix = "objqueue4parameter_"; + String paramqarrayprefix = "paramqueuearray4task"; + String coreqarrayprefix = "paramqueuearrays_core"; String taskprefix = "task_"; String taskarrayprefix = "taskarray_core"; String otqueueprefix = "___otqueue"; @@ -65,13 +65,11 @@ public class BuildCodeMultiCore extends BuildCode { /* Create output streams to write to */ PrintWriter outclassdefs=null; PrintWriter outstructs=null; - //PrintWriter outrepairstructs=null; PrintWriter outmethodheader=null; PrintWriter outmethod=null; PrintWriter outvirtual=null; PrintWriter outtask=null; PrintWriter outtaskdefs=null; - //PrintWriter[] outtaskdefs=null; //PrintWriter outoptionalarrays=null; //PrintWriter optionalheaders=null; @@ -84,14 +82,6 @@ public class BuildCodeMultiCore extends BuildCode { if (state.TASK) { outtask=new PrintWriter(new FileOutputStream(PREFIX+"task.h"), true); outtaskdefs=new PrintWriter(new FileOutputStream(PREFIX+"taskdefs.c"), true); - /*if(this.scheduling != null) { - outtaskdefs = new PrintWriter[this.coreNum]; - for(int i = 0; i < this.scheduling.size(); ++i) { - this.currentSchedule = this.scheduling.elementAt(i); - outtaskdefs[this.currentSchedule.getCoreNum()] = new PrintWriter( - new FileOutputStream(PREFIX+"taskdefs_"+this.currentSchedule.getCoreNum()+".c"), true); - } - }*/ /* optional if (state.OPTIONAL){ outoptionalarrays=new PrintWriter(new FileOutputStream(PREFIX+"optionalarrays.c"), true); @@ -159,53 +149,14 @@ public class BuildCodeMultiCore extends BuildCode { } int[] numtasks = new int[this.coreNum]; int[][] numqueues = new int[this.coreNum][numclasses]; - // arrays record the queues for startup object & socket object - //int[][] numqueues = new int[2][this.coreNum]; /* Output code for tasks */ for(int i = 0; i < this.scheduling.size(); ++i) { this.currentSchedule = this.scheduling.elementAt(i); outputTaskCode(outtaskdefs, outmethod, outtask, taskits, numtasks, numqueues); - /*outputTaskCode(outtaskdefs[this.currentSchedule.getCoreNum()], outmethod); - outtaskdefs[this.currentSchedule.getCoreNum()].close();*/ } // Output task descriptors boolean comma = false; - /* - for(int index = 0; index < 2; ++index) { - if(index == 0) { - outtaskdefs.println("struct parameterwrapper ** objq4startupobj[] = {"); - } else { - outtaskdefs.println("struct parameterwrapper ** objq4socketobj[] = {"); - } - comma = false; - for(int i = 0; i < this.coreNum; ++i) { - if(comma) { - outtaskdefs.println(","); - } else { - comma = true; - } - outtaskdefs.println("/* object queue array for core " + i + "* /"); - outtaskdefs.print(this.objqs4startupprefix + "_core" + i); - } - outtaskdefs.println("};"); - if(index == 0) { - outtaskdefs.println("int numqueues4startupobj[] = {"); - } else { - outtaskdefs.println("int numqueues4socketobj[] = {"); - } - int[] tmparray = numqueues[index]; - comma = false; - for(int i = 0; i < tmparray.length; ++i) { - if(comma) { - outtaskdefs.print(","); - } else { - comma = true; - } - outtaskdefs.print(tmparray[i]); - } - outtaskdefs.println("};"); - }*/ outtaskdefs.println("struct parameterwrapper ** objectqueues[][NUMCLASSES] = {"); boolean needcomma = false; for(int i = 0; i < numqueues.length ; ++i) { @@ -251,6 +202,20 @@ public class BuildCodeMultiCore extends BuildCode { } outtaskdefs.println("};"); + /* parameter queue arrays for all the tasks*/ + outtaskdefs.println("struct parameterwrapper *** paramqueues[] = {"); + needcomma = false; + for(int i = 0; i < this.coreNum ; ++i) { + if(needcomma) { + outtaskdefs.println(","); + } else { + needcomma = true; + } + outtaskdefs.println("/* parameter queue array for core " + i + "*/"); + outtaskdefs.print(this.coreqarrayprefix + i); + } + outtaskdefs.println("};"); + for(int i = 0; i < taskits.length; ++i) { outtaskdefs.println("struct taskdescriptor * " + this.taskarrayprefix + i + "[]={"); Iterator taskit = taskits[i]; @@ -289,13 +254,7 @@ public class BuildCodeMultiCore extends BuildCode { outtaskdefs.print(numtasks[i]); } outtaskdefs.println("};"); - - outtaskdefs.println("#ifdef RAW"); - outtaskdefs.println("#include \"raw.h\""); - outtaskdefs.println("int corenum=raw_get_tile_num();"); - outtaskdefs.println("#else"); outtaskdefs.println("int corenum=0;"); - outtaskdefs.println("#endif"); outtaskdefs.close(); outtask.println("#endif"); @@ -429,39 +388,9 @@ public class BuildCodeMultiCore extends BuildCode { // generate queuearray for this core int num = this.currentSchedule.getCoreNum(); boolean comma = false; - /*for(int i = 0; i < 2; ++i) { - if(i == 0) { - outtaskdefs.println("/* object queue array for class StartupObject on core " + num + "* /"); - } else { - outtaskdefs.println("/* object queue array for class Socket on core " + num + "* /"); - } - if(i == 0) { - outtaskdefs.println("struct parameterwrapper * " + this.objqs4startupprefix + "_core" + num + "[] = {"); - } else { - outtaskdefs.println("struct parameterwrapper * " + this.objqs4socketprefix + "_core" + num + "[] = {"); - } - Vector tmpvector = qnames[i]; - comma = false; - if(tmpvector != null) { - for(int j = 0; j < tmpvector.size(); ++j) { - if(comma) { - outtaskdefs.println(","); - } else { - comma = true; - } - outtaskdefs.print("&" + tmpvector.elementAt(j)); - } - numqueues[i][num] = tmpvector.size(); - } else { - numqueues[i][num] = 0; - } - outtaskdefs.println(); - outtaskdefs.println("};"); - }*/ for(int i = 0; i < qnames.length; ++i) { outtaskdefs.println("/* object queue array for class " + i + " on core " + num + "*/"); outtaskdefs.println("struct parameterwrapper * " + this.objqarrayprefix + i + "_core" + num + "[] = {"); - //outtaskdefs.print("0"); comma = false; Vector tmpvector = qnames[i]; if(tmpvector != null) { @@ -473,12 +402,28 @@ public class BuildCodeMultiCore extends BuildCode { } outtaskdefs.print("&" + tmpvector.elementAt(j)); } - numqueues[num][i] = tmpvector.size();// + 1; + numqueues[num][i] = tmpvector.size(); } else { - numqueues[num][i] = 0;//1; + numqueues[num][i] = 0; } outtaskdefs.println("};"); } + + /* All the queues for tasks residing on this core*/ + comma = false; + outtaskdefs.println("/* object queue array for tasks on core " + num + "*/"); + outtaskdefs.println("struct parameterwrapper ** " + this.coreqarrayprefix + num + "[] = {"); + taskit=this.currentSchedule.getTasks().iterator(); + while(taskit.hasNext()) { + if (comma) { + outtaskdefs.println(","); + } else { + comma = true; + } + TaskDescriptor td=taskit.next(); + outtaskdefs.print(this.paramqarrayprefix + td.getCoreSafeSymbol(num)); + } + outtaskdefs.println("};"); // record the iterator of tasks on this core taskit=this.currentSchedule.getTasks().iterator(); @@ -493,6 +438,10 @@ public class BuildCodeMultiCore extends BuildCode { outtask.println("#include \"ObjectHash.h\""); outtask.println("#include \"structdefs.h\""); outtask.println("#include \"Queue.h\""); + outtask.println("#include "); + outtask.println("#ifdef RAW"); + outtask.println("#include "); + outtask.println("#endif"); outtask.println(); outtask.println("struct tagobjectiterator {"); outtask.println(" int istag; /* 0 if object iterator, 1 if tag iterator */"); @@ -523,12 +472,6 @@ public class BuildCodeMultiCore extends BuildCode { outtask.println(" struct tagobjectiterator iterators[MAXTASKPARAMS-1];"); outtask.println("};"); outtask.println(); - /* - outtask.println("extern struct parameterwrapper ** objq4startupobj[];"); - outtask.println("extern int numqueues4startupobj[];"); - outtask.println("extern struct parameterwrapper ** objq4socketobj[];"); - outtask.println("extern int numqueues4socketobj[];"); - */ outtask.println("extern struct parameterwrapper ** objectqueues[][NUMCLASSES];"); outtask.println("extern int numqueues[][NUMCLASSES];"); outtask.println(); @@ -552,6 +495,7 @@ public class BuildCodeMultiCore extends BuildCode { outtask.println("extern struct taskdescriptor ** taskarray[];"); outtask.println("extern int numtasks[];"); outtask.println("extern int corenum;"); // define corenum to identify different core + outtask.println("extern struct parameterwrapper *** paramqueues[];"); outtask.println(); } @@ -627,13 +571,10 @@ public class BuildCodeMultiCore extends BuildCode { TempDescriptor td=objecttemp.getPrimitive(i); TypeDescriptor type=td.getType(); if (type.isNull()) - //output.println(" void * "+td.getCoreSafeSymbol(num)+";"); output.println(" void * "+td.getSafeSymbol()+";"); else if (type.isClass()||type.isArray()) - //output.println(" struct "+type.getSafeSymbol()+" * "+td.getCoreSafeSymbol(num)+";"); output.println(" struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";"); else - //output.println(" "+type.getSafeSymbol()+" "+td.getCoreSafeSymbol(num)+";"); output.println(" "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";"); } @@ -641,7 +582,6 @@ public class BuildCodeMultiCore extends BuildCode { TempDescriptor temp = fm.getParameter(i); output.println(" int "+generateTempFlagName(fm, temp, lb)+" = "+super.generateTemp(fm, temp, lb)+ "->flag;"); - output.println(" ++" + super.generateTemp(fm, temp, lb)+"->version;"); } /* Assign labels to FlatNode's if necessary.*/ @@ -660,8 +600,25 @@ public class BuildCodeMultiCore extends BuildCode { /* Create queues to store objects need to be transferred to other cores and their destination*/ output.println(" struct Queue * totransobjqueue = createQueue();"); - output.println(" struct Queue * desqueue = createQueue();"); - output.println("int tmpint = 0;"); + output.println(" struct transObjInfo * tmpObjInfo = NULL;"); + + /* generate print information for RAW version */ + output.println("#ifdef RAW"); + output.println("int tmpsum = 0;"); + output.println("char * taskname = \"" + task.getSymbol() + "\";"); + output.println("int tmplen = " + task.getSymbol().length() + ";"); + output.println("int tmpindex = 1;"); + output.println("for(;tmpindex < tmplen; tmpindex++) {"); + output.println(" tmpsum = tmpsum * 10 + *(taskname + tmpindex) - '0';"); + output.println("}"); + output.println("raw_test_pass(0xAAAA);"); + output.println("raw_test_pass_reg(tmpsum);"); + output.println("#endif"); + + for(int i = 0; i < fm.numParameters(); ++i) { + TempDescriptor temp = fm.getParameter(i); + output.println(" ++" + super.generateTemp(fm, temp, lb)+"->version;"); + } /* Do the actual code generation */ FlatNode current_node=null; @@ -687,6 +644,7 @@ public class BuildCodeMultiCore extends BuildCode { output.print(" "); super.generateFlatNode(fm, lb, current_node, output); if (current_node.kind()!=FKind.FlatReturnNode) { + output.println(" flushAll();"); outputTransCode(output); output.println(" return;"); } @@ -781,24 +739,12 @@ public class BuildCodeMultiCore extends BuildCode { if(param_type.getClassDesc().getSymbol().equals("StartupObject")) { this.startupcorenum = num; } - /*if(param_type.getClassDesc().getSymbol().equals("StartupObject")) { - if(qnames[0] == null) { - qnames[0] = new Vector(); - } - qnames[0].addElement(qname); - } else if(param_type.getClassDesc().getSymbol().equals("Socket")) { - if(qnames[1] == null) { - qnames[1] = new Vector(); - } - qnames[1].addElement(qname); - }*/ if(qnames[param_type.getClassDesc().getId()] == null) { qnames[param_type.getClassDesc().getId()] = new Vector(); } qnames[param_type.getClassDesc().getId()].addElement(qname); outtask.println("extern struct parameterwrapper " + qname + ";"); output.println("struct parameterwrapper " + qname + "={"); - //output.println(".type = " + param_type.getClassDesc().getId() + ","); // type output.println(".objectset = 0,"); // objectset output.println("/* number of DNF terms */ .numberofterms = "+dnfterms+","); // numberofterms output.println(".intarray = parameterdnf_"+i+"_"+task.getCoreSafeSymbol(num)+","); // intarray @@ -827,7 +773,15 @@ public class BuildCodeMultiCore extends BuildCode { output.println("parametertag_"+i+"_"+task.getCoreSafeSymbol(num)); // tagarray output.println("};"); } - + + /* parameter queues for this task*/ + output.println("struct parameterwrapper * " + this.paramqarrayprefix + task.getCoreSafeSymbol(num)+"[] = {"); + for (int i=0;i initfstates = ffan.getInitFStates(cd); for(int i = 0; i < initfstates.size(); ++i) { FlagState tmpFState = initfstates.elementAt(i); - + output.println("{"); QueueInfo qinfo = outputqueues(tmpFState, num, output, false); output.println("flagorand("+super.generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+ ", 0x"+Integer.toHexString(andmask)+", " + qinfo.qname + ", " + qinfo.length + ");"); + output.println("}"); } - //output.println("flagorand("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); } } @@ -953,7 +907,6 @@ public class BuildCodeMultiCore extends BuildCode { for(int j = 0; j < targetFStates.length; ++j) { if(initfstates != null) { FlagState fs = initfstates.elementAt(j); - //isolate = this.currentSchedule.getAllyCoreTable().keySet().contains(fs); output.println("if(" + generateTempFlagName(fm, temp, lb) + "&(0x" + Integer.toHexString(fs.getAndmask()) + ")==(0x" + Integer.toHexString(fs.getCheckmask()) + ")) {"); } @@ -964,14 +917,11 @@ public class BuildCodeMultiCore extends BuildCode { // may have bugs here output.println("/* reside on this core*"); output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); - //output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", objq4socketobj[corenum], numqueues4socketobj[corenum]);"); - //output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+");"); } if(initfstates != null) { output.println("}"); } } - //output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+");"); return; } @@ -994,15 +944,14 @@ public class BuildCodeMultiCore extends BuildCode { isolate = (this.currentSchedule.getAllyCoreTable().get(tmpFState) == null) || (this.currentSchedule.getAllyCoreTable().get(tmpFState).size() == 0); } - /*if(isolate) { - output.println(super.generateTemp(fm, temp, lb) + "->isolate = 1;"); // not shared object - } else {*/ if(!isolate) { // indentify this object as a shared object // isolate flag is initially set as 1, once this flag is set as 0, it is never reset to 1, i.e. once an object // is shared, it maybe shared all the time afterwards - output.println(super.generateTemp(fm, temp, lb) + "->isolate = 0;"); - output.println(super.generateTemp(fm, temp, lb) + "->original = (struct ___Object___ *)" + super.generateTemp(fm, temp, lb) + ";"); + output.println("if(" + super.generateTemp(fm, temp, lb) + "->isolate == 1) {"); + output.println(" " + super.generateTemp(fm, temp, lb) + "->isolate = 0;"); + output.println(" " + super.generateTemp(fm, temp, lb) + "->original = (struct ___Object___ *)" + super.generateTemp(fm, temp, lb) + ";"); + output.println("}"); } Vector sendto = new Vector(); @@ -1031,50 +980,73 @@ public class BuildCodeMultiCore extends BuildCode { if(targetcore.intValue() == num) { output.println("/* reside on this core*/"); if(isolate) { + output.println("{"); QueueInfo qinfo = outputqueues(tmpFState, num, output, true); output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", " + qinfo.qname + ", " + qinfo.length + ");"); + output.println("}"); } else { + // TODO + // really needed? + output.println("/* possibly needed by multi-parameter tasks on this core*/"); output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); } - - //output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+");"); } else { if(!isolate) { + // TODO + // Is it possible to decide the actual queues? output.println("/* possibly needed by multi-parameter tasks on this core*/"); output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); } output.println("/* transfer to core " + targetcore.toString() + "*/"); - // method call of transfer objects - //output.println("transferObject("+super.generateTemp(fm, temp, lb)+", " + targetcore.toString() + ");"); - // enqueue this object and its destination - output.println(";"); - output.println("tmpint = "+targetcore.toString()+";"); - output.println("addNewItem(totransobjqueue, (void*)" +super.generateTemp(fm, temp, lb) + ");"); - output.println("addNewItem(desqueue, (void *)tmpint);"); + output.println("{"); + // enqueue this object and its destinations for later process + // all the possible queues + QueueInfo qinfo = null; + FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); + if(targetFS != null) { + qinfo = outputtransqueues(targetFS, targetcore, output); + } else { + qinfo = outputtransqueues(tmpFState, targetcore, output); + } + output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); + output.println("tmpObjInfo->objptr = (void *)" + super.generateTemp(fm, temp, lb) + ";"); + output.println("tmpObjInfo->targetcore = "+targetcore.toString()+";"); + output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); + output.println("tmpObjInfo->length = " + qinfo.length + ";"); + output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); + output.println("}"); sendto.add(targetcore); - //output.println("transferObject("+super.generateTemp(fm, temp, lb)+", " + targetcore.toString() + - // ", \"" + targetcore.toString() + "\"" + ");"); } output.println("break;"); } output.println("}"); } else { if(!isolate) { + // TODO + // Is it possible to decide the actual queues? output.println("/* possibly needed by multi-parameter tasks on this core*/"); output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); } output.println("/* transfer to core " + targetcore.toString() + "*/"); - // method call of transfer objectts - //output.println("transferObject("+super.generateTemp(fm, temp, lb)+", " + targetcore.toString() + ");"); - // enqueue this object and its destination - output.println(";"); - output.println("tmpint = "+targetcore.toString()+";"); - output.println("addNewItem(totransobjqueue, (void*)" +super.generateTemp(fm, temp, lb) + ");"); - output.println("addNewItem(desqueue, (void *)tmpint);"); + output.println("{"); + // enqueue this object and its destinations for later process + // all the possible queues + QueueInfo qinfo = null; + FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); + if(targetFS != null) { + qinfo = outputtransqueues(targetFS, targetcore, output); + } else { + qinfo = outputtransqueues(tmpFState, targetcore, output); + } + output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); + output.println("tmpObjInfo->objptr = (void *)" + super.generateTemp(fm, temp, lb) + ";"); + output.println("tmpObjInfo->targetcore = "+targetcore.toString()+";"); + output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); + output.println("tmpObjInfo->length = " + qinfo.length + ";"); + output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); + output.println("}"); sendto.add(targetcore); - //output.println("transferObject("+super.generateTemp(fm, temp, lb)+", " + targetcore.toString() + - // ", \"" + targetcore.toString() + "\"" + ");"); } output.println("/* increase index*/"); output.println("++" + queueins + ".index;"); @@ -1082,14 +1054,16 @@ public class BuildCodeMultiCore extends BuildCode { // this object will reside on current core output.println("/* reside on this core*/"); if(isolate) { + output.println("{"); QueueInfo qinfo = outputqueues(tmpFState, num, output, true); output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", " + qinfo.qname + ", " + qinfo.length + ");"); + output.println("}"); } else { + // TODO + // really needed? output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); } - - //output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+");"); } // codes for multi-params tasks @@ -1099,17 +1073,27 @@ public class BuildCodeMultiCore extends BuildCode { Vector targetcores = this.currentSchedule.getAllyCores(tmpFState); output.println("/* send the shared object to possible queues on other cores*/"); for(int k = 0; k < targetcores.size(); ++k) { - //QueueInfo qinfo = outputqueues(tmpFState, num, output); // TODO // add the information of exactly which queue if(!sendto.contains(targetcores.elementAt(i))) { // previously not sended to this target core - //output.println("transferObject("+super.generateTemp(fm, temp, lb)+", " + targetcores.elementAt(i).toString() + ");"); - // enqueue this object and its destination - output.println(";"); - output.println("tmpint = "+targetcores.elementAt(i).toString()+";"); - output.println("addNewItem(totransobjqueue, (void*)" +super.generateTemp(fm, temp, lb) + ");"); - output.println("addNewItem(desqueue, (void *)tmpint);"); + // enqueue this object and its destinations for later process + output.println("{"); + // all the possible queues + QueueInfo qinfo = null; + FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); + if(targetFS != null) { + qinfo = outputtransqueues(targetFS, targetcores.elementAt(i), output); + } else { + qinfo = outputtransqueues(tmpFState, targetcores.elementAt(i), output); + } + output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); + output.println("tmpObjInfo->objptr = (void *)" + super.generateTemp(fm, temp, lb) + ";"); + output.println("tmpObjInfo->targetcore = "+targetcores.elementAt(i).toString()+";"); + output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); + output.println("tmpObjInfo->length = " + qinfo.length + ";"); + output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); + output.println("}"); } } } @@ -1124,7 +1108,6 @@ public class BuildCodeMultiCore extends BuildCode { private QueueInfo outputqueues(FlagState tmpFState, int num, PrintWriter output, boolean isEnqueue) { // queue array QueueInfo qinfo = new QueueInfo(); - output.println(";"); qinfo.qname = "queues_" + tmpFState.getLabel() + "_" + tmpFState.getiuid(); output.println("struct parameterwrapper * " + qinfo.qname + "[] = {"); Iterator it_edges = tmpFState.getEdgeVector().iterator(); @@ -1156,6 +1139,43 @@ public class BuildCodeMultiCore extends BuildCode { return qinfo; } + private QueueInfo outputtransqueues(FlagState tmpFState, int targetcore, PrintWriter output) { + // queue array + QueueInfo qinfo = new QueueInfo(); + qinfo.qname = "queues_" + tmpFState.getLabel() + "_" + tmpFState.getiuid(); + output.println("int " + qinfo.qname + "_clone[] = {"); + Iterator it_edges = tmpFState.getEdgeVector().iterator(); + Vector residetasks = this.scheduling.get(targetcore).getTasks(); + Vector tasks = new Vector(); + Vector indexes = new Vector(); + boolean comma = false; + qinfo.length = 0; + while(it_edges.hasNext()) { + FEdge fe = (FEdge)it_edges.next(); + TaskDescriptor td = fe.getTask(); + int paraindex = fe.getIndex(); + if(residetasks.contains(td)) { + if((!tasks.contains(td)) || + ((tasks.contains(td)) && (paraindex != indexes.elementAt(tasks.indexOf(td)).intValue()))) { + tasks.addElement(td); + indexes.addElement(paraindex); + if(comma) { + output.println(","); + } else { + comma = true; + } + output.print(residetasks.indexOf(td) + ", "); + output.print(paraindex); + ++qinfo.length; + } + } + } + output.println("};"); + output.println("int * " + qinfo.qname + " = RUNMALLOC(sizeof(int) * " + qinfo.length * 2 + ");"); + output.println("memcpy(" + qinfo.qname + ", (int *)" + qinfo.qname + "_clone, sizeof(int) * " + qinfo.length * 2 + ");"); + return qinfo; + } + private class QueueInfo { public int length; public String qname; @@ -1183,13 +1203,13 @@ public class BuildCodeMultiCore extends BuildCode { protected void outputTransCode(PrintWriter output) { output.println("while(0 == isEmpty(totransobjqueue)) {"); output.println(" struct QueueItem * totransitem = getTail(totransobjqueue);"); - output.println(" struct QueueItem * desitem = getTail(desqueue);"); - output.println(" transferObject(totransitem->objectptr, (int)desitem->objectptr);"); + + output.println(" transferObject((struct transObjInfo *)totransitem->objectptr);"); + output.println(" RUNFREE(((struct transObjInfo *)totransitem->objectptr)->queues);"); + output.println(" RUNFREE(totransitem->objectptr);"); output.println(" removeItem(totransobjqueue, totransitem);"); - output.println(" removeItem(desqueue, desitem);"); output.println("}"); output.println("freeQueue(totransobjqueue);"); - output.println("freeQueue(desqueue);"); } protected void generateFlatReturnNode(FlatMethod fm, LocalityBinding lb, FlatReturnNode frn, PrintWriter output) { @@ -1200,9 +1220,10 @@ public class BuildCodeMultiCore extends BuildCode { output.println("return "+generateTemp(fm, frn.getReturnTemp(), lb)+";"); } else { if(fm.getTask() != null) { + output.println("flushAll();"); outputTransCode(output); } output.println("return;"); } } -} \ No newline at end of file +} diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index 63345fcd..07bbae6e 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -55,7 +55,7 @@ public class State { public boolean MULTICORE=false; public boolean OWNERSHIP=false; public boolean OPTIONAL=false; - //public boolean RAW=false; + public boolean RAW=false; public boolean SCHEDULING=false; public boolean THREAD=false; public boolean CONSCHECK=false; diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 2fa3e23e..0d214bfd 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -102,8 +102,8 @@ public class Main { state.OWNERSHIP=true; else if (option.equals("-optional")) state.OPTIONAL=true; - /*else if (option.equals("-raw")) - state.RAW=true;*/ + else if (option.equals("-raw")) + state.RAW=true; else if (option.equals("-scheduling")) state.SCHEDULING=true; else if (option.equals("-thread")) @@ -152,19 +152,23 @@ public class Main { readSourceFile(state, ClassLibraryPrefix+"HashEntry.java"); readSourceFile(state, ClassLibraryPrefix+"Integer.java"); readSourceFile(state, ClassLibraryPrefix+"StringBuffer.java"); + //if(!state.RAW) { readSourceFile(state, ClassLibraryPrefix+"FileInputStream.java"); readSourceFile(state, ClassLibraryPrefix+"InputStream.java"); readSourceFile(state, ClassLibraryPrefix+"OutputStream.java"); readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java"); readSourceFile(state, ClassLibraryPrefix+"File.java"); - readSourceFile(state, ClassLibraryPrefix+"Math.java"); readSourceFile(state, ClassLibraryPrefix+"InetAddress.java"); readSourceFile(state, ClassLibraryPrefix+"SocketInputStream.java"); readSourceFile(state, ClassLibraryPrefix+"SocketOutputStream.java"); + //} + readSourceFile(state, ClassLibraryPrefix+"Math.java"); readSourceFile(state, ClassLibraryPrefix+"gnu/Random.java"); readSourceFile(state, ClassLibraryPrefix+"Vector.java"); readSourceFile(state, ClassLibraryPrefix+"Enumeration.java"); + if(!state.MULTICORE) { readSourceFile(state, ClassLibraryPrefix+"Signal.java"); + } if (state.TASK) { diff --git a/Robust/src/Runtime/GenericHashtable.c b/Robust/src/Runtime/GenericHashtable.c index 763aa9ca..44782c6c 100755 --- a/Robust/src/Runtime/GenericHashtable.c +++ b/Robust/src/Runtime/GenericHashtable.c @@ -1,4 +1,8 @@ +#ifdef RAW +#include +#else #include +#endif #include #include #include @@ -12,6 +16,9 @@ #endif void * getfirstkey(struct genhashtable *ht) { + if(ht->list == NULL) { + return NULL; + } return ht->list->src; } @@ -59,6 +66,52 @@ int genputtable(struct genhashtable *ht, void * key, void * object) { return 1; } +#ifdef RAW +int genputtable_I(struct genhashtable *ht, void * key, void * object) { + unsigned int bin=genhashfunction(ht,key); + struct genpointerlist * newptrlist=(struct genpointerlist *) RUNMALLOC_I(sizeof(struct genpointerlist)); + newptrlist->src=key; + newptrlist->object=object; + newptrlist->next=ht->bins[bin]; + newptrlist->inext=NULL; + /* maintain linked list of ht entries for iteration*/ + if (ht->last==NULL) { + ht->last=newptrlist; + ht->list=newptrlist; + newptrlist->iprev=NULL; + } else { + ht->last->inext=newptrlist; + newptrlist->iprev=ht->last; + ht->last=newptrlist; + } + ht->bins[bin]=newptrlist; + ht->counter++; + if(ht->counter>ht->currentsize&&ht->currentsize!=INT_MAX) { + /* Expand hashtable */ + long newcurrentsize=(ht->currentsize<(INT_MAX/2))?ht->currentsize*2:INT_MAX; + long oldcurrentsize=ht->currentsize; + struct genpointerlist **newbins=(struct genpointerlist **) RUNMALLOC_I(sizeof (struct genpointerlist *)*newcurrentsize); + struct genpointerlist **oldbins=ht->bins; + long j,i; + for(j=0;jcurrentsize=newcurrentsize; + for(i=0;isrc); + struct genpointerlist *nextptr=tmpptr->next; + tmpptr->next=newbins[hashcode]; + newbins[hashcode]=tmpptr; + tmpptr=nextptr; + } + } + ht->bins=newbins; + RUNFREE(oldbins); + } + return 1; +} +#endif + int hashsize(struct genhashtable *ht) { return ht->counter; } @@ -89,7 +142,9 @@ void * gengettable(struct genhashtable *ht, void * key) { return ptr->object; ptr=ptr->next; } +#ifndef RAW printf("XXXXXXXXX: COULDN'T FIND ENTRY FOR KEY %p\n",key); +#endif return NULL; } @@ -103,7 +158,9 @@ void * getnext(struct genhashtable *ht, void * key) { return NULL; ptr=ptr->next; } +#ifndef RAW printf("XXXXXXXXX: COULDN'T FIND ENTRY FOR KEY %p...\n Likely concurrent removal--bad user!!!\n",key); +#endif return NULL; } @@ -158,7 +215,9 @@ void genfreekey(struct genhashtable *ht, void * key) { } ptr=ptr->next; } +#ifndef RAW printf("XXXXXXXXX: COULDN'T FIND ENTRY FOR KEY %p\n",key); +#endif } unsigned int genhashfunction(struct genhashtable *ht, void * key) { @@ -169,11 +228,28 @@ unsigned int genhashfunction(struct genhashtable *ht, void * key) { } struct genhashtable * genallocatehashtable(unsigned int (*hash_function)(void *),int (*comp_function)(void *, void *)) { - struct genhashtable *ght=(struct genhashtable *) RUNMALLOC(sizeof(struct genhashtable)); - struct genpointerlist **gpl=(struct genpointerlist **) RUNMALLOC(sizeof(struct genpointerlist *)*geninitialnumbins); + struct genhashtable *ght; + struct genpointerlist **gpl; int i; - for(i=0;ihash_function=hash_function; ght->comp_function=comp_function; ght->currentsize=geninitialnumbins; @@ -181,6 +257,9 @@ struct genhashtable * genallocatehashtable(unsigned int (*hash_function)(void *) ght->counter=0; ght->list=NULL; ght->last=NULL; +#ifdef RAW + raw_test_pass(0xf004); +#endif return ght; } diff --git a/Robust/src/Runtime/GenericHashtable.h b/Robust/src/Runtime/GenericHashtable.h index 951f044c..832a8bd2 100755 --- a/Robust/src/Runtime/GenericHashtable.h +++ b/Robust/src/Runtime/GenericHashtable.h @@ -37,6 +37,9 @@ void genfreehashtable(struct genhashtable * ht); void genrehash(struct genhashtable * ht); void * getnext(struct genhashtable *,void *); int genputtable(struct genhashtable *, void *, void *); +#ifdef RAW +int genputtable_I(struct genhashtable *, void *, void *); +#endif void * gengettable(struct genhashtable *, void *); int gencontains(struct genhashtable *, void *); unsigned int genhashfunction(struct genhashtable *,void *); diff --git a/Robust/src/Runtime/ObjectHash.c b/Robust/src/Runtime/ObjectHash.c index fa5f5a36..affbc128 100755 --- a/Robust/src/Runtime/ObjectHash.c +++ b/Robust/src/Runtime/ObjectHash.c @@ -1,5 +1,9 @@ #include "ObjectHash.h" +#ifdef RAW +#include +#else #include +#endif #ifdef DMALLOC #include "dmalloc.h" #endif @@ -18,11 +22,16 @@ struct ObjectHash * noargallocateObjectHash() { } struct ObjectHash * allocateObjectHash(int size) { - struct ObjectHash *thisvar=(struct ObjectHash *)RUNMALLOC(sizeof(struct ObjectHash)); + struct ObjectHash *thisvar;//=(struct ObjectHash *)RUNMALLOC(sizeof(struct ObjectHash)); if (size <= 0) { +#ifdef RAW + raw_test_done(0xc001); +#else printf("Negative Hashtable size Exception\n"); - exit(-1); + exit(-1); +#endif } + thisvar=(struct ObjectHash *)RUNMALLOC(sizeof(struct ObjectHash)); thisvar->size = size; thisvar->bucket = (struct ObjectNode **) RUNMALLOC(sizeof(struct ObjectNode *)*size); /* Set allocation blocks*/ @@ -64,14 +73,16 @@ int ObjectHashremove(struct ObjectHash *thisvar, int key) { struct ObjectNode *toremove=*ptr; *ptr=(*ptr)->next; - if (toremove->lprev!=NULL) + if (toremove->lprev!=NULL) { toremove->lprev->lnext=toremove->lnext; - else + } else { thisvar->listhead=toremove->lnext; - if (toremove->lnext!=NULL) + } + if (toremove->lnext!=NULL) { toremove->lnext->lprev=toremove->lprev; - else + } else { thisvar->listtail=toremove->lprev; + } RUNFREE(toremove); thisvar->numelements--; @@ -155,6 +166,61 @@ int ObjectHashadd(struct ObjectHash * thisvar,int key, int data, int data2, int return 1; } +#ifdef RAW +int ObjectHashadd_I(struct ObjectHash * thisvar,int key, int data, int data2, int data3, int data4) { + /* Rehash code */ + unsigned int hashkey; + struct ObjectNode **ptr; + + if (thisvar->numelements>=thisvar->size) { + int newsize=2*thisvar->size+1; + struct ObjectNode ** newbucket = (struct ObjectNode **) RUNMALLOC_I(sizeof(struct ObjectNode *)*newsize); + int i; + for(i=thisvar->size-1;i>=0;i--) { + struct ObjectNode *ptr; + for(ptr=thisvar->bucket[i];ptr!=NULL;) { + struct ObjectNode * nextptr=ptr->next; + unsigned int newhashkey=(unsigned int)ptr->key % newsize; + ptr->next=newbucket[newhashkey]; + newbucket[newhashkey]=ptr; + ptr=nextptr; + } + } + thisvar->size=newsize; + RUNFREE(thisvar->bucket); + thisvar->bucket=newbucket; + } + + hashkey = (unsigned int)key % thisvar->size; + ptr = &thisvar->bucket[hashkey]; + + { + struct ObjectNode *node=RUNMALLOC_I(sizeof(struct ObjectNode)); + node->data=data; + node->data2=data2; + node->data3=data3; + node->data4=data4; + node->key=key; + node->next=(*ptr); + *ptr=node; + if (thisvar->listhead==NULL) { + thisvar->listhead=node; + thisvar->listtail=node; + node->lnext=NULL; + node->lprev=NULL; + } else { + node->lprev=NULL; + node->lnext=thisvar->listhead; + thisvar->listhead->lprev=node; + thisvar->listhead=node; + } + } + + thisvar->numelements++; + return 1; +} +#endif + bool ObjectHashcontainskey(struct ObjectHash *thisvar,int key) { unsigned int hashkey = (unsigned int)key % thisvar->size; diff --git a/Robust/src/Runtime/ObjectHash.h b/Robust/src/Runtime/ObjectHash.h index 4a7774a9..b3a565bd 100755 --- a/Robust/src/Runtime/ObjectHash.h +++ b/Robust/src/Runtime/ObjectHash.h @@ -24,6 +24,9 @@ void freeObjectHash(struct ObjectHash *); void ObjectHashrehash(struct ObjectHash * thisvar); int ObjectHashadd(struct ObjectHash *, int key, int data, int data2, int data3, int data4); +#ifdef RAW +int ObjectHashadd_I(struct ObjectHash *, int key, int data, int data2, int data3, int data4); +#endif int ObjectHashremove(struct ObjectHash *,int key); bool ObjectHashcontainskey(struct ObjectHash *,int key); bool ObjectHashcontainskeydata(struct ObjectHash *,int key, int data); diff --git a/Robust/src/Runtime/Queue.c b/Robust/src/Runtime/Queue.c index 0e3c42e8..90743065 100644 --- a/Robust/src/Runtime/Queue.c +++ b/Robust/src/Runtime/Queue.c @@ -5,7 +5,10 @@ #endif struct Queue * createQueue() { - return (struct Queue *)RUNMALLOC(sizeof(struct Queue)); + struct Queue * queue = (struct Queue *)RUNMALLOC(sizeof(struct Queue)); + queue->head = NULL; + queue->tail = NULL; + return queue; } void freeQueue(struct Queue * q) { @@ -31,6 +34,23 @@ struct QueueItem * addNewItem(struct Queue * queue, void * ptr) { return item; } +#ifdef RAW +struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr) { + struct QueueItem * item=RUNMALLOC_I(sizeof(struct QueueItem)); + item->objectptr=ptr; + item->queue=queue; + if (queue->head==NULL) { + queue->head=item; + queue->tail=item; + } else { + item->next=queue->head; + queue->head->prev=item; + queue->head=item; + } + return item; +} +#endif + struct QueueItem * findItem(struct Queue * queue, void *ptr) { struct QueueItem * item=queue->head; while(item!=NULL) { diff --git a/Robust/src/Runtime/Queue.h b/Robust/src/Runtime/Queue.h index ef25820d..033478bf 100644 --- a/Robust/src/Runtime/Queue.h +++ b/Robust/src/Runtime/Queue.h @@ -16,6 +16,9 @@ struct QueueItem { void freeQueue(struct Queue * q); struct Queue * createQueue(); struct QueueItem * addNewItem(struct Queue * queue, void * ptr); +#ifdef RAW +struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr); +#endif struct QueueItem * findItem(struct Queue * queue, void * ptr); void removeItem(struct Queue * queue, struct QueueItem * item); int isEmpty(struct Queue *queue); diff --git a/Robust/src/Runtime/SimpleHash.c b/Robust/src/Runtime/SimpleHash.c index 5e69d1d7..92fe695f 100755 --- a/Robust/src/Runtime/SimpleHash.c +++ b/Robust/src/Runtime/SimpleHash.c @@ -1,5 +1,9 @@ #include "SimpleHash.h" +#ifdef RAW +#include +#else #include +#endif #ifdef DMALLOC #include "dmalloc.h" #endif @@ -18,11 +22,16 @@ struct RuntimeHash * noargallocateRuntimeHash() { } struct RuntimeHash * allocateRuntimeHash(int size) { - struct RuntimeHash *thisvar=(struct RuntimeHash *)RUNMALLOC(sizeof(struct RuntimeHash)); + struct RuntimeHash *thisvar;//=(struct RuntimeHash *)RUNMALLOC(sizeof(struct RuntimeHash)); if (size <= 0) { +#ifdef RAW + raw_test_done(0xb001); +#else printf("Negative Hashtable size Exception\n"); - exit(-1); + exit(-1); +#endif } + thisvar=(struct RuntimeHash *)RUNMALLOC(sizeof(struct RuntimeHash)); thisvar->size = size; thisvar->bucket = (struct RuntimeNode **) RUNMALLOC(sizeof(struct RuntimeNode *)*size); /* Set allocation blocks*/ @@ -64,14 +73,16 @@ int RuntimeHashremovekey(struct RuntimeHash *thisvar, int key) { struct RuntimeNode *toremove=*ptr; *ptr=(*ptr)->next; - if (toremove->lprev!=NULL) + if (toremove->lprev!=NULL) { toremove->lprev->lnext=toremove->lnext; - else + } else { thisvar->listhead=toremove->lnext; - if (toremove->lnext!=NULL) + } + if (toremove->lnext!=NULL) { toremove->lnext->lprev=toremove->lprev; - else + } else{ thisvar->listtail=toremove->lprev; + } RUNFREE(toremove); thisvar->numelements--; @@ -94,14 +105,16 @@ int RuntimeHashremove(struct RuntimeHash *thisvar, int key, int data) { struct RuntimeNode *toremove=*ptr; *ptr=(*ptr)->next; - if (toremove->lprev!=NULL) + if (toremove->lprev!=NULL) { toremove->lprev->lnext=toremove->lnext; - else + } else { thisvar->listhead=toremove->lnext; - if (toremove->lnext!=NULL) + } + if (toremove->lnext!=NULL) { toremove->lnext->lprev=toremove->lprev; - else + } else { thisvar->listtail=toremove->lprev; + } RUNFREE(toremove); thisvar->numelements--; @@ -192,6 +205,68 @@ int RuntimeHashadd(struct RuntimeHash * thisvar,int key, int data) { return 1; } +#ifdef RAW +int RuntimeHashadd_I(struct RuntimeHash * thisvar,int key, int data) { + /* Rehash code */ + unsigned int hashkey; + struct RuntimeNode **ptr; + + if (thisvar->numelements>=thisvar->size) { + int newsize=2*thisvar->size+1; + struct RuntimeNode ** newbucket = (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*newsize); + int i; + for(i=thisvar->size-1;i>=0;i--) { + struct RuntimeNode *ptr; + for(ptr=thisvar->bucket[i];ptr!=NULL;) { + struct RuntimeNode * nextptr=ptr->next; + unsigned int newhashkey=(unsigned int)ptr->key % newsize; + ptr->next=newbucket[newhashkey]; + newbucket[newhashkey]=ptr; + ptr=nextptr; + } + } + thisvar->size=newsize; + RUNFREE(thisvar->bucket); + thisvar->bucket=newbucket; + } + + hashkey = (unsigned int)key % thisvar->size; + ptr = &thisvar->bucket[hashkey]; + + /* check that thisvar key/object pair isn't already here */ + /* TBD can be optimized for set v. relation */ + + while (*ptr) { + if ((*ptr)->key == key && (*ptr)->data == data) { + return 0; + } + ptr = &((*ptr)->next); + } + + { + struct RuntimeNode *node=RUNMALLOC_I(sizeof(struct RuntimeNode)); + node->data=data; + node->key=key; + node->next=(*ptr); + *ptr=node; + if (thisvar->listhead==NULL) { + thisvar->listhead=node; + thisvar->listtail=node; + node->lnext=NULL; + node->lprev=NULL; + } else { + node->lprev=NULL; + node->lnext=thisvar->listhead; + thisvar->listhead->lprev=node; + thisvar->listhead=node; + } + } + + thisvar->numelements++; + return 1; +} +#endif + bool RuntimeHashcontainskey(struct RuntimeHash *thisvar,int key) { unsigned int hashkey = (unsigned int)key % thisvar->size; diff --git a/Robust/src/Runtime/SimpleHash.h b/Robust/src/Runtime/SimpleHash.h index 7810120a..e777d541 100755 --- a/Robust/src/Runtime/SimpleHash.h +++ b/Robust/src/Runtime/SimpleHash.h @@ -24,6 +24,9 @@ void freeRuntimeHash(struct RuntimeHash *); void RuntimeHashrehash(struct RuntimeHash * thisvar); int RuntimeHashadd(struct RuntimeHash *, int key, int data); +#ifdef RAW +int RuntimeHashadd_I(struct RuntimeHash *, int key, int data); +#endif int RuntimeHashremovekey(struct RuntimeHash *,int key); int RuntimeHashremove(struct RuntimeHash *,int key, int data); bool RuntimeHashcontainskey(struct RuntimeHash *,int key); diff --git a/Robust/src/Runtime/checkpoint.c b/Robust/src/Runtime/checkpoint.c index d0dce59e..dd3be84d 100644 --- a/Robust/src/Runtime/checkpoint.c +++ b/Robust/src/Runtime/checkpoint.c @@ -20,7 +20,11 @@ extern void * to_heaptop; struct malloclist { struct malloclist *next; int size; +#ifdef RAW + char * space; +#else char space[]; +#endif }; struct malloclist * top=NULL; @@ -28,6 +32,7 @@ int offset=0; void * cpmalloc(int size) { int endoffset=offset+size; + int tmpoffset=0; if (top==NULL||endoffset>top->size) { int basesize=MALLOCSIZE; struct malloclist *tmp; @@ -39,7 +44,7 @@ void * cpmalloc(int size) { top->size=basesize; offset=0; } - int tmpoffset=offset; + tmpoffset=offset; offset+=size; return &top->space[tmpoffset]; } @@ -54,7 +59,9 @@ void freemalloc() { void checkvalid(void * ptr) { if (ptr>=curr_heapbase&&ptr<=curr_heaptop) { +#ifndef RAW printf("Valid\n"); +#endif } } @@ -73,7 +80,9 @@ void validitycheck(struct RuntimeHash *forward, struct RuntimeHash *reverse) { int offset=pointer[i]; void * ptr=*(void **) (((int) data) + offset); if (ptr!=NULL&&!RuntimeHashcontainskey(reverse, (int) ptr)) { +#ifndef RAW printf("Bad\n"); +#endif } checkvalid(ptr); } @@ -83,18 +92,22 @@ void validitycheck(struct RuntimeHash *forward, struct RuntimeHash *reverse) { RuntimeHashiterator(reverse, &rit); while(RunhasNext(&rit)) { struct ___Object___ * data=(struct ___Object___*) Runkey(&rit); + int type=0; + unsigned int * pointer=NULL; + int size; + int i; Runnext(&rit); - int type=data->type; - unsigned int * pointer=pointerarray[type]; - int size; - int i; + type=data->type; + pointer=pointerarray[type]; if (pointer!=0&&((int)pointer)!=1) { size=pointer[0]; for(i=1;i<=size;i++) { int offset=pointer[i]; void * ptr=*(void **) (((int) data) + offset); if (ptr!=NULL&&!RuntimeHashcontainskey(reverse, (int) ptr)) { +#ifndef RAW printf("Bad2\n"); +#endif } checkvalid(ptr); } @@ -131,9 +144,10 @@ void ** makecheckpoint(int numparams, void ** srcpointer, struct RuntimeHash * f RuntimeHashremove(todo, (int) ptr, (int) ptr); { void *cpy; + unsigned int * pointer=NULL; RuntimeHashget(forward, (int) ptr, (int *) &cpy); - unsigned int * pointer=pointerarray[type]; + pointer=pointerarray[type]; #ifdef TASK if (type==TAGTYPE) { void *objptr=((struct ___TagDescriptor___*)ptr)->flagptr; diff --git a/Robust/src/Runtime/file.c b/Robust/src/Runtime/file.c index 63f21bd5..6a13701d 100644 --- a/Robust/src/Runtime/file.c +++ b/Robust/src/Runtime/file.c @@ -1,7 +1,9 @@ #include #include #include -#include +//#ifndef RAW +//#include +//#endif #include #include "structdefs.h" #include "mem.h" @@ -17,7 +19,10 @@ void CALL11(___FileOutputStream______nativeClose____I, int fd, int fd) { } void CALL11(___FileOutputStream______nativeFlush____I, int fd, int fd) { + // not supported in RAW version +#ifndef RAW fsync(fd); +#endif } int CALL01(___FileOutputStream______nativeOpen_____AR_B, struct ArrayObject * ___filename___) { diff --git a/Robust/src/Runtime/mem.h b/Robust/src/Runtime/mem.h index ed927099..fa82a2c3 100644 --- a/Robust/src/Runtime/mem.h +++ b/Robust/src/Runtime/mem.h @@ -1,7 +1,9 @@ #ifndef MEMH #define MEMH #include +#ifndef RAW #include +#endif #ifdef BOEHM_GC #include "gc.h" @@ -14,9 +16,21 @@ #define RUNMALLOC(x) calloc(1,x) #define RUNFREE(x) free(x) #else +#ifdef RAW +void * mycalloc(int m, int size); +void * mycalloc_i(int m, int size); +void myfree(void * ptr); +#define FREEMALLOC(x) mycalloc(1,x) +#define RUNMALLOC(x) mycalloc(1,x) // handle interruption inside +#define RUNMALLOC_I(x) mycalloc_i(1,x) // with interruption blocked beforehand +#define RUNFREE(x) myfree(x); +//#define PTR(x) (32+(x-1)&~31) +#else #define FREEMALLOC(x) calloc(1,x) #define RUNMALLOC(x) calloc(1,x) #define RUNFREE(x) free(x) +//#define PTR(x) (x) +#endif #endif #endif #endif diff --git a/Robust/src/Runtime/multicoreruntime.c b/Robust/src/Runtime/multicoreruntime.c index efd6ac71..a65f8c08 100644 --- a/Robust/src/Runtime/multicoreruntime.c +++ b/Robust/src/Runtime/multicoreruntime.c @@ -5,8 +5,10 @@ #include #include #include +#ifndef RAW #include -#include "option.h" +#endif +//#include "option.h" extern int classsize[]; jmp_buf error_handler; @@ -25,6 +27,9 @@ int instaccum=0; #include "dmalloc.h" #endif +#ifdef RAW +void initializeexithandler() {} +#else void exithandler(int sig, siginfo_t *info, void * uap) { #ifdef DEBUG printf("exit in exithandler\n"); @@ -39,11 +44,15 @@ void initializeexithandler() { sigemptyset(&sig.sa_mask); sigaction(SIGUSR2, &sig, 0); } - +#endif /* This function inject failures */ void injectinstructionfailure() { +#ifdef RAW + // not supported in RAW version + return; +#else #ifdef TASK if (injectinstructionfailures) { if (numfailures==0) @@ -72,25 +81,49 @@ void injectinstructionfailure() { } #endif #endif +#endif } void CALL11(___System______exit____I,int ___status___, int ___status___) { #ifdef DEBUG printf("exit in CALL11\n"); #endif +#ifdef RAW + raw_test_done(___status___); +#else exit(___status___); +#endif +} + +void CALL11(___System______printI____I,int ___status___, int ___status___) { +#ifdef DEBUG + printf("printI in CALL11\n"); +#endif +#ifdef RAW + raw_test_pass(0x1111); + raw_test_pass_reg(___status___); +#else + printf("%d\n", ___status___); +#endif } long CALL00(___System______currentTimeMillis____) { +#ifdef RAW + // not supported in RAW version + return -1; +#else struct timeval tv; long long retval; gettimeofday(&tv, NULL); retval = tv.tv_sec; /* seconds */ retval*=1000; /* milliseconds */ retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */ return retval; +#endif } void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) { +#ifdef RAW +#else struct ArrayObject * chararray=VAR(___s___)->___value___; int i; int offset=VAR(___s___)->___offset___; @@ -98,6 +131,7 @@ void CALL01(___System______printString____L___String___,struct ___String___ * __ short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset]; putchar(sc); } +#endif } /* Object allocation function */ @@ -106,6 +140,8 @@ void CALL01(___System______printString____L___String___,struct ___String___ * __ void * allocate_new(void * ptr, int type) { struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]); v->type=type; + v->isolate = 1; + v->version = 0; #ifdef THREADS v->tid=0; v->lockentry=0; @@ -119,8 +155,12 @@ void * allocate_new(void * ptr, int type) { struct ArrayObject * allocate_newarray(void * ptr, int type, int length) { struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]); v->type=type; + v->isolate = 1; + v->version = 0; if (length<0) { +#ifndef RAW printf("ERROR: negative array\n"); +#endif return NULL; } v->___length___=length; @@ -136,6 +176,8 @@ struct ArrayObject * allocate_newarray(void * ptr, int type, int length) { void * allocate_new(int type) { struct ___Object___ * v=FREEMALLOC(classsize[type]); v->type=type; + v->isolate = 1; + v->version = 0; return v; } @@ -144,6 +186,8 @@ void * allocate_new(int type) { struct ArrayObject * allocate_newarray(int type, int length) { struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]); v->type=type; + v->isolate = 1; + v->version = 0; v->___length___=length; return v; } diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index 283f585e..12df2c22 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -1,5 +1,6 @@ #ifdef TASK #include "runtime.h" +#ifndef RAW #include "structdefs.h" #include "mem.h" #include "checkpoint.h" @@ -13,17 +14,12 @@ #include #include #include +#endif #ifdef RAW +#include +#include +#include #elif defined THREADSIMULATE -#if 0 -#include // for mmap -#include -#include -#include - -int offset_transObj = 0; -#endif - // use POSIX message queue // for each core, its message queue named as // /msgqueue_corenum @@ -37,6 +33,10 @@ extern float failurechance; extern int debugtask; extern int instaccum; +#ifdef RAW +#define TOTALCORE raw_get_num_tiles() +#endif + #ifdef CONSCHECK #include "instrument.h" #endif @@ -44,15 +44,38 @@ extern int instaccum; struct genhashtable * activetasks; struct genhashtable * failedtasks; struct taskparamdescriptor * currtpd; +#ifndef RAW struct RuntimeHash * forward; struct RuntimeHash * reverse; +#endif int corestatus[NUMCORES]; // records status of each core // 1: running tasks // 0: stall int numsendobjs[NUMCORES]; // records how many objects a core has sent out int numreceiveobjs[NUMCORES]; // records how many objects a core has received -#ifdef THREADSIMULATE +#ifdef RAW +struct RuntimeHash locktable; +static struct RuntimeHash* locktbl = &locktable; +void * curr_heapbase=0; +void * curr_heaptop=0; +int self_numsendobjs; +int self_numreceiveobjs; +int lockobj; +int lockresult; +bool lockflag; +#ifndef INTERRUPT +bool reside; +#endif +struct Queue objqueue; +int msgdata[30]; +int msgtype; +int msgdataindex; +int msglength; +void calCoords(int core_num, int* coordY, int* coordX); +void recvMsg(void); +#elif defined THREADSIMULATE +static struct RuntimeHash* locktbl; struct thread_data { int corenum; int argc; @@ -63,20 +86,127 @@ struct thread_data { struct thread_data thread_data_array[NUMCORES]; mqd_t mqd[NUMCORES]; static pthread_key_t key; -static struct RuntimeHash* locktbl; static pthread_rwlock_t rwlock_tbl; static pthread_rwlock_t rwlock_init; + +void run(void * arg); #endif + bool transStallMsg(int targetcore); void transTerminateMsg(int targetcore); -void run(void * arg); +int receiveObject(); bool getreadlock(void* ptr); void releasereadlock(void* ptr); +#ifdef RAW +bool getreadlock_I(void* ptr); +void releasereadlock_I(void* ptr); +#endif bool getwritelock(void* ptr); void releasewritelock(void* ptr); +#ifdef RAW +void flushAll(void); + +void flushAll(void) { + int i = 0; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + raw_test_pass(0xec00); + for(i = 0; i < 512; ++i) { + int base = i << 5; + int off1 = 1 << 14; + flushCacheline(base); + flushCacheline(base|off1); + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + raw_test_pass(0xec02); +} + +void recvMsg() { + raw_test_pass(0xefee); + raw_user_interrupts_off(); + raw_test_pass(0xef00); + receiveObject(); + raw_test_pass(0xefff); + raw_user_interrupts_on(); + raw_test_pass(0xefef); +} + +void begin() { +#else int main(int argc, char **argv) { -#ifdef THREADSIMULATE +#endif +#ifdef RAW + int i = 0; + int argc = 1; + char ** argv = NULL; + bool sendStall = false; + bool isfirst = true; + bool tocontinue = false; + struct QueueItem * objitem = NULL; + struct transObjInfo * objInfo = NULL; + int grount = 0; + bool allStall = true; + int sumsendobj = 0; + + raw_test_pass_reg(&locktable); + raw_test_pass_reg(&msglength); + raw_test_pass_reg(&i); + raw_test_pass(0xee01); + corenum = raw_get_abs_pos_x() + 4 * raw_get_abs_pos_y(); + + // initialize the arrays + if(STARTUPCORE == corenum) { + // startup core to initialize corestatus[] + for(i = 0; i < NUMCORES; ++i) { + corestatus[i] = 1; + numsendobjs[i] = 0; // assume all variables in RAW are local variables! MAY BE WRONG!!! + numreceiveobjs[i] = 0; + } + } + self_numsendobjs = 0; + self_numreceiveobjs = 0; + for(i = 0; i < 30; ++i) { + msgdata[i] = -1; + } + //msgdata = NULL; + msgtype = -1; + msgdataindex = 0; + msglength = 30; + raw_test_pass(0xee02); + + // create the lock table, lockresult table and obj queue + locktable.size = 20; + locktable.bucket = (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20); + /* Set allocation blocks*/ + locktable.listhead=NULL; + locktable.listtail=NULL; + /*Set data counts*/ + locktable.numelements = 0; + lockobj = 0; + lockresult = 0; + lockflag = false; +#ifndef INTERRUPT + reside = false; +#endif + objqueue.head = NULL; + objqueue.tail = NULL; + raw_test_pass(0xee03); + +#ifdef INTERRUPT + if (corenum < NUMCORES) { + // set up interrupts + setup_interrupts(); + start_gdn_avail_ints(recvMsg); + raw_user_interrupts_on(); + raw_test_pass(0xee04); + } +#endif + +#elif defined THREADSIMULATE errno = 0; int tids[NUMCORES]; int rc[NUMCORES]; @@ -130,23 +260,7 @@ int main(int argc, char **argv) { int rc_locktbl = pthread_rwlock_init(&rwlock_tbl, NULL); printf("[Main] initialize the rwlock for lock table: %d error: \n", rc_locktbl, strerror(rc_locktbl)); -/* if(argc < 2) { - printf("Usage: \n"); - fflush(stdout); - exit(-1); - } - - int cnum = 0; - char * number = argv[1]; - int len = strlen(number); - for(i = 0; i < len; ++i) { - cnum = (number[i] - '0') + cnum * 10; - } -*/ for(i = 0; i < NUMCORES; ++i) { - /* if(STARTUPCORE == i) { - continue; - }*/ thread_data_array[i].corenum = i; thread_data_array[i].argc = argc; thread_data_array[i].argv = argv; @@ -159,23 +273,13 @@ int main(int argc, char **argv) { fflush(stdout); exit(-1); } - }//*/ + } - /*// do stuff of startup core - thread_data_array[STARTUPCORE].corenum = STARTUPCORE; - thread_data_array[STARTUPCORE].argc = argc;// - 1; - thread_data_array[STARTUPCORE].argv = argv;//&argv[1]; - thread_data_array[STARTUPCORE].numsendobjs = 0; - thread_data_array[STARTUPCORE].numreceiveobjs = 0; - run(&thread_data_array[STARTUPCORE]);*/ pthread_exit(NULL); } void run(void* arg) { struct thread_data * my_tdata = (struct thread_data *)arg; - //corenum = my_tdata->corenum; - //void * ptr = malloc(sizeof(int)); - //*((int*)ptr) = my_tdata->corenum; pthread_setspecific(key, (void *)my_tdata->corenum); int argc = my_tdata->argc; char** argv = my_tdata->argv; @@ -190,26 +294,208 @@ void run(void* arg) { #ifdef CONSCHECK initializemmap(); #endif +#ifndef RAW processOptions(); +#endif initializeexithandler(); +#ifdef RAW + raw_test_pass(0xee05); +#endif /* Create table for failed tasks */ - failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, - (int (*)(void *,void *)) &comparetpd); +#ifdef RAW + if(corenum > NUMCORES - 1) { + failedtasks = NULL; + activetasks = NULL; + while(true) { + receiveObject(); + } + } else { + raw_test_pass(0xee06); +#endif + /*failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, + (int (*)(void *,void *)) &comparetpd);*/ + failedtasks = NULL; +#ifdef RAW + raw_test_pass(0xee07); +#endif /* Create queue of active tasks */ activetasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, (int (*)(void *,void *)) &comparetpd); +#ifdef RAW + raw_test_pass(0xee08); +#endif /* Process task information */ processtasks(); +#ifdef RAW + raw_test_pass(0xee09); +#endif /* Create startup object */ createstartupobject(argc, argv); +#ifdef RAW + raw_test_pass(0xee0a); +#endif +#ifdef RAW + raw_test_pass(0xee0b); + + while(true) { +/*#ifndef INTERRUPT + while(receiveObject() != -1) { + } +#endif*/ + + // check if there are new active tasks can be executed + executetasks(); + +#ifndef INTERRUPT + while(receiveObject() != -1) { + } +#endif + + raw_test_pass(0xee0c); + + // check if there are some pending objects, if yes, enqueue them and executetasks again + tocontinue = false; + raw_test_pass(0xee0d); + while(!isEmpty(&objqueue)) { + void * obj = NULL; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + raw_test_pass(0xeee1); + sendStall = false; + tocontinue = true; + objitem = getTail(&objqueue); + //obj = objitem->objectptr; + objInfo = (struct transObjInfo *)objitem->objectptr; + obj = objInfo->objptr; + raw_test_pass_reg((int)obj); + // grab lock and flush the obj + getreadlock_I(obj); + while(!lockflag) { + receiveObject(); + } + grount = lockresult; + raw_test_pass_reg(grount); + + lockresult = 0; + lockobj = 0; + lockflag = false; +#ifndef INTERRUPT + reside = false; +#endif + + if(grount == 1) { + int k = 0; + // flush the obj + for(k = 0; k < classsize[((struct ___Object___ *)obj)->type]; ++k) { + invalidateAddr(obj + k); + } + // enqueue the object + for(k = 0; k < objInfo->length; ++k) { + int taskindex = objInfo->queues[2 * k]; + int paramindex = objInfo->queues[2 * k + 1]; + struct parameterwrapper ** queues = &(paramqueues[corenum][taskindex][paramindex]); + raw_test_pass_reg(taskindex); + raw_test_pass_reg(paramindex); + enqueueObject_I(obj, queues, 1); + } + removeItem(&objqueue, objitem); + releasereadlock_I(obj); + RUNFREE(objInfo->queues); + RUNFREE(objInfo); + /*enqueueObject_I(obj, NULL, 0); + removeItem(&objqueue, objitem); + releasereadlock_I(obj);*/ + } else { + // can not get lock + // put it at the end of the queue + // and try to execute active tasks already enqueued first + removeItem(&objqueue, objitem); + addNewItem_I(&objqueue, objInfo); + break; + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + raw_test_pass(0xee0e); + } + + if(!tocontinue) { + // check if stop + if(STARTUPCORE == corenum) { + if(isfirst) { + raw_test_pass(0xee0f); + isfirst = false; + } +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + corestatus[corenum] = 0; + numsendobjs[corenum] = self_numsendobjs; + numreceiveobjs[corenum] = self_numreceiveobjs; + // check the status of all cores + allStall = true; + raw_test_pass_reg(NUMCORES); + for(i = 0; i < NUMCORES; ++i) { + raw_test_pass(0xe000 + corestatus[i]); + if(corestatus[i] != 0) { + allStall = false; + break; + } + } + if(allStall) { + // check if the sum of send objs and receive obj are the same + // yes->terminate + // no->go on executing + sumsendobj = 0; + for(i = 0; i < NUMCORES; ++i) { + sumsendobj += numsendobjs[i]; + raw_test_pass(0xf000 + numsendobjs[i]); + } + for(i = 0; i < NUMCORES; ++i) { + sumsendobj -= numreceiveobjs[i]; + raw_test_pass(0xf000 + numreceiveobjs[i]); + } + if(0 == sumsendobj) { + // terminate + raw_test_pass(0xee10); + raw_test_done(1); // All done. + } + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + } else { + if(!sendStall) { + raw_test_pass(0xee11); + if(isfirst) { + // wait for some time + int halt = 10000; + raw_test_pass(0xee12); + while(halt--){} + isfirst = false; + raw_test_pass(0xee13); + } else { + // send StallMsg to startup core + raw_test_pass(0xee14); + sendStall = transStallMsg(STARTUPCORE); + isfirst = true; + } + } else { + isfirst = true; + raw_test_pass(0xee15); + } + } + } + } + } +#elif defined THREADSIMULATE /* Start executing the tasks */ executetasks(); -#ifdef THREADSIMULATE - int i = 0; // check if there are new objects coming bool sendStall = false; @@ -251,21 +537,17 @@ void run(void* arg) { } if(0 == sumsendobj) { // terminate - // TODO - /* for(i = 0; i < NUMCORES; ++i) { - if(i != corenum) { - transTerminateMsg(i); - } - } - mq_close(mqd[corenum]);*/ // release all locks + int rc_tbl = pthread_rwlock_wrlock(&rwlock_tbl); + printf("[run, %d] getting the write lock for locktbl: %d error: \n", numofcore, rc_tbl, strerror(rc_tbl)); struct RuntimeIterator* it_lock = RuntimeHashcreateiterator(locktbl); while(0 != RunhasNext(it_lock)) { int key = Runkey(it_lock); pthread_rwlock_t* rwlock_obj = (pthread_rwlock_t*)Runnext(it_lock); int rc_des = pthread_rwlock_destroy(rwlock_obj); printf("[run, %d] destroy the rwlock for object: %d error: \n", numofcore, key, strerror(rc_des)); + RUNFREE(rwlock_obj); } freeRuntimeHash(locktbl); locktbl = NULL; @@ -366,7 +648,9 @@ void createstartupobject(int argc, char ** argv) { /* Set initialized flag for startup object */ flagorandinit(startupobject,1,0xFFFFFFFF); enqueueObject(startupobject, NULL, 0); - //enqueueObject(startupobject, objq4startupobj[corenum], numqueues4startupobj[corenum]); +#ifdef RAW + flushAll(); +#endif } int hashCodetpd(struct taskparamdescriptor *ftd) { @@ -394,15 +678,29 @@ void tagset(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * t #else void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { #endif + struct ArrayObject * ao=NULL; struct ___Object___ * tagptr=obj->___tags___; +#ifdef RAW + raw_test_pass(0xebb0); +#endif if (tagptr==NULL) { +#ifdef RAW + raw_test_pass(0xebb1); +#endif obj->___tags___=(struct ___Object___ *)tagd; } else { /* Have to check if it is already set */ if (tagptr->type==TAGTYPE) { struct ___TagDescriptor___ * td=(struct ___TagDescriptor___ *) tagptr; - if (td==tagd) +#ifdef RAW + raw_test_pass(0xebb2); +#endif + if (td==tagd) { +#ifdef RAW + raw_test_pass(0xebb3); +#endif return; + } #ifdef PRECISE_GC int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd}; struct ArrayObject * ao=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL); @@ -410,24 +708,49 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { tagd=(struct ___TagDescriptor___ *)ptrarray[3]; td=(struct ___TagDescriptor___ *) obj->___tags___; #else - struct ArrayObject * ao=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL); +#ifdef RAW + raw_test_pass(0xebb4); +#endif + ao=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL); +#endif +#ifdef RAW + raw_test_pass(0xebb5); #endif ARRAYSET(ao, struct ___TagDescriptor___ *, 0, td); ARRAYSET(ao, struct ___TagDescriptor___ *, 1, tagd); obj->___tags___=(struct ___Object___ *) ao; ao->___cachedCode___=2; +#ifdef RAW + raw_test_pass(0xebb6); +#endif } else { /* Array Case */ int i; struct ArrayObject *ao=(struct ArrayObject *) tagptr; +#ifdef RAW + raw_test_pass(0xebb7); +#endif for(i=0;i___cachedCode___;i++) { struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___*, i); - if (td==tagd) +#ifdef RAW + raw_test_pass(0xebb8); +#endif + if (td==tagd) { +#ifdef RAW + raw_test_pass(0xebb9); +#endif return; + } } if (ao->___cachedCode______length___) { +#ifdef RAW + raw_test_pass(0xebba); +#endif ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, tagd); ao->___cachedCode___++; +#ifdef RAW + raw_test_pass(0xebbb); +#endif } else { #ifdef PRECISE_GC int ptrarray[]={2,(int) ptr, (int) obj, (int) tagd}; @@ -437,19 +760,37 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { ao=(struct ArrayObject *)obj->___tags___; #else struct ArrayObject * aonew=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___); +#endif +#ifdef RAW + raw_test_pass(0xebbc); #endif aonew->___cachedCode___=ao->___length___+1; for(i=0;i___length___;i++) { +#ifdef RAW + raw_test_pass(0xebbd); +#endif ARRAYSET(aonew, struct ___TagDescriptor___*, i, ARRAYGET(ao, struct ___TagDescriptor___*, i)); } +#ifdef RAW + raw_test_pass(0xebbe); +#endif ARRAYSET(aonew, struct ___TagDescriptor___ *, ao->___length___, tagd); +#ifdef RAW + raw_test_pass(0xebbf); +#endif } } } { struct ___Object___ * tagset=tagd->flagptr; +#ifdef RAW + raw_test_pass(0xb008); +#endif if(tagset==NULL) { +#ifdef RAW + raw_test_pass(0xb009); +#endif tagd->flagptr=obj; } else if (tagset->type!=OBJECTARRAYTYPE) { #ifdef PRECISE_GC @@ -464,9 +805,15 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { ARRAYSET(ao, struct ___Object___ *, 1, obj); ao->___cachedCode___=2; tagd->flagptr=(struct ___Object___ *)ao; +#ifdef RAW + raw_test_pass(0xb00a); +#endif } else { struct ArrayObject *ao=(struct ArrayObject *) tagset; if (ao->___cachedCode______length___) { +#ifdef RAW + raw_test_pass(0xb00b); +#endif ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj); } else { int i; @@ -485,6 +832,9 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { } ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj); tagd->flagptr=(struct ___Object___ *) aonew; +#ifdef RAW + raw_test_pass(0xb00c); +#endif } } } @@ -504,7 +854,10 @@ void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { if ((struct ___TagDescriptor___ *)tagptr==tagd) obj->___tags___=NULL; else +#ifndef RAW printf("ERROR 1 in tagclear\n"); +#endif + ; } else { struct ArrayObject *ao=(struct ArrayObject *) tagptr; int i; @@ -520,7 +873,10 @@ void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { goto PROCESSCLEAR; } } +#ifndef RAW printf("ERROR 2 in tagclear\n"); +#endif + ; } PROCESSCLEAR: { @@ -529,7 +885,10 @@ void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { if (tagset==obj) tagd->flagptr=NULL; else +#ifndef RAW printf("ERROR 3 in tagclear\n"); +#endif + ; } else { struct ArrayObject *ao=(struct ArrayObject *) tagset; int i; @@ -545,7 +904,9 @@ void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { goto ENDCLEAR; } } +#ifndef RAW printf("ERROR 4 in tagclear\n"); +#endif } } ENDCLEAR: @@ -581,6 +942,10 @@ void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** q int oldflag=((int *)ptr)[1]; int flag=ormask|oldflag; flag&=andmask; +#ifdef RAW + raw_test_pass(0xaa000000 + oldflag); + raw_test_pass(0xaa000000 + flag); +#endif flagbody(ptr, flag, queues, length, false); } } @@ -603,6 +968,10 @@ void flagorandinit(void * ptr, int ormask, int andmask) { int oldflag=((int *)ptr)[1]; int flag=ormask|oldflag; flag&=andmask; +#ifdef RAW + raw_test_pass(0xaa100000 + oldflag); + raw_test_pass(0xaa100000 + flag); +#endif flagbody(ptr,flag,NULL,0,true); } @@ -611,28 +980,39 @@ void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqu int i = 0; struct parameterwrapper ** queues = vqueues; int length = vlength; + int next; + int UNUSED, UNUSED2; + int * enterflags = NULL; if((!isnew) && (queues == NULL)) { #ifdef THREADSIMULATE int numofcore = pthread_getspecific(key); queues = objectqueues[numofcore][ptr->type]; length = numqueues[numofcore][ptr->type]; #else +#ifdef RAW + if(corenum < NUMCORES) { +#endif queues = objectqueues[corenum][ptr->type]; length = numqueues[corenum][ptr->type]; +#ifdef RAW + } else { + return; + } +#endif #endif } ptr->flag=flag; +#ifdef RAW + raw_test_pass(0xbb000000 + ptr->flag); +#endif /*Remove object from all queues */ for(i = 0; i < length; ++i) { flagptr = queues[i]; - int next; - int UNUSED, UNUSED2; - int * enterflags; ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2); ObjectHashremove(flagptr->objectset, (int)ptr); if (enterflags!=NULL) - free(enterflags); + RUNFREE(enterflags); } } @@ -643,8 +1023,16 @@ void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqu struct QueueItem *tmpptr; struct parameterwrapper * parameter=NULL; int j; + int i; + struct parameterwrapper * prevptr=NULL; + struct ___Object___ *tagptr=NULL; struct parameterwrapper ** queues = vqueues; int length = vlength; +#ifdef RAW + if(corenum > NUMCORES - 1) { + return; + } +#endif if(queues == NULL) { #ifdef THREADSIMULATE int numofcore = pthread_getspecific(key); @@ -655,14 +1043,11 @@ void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqu length = numqueues[corenum][ptr->type]; #endif } - int i; - struct parameterwrapper * prevptr=NULL; - struct ___Object___ *tagptr=ptr->___tags___; + tagptr=ptr->___tags___; /* Outer loop iterates through all parameter queues an object of this type could be in. */ - - for(j = 0; j < length; ++j) { + for(j = 0; j < length; ++j) { parameter = queues[j]; /* Check tags */ if (parameter->numbertags>0) { @@ -698,6 +1083,12 @@ void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqu int andmask=parameter->intarray[i*2]; int checkmask=parameter->intarray[i*2+1]; if ((ptr->flag&andmask)==checkmask) { +#ifdef RAW + raw_test_pass(0xcc000000 + andmask); + raw_test_pass_reg((int)ptr); + raw_test_pass(0xcc000000 + ptr->flag); + raw_test_pass(0xcc000000 + checkmask); +#endif enqueuetasks(parameter, prevptr, ptr, NULL, 0); prevptr=parameter; break; @@ -709,41 +1100,192 @@ void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqu } } +#ifdef RAW +void enqueueObject_I(void * vptr, struct parameterwrapper ** vqueues, int vlength) { + struct ___Object___ *ptr = (struct ___Object___ *)vptr; + + { + struct QueueItem *tmpptr; + struct parameterwrapper * parameter=NULL; + int j; + int i; + struct parameterwrapper * prevptr=NULL; + struct ___Object___ *tagptr=NULL; + struct parameterwrapper ** queues = vqueues; + int length = vlength; +#ifdef RAW + if(corenum > NUMCORES - 1) { + return; + } +#endif + if(queues == NULL) { +#ifdef THREADSIMULATE + int numofcore = pthread_getspecific(key); + queues = objectqueues[numofcore][ptr->type]; + length = numqueues[numofcore][ptr->type]; +#else + queues = objectqueues[corenum][ptr->type]; + length = numqueues[corenum][ptr->type]; +#endif + } +#ifdef RAW + raw_test_pass(0xeaa1); + raw_test_pass_reg(queues); + raw_test_pass_reg(length); +#endif + tagptr=ptr->___tags___; + + /* Outer loop iterates through all parameter queues an object of + this type could be in. */ + for(j = 0; j < length; ++j) { + parameter = queues[j]; + /* Check tags */ + if (parameter->numbertags>0) { +#ifdef RAW + raw_test_pass(0xeaa2); + raw_test_pass_reg(tagptr); +#endif + if (tagptr==NULL) + goto nextloop;//that means the object has no tag but that param needs tag + else if(tagptr->type==TAGTYPE) {//one tag + struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr; +#ifdef RAW + raw_test_pass(0xeaa3); +#endif + for(i=0;inumbertags;i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + if (tagid!=tagptr->flag) { +#ifdef RAW + raw_test_pass(0xeaa4); +#endif + goto nextloop; /*We don't have this tag */ + } + } + } else {//multiple tags + struct ArrayObject * ao=(struct ArrayObject *) tagptr; +#ifdef RAW + raw_test_pass(0xeaa5); +#endif + for(i=0;inumbertags;i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + int j; + for(j=0;j___cachedCode___;j++) { + if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag) { + goto foundtag; + } + } +#ifdef RAW + raw_test_pass(0xeaa6); +#endif + goto nextloop; + foundtag: + ; + } + } + } + + /* Check flags */ + for(i=0;inumberofterms;i++) { + int andmask=parameter->intarray[i*2]; + int checkmask=parameter->intarray[i*2+1]; +#ifdef RAW + raw_test_pass(0xeaa7); + raw_test_pass(0xcc000000 + andmask); + raw_test_pass_reg(ptr); + raw_test_pass(0xcc000000 + ptr->flag); + raw_test_pass(0xcc000000 + checkmask); +#endif + if ((ptr->flag&andmask)==checkmask) { +#ifdef RAW + raw_test_pass(0xeaa8); +#endif + enqueuetasks_I(parameter, prevptr, ptr, NULL, 0); + prevptr=parameter; + break; + } + } + nextloop: + ; + } + } +} + +// helper function to compute the coordinates of a core from the core number +void calCoords(int core_num, int* coordY, int* coordX) { + *coordX = core_num % 4; + *coordY = core_num / 4; +} +#endif + +/* Message format for RAW version: + * type + Msgbody + * type: 0 -- transfer object + * 1 -- transfer stall msg + * 2 -- lock request + * 3 -- lock grount + * 4 -- lock deny + * 5 -- lock release + * + * ObjMsg: 0 + size of msg + obj's address + (task index + param index)+ + * StallMsg: 1 + corenum + sendobjs + receiveobjs (size is always 4 * sizeof(int)) + * LockMsg: 2 + lock type + obj pointer + request core (size is always 4 * sizeof(int)) + * 3/4/5 + lock type + obj pointer (size is always 3 * sizeof(int)) + * lock type: 0 -- read; 1 -- write + */ + // transfer an object to targetcore // format: object -void transferObject(void * obj, int targetcore) { +void transferObject(struct transObjInfo * transObj) { + void * obj = transObj->objptr; int type=((int *)obj)[0]; - assert(type < NUMCLASSES); // can only transfer normal object int size=classsize[type]; + int targetcore = transObj->targetcore; + //assert(type < NUMCLASSES); // can only transfer normal object #ifdef RAW + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + //int isshared = 0; + // for 32 bit machine, the size of fixed part is always 3 words + //int msgsize = sizeof(int) * 2 + sizeof(void *); + int msgsize = 3 + transObj->length * 2; + int i = 0; -#elif defined THREADSIMULATE -#if 0 - // use shared memory to transfer objects between cores - int fd = 0; // mapped file - void * p_map = NULL; - char * filepath = "/scratch/transObj/file_" + targetcore + ".txt"; - int offset; - // open the file - fd = open(filepath, O_CREAT|O_WRONLY|O_APPEND, 00777); // append to end of the file - offset = lseek(fd, 0, SEEK_CUR); - if(offset == -1) { - printf("fail to open file " + filepath + " in transferObject.\n"); - fflush(stdout); - exit(-1); + struct ___Object___ * newobj = (struct ___Object___ *)obj; + /*if(0 == newobj->isolate) { + isshared = 1; + }*/ + + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + gdn_send(0); + raw_test_pass(0); + gdn_send(msgsize); + raw_test_pass_reg(msgsize); + gdn_send(obj); + raw_test_pass_reg(obj); + //gdn_send(isshared); + //raw_test_pass_reg(isshared); + for(i = 0; i < transObj->length; ++i) { + int taskindex = transObj->queues[2*i]; + int paramindex = transObj->queues[2*i+1]; + gdn_send(taskindex); + raw_test_pass_reg(taskindex); + gdn_send(paramindex); + raw_test_pass_reg(paramindex); } - lseek(fd, size + sizeof(int)*2, SEEK_CUR); - write(fd, "", 1); - p_map = (void *)mmap(NULL,size+sizeof(int)*2,PROT_WRITE,MAP_SHARED,fd,offset); - close(fd); - memcpy(p_map, type, sizeof(int)); - memcpy(p_map+sizeof(int), corenum, sizeof(int)); - memcpy((p_map+sizeof(int)*2), obj, size); - munmap(p_map, size+sizeof(int)*2); - //printf( "umap ok \n" ); -#endif - + raw_test_pass(0xffff); + ++(self_numsendobjs); +#elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); // use POSIX message queue to transfer objects between cores @@ -777,19 +1319,28 @@ void transferObject(void * obj, int targetcore) { fflush(stdout); exit(-1); } - struct ___Object___ * newobj = (struct ___Object___ *)obj; + /*struct ___Object___ * newobj = (struct ___Object___ *)obj; if(0 == newobj->isolate) { newobj = RUNMALLOC(size); memcpy(newobj, obj, size); newobj->original=obj; - } + }*/ + struct transObjInfo * tmptransObj = RUNMALLOC(sizeof(struct transObjInfo)); + memcpy(tmptransObj, transObj, sizeof(struct transObjInfo)); + int * tmpqueue = RUNMALLOC(sizeof(int)*2*tmptransObj->length); + memcpy(tmpqueue, tmptransObj->queues, sizeof(int)*2*tmptransObj->length); + tmptransObj->queues = tmpqueue; + struct ___Object___ * newobj = RUNMALLOC(sizeof(struct ___Object___)); + newobj->type = ((struct ___Object___ *)obj)->type; + newobj->original = (struct ___Object___ *)tmptransObj; int ret; do { - ret=mq_send(mqdnum, (void *)newobj, size, 0); // send the object into the queue + ret=mq_send(mqdnum, (void *)newobj, sizeof(struct ___Object___), 0); // send the object into the queue if(ret != 0) { printf("[transferObject, %d] mq_send to %s returned: %d, error: %s\n", numofcore, path, ret, strerror(errno)); } - }while(ret!=0); + }while(ret!=0); + RUNFREE(newobj); if(numofcore == STARTUPCORE) { ++numsendobjs[numofcore]; } else { @@ -802,43 +1353,40 @@ void transferObject(void * obj, int targetcore) { // send terminate message to targetcore // format: -1 bool transStallMsg(int targetcore) { - struct ___Object___ newobj; - // use the first four int field to hold msgtype/corenum/sendobj/receiveobj - newobj.type = -1; - #ifdef RAW - newobj.flag = corenum; - newobj.___cachedHash___ = thread_data_array[corenum].numsendobjs; - newobj.___cachedCode___ = thread_data_array[corenum].numreceiveobjs; - + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + // for 32 bit machine, the size is always 4 words + //int msgsize = sizeof(int) * 4; + int msgsize = 4; + + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + gdn_send(1); + raw_test_pass(1); + gdn_send(corenum); + raw_test_pass_reg(corenum); + gdn_send(self_numsendobjs); + raw_test_pass_reg(self_numsendobjs); + gdn_send(self_numreceiveobjs); + raw_test_pass_reg(self_numreceiveobjs); + raw_test_pass(0xffff); + return true; #elif defined THREADSIMULATE + struct ___Object___ *newobj = RUNMALLOC(sizeof(struct ___Object___)); + // use the first four int field to hold msgtype/corenum/sendobj/receiveobj + newobj->type = -1; int numofcore = pthread_getspecific(key); - newobj.flag = numofcore; - newobj.___cachedHash___ = thread_data_array[numofcore].numsendobjs; - newobj.___cachedCode___ = thread_data_array[numofcore].numreceiveobjs; -#if 0 - // use shared memory to transfer objects between cores - int fd = 0; // mapped file - void * p_map = NULL; - char * filepath = "/scratch/transObj/file_" + targetcore + ".txt"; - int offset; - // open the file - fd = open(filepath, O_CREAT|O_WRONLY|O_APPEND, 00777); // append to end of the file - offset = lseek(fd, 0, SEEK_CUR); - if(offset == -1) { - printf("fail to open file " + filepath + " in transferObject.\n"); - fflush(stdout); - exit(-1); - } - lseek(fd, sizeof(int)*2, SEEK_CUR); - write(fd, "", 1); - p_map = (void *)mmap(NULL,sizeof(int)*2,PROT_WRITE,MAP_SHARED,fd,offset); - close(fd); - memcpy(p_map, type, sizeof(int)); - memcpy(p_map+sizeof(int), corenum, sizeof(int)); - munmap(p_map, sizeof(int)*2); - //printf( "umap ok \n" ); -#endif + newobj->flag = numofcore; + newobj->___cachedHash___ = thread_data_array[numofcore].numsendobjs; + newobj->___cachedCode___ = thread_data_array[numofcore].numreceiveobjs; // use POSIX message queue to send stall msg to startup core assert(targetcore == STARTUPCORE); @@ -873,108 +1421,279 @@ bool transStallMsg(int targetcore) { exit(-1); } int ret; - ret=mq_send(mqdnum, (void *)&newobj, sizeof(struct ___Object___), 0); // send the object into the queue + ret=mq_send(mqdnum, (void *)newobj, sizeof(struct ___Object___), 0); // send the object into the queue if(ret != 0) { printf("[transStallMsg, %d] mq_send to %s returned: %d, error: %s\n", numofcore, path, ret, strerror(errno)); + RUNFREE(newobj); return false; } else { printf("[transStallMsg, %d] mq_send to %s returned: $%x\n", numofcore, path, ret); - printf(" to %s index: %d, sendobjs: %d, receiveobjs: %d\n", path, newobj.flag, newobj.___cachedHash___, newobj.___cachedCode___); + printf(" to %s index: %d, sendobjs: %d, receiveobjs: %d\n", path, newobj->flag, newobj->___cachedHash___, newobj->___cachedCode___); + RUNFREE(newobj); return true; } #endif } -#if 0 -// send terminate message to targetcore -// format: -1 -void transTerminateMsg(int targetcore) { - // use the first four int field to hold msgtype/corenum/sendobj/receiveobj - int type = -2; - -#ifdef RAW -#elif defined THREADSIMULATE - - // use POSIX message queue to send stall msg to startup core - assert(targetcore != STARTUPCORE); - mqd_t mqdnum; - char corenumstr[3]; - int sourcelen = 0; - if(targetcore < 10) { - corenumstr[0] = targetcore + '0'; - corenumstr[1] = '\0'; - sourcelen = 1; - } else if(corenum < 100) { - corenumstr[1] = targetcore % 10 + '0'; - corenumstr[0] = (targetcore / 10) + '0'; - corenumstr[2] = '\0'; - sourcelen = 2; - } else { - printf("Error: targetcore >= 100\n"); - fflush(stdout); - exit(-1); - } - char * pathhead = "/msgqueue_"; - int targetlen = strlen(pathhead); - char path[targetlen + sourcelen + 1]; - strcpy(path, pathhead); - strncat(path, corenumstr, sourcelen); - int oflags = O_WRONLY|O_NONBLOCK; - int omodes = S_IRWXU|S_IRWXG|S_IRWXO; - mqdnum = mq_open(path, oflags, omodes, NULL); - if(mqdnum==-1) { - printf("[transStallMsg] mq_open fail: %d, error: %s\n", mqdnum, strerror(errno)); - fflush(stdout); - exit(-1); - } - int ret; - do { - ret=mq_send(mqdnum, (void *)&type, sizeof(int), 0); // send the object into the queue - if(ret != 0) { - printf("[transStallMsg] mq_send returned: %d, error: %s\n", ret, strerror(errno)); - } - }while(ret != 0); -#endif -} -#endif // receive object transferred from other cores // or the terminate message from other cores -// format: type [+ object] +// NOTICE: following format is for threadsimulate version only +// RAW version please see previous description +// format: type + object // type: -1--stall msg // !-1--object // return value: 0--received an object // 1--received nothing // 2--received a Stall Msg +// 3--received a lock Msg +// RAW version: -1 -- received nothing +// otherwise -- received msg type int receiveObject() { -#ifdef RAW - -#elif defined THREADSIMULATE -#if 0 - char * filepath = "/scratch/transObj/file_" + corenum + ".txt"; - int fd = 0; - void * p_map = NULL; - int type = 0; - int sourcecorenum = 0; - int size = 0; - fd = open(filepath, O_CREAT|O_RDONLY, 00777); - lseek(fd, offset_transObj, SEEK_SET); - p_map = (void*)mmap(NULL,sizeof(int)*2,PROT_READ,MAP_SHARED,fd,offset_transObj); - type = *(int*)p_map; - sourcecorenum = *(int*)(p_map+sinzeof(int)); - offset_transObj += sizeof(int)*2; - munmap(p_map,sizeof(int)*2); - if(type == -1) { - // sourecorenum has terminated - ++offset_transObj; - return; +#ifdef RAW + bool deny = false; + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + int targetcore = 0; + if(gdn_input_avail() == 0) { + if(corenum < NUMCORES) { + raw_test_pass(0xd001); + } + return -1; + } + raw_test_pass(0xcccc); + while((gdn_input_avail() != 0) && (msgdataindex < msglength)) { + msgdata[msgdataindex] = gdn_receive(); + if(msgdataindex == 0) { + if(msgdata[0] > 2) { + msglength = 3; + } else if(msgdata[0] > 0) { + msglength = 4; + } + } else if((msgdataindex == 1) && (msgdata[0] == 0)) { + msglength = msgdata[msgdataindex]; + } + raw_test_pass_reg(msgdata[msgdataindex]); + msgdataindex++; + + /*if(msgdataindex == 0) { + // type + msgtype = gdn_receive(); + if(msgtype > 2) { + msglength = 3; + } else { + msglength = 4; + } + if(msgtype != 0) { + msgdata = (int *)RUNMALLOC_I(msglength * sizeof(int)); + msgdata[msgdataindex] = msgtype; + } + raw_test_pass_reg(msgtype); + } else if((msgdataindex == 1) && (msgtype == 0)) { + // object transfer msg + msglength = gdn_receive(); + msgdata = (int *)RUNMALLOC_I(msglength * sizeof(int)); + msgdata[0] = msgtype; + msgdata[msgdataindex] = msglength; + raw_test_pass_reg(msgdata[msgdataindex]); + } else { + msgdata[msgdataindex] = gdn_receive(); + raw_test_pass_reg(msgdata[msgdataindex]); + } + msgdataindex++;*/ } - size = classsize[type]; - p_map = (void*)mmap(NULL,size,PROT_READ,MAP_SHARED,fd,offset_transObj); - struct ___Object___ * newobj=RUNMALLOC(size); - memcpy(newobj, p_map, size); - ++offset_transObj; - enqueueObject(newobj,NULL,0); + raw_test_pass(0xffff); + if(msgdataindex == msglength) { + // received a whole msg + int type, data1, data2; // will receive at least 3 words including type + type = msgdata[0]; + data1 = msgdata[1]; + data2 = msgdata[2]; + switch(type) { + case 0: { + // receive a object transfer msg + struct transObjInfo * transObj = RUNMALLOC_I(sizeof(struct transObjInfo)); + int k = 0; + if(corenum > NUMCORES - 1) { + raw_test_done(0xa00a); + } + // store the object and its corresponding queue info, enqueue it later + transObj->objptr = (void *)data2; // data1 is now size of the msg + transObj->length = (msglength - 3) / 2; + transObj->queues = RUNMALLOC_I(sizeof(int)*(msglength - 3)); + for(k = 0; k < transObj->length; ++k) { + transObj->queues[2*k] = msgdata[3+2*k]; + raw_test_pass_reg(transObj->queues[2*k]); + transObj->queues[2*k+1] = msgdata[3+2*k+1]; + raw_test_pass_reg(transObj->queues[2*k+1]); + } + //memcpy(transObj->queues, msgdata[3], sizeof(int)*(msglength - 3)); + addNewItem_I(&objqueue, (void *)transObj); + ++(self_numreceiveobjs); + raw_test_pass(0xe881); + /* + addNewItem_I(&objqueue, (void *)data2); + ++(self_numreceiveobjs); + raw_test_pass(0xe881);*/ + break; + } + case 1: { + // receive a stall msg + if(corenum != STARTUPCORE) { + // non startup core can not receive stall msg + // return -1 + raw_test_done(0xa001); + } + if(data1 < NUMCORES) { + raw_test_pass(0xe882); + corestatus[data1] = 0; + numsendobjs[data1] = data2; + numreceiveobjs[data1] = msgdata[3]; + } + break; + } + case 2: { + // receive lock request msg + // for 32 bit machine, the size is always 3 words + //int msgsize = sizeof(int) * 3; + int msgsize = 3; + // lock request msg, handle it right now + // check to see if there is a lock exist in locktbl for the required obj + int data3 = msgdata[3]; + deny = false; + if(!RuntimeHashcontainskey(locktbl, data2)) { + // no locks for this object + // first time to operate on this shared object + // create a lock for it + // the lock is an integer: 0 -- stall, >0 -- read lock, -1 -- write lock + raw_test_pass(0xe883); + if(data1 == 0) { + RuntimeHashadd_I(locktbl, data2, 1); + } else { + RuntimeHashadd_I(locktbl, data2, -1); + } + } else { + int rwlock_obj = 0; + raw_test_pass(0xe884); + RuntimeHashget(locktbl, data2, &rwlock_obj); + raw_test_pass_reg(rwlock_obj); + if(0 == rwlock_obj) { + if(data1 == 0) { + rwlock_obj = 1; + } else { + rwlock_obj = -1; + } + RuntimeHashremovekey(locktbl, data2); + RuntimeHashadd_I(locktbl, data2, rwlock_obj); + } else if((rwlock_obj > 0) && (data1 == 0)) { + // read lock request and there are only read locks + rwlock_obj++; + RuntimeHashremovekey(locktbl, data2); + RuntimeHashadd_I(locktbl, data2, rwlock_obj); + } else { + deny = true; + } + raw_test_pass_reg(rwlock_obj); + } + targetcore = data3; + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + if(deny == true) { + // deny the lock request + gdn_send(4); // lock request + raw_test_pass(4); + } else { + // grount the lock request + gdn_send(3); // lock request + raw_test_pass(3); + } + gdn_send(data1); // lock type + raw_test_pass_reg(data1); + gdn_send(data2); // lock target + raw_test_pass_reg(data2); + raw_test_pass(0xffff); + break; + } + case 3: { + // receive lock grount msg + if(corenum > NUMCORES - 1) { + raw_test_done(0xa00b); + } + if(lockobj == data2) { + lockresult = 1; + lockflag = true; +#ifndef INTERRUPT + reside = false; +#endif + } else { + // conflicts on lockresults + raw_test_done(0xa002); + } + break; + } + case 4: { + // receive lock grount/deny msg + if(corenum > NUMCORES - 1) { + raw_test_done(0xa00c); + } + if(lockobj == data2) { + lockresult = 0; + lockflag = true; +#ifndef INTERRUPT + reside = false; #endif + } else { + // conflicts on lockresults + raw_test_done(0xa003); + } + break; + } + case 5: { + // receive lock release msg + if(!RuntimeHashcontainskey(locktbl, data2)) { + // no locks for this object, something is wrong + raw_test_done(0xa004); + } else { + int rwlock_obj = 0; + RuntimeHashget(locktbl, data2, &rwlock_obj); + raw_test_pass(0xe885); + raw_test_pass_reg(rwlock_obj); + if(data1 == 0) { + rwlock_obj--; + } else { + rwlock_obj++; + } + RuntimeHashremovekey(locktbl, data2); + RuntimeHashadd_I(locktbl, data2, rwlock_obj); + raw_test_pass_reg(rwlock_obj); + } + break; + } + default: + break; + } + //RUNFREE(msgdata); + //msgdata = NULL; + for(msgdataindex--;msgdataindex > 0; --msgdataindex) { + msgdata[msgdataindex] = -1; + } + msgtype = -1; + //msgdataindex = 0; + msglength = 30; + raw_test_pass(0xe886); + return type; + } else { + // not a whole msg + raw_test_pass(0xe887); + return -2; + } +#elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); // use POSIX message queue to transfer object int msglen = 0; @@ -1008,10 +1727,27 @@ int receiveObject() { } else { ++(thread_data_array[numofcore].numreceiveobjs); } - struct ___Object___ * newobj=RUNMALLOC(msglen); - memcpy(newobj, msgptr, msglen); - free(msgptr); - enqueueObject(newobj, NULL, 0); + struct ___Object___ * tmpptr = (struct ___Object___ *)msgptr; + struct transObjInfo * transObj = (struct transObjInfo *)tmpptr->original; + tmpptr = (struct ___Object___ *)(transObj->objptr); + int type = tmpptr->type; + int size=classsize[type]; + struct ___Object___ * newobj=RUNMALLOC(size); + memcpy(newobj, tmpptr, size); + if(0 == newobj->isolate) { + newobj->original=tmpptr; + } + RUNFREE(msgptr); + tmpptr = NULL; + int k = 0; + for(k = 0; k < transObj->length; ++k) { + int taskindex = transObj->queues[2 * k]; + int paramindex = transObj->queues[2 * k + 1]; + struct parameterwrapper ** queues = &(paramqueues[numofcore][taskindex][paramindex]); + enqueueObject(newobj, queues, 1); + } + RUNFREE(transObj->queues); + RUNFREE(transObj); return 0; } #endif @@ -1019,13 +1755,88 @@ int receiveObject() { bool getreadlock(void * ptr) { #ifdef RAW + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + int targetcore = ((int)ptr) % TOTALCORE; + // for 32 bit machine, the size is always 4 words + //int msgsize = sizeof(int) * 4; + int msgsize = 4; + + lockobj = (int)ptr; + lockflag = false; +#ifndef INTERRUPT + reside = false; +#endif + lockresult = 0; + + if(targetcore == corenum) { + // reside on this core + bool deny = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // no locks for this object + // first time to operate on this shared object + // create a lock for it + // the lock is an integer: 0 -- stall, >0 -- read lock, -1 -- write lock + RuntimeHashadd_I(locktbl, (int)ptr, 1); + } else { + int rwlock_obj = 0; + RuntimeHashget(locktbl, (int)ptr, &rwlock_obj); + if(-1 != rwlock_obj) { + rwlock_obj++; + RuntimeHashremovekey(locktbl, (int)ptr); + RuntimeHashadd_I(locktbl, (int)ptr, rwlock_obj); + } else { + deny = true; + } + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + if(lockobj == (int)ptr) { + if(deny) { + lockresult = 0; + } else { + lockresult = 1; + } + lockflag = true; +#ifndef INTERRUPT + reside = true; +#endif + } else { + // conflicts on lockresults + raw_test_done(0xa005); + } + return true; + } + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + gdn_send(2); // lock request + raw_test_pass(2); + gdn_send(0); // read lock + raw_test_pass(0); + gdn_send(ptr); + raw_test_pass_reg(ptr); + gdn_send(corenum); + raw_test_pass_reg(corenum); + raw_test_pass(0xffff); + return true; #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); int rc = pthread_rwlock_tryrdlock(&rwlock_tbl); printf("[getreadlock, %d] getting the read lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); - if(EBUSY == rc) { + if(0 != rc) { return false; } if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { @@ -1040,17 +1851,23 @@ bool getreadlock(void * ptr) { printf("[getreadlock, %d] initialize the rwlock for object %d: %d error: \n", numofcore, (int)ptr, rc, strerror(rc)); rc = pthread_rwlock_trywrlock(&rwlock_tbl); printf("[getreadlock, %d] getting the write lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); - if(EBUSY == rc) { + if(0 != rc) { + RUNFREE(rwlock); return false; } else { - RuntimeHashadd(locktbl, (int)ptr, (int)rwlock); + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // check again + RuntimeHashadd(locktbl, (int)ptr, (int)rwlock); + } else { + RUNFREE(rwlock); + RuntimeHashget(locktbl, (int)ptr, (int*)&rwlock); + } rc = pthread_rwlock_unlock(&rwlock_tbl); - printf("[getreadlock, %d] release the write lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); + printf("[getreadlock, %d] release the write lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); } - //rc = pthread_rwlock_rdlock(&rwlock); rc = pthread_rwlock_tryrdlock(rwlock); printf("[getreadlock, %d] getting read lock for object %d: %d error: \n", numofcore, (int)ptr, rc, strerror(rc)); - if(EBUSY == rc) { + if(0 != rc) { return false; } else { return true; @@ -1060,10 +1877,9 @@ bool getreadlock(void * ptr) { RuntimeHashget(locktbl, (int)ptr, (int*)&rwlock_obj); rc = pthread_rwlock_unlock(&rwlock_tbl); printf("[getreadlock, %d] release the read lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); - //int rc_obj = pthread_rwlock_rdlock(&rwlock_obj); int rc_obj = pthread_rwlock_tryrdlock(rwlock_obj); printf("[getreadlock, %d] getting read lock for object %d: %d error: \n", numofcore, (int)ptr, rc_obj, strerror(rc_obj)); - if(EBUSY == rc_obj) { + if(0 != rc_obj) { return false; } else { return true; @@ -1074,7 +1890,50 @@ bool getreadlock(void * ptr) { void releasereadlock(void * ptr) { #ifdef RAW + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + int targetcore = ((int)ptr) % TOTALCORE; + // for 32 bit machine, the size is always 3 words + //int msgsize = sizeof(int) * 3; + int msgsize = 3; + + if(targetcore == corenum) { +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // reside on this core + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // no locks for this object, something is wrong + raw_test_done(0xa006); + } else { + int rwlock_obj = 0; + RuntimeHashget(locktbl, (int)ptr, &rwlock_obj); + rwlock_obj--; + RuntimeHashremovekey(locktbl, (int)ptr); + RuntimeHashadd_I(locktbl, (int)ptr, rwlock_obj); + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + return; + } + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + gdn_send(5); // lock release + raw_test_pass(5); + gdn_send(0); // read lock + raw_test_pass(0); + gdn_send(ptr); + raw_test_pass_reg(ptr); + raw_test_pass(0xffff); #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); int rc = pthread_rwlock_rdlock(&rwlock_tbl); @@ -1092,15 +1951,214 @@ void releasereadlock(void * ptr) { #endif } +#ifdef RAW +bool getreadlock_I(void * ptr) { + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + int targetcore = ((int)ptr) % TOTALCORE; + // for 32 bit machine, the size is always 4 words + //int msgsize = sizeof(int) * 4; + int msgsize = 4; + + lockobj = (int)ptr; + lockflag = false; +#ifndef INTERRUPT + reside = false; +#endif + lockresult = 0; + + if(targetcore == corenum) { + // reside on this core + bool deny = false; + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // no locks for this object + // first time to operate on this shared object + // create a lock for it + // the lock is an integer: 0 -- stall, >0 -- read lock, -1 -- write lock + RuntimeHashadd_I(locktbl, (int)ptr, 1); + } else { + int rwlock_obj = 0; + RuntimeHashget(locktbl, (int)ptr, &rwlock_obj); + if(-1 != rwlock_obj) { + rwlock_obj++; + RuntimeHashremovekey(locktbl, (int)ptr); + RuntimeHashadd_I(locktbl, (int)ptr, rwlock_obj); + } else { + deny = true; + } + } + if(lockobj == (int)ptr) { + if(deny) { + lockresult = 0; + } else { + lockresult = 1; + } + lockflag = true; +#ifndef INTERRUPT + reside = true; +#endif + } else { + // conflicts on lockresults + raw_test_done(0xa005); + } + return true; + } + + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + gdn_send(2); // lock request + raw_test_pass(2); + gdn_send(0); // read lock + raw_test_pass(0); + gdn_send(ptr); + raw_test_pass_reg(ptr); + gdn_send(corenum); + raw_test_pass_reg(corenum); + raw_test_pass(0xffff); + return true; +} + +void releasereadlock_I(void * ptr) { + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + int targetcore = ((int)ptr) % TOTALCORE; + // for 32 bit machine, the size is always 3 words + //int msgsize = sizeof(int) * 3; + int msgsize = 3; + + if(targetcore == corenum) { + // reside on this core + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // no locks for this object, something is wrong + raw_test_done(0xa006); + } else { + int rwlock_obj = 0; + RuntimeHashget(locktbl, (int)ptr, &rwlock_obj); + rwlock_obj--; + RuntimeHashremovekey(locktbl, (int)ptr); + RuntimeHashadd_I(locktbl, (int)ptr, rwlock_obj); + } + return; + } + + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + gdn_send(5); // lock release + raw_test_pass(5); + gdn_send(0); // read lock + raw_test_pass(0); + gdn_send(ptr); + raw_test_pass_reg(ptr); + raw_test_pass(0xffff); +} +#endif + bool getwritelock(void * ptr) { #ifdef RAW + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + int targetcore = ((int)ptr) % TOTALCORE; + // for 32 bit machine, the size is always 4 words + //int msgsize = sizeof(int) * 4; + int msgsize= 4; + + lockobj = (int)ptr; + lockflag = false; +#ifndef INTERRUPT + reside = false; +#endif + lockresult = 0; + + if(targetcore == corenum) { + // reside on this core + bool deny = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // no locks for this object + // first time to operate on this shared object + // create a lock for it + // the lock is an integer: 0 -- stall, >0 -- read lock, -1 -- write lock + raw_test_pass(0xe552); + RuntimeHashadd_I(locktbl, (int)ptr, -1); + } else { + int rwlock_obj = 0; + RuntimeHashget(locktbl, (int)ptr, &rwlock_obj); + raw_test_pass(0xe553); + raw_test_pass_reg(rwlock_obj); + if(0 == rwlock_obj) { + rwlock_obj = -1; + RuntimeHashremovekey(locktbl, (int)ptr); + RuntimeHashadd_I(locktbl, (int)ptr, rwlock_obj); + } else { + deny = true; + } + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + raw_test_pass(0xe554); + raw_test_pass_reg(lockresult); + if(lockobj == (int)ptr) { + if(deny) { + lockresult = 0; + raw_test_pass(0); + } else { + lockresult = 1; + raw_test_pass(1); + } + lockflag = true; +#ifndef INTERRUPT + reside = true; +#endif + } else { + // conflicts on lockresults + raw_test_done(0xa007); + } + return true; + } + raw_test_pass(0xe555); + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore + gdn_send(2); // lock request + raw_test_pass(2); + gdn_send(1); // write lock + raw_test_pass(1); + gdn_send(ptr); + raw_test_pass_reg(ptr); + gdn_send(corenum); + raw_test_pass_reg(corenum); + raw_test_pass(0xffff); + return true; #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); int rc = pthread_rwlock_tryrdlock(&rwlock_tbl); printf("[getwritelock, %d] getting the read lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); - if(EBUSY == rc) { + if(0 != rc) { return false; } if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { @@ -1115,17 +2173,25 @@ bool getwritelock(void * ptr) { printf("[getwritelock, %d] initialize the rwlock for object %d: %d error: \n", numofcore, (int)ptr, rc, strerror(rc)); rc = pthread_rwlock_trywrlock(&rwlock_tbl); printf("[getwritelock, %d] getting the write lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); - if(EBUSY == rc) { + if(0 != rc) { + pthread_rwlock_destroy(rwlock); + RUNFREE(rwlock); return false; } else { - RuntimeHashadd(locktbl, (int)ptr, (int)rwlock); + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // check again + RuntimeHashadd(locktbl, (int)ptr, (int)rwlock); + } else { + pthread_rwlock_destroy(rwlock); + RUNFREE(rwlock); + RuntimeHashget(locktbl, (int)ptr, (int*)&rwlock); + } rc = pthread_rwlock_unlock(&rwlock_tbl); printf("[getwritelock, %d] release the write lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); } - //rc = pthread_rwlock_wrlock(rwlock); rc = pthread_rwlock_trywrlock(rwlock); printf("[getwritelock, %d] getting write lock for object %d: %d error: \n", numofcore, (int)ptr, rc, strerror(rc)); - if(EBUSY == rc) { + if(0 != rc) { return false; } else { return true; @@ -1135,10 +2201,9 @@ bool getwritelock(void * ptr) { RuntimeHashget(locktbl, (int)ptr, (int*)&rwlock_obj); rc = pthread_rwlock_unlock(&rwlock_tbl); printf("[getwritelock, %d] release the read lock for locktbl: %d error: \n", numofcore, rc, strerror(rc)); - //int rc_obj = pthread_rwlock_wrlock(rwlock_obj); int rc_obj = pthread_rwlock_trywrlock(rwlock_obj); printf("[getwritelock, %d] getting write lock for object %d: %d error: \n", numofcore, (int)ptr, rc_obj, strerror(rc_obj)); - if(EBUSY == rc_obj) { + if(0 != rc_obj) { return false; } else { return true; @@ -1150,7 +2215,54 @@ bool getwritelock(void * ptr) { void releasewritelock(void * ptr) { #ifdef RAW + unsigned msgHdr; + int self_y, self_x, target_y, target_x; + int targetcore = ((int)ptr) % TOTALCORE; + // for 32 bit machine, the size is always 3 words + //int msgsize = sizeof(int) * 3; + int msgsize = 3; + + if(targetcore == corenum) { +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // reside on this core + if(!RuntimeHashcontainskey(locktbl, (int)ptr)) { + // no locks for this object, something is wrong + raw_test_done(0xa008); + } else { + int rwlock_obj = 0; + raw_test_pass(0xe662); + RuntimeHashget(locktbl, (int)ptr, &rwlock_obj); + raw_test_pass_reg(rwlock_obj); + rwlock_obj++; + RuntimeHashremovekey(locktbl, (int)ptr); + RuntimeHashadd_I(locktbl, (int)ptr, rwlock_obj); + raw_test_pass_reg(rwlock_obj); + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + return; + } + raw_test_pass(0xe663); + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); + gdn_send(5); // lock release + raw_test_pass(5); + gdn_send(1); // write lock + raw_test_pass(1); + gdn_send(ptr); + raw_test_pass_reg(ptr); + raw_test_pass(0xffff); #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); int rc = pthread_rwlock_rdlock(&rwlock_tbl); @@ -1217,7 +2329,7 @@ int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *pr tpd->parameterArray[j]=taskpointerarray[j];//store the actual parameters } /* Enqueue task */ - if ((!gencontains(failedtasks, tpd)&&!gencontains(activetasks,tpd))) { + if ((/*!gencontains(failedtasks, tpd)&&*/!gencontains(activetasks,tpd))) { genputtable(activetasks, tpd, tpd); } else { RUNFREE(tpd->parameterArray); @@ -1245,10 +2357,89 @@ int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *pr } return retval; } + +#ifdef RAW +int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags) { + void * taskpointerarray[MAXTASKPARAMS]; + int j; + int numparams=parameter->task->numParameters; + int numiterators=parameter->task->numTotal-1; + int retval=1; + int addnormal=1; + int adderror=1; + + struct taskdescriptor * task=parameter->task; + + ObjectHashadd_I(parameter->objectset, (int) ptr, 0, (int) enterflags, numenterflags, enterflags==NULL);//this add the object to parameterwrapper + /* Add enqueued object to parameter vector */ + taskpointerarray[parameter->slot]=ptr; + + /* Reset iterators */ + for(j=0;jiterators[j]); + } + + /* Find initial state */ + for(j=0;jiterators[j], taskpointerarray OPTARG(failed))) + toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)); + else if (j>0) { + /* Need to backtrack */ + toiReset(¶meter->iterators[j]); + j--; + goto backtrackinit; + } else { + /* Nothing to enqueue */ + return retval; + } + } + + while(1) { + /* Enqueue current state */ + int launch = 0; + struct taskparamdescriptor *tpd=RUNMALLOC_I(sizeof(struct taskparamdescriptor)); + tpd->task=task; + tpd->numParameters=numiterators+1; + tpd->parameterArray=RUNMALLOC_I(sizeof(void *)*(numiterators+1)); + for(j=0;j<=numiterators;j++){ + tpd->parameterArray[j]=taskpointerarray[j];//store the actual parameters + } + /* Enqueue task */ + if ((/*!gencontains(failedtasks, tpd)&&*/!gencontains(activetasks,tpd))) { + genputtable_I(activetasks, tpd, tpd); + } else { + RUNFREE(tpd->parameterArray); + RUNFREE(tpd); + } + + /* This loop iterates to the next parameter combination */ + if (numiterators==0) + return retval; + + for(j=numiterators-1; jiterators[j], taskpointerarray OPTARG(failed))) + toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)); + else if (j>0) { + /* Need to backtrack */ + toiReset(¶meter->iterators[j]); + j--; + goto backtrackinc; + } else { + /* Nothing more to enqueue */ + return retval; + } + } + } + return retval; +} +#endif + /* Handler for signals. The signals catch null pointer errors and arithmatic errors. */ - +#ifndef RAW void myhandler(int sig, siginfo_t *info, void *uap) { sigset_t toclear; #ifdef DEBUG @@ -1260,6 +2451,7 @@ void myhandler(int sig, siginfo_t *info, void *uap) { sigprocmask(SIG_UNBLOCK, &toclear,NULL); longjmp(error_handler,1); } +#endif fd_set readfds; int maxreadfd; @@ -1288,7 +2480,23 @@ void removereadfd(int fd) { void executetasks() { void * taskpointerarray[MAXTASKPARAMS+OFFSET]; + int numparams=0; + int numtotal=0; + struct ___Object___ * tmpparam = NULL; + struct parameterdescriptor * pd=NULL; + struct parameterwrapper *pw=NULL; + int j = 0; + int x = 0; + +#ifdef RAW + int grount = 0; + int andmask=0; + int checkmask=0; + + raw_test_pass(0xe991); +#endif +#ifndef RAW /* Set up signal handlers */ struct sigaction sig; sig.sa_sigaction=&myhandler; @@ -1300,18 +2508,28 @@ void executetasks() { sigaction(SIGSEGV,&sig,0); sigaction(SIGFPE,&sig,0); sigaction(SIGPIPE,&sig,0); +#endif +#ifndef RAW /* Zero fd set */ FD_ZERO(&readfds); +#endif maxreadfd=0; +#ifndef RAW fdtoobject=allocateRuntimeHash(100); +#endif +#ifndef RAW /* Map first block of memory to protected, anonymous page */ mmap(0, 0x1000, 0, MAP_SHARED|MAP_FIXED|MAP_ANON, -1, 0); +#endif newtask: while((hashsize(activetasks)>0)||(maxreadfd>0)) { +#ifdef RAW + raw_test_pass(0xe992); +#else /* Check if any filedescriptors have IO pending */ if (maxreadfd>0) { int i; @@ -1337,6 +2555,7 @@ void executetasks() { } } } +#endif /* See if there are any active tasks */ if (hashsize(activetasks)>0) { @@ -1345,20 +2564,65 @@ void executetasks() { genfreekey(activetasks, currtpd); /* Check if this task has failed, allow a task that contains optional objects to fire */ - if (gencontains(failedtasks, currtpd)) { + /*if (gencontains(failedtasks, currtpd)) { // Free up task parameter descriptor RUNFREE(currtpd->parameterArray); RUNFREE(currtpd); goto newtask; - } - int numparams=currtpd->task->numParameters; - int numtotal=currtpd->task->numTotal; + }*/ + numparams=currtpd->task->numParameters; + numtotal=currtpd->task->numTotal; +#ifdef THREADSIMULATE int isolateflags[numparams]; +#endif /* Make sure that the parameters are still in the queues */ for(i=0;iparameterArray[i]; - struct ___Object___ * tmpparam = (struct ___Object___ *)parameter; +#ifdef RAW + raw_test_pass(0xe993); + // require locks for this parameter + getwritelock(parameter); + grount = 0; + while(!lockflag) { +#ifndef INTERRUPT + receiveObject(); +#endif + } +#ifndef INTERRUPT + if(reside) { + while(receiveObject() != -1) { + } + } +#endif + grount = lockresult; + + lockresult = 0; + lockobj = 0; + lockflag = false; +#ifndef INTERRUPT + reside = false; +#endif + + if(grount == 0) { + raw_test_pass(0xe994); + // can not get the lock, try later + for(j = 0; j < i; ++j) { + releasewritelock(taskpointerarray[j+OFFSET]); + } + genputtable(activetasks, currtpd, currtpd); + goto newtask; + } + // flush the object + { + int tmp = 0; + for(tmp = 0; tmp < classsize[((struct ___Object___ *)parameter)->type]; ++tmp) { + invalidateAddr(parameter + tmp); + } + } +#endif + tmpparam = (struct ___Object___ *)parameter; +#ifdef THREADSIMULATE if(0 == tmpparam->isolate) { isolateflags[i] = 0; // shared object, need to flush with current value @@ -1369,17 +2633,17 @@ void executetasks() { int j = 0; for(j = 0; j < i; ++j) { if(0 == isolateflags[j]) { - releasewritelock(taskpointerarray[j]); + releasewritelock(((struct ___Object___ *)taskpointerarray[j+OFFSET])->original); } } genputtable(activetasks, currtpd, currtpd); goto newtask; } if(tmpparam->version != tmpparam->original->version) { + // some task on another core has changed this object // flush this object - memcpy(tmpparam, tmpparam->original, classsize[tmpparam->type]); - //releasereadlock(tmpparam->original); - // fail to get write lock, release all obtained locks and try this task later + //memcpy(tmpparam, tmpparam->original, classsize[tmpparam->type]); + // release all obtained locks int j = 0; for(j = 0; j < i; ++j) { if(0 == isolateflags[j]) { @@ -1388,19 +2652,10 @@ void executetasks() { } releasewritelock(tmpparam->original); - // some task on another core has changed this object - // Free up task parameter descriptor - RUNFREE(currtpd->parameterArray); - RUNFREE(currtpd); // dequeue this object -#ifdef THREADSIMULATE int numofcore = pthread_getspecific(key); struct parameterwrapper ** queues = objectqueues[numofcore][tmpparam->type]; int length = numqueues[numofcore][tmpparam->type]; -#else - struct parameterwrapper ** queues = objectqueues[corenum][tmpparam->type]; - int length = numqueues[corenum][tmpparam->type]; -#endif for(j = 0; j < length; ++j) { struct parameterwrapper * pw = queues[j]; if(ObjectHashcontainskey(pw->objectset, (int)tmpparam)) { @@ -1414,24 +2669,68 @@ void executetasks() { } } // try to enqueue it again to check if it feeds other tasks; - enqueueObject(tmpparam, NULL, 0); + //enqueueObject(tmpparam, NULL, 0); + // Free up task parameter descriptor + RUNFREE(currtpd->parameterArray); + RUNFREE(currtpd); goto newtask; } - //releasereadlock(tmpparam->original); } else { isolateflags[i] = 1; } - struct parameterdescriptor * pd=currtpd->task->descriptorarray[i]; - struct parameterwrapper *pw=(struct parameterwrapper *) pd->queue; - int j; +#endif + pd=currtpd->task->descriptorarray[i]; + pw=(struct parameterwrapper *) pd->queue; /* Check that object is still in queue */ { if (!ObjectHashcontainskey(pw->objectset, (int) parameter)) { +#ifdef RAW + raw_test_pass(0xe995); +#endif RUNFREE(currtpd->parameterArray); RUNFREE(currtpd); goto newtask; } } +#ifdef RAW + /* Check if the object's flags still meets requirements */ + { + int tmpi = 0; + bool ismet = false; + for(tmpi = 0; tmpi < pw->numberofterms; ++tmpi) { + andmask=pw->intarray[tmpi*2]; + checkmask=pw->intarray[tmpi*2+1]; + raw_test_pass(0xdd000000 + andmask); + raw_test_pass_reg((int)parameter); + raw_test_pass(0xdd000000 + ((struct ___Object___ *)parameter)->flag); + raw_test_pass(0xdd000000 + checkmask); + if((((struct ___Object___ *)parameter)->flag&andmask)==checkmask) { + ismet = true; + break; + } + } + if (!ismet) { + // flags are never suitable + // remove this obj from the queue + int next; + int UNUSED, UNUSED2; + int * enterflags; + raw_test_pass(0xe996); + ObjectHashget(pw->objectset, (int) parameter, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2); + ObjectHashremove(pw->objectset, (int)parameter); + if (enterflags!=NULL) + free(enterflags); + // release grabbed locks + for(j = 0; j < i; ++j) { + releasewritelock(taskpointerarray[j+OFFSET]); + } + releasewritelock(parameter); + RUNFREE(currtpd->parameterArray); + RUNFREE(currtpd); + goto newtask; + } + } +#endif parameterpresent: ; /* Check that object still has necessary tags */ @@ -1439,6 +2738,9 @@ void executetasks() { int slotid=pd->tagarray[2*j]+numparams; struct ___TagDescriptor___ *tagd=currtpd->parameterArray[slotid]; if (!containstag(parameter, tagd)) { +#ifdef RAW + raw_test_pass(0xe997); +#endif RUNFREE(currtpd->parameterArray); RUNFREE(currtpd); goto newtask; @@ -1452,39 +2754,33 @@ void executetasks() { taskpointerarray[i+OFFSET]=currtpd->parameterArray[i]; } +#ifdef THREADSIMULATE for(i = 0; i < numparams; ++i) { if(0 == isolateflags[i]) { struct ___Object___ * tmpparam = (struct ___Object___ *)taskpointerarray[i+OFFSET]; - // shared object, need to replace this copy with original one - /*if(!getwritelock(tmpparam->original)) { - // fail to get write lock, release all obtained locks and try this task later - int j = 0; - for(j = 0; j < i; ++j) { - if(0 == isolateflags[j]) { - releasewritelock(taskpointerarray[j]); - } - } - genputtable(activetasks, tpd, tpd); - goto newtask; - }*/ if(tmpparam != tmpparam->original) { taskpointerarray[i+OFFSET] = tmpparam->original; } } } +#endif { +#if 0 +#ifndef RAW /* Checkpoint the state */ forward=allocateRuntimeHash(100); reverse=allocateRuntimeHash(100); //void ** checkpoint=makecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, forward, reverse); - int x; +#endif +#endif if (x=setjmp(error_handler)) { int counter; /* Recover */ - +#ifndef RAW #ifdef DEBUG printf("Fatal Error=%d, Recovering!\n",x); +#endif #endif /* genputtable(failedtasks,currtpd,currtpd); @@ -1496,8 +2792,13 @@ void executetasks() { forward=NULL; reverse=NULL; */ - fflush(stdout); + //fflush(stdout); +#ifdef RAW + raw_test_pass_reg(x); + raw_test_done(0xa009); +#else exit(-1); +#endif } else { /*if (injectfailures) { if ((((double)random())/RAND_MAX)task->name, (instaccum-instructioncount)); +#endif ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray); +#ifndef RAW printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount)); +#endif } else ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray); +#ifdef RAW + for(i = 0; i < numparams; ++i) { + int j = 0; + struct ___Object___ * tmpparam = (struct ___Object___ *)taskpointerarray[i+OFFSET]; + raw_test_pass(0xe998); + raw_test_pass(0xdd100000 + tmpparam->flag); + releasewritelock(tmpparam); + } +#elif defined THREADSIMULATE for(i = 0; i < numparams; ++i) { if(0 == isolateflags[i]) { struct ___Object___ * tmpparam = (struct ___Object___ *)taskpointerarray[i+OFFSET]; releasewritelock(tmpparam); } } +#endif +#if 0 +#ifndef RAW freeRuntimeHash(forward); freeRuntimeHash(reverse); +#endif +#endif freemalloc(); // Free up task parameter descriptor RUNFREE(currtpd->parameterArray); RUNFREE(currtpd); +#if 0 +#ifndef RAW forward=NULL; reverse=NULL; +#endif +#endif } } } } +#ifndef RAW + freeRuntimeHash(fdtoobject); +#endif } /* This function processes an objects tags */ @@ -1651,16 +2977,25 @@ void builditerators(struct taskdescriptor * task, int index, struct parameterwra for(i=0;i NUMCORES - 1) { + return; + } +#endif for(i=0;iname); +#endif for(j=0;jnumParameters;j++) { struct parameterdescriptor *param=task->descriptorarray[j]; struct parameterwrapper *parameter=param->queue; struct ObjectHash * set=parameter->objectset; struct ObjectIterator objit; +#ifndef RAW printf(" Parameter %d\n", j); +#endif ObjectHashiterator(set, &objit); while(ObjhasNext(&objit)) { struct ___Object___ * obj=(struct ___Object___ *)Objkey(&objit); @@ -1669,16 +3004,23 @@ void builditerators(struct taskdescriptor * task, int index, struct parameterwra int numflags=Objdata3(&objit); int flags=Objdata2(&objit); Objnext(&objit); +#ifndef RAW printf(" Contains %lx\n", obj); printf(" flag=%d\n", obj->flag); +#endif if (tagptr==NULL) { } else if (tagptr->type==TAGTYPE) { +#ifndef RAW printf(" tag=%lx\n",tagptr); +#endif + ; } else { int tagindex=0; struct ArrayObject *ao=(struct ArrayObject *)tagptr; for(;tagindex___cachedCode___;tagindex++) { +#ifndef RAW printf(" tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*, tagindex)); +#endif } } } @@ -1692,6 +3034,11 @@ void builditerators(struct taskdescriptor * task, int index, struct parameterwra void processtasks() { int i; +#ifdef RAW + if(corenum > NUMCORES - 1) { + return; + } +#endif #ifdef THREADSIMULATE int numofcore = pthread_getspecific(key); for(i=0;iqueue; builditerators(task, j, parameter); } - } + } } void toiReset(struct tagobjectiterator * it) { diff --git a/Robust/src/Runtime/object.c b/Robust/src/Runtime/object.c index ab986ecb..0bff6175 100644 --- a/Robust/src/Runtime/object.c +++ b/Robust/src/Runtime/object.c @@ -1,5 +1,9 @@ #include "object.h" +#ifdef RAW +#include +#else #include "stdio.h" +#endif #include "stdlib.h" #ifdef THREADS @@ -70,8 +74,12 @@ int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) { pthread_cond_broadcast(&objcond); pthread_mutex_unlock(&objlock); } else { +#ifdef RAW + raw_test_done(-1); +#else printf("ERROR...UNLOCKING LOCK WE DON'T HAVE\n"); exit(-1); +#endif } } #endif diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 03ee0bcf..0f84c36a 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -78,6 +78,10 @@ void CALL11(___System______exit____I,int ___status___, int ___status___) { exit(___status___); } +void CALL11(___System______printI____I,int ___status___, int ___status___) { + printf("%d\n",___status___); +} + long CALL00(___System______currentTimeMillis____) { struct timeval tv; long long retval; gettimeofday(&tv, NULL); diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index e929260a..fdad772e 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -98,10 +98,26 @@ struct failedtasklist { }; #endif +#ifdef MULTICORE +struct transObjInfo { + void * objptr; + int targetcore; + int * queues; + int length; +}; +#endif + +#ifdef RAW +//struct RuntimeHash * ptbl = NULL; +#endif + #ifdef MULTICORE void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length); void flagorandinit(void * ptr, int ormask, int andmask); void enqueueObject(void * ptr, struct parameterwrapper ** queues, int length); +#ifdef RAW +void enqueueObject_I(void * ptr, struct parameterwrapper ** queues, int length); +#endif #else void flagorand(void * ptr, int ormask, int andmask); void flagorandinit(void * ptr, int ormask, int andmask); @@ -111,7 +127,7 @@ void executetasks(); void processtasks(); #ifdef MULTICORE -void transferObject(void * ptr, int targetcore); +void transferObject(struct transObjInfo * transObj); #endif #ifndef MULTICORE @@ -164,6 +180,9 @@ void processobject(struct parameterwrapper *parameter, int index, struct paramet void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams); void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter); int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags); +#ifdef RAW +int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags); +#endif #endif diff --git a/Robust/src/Runtime/socket.c b/Robust/src/Runtime/socket.c index 278ad182..be44968e 100644 --- a/Robust/src/Runtime/socket.c +++ b/Robust/src/Runtime/socket.c @@ -1,17 +1,23 @@ #include "runtime.h" #include "structdefs.h" -#include #include +#ifndef RAW +#include #include #include -#include #include +#endif +#include #include "SimpleHash.h" #include "GenericHashtable.h" -extern struct RuntimeHash *fdtoobject; +struct RuntimeHash *fdtoobject; int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port___, struct ___Socket___ * ___this___, int ___fd___, struct ArrayObject * ___address___ ,int ___port___) { +#ifdef RAW + // not supported in RAW version + return -1; +#else struct sockaddr_in sin; int rc; @@ -49,6 +55,7 @@ int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port_ error: close(___fd___); return -1; +#endif } #ifdef TASK @@ -62,6 +69,10 @@ int CALL12(___Socket______nativeBindFD____I, int ___fd___, struct ___Socket___ * int CALL12(___Socket______nativeBind_____AR_B_I, int ___port___, struct ArrayObject * ___address___, int ___port___) { +#ifdef RAW + // not supported in RAW version + return -1; +#else int fd; int rc; socklen_t sa_size; @@ -112,9 +123,14 @@ int CALL12(___Socket______nativeBind_____AR_B_I, int ___port___, struct ArrayOb exit(-1); #endif #endif +#endif } struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct ArrayObject * ___hostname___) { +#ifdef RAW + // not supported in RAW version + return NULL; +#else //struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct ___ArrayObject___ * ___hostname___) { int length=VAR(___hostname___)->___length___; int i,j,n; @@ -155,10 +171,15 @@ struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct A } return arraybytearray; +#endif } int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSocket___ * ___this___, int port) { +#ifdef RAW + // not supported in RAW version + return -1; +#else int fd; int n=1; @@ -256,9 +277,14 @@ int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSoc addreadfd(fd); #endif return fd; +#endif } int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSocket___ * ___this___, struct ___Socket___ * ___s___) { +#ifdef RAW + // not supported in RAW version + return -1; +#else struct sockaddr_in sin; unsigned int sinlen=sizeof(sin); int fd=VAR(___this___)->___fd___; @@ -304,6 +330,7 @@ int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSo #endif #endif return newfd; +#endif } void CALL24(___Socket______nativeWrite_____AR_B_I_I, int offset, int length, struct ___Socket___ * ___this___, struct ArrayObject * ___b___, int offset, int length) { @@ -321,8 +348,10 @@ void CALL24(___Socket______nativeWrite_____AR_B_I_I, int offset, int length, str } if (length!=0) { +#ifndef RAW perror("ERROR IN NATIVEWRITE"); printf("error=%d remaining bytes %d\n",errno, length); +#endif } break; } @@ -361,8 +390,10 @@ int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___, if (byteread<0) { +#ifndef RAW printf("ERROR IN NATIVEREAD\n"); perror(""); +#endif } #ifdef TASK #ifdef MULTICORE diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index 00b8a6e0..a737e8df 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -9,7 +9,9 @@ #include #include +#ifndef RAW #include +#endif int threadcount; pthread_mutex_t gclock; pthread_mutex_t gclistlock; diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 6042f0bb..b70c9d82 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -18,6 +18,8 @@ echo -scheduling do task scheduling echo -multicore generate multi-core version binary echo "-numcore set the number of cores (should be used together with -multicore), defaultly set as 1" echo "-raw generate raw version binary (should be used together with -multicore)" +echo "-interrupt generate raw version binary with interruption (should be used togethere with -raw)" +echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)" echo -threadsimulate generate multi-thread simulate version binary echo -optional enable optional echo -debug generate debug symbols @@ -49,6 +51,8 @@ RECOVERFLAG=false MULTICOREFLAG=false TRANSSTATSFLAG=false RAWFLAG=false +RAWCONFIG='' +INTERRUPTFLAG=false THREADSIMULATEFLAG=false; USEDMALLOC=false THREADFLAG=false @@ -138,7 +142,14 @@ shift elif [[ $1 = '-raw' ]] then RAWFLAG=true -#JAVAOPTS="$JAVAOPTS -raw" +JAVAOPTS="$JAVAOPTS -raw" +elif [[ $1 = '-rawconfig' ]] +then +RAWCONFIG="$2" +shift +elif [[ $1 = '-interrupt' ]] +then +INTERRUPTFLAG=true elif [[ $1 = '-threadsimulate' ]] then THREADSIMULATEFLAG=true @@ -271,6 +282,33 @@ fi # CHECKFLAG #build and link everything +if $RAWFLAG +then # RAWFLAG +RAWDIR="$CURDIR/raw" +MAKEFILE="../Makefile.raw" +mkdir $RAWDIR +cd $RAWDIR +make clean +rm ./* + +if $INTERRUPTFLAG +then #INTERRUPT version +MAKEFILE="$MAKEFILE.i" +fi #INTERRUPT version + +MAKEFILE="$MAKEFILE.$RAWCONFIG" + +cp $MAKEFILE ./Makefile +cp ../Runtime/*.c ./ +cp ../Runtime/*.h ./ +cp ../Runtime/*.S ./ +cp ../Runtime/*.s ./ +cp ../tmpbuilddirectory/*.c ./ +cp ../tmpbuilddirectory/*.h ./ + +make + +else #!RAWFLAG cd $CURDIR INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \ @@ -352,5 +390,7 @@ gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \ tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin fi +fi #!RAWFLAG + exit