Changes... small fix to jim's bugfix...touching our record after we free it is also...
authorbdemsky <bdemsky>
Tue, 26 Oct 2010 01:48:55 +0000 (01:48 +0000)
committerbdemsky <bdemsky>
Tue, 26 Oct 2010 01:48:55 +0000 (01:48 +0000)
poolalloc the rentry's...avoid running out of memory...looks like speed gains for micro also...

eliminate parentsemaphore...just use the thread local semaphore...needed to simplify freeing rentry records

Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/memPool.h
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h
Robust/src/Runtime/oooJava/hashStructure.c
Robust/src/Runtime/oooJava/trqueue.c

index 5573f7610ef4270e7875bc8636ea57d1a364fb46..b50fd27f7c3959b7c25cfc520f73c42beabfad29 100644 (file)
@@ -3266,12 +3266,13 @@ public class BuildCode {
               for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
                 Analysis.OoOJava.WaitingElement waitingElement = (Analysis.OoOJava.WaitingElement) iterator.next();
                if( waitingElement.getStatus() >= ConflictNode.COARSE ){
-                  output.println("     rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", runningSESE);");
+                  output.println("     rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],"+waitingElement.getStatus()+ ", runningSESE);");
                 }else{
-                  output.println("     rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE,  (void*)&" +generateTemp(fm,waitingElement.getTempDesc(),lb)+ ");");
+                  output.println("     rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],"+ 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->parentStallSem=&runningSESEstallSem;");
+                output.println("     psem_reset( &runningSESEstallSem);");
+               output.println("     rentry->tag=runningSESEstallSem.tag;");
                 output.println("     rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];");
                 output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],rentry)==NOTREADY){");
                 if( state.COREPROF ) {
@@ -3283,7 +3284,7 @@ public class BuildCode {
                  //no need to enqueue parent effect if coarse grained conflict clears us
                  output.println("       while(stallrecord.common.rcrstatus) ;");
                  output.println("         BARRIER();");
-                 output.println("       stallrecord.common.parentsStallSem=&rentry->parentStallSem;");
+                 output.println("       stallrecord.common.parentsStallSem=&runningSESEstallSem;");
                  output.println("       stallrecord.tag=rentry->tag;");
                  output.println("       stallrecord.___obj___=(struct ___Object___ *)"+generateTemp(fm, waitingElement.getTempDesc(), null)+";");
                  output.println("       stallrecord.common.classID=-"+rcr.getTraverserID(waitingElement.getTempDesc(), fn)+";");
@@ -3291,7 +3292,7 @@ public class BuildCode {
                  output.println("       stallrecord.common.rcrstatus=1;");
                  output.println("       enqueueTR(TRqueue, (void *)&stallrecord);");
                 }
-               output.println("        psem_take( &(rentry->parentStallSem), (struct garbagelist *)&___locals___ );");
+               output.println("        psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
                 if( state.COREPROF ) {
                   output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
                   output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
@@ -3327,12 +3328,13 @@ public class BuildCode {
                                        
                   if( waitingElement.getStatus() >= ConflictNode.COARSE ){
                     // HERE! a parent might conflict with a child
-                    output.println("     rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", runningSESE);");
+                    output.println("     rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],"+ waitingElement.getStatus()+ ", runningSESE);");
                   } else {
-                    output.println("     rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE,  (void*)&___locals___."+ waitingElement.getDynID() + ");");
+                    output.println("     rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],"+ waitingElement.getStatus()+ ", runningSESE,  (void*)&___locals___."+ waitingElement.getDynID() + ");");
                   }                                    
-                  output.println("     psem_init(&(rentry->parentStallSem));");
-                 output.println("     rentry->tag=rentry->parentStallSem->tag;");
+                 output.println("     rentry->parentStallSem=&runningSESEstallSem;");
+                 output.println("     psem_reset( &runningSESEstallSem);");
+                 output.println("     rentry->tag=runningSESEstallSem.tag;");
                   output.println("     rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];");
                   output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+"],rentry)==NOTREADY) {");
                   if( state.COREPROF ) {
@@ -3340,7 +3342,7 @@ public class BuildCode {
                     output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
                     output.println("#endif");
                   }
-                  output.println("        psem_take( &(rentry->parentStallSem), (struct garbagelist *)&___locals___ );");
+                  output.println("        psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
                   if( state.COREPROF ) {
                     output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
                     output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
@@ -4176,7 +4178,7 @@ public class BuildCode {
                 Analysis.OoOJava.WaitingElement waitingElement 
                   = (Analysis.OoOJava.WaitingElement) iterator2.next();
                 if (waitingElement.getStatus() >= ConflictNode.COARSE) {
-                  output.println("       rentry=mlpCreateREntry("
+                  output.println("       rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
                                  + waitingElement.getStatus()
                                  + ", &(seseToIssue->common));");
                 } else {
@@ -4189,7 +4191,7 @@ public class BuildCode {
                                    + "_srcSESE+seseToIssue->"
                                    + waitingElement.getDynID()
                                    + "_srcOffset;");
-                    output.println("       rentry=mlpCreateFineREntry("
+                    output.println("       rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
                                    + waitingElement.getStatus()
                                    + ", &(seseToIssue->common),  pointer );");
                   } else if (fsen.getStaticInVarSet().contains(td)) {
@@ -4281,7 +4283,7 @@ public class BuildCode {
                 WaitingElement waitingElement = (WaitingElement) iterator2
                   .next();
                 if (waitingElement.getStatus() >= ConflictNode.COARSE) {
-                  output.println("     rentry=mlpCreateREntry("
+                  output.println("     rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
                                  + waitingElement.getStatus()
                                  + ", &(seseToIssue->common));");
                 } else {
@@ -4297,7 +4299,7 @@ public class BuildCode {
                                    + waitingElement.getDynID()
                                    + "_srcOffset;");
                     output
-                      .println("     rentry=mlpCreateFineREntry("
+                      .println("     rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
                                + waitingElement
                                .getStatus()
                                + ", &(seseToIssue->common),  pointer );");
@@ -4424,7 +4426,7 @@ public class BuildCode {
            Analysis.OoOJava.WaitingElement waitingElement=wtit.next();
            int queueID=waitingElement.getQueueID();
            assert(waitingElement.getStatus()>=ConflictNode.COARSE);
-           output.println("       rentry=mlpCreateREntry(" + waitingElement.getStatus() + ", &(seseToIssue->common));");
+           output.println("       rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "]," + waitingElement.getStatus() + ", &(seseToIssue->common));");
            output.println("       seseToIssue->common.rentryArray[seseToIssue->common.rentryIdx++]=rentry;");
            output.println("       rentry->queue=runningSESE->memoryQueueArray[" + waitingElement.getQueueID()+"];");
            output.println("       if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],rentry)==READY) {");
@@ -4642,6 +4644,9 @@ public class BuildCode {
     output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
 
 
+    output.println("{");
+    output.println("SESEcommon *myparent=runningSESE->parent;");
+
     // if this is not the Main sese (which has no parent) then return
     // THIS task's record to the PARENT'S task record pool, and only if
     // the reference count is now zero
@@ -4658,14 +4663,15 @@ public class BuildCode {
 
 
     // last of all, decrement your parent's number of running children    
-    output.println("   if( runningSESE->parent != NULL ) {");
-    output.println("     if( atomic_sub_and_test( 1, &(runningSESE->parent->numRunningChildren) ) ) {");
-    output.println("       pthread_mutex_lock  ( &(runningSESE->parent->lock) );");
-    output.println("       pthread_cond_signal ( &(runningSESE->parent->runningChildrenCond) );");
-    output.println("       pthread_mutex_unlock( &(runningSESE->parent->lock) );");
+    output.println("   if( myparent != NULL ) {");
+    output.println("     if( atomic_sub_and_test( 1, &(myparent->numRunningChildren) ) ) {");
+    output.println("       pthread_mutex_lock  ( &(myparent->lock) );");
+    output.println("       pthread_cond_signal ( &(myparent->runningChildrenCond) );");
+    output.println("       pthread_mutex_unlock( &(myparent->lock) );");
     output.println("     }");
     output.println("   }");
 
+    output.println("}");
     
     // as this thread is wrapping up the task, make sure the thread-local var
     // for the currently running task record references an invalid task
index 17e8cc4212a944d59f5514efb73062711606342b..3087881aee088c4b976aa3cc5fa130e39acf5c08 100644 (file)
@@ -22,7 +22,7 @@
 #include "runtime.h"
 #include "mem.h"
 #include "mlp_lock.h"
-
+#define CACHELINESIZE 64
 
 
 typedef struct MemPoolItem_t {
@@ -106,7 +106,7 @@ static inline void* poolalloc( MemPool* p ) {
   // it doesn't require an atomic op
   MemPoolItem* headCurrent = p->head;
   MemPoolItem* next=headCurrent->next;
-
+  int i;
   if(next == NULL) {
     // only one item, so don't take from pool
     return (void*) RUNMALLOC( p->itemSize );
@@ -127,6 +127,8 @@ static inline void* poolalloc( MemPool* p ) {
   //////////////////////////////////////////////////////////
   //__builtin_prefetch( &(p->head->next) );
   asm volatile( "prefetcht0 (%0)" :: "r" (next));
+  next=(MemPoolItem*)(((char *)next)+CACHELINESIZE);
+  asm volatile( "prefetcht0 (%0)" :: "r" (next));
 
   return (void*)headCurrent;
 }
index 5d01810769abc528974be3d4adaa220540cdea78..75a296d2563c3c2d4ec83949698158ce032e1189 100644 (file)
@@ -38,21 +38,24 @@ MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue){
   return newMemoryQueue;
 }
 
-REntry* mlpCreateREntryArray(){
-  REntry* newREntryArray=(REntry*)RUNMALLOC(sizeof(REntry)*NUMRENTRY);
-  return newREntryArray;
-}
-
-REntry* mlpCreateFineREntry(int type, SESEcommon* seseToIssue, void* dynID){
+REntry* mlpCreateFineREntry(MemoryQueue* q, int type, SESEcommon* seseToIssue, void* dynID){
+#ifdef OOO_DISABLE_TASKMEMPOOL
   REntry* newREntry=(REntry*)RUNMALLOC(sizeof(REntry));
+#else
+  REntry* newREntry=poolalloc(q->rentrypool);
+#endif
   newREntry->type=type;
   newREntry->seseRec=seseToIssue;
   newREntry->pointer=dynID;
   return newREntry;
 }
 
-REntry* mlpCreateREntry(int type, SESEcommon* seseToIssue){
+REntry* mlpCreateREntry(MemoryQueue* q, int type, SESEcommon* seseToIssue){
+#ifdef OOO_DISABLE_TASKMEMPOOL
   REntry* newREntry=(REntry*)RUNMALLOC(sizeof(REntry));
+#else
+  REntry* newREntry=poolalloc(q->rentrypool);
+#endif
   newREntry->type=type;
   newREntry->seseRec=seseToIssue;
   return newREntry;
@@ -197,6 +200,9 @@ MemoryQueue* createMemoryQueue(){
   dummy->status=READY;
   queue->head = dummy;
   queue->tail = dummy;
+#ifndef OOO_DISABLE_TASKMEMPOOL
+  queue->rentrypool = poolcreate(sizeof(REntry));
+#endif
   return queue;
 }
 
@@ -568,6 +574,9 @@ void RETIRERENTRY(MemoryQueue* Q, REntry * r) {
   } else if (isSCC(r)) {
     RETIRESCC(Q, r);
   }
+#ifndef OOO_DISABLE_TASKMEMPOOL
+  poolfreeinto(Q->rentrypool, r);
+#endif
 }
 
 RETIRESCC(MemoryQueue *Q, REntry *r) {
@@ -786,7 +795,7 @@ resolveDependencies(REntry* rentry){
       workScheduleSubmit(seseCommon);
     }   
   }else if(rentry->type==PARENTREAD || rentry->type==PARENTWRITE ||rentry->type==PARENTCOARSE){
-    psem_give_tag(&(rentry->parentStallSem), rentry->tag);
+    psem_give_tag(rentry->parentStallSem, rentry->tag);
   }
 }
 
index 520a7d21fc8e230db0e4b0bc24a4ff8116c1c74d..b7657e45951701fbb9a1a7e9da6bc4641e0fe002 100644 (file)
@@ -151,7 +151,7 @@ typedef struct REntry_t{
   struct Vector_t* vector;
   struct SCC_t* scc;
   struct MemoryQueue_t* queue;
-  psemaphore parentStallSem;
+  psemaphore parentStallSem;
   int tag;
   SESEcommon* seseRec;
   INTPTR* pointer;
@@ -185,7 +185,8 @@ typedef struct MemoryQueueItem_t {
   int type; // hashtable:0, vector:1, singleitem:2
   int total;        //total non-retired
   int status;       //NOTREADY, READY
-  struct MemoryQueueItem_t *next; 
+  struct MemoryQueueItem_t *next;
+  
 } MemoryQueueItem;
 
 typedef struct MemoryQueue_t {
@@ -194,6 +195,9 @@ typedef struct MemoryQueue_t {
   REntry * binbuf[NUMBINS];
   REntry * buf[NUMRENTRY];
   int bufcount;
+#ifndef OOO_DISABLE_TASKMEMPOOL
+  MemPool * rentrypool;
+#endif
 } MemoryQueue;
 
 typedef struct BinItem_t {
@@ -256,8 +260,8 @@ void* mlpAllocSESErecord( int size );
 void  mlpFreeSESErecord( SESEcommon* seseRecord );
 
 MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue);
-REntry* mlpCreateFineREntry(int type, SESEcommon* seseToIssue, void* dynID);
-REntry* mlpCreateREntry    (int type, SESEcommon* seseToIssue);
+REntry* mlpCreateFineREntry(MemoryQueue *q, int type, SESEcommon* seseToIssue, void* dynID);
+REntry* mlpCreateREntry(MemoryQueue *q, int type, SESEcommon* seseToIssue);
 MemoryQueue* createMemoryQueue();
 void rehashMemoryQueue(SESEcommon* seseParent);
 
index 790c55f4342288deb1e29c95defad1d9cfbaa864..2b8222288fca10be0c24c5e1184b47083a81e89a 100644 (file)
@@ -92,13 +92,13 @@ inline int rcr_BWRITEBINCASE(HashStructure *T, int key, SESEcommon *task, struct
     td->task=task;
     td->bitindexrd=td->bitindexwr=1<<index;
     be->tail=b;
-    
+    BARRIER();//do tail before head
     //release lock
     be->head=b;
     enqueuerecord(rcrrec, key, b);
     return READY;
   }
-
+  BARRIER();//read head before tail
   BinItem_rcr *bintail=be->tail;
   bitvt rdmask=0,wrmask=0;
   int status=NOTREADY;
index 852c48ae4e5dc648677d56d2b8b203f8e5a51785..55d105a0ac613b257472bb835fe4d9fc14d6fc45 100644 (file)
@@ -25,10 +25,11 @@ void * dequeueTR(struct trQueue *q) {
   if(q->head==tail)
     return NULL;
 
-  void * ptr = q->elements[tail];
   tail++;
   if(tail & TRSIZE)
     tail =  0;
+
+  void * ptr = q->elements[tail];
   q->tail=tail;
   return ptr;
 }