From 9d961bc0bb1b6a96c1db060e037dad6deb6fdb88 Mon Sep 17 00:00:00 2001 From: yeom Date: Tue, 4 May 2010 23:58:42 +0000 Subject: [PATCH] changes for using unique ID instead of obj address for the memory queue --- Robust/src/IR/Flat/BuildCode.java | 41 ++++++++++++++++++++++++++++--- Robust/src/Runtime/mlp_runtime.c | 18 +++++++++++--- Robust/src/Runtime/mlp_runtime.h | 1 + Robust/src/Runtime/runtime.c | 21 +++++++++++++++- Robust/src/Runtime/runtime.h | 7 ++++++ Robust/src/Runtime/workschedule.c | 38 +++++++++++++++++++++------- 6 files changed, 109 insertions(+), 17 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 85b4c1e3..496f3293 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -637,6 +637,7 @@ public class BuildCode { //Print out definition for array type outclassdefs.println("struct "+arraytype+" {"); outclassdefs.println(" int type;"); + outclassdefs.println(" int oid;"); if (state.EVENTMONITOR) { outclassdefs.println(" int objuid;"); } @@ -979,6 +980,10 @@ public class BuildCode { outclassdefs.print("#endif\n"); outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n"); + if(this.state.MLP){ + outclassdefs.print("extern __thread int oid;\n"); + outclassdefs.print("extern int numWorkers;\n"); + } Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); cdarray=new ClassDescriptor[state.numClasses()]; @@ -1375,6 +1380,9 @@ public class BuildCode { /* Output class structure */ classdefout.println("struct "+cn.getSafeSymbol()+" {"); classdefout.println(" int type;"); + if(state.MLP){ + classdefout.println(" int oid;"); + } if (state.EVENTMONITOR) { classdefout.println(" int objuid;"); } @@ -2778,7 +2786,8 @@ public class BuildCode { if( waitingElement.getStatus() >= ConflictNode.COARSE ){ output.println(" rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", seseCaller);"); }else{ - output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", seseCaller, ___locals___."+ waitingElement.getDynID() + ");"); + output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", seseCaller, (void*)&___locals___."+ waitingElement.getDynID() + ");"); +// output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", seseCaller, ___locals___."+ waitingElement.getDynID() + "->oid);"); } output.println(" psem_init( &(rentry->parentStallSem) );"); output.println(" rentry->queue=seseCaller->memoryQueueArray["+ waitingElement.getQueueID()+ "];"); @@ -3557,11 +3566,16 @@ public class BuildCode { output.println(" pointer=seseToIssue->"+ waitingElement.getDynID()+"_srcSESE+seseToIssue->"+ waitingElement.getDynID()+"_srcOffset;"); output.println(" rentry=mlpCreateFineREntry(" + waitingElement.getStatus() - + ", seseToIssue, pointer );"); + + ", seseToIssue, pointer );"); +// output.println(" rentry=mlpCreateFineREntry(" +// + waitingElement.getStatus() +// + ", seseToIssue, seseToIssue->" +// + waitingElement.getDynID() + "->oid);"); }else if(fsen.getStaticInVarSet().contains(td)){ // static in-var case VariableSourceToken vst = fsen.getStaticInVarSrc(td); if (vst != null) { + String srcId = "SESE_" + vst.getSESE() .getPrettyIdentifier() @@ -3576,12 +3590,21 @@ public class BuildCode { output.println(" rentry=mlpCreateFineREntry(" + waitingElement.getStatus() + ", seseToIssue, pointer );"); + +// output.println(" rentry=mlpCreateFineREntry(" +// + waitingElement.getStatus() +// + ", seseToIssue, seseToIssue->" +// + waitingElement.getDynID() + "->oid);"); } }else{ output.println(" rentry=mlpCreateFineREntry(" + waitingElement.getStatus() + ", seseToIssue, (void*)&seseToIssue->" + waitingElement.getDynID() + ");"); +// output.println(" rentry=mlpCreateFineREntry(" +// + waitingElement.getStatus() +// + ", seseToIssue, seseToIssue->" +// + waitingElement.getDynID() + "->oid);"); } } output @@ -4382,7 +4405,12 @@ public class BuildCode { if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) { output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + if(this.state.MLP){ + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray_oid("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+", oid);"); + output.println(" oid += numWorkers;"); + }else{ + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + } } else { output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); } @@ -4390,7 +4418,12 @@ public class BuildCode { if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) { output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");"); } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); + if (this.state.MLP){ + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new_oid("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+", oid);"); + output.println(" oid += numWorkers;"); + } else { + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); + } } else { output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+fn.getType().getClassDesc().getId()+");"); } diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index 7d6a7284..7302fc7b 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -7,6 +7,8 @@ #include "mem.h" #include "mlp_runtime.h" #include "workschedule.h" +#include "methodheaders.h" + /* @@ -52,6 +54,10 @@ REntry* mlpCreateFineREntry(int type, void* seseToIssue, void* dynID){ newREntry->type=type; newREntry->seseRec=seseToIssue; newREntry->pointer=dynID; + if((*newREntry->pointer)!=0){// make sure it is not unresolved address. + struct ___Object___ * obj=(struct ___Object___*)((unsigned INTPTR)*newREntry->pointer); + newREntry->oid=obj->oid; + } return newREntry; } @@ -267,7 +273,8 @@ int ADDTABLE(MemoryQueue *q, REntry *r) { return NOTREADY; } BinItem * val; - int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); + //int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); + int key=generateKey(r->oid); do { val=(BinItem*)0x1; BinElement* bin=table->array[key]; @@ -288,7 +295,8 @@ int ADDTABLE(MemoryQueue *q, REntry *r) { int ADDTABLEITEM(Hashtable* table, REntry* r, int inc){ BinItem * val; - int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); + // int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); + int key=generateKey(r->oid); do { val=(BinItem*)0x1; BinElement* bin=table->array[key]; @@ -564,7 +572,8 @@ RETIREHASHTABLE(MemoryQueue *q, REntry *r) { } RETIREBIN(Hashtable *T, REntry *r, BinItem *b) { - int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); + // int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); + int key=generateKey(r->oid); if(isFineRead(r)) { atomic_dec(&b->total); } @@ -792,6 +801,9 @@ resolvePointer(REntry* rentry){ break; } removeItem(val,head); + //now, address is resolved. update OID field. + struct ___Object___ * obj=(struct ___Object___*)((unsigned INTPTR)*rentry->pointer); + rentry->oid=obj->oid; if(ADDTABLEITEM(table, rentry, FALSE)==READY){ resolveDependencies(rentry); } diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index 7cf08a4c..e415fce3 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -58,6 +58,7 @@ typedef struct REntry_t{ psemaphore parentStallSem; void* seseRec; INTPTR* pointer; + int oid; } REntry; typedef struct MemoryQueueItem_t { diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 038e80b3..3c6b3911 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -593,7 +593,14 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int t #ifndef STM #if defined(PRECISE_GC) +#ifdef MLP __attribute__((malloc)) void * allocate_new(void * ptr, int type) { + return allocate_new_oid(ptr, type, 0); +} +__attribute__((malloc)) void * allocate_new_oid(void * ptr, int type, int oid) { +#else +__attribute__((malloc)) void * allocate_new(void * ptr, int type) { +#endif struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]); v->type=type; #ifdef THREADS @@ -603,13 +610,22 @@ __attribute__((malloc)) void * allocate_new(void * ptr, int type) { #endif #ifdef OPTIONAL v->fses=0; +#endif +#ifdef MLP + v->oid=oid; #endif return v; } /* Array allocation function */ - +#ifdef MLP __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) { + return allocate_newarray_oid(ptr, type, length, 0); +} + __attribute__((malloc)) struct ArrayObject * allocate_newarray_oid(void * ptr, int type, int length, int oid) { +#else +__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) { +#endif struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]); v->type=type; if (length<0) { @@ -624,6 +640,9 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int t #endif #ifdef OPTIONAL v->fses=0; +#endif +#ifdef MLP + v->oid=oid; #endif return v; } diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index 02ef5503..6c8257a7 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -62,8 +62,15 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, #ifdef PRECISE_GC #include "garbage.h" +#ifdef MLP +__attribute__((malloc)) void * allocate_new_oid(void *, int type, int oid); +__attribute__((malloc)) void * allocate_new(void *, int type); +__attribute__((malloc)) struct ArrayObject * allocate_newarray_oid(void *, int type, int length, int oid); +__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length); +#else __attribute__((malloc)) void * allocate_new(void *, int type); __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length); +#endif __attribute__((malloc)) struct ___String___ * NewString(void *, const char *str,int length); __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index); #elif defined MULTICORE_GC diff --git a/Robust/src/Runtime/workschedule.c b/Robust/src/Runtime/workschedule.c index 451b8a2d..d0c4efc3 100644 --- a/Robust/src/Runtime/workschedule.c +++ b/Robust/src/Runtime/workschedule.c @@ -28,6 +28,11 @@ typedef struct workerData_t { } workerData; */ +typedef struct workerData_t{ + pthread_t workerThread; + int id; +} WorkerData; + static pthread_mutex_t systemLockIn; static pthread_mutex_t systemLockOut; @@ -38,8 +43,7 @@ static pthread_mutex_t systemLockOut; // implementation internal data -static int numWorkers; -//static workerData* workerDataArray; +static WorkerData* workerDataArray; static pthread_t* workerArray; static int systemStarted = 0; @@ -52,6 +56,7 @@ static void(*workFunc)(void*); static pthread_cond_t workAvailCond = PTHREAD_COND_INITIALIZER; +int numWorkers; int threadcount; pthread_mutex_t gclock; @@ -62,6 +67,8 @@ extern struct listitem * list; extern __thread struct listitem litem; extern __thread SESEcommon* seseCommon; +__thread int oid; + /* struct QI { struct QI * next; @@ -170,6 +177,8 @@ void* workerMain( void* arg ) { void* workerMain( void* arg ) { void* workUnit; + WorkerData* myData = (WorkerData*) arg; + oid=myData->id; // make sure init mlp once-per-thread stuff //pthread_once( &mlpOnceObj, mlpInitOncePerThread ); @@ -178,7 +187,7 @@ void* workerMain( void* arg ) { // then continue to process work while( 1 ) { - + /* while(1){ if(pthread_mutex_trylock(&systemLock)==0){ @@ -221,7 +230,7 @@ void* workerMain( void* arg ) { list=&litem; seseCommon=(SESEcommon*)workUnit; pthread_mutex_unlock(&gclistlock); - + workFunc( workUnit ); pthread_mutex_lock(&gclistlock); @@ -310,10 +319,17 @@ void workScheduleInit( int numProcessors, status = pthread_mutex_init( &systemLockIn, NULL ); status = pthread_mutex_init( &systemLockOut, NULL ); - workerArray = RUNMALLOC( sizeof( pthread_t ) * numWorkers ); + //workerArray = RUNMALLOC( sizeof( pthread_t ) * numWorkers ); + workerDataArray = RUNMALLOC( sizeof( WorkerData ) * numWorkers ); - for( i = 0; i < numWorkers; ++i ) { - status = pthread_create( &(workerArray[i]), NULL, workerMain, NULL ); + for( i = 0; i < numWorkers; ++i ) { + workerDataArray[i].id=i+2; + status = pthread_create( &(workerDataArray[i].workerThread), + NULL, + workerMain, + (void*) &(workerDataArray[i]) + ); + //status = pthread_create( &(workerArray[i]), NULL, workerMain, NULL ); if( status != 0 ) { printf( "Error\n" ); exit( -1 ); } // yield and let all workers get to the beginx3 @@ -370,10 +386,14 @@ void workScheduleSubmit( void* workUnit ) { void workScheduleBegin() { int i; - workerMain(NULL); + WorkerData *workerData = RUNMALLOC( sizeof( WorkerData ) ); + workerData->id=1; + // workerMain(NULL); + workerMain(workerData); // tell all workers to begin for( i = 0; i < numWorkers; ++i ) { - pthread_join( workerArray[i], NULL ); + //pthread_join( workerArray[i], NULL ); + pthread_join( workerDataArray[i].workerThread, NULL ); } } -- 2.34.1