From 92054074e9359e47defbb181ad63426187279fcf Mon Sep 17 00:00:00 2001 From: jzhou Date: Thu, 1 Jul 2010 03:10:31 +0000 Subject: [PATCH] Statically ping memory from the nearest memory controller on the cores --- Robust/src/Runtime/GCSharedHash.c | 64 +++++++++++++++++++++++---- Robust/src/Runtime/GCSharedHash.h | 1 + Robust/src/Runtime/multicoregarbage.c | 47 +++++++++++++------- Robust/src/Runtime/multicoregarbage.h | 2 +- Robust/src/Runtime/multicoretask.c | 58 +++++++++++++----------- 5 files changed, 123 insertions(+), 49 deletions(-) diff --git a/Robust/src/Runtime/GCSharedHash.c b/Robust/src/Runtime/GCSharedHash.c index c56a1da4..c6437ab1 100755 --- a/Robust/src/Runtime/GCSharedHash.c +++ b/Robust/src/Runtime/GCSharedHash.c @@ -21,6 +21,10 @@ #define INLINE inline __attribute__((always_inline)) #endif // #ifndef INLINE +// TODO check the average collision times +//int gc_num_search = 0; +//int gc_num_collision = 0; + /* GCSHARED HASH ********************************************************/ // params: startaddr -- the start addr of the shared memory @@ -301,7 +305,39 @@ mgcsharedhashtbl_t * mgcsharedhashCreate(unsigned int size, ctable->loadfactor = loadfactor; ctable->threshold = size*loadfactor; - ctable->mask = (size << 7)-1; + ctable->mask = (size << 6)-1; + + ctable->structs = NULL ; //FREEMALLOC_NGC(1*sizeof(mgcliststruct_t)); + ctable->numelements = 0; // Initial number of elements in the hash + ctable->list = NULL; + + return ctable; +} + +mgcsharedhashtbl_t * mgcsharedhashCreate_I(unsigned int size, + double loadfactor) { + mgcsharedhashtbl_t * ctable; + mgcsharedhashlistnode_t * nodes; + int i; + + ctable = (mgcsharedhashtbl_t *)FREEMALLOC_NGC_I(sizeof(mgcsharedhashtbl_t)); + if(ctable == NULL) { + // TODO + BAMBOO_EXIT(0xeeef); + return NULL; + } + // Allocate space for the hash table + ctable->table = (mgcsharedhashlistnode_t *)FREEMALLOC_NGC_I( + size*sizeof(mgcsharedhashlistnode_t)); + if(ctable->table == NULL) { + BAMBOO_EXIT(0xfffe); // TODO + return NULL; + } + ctable->size = size; + ctable->loadfactor = loadfactor; + ctable->threshold = size*loadfactor; + + ctable->mask = (size << 6)-1; ctable->structs = NULL ; //FREEMALLOC_NGC(1*sizeof(mgcliststruct_t)); ctable->numelements = 0; // Initial number of elements in the hash @@ -351,8 +387,10 @@ int mgcsharedhashInsert(mgcsharedhashtbl_t * tbl, void * key, void * val) { return -1; } - ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>7]; - //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>7); // TODO + //int keyto = ((unsigned INTPTR)key) % (tbl->size); + //ptr=&tbl->table[keyto]; + ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6]; + //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>6); // TODO if(ptr->key==0) { // the first time insert a value for the key @@ -370,6 +408,8 @@ int mgcsharedhashInsert(mgcsharedhashtbl_t * tbl, void * key, void * val) { ptr->val = val; } } + ptr->next = tbl->list; + tbl->list = ptr; tbl->numelements++; return 1; } @@ -382,8 +422,10 @@ int mgcsharedhashInsert_I(mgcsharedhashtbl_t * tbl, void * key, void * val) { return -1; } - ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>7]; - //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>7); // TODO + //int keyto = ((unsigned INTPTR)key) % (tbl->size); + //ptr=&tbl->table[keyto]; + ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6]; + //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>6); // TODO if(ptr->key==0) { // the first time insert a value for the key @@ -405,6 +447,8 @@ int mgcsharedhashInsert_I(mgcsharedhashtbl_t * tbl, void * key, void * val) { ptr->val = val; } } + ptr->next = tbl->list; + tbl->list = ptr; tbl->numelements++; return 1; } @@ -412,16 +456,20 @@ int mgcsharedhashInsert_I(mgcsharedhashtbl_t * tbl, void * key, void * val) { // Search for an address for a given oid INLINE void * mgcsharedhashSearch(mgcsharedhashtbl_t * tbl, void * key) { //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE] + //int keyto = ((unsigned INTPTR)key) % (tbl->size); + //mgcsharedhashlistnode_t * node=&tbl->table[keyto]; mgcsharedhashlistnode_t * node = &tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6]; mgcsharedhashlistnode_t *top = &tbl->table[tbl->size]; - int i = 0; + //int i = 0; + //gc_num_search++; do { - i++; + //i++; if(node->key == key) { // TODO - printf("%x \n", 0xe000+i); + //printf("%x \n", 0xe000+i); + //gc_num_collision += i; return node->val; } node++; diff --git a/Robust/src/Runtime/GCSharedHash.h b/Robust/src/Runtime/GCSharedHash.h index 375e693f..94725fbf 100755 --- a/Robust/src/Runtime/GCSharedHash.h +++ b/Robust/src/Runtime/GCSharedHash.h @@ -80,6 +80,7 @@ typedef struct mgcsharedhashtbl { } mgcsharedhashtbl_t; mgcsharedhashtbl_t * mgcsharedhashCreate(unsigned int size, double loadfactor); +mgcsharedhashtbl_t * mgcsharedhashCreate_I(unsigned int size,double loadfactor); int mgcsharedhashInsert(mgcsharedhashtbl_t * tbl, void * key, void * val); void * mgcsharedhashSearch(mgcsharedhashtbl_t * tbl, void * key); //unsigned int mgchashResize(unsigned int newsize); diff --git a/Robust/src/Runtime/multicoregarbage.c b/Robust/src/Runtime/multicoregarbage.c index f3a93c63..e0f92c45 100644 --- a/Robust/src/Runtime/multicoregarbage.c +++ b/Robust/src/Runtime/multicoregarbage.c @@ -1941,11 +1941,18 @@ innermoveobj: //mgchashInsert_I(orig->ptr, to->ptr); RuntimeHashadd_I(gcpointertbl, orig->ptr, to->ptr); if(isremote) { +#ifdef GC_PROFILE + //unsigned long long ttimet = BAMBOO_GET_EXE_TIME(); +#endif // add to the sharedptbl if(gcsharedptbl != NULL) { //GCSharedHashadd_I(gcsharedptbl, orig->ptr, to->ptr); mgcsharedhashInsert_I(gcsharedptbl, orig->ptr, to->ptr); + //num_mapinforequest++; // TODO } +#ifdef GC_PROFILE + //flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet; +#endif } //MGCHashadd_I(gcpointertbl, orig->ptr, to->ptr); BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); @@ -2233,12 +2240,12 @@ inline void * flushObj(void * objptr) { // a shared obj ptr, change to new address BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(); #ifdef GC_PROFILE - // TODO unsigned long long ttime = BAMBOO_GET_EXE_TIME(); + unsigned long long ttime = BAMBOO_GET_EXE_TIME(); #endif //dstptr = mgchashSearch(objptr); RuntimeHashget(gcpointertbl, objptr, &dstptr); #ifdef GC_PROFILE - // TODO flushstalltime += BAMBOO_GET_EXE_TIME()-ttime; + flushstalltime += BAMBOO_GET_EXE_TIME()-ttime; #endif //MGCHashget(gcpointertbl, objptr, &dstptr); BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); @@ -2254,13 +2261,16 @@ inline void * flushObj(void * objptr) { BAMBOO_DEBUGPRINT_REG(hostcore(objptr)); #endif if(hostcore(objptr) == BAMBOO_NUM_OF_CORE) { - // error! the obj is right on this core, but cannot find it - BAMBOO_DEBUGPRINT_REG(objptr); - BAMBOO_EXIT(0xb103); - // assume that the obj has not been moved, use the original address - //dstptr = objptr; + // error! the obj is right on this core, but cannot find it + BAMBOO_DEBUGPRINT_REG(objptr); + BAMBOO_EXIT(0xb103); + // assume that the obj has not been moved, use the original address + //dstptr = objptr; } else { int hostc = hostcore(objptr); +#ifdef GC_PROFILE + unsigned long long ttimet = BAMBOO_GET_EXE_TIME(); +#endif // check the corresponsing sharedptbl BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(); //struct GCSharedHash * sptbl = gcrpointertbls[hostcore(objptr)]; @@ -2273,6 +2283,9 @@ inline void * flushObj(void * objptr) { } } BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); +#ifdef GC_PROFILE + flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet; +#endif if(dstptr == NULL) { // still can not get the mapping info, @@ -2282,11 +2295,11 @@ inline void * flushObj(void * objptr) { gcmappedobj = NULL; #ifdef GC_PROFILE // TODO - num_mapinforequest++; + //num_mapinforequest++; //unsigned long long ttime = BAMBOO_GET_EXE_TIME(); #endif #ifdef GC_PROFILE - unsigned long long ttimet = BAMBOO_GET_EXE_TIME(); + //unsigned long long ttimet = BAMBOO_GET_EXE_TIME(); #endif // the first time require the mapping, send msg to the hostcore // for the mapping info @@ -2298,7 +2311,7 @@ inline void * flushObj(void * objptr) { } } #ifdef GC_PROFILE - flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet; + //flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet; #endif #ifdef GC_PROFILE // TODO @@ -2686,13 +2699,13 @@ inline void flush(struct garbagelist * stackptr) { } #ifdef GC_PROFILE // TODO - if(BAMBOO_NUM_OF_CORE == 0) { - BAMBOO_DEBUGPRINT(0xffff); - BAMBOO_DEBUGPRINT_REG(num_mapinforequest); + //if(BAMBOO_NUM_OF_CORE == 0) { + //BAMBOO_DEBUGPRINT(0xffff); + //BAMBOO_DEBUGPRINT_REG(num_mapinforequest); //BAMBOO_DEBUGPRINT_REG(flushstalltime); //BAMBOO_DEBUGPRINT_REG(num_mapinforequest_i); - BAMBOO_DEBUGPRINT_REG(flushstalltime_i); - } + //BAMBOO_DEBUGPRINT_REG(flushstalltime_i); + //} //BAMBOO_DEBUGPRINT_REG(flushstalltime); #endif #ifdef DEBUG @@ -3195,6 +3208,10 @@ inline void gc(struct garbagelist * stackptr) { udn_tile_coord_y()); //dumpSMem(); #endif + // TODO + /*extern int gc_num_search; + extern int gc_num_collision; + tprintf("Average collision: %d \n", gc_num_collision/gc_num_search);*/ } else if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) { gcprocessing = true; gc_collect(stackptr); diff --git a/Robust/src/Runtime/multicoregarbage.h b/Robust/src/Runtime/multicoregarbage.h index 0cbab6e0..76512210 100644 --- a/Robust/src/Runtime/multicoregarbage.h +++ b/Robust/src/Runtime/multicoregarbage.h @@ -115,7 +115,7 @@ void * gcmappingtbl[NUMCORESACTIVE][NUM_MAPPING];*/ // + NUMCORES4GC bamboo_rmsp // These three types of table are always reside at the bottom of the shared // memory and will never be moved or garbage collected -#define BAMBOO_RMSP_SIZE (BAMBOO_SMEM_SIZE * 64) +#define BAMBOO_RMSP_SIZE (BAMBOO_SMEM_SIZE * 45) mspace bamboo_rmsp; // shared pointer mapping tbl //volatile struct GCSharedHash * gcsharedptbl; diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index 829ac1d9..fd1ae1e4 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -136,7 +136,14 @@ void initruntimedata() { if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) { int t_size = ((BAMBOO_RMSP_SIZE)-sizeof(mgcsharedhashtbl_t)*2 -128*sizeof(size_t))/sizeof(mgcsharedhashlistnode_t)-2; - gcsharedptbl = mgcsharedhashCreate(t_size,0.30);//allocateGCSharedHash_I(20); + int kk = 0; + unsigned int tmp_k = 1 << (sizeof(int)*8 -1); + while(((t_size & tmp_k) == 0) && (kk < sizeof(int)*8)) { + t_size = t_size << 1; + kk++; + } + t_size = tmp_k >> kk; + gcsharedptbl = mgcsharedhashCreate_I(t_size,0.30);//allocateGCSharedHash_I(20); } else { gcsharedptbl = NULL; } @@ -1311,12 +1318,12 @@ void * localmalloc_I(int coren, if(foundsmem == 1) { // find suitable block mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb= isize) { - // have enough space in the block, malloc - foundsmem = 1; - break; - } // if(size > isize) - } // if(tocheck) + if(size >= isize) { + // have enough space in the block, malloc + foundsmem = 1; + break; + } // if(size > isize) + } // if(tocheck) } else { isnext = true; } // if(nsize < bound) else ... @@ -1377,18 +1384,18 @@ void * globalmalloc_I(int coren, if(isnext) { // start another block tofindb = totest; - } // if(islocal) + } // if(islocal) } while(true); if(foundsmem == 1) { // find suitable block mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb