still some bugs...but stall site code generation is in
authorbdemsky <bdemsky>
Fri, 22 Oct 2010 08:18:56 +0000 (08:18 +0000)
committerbdemsky <bdemsky>
Fri, 22 Oct 2010 08:18:56 +0000 (08:18 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/RuntimeConflictResolver.java
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h
Robust/src/Runtime/oooJava/hashStructure.c
Robust/src/Runtime/oooJava/rcr_runtime.c
Robust/src/Runtime/oooJava/rcr_runtime.h
Robust/src/Runtime/psemaphore.c
Robust/src/Runtime/psemaphore.h
Robust/src/Runtime/workschedule.c
Robust/src/Tests/rcr/test.java

index 4206824c147bfb222248840868c8224601dccdcb..ef1d21b4dd1d127ba171aa2647f5685407521413 100644 (file)
@@ -3245,26 +3245,27 @@ public class BuildCode {
                   output.println("     rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE,  (void*)&" +generateTemp(fm,waitingElement.getTempDesc(),lb)+ ");");
                 }         
                 output.println("     psem_init( &(rentry->parentStallSem) );");
+               output.println("     rentry->tag=rentry->parentStallSem.tag;");
                 output.println("     rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];");
-                output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()
-                           + "],rentry)==NOTREADY){");
+                output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],rentry)==NOTREADY){");
                 if( state.COREPROF ) {
                   output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
                   output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
                   output.println("#endif");
                 }
-                output.println("        psem_take( &(rentry->parentStallSem), (struct garbagelist *)&___locals___ );");
+                if(state.RCR) {
+                 //no need to enqueue parent effect if coarse grained conflict clears us
+                 output.println("   stallrecord.common.parentsStallSem=&rentry->parentStallSem;");
+                 output.println("   stallrecord.tag=rentry->tag;");
+                  output.println("   "+rcr.getTraverserInvocation(waitingElement.getTempDesc(), generateTemp(fm, waitingElement.getTempDesc(), null)+", &stallrecord", fn));
+                }
+               output.println("        psem_take( &(rentry->parentStallSem), (struct garbagelist *)&___locals___ );");
                 if( state.COREPROF ) {
                   output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
                   output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
                   output.println("#endif");
                 }
                 output.println("     }  ");
-                
-                if(state.RCR) {
-                  output.println("   "+rcr.getTraverserInvocation(waitingElement.getTempDesc(), 
-                      generateTemp(fm, waitingElement.getTempDesc(), null), fn));
-                }
               }
               output.println("   }");
             }
@@ -3295,14 +3296,13 @@ public class BuildCode {
                   if( waitingElement.getStatus() >= ConflictNode.COARSE ){
                     // HERE! a parent might conflict with a child
                     output.println("     rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", runningSESE);");
-                  }else{
+                  } else {
                     output.println("     rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE,  (void*)&___locals___."+ waitingElement.getDynID() + ");");
                   }                                    
-                  output.println("     psem_init( &(rentry->parentStallSem) );");
+                  output.println("     psem_init(&(rentry->parentStallSem));");
+                 output.println("     rentry->tag=rentry->parentStallSem->tag;");
                   output.println("     rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];");
-                  output
-                    .println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()
-                             + "],rentry)==NOTREADY){");
+                  output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+"],rentry)==NOTREADY) {");
                   if( state.COREPROF ) {
                     output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
                     output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
index cf3d14e37d3b154b7ca88e1e6f1bbc061ff57ce0..e2e6cec0f8cdb4260e0f3e48a9651fb77f62e301 100644 (file)
@@ -294,14 +294,14 @@ public class RuntimeConflictResolver {
       flatname = fn.toString();
     }
     
-    return "traverse___" + removeInvalidChars(invar.getSafeSymbol()) + 
+    return "traverse___" + invar.getSafeSymbol() + 
     removeInvalidChars(flatname) + "___("+varString+");";
   }
   
   public String removeInvalidChars(String in) {
     StringBuilder s = new StringBuilder(in);
     for(int i = 0; i < s.length(); i++) {
-      if(s.charAt(i) == ' ' || s.charAt(i) == '.' || s.charAt(i) == '=') {
+      if(s.charAt(i) == ' ' || s.charAt(i) == '.' || s.charAt(i) == '='||s.charAt(i)=='['||s.charAt(i)==']') {
         s.deleteCharAt(i);
         i--;
       }
@@ -402,17 +402,18 @@ public class RuntimeConflictResolver {
   private void printResumeTraverserInvocation() {
     headerFile.println("\nint traverse(void * startingPtr, SESEcommon * record, int traverserID);");
     cFile.println("\nint traverse(void * startingPtr, SESEcommon *record, int traverserID) {");
-    cFile.println(" switch(traverserID) {");
+    cFile.println("  switch(traverserID) {");
     
     for(Taint t: doneTaints.keySet()) {
       cFile.println("  case " + doneTaints.get(t)+ ":");
       if(t.isRBlockTaint()) {
         cFile.println("    " + this.getTraverserInvocation(t.getVar(), "startingPtr, ("+t.getSESE().getSESErecordName()+" *)record", t.getSESE()));
       } else if (t.isStallSiteTaint()){
-        cFile.println("    " + this.getTraverserInvocation(t.getVar(), "startingPtr, record", t.getStallSite()));
+        cFile.println("/*    " + this.getTraverserInvocation(t.getVar(), "startingPtr, record", t.getStallSite())+"*/");
       } else {
         System.out.println("RuntimeConflictResolver encountered a taint that is neither SESE nor stallsite: " + t);
       }
+      cFile.println("    break;");
     }
     
     if(RuntimeConflictResolver.cSideDebug) {
@@ -657,11 +658,9 @@ public class RuntimeConflictResolver {
     int index=-1;
 
     if (taint.isStallSiteTaint()) {
-      methodName= "void traverse___" + removeInvalidChars(inVar) + 
-       removeInvalidChars(rBlock) + "___(void * InVar, SESEcommon *record)";
+      methodName= "void traverse___" + inVar + removeInvalidChars(rBlock) + "___(void * InVar, SESEstall *record)";
     } else {
-      methodName= "void traverse___" + removeInvalidChars(inVar) + 
-       removeInvalidChars(rBlock) + "___(void * InVar, "+taint.getSESE().getSESErecordName() +" *record)";
+      methodName= "void traverse___" + inVar + removeInvalidChars(rBlock) + "___(void * InVar, "+taint.getSESE().getSESErecordName() +" *record)";
       FlatSESEEnterNode fsese=taint.getSESE();
       TempDescriptor tmp=taint.getVar();
       index=fsese.getInVarsForDynamicCoarseConflictResolution().indexOf(tmp);
@@ -671,7 +670,8 @@ public class RuntimeConflictResolver {
     headerFile.println(methodName + ";");
     cFile.println("    int totalcount=RUNBIAS;\n");
     if (taint.isStallSiteTaint()) {
-      //need to add this
+      cFile.println("    record->rcrRecords[0].count=RUNBIAS;\n");
+      cFile.println("    record->rcrRecords[0].index=0;\n");
     } else {
       cFile.println("    record->rcrRecords["+index+"].count=RUNBIAS;\n");
       cFile.println("    record->rcrRecords["+index+"].index=0;\n");
@@ -700,6 +700,9 @@ public class RuntimeConflictResolver {
     }
     if (taint.isStallSiteTaint()) {
       //need to add this
+      cFile.println("     if(atomic_sub_and_test(RUNBIAS-totalcount,&(record->rcrRecords[0].count))) {");
+      cFile.println("         psem_give_tag(record->common.parentsStallSem, record->tag);");
+      cFile.println("}");
     } else {
       cFile.println("     if(atomic_sub_and_test(RUNBIAS-totalcount,&(record->rcrRecords["+index+"].count))) {");
       cFile.println("        int flag=LOCKXCHG32(&(record->rcrRecords["+index+"].flag),0);");
index 4cec64aa598fa53070c842657054d4eede6db229..5d01810769abc528974be3d4adaa220540cdea78 100644 (file)
@@ -786,7 +786,7 @@ resolveDependencies(REntry* rentry){
       workScheduleSubmit(seseCommon);
     }   
   }else if(rentry->type==PARENTREAD || rentry->type==PARENTWRITE ||rentry->type==PARENTCOARSE){
-     psem_give(&(rentry->parentStallSem));
+    psem_give_tag(&(rentry->parentStallSem), rentry->tag);
   }
 }
 
index c7dce30f2a7d0481de8b69e4ea84213c5b1832b3..419f0143be6d6326e0cf493d6488e4ed97da2225 100644 (file)
@@ -110,7 +110,7 @@ typedef struct SESEcommon_t {
   int             numRunningChildren;
 
   struct SESEcommon_t*   parent;
-
+  
   int numMemoryQueue;
   int rentryIdx;
   int unresolvedRentryIdx;
@@ -128,10 +128,8 @@ typedef struct SESEcommon_t {
   // to the parent record's memory pool
   MemPool*     taskRecordMemPool;
   volatile int refCount;
-
 } SESEcommon;
 
-
 // a thread-local var refers to the currently
 // running task
 extern __thread SESEcommon* runningSESE;
@@ -153,6 +151,7 @@ typedef struct REntry_t{
   struct SCC_t* scc;
   struct MemoryQueue_t* queue;
   psemaphore parentStallSem;
+  int tag;
   SESEcommon* seseRec;
   INTPTR* pointer;
   int isBufMode;
index 4529dedd0c7657f1d324d266be90365dd6ff261d..18b6fbe4a7efc610fe8a404a1cae510d86f66964 100644 (file)
@@ -399,10 +399,15 @@ void RESOLVE(SESEcommon *record, bitvt mask) {
     int shift=__builtin_ctzll(mask)+1;
     index+=shift;
     if (atomic_sub_and_test(1,&array[index].count)) {
-      int flag=LOCKXCHG32(&array[index].flag,0);
-      if (flag) {
-       if(atomic_sub_and_test(1, &(record->unresolvedDependencies))) 
-         workScheduleSubmit((void *)record);
+      if(unlikely(record->classID==STALLCLASSID)) {
+       //parent stall...clear it
+       psem_give_tag(record->parentsStallSem, ((SESEstall *)record)->tag);
+      } else {
+       int flag=LOCKXCHG32(&array[index].flag,0);
+       if (flag) {
+         if(atomic_sub_and_test(1, &(record->unresolvedDependencies))) 
+           workScheduleSubmit((void *)record);
+       }
       }
     }
     mask=mask>>shift;
index e73e676a47dc0633fac8ecb978c8a7fbcc2c29b7..d597726105fc99e3ae7e0f49e7e2db7af953058a 100644 (file)
@@ -1,6 +1,7 @@
 #include "trqueue.h"
-#include "rcr_runtime.h"
 #include "mlp_runtime.h"
+#include "rcr_runtime.h"
+
 
 void * workerTR(void *x) {
   struct trQueue * queue=(struct trQueue *)x;
@@ -15,3 +16,5 @@ void * workerTR(void *x) {
   }
   return NULL;
 }
+
+__thread SESEstall stallrecord;
index f5ef312fdee2e79c68b38b5f8805bcea65ba7cc5..f6f58dbd5668fbb64207eb9817df239906bd44fb 100644 (file)
@@ -15,4 +15,16 @@ struct rcrRecord {
   int array[RCRSIZE];
   struct rcrRecord *next;
 };
+
+#define STALLCLASSID 1939921
+
+typedef struct SESEstall_t { 
+  SESEcommon common;
+  int size;
+  void * next;
+  struct rcrRecord rcrRecords[1];
+  int tag;
+} SESEstall;
+
+extern __thread SESEstall stallrecord;
 #endif
index 9ba7daa8e199c97782ffb91bdf2b2d4ba2e804de..64cdda50ca68bb49d53f8500c227580a241c17d5 100644 (file)
@@ -7,6 +7,7 @@ void psem_init( psemaphore* sem ) {
   pthread_mutex_init( &(sem->lock), NULL );
   pthread_cond_init ( &(sem->cond), NULL );
   sem->signaled = 0;
+  sem->tag = 0;
 }
 
 
@@ -23,13 +24,22 @@ void psem_take( psemaphore* sem, struct garbagelist* gl ) {
 }
 
 
-void psem_give( psemaphore* sem ) {
+void psem_give( psemaphore* sem) {
   pthread_mutex_lock  ( &(sem->lock) );
   sem->signaled = 1;
   pthread_cond_signal ( &(sem->cond) );
   pthread_mutex_unlock( &(sem->lock) );
 }
 
+void psem_give_tag( psemaphore* sem, int tag) {
+  pthread_mutex_lock  ( &(sem->lock) );
+  if (sem->tag==tag) {
+    sem->signaled = 1;
+    pthread_cond_signal ( &(sem->cond) );
+  }
+  pthread_mutex_unlock( &(sem->lock) );
+}
+
 
 void psem_reset( psemaphore* sem ) {
   // this should NEVER BE CALLED if it is possible
@@ -38,5 +48,6 @@ void psem_reset( psemaphore* sem ) {
     exit( -1 );
   }
   pthread_mutex_unlock( &(sem->lock) );
+  sem->tag++;
   sem->signaled = 0;
 }
index 11bea19694d89bea4f996ff764a4b6e0dfa721b4..09eb479d589cb804825b7552fd646fb56cd75f58 100644 (file)
@@ -9,12 +9,14 @@ typedef struct psemaphore_t {
   pthread_mutex_t lock;
   pthread_cond_t  cond;
   int             signaled;
+  int             tag;
 } psemaphore;
 
 
 void psem_init ( psemaphore* sem );
 void psem_take ( psemaphore* sem, struct garbagelist* gl );
-void psem_give ( psemaphore* sem );
+void psem_give_tag ( psemaphore* sem, int tag );
+void psem_give ( psemaphore* sem);
 void psem_reset( psemaphore* sem );
 
 
index f35d94602dfef3f8c4b4e306a44de0495efb21d0..8b0890699671a0d101ae2e42a8dab92e9fb0c3cb 100644 (file)
@@ -102,6 +102,10 @@ void* workerMain( void* arg ) {
   pthread_attr_init( &nattr );
   pthread_attr_setdetachstate( &nattr, PTHREAD_CREATE_DETACHED );
 
+  //set up the stall site SESErecord
+  stallrecord.common.classID=STALLCLASSID;
+  stallrecord.common.offsetToParamRecords=(INTPTR) &((SESEstall *)0)->rcrRecords;
+
   if( TRqueue == NULL ) {
     TRqueue = allocTR();
   }
index ae6628ce3423d81ac4686716bf27627f4a4a4b7c..f546912bf0900294482fe1a8256254038022b509 100644 (file)
@@ -17,10 +17,8 @@ public class test {
        }
       }
     }
-    sese print {
-      for(int i=0;i<10;i++)
-       System.out.println(r[i].f);
-    }
+    for(int i=0;i<10;i++)
+      System.out.println(r[i].f);
   }
 }