public FlagState getTargetFState(FlagState fstate) {
if(targetFState == null) {
- return null;
+ return fstate;
}
return targetFState.get(fstate);
}
obj.setShared(true);
for(int k = 0; k < allycores.size(); ++k) {
Integer allyCore = allycores.elementAt(k);
- /*if(allyCore == coreNum) {
- remove = false;
- } else {*/
- if(transObjs == null) {
- transObjs = new Vector<ObjectSimulator>();
- }
- if(!transObjs.contains(obj)) {
- transObjs.add(obj);
- }
- remove = false;
- //}
+ if(transObjs == null) {
+ transObjs = new Vector<ObjectSimulator>();
+ }
+ if(!transObjs.contains(obj)) {
+ transObjs.add(obj);
+ }
+ remove = false;
}
}
for(int j = 0; j < this.tasks.size(); j++) {
}
public void setCurrentFS(FlagState currentFS) {
- /*if(!this.currentFS.equals(currentFS)) {
- changed = true;
- this.currentFS = currentFS;
- } else {
- changed = false;
- }*/
changed = true;
this.currentFS = currentFS;
}
private int coreNum;
private Vector<TaskDescriptor> tasks;
private Hashtable<FlagState, Queue<Integer>> targetCores;
- private Hashtable<FlagState, FlagState> targetFState;
- private Vector<Integer> ancestorCores;
- private Vector<Integer> childCores;
+ private Hashtable<FlagState, FlagState> targetFState; // only affected by transimit edges
private Hashtable<FlagState, Vector<Integer>> allyCores;
private Hashtable<TaskDescriptor, Vector<FlagState>> td2fs;
this.tasks = null;
this.targetCores = null;
this.targetFState = null;
- this.ancestorCores = null;
this.allyCores = null;
this.td2fs = null;
}
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<FlagState, Queue<Integer>>();
}
if(!this.targetCores.containsKey(fstate)) {
this.targetCores.put(fstate, new LinkedList<Integer>());
}
- //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) {
if(!this.targetCores.containsKey(fstate)) {
this.targetCores.put(fstate, new LinkedList<Integer>());
}
- //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<FlagState, FlagState>();
}
- //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<FlagState, Vector<Integer>>();
}
}
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.
}
}
if(!this.tasks.contains(task)) {
this.tasks.add(task);
}
- }
-
- public Vector<Integer> getAncestorCores() {
- return ancestorCores;
- }
-
- public void setAncestorCores(Vector<Integer> ancestorCores) {
- this.ancestorCores = ancestorCores;
- }
-
- public void addAncestorCores(Integer ancestorCore) {
- if(this.ancestorCores == null) {
- this.ancestorCores = new Vector<Integer>();
- }
- 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<Integer> getChildCores() {
- return childCores;
- }
-
- public void setChildCores(Vector<Integer> childCores) {
- this.childCores = childCores;
- }
-
- public void addChildCores(Integer childCore) {
- if(this.childCores == null) {
- this.childCores = new Vector<Integer>();
- }
- 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
}
}
cdToCNodes = null;
-
- // Create 'associate' edges between the ScheduleNodes.
- /*Iterator<TaskDescriptor> it_tasks = (Iterator<TaskDescriptor>)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<FEdge> fev = (Vector<FEdge>)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 {
// 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);
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");
}
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);
}
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");
}
tocn2cn = null;
edges = null;
}
-
- // associate ScheduleEdges
- /*for(int j = 0; j < origins.size(); ++j) {
- ScheduleNode osNode = origins.elementAt(i);
- Vector<ScheduleEdge> 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;
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();
int startupcore = 0;
boolean setstartupcore = false;
Schedule startup = null;
- Vector<Integer> leafcores = new Vector<Integer>();
- 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);
while(it_edges.hasNext()) {
TaskDescriptor td = ((FEdge)it_edges.next()).getTask();
tmpSchedule.addTask(td);
+ if(!td2cores.containsKey(td)) {
+ td2cores.put(td, new Vector<Schedule>());
+ }
+ Vector<Schedule> 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<Schedule>());
- }
- Vector<Schedule> tmpcores = td2cores.get(td);
- if(!tmpcores.contains(tmpSchedule)) {
- tmpcores.add(tmpSchedule);
- }
tmpSchedule.addFState4TD(td, fs);
}
if(td.getParamType(0).getClassDesc().getSymbol().equals(TypeUtil.StartupClass)) {
// 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();
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()) {
}
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<FEdge> fes = (Vector<FEdge>)this.taskanalysis.getFEdgesFromTD(td);
Vector<Schedule> cores = td2cores.get(td);
- if(cores.size() == 1) {
- continue;
- }
for(int k = 0; k < cores.size(); ++k) {
Schedule tmpSchedule = cores.elementAt(k);
- Vector<FlagState> 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<TaskDescriptor> tmptds = new Vector<TaskDescriptor>();
+ 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<Schedule> 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<FlagState> 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());
+ }
}
}
}
public final static int NEWEDGE = 0;
public final static int TRANSEDGE = 1;
- public final static int ASSOCEDGE = 2;
protected int uid;
protected int gid;
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;
public void setTargetCNode(ClassNode targetCNode) {
this.targetCNode = targetCNode;
- //this.targetCNode.getInedgeVector().addElement(this);
this.transTime = targetCNode.getTransTime();
}
private Vector<ClassNode> classNodes;
Vector<ScheduleEdge> scheduleEdges;
- private Vector<ScheduleEdge> associateEdges;
- private Vector<ScheduleEdge> inassociateEdges;
private int executionTime;
this.executionTime = -1;
this.classNodes = null;
this.scheduleEdges = null;
- this.associateEdges = new Vector<ScheduleEdge>();
- this.inassociateEdges = new Vector<ScheduleEdge>();
}
public ScheduleNode(ClassNode cn, int gid) {
this.classNodes.add(cn);
this.addEdge(cn.getEdgeVector());
this.executionTime = -1;
- this.associateEdges = new Vector<ScheduleEdge>();
- this.inassociateEdges = new Vector<ScheduleEdge>();
}
public int getuid() {
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 {
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()));
tcns = null;
tses = null;
- /*Vector<ScheduleEdge> assses = new Vector<ScheduleEdge>();
- 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<ScheduleEdge> assses = new Vector<ScheduleEdge>();
- 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<ScheduleEdge>();
- o.inassociateEdges = new Vector<ScheduleEdge>();
return o;
}
action = new Action(coreNum, Action.TFWITHOBJ);
action.setTd(cs.getRtask().getTd());
Vector<ObjectSimulator> nobjs = task.getCurrentRun().getNewObjs();
- //Schedule schedule = this.scheduling.elementAt(coreNum);
for(int j = 0; j < nobjs.size(); j++) {
ObjectSimulator nobj = nobjs.elementAt(j);
action.addNewObj(nobj.getCd(), Integer.valueOf(1));
}
output.print(" -> ");
- //if(se.getTargetFState() == null) {
if(se.isclone()) {
if(se.getTargetCNode().isclone()) {
output.print(se.getTargetCNode().getLabel());
}
output.print(" -> ");
- //if(se.getTargetFState() == null) {
if(se.isclone()) {
if(se.getTargetCNode().isclone()) {
output.print(se.getTargetCNode().getLabel());
Vector namers=new Vector();
namers.add(new Namer());
namers.add(new Allocations());
- //namers.add(new TaskEdges());
Iterator it = nodes.iterator();
while (it.hasNext()) {
}
Vector<Action> actions = tcp.getActions();
Hashtable<String, StringBuffer> tmpTaskNodes = new Hashtable<String, StringBuffer>();
- //Vector<String> sortedttnodes = new Vector<String>();
for(int i = 0; i < actions.size(); i++) {
Action taction = actions.elementAt(i);
int cNum = taction.getCoreNum();
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()){
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");
}
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();
}
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 + "->");
}
}
}
}
- //FlagState tFState = (FlagState)toexecute.getTarget();
- //tpara.setCurrentFS(tFState);
tpara.applyEdge(toexecute);
tpara.increaseVersion();
}
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;
}
}
public static native void exit(int status);
+
+ public static native void printI(int status);
public static native void clearPrefetchCache();
}
public static int flagcount = 0;
Virtual virtualcalls;
TypeUtil typeutil;
- //private int maxtaskparams=0;
protected int maxtaskparams=0;
private int maxcount=0;
ClassDescriptor[] cdarray;
* 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 <runtime.h>");
+ outmethod.println("#include \"runtime.h\"");
if (state.DSM) {
outmethod.println("#include \"localobjects.h\"");
}
}
}
- //private void outputStructs(PrintWriter outstructs) {
protected void outputStructs(PrintWriter outstructs) {
outstructs.println("#ifndef STRUCTDEFS_H");
outstructs.println("#define STRUCTDEFS_H");
}
}
- //private void outputClassDeclarations(PrintWriter outclassdefs) {
protected void outputClassDeclarations(PrintWriter outclassdefs) {
if (state.THREAD||state.DSM)
outclassdefs.println("#include <pthread.h>");
/** 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()) {
* 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();
/* 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)
* 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()+" {");
/** This method assigns labels to FlatNodes */
- //private Hashtable<FlatNode, Integer> assignLabels(FlatMethod fm) {
protected Hashtable<FlatNode, Integer> assignLabels(FlatMethod fm) {
HashSet tovisit=new HashSet();
HashSet visited=new HashSet();
/** 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();
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:
} 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
} 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
} 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
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+";");
}
}
- //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+";");
}
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);
}
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";
/* 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;
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);
}
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) {
}
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];
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");
// 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) {
}
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();
outtask.println("#include \"ObjectHash.h\"");
outtask.println("#include \"structdefs.h\"");
outtask.println("#include \"Queue.h\"");
+ outtask.println("#include <string.h>");
+ outtask.println("#ifdef RAW");
+ outtask.println("#include <raw.h>");
+ outtask.println("#endif");
outtask.println();
outtask.println("struct tagobjectiterator {");
outtask.println(" int istag; /* 0 if object iterator, 1 if tag iterator */");
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();
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();
}
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()+";");
}
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.*/
/* 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;
output.print(" ");
super.generateFlatNode(fm, lb, current_node, output);
if (current_node.kind()!=FKind.FlatReturnNode) {
+ output.println(" flushAll();");
outputTransCode(output);
output.println(" return;");
}
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
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<task.numParameters();i++) {
+ if (i!=0)
+ output.println(",");
+ output.print("&" + this.objqueueprefix + i + "_" + task.getCoreSafeSymbol(num));
+ }
+ output.println("};");
output.println("struct parameterdescriptor * parameterdescriptors_"+task.getCoreSafeSymbol(num)+"[] = {");
for (int i=0;i<task.numParameters();i++) {
Vector<FlagState> 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)+");");
}
}
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()) + ")) {");
}
// 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;
}
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<Integer> sendto = new Vector<Integer>();
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;");
// 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
Vector<Integer> 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("}");
}
}
}
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();
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<TaskDescriptor> residetasks = this.scheduling.get(targetcore).getTasks();
+ Vector<TaskDescriptor> tasks = new Vector<TaskDescriptor>();
+ Vector<Integer> indexes = new Vector<Integer>();
+ 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;
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) {
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
+}
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;
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"))
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) {
+#ifdef RAW
+#include <raw.h>
+#else
#include <stdio.h>
+#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
void * getfirstkey(struct genhashtable *ht) {
+ if(ht->list == NULL) {
+ return NULL;
+ }
return ht->list->src;
}
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;j<newcurrentsize;j++) newbins[j]=NULL;
+ ht->currentsize=newcurrentsize;
+ for(i=0;i<oldcurrentsize;i++) {
+ struct genpointerlist * tmpptr=oldbins[i];
+ while(tmpptr!=NULL) {
+ unsigned int hashcode=genhashfunction(ht, tmpptr->src);
+ 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;
}
return ptr->object;
ptr=ptr->next;
}
+#ifndef RAW
printf("XXXXXXXXX: COULDN'T FIND ENTRY FOR KEY %p\n",key);
+#endif
return NULL;
}
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;
}
}
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) {
}
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;i<geninitialnumbins;i++)
+
+#ifdef RAW
+ raw_test_pass(0xf000);
+#endif
+
+ gpl=(struct genpointerlist **) RUNMALLOC(sizeof(struct genpointerlist *)*geninitialnumbins);
+#ifdef RAW
+ raw_test_pass(0xf001);
+#endif
+ for(i=0;i<geninitialnumbins;i++) {
gpl[i]=NULL;
+ }
+#ifdef RAW
+ raw_test_pass(0xf002);
+#endif
+ ght=(struct genhashtable *) RUNMALLOC(sizeof(struct genhashtable));
+#ifdef RAW
+ raw_test_pass(0xf003);
+#endif
ght->hash_function=hash_function;
ght->comp_function=comp_function;
ght->currentsize=geninitialnumbins;
ght->counter=0;
ght->list=NULL;
ght->last=NULL;
+#ifdef RAW
+ raw_test_pass(0xf004);
+#endif
return ght;
}
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 *);
#include "ObjectHash.h"
+#ifdef RAW
+#include <raw.h>
+#else
#include <stdio.h>
+#endif
#ifdef DMALLOC
#include "dmalloc.h"
#endif
}
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*/
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--;
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;
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);
#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) {
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) {
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);
#include "SimpleHash.h"
+#ifdef RAW
+#include <raw.h>
+#else
#include <stdio.h>
+#endif
#ifdef DMALLOC
#include "dmalloc.h"
#endif
}
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*/
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--;
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--;
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;
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);
struct malloclist {
struct malloclist *next;
int size;
+#ifdef RAW
+ char * space;
+#else
char space[];
+#endif
};
struct malloclist * top=NULL;
void * cpmalloc(int size) {
int endoffset=offset+size;
+ int tmpoffset=0;
if (top==NULL||endoffset>top->size) {
int basesize=MALLOCSIZE;
struct malloclist *tmp;
top->size=basesize;
offset=0;
}
- int tmpoffset=offset;
+ tmpoffset=offset;
offset+=size;
return &top->space[tmpoffset];
}
void checkvalid(void * ptr) {
if (ptr>=curr_heapbase&&ptr<=curr_heaptop) {
+#ifndef RAW
printf("Valid\n");
+#endif
}
}
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);
}
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);
}
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;
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/uio.h>
+//#ifndef RAW
+//#include <sys/uio.h>
+//#endif
#include <unistd.h>
#include "structdefs.h"
#include "mem.h"
}
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___) {
#ifndef MEMH
#define MEMH
#include<stdlib.h>
+#ifndef RAW
#include<stdio.h>
+#endif
#ifdef BOEHM_GC
#include "gc.h"
#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
#include<fcntl.h>
#include<errno.h>
#include<signal.h>
+#ifndef RAW
#include<stdio.h>
-#include "option.h"
+#endif
+//#include "option.h"
extern int classsize[];
jmp_buf error_handler;
#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");
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)
}
#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___;
short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
putchar(sc);
}
+#endif
}
/* Object allocation function */
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;
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;
void * allocate_new(int type) {
struct ___Object___ * v=FREEMALLOC(classsize[type]);
v->type=type;
+ v->isolate = 1;
+ v->version = 0;
return v;
}
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;
}
#ifdef TASK
#include "runtime.h"
+#ifndef RAW
#include "structdefs.h"
#include "mem.h"
#include "checkpoint.h"
#include <signal.h>
#include <assert.h>
#include <errno.h>
+#endif
#ifdef RAW
+#include <raw.h>
+#include <raw_compiler_defs.h>
+#include <libints.h>
#elif defined THREADSIMULATE
-#if 0
-#include <sys/mman.h> // for mmap
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-int offset_transObj = 0;
-#endif
-
// use POSIX message queue
// for each core, its message queue named as
// /msgqueue_corenum
extern int debugtask;
extern int instaccum;
+#ifdef RAW
+#define TOTALCORE raw_get_num_tiles()
+#endif
+
#ifdef CONSCHECK
#include "instrument.h"
#endif
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;
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];
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: <bin> <corenum>\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;
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;
#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;
}
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;
/* 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) {
#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);
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<ao->___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___<ao->___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};
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<ao->___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
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___<ao->___length___) {
+#ifdef RAW
+ raw_test_pass(0xb00b);
+#endif
ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj);
} else {
int i;
}
ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
tagd->flagptr=(struct ___Object___ *) aonew;
+#ifdef RAW
+ raw_test_pass(0xb00c);
+#endif
}
}
}
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;
goto PROCESSCLEAR;
}
}
+#ifndef RAW
printf("ERROR 2 in tagclear\n");
+#endif
+ ;
}
PROCESSCLEAR:
{
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;
goto ENDCLEAR;
}
}
+#ifndef RAW
printf("ERROR 4 in tagclear\n");
+#endif
}
}
ENDCLEAR:
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);
}
}
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);
}
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);
}
}
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);
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) {
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;
}
}
+#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;i<parameter->numbertags;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;i<parameter->numbertags;i++) {
+ //slotid is parameter->tagarray[2*i];
+ int tagid=parameter->tagarray[2*i+1];
+ int j;
+ for(j=0;j<ao->___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;i<parameter->numberofterms;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
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 {
// 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);
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("<transStallMsg> to %s index: %d, sendobjs: %d, receiveobjs: %d\n", path, newobj.flag, newobj.___cachedHash___, newobj.___cachedCode___);
+ printf("<transStallMsg> 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;
} 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
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)) {
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;
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;
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);
#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)) {
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;
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;
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);
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);
}
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;j<numiterators;j++) {
+ toiReset(¶meter->iterators[j]);
+ }
+
+ /* Find initial state */
+ for(j=0;j<numiterators;j++) {
+ backtrackinit:
+ if(toiHasNext(¶meter->iterators[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; j<numiterators;j++) {
+ backtrackinc:
+ if(toiHasNext(¶meter->iterators[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
sigprocmask(SIG_UNBLOCK, &toclear,NULL);
longjmp(error_handler,1);
}
+#endif
fd_set readfds;
int maxreadfd;
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;
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;
}
}
}
+#endif
/* See if there are any active tasks */
if (hashsize(activetasks)>0) {
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;i<numparams;i++) {
void * parameter=currtpd->parameterArray[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
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]) {
}
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)) {
}
}
// 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 */
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;
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);
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)<failurechance) {
taskpointerarray[1]=NULL;
#endif
if(debugtask){
+#ifndef RAW
printf("ENTER %s count=%d\n",currtpd->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 */
for(i=0;i<numtasks[numofcore];i++) {
struct taskdescriptor * task=taskarray[numofcore][i];
#else
+#ifdef RAW
+ if(corenum > NUMCORES - 1) {
+ return;
+ }
+#endif
for(i=0;i<numtasks[corenum];i++) {
struct taskdescriptor * task=taskarray[corenum][i];
#endif
+#ifndef RAW
printf("%s\n", task->name);
+#endif
for(j=0;j<task->numParameters;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);
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<ao->___cachedCode___;tagindex++) {
+#ifndef RAW
printf(" tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*, tagindex));
+#endif
}
}
}
void processtasks() {
int i;
+#ifdef RAW
+ if(corenum > NUMCORES - 1) {
+ return;
+ }
+#endif
#ifdef THREADSIMULATE
int numofcore = pthread_getspecific(key);
for(i=0;i<numtasks[numofcore];i++) {
struct parameterwrapper *parameter=param->queue;
builditerators(task, j, parameter);
}
- }
+ }
}
void toiReset(struct tagobjectiterator * it) {
#include "object.h"
+#ifdef RAW
+#include <raw.h>
+#else
#include "stdio.h"
+#endif
#include "stdlib.h"
#ifdef THREADS
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
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);
};
#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);
void processtasks();
#ifdef MULTICORE
-void transferObject(void * ptr, int targetcore);
+void transferObject(struct transObjInfo * transObj);
#endif
#ifndef MULTICORE
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
#include "runtime.h"
#include "structdefs.h"
-#include <sys/socket.h>
#include <fcntl.h>
+#ifndef RAW
+#include <sys/socket.h>
#include <arpa/inet.h>
#include <strings.h>
-#include <errno.h>
#include <netdb.h>
+#endif
+#include <errno.h>
#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;
error:
close(___fd___);
return -1;
+#endif
}
#ifdef TASK
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;
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;
}
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;
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___;
#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) {
}
if (length!=0) {
+#ifndef RAW
perror("ERROR IN NATIVEWRITE");
printf("error=%d remaining bytes %d\n",errno, length);
+#endif
}
break;
}
if (byteread<0) {
+#ifndef RAW
printf("ERROR IN NATIVEREAD\n");
perror("");
+#endif
}
#ifdef TASK
#ifdef MULTICORE
#include <DSTM/interface/dstm.h>
#include <DSTM/interface/llookup.h>
+#ifndef RAW
#include <stdio.h>
+#endif
int threadcount;
pthread_mutex_t gclock;
pthread_mutex_t gclistlock;
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
MULTICOREFLAG=false
TRANSSTATSFLAG=false
RAWFLAG=false
+RAWCONFIG=''
+INTERRUPTFLAG=false
THREADSIMULATEFLAG=false;
USEDMALLOC=false
THREADFLAG=false
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
#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 \
tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
fi
+fi #!RAWFLAG
+
exit