From 4b8c963c7ce46c4af38dcd341380658b7c0f0012 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 8 Nov 2010 08:09:12 +0000 Subject: [PATCH] changes: (1) create traversers only for non leaf threads (2) fixup stuff to have separate tables for separate weakly connected components (3) fixup stallsite code --- Robust/src/IR/Flat/BuildCode.java | 245 +++++++++++------- .../src/IR/Flat/RuntimeConflictResolver.java | 43 ++- Robust/src/Runtime/mlp_runtime.c | 8 +- Robust/src/Runtime/mlp_runtime.h | 1 + Robust/src/Runtime/oooJava/TODO | 1 + Robust/src/Runtime/oooJava/hashStructure.c | 6 +- Robust/src/Runtime/oooJava/hashStructure.h | 4 +- Robust/src/Runtime/oooJava/rcr_runtime.c | 3 +- Robust/src/Runtime/oooJava/rcr_runtime.h | 1 - Robust/src/Runtime/oooJava/trqueue.c | 41 ++- Robust/src/Runtime/oooJava/trqueue.h | 5 +- Robust/src/Runtime/workschedule.c | 45 +--- 12 files changed, 243 insertions(+), 160 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 3cfd3827..a6f4cea6 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -379,7 +379,7 @@ public class BuildCode { if(rcr != null) { rcr.close(); System.out.println("Runtime Conflict Resolver Done."); - } + } } /* This method goes though the call graph and tag those methods that are @@ -2564,6 +2564,10 @@ public class BuildCode { if( !fsen.getIsLeafSESE() ) { output.println(" runningSESE->taskRecordMemPool = poolcreate( "+ maxTaskRecSizeStr+", freshTaskRecordInitializer );"); + if (state.RCR) { + output.println(" createTR();"); + output.println(" runningSESE->allHashStructures=TRqueue->allHashStructures;"); + } } else { // make it clear we purposefully did not initialize this output.println(" runningSESE->taskRecordMemPool = (MemPool*)0x7;"); @@ -3102,6 +3106,87 @@ public class BuildCode { throw new Error(); } + + void stallMEMRCR(FlatMethod fm, FlatNode fn, Set waitingElementSet, PrintWriter output) { + output.println("// stall on parent's stall sites "); + output.println(" {"); + output.println(" REntry* rentry;"); + output.println(" SESEstall * stallrecord=(SESEstall *) poolalloc(runningSESE->taskRecordMemPool);"); + output.println(" stallrecord->common.unresolvedDependencies=10000;"); + output.println(" stallrecord->common.rcrstatus=1;"); + output.println(" stallrecord->common.offsetToParamRecords=(INTPTR) & (((SESEstall *)0)->rcrRecords);"); + output.println(" stallrecord->common.refCount = 3;"); + output.println(" stallrecord->tag=rentry->tag;"); + output.println(" int localCount=10000;"); + output.println(" stallrecord->rcrRecords[0].index=0;"); + output.println(" stallrecord->rcrRecords[0].flag=0;"); + output.println(" stallrecord->rcrRecords[0].next=NULL;"); + output.println(" stallrecord->common.parentsStallSem=&runningSESEstallSem;"); + + TempDescriptor stalltd=null; + 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(runningSESE->memoryQueueArray[" + + waitingElement.getQueueID() + "]," + waitingElement.getStatus() + + ", (SESEcommon *) stallrecord, 1LL);"); + } else { + throw new Error("Fine-grained conflict: This should not happen in RCR"); + } + 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)==READY) "); + output.println(" localCount--;"); + if (stalltd==null) { + stalltd=waitingElement.getTempDesc(); + } else if (stalltd!=waitingElement.getTempDesc()) { + throw new Error("Multiple temp descriptors at stall site"+stalltd+"!="+waitingElement.getTempDesc()); + } + } + + //did all of the course grained stuff + output.println(" if(!atomic_sub_and_test(localCount, &(stallrecord->common.unresolvedDependencies))) {"); + //have to do fine-grained work also + output.println(" stallrecord->___obj___=(struct ___Object___ *)" + + generateTemp(fm, stalltd, null) + ";"); + output.println(" stallrecord->common.classID=-" + + rcr.getTraverserID(stalltd, fn) + ";"); + + output.println(" enqueueTR(TRqueue, (void *)stallrecord);"); + + 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( &runningSESEstallSem, (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(" } else {");//exit if condition + //release traversers reference if we didn't use traverser + output.println("#ifndef OOO_DISABLE_TASKMEMPOOL"); + output.println(" RELEASE_REFERENCE_TO((SESEcommon *)stallrecord);"); + output.println("#endif"); + output.println(" }"); + //release our reference to stall record + output.println("#ifndef OOO_DISABLE_TASKMEMPOOL"); + output.println(" RELEASE_REFERENCE_TO((SESEcommon *)stallrecord);"); + output.println("#endif"); + output.println(" }");//exit block + } + protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) { // insert pre-node actions from the code plan @@ -3286,88 +3371,55 @@ public class BuildCode { Set waitingElementSet = graph.getStallSiteWaitingElementSet(fn, seseLockSet); if (waitingElementSet.size() > 0) { - output.println("// stall on parent's stall sites "); - output.println(" {"); - output.println(" REntry* rentry;"); - - for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) { - Analysis.OoOJava.WaitingElement waitingElement = - (Analysis.OoOJava.WaitingElement) iterator.next(); - if (waitingElement.getStatus() >= ConflictNode.COARSE) { - if (state.RCR) { - output.println(" rentry=mlpCreateREntry(runningSESE->memoryQueueArray[" - + waitingElement.getQueueID() + "]," + waitingElement.getStatus() - + ", runningSESE, 1LL);"); - } else { - output.println(" rentry=mlpCreateREntry(runningSESE->memoryQueueArray[" - + waitingElement.getQueueID() + "]," + waitingElement.getStatus() - + ", runningSESE);"); - } - } else { - output.println(" rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray[" - + waitingElement.getQueueID() + "]," + waitingElement.getStatus() - + ", runningSESE, (void*)&" - + generateTemp(fm, waitingElement.getTempDesc(), lb) + ");"); - } - 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) { - output.println("#ifdef CP_EVENTID_TASKSTALLMEM"); - output + if (state.RCR) { + stallMEMRCR(fm, fn, waitingElementSet, output); + } else { + output.println("// stall on parent's stall sites "); + output.println(" {"); + output.println(" REntry* rentry;"); + + 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(runningSESE->memoryQueueArray[" + + waitingElement.getQueueID() + "]," + waitingElement.getStatus() + + ", runningSESE);"); + } else { + output.println(" rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray[" + + waitingElement.getQueueID() + "]," + waitingElement.getStatus() + + ", runningSESE, (void*)&" + + generateTemp(fm, waitingElement.getTempDesc(), lb) + ");"); + } + 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) { + output.println("#ifdef CP_EVENTID_TASKSTALLMEM"); + output .println(" CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );"); - output.println("#endif"); - } - if (state.RCR) { - // no need to enqueue parent effect if coarse grained conflict - // clears us - - output.println(" while(stallrecord.common.rcrstatus) BARRIER();"); - // was the code above actually meant to look like this? - // output.println(" while(stallrecord.common.rcrstatus) {"); - // output.println(" BARRIER();"); - // output.println(" sched_yield();"); - // output.println(" }"); - - 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) + ";"); - // mark the record used..so we won't use it again until it is - // free - // clear rcrRecord - output.println(" stallrecord.rcrRecords[0].index=0;"); - output.println(" stallrecord.rcrRecords[0].flag=0;"); - output.println(" stallrecord.rcrRecords[0].next=NULL;"); - output.println(" stallrecord.common.rcrstatus=1;"); - output.println(" enqueueTR(TRqueue, (void *)&stallrecord);"); - } - - output - .println(" psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );"); - - if (state.RCR) { - output.println(" stallrecord.common.rcrstatus=0;"); - } - - if (state.COREPROF) { - output.println("#ifdef CP_EVENTID_TASKSTALLMEM"); - output + output.println("#endif"); + } + + 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 );"); - output.println("#endif"); - } - output.println(" } "); - } - output.println(" }"); - } - } - }else{ + output.println("#endif"); + } + output.println(" } "); + } + output.println(" }"); + } + } + } + } else{ ParentChildConflictsMap conflictsMap = mlpa.getConflictsResults().get(fn); if (conflictsMap != null) { Set allocSet = conflictsMap.getAllocationSiteIDSetofStallSite(); @@ -4205,8 +4257,6 @@ public class BuildCode { output.println(" }"); } - - if( state.COREPROF ) { output.println("#ifdef CP_EVENTID_PREPAREMEMQ"); output.println(" CP_LOGEVENT( CP_EVENTID_PREPAREMEMQ, CP_EVENTTYPE_BEGIN );"); @@ -4703,20 +4753,20 @@ public class BuildCode { output.println(" }"); output.println("{"); output.println(" int idx,idx2;"); - if(inset.size()==1){ - output.println(" idx=0; {"); - } else { - output.println(" for(idx=0;idx<" + inset.size() + ";idx++){"); + + //NEED TO FIX THIS + //XXXXXXXXX + output.println(" struct rcrRecord *rec;"); + output.println(" struct Hashtable_rcr ** hashstruct=runningSESE->parent->allHashStructures;"); + for(int i=0;ircrRecords["+i+"];"); + output.println(" while(rec!=NULL) {"); + output.println(" for(idx2=0;idx2index;idx2++) {"); + output.println(" rcr_RETIREHASHTABLE(hashstruct["+rcr.getWeakID(inset.get(i),fsen)+"],&(___params___->common), rec->array[idx2], (BinItem_rcr *) rec->ptrarray[idx2]);"); + output.println(" }");// exit idx2 for loop + output.println(" rec=rec->next;"); + output.println(" }");// exit rec while loop } - output.println(" struct rcrRecord *rec=&" + paramsprefix + "->rcrRecords[idx];"); - output.println(" while(rec!=NULL) {"); - output.println(" for(idx2=0;idx2index;idx2++) {"); - output - .println(" rcr_RETIREHASHTABLE(allHashStructures[0],&(___params___->common),rec->array[idx2], (BinItem_rcr *) rec->ptrarray[idx2]);"); - output.println(" }");// exit idx2 for loop - output.println(" rec=rec->next;"); - output.println(" }");// exit rec while loop - output.println(" }");// exit idx for loop output.println("}"); } @@ -4744,6 +4794,9 @@ public class BuildCode { // destroy this task's mempool if it is not a leaf task if( !fsen.getIsLeafSESE() ) { output.println(" pooldestroy( runningSESE->taskRecordMemPool );"); + if (state.RCR) { + output.println(" returnTR();"); + } } output.println("#endif // OOO_DISABLE_TASKMEMPOOL" ); diff --git a/Robust/src/IR/Flat/RuntimeConflictResolver.java b/Robust/src/IR/Flat/RuntimeConflictResolver.java index a326d864..b68bf535 100644 --- a/Robust/src/IR/Flat/RuntimeConflictResolver.java +++ b/Robust/src/IR/Flat/RuntimeConflictResolver.java @@ -38,6 +38,7 @@ public class RuntimeConflictResolver { //The Integer keeps track of the weakly connected group it's in (used in enumerateHeapRoots) private Hashtable doneTaints; private Hashtable idMap=new Hashtable(); + private Hashtable weakMap=new Hashtable(); private Hashtable> globalEffects; private Hashtable> globalConflicts; private ArrayList toTraverse; @@ -307,6 +308,10 @@ public class RuntimeConflictResolver { removeInvalidChars(flatname) + "___("+varString+");"; } + public int getWeakID(TempDescriptor invar, FlatNode fn) { + return weakMap.get(new Tuple(invar, fn)).intValue(); + } + public int getTraverserID(TempDescriptor invar, FlatNode fn) { Tuple t=new Tuple(invar, fn); if (idMap.containsKey(t)) @@ -379,20 +384,27 @@ public class RuntimeConflictResolver { //TODO: This is only temporary, remove when thread local variables are functional. private void createMasterHashTableArray() { - headerFile.println("void createAndFillMasterHashStructureArray();"); - cFile.println("void createAndFillMasterHashStructureArray() {\n" + - " rcr_createMasterHashTableArray("+weaklyConnectedHRCounter + ");"); + headerFile.println("struct Hashtable_rcr ** createAndFillMasterHashStructureArray();"); + cFile.println("struct Hashtable_rcr ** createAndFillMasterHashStructureArray() {"); + cFile.println(" struct Hashtable_rcr **table=rcr_createMasterHashTableArray("+weaklyConnectedHRCounter + ");"); for(int i = 0; i < weaklyConnectedHRCounter; i++) { - cFile.println(" allHashStructures["+i+"] = (HashStructure *) rcr_createHashtable("+num2WeaklyConnectedHRGroup.get(i).connectedHRs.size()+");"); + cFile.println(" table["+i+"] = (struct Hashtable_rcr *) rcr_createHashtable("+num2WeaklyConnectedHRGroup.get(i).connectedHRs.size()+");"); } + cFile.println(" return table;"); cFile.println("}"); } private void printMasterTraverserInvocation() { headerFile.println("\nint tasktraverse(SESEcommon * record);"); cFile.println("\nint tasktraverse(SESEcommon * record) {"); - cFile.println(" if(!CAS(&record->rcrstatus,1,2)) return;"); + cFile.println(" if(!CAS(&record->rcrstatus,1,2)) {"); + //release traverser reference...no traversal necessary + cFile.println("#ifndef OOO_DISABLE_TASKMEMPOOL"); + cFile.println(" RELEASE_REFERENCE_TO(record);"); + cFile.println("#endif"); + cFile.println(" return;"); + cFile.println(" }"); cFile.println(" switch(record->classID) {"); for(Iterator seseit=oooa.getAllSESEs().iterator();seseit.hasNext();) { @@ -422,6 +434,11 @@ public class RuntimeConflictResolver { cFile.println(" default:\n printf(\"Invalid SESE ID was passed in: %d.\\n\",record->classID);\n break;"); cFile.println(" }"); + //release traverser reference...traversal finished... + //executing thread will clean bins for us + cFile.println("#ifndef OOO_DISABLE_TASKMEMPOOL"); + cFile.println(" RELEASE_REFERENCE_TO(record);"); + cFile.println("#endif"); cFile.println("}"); } @@ -656,14 +673,10 @@ public class RuntimeConflictResolver { cFile.println(" return;"); } else { cFile.println(" int totalcount=RUNBIAS;"); - if (taint.isStallSiteTaint()) { + if (!taint.isStallSiteTaint()) { cFile.println(" record->rcrRecords[0].count=RUNBIAS;"); - cFile.println(" record->rcrRecords[0].index=0;"); - cFile.println(" record->rcrRecords[0].next=NULL;"); } else { cFile.println(" record->rcrRecords["+index+"].count=RUNBIAS;"); - cFile.println(" record->rcrRecords["+index+"].index=0;"); - cFile.println(" record->rcrRecords["+index+"].next=NULL;"); } //clears queue and hashtable that keeps track of where we've been. @@ -690,8 +703,8 @@ public class RuntimeConflictResolver { 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(" BARRIER();"); - cFile.println(" record->common.rcrstatus=0;"); cFile.println("}"); + cFile.println(" record->common.rcrstatus=0;"); } else { cFile.println(" if(atomic_sub_and_test(RUNBIAS-totalcount,&(record->rcrRecords["+index+"].count))) {"); cFile.println(" int flag=LOCKXCHG32(&(record->rcrRecords["+index+"].flag),0);"); @@ -914,6 +927,14 @@ public class RuntimeConflictResolver { num2WeaklyConnectedHRGroup.add(weaklyConnectedHRCounter, hg); weaklyConnectedHRCounter++; } + if(t.isRBlockTaint()) { + int id=connectedHRHash.get(t).id; + Tuple tup=new Tuple(t.getVar(),t.getSESE()); + if (weakMap.containsKey(tup)) { + if (weakMap.get(tup).intValue()!=id) + throw new Error("Var/SESE not unique for weak component."); + } else weakMap.put(tup, new Integer(id)); + } } } diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index ee4a593f..b7b458c8 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -828,7 +828,13 @@ void resolveDependencies(REntry* rentry){ } } } else if (type==PARENTCOARSE) { - psem_give_tag(rentry->parentStallSem, rentry->tag); + if (atomic_sub_and_test(1, &(seseCommon->unresolvedDependencies))) { + psem_give_tag(rentry->parentStallSem, rentry->tag); + //release our reference to stallrecord +#ifndef OOO_DISABLE_TASKMEMPOOL + RELEASE_REFERENCE_TO(seseCommon); +#endif + } } else { printf("ERROR: REntry type %d should never be generated in RCR..\n", rentry->type); } diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index 63365aa5..b52bb569 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -120,6 +120,7 @@ typedef struct SESEcommon_t { struct REntry_t* unresolvedRentryArray[NUMRENTRY]; #ifdef RCR + struct Hashtable_rcr ** allHashStructures; int offsetToParamRecords; volatile int rcrstatus; volatile int retired; diff --git a/Robust/src/Runtime/oooJava/TODO b/Robust/src/Runtime/oooJava/TODO index 551a2d32..b217103d 100644 --- a/Robust/src/Runtime/oooJava/TODO +++ b/Robust/src/Runtime/oooJava/TODO @@ -6,3 +6,4 @@ Big TODOS: 5) Recycling [recycle entries to improve runtime] 6) Parallelize traversal 7) Fix race on enqueue into table vs dequeue at retire... - done +8) Fix stall stie handling -- done \ No newline at end of file diff --git a/Robust/src/Runtime/oooJava/hashStructure.c b/Robust/src/Runtime/oooJava/hashStructure.c index 414c6ea5..b7152ed6 100644 --- a/Robust/src/Runtime/oooJava/hashStructure.c +++ b/Robust/src/Runtime/oooJava/hashStructure.c @@ -8,7 +8,7 @@ //NOTE: this is only temporary (for testing) and will be removed in favor of thread local variables //It's basically an array of hashStructures so we can simulate what would happen in a many-threaded version -HashStructure ** allHashStructures; +__thread HashStructure ** allHashStructures; #define ISWRITEBIN(x) (x&BINMASK) #define ISREADBIN(x) (!(x&BINMASK)) //#define POPCOUNT(x) __builtin_popcountll(x) @@ -39,8 +39,8 @@ inline enqueuerecord(struct rcrRecord *rcrrec, int tmpkey, BinItem_rcr *item) { } //NOTE: only temporary -void rcr_createMasterHashTableArray(int maxSize){ - allHashStructures = (HashStructure **) malloc(sizeof(HashStructure *) * maxSize); +HashStructure ** rcr_createMasterHashTableArray(int maxSize){ + return (HashStructure **) malloc(sizeof(HashStructure *) * maxSize); } HashStructure* rcr_createHashtable(int sizeofWaitingQueue){ diff --git a/Robust/src/Runtime/oooJava/hashStructure.h b/Robust/src/Runtime/oooJava/hashStructure.h index eb47a0cf..4e324c65 100644 --- a/Robust/src/Runtime/oooJava/hashStructure.h +++ b/Robust/src/Runtime/oooJava/hashStructure.h @@ -72,9 +72,9 @@ typedef struct ReadBinItem_rcr { int index; } ReadBinItem_rcr; -extern HashStructure ** allHashStructures; +extern __thread HashStructure ** allHashStructures; -void rcr_createMasterHashTableArray(int maxSize); //temporary +HashStructure ** rcr_createMasterHashTableArray(int maxSize); //temporary HashStructure* rcr_createHashtable(int sizeofWaitingQueue); WriteBinItem_rcr* rcr_createWriteBinItem(); ReadBinItem_rcr* rcr_createReadBinItem(); diff --git a/Robust/src/Runtime/oooJava/rcr_runtime.c b/Robust/src/Runtime/oooJava/rcr_runtime.c index 52b42a56..3112ef89 100644 --- a/Robust/src/Runtime/oooJava/rcr_runtime.c +++ b/Robust/src/Runtime/oooJava/rcr_runtime.c @@ -1,11 +1,13 @@ #include "trqueue.h" #include "mlp_runtime.h" #include "rcr_runtime.h" +#include "hashStructure.h" #include "structdefs.h" #include "RuntimeConflictResolver.h" void * workerTR(void *x) { struct trQueue * queue=(struct trQueue *)x; + allHashStructures=queue->allHashStructures; while(1) { SESEcommon * tmp; do { @@ -23,4 +25,3 @@ 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 aa2ad3f3..e32e081b 100644 --- a/Robust/src/Runtime/oooJava/rcr_runtime.h +++ b/Robust/src/Runtime/oooJava/rcr_runtime.h @@ -5,5 +5,4 @@ extern __thread struct trQueue * TRqueue; void * workerTR(void *); -extern __thread SESEstall stallrecord; #endif diff --git a/Robust/src/Runtime/oooJava/trqueue.c b/Robust/src/Runtime/oooJava/trqueue.c index 55d105a0..68ef603f 100644 --- a/Robust/src/Runtime/oooJava/trqueue.c +++ b/Robust/src/Runtime/oooJava/trqueue.c @@ -2,6 +2,12 @@ #include "stdlib.h" #include "stdio.h" #include "mlp_lock.h" +#include +#include "structdefs.h" +#include "RuntimeConflictResolver.h" + +struct trQueue * queuelist=NULL; +pthread_mutex_t queuelock; //0 would mean sucess //1 would mean fail @@ -34,10 +40,35 @@ void * dequeueTR(struct trQueue *q) { return ptr; } -struct trQueue * allocTR() { - struct trQueue *ptr=malloc(sizeof(struct trQueue)); - ptr->head=0; - ptr->tail=0; - return ptr; +void createTR() { + struct trQueue *ptr=NULL; + pthread_mutex_lock(&queuelock); + ptr=queuelist; + if (ptr!=NULL) + queuelist=ptr->next; + pthread_mutex_unlock(&queuelock); + if (ptr==NULL) { + pthread_t thread; + pthread_attr_t nattr; + pthread_attr_init(&nattr); + pthread_attr_setdetachstate( &nattr, PTHREAD_CREATE_DETACHED); + ptr=malloc(sizeof(struct trQueue)); + ptr->head=0; + ptr->tail=0; + ptr->allHashStructures=createAndFillMasterHashStructureArray(); + int status=pthread_create( &thread, NULL, workerTR, (void *) ptr); + if (status!=0) {printf("ERROR\n");exit(-1);} + pthread_attr_destroy(&nattr); + } + TRqueue=ptr; } +void returnTR() { + //return worker thread to pool + pthread_mutex_lock(&queuelock); + TRqueue->next=queuelist; + queuelist=TRqueue; + pthread_mutex_unlock(&queuelock); + //release our worker thread + TRqueue=NULL; +} diff --git a/Robust/src/Runtime/oooJava/trqueue.h b/Robust/src/Runtime/oooJava/trqueue.h index 28f97499..575ca8b5 100644 --- a/Robust/src/Runtime/oooJava/trqueue.h +++ b/Robust/src/Runtime/oooJava/trqueue.h @@ -10,9 +10,12 @@ struct trQueue { volatile unsigned int head; char buffer[60];//buffer us to the next cache line volatile unsigned int tail; + struct trQueue *next; + struct Hashtable_rcr ** allHashStructures; }; void enqueueTR(struct trQueue *, void * ptr); void * dequeueTR(struct trQueue *); -struct trQueue * allocTR(); +void createTR(); +void returnTR(); #endif diff --git a/Robust/src/Runtime/workschedule.c b/Robust/src/Runtime/workschedule.c index 07709e85..333bfb0e 100644 --- a/Robust/src/Runtime/workschedule.c +++ b/Robust/src/Runtime/workschedule.c @@ -27,7 +27,9 @@ int threadcount; pthread_mutex_t gclock; pthread_mutex_t gclistlock; pthread_cond_t gccond; - +#ifdef RCR +extern pthread_mutex_t queuelock; +#endif // in garbage.h, listitem is a struct with a pointer // to a stack, objects, etc. such that the garbage // collector can find pointers for garbage collection @@ -128,38 +130,6 @@ void* workerMain( void* arg ) { // pass to the collector if collection occurs struct garbagelist emptygarbagelist = { 0, NULL }; -#ifdef RCR - //allocate task record queue - pthread_t thread; - pthread_attr_t nattr; - pthread_attr_init( &nattr ); - pthread_attr_setdetachstate( &nattr, PTHREAD_CREATE_DETACHED ); - - //set up the stall site SESErecord - stallrecord.common.offsetToParamRecords=(INTPTR) &((SESEstall *)0)->rcrRecords; - stallrecord.common.classID=-1; - stallrecord.common.rcrstatus=0; - - //initialize rcrRecord - stallrecord.rcrRecords[0].next=NULL; - stallrecord.rcrRecords[0].index=0; - stallrecord.rcrRecords[0].count=0; - - if( TRqueue == NULL ) { - TRqueue = allocTR(); - } - - int status = pthread_create( &thread, - NULL, - workerTR, - (void*) TRqueue ); - - pthread_attr_destroy( &nattr ); - - if( status != 0 ) { printf( "Error\n" ); exit( -1 ); } -#endif - - // Add this worker to the gc list pthread_mutex_lock( &gclistlock ); threadcount++; @@ -295,6 +265,9 @@ void workScheduleInit( int numProcessors, myWorkerID = 0; oid = 1; +#ifdef RCR + pthread_mutex_init( &queuelock, NULL ); +#endif pthread_mutex_init( &gclock, NULL ); pthread_mutex_init( &gclistlock, NULL ); pthread_cond_init ( &gccond, NULL ); @@ -311,12 +284,6 @@ void workScheduleInit( int numProcessors, dqInit( &(deques[i]) ); } -#ifdef RCR - //make sure the queue is initialized - if (TRqueue==NULL) - TRqueue=allocTR(); -#endif - pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); -- 2.34.1