From: bdemsky <bdemsky>
Date: Fri, 22 Oct 2010 08:18:56 +0000 (+0000)
Subject: still some bugs...but stall site code generation is in
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a08a9cab2a153dd64d04d6d200c8740e8c42dda9;p=IRC.git

still some bugs...but stall site code generation is in
---

diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java
index 4206824c..ef1d21b4 100644
--- a/Robust/src/IR/Flat/BuildCode.java
+++ b/Robust/src/IR/Flat/BuildCode.java
@@ -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 );");
diff --git a/Robust/src/IR/Flat/RuntimeConflictResolver.java b/Robust/src/IR/Flat/RuntimeConflictResolver.java
index cf3d14e3..e2e6cec0 100644
--- a/Robust/src/IR/Flat/RuntimeConflictResolver.java
+++ b/Robust/src/IR/Flat/RuntimeConflictResolver.java
@@ -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);");
diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c
index 4cec64aa..5d018107 100644
--- a/Robust/src/Runtime/mlp_runtime.c
+++ b/Robust/src/Runtime/mlp_runtime.c
@@ -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);
   }
 }
 
diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h
index c7dce30f..419f0143 100644
--- a/Robust/src/Runtime/mlp_runtime.h
+++ b/Robust/src/Runtime/mlp_runtime.h
@@ -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;
diff --git a/Robust/src/Runtime/oooJava/hashStructure.c b/Robust/src/Runtime/oooJava/hashStructure.c
index 4529dedd..18b6fbe4 100644
--- a/Robust/src/Runtime/oooJava/hashStructure.c
+++ b/Robust/src/Runtime/oooJava/hashStructure.c
@@ -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;
diff --git a/Robust/src/Runtime/oooJava/rcr_runtime.c b/Robust/src/Runtime/oooJava/rcr_runtime.c
index e73e676a..d5977261 100644
--- a/Robust/src/Runtime/oooJava/rcr_runtime.c
+++ b/Robust/src/Runtime/oooJava/rcr_runtime.c
@@ -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;
diff --git a/Robust/src/Runtime/oooJava/rcr_runtime.h b/Robust/src/Runtime/oooJava/rcr_runtime.h
index f5ef312f..f6f58dbd 100644
--- a/Robust/src/Runtime/oooJava/rcr_runtime.h
+++ b/Robust/src/Runtime/oooJava/rcr_runtime.h
@@ -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
diff --git a/Robust/src/Runtime/psemaphore.c b/Robust/src/Runtime/psemaphore.c
index 9ba7daa8..64cdda50 100644
--- a/Robust/src/Runtime/psemaphore.c
+++ b/Robust/src/Runtime/psemaphore.c
@@ -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;
 }
diff --git a/Robust/src/Runtime/psemaphore.h b/Robust/src/Runtime/psemaphore.h
index 11bea196..09eb479d 100644
--- a/Robust/src/Runtime/psemaphore.h
+++ b/Robust/src/Runtime/psemaphore.h
@@ -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 );
 
 
diff --git a/Robust/src/Runtime/workschedule.c b/Robust/src/Runtime/workschedule.c
index f35d9460..8b089069 100644
--- a/Robust/src/Runtime/workschedule.c
+++ b/Robust/src/Runtime/workschedule.c
@@ -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();
   }
diff --git a/Robust/src/Tests/rcr/test.java b/Robust/src/Tests/rcr/test.java
index ae6628ce..f546912b 100644
--- a/Robust/src/Tests/rcr/test.java
+++ b/Robust/src/Tests/rcr/test.java
@@ -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);
   }
 }