From 4a4ad151c5485affc360d96352baeb43bf055a51 Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 23 Dec 2009 19:49:47 +0000 Subject: [PATCH] initial commit for adding memory conflicts feature to the SESE runtime. seems to work fine with a very simple test case. --- Robust/src/Analysis/MLP/ConflictGraph.java | 138 ++++++++++- Robust/src/Analysis/MLP/LiveInNode.java | 8 +- Robust/src/Analysis/MLP/MLPAnalysis.java | 215 ++++++++++++++++-- .../Analysis/MLP/ParentChildConflictsMap.java | 6 + .../OwnershipAnalysis/HeapRegionNode.java | 13 ++ .../OwnershipAnalysis/OwnershipAnalysis.java | 1 - Robust/src/IR/Flat/BuildCode.java | 105 ++++++++- Robust/src/Runtime/mlp_runtime.c | 22 ++ Robust/src/Runtime/mlp_runtime.h | 12 + 9 files changed, 490 insertions(+), 30 deletions(-) diff --git a/Robust/src/Analysis/MLP/ConflictGraph.java b/Robust/src/Analysis/MLP/ConflictGraph.java index 6cf4cbc0..bdc4d1fc 100644 --- a/Robust/src/Analysis/MLP/ConflictGraph.java +++ b/Robust/src/Analysis/MLP/ConflictGraph.java @@ -431,7 +431,8 @@ public class ConflictGraph { String liveinNodeID = td + "_" + fsen.getIdentifier(); LiveInNode newNode = new LiveInNode(liveinNodeID, td, hrnSet, - readEffectsSet, writeEffectsSet, reachabilitySet); + readEffectsSet, writeEffectsSet, reachabilitySet, fsen + .getIdentifier()); id2cn.put(liveinNodeID, newNode); } @@ -460,6 +461,141 @@ public class ConflictGraph { return resultSet; } + /* + public Set getAllocationSiteIDSetBySESEID(int seseID) { + + HashSet allocSiteIDSet = new HashSet(); + + Set> s = id2cn.entrySet(); + Iterator> i = s.iterator(); + + while (i.hasNext()) { + Entry entry = i.next(); + ConflictNode node = entry.getValue(); + + if (node instanceof LiveInNode) { + LiveInNode liveInNode = (LiveInNode) node; + if (liveInNode.getSESEIdentifier() == seseID) { + Set hrnSet = liveInNode.getHRNSet(); + for (Iterator iterator = hrnSet.iterator(); iterator + .hasNext();) { + HeapRegionNode hrn = (HeapRegionNode) iterator.next(); + // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); + allocSiteIDSet.add(new pthread_mutex_lock( &(parentCommon->lock) ); + addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites,196130920,seseToIssue->common.classID); + ++(seseToIssue->common.unresolvedDependencies); + addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites,1289650030,seseToIssue->common.classID); Integer(hrn + .getGloballyUniqueIntegerIdentifier())); + } + } + } + } + + return allocSiteIDSet; + + } +*/ + + public Set getAllocationSiteIDSetBySESEID(int seseID) { + + HashSet allocSiteIDSet = new HashSet(); + + Set> s = id2cn.entrySet(); + Iterator> i = s.iterator(); + + while (i.hasNext()) { + Entry entry = i.next(); + ConflictNode node = entry.getValue(); + + if (node instanceof LiveInNode) { + LiveInNode liveInNode = (LiveInNode) node; + if (liveInNode.getSESEIdentifier() == seseID) { + + HashSet edgeSet = liveInNode.getEdgeSet(); + for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) { + ConflictEdge conflictEdge = (ConflictEdge) iterator.next(); + if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE) { + allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge.getVertexU())); + allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge.getVertexV())); + }else{// it is fine-grain edge + allocSiteIDSet.addAll(getHRNIdentifierSet(node)); + } + } + + +// Set hrnSet = liveInNode.getHRNSet(); +// for (Iterator iterator = hrnSet.iterator(); iterator +// .hasNext();) { +// HeapRegionNode hrn = (HeapRegionNode) iterator.next(); +// // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); +// allocSiteIDSet.add(new Integer(hrn +// .getGloballyUniqueIntegerIdentifier())); +// } + + } + } + } + + return allocSiteIDSet; + + } + + public Set getAllocationSiteIDSet() { + + HashSet allocSiteIDSet = new HashSet(); + + Set> s = id2cn.entrySet(); + Iterator> i = s.iterator(); + + while (i.hasNext()) { + Entry entry = i.next(); + ConflictNode node = entry.getValue(); + + HashSet edgeSet = node.getEdgeSet(); + for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) { + ConflictEdge conflictEdge = (ConflictEdge) iterator.next(); + if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE) { + allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge.getVertexU())); + allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge.getVertexV())); + }else{// it is fine-grain edge + allocSiteIDSet.addAll(getHRNIdentifierSet(node)); + } + } + + } + + return allocSiteIDSet; + + } + + private HashSet getHRNIdentifierSet(ConflictNode node) { + + HashSet returnSet = new HashSet(); + + if (node instanceof StallSiteNode) { + StallSiteNode stallSiteNode = (StallSiteNode) node; + Set hrnSet = stallSiteNode.getHRNSet(); + for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) { + HeapRegionNode hrn = (HeapRegionNode) iterator.next(); + // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); + returnSet.add(new Integer(hrn + .getGloballyUniqueIntegerIdentifier())); + } + } else { + LiveInNode liveInNode = (LiveInNode) node; + Set hrnSet = liveInNode.getHRNSet(); + for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) { + HeapRegionNode hrn = (HeapRegionNode) iterator.next(); + // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); + returnSet.add(new Integer(hrn + .getGloballyUniqueIntegerIdentifier())); + } + } + + return returnSet; + + } + public void writeGraph(String graphName, boolean filter) throws java.io.IOException { diff --git a/Robust/src/Analysis/MLP/LiveInNode.java b/Robust/src/Analysis/MLP/LiveInNode.java index c8584fe1..1923ce65 100644 --- a/Robust/src/Analysis/MLP/LiveInNode.java +++ b/Robust/src/Analysis/MLP/LiveInNode.java @@ -12,16 +12,18 @@ public class LiveInNode extends ConflictNode { Set readEffectsSet; Set writeEffectsSet; Set hrnSet; + int seseID; public LiveInNode(String id, TempDescriptor td, Set hrnSet, Set readEffectsSet, - Set writeEffectsSet, Set reachabilitySet) { + Set writeEffectsSet, Set reachabilitySet, int seseID) { this.hrnSet = hrnSet; this.id = id; this.td = td; this.readEffectsSet = readEffectsSet; this.writeEffectsSet = writeEffectsSet; this.reachabilitySet = reachabilitySet; + this.seseID=seseID; } public Set getHRNSet() { @@ -137,6 +139,10 @@ public class LiveInNode extends ConflictNode { return result; } + + public int getSESEIdentifier(){ + return seseID; + } public boolean equals(Object o) { diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index 00c01c0f..2cc97ad0 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -4,6 +4,7 @@ import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; +import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; @@ -97,7 +98,7 @@ public class MLPAnalysis { private Hashtable < FlatNode, ParentChildConflictsMap > conflictsResults; private Hashtable< FlatMethod, MethodSummary > methodSummaryResults; private OwnershipAnalysis ownAnalysisForSESEConflicts; - private Hashtable conflictGraphResults; + private Hashtable conflictGraphResults; // temporal data structures to track analysis progress. private MethodSummary currentMethodSummary; @@ -161,7 +162,7 @@ public class MLPAnalysis { conflictsResults = new Hashtable < FlatNode, ParentChildConflictsMap >(); methodSummaryResults=new Hashtable(); - conflictGraphResults=new Hashtable(); + conflictGraphResults=new Hashtable(); seseSummaryMap= new Hashtable(); isAfterChildSESEIndicatorMap= new Hashtable(); @@ -295,12 +296,37 @@ public class MLPAnalysis { // postSESEConflictsForward(javaCallGraph); // another pass for making graph + makeConflictGraph(); + /* methItr = ownAnalysis.descriptorsToAnalyze.iterator(); while (methItr.hasNext()) { Descriptor d = methItr.next(); FlatMethod fm = state.getMethodFlat(d); - makeConflictGraph(fm); - } + makeConflictGraph2(fm); + } + + Enumeration keyEnum1=conflictGraphResults.keys(); + while (keyEnum1.hasMoreElements()) { + FlatNode flatNode = (FlatNode) keyEnum1.nextElement(); + ConflictGraph conflictGraph=conflictGraphResults.get(flatNode); + conflictGraph.analyzeConflicts(); + conflictGraphResults.put(flatNode, conflictGraph); + } + */ + + Enumeration keyEnum=conflictGraphResults.keys(); + while (keyEnum.hasMoreElements()) { + FlatNode key = (FlatNode) keyEnum.nextElement(); + ConflictGraph cg=conflictGraphResults.get(key); + try { + cg.writeGraph("ConflictGraphFor"+key, false); + } catch (IOException e) { + System.out.println("Error writing"); + System.exit(0); + } + } + + /* methItr = ownAnalysis.descriptorsToAnalyze.iterator(); while(methItr.hasNext()){ Descriptor d = methItr.next(); @@ -315,6 +341,7 @@ public class MLPAnalysis { } } } + */ //////////////// } @@ -1893,10 +1920,7 @@ public class MLPAnalysis { return sorted; } - private void makeConflictGraph(FlatMethod fm) { - - // create conflict graph for each flat method - ConflictGraph conflictGraph = new ConflictGraph(); + private void makeConflictGraph2(FlatMethod fm) { HashSet mcSet = ownAnalysisForSESEConflicts .getAllMethodContextSetByDescriptor(fm.getMethod()); @@ -1909,6 +1933,9 @@ public class MLPAnalysis { flatNodesToVisit.add(fm); Set visited = new HashSet(); + + SESESummary summary = new SESESummary(null, fm); + seseSummaryMap.put(fm, summary); while (!flatNodesToVisit.isEmpty()) { Iterator fnItr = flatNodesToVisit.iterator(); @@ -1916,7 +1943,7 @@ public class MLPAnalysis { flatNodesToVisit.remove(fn); visited.add(fn); - + // /////////////////////////////////////////////////////////////////////// // Adding Stall Node of current program statement ParentChildConflictsMap currentConflictsMap = conflictsResults @@ -1926,45 +1953,143 @@ public class MLPAnalysis { .getStallMap(); Set> entrySet = stallMap .entrySet(); - -// HashSet newStallNodeSet = new HashSet(); - + + + SESESummary seseSummary=seseSummaryMap.get(fn); + + ConflictGraph conflictGraph=null; + conflictGraph=conflictGraphResults.get(seseSummary.getCurrentSESE()); + + if(conflictGraph==null){ + conflictGraph = new ConflictGraph(); + } for (Iterator> iterator2 = entrySet .iterator(); iterator2.hasNext();) { Entry entry = iterator2.next(); TempDescriptor td = entry.getKey(); StallSite stallSite = entry.getValue(); - String stallNodeID; // reachability set OwnershipGraph og = ownAnalysisForSESEConflicts .getOwnvershipGraphByMethodContext(mc); Set reachabilitySet = calculateReachabilitySet(og, td); - conflictGraph.addStallNode(td, fm, stallSite, reachabilitySet); - + + } + + if(conflictGraph.id2cn.size()>0){ + conflictGraphResults.put(seseSummary.getCurrentSESE(), conflictGraph); } - conflictGraph_nodeAction(mc, fm, fn, conflictGraph, - currentConflictsMap); - + conflictGraph_nodeAction(mc, fm, fn); + for (int i = 0; i < fn.numNext(); i++) { FlatNode nn = fn.getNext(i); if (!visited.contains(nn)) { flatNodesToVisit.add(nn); } } - } // end of while(flatNodesToVisit) } // end of while(mcIter) // decide fine-grain edge or coarse-grain edge among all vertexes by pair-wise comparison - conflictGraph.analyzeConflicts(); - conflictGraphResults.put(fm, conflictGraph); + } + + private void makeConflictGraph() { + Iterator methItr = ownAnalysis.descriptorsToAnalyze + .iterator(); + while (methItr.hasNext()) { + Descriptor d = methItr.next(); + FlatMethod fm = state.getMethodFlat(d); + + HashSet mcSet = ownAnalysisForSESEConflicts + .getAllMethodContextSetByDescriptor(fm.getMethod()); + Iterator mcIter = mcSet.iterator(); + + while (mcIter.hasNext()) { + MethodContext mc = mcIter.next(); + + Set flatNodesToVisit = new HashSet(); + flatNodesToVisit.add(fm); + + Set visited = new HashSet(); + + SESESummary summary = new SESESummary(null, fm); + seseSummaryMap.put(fm, summary); + + while (!flatNodesToVisit.isEmpty()) { + Iterator fnItr = flatNodesToVisit.iterator(); + FlatNode fn = fnItr.next(); + + flatNodesToVisit.remove(fn); + visited.add(fn); + + // Adding Stall Node of current program statement + ParentChildConflictsMap currentConflictsMap = conflictsResults + .get(fn); + + Hashtable stallMap = currentConflictsMap + .getStallMap(); + Set> entrySet = stallMap + .entrySet(); + + SESESummary seseSummary = seseSummaryMap.get(fn); + + ConflictGraph conflictGraph = null; + conflictGraph = conflictGraphResults.get(seseSummary + .getCurrentSESE()); + + if (conflictGraph == null) { + conflictGraph = new ConflictGraph(); + } + for (Iterator> iterator2 = entrySet + .iterator(); iterator2.hasNext();) { + Entry entry = iterator2 + .next(); + TempDescriptor td = entry.getKey(); + StallSite stallSite = entry.getValue(); + + // reachability set + OwnershipGraph og = ownAnalysisForSESEConflicts + .getOwnvershipGraphByMethodContext(mc); + Set reachabilitySet = calculateReachabilitySet(og, + td); + conflictGraph.addStallNode(td, fm, stallSite, + reachabilitySet); + + } + + if (conflictGraph.id2cn.size() > 0) { + conflictGraphResults.put(seseSummary.getCurrentSESE(), + conflictGraph); + } + conflictGraph_nodeAction(mc, fm, fn); + + for (int i = 0; i < fn.numNext(); i++) { + FlatNode nn = fn.getNext(i); + if (!visited.contains(nn)) { + flatNodesToVisit.add(nn); + } + } + } // end of while(flatNodesToVisit) + + } // end of while(mcIter) + + } + + // decide fine-grain edge or coarse-grain edge among all vertexes by pair-wise comparison + Enumeration keyEnum1=conflictGraphResults.keys(); + while (keyEnum1.hasMoreElements()) { + FlatNode flatNode = (FlatNode) keyEnum1.nextElement(); + ConflictGraph conflictGraph=conflictGraphResults.get(flatNode); + conflictGraph.analyzeConflicts(); + conflictGraphResults.put(flatNode, conflictGraph); + } + } private Set calculateReachabilitySet(OwnershipGraph og, @@ -2001,9 +2126,25 @@ public class MLPAnalysis { return reachabilitySet; } - private void conflictGraph_nodeAction(MethodContext mc, FlatMethod fm, + private void conflictGraph_nodeAction2(MethodContext mc, FlatMethod fm, FlatNode fn, ConflictGraph graph, ParentChildConflictsMap currentConflictsMap) { + + switch (fn.kind()) { + + case FKind.FlatSESEEnterNode: { + + }break; + + + + } + + + } + + private void conflictGraph_nodeAction(MethodContext mc, FlatMethod fm, + FlatNode fn) { switch (fn.kind()) { @@ -2015,6 +2156,15 @@ public class MLPAnalysis { if (!fsen.getIsCallerSESEplaceholder()) { Set invar_set = fsen.getInVarSet(); + + SESESummary seseSummary=seseSummaryMap.get(fsen); + ConflictGraph conflictGraph=null; + conflictGraph=conflictGraphResults.get(seseSummary.getCurrentParent()); + + if(conflictGraph==null){ + conflictGraph = new ConflictGraph(); + } + for (Iterator iterator = invar_set.iterator(); iterator .hasNext();) { @@ -2041,11 +2191,15 @@ public class MLPAnalysis { .next(); hrnSet.add(referenceEdge.getDst()); } - graph.addLiveInNode(tempDescriptor, hrnSet, fsen, + + conflictGraph.addLiveInNode(tempDescriptor, hrnSet, fsen, readEffectsSet, writeEffectsSet, reachabilitySet); - } - + + if(conflictGraph.id2cn.size()>0){ + conflictGraphResults.put(seseSummary.getCurrentParent(),conflictGraph); + } + } } @@ -2206,6 +2360,8 @@ public class MLPAnalysis { isAfterChildSESEIndicatorMap.put(currentSummary .getCurrentParent(), new Boolean(true)); } +// currentConflictsMap = new ParentChildConflictsMap(); + currentConflictsMap.clear(); } break; @@ -3225,4 +3381,13 @@ public class MLPAnalysis { printSESEInfoTree( bw, fsenChild ); } } + + public Hashtable getConflictGraphResults(){ + return conflictGraphResults; + } + + public Hashtable < FlatNode, ParentChildConflictsMap > getConflictsResults(){ + return conflictsResults; + } + } diff --git a/Robust/src/Analysis/MLP/ParentChildConflictsMap.java b/Robust/src/Analysis/MLP/ParentChildConflictsMap.java index 5a6cd89d..773b5eaa 100644 --- a/Robust/src/Analysis/MLP/ParentChildConflictsMap.java +++ b/Robust/src/Analysis/MLP/ParentChildConflictsMap.java @@ -27,6 +27,12 @@ public class ParentChildConflictsMap { stallEdgeMap= new Hashtable < ReferenceEdge, HashSet >(); } + public void clear(){ + accessibleMap.clear(); + stallMap.clear(); + stallEdgeMap.clear(); + } + public void makeAllInaccessible(){ Set keySet=accessibleMap.keySet(); diff --git a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java index 36b6c8a5..16cc332b 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java +++ b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java @@ -231,4 +231,17 @@ public class HeapRegionNode extends OwnershipNode { public String getGloballyUniqueIdentifier(){ return globalIdentifier; } + + public int getGloballyUniqueIntegerIdentifier() { + String fristpart = globalIdentifier; + fristpart = fristpart.replaceAll("FN", "1"); + fristpart = fristpart.replaceAll("FM", "2"); + int idx = fristpart.indexOf("."); + String endpart = fristpart.substring(idx + 1); + endpart = endpart.replaceAll("S", "1"); + endpart = endpart.replaceAll("P", "2"); + endpart = endpart.replaceAll("A", "3"); + String modified = fristpart.substring(0, idx) + endpart; + return Integer.parseInt(modified); + } } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 13d49da9..f3606325 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -1540,7 +1540,6 @@ public class OwnershipAnalysis { } public MethodContext getCalleeMethodContext(MethodContext callerMC, FlatCall fc){ - assert methodEffects; Hashtable table=mapMethodContextToFlatNodeOwnershipGraph.get(callerMC); diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index ed4b95a0..a51e86de 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -27,6 +27,7 @@ import Analysis.Prefetch.*; import Analysis.Loops.WriteBarrier; import Analysis.Loops.GlobalFieldType; import Analysis.Locality.TypeAnalysis; +import Analysis.MLP.ConflictGraph; import Analysis.MLP.MLPAnalysis; import Analysis.MLP.VariableSourceToken; import Analysis.MLP.CodePlan; @@ -1744,6 +1745,28 @@ public class BuildCode { } } } + + // set up related allocation sites's waiting queues + // eom + output.println(" /* set up waiting queues */"); + ConflictGraph graph=null; + graph=mlpa.getConflictGraphResults().get(fm); + if(graph!=null){ + Set allocSet=graph.getAllocationSiteIDSet(); + + if(allocSet.size()>0){ + output.println(" int numRelatedAllocSites="+allocSet.size()+";"); + output.println(" seseCaller->numRelatedAllocSites=numRelatedAllocSites;"); + output.println(" seseCaller->allocSiteArray=mlpCreateAllocSiteArray(numRelatedAllocSites);"); + int idx=0; + for (Iterator iterator = allocSet.iterator(); iterator.hasNext();) { + Integer allocID = (Integer) iterator.next(); + output.println(" seseCaller->allocSiteArray["+idx+"].id="+allocID+";"); + idx++; + } + output.println(); + } + } } @@ -3171,7 +3194,7 @@ public class BuildCode { output.println(" SESEcommon* parentCommon = seseCaller;"); } } - + // before doing anything, lock your own record and increment the running children if( fsen != mlpa.getMainSESE() ) { output.println(" pthread_mutex_lock( &(parentCommon->lock) );"); @@ -3224,6 +3247,56 @@ public class BuildCode { generateTemp( fsen.getfmEnclosing(), temp, null )+";"); } } + + // count up memory conflict dependencies, + // eom + ConflictGraph graph=null; + FlatSESEEnterNode parent=fsen.getParent(); + if(parent!=null){ + if(parent.isCallerSESEplaceholder){ + graph=mlpa.getConflictGraphResults().get(parent.getfmEnclosing()); + }else{ + graph=mlpa.getConflictGraphResults().get(fsen); + } + } + if (graph != null) { + output.println(); + output.println(" /*add waiting queue element*/"); + + Set allocSet = graph.getAllocationSiteIDSetBySESEID(fsen + .getIdentifier()); + if (allocSet.size() > 0) { + output.println(" {"); + output + .println(" pthread_mutex_lock( &(parentCommon->lock) );"); + + for (Iterator iterator = allocSet.iterator(); iterator + .hasNext();) { + Integer allocID = (Integer) iterator.next(); + output + .println(" addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites," + + allocID + + ",seseToIssue);"); + output + .println(" ++(seseToIssue->common.unresolvedDependencies);"); + } + output + .println(" pthread_mutex_unlock( &(parentCommon->lock) );"); + output.println(" }"); + } + + output.println(" /*decide whether it is runnable or not in regarding to memory conflicts*/"); + output.println(" {"); + output.println(" int idx;"); + output.println(" for(idx = 0 ; idx < numRelatedAllocSites ; idx++){"); + output.println(" SESEcommon* item=peekItem(seseCaller->allocSiteArray[idx].waitingQueue);"); + output.println(" if(item->classID==seseToIssue->common.classID){"); + output.println(" --(seseToIssue->common.unresolvedDependencies);"); + output.println(" }"); + output.println(" }"); + output.println(" }"); + output.println(); + } // before potentially adding this SESE to other forwarding lists, // create it's lock and take it immediately @@ -3317,6 +3390,7 @@ public class BuildCode { } output.println(" "+p+" = seseToIssue;"); } + } // if there were no outstanding dependencies, issue here @@ -3328,7 +3402,7 @@ public class BuildCode { // eventually, for it to mark itself finished output.println(" pthread_mutex_unlock( &(seseToIssue->common.lock) );"); output.println(" }"); - + } public void generateFlatSESEExitNode( FlatMethod fm, @@ -3416,6 +3490,33 @@ public class BuildCode { output.println(" pthread_mutex_unlock( &(consumer->lock) );"); output.println(" }"); + // eom + // clean up its lock element from waiting queue, and decrement dependency count for next SESE block + if( fsen != mlpa.getMainSESE() ) { + output.println(); + output.println(" /* check memory dependency*/"); + output.println(" {"); + output.println(" int idx;"); + output.println(" for(idx = 0 ; idx < ___params___->common.parent->numRelatedAllocSites ; idx++){"); + output.println(" SESEcommon* item=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);"); + output.println(" if( item->classID == ___params___->common.classID ){"); + output.println(" struct QueueItem* qItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,item);"); + output.println(" removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,qItem);"); + output.println(" if( !isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue) ){"); + output.println(" SESEcommon* nextItem=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);"); + output.println(" pthread_mutex_lock( &(nextItem->lock) );"); + output.println(" --(nextItem->unresolvedDependencies);"); + output.println(" if( nextItem->unresolvedDependencies == 0){"); + output.println(" workScheduleSubmit( (void*)nextItem);"); + output.println(" }"); + output.println(" pthread_mutex_unlock( &(nextItem->lock) );"); + output.println(" }"); + output.println(" }"); + output.println(" }"); + output.println(" }"); + } + + // if parent is stalling on you, let them know you're done if( fsexn.getFlatEnter() != mlpa.getMainSESE() ) { output.println(" psem_give( &("+paramsprefix+"->common.stallSem) );"); diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index 637558d1..2101ce23 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -29,3 +29,25 @@ void* mlpAllocSESErecord( int size ) { void mlpFreeSESErecord( void* seseRecord ) { RUNFREE( seseRecord ); } + +AllocSite* mlpCreateAllocSiteArray(int numAllocSites){ + int i; + AllocSite* newAllocSite=(AllocSite*)RUNMALLOC( sizeof( AllocSite ) * numAllocSites ); + for(i=0; iclassID,allocID); + break; + } + } + +} diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index 3f7ca184..05d4ca57 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -15,6 +15,12 @@ #define TRUE 1 #endif +// each allocation site nees the following +typedef struct AllocSite_t{ + int id; + struct Queue* waitingQueue; +} AllocSite; + // forward declaration of pointer type typedef struct SESEcommon_t* SESEcommon_p; @@ -48,6 +54,10 @@ typedef struct SESEcommon_t { SESEcommon_p parent; + AllocSite* allocSiteArray; + int numRelatedAllocSites; + psemaphore stallSiteSem; + } SESEcommon; @@ -66,5 +76,7 @@ extern __thread SESEcommon_p seseCaller; void* mlpCreateSESErecord( int size ); void mlpDestroySESErecord( void* seseRecord ); +AllocSite* mlpCreateAllocSiteArray(int numAllocSites); + #endif /* __MLP_RUNTIME__ */ -- 2.34.1