From: bdemsky Date: Tue, 26 Oct 2010 01:48:55 +0000 (+0000) Subject: Changes... small fix to jim's bugfix...touching our record after we free it is also... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=357bbf5bf45bdc94704ec7adaeed3c43f7de51dd;p=IRC.git Changes... small fix to jim's bugfix...touching our record after we free it is also bad... 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 --- diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 5573f761..b50fd27f 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -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 diff --git a/Robust/src/Runtime/memPool.h b/Robust/src/Runtime/memPool.h index 17e8cc42..3087881a 100644 --- a/Robust/src/Runtime/memPool.h +++ b/Robust/src/Runtime/memPool.h @@ -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; } diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index 5d018107..75a296d2 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -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); } } diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index 520a7d21..b7657e45 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -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); diff --git a/Robust/src/Runtime/oooJava/hashStructure.c b/Robust/src/Runtime/oooJava/hashStructure.c index 790c55f4..2b822228 100644 --- a/Robust/src/Runtime/oooJava/hashStructure.c +++ b/Robust/src/Runtime/oooJava/hashStructure.c @@ -92,13 +92,13 @@ inline int rcr_BWRITEBINCASE(HashStructure *T, int key, SESEcommon *task, struct td->task=task; td->bitindexrd=td->bitindexwr=1<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; diff --git a/Robust/src/Runtime/oooJava/trqueue.c b/Robust/src/Runtime/oooJava/trqueue.c index 852c48ae..55d105a0 100644 --- a/Robust/src/Runtime/oooJava/trqueue.c +++ b/Robust/src/Runtime/oooJava/trqueue.c @@ -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; }