From ee25693be307b73ee228c42cea0506fd02c398ef Mon Sep 17 00:00:00 2001 From: jzhou Date: Tue, 1 Dec 2009 01:13:07 +0000 Subject: [PATCH] bug fix in multicore gc --- Robust/src/Runtime/multicoregarbage.c | 30 +++++++++++- Robust/src/Runtime/multicoregarbage.h | 6 +-- Robust/src/Runtime/multicorehelper.h | 8 ++++ Robust/src/Runtime/multicoretask.c | 69 +++++++++++++++------------ Robust/src/buildscript | 4 +- 5 files changed, 81 insertions(+), 36 deletions(-) diff --git a/Robust/src/Runtime/multicoregarbage.c b/Robust/src/Runtime/multicoregarbage.c index d514567b..5ffdd497 100644 --- a/Robust/src/Runtime/multicoregarbage.c +++ b/Robust/src/Runtime/multicoregarbage.c @@ -15,6 +15,9 @@ extern struct genhashtable * activetasks; extern struct parameterwrapper ** objectqueues[][NUMCLASSES]; extern struct taskparamdescriptor *currtpd; +extern struct LockValue runtime_locks[MAXTASKPARAMS]; +extern int runtime_locklen; + struct pointerblock { void * ptrs[NUMPTRS]; struct pointerblock *next; @@ -92,7 +95,7 @@ inline void dumpSMem() { } // compute core # if(advanceblock) { - coren = gc_block2core[block%124]; + coren = gc_block2core[block%(NUMCORES*2)]; } // compute core coordinate int tmpcore = coren; @@ -653,7 +656,7 @@ void updateSmemTbl(int coren, int j = 0; int toset = 0; do{ - toset = gc_core2block[2*coren+i]+124*j; + toset = gc_core2block[2*coren+i]+(NUMCORES*2)*j; if(toset < ltopcore) { gcsmemtbl[toset] = (tosetkey = flushObj((void *)ptr->key); ptr=ptr->lnext; } + ObjectHashrehash(set); } } @@ -2097,6 +2113,7 @@ inline void flushRuntimeObj(struct garbagelist * stackptr) { } ptr=ptr->inext; } + genrehash(activetasks); // flush cached transferred obj struct QueueItem * tmpobjptr = getHead(&objqueue); @@ -2115,6 +2132,15 @@ inline void flushRuntimeObj(struct garbagelist * stackptr) { totransobj->objptr = flushObj(totransobj->objptr); item = getNextQueueItem(item); } // while(item != NULL) + + // enqueue lock related info + for(i = 0; i < runtime_locklen; ++i) { + runtime_locks[i].redirectlock = (int)flushObj(runtime_locks[i].redirectlock); + if(runtime_locks[i].value != NULL) { + runtime_locks[i].value = (int)flushObj(runtime_locks[i].value); + } + } + } // void flushRuntimeObj(struct garbagelist * stackptr) inline void flush(struct garbagelist * stackptr) { diff --git a/Robust/src/Runtime/multicoregarbage.h b/Robust/src/Runtime/multicoregarbage.h index 47da6c80..ac4b1c97 100644 --- a/Robust/src/Runtime/multicoregarbage.h +++ b/Robust/src/Runtime/multicoregarbage.h @@ -108,7 +108,7 @@ int * gcsmemtbl; } else {\ int b; \ BLOCKINDEX((p), &b); \ - (*((int*)c)) = gc_block2core[(b%124)]; \ + (*((int*)c)) = gc_block2core[(b%(NUMCORES*2))]; \ }\ } @@ -132,7 +132,7 @@ int * gcsmemtbl; } // mapping of (core #, index of the block) to the global block index -#define BLOCKINDEX2(c, n) (gc_core2block[(2*(c))+((n)%2)]+(124*((n)/2))) +#define BLOCKINDEX2(c, n) (gc_core2block[(2*(c))+((n)%2)]+((NUMCORES*2)*((n)/2))) // mapping of (core #, number of the block) to the base pointer of the block #define BASEPTR(c, n, p) \ @@ -147,7 +147,7 @@ int * gcsmemtbl; } // the next core in the top of the heap -#define NEXTTOPCORE(b) (gc_block2core[((b)+1)%124]) +#define NEXTTOPCORE(b) (gc_block2core[((b)+1)%(NUMCORES*2)]) inline void gc(struct garbagelist * stackptr); // core coordinator routine inline void gc_collect(struct garbagelist* stackptr);//core collector routine diff --git a/Robust/src/Runtime/multicorehelper.h b/Robust/src/Runtime/multicorehelper.h index bb5e581f..ed80ec3b 100644 --- a/Robust/src/Runtime/multicorehelper.h +++ b/Robust/src/Runtime/multicorehelper.h @@ -1,6 +1,13 @@ #ifndef MULTICORE_HELPER_H #define MULTICORE_HELPER_H +#ifdef GC_1 +// NUMCORES = 1 +static int gc_core2block[2] = {0,1}; + +static int gc_block2core[2] = { 0, 0}; +#elif defined GC_62 +// NUMCORES = 62 static int gc_core2block[124] = {0,123, 15,108, 16,107, 31,92, 32,91, 47,76, 1,122, 14,109, 17,106, 30,93, 33,90, 46,77, 48,75, 61,62, 2,121, 13,110, 18,105, 29,94, 34,89, 45,78, 49,74, 60,63, @@ -18,5 +25,6 @@ static int gc_block2core[124] = { 0, 6, 14, 22, 30, 38, 46, 54, 55, 47, 39, 31, 5, 11, 19, 27, 35, 43, 51, 59, 58, 50, 42, 34, 26, 18, 10, 4, 3, 9, 17, 25, 33, 41, 49, 57, 56, 48, 40, 32, 24, 16, 8, 2, 1, 7, 15, 23, 31, 39, 47, 55, 54, 46, 38, 30, 22, 14, 6, 0}; +#endif #endif // MULTICORE_HELPER_H diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index ad91ea61..68d49b79 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -7,6 +7,8 @@ // data structures for task invocation struct genhashtable * activetasks; struct taskparamdescriptor * currtpd; +struct LockValue runtime_locks[MAXTASKPARAMS]; +int runtime_locklen; // specific functions used inside critical sections void enqueueObject_I(void * ptr, @@ -147,6 +149,12 @@ void initruntimedata() { /*interruptInfoIndex = 0; interruptInfoOverflow = false;*/ #endif + + for(i = 0; i < MAXTASKPARAMS; i++) { + runtime_locks[i].redirectlock = 0; + runtime_locks[i].value = 0; + } + runtime_locklen = 0; } inline __attribute__((always_inline)) @@ -1189,7 +1197,7 @@ struct freeMemItem * findFreeMemChunk_I(int coren, struct freeMemItem * prev = NULL; int i = 0; int j = 0; - *tofindb = gc_core2block[2*coren+i]+124*j; + *tofindb = gc_core2block[2*coren+i]+(NUMCORES*2)*j; // check available shared mem chunks do { int foundsmem = 0; @@ -1203,7 +1211,7 @@ struct freeMemItem * findFreeMemChunk_I(int coren, i = 0; j++; } - *tofindb = gc_core2block[2*coren+i]+124*j; + *tofindb = gc_core2block[2*coren+i]+(NUMCORES*2)*j; } // while(startb > tofindb) if(startb <= *tofindb) { if((endb >= *tofindb) && (freemem->size >= isize)) { @@ -2456,8 +2464,6 @@ void executetasks() { int x = 0; bool islock = true; - struct LockValue locks[MAXTASKPARAMS]; - int locklen = 0; int grount = 0; int andmask=0; int checkmask=0; @@ -2490,11 +2496,11 @@ newtask: // (TODO, this table should be empty after all locks are released) // reset all locks for(j = 0; j < MAXTASKPARAMS; j++) { - locks[j].redirectlock = 0; - locks[j].value = 0; + runtime_locks[j].redirectlock = 0; + runtime_locks[j].value = 0; } // get all required locks - locklen = 0; + runtime_locklen = 0; // check which locks are needed for(i = 0; i < numparams; i++) { void * param = currtpd->parameterArray[i]; @@ -2512,36 +2518,36 @@ newtask: tmplock = (int)(((struct ___Object___ *)param)->lock); } // insert into the locks array - for(j = 0; j < locklen; j++) { - if(locks[j].value == tmplock) { + for(j = 0; j < runtime_locklen; j++) { + if(runtime_locks[j].value == tmplock) { insert = false; break; - } else if(locks[j].value > tmplock) { + } else if(runtime_locks[j].value > tmplock) { break; } } if(insert) { - int h = locklen; + int h = runtime_locklen; for(; h > j; h--) { - locks[h].redirectlock = locks[h-1].redirectlock; - locks[h].value = locks[h-1].value; + runtime_locks[h].redirectlock = runtime_locks[h-1].redirectlock; + runtime_locks[h].value = runtime_locks[h-1].value; } - locks[j].value = tmplock; - locks[j].redirectlock = (int)param; - locklen++; + runtime_locks[j].value = tmplock; + runtime_locks[j].redirectlock = (int)param; + runtime_locklen++; } } // line 2713: for(i = 0; i < numparams; i++) // grab these required locks #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe991); #endif - for(i = 0; i < locklen; i++) { - int * lock = (int *)(locks[i].redirectlock); + for(i = 0; i < runtime_locklen; i++) { + int * lock = (int *)(runtime_locks[i].redirectlock); islock = true; // require locks for this parameter if it is not a startup object #ifdef DEBUG BAMBOO_DEBUGPRINT_REG((int)lock); - BAMBOO_DEBUGPRINT_REG((int)(locks[i].value)); + BAMBOO_DEBUGPRINT_REG((int)(runtime_locks[i].value)); #endif getwritelock(lock); BAMBOO_START_CRITICAL_SECTION(); @@ -2581,11 +2587,12 @@ newtask: int j = 0; #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe992); + BAMBOO_DEBUGPRINT_REG(lock); #endif // can not get the lock, try later // releas all grabbed locks for previous parameters for(j = 0; j < i; ++j) { - lock = (int*)(locks[j].redirectlock); + lock = (int*)(runtime_locks[j].redirectlock); releasewritelock(lock); } genputtable(activetasks, currtpd, currtpd); @@ -2603,7 +2610,7 @@ newtask: #endif goto newtask; } // line 2794: if(grount == 0) - } // line 2752: for(i = 0; i < locklen; i++) + } // line 2752: for(i = 0; i < runtime_locklen; i++) #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe993); @@ -2625,10 +2632,11 @@ newtask: if (!ObjectHashcontainskey(pw->objectset, (int) parameter)) { #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe994); + BAMBOO_DEBUGPRINT_REG(parameter); #endif // release grabbed locks - for(j = 0; j < locklen; ++j) { - int * lock = (int *)(locks[j].redirectlock); + for(j = 0; j < runtime_locklen; ++j) { + int * lock = (int *)(runtime_locks[j].redirectlock); releasewritelock(lock); } RUNFREE(currtpd->parameterArray); @@ -2657,6 +2665,7 @@ newtask: int * enterflags; #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe995); + BAMBOO_DEBUGPRINT_REG(parameter); #endif ObjectHashget(pw->objectset, (int) parameter, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2); @@ -2664,8 +2673,8 @@ newtask: if (enterflags!=NULL) RUNFREE(enterflags); // release grabbed locks - for(j = 0; j < locklen; ++j) { - int * lock = (int *)(locks[j].redirectlock); + for(j = 0; j < runtime_locklen; ++j) { + int * lock = (int *)(runtime_locks[j].redirectlock); releasewritelock(lock); } RUNFREE(currtpd->parameterArray); @@ -2693,8 +2702,8 @@ parameterpresent: { // release grabbed locks int tmpj = 0; - for(tmpj = 0; tmpj < locklen; ++tmpj) { - int * lock = (int *)(locks[tmpj].redirectlock); + for(tmpj = 0; tmpj < runtime_locklen; ++tmpj) { + int * lock = (int *)(runtime_locks[tmpj].redirectlock); releasewritelock(lock); } } @@ -2748,9 +2757,9 @@ execute: #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe999); #endif - for(i = 0; i < locklen; ++i) { - void * ptr = (void *)(locks[i].redirectlock); - int * lock = (int *)(locks[i].value); + for(i = 0; i < runtime_locklen; ++i) { + void * ptr = (void *)(runtime_locks[i].redirectlock); + int * lock = (int *)(runtime_locks[i].value); #ifdef DEBUG BAMBOO_DEBUGPRINT_REG((int)ptr); BAMBOO_DEBUGPRINT_REG((int)lock); diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 8b15dd91..85ebcbc1 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -128,6 +128,7 @@ JAVAOPTS='' OPTIONALFLAG=false EXITAFTERANALYSIS=false ASSEMBLY=false +GCCORES='' if [[ -z $1 ]] then @@ -287,6 +288,7 @@ JAVAOPTS="$JAVAOPTS -multicore" elif [[ $1 = '-numcore' ]] then JAVAOPTS="$JAVAOPTS -numcore $2" +GCCORES="GC_$2" shift elif [[ $1 = '-raw' ]] then @@ -665,7 +667,7 @@ fi #INTERRUPT version if $MULTICOREGCFLAG then #MULTICOREGC version -TILERACFLAGS="${TILERACFLAGS} -DMULTICORE_GC" +TILERACFLAGS="${TILERACFLAGS} -DMULTICORE_GC -D${GCCORES}" fi cp $ROBUSTROOT/Tilera/Runtime/$MAKEFILE ./Makefile -- 2.34.1