From eb4445c1d0faad730d18eaea849503e005e28821 Mon Sep 17 00:00:00 2001 From: jzhou Date: Wed, 7 Jul 2010 00:33:21 +0000 Subject: [PATCH] Add a new shared memory allocation strategy: mixed mode. Comparing to the fixed mode, there are following differences: 1) the neighbours cores are extended to the cores that a core can reach in no more than 2 flips; 2) introduced a threshold--if the master core can not allocate the neighbour cores' shared memory chunks, it checks current shared memory usage rate, if greater than the threshold it will enable gc, otherwise it tries to allocate the shared memory globally for the request core. --- Robust/src/Runtime/multicoregarbage.c | 37 ++-- Robust/src/Runtime/multicoretask.c | 234 +++++++++++++++++++++++--- 2 files changed, 237 insertions(+), 34 deletions(-) diff --git a/Robust/src/Runtime/multicoregarbage.c b/Robust/src/Runtime/multicoregarbage.c index e0f92c45..f68e2bbf 100644 --- a/Robust/src/Runtime/multicoregarbage.c +++ b/Robust/src/Runtime/multicoregarbage.c @@ -26,6 +26,11 @@ extern struct taskparamdescriptor *currtpd; extern struct LockValue runtime_locks[MAXTASKPARAMS]; extern int runtime_locklen; +#ifdef SMEMM +extern unsigned int gcmem_mixed_threshold; +extern unsigned int gcmem_mixed_usedmem; +#endif + struct pointerblock { void * ptrs[NUMPTRS]; struct pointerblock *next; @@ -795,9 +800,6 @@ inline bool cacheLObjs() { return true; } // void cacheLObjs() -// NOTE: the free mem chunks should be maintained in an ordered linklist -// the listtop param always specify current list tail - // update the bmmboo_smemtbl to record current shared mem usage void updateSmemTbl(int coren, int localtop) { @@ -816,8 +818,14 @@ void updateSmemTbl(int coren, if(toset < ltopcore) { bamboo_smemtbl[toset]= (toset 4) { + if(k >= NUM_CORES2TEST) { // no more memory available on either coren or its neighbour cores foundsmem = 2; goto memsearchresult; @@ -1512,6 +1580,119 @@ memsearchresult: return mem; } // void * fixedmalloc_I(int, int, int *) +#endif // #ifdef SMEMF + +#ifdef SMEMM +// Allocate the local shared memory to each core with the highest priority, +// if a core has used up its local shared memory, try to allocate the +// shared memory that belong to its neighbours first, if failed, check +// current memory allocation rate, if it has already reached the threshold, +// start gc, otherwise, allocate the shared memory globally. If all the +// shared memory has been used up, start gc. +void * mixedmalloc_I(int coren, + int isize, + int * allocsize) { + void * mem = NULL; + int i = 0; + int j = 0; + int k = 0; + int coords_x = bamboo_cpu2coords[coren*2]; + int coords_y = bamboo_cpu2coords[coren*2+1]; + int ii = 1; + int tofindb = gc_core2block[2*core2test[coren][k]+i]+(NUMCORES4GC*2)*j; + int totest = tofindb; + int bound = BAMBOO_SMEM_SIZE_L; + int foundsmem = 0; + int size = 0; + do { + bound = (totest < NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE; + int nsize = bamboo_smemtbl[totest]; + bool islocal = true; + if(nsize < bound) { + bool tocheck = true; + // have some space in the block + if(totest == tofindb) { + // the first partition + size = bound - nsize; + } else if(nsize == 0) { + // an empty partition, can be appended + size += bound; + } else { + // not an empty partition, can not be appended + // the last continuous block is not big enough, go to check the next + // local block + islocal = true; + tocheck = false; + } // if(totest == tofindb) else if(nsize == 0) else ... + if(tocheck) { + if(size >= isize) { + // have enough space in the block, malloc + foundsmem = 1; + break; + } else { + // no enough space yet, try to append next continuous block + // TODO may consider to go to next local block? + islocal = false; + } // if(size > isize) else ... + } // if(tocheck) + } // if(nsize < bound) + if(islocal) { + // no space in the block, go to check the next block + i++; + if(2==i) { + i = 0; + j++; + } + tofindb=totest=gc_core2block[2*core2test[coren][k]+i]+(NUMCORES4GC*2)*j; + } else { + totest += 1; + } // if(islocal) else ... + if(totest > gcnumblock-1-bamboo_reserved_smem) { + // no more local mem, do not find suitable block on local mem + // try to malloc shared memory assigned to the neighbour cores + do{ + k++; + if(k >= NUM_CORES2TEST) { + if(gcmem_mixed_usedmem >= gcmem_mixed_threshold) { + // no more memory available on either coren or its neighbour cores + foundsmem = 2; + goto memmixedsearchresult; + } else { + // try allocate globally + mem = globalmalloc_I(coren, isize, allocsize); + return mem; + } + } + } while(core2test[coren][k] == -1); + i = 0; + j = 0; + tofindb=totest=gc_core2block[2*core2test[coren][k]+i]+(NUMCORES4GC*2)*j; + } // if(totest > gcnumblock-1-bamboo_reserved_smem) ... + } while(true); + +memmixedsearchresult: + if(foundsmem == 1) { + // find suitable block + mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb