#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
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
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
ptr->val = val;
}
}
+ ptr->next = tbl->list;
+ tbl->list = ptr;
tbl->numelements++;
return 1;
}
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
ptr->val = val;
}
}
+ ptr->next = tbl->list;
+ tbl->list = ptr;
tbl->numelements++;
return 1;
}
// 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++;
} 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);
//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();
// 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();
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)];
}
}
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,
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
}
}
#ifdef GC_PROFILE
- flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
+ //flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
#endif
#ifdef GC_PROFILE
// TODO
}
#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
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);
// + 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;
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;
}
if(foundsmem == 1) {
// find suitable block
mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC) ?
- (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
- (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
+ (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
+ (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
*allocsize = size;
// set bamboo_smemtbl
for(i = tofindb; i <= totest; i++) {
- bamboo_smemtbl[i]=(i<NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
+ bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
}
} else if(foundsmem == 2) {
// no suitable block
bool tocheck = true;
// have some space in the block
if(totest == tofindb) {
- // the first partition
- size = bound - nsize;
+ // the first partition
+ size = bound - nsize;
} else if(nsize == 0) {
- // an empty partition, can be appended
- size += bound;
+ // 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, start another block
- isnext = true;
- tocheck = false;
- } // if(totest == tofindb) else if(nsize == 0) else ...
+ // not an empty partition, can not be appended
+ // the last continuous block is not big enough, start another block
+ isnext = 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;
- } // 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 ...
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<NUMCORES4GC) ?
- (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
- (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
+ (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
+ (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
*allocsize = size;
// set bamboo_smemtbl
for(int i = tofindb; i <= totest; i++) {
- bamboo_smemtbl[i]=(i<NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
+ bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
}
if(tofindb == bamboo_free_block) {
bamboo_free_block = totest+1;
} else {
#ifdef MULTICORE_GC
// fill header to store the size of this mem block
- memset(data1, 0, BAMBOO_CACHE_LINE_SIZE);
+ BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE);
+ //memset(data1, 0, BAMBOO_CACHE_LINE_SIZE);
(*((int*)data1)) = data2;
bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
if(((int *)data1)[6] == INIT) {
// this is the first time that this object is discovered,
// set the flag as DISCOVERED
- ((int *)data1)[6] |= DISCOVERED;
+ ((int *)data1)[6] = DISCOVERED;
gc_enqueue_I(data1);
}
// set the remote flag