From edae4bedef87b02fa16acc12b68fc4727d90a6a4 Mon Sep 17 00:00:00 2001 From: jjenista Date: Tue, 18 Aug 2009 17:32:54 +0000 Subject: [PATCH] found one reason for system hang--there is still at least one other problem that sometimes causes it, now much less frequently --- Robust/src/Analysis/MLP/MLPAnalysis.java | 52 ++++++++++++++++-- Robust/src/IR/Flat/BuildCode.java | 68 +++++++++++++++++++----- Robust/src/Runtime/mlp_runtime.h | 3 ++ Robust/src/Tests/mlp/tinyTest/test.java | 24 +++++++-- 4 files changed, 126 insertions(+), 21 deletions(-) diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index ea827af0..49fca039 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -143,7 +143,7 @@ public class MLPAnalysis { pruneVariableResultsWithLiveness( fm ); } if( state.MLPDEBUG ) { - //System.out.println( "\nVariable Results-Out\n----------------\n"+fmMain.printMethod( variableResults ) ); + System.out.println( "\nVariable Results-Out\n----------------\n"+fmMain.printMethod( variableResults ) ); } @@ -175,7 +175,6 @@ public class MLPAnalysis { //System.out.println( "\nCode Plans\n----------\n"+fmMain.printMethod( codePlans ) ); } - // splice new IR nodes into graph after all // analysis passes are complete Iterator spliceItr = wdvNodesToSpliceIn.entrySet().iterator(); @@ -185,6 +184,10 @@ public class MLPAnalysis { fwdvn.spliceIntoIR(); } + // detailed per-SESE information + if( state.MLPDEBUG ) { + System.out.println( "\nSESE info\n-------------\n" ); printSESEInfo(); + } double timeEndAnalysis = (double) System.nanoTime(); double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) ); @@ -447,6 +450,49 @@ public class MLPAnalysis { } } + private void printSESEInfo() { + printSESEInfoTree( rootSESE ); + System.out.println( "" ); + } + + private void printSESEInfoTree( FlatSESEEnterNode fsen ) { + + System.out.println( "SESE "+fsen.getPrettyIdentifier()+" {" ); + + System.out.println( " in-set: "+fsen.getInVarSet() ); + Iterator tItr = fsen.getInVarSet().iterator(); + while( tItr.hasNext() ) { + TempDescriptor inVar = tItr.next(); + if( fsen.getReadyInVarSet().contains( inVar ) ) { + System.out.println( " (ready) "+inVar ); + } + if( fsen.getStaticInVarSet().contains( inVar ) ) { + System.out.println( " (static) "+inVar ); + } + if( fsen.getDynamicInVarSet().contains( inVar ) ) { + System.out.println( " (dynamic)"+inVar ); + } + } + + System.out.println( " out-set: "+fsen.getOutVarSet() ); + + /* + System.out.println( " static names to track:" ); + tItr = fsen.getOutVarSet().iterator(); + while( tItr.hasNext() ) { + System.out.println( " "+tItr.next() ); + } + */ + + System.out.println( "}" ); + + Iterator childItr = fsen.getChildren().iterator(); + while( childItr.hasNext() ) { + FlatSESEEnterNode fsenChild = childItr.next(); + printSESEInfoTree( fsenChild ); + } + } + private void variableAnalysisForward( FlatMethod fm ) { @@ -957,7 +1003,7 @@ public class MLPAnalysis { // just stall for the exact thing we need and move on plan.addDynamicStall( readtmp ); currentSESE.addDynamicVar( readtmp ); - + } else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) { // 2) Single token/age pair: Stall for token/age pair, and copy // all live variables with same token/age pair at the same diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index cff00ce7..789d90e4 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1931,8 +1931,20 @@ public class BuildCode { TempDescriptor temp = tempItr.next(); VariableSourceToken vst = fsen.getStaticInVarSrc( temp ); SESEandAgePair srcPair = new SESEandAgePair( vst.getSESE(), vst.getAge() ); + + // can't grab something from this source until it is done + output.println(" {"); + output.println(" SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+srcPair+";" ); + output.println(" pthread_mutex_lock( &(com->lock) );"); + output.println(" while( com->doneExecuting == FALSE ) {"); + output.println(" pthread_cond_wait( &(com->doneCond), &(com->lock) );"); + output.println(" }"); + output.println(" pthread_mutex_unlock( &(com->lock) );"); + output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+ " = "+paramsprefix+"->"+srcPair+"->"+vst.getAddrVar()+";"); + + output.println(" }"); } // dynamic vars come from an SESE and src @@ -1942,6 +1954,15 @@ public class BuildCode { // go grab it from the SESE source output.println(" if( "+paramsprefix+"->"+temp+"_srcSESE != NULL ) {"); + + // gotta wait until the source is done + output.println(" SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+temp+"_srcSESE;" ); + output.println(" pthread_mutex_lock( &(com->lock) );"); + output.println(" while( com->doneExecuting == FALSE ) {"); + output.println(" pthread_cond_wait( &(com->doneCond), &(com->lock) );"); + output.println(" }"); + output.println(" pthread_mutex_unlock( &(com->lock) );"); + output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+ " = *(("+temp.getType().toPrettyString()+"*) ("+ paramsprefix+"->"+temp+"_srcSESE + "+ @@ -2289,7 +2310,14 @@ public class BuildCode { output.println(" {"); output.println(" SESEcommon* common = (SESEcommon*) "+p+";"); - output.println(" psem_take( &(common->stallSem) );"); + + output.println(" pthread_mutex_lock( &(common->lock) );"); + output.println(" while( common->doneExecuting == FALSE ) {"); + output.println(" pthread_cond_wait( &(common->doneCond), &(common->lock) );"); + output.println(" }"); + output.println(" pthread_mutex_unlock( &(common->lock) );"); + + //output.println(" psem_take( &(common->stallSem) );"); // copy things we might have stalled for output.println(" "+p.getSESE().getSESErecordName()+"* child = ("+ @@ -2814,13 +2842,9 @@ public class BuildCode { output.println(" seseToIssue->common.classID = "+fsen.getIdentifier()+";"); output.println(" psem_init( &(seseToIssue->common.stallSem) );"); - // before potentially adding this SESE to other forwarding lists, - // create it's lock and take it immediately - output.println(" pthread_mutex_init( &(seseToIssue->common.lock), NULL );"); - output.println(" pthread_mutex_lock( &(seseToIssue->common.lock) );"); - output.println(" seseToIssue->common.forwardList = createQueue();"); output.println(" seseToIssue->common.unresolvedDependencies = 0;"); + output.println(" pthread_cond_init( &(seseToIssue->common.doneCond), NULL );"); output.println(" seseToIssue->common.doneExecuting = FALSE;"); output.println(" pthread_cond_init( &(seseToIssue->common.runningChildrenCond), NULL );"); output.println(" seseToIssue->common.numRunningChildren = 0;"); @@ -2844,6 +2868,11 @@ public class BuildCode { } } + // before potentially adding this SESE to other forwarding lists, + // create it's lock and take it immediately + output.println(" pthread_mutex_init( &(seseToIssue->common.lock), NULL );"); + output.println(" pthread_mutex_lock( &(seseToIssue->common.lock) );"); + if( fsen != mlpa.getRootSESE() ) { // count up outstanding dependencies, static first, then dynamic Iterator staticSrcsItr = fsen.getStaticInVarSrcs().iterator(); @@ -2857,8 +2886,10 @@ public class BuildCode { output.println(" printf( \"This shouldnt already be here\\n\");"); output.println(" exit( -1 );"); output.println(" }"); - output.println(" addNewItem( src->forwardList, seseToIssue );"); - output.println(" ++(seseToIssue->common.unresolvedDependencies);"); + output.println(" if( !src->doneExecuting ) {"); + output.println(" addNewItem( src->forwardList, seseToIssue );"); + output.println(" ++(seseToIssue->common.unresolvedDependencies);"); + output.println(" }"); output.println(" pthread_mutex_unlock( &(src->lock) );"); output.println(" }"); @@ -2882,8 +2913,10 @@ public class BuildCode { output.println(" pthread_mutex_lock( &(src->lock) );"); output.println(" if( isEmpty( src->forwardList ) ||"); output.println(" seseToIssue != peekItem( src->forwardList ) ) {"); - output.println(" addNewItem( src->forwardList, seseToIssue );"); - output.println(" ++(seseToIssue->common.unresolvedDependencies);"); + output.println(" if( !src->doneExecuting ) {"); + output.println(" addNewItem( src->forwardList, seseToIssue );"); + output.println(" ++(seseToIssue->common.unresolvedDependencies);"); + output.println(" }"); output.println(" }"); output.println(" pthread_mutex_unlock( &(src->lock) );"); output.println(" seseToIssue->"+dynInVar+"_srcOffset = "+dynInVar+"_srcOffset;"); @@ -2939,7 +2972,7 @@ public class BuildCode { output.println(" while( "+com+".numRunningChildren > 0 ) {"); output.println(" pthread_cond_wait( &("+com+".runningChildrenCond), &("+com+".lock) );"); output.println(" }"); - output.println(" pthread_mutex_unlock( &("+com+".lock) );"); + //output.println(" pthread_mutex_unlock( &("+com+".lock) );"); // copy out-set from local temps into the sese record Iterator itr = fsexn.getFlatEnter().getOutVarSet().iterator(); @@ -2951,8 +2984,9 @@ public class BuildCode { } // mark yourself done, your SESE data is now read-only - output.println(" pthread_mutex_lock( &("+com+".lock) );"); + //output.println(" pthread_mutex_lock( &("+com+".lock) );"); output.println(" "+com+".doneExecuting = TRUE;"); + output.println(" pthread_cond_signal( &("+com+".doneCond) );"); output.println(" pthread_mutex_unlock( &("+com+".lock) );"); // decrement dependency count for all SESE's on your forwarding list @@ -3002,10 +3036,16 @@ public class BuildCode { TempDescriptor refVar = (TempDescriptor) me.getKey(); VariableSourceToken vst = (VariableSourceToken) me.getValue(); - SESEandAgePair instance = new SESEandAgePair( vst.getSESE(), vst.getAge() ); - FlatSESEEnterNode current = fwdvn.getEnclosingSESE(); + // only do this if the variable in question should be tracked, + // meaning that it was explicitly added to the dynamic var set + if( !current.getDynamicVarSet().contains( vst.getAddrVar() ) ) { + continue; + } + + SESEandAgePair instance = new SESEandAgePair( vst.getSESE(), vst.getAge() ); + output.println(" {"); if( current.equals( vst.getSESE() ) ) { diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index f2f291d3..859a430b 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -39,10 +39,13 @@ typedef struct SESEcommon_t { struct Queue* forwardList; int unresolvedDependencies; + + pthread_cond_t doneCond; int doneExecuting; pthread_cond_t runningChildrenCond; int numRunningChildren; + SESEcommon_p parent; } SESEcommon; diff --git a/Robust/src/Tests/mlp/tinyTest/test.java b/Robust/src/Tests/mlp/tinyTest/test.java index 17e45e0b..c7637214 100644 --- a/Robust/src/Tests/mlp/tinyTest/test.java +++ b/Robust/src/Tests/mlp/tinyTest/test.java @@ -8,8 +8,8 @@ public class Test { public static void main( String args[] ) { - int x = Integer.parseInt( args[0] ); - int y = Integer.parseInt( args[1] ); + //int x = Integer.parseInt( args[0] ); + //int y = Integer.parseInt( args[1] ); //System.out.println( "root: x="+x+", y="+y ); /* @@ -26,16 +26,32 @@ public class Test { } */ + int total = 0; - for( int i = 0; i < x; ++i ) { + for( int i = 0; i < 5; ++i ) { + + System.out.println( "i="+i ); + sese sum { total = total + i; } } - + //setTo3( foo ); + + + /* + int total = 0; + sese kemper { + for( int i = 0; i < 5; ++i ) { + total = total + i; + } + } + */ + + System.out.println( "total="+total ); // just for testing root's ability to -- 2.34.1