From: jjenista Date: Wed, 10 Jun 2009 16:55:20 +0000 (+0000) Subject: more mlp code, needs dependency counts X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f25418f8dde1e9a1f6242b99f42cc95059077d51;p=IRC.git more mlp code, needs dependency counts --- diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 18a403cb..d765ecaa 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -55,6 +55,9 @@ public class BuildCode { SafetyAnalysis sa; PrefetchAnalysis pa; MLPAnalysis mlpa; + String mlperrstr = "if(status != 0) { "+ + "sprintf(errmsg, \"MLP error at %s:%d\", __FILE__, __LINE__); "+ + "perror(errmsg); exit(-1); }"; Hashtable sese2bogusFlatMeth; boolean nonSESEpass=true; WriteBarrier wb; @@ -427,6 +430,8 @@ public class BuildCode { outmethod.println("#include \"checkers.h\""); } if (state.MLP) { + outmethod.println("#include "); + outmethod.println("#include "); outmethod.println("#include \"mlp_runtime.h\""); outmethod.println("/* GET RID OF THIS LATER */"); outmethod.println("SESErecord* tempSESE;"); @@ -1515,18 +1520,30 @@ public class BuildCode { output.println("}\n\n"); } + // when a new mlp thread is created for an issued SESE, it is started + // by running this method which blocks on a cond variable until + // it is allowed to transition to execute. Then a case statement + // allows it to invoke the method with the proper SESE body, and after + // exiting the SESE method, executes proper SESE exit code before the + // thread can be destroyed private void generateSESEinvocationMethod(PrintWriter outmethodheader, PrintWriter outmethod ) { outmethodheader.println("void* invokeSESEmethod( void* vargs );"); outmethod.println( "void* invokeSESEmethod( void* vargs ) {"); + outmethod.println( " int status;"); + outmethod.println( " char errmsg[128];"); outmethod.println( " invokeSESEargs* args = (invokeSESEargs*) vargs;"); - // use this info in the invocation cases to decide whether - // to gather SESE variables from a parent SESE record, or - // if parent is root, from noraml temps - outmethod.println( " char parentIsRoot = (args->parent == NULL);"); + // wait on a condition variable that dispatcher will signal + // then this SESE instance's dependencies are resolved + outmethod.println( " status = pthread_mutex_lock( args->invokee->startCondVarLock );"); + outmethod.println( " "+mlperrstr); + outmethod.println( " while( !(args->invokee->startedExecuting) ){"); + outmethod.println( " status = pthread_cond_wait( args->invokee->startCondVar, args->invokee->startCondVarLock );"); + outmethod.println( " "+mlperrstr); + outmethod.println( " }"); // generate a case for each SESE class that can be invoked outmethod.println( " switch( args->classID ) {"); @@ -1562,9 +1579,7 @@ public class BuildCode { ParamsObject objectparams = (ParamsObject)paramstable.get(bogusmd); // first copy SESE record into param structure - output.println(" if( parentIsRoot ) {"); - output.println(" "); - output.println(" }"); + // then invoke the sese's method output.print(" "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()); @@ -2278,29 +2293,33 @@ public class BuildCode { return; } - output.println(" tempSESE = (SESErecord*) malloc( sizeof( SESErecord ) );"); - output.println(" tempSESE->vars = (SESEvar*) malloc( sizeof( SESEvar ) * "+ - +fsen.numParameters()+ - ");"); + output.println("\n /* SESE "+fsen.getPrettyIdentifier()+" issue */"); + output.println(" tempSESE = mlpCreateSESErecord( "+ + fsen.getIdentifier()+", "+ + "0, "+ + "mlpGetCurrent(), "+ + fsen.numParameters()+", "+ + "NULL );"); for( int i = 0; i < fsen.numParameters(); ++i ) { TempDescriptor td = fsen.getParameter( i ); TypeDescriptor type = td.getType(); - output.println(" tempSESE->vars["+i+"].sesetype_"+type.toString()+" = "+td+";"); + output.println(" tempSESE->vars["+i+"].sesetype_"+type.toString()+" = "+td+";"); } - output.println(" mlpIssue( tempSESE );"); - output.println(" tempSESE = mlpSchedule();"); - output.println(" tempParentSESE = mlpGetCurrent();"); + output.println(" mlpIssue( tempSESE );"); + output.println(" tempSESE = mlpSchedule();"); + output.println(" tempParentSESE = mlpGetCurrent();"); // do a pthread_create wit invokeSESE as the argument // and pack all args into a single void* - output.println(" tempSESEargs = (invokeSESEargs*) malloc( sizeof( invokeSESEargs ) );"); - output.println(" tempSESEargs->classID = "+fsen.getIdentifier()+";"); - output.println(" tempSESEargs->invokee = tempSESE;"); - output.println(" tempSESEargs->parent = tempParentSESE;"); + output.println(" tempSESEargs = (invokeSESEargs*) malloc( sizeof( invokeSESEargs ) );"); + output.println(" tempSESEargs->classID = "+fsen.getIdentifier()+";"); + output.println(" tempSESEargs->invokee = tempSESE;"); + output.println(" tempSESEargs->parent = tempParentSESE;"); - output.println(" invokeSESEmethod( (void*) tempSESEargs );"); + output.println(" invokeSESEmethod( (void*) tempSESEargs );"); + output.println("\n"); } public void generateFlatSESEExitNode(FlatMethod fm, LocalityBinding lb, FlatSESEExitNode fsen, PrintWriter output) { diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index 9c293563..0aaf5657 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -48,6 +48,7 @@ SESErecord* mlpCreateSESErecord( int classID, newrec->paramStruct = paramStruct; newrec->forwardList = createQueue(); newrec->doneExecuting = FALSE; + newrec->startedExecuting = FALSE; newrec->startCondVar = (pthread_cond_t*) malloc( sizeof( pthread_cond_t ) ); newrec->startCondVarLock = (pthread_mutex_t*) malloc( sizeof( pthread_mutex_t ) ); @@ -83,9 +84,9 @@ void mlpInit( int totalNumSESEs, int maxSESEage ) { issuedQ = createQueue(); class_age2instance = (SESErecord**) malloc( sizeof( SESErecord* ) * - maxSESEage * - totalNumSESEs - ); + maxSESEage * + totalNumSESEs + ); current = rootsese; } diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index 75753ad1..c8af40c2 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -65,10 +65,11 @@ typedef struct SESErecord_t { // above var array at the call site void* paramStruct; - + // for signaling transition from issue + // to execute pthread_cond_t* startCondVar; pthread_mutex_t* startCondVarLock; - + int startedExecuting; // use a list of SESErecords and a lock to let // consumers tell this SESE who wants values @@ -76,6 +77,7 @@ typedef struct SESErecord_t { pthread_mutex_t* forwardListLock; struct Queue* forwardList; int doneExecuting; + } SESErecord;