From: bdemsky Date: Wed, 13 Jul 2011 08:40:11 +0000 (+0000) Subject: towards fixing bugs... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b46c0e2cf1d44c3e923858281551dc45dbe8b854;p=IRC.git towards fixing bugs... --- diff --git a/Robust/src/Runtime/bamboo/multicorecache.c b/Robust/src/Runtime/bamboo/multicorecache.c index 2de873f0..377bc698 100644 --- a/Robust/src/Runtime/bamboo/multicorecache.c +++ b/Robust/src/Runtime/bamboo/multicorecache.c @@ -3,211 +3,85 @@ #include "multicoremsg.h" #include "multicoregcprofile.h" -gc_cache_revise_info_t gc_cache_revise_information; - -/* This function initialize the gc_cache_revise_information. It should be - * invoked before we start compaction. - */ -void samplingDataReviseInit(struct moveHelper * orig,struct moveHelper * to) { - // initialize the destination page info - gc_cache_revise_information.to_page_start_va=to->ptr; - unsigned int toindex=(unsigned INTPTR)(to->base-gcbaseva)>>BAMBOO_PAGE_SIZE_BITS; - gc_cache_revise_information.to_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(toindex+1); - gc_cache_revise_information.to_page_index=toindex; - // initilaize the original page info - unsigned int origindex=((unsigned INTPTR)(orig->base-gcbaseva))>>BAMBOO_PAGE_SIZE_BITS; - gc_cache_revise_information.orig_page_start_va=orig->ptr; - gc_cache_revise_information.orig_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(origindex+1); - gc_cache_revise_information.orig_page_index=origindex; -} +void cacheadapt_finish_src_page(void *srcptr, void *tostart, void *tofinish) { + unsigned int srcpage=(srcptr-gcbaseva)>>BAMBOO_PAGE_SIZE_BITS; + unsigned int dstpage=(tostart-gcbase)>>BAMBOO_PAGE_SIZE_BITS; + unsigned int numbytes=tofinish-tostart; + + unsigned int * oldtable=&gccachesamplingtbl[srcpage*NUMCORESACTIVE]; + unsigned int * newtable=&gccachesamplingtbl_r[dstpage*NUMCORESACTIVE]; + + unsigned int page64th=numbytes>>(BAMBOO_PAGE_SIZE_BITS-6); -/* This function computes the revised profiling data of the first closed destination - * page of an object that acrosses multiple pages - */ -void firstPageConvert(bool origclosefirst, unsigned INTPTR main_factor, unsigned INTPTR delta_factor) { - unsigned INTPTR topage=gc_cache_revise_information.to_page_index*NUMCORESACTIVE; - unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index*NUMCORESACTIVE; - int * newtable=&gccachesamplingtbl_r[topage]; - int * oldtable=&gccachesamplingtbl[oldpage]; - // compute the revised profiling info for the start destination page - if(origclosefirst) { - // the start original page closes first, now compute the revised profiling - // info for the start destination page. - // The start destination page = the rest of the start original page + - // delta_fator from the next original page - int * oldtable_next=&gccachesamplingtbl[oldpage+NUMCORESACTIVE]; - for(int tt = 0; tt < NUMCORESACTIVE; tt++) { - (*newtable)=(*newtable)+((*oldtable)*main_factor+(*oldtable_next)*delta_factor)>>BAMBOO_PAGE_SIZE_BITS; - newtable++; - oldtable++; - oldtable_next++; - } - // close the start original page - gc_cache_revise_information.orig_page_start_va+=main_factor+delta_factor; - gc_cache_revise_information.orig_page_end_va+=BAMBOO_PAGE_SIZE; - gc_cache_revise_information.orig_page_index++; - } else { - // the start destination page closes first, now compute the revised - // profiling info for it. - for(int tt = 0; tt < NUMCORESACTIVE; tt++) { - (*newtable)=(*newtable)+((*oldtable)*main_factor)>>BAMBOO_PAGE_SIZE_BITS; - newtable++; - oldtable++; - } - // record the new start of the original page - gc_cache_revise_information.orig_page_start_va+=main_factor; - } - // close the start original page and destination page - gc_cache_revise_information.to_page_start_va=gc_cache_revise_information.to_page_end_va; - gc_cache_revise_information.to_page_end_va+=BAMBOO_PAGE_SIZE; - gc_cache_revise_information.to_page_index++; + for(int core = 0; core < NUMCORESACTIVE; core++) { + (*newtable)+=page64th*(*oldtable); + newtable++; + oldtable++; + } } -/* This function computes the revised profiling info for closed destination - * pages that are occupied by one object that acrosses multiple pages. - * the destination page = main_factor from the first unclosed original page - * + delta_factor from the next unclosed original page - */ -void restClosedPageConvert(void * current_ptr, unsigned INTPTR main_factor, unsigned INTPTR delta_factor) { - while(gc_cache_revise_information.to_page_end_va<=current_ptr) { - unsigned INTPTR topage=gc_cache_revise_information.to_page_index*NUMCORESACTIVE; - unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index*NUMCORESACTIVE; - int *newtable=&gccachesamplingtbl_r[topage]; - int *oldtable=&gccachesamplingtbl[oldpage]; - int *oldtable_next=&gccachesamplingtbl[oldpage+NUMCORESACTIVE]; - - for(int tt = 0; tt < NUMCORESACTIVE; tt++) { - (*newtable)=(*newtable)+((*oldtable)*main_factor+(*oldtable_next)*delta_factor)>>BAMBOO_PAGE_SIZE_BITS; - newtable++; - oldtable++; - oldtable_next++; - } +void cacheadapt_finish_dst_page(void *origptr, void *tostart, void *toptr, unsigned int bytesneeded) { + unsigned int numbytes=toptr-tostart; - // close the original page and the destination page - gc_cache_revise_information.orig_page_start_va+=BAMBOO_PAGE_SIZE; - gc_cache_revise_information.orig_page_end_va+=BAMBOO_PAGE_SIZE; - gc_cache_revise_information.orig_page_index++; - gc_cache_revise_information.to_page_start_va=gc_cache_revise_information.to_page_end_va; - gc_cache_revise_information.to_page_end_va+=BAMBOO_PAGE_SIZE; - gc_cache_revise_information.to_page_index++; - } -} + void *tobound=(tostart&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE; + void *origbound=(origstart&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE; + + unsigned int topage=(tostart-gcbase)>>BAMBOO_PAGE_SIZE_BITS; + unsigned int origpage=(origptr-gcbaseva)>>BAMBOO_PAGE_SIZE_BITS; -/* This function computes the revised profiling info for the last - * destination page of an object that acrosses multiple pages. - */ -void lastPageConvert(void * current_ptr) { - unsigned INTPTR to_factor=current_ptr-gc_cache_revise_information.to_page_start_va; - unsigned INTPTR topage=gc_cache_revise_information.to_page_index*NUMCORESACTIVE; - unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index*NUMCORESACTIVE; - int *newtable=&gccachesamplingtbl_r[topage]; - int *oldtable=&gccachesamplingtbl[oldpage]; + unsigned int * totable=&gccachesamplingtbl_r[topage*NUMCORESACTIVE]; + unsigned int * origtable=&gccachesamplingtbl[origpage*NUMCORESACTIVE]; - for(int tt = 0; tt < NUMCORESACTIVE; tt++) { - (*newtable)=(*newtable)+((*oldtable)*to_factor)>>BAMBOO_PAGE_SIZE_BITS; - newtable++; - oldtable++; - } - // do not need to set gc_cache_revise_information here for the last - // original/destination page as it will be set in completePageConvert() -} - -/* This function converts multiple original pages profiling data to multiple - * destination pages' profiling data - */ -void samplingDataConvertMultiple(void * current_ptr) { - // first decide which page close first: original or destination? - unsigned INTPTR to_factor=(unsigned INTPTR)(gc_cache_revise_information.to_page_end_va-gc_cache_revise_information.to_page_start_va); - unsigned INTPTR orig_factor=(unsigned INTPTR)(gc_cache_revise_information.orig_page_end_va-gc_cache_revise_information.orig_page_start_va); - bool origclosefirst=to_factor>orig_factor; - unsigned INTPTR delta_factor=(origclosefirst)?(to_factor-orig_factor):(orig_factor-to_factor); - unsigned INTPTR main_factor=(origclosefirst)?orig_factor:to_factor; + unsigned int remaintobytes=tobound-toptr; + unsigned int remainorigbytes=origbound-origptr; - // compute the revised profiling info for the start destination page - firstPageConvert(origclosefirst, main_factor, delta_factor); - // update main_factor/delta_factor - if(origclosefirst) { - // for the following destination pages that are fully used: - // the destination page = (page_size-delta_factor) from the - // first unclosed original page + delta_factor - // from the next unclosed original page - // we always use main_factor to represent the factor from the first - // unclosed original page - main_factor=BAMBOO_PAGE_SIZE-delta_factor; - } else { - // for the following destination pages that are fully used: - // the destination page = delta_factor from the first unclosed original - // page + (page_size-delta_factor) from the next - // unclosed original page - // we always use main_factor to represent the factor from the first - // unclosed original page - main_factor=delta_factor; - delta_factor=BAMBOO_PAGE_SIZE-delta_factor; - } + do { + //round source bytes down....don't want to close out page if not necessary + remainorigbytes=(remainorigbytes>bytesneeded)?bytesneeded:remainorigbytes; - // compute the revised profiling info for the following closed destination - // pages - restClosedPageConvert(current_ptr, main_factor, delta_factor); + if (remaintobytes<=remainorigbytes) { + //Need to close out to page - // compute the revised profiling info for the last destination page if needed - lastPageConvert(current_ptr); -} + numbytes+=remaintobytes; + unsigned int page64th=numbytes>>(BAMBOO_PAGE_SIZE_BITS-6); -/* This function converts originial pages' profiling data to destination pages' - * profiling data. - * The parameter current_ptr indicates the current position in the destination - * pages. - * Note that there could be objects that across pages. In such cases, there are - * multiple orig/to pages are closed and all these to pages' profiling data - * should be properly updated. - */ -void samplingDataConvert(void * current_ptr) { - if(gc_cache_revise_information.to_page_end_va>BAMBOO_PAGE_SIZE_BITS; - newtable++; - oldtable++; + for(int core = 0; core < NUMCORESACTIVE; core++) { + (*totable)=(*totable+page64th*(*origtable))>>6; + totable++; + origtable++; } + toptr+=remaintobytes; + origptr+=remaintobytes; + bytesneeded-=remaintobytes; + topage++;//to page is definitely done + tobound+=BAMBOO_PAGE_SIZE; + origpage=(origptr-gcbaseva)>>BAMBOO_PAGE_SIZE_BITS;//handle exact match case + origbound=(origptr&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE; + } else { + //Finishing off orig page + + numbytes+=remainorigbytes; + unsigned int page64th=numbytes>>(BAMBOO_PAGE_SIZE_BITS-6); + + for(int core = 0; core < NUMCORESACTIVE; core++) { + (*totable)+=page64th*(*origtable); + totable++; + origtable++; + } + toptr+=remainorigbytes; + origptr+=remainorigbytes; + bytesneeded-=remainorigbytes; + origpage++;//just orig page is done + origbound+=BAMBOO_PAGE_SIZE; } - } -} - -/* This function computes the impact of an original page on a destination page - * in terms of profiling data. It can only be invoked when there is an original - * page that is closed or a destination page that is closed. When finished - * computing the revised profiling info of the current destination page, it - * sets up the gc_cache_revise_information to the latest position in the - * original page and the destination page. - */ -void completePageConvert(void * origptr, void * toptr, void * current_ptr) { - bool closeToPage=(unsigned int)(toptr)>=(unsigned int)(gc_cache_revise_information.to_page_end_va); - bool closeOrigPage=(unsigned int)(origptr)>=(unsigned int)(gc_cache_revise_information.orig_page_end_va); - if(closeToPage||closeOrigPage) { - // end of one or more orig/to page - // compute the impact of the original page(s) for the desitination page(s) - samplingDataConvert(current_ptr); - // prepare for an new orig page - unsigned INTPTR tmp_index=((unsigned INTPTR)(origptr-gcbaseva))>>BAMBOO_PAGE_SIZE_BITS; - gc_cache_revise_information.orig_page_start_va=origptr; - gc_cache_revise_information.orig_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(tmp_index+1); - gc_cache_revise_information.orig_page_index=tmp_index; - gc_cache_revise_information.to_page_start_va=toptr; - if(closeToPage) { - unsigned INTPTR to_index=((unsigned INTPTR)(toptr-gcbaseva))>>BAMBOO_PAGE_SIZE_BITS; - gc_cache_revise_information.to_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(to_index+1); - gc_cache_revise_information.to_page_index=to_index; - } - } + totable=&gccachesamplingtbl_r[topage*NUMCORESACTIVE]; + origtable=&gccachesamplingtbl[origpage*NUMCORESACTIVE]; + + remaintobytes=tobound-toptr; + remainorigbytes=origbound-origptr; + + numbytes=0; + } while(bytesneeded!=0); } // prepare for cache adaption: @@ -234,7 +108,7 @@ void cacheAdapt_gc(bool isgccachestage) { // find the core that accesses the page #page_index most #define CACHEADAPT_FIND_HOTTEST_CORE(page_index,hottestcore,hotfreq) \ { \ - int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE]; \ + unsigned int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE]; \ for(int i = 0; i < NUMCORESACTIVE; i++) { \ int freq = *local_tbl; \ local_tbl++; \ @@ -248,7 +122,7 @@ void cacheAdapt_gc(bool isgccachestage) { // access time of the page at the same time #define CACHEADAPT_FIND_HOTTEST_CORE_W_TOTALFREQ(page_index,hottestcore,hotfreq,totalfreq) \ { \ - int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE]; \ + unsigned int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE]; \ for(int i = 0; i < NUMCORESACTIVE; i++) { \ int freq = *local_tbl; \ local_tbl++; \ @@ -280,7 +154,7 @@ void cacheAdapt_policy_h4h(int coren){ unsigned int page_index=page_gap*coren; unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap); VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index; - int * tmp_p = gccachepolicytbl; + unsigned int * tmp_p = gccachepolicytbl; for(; page_index < page_index_end; page_index++) { bamboo_cache_policy_t policy = {0}; policy.cache_mode = BAMBOO_CACHE_MODE_HASH; @@ -296,7 +170,7 @@ void cacheAdapt_policy_local(int coren){ unsigned int page_index=page_gap*coren; unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap); VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index; - int * tmp_p = gccachepolicytbl; + unsigned int * tmp_p = gccachepolicytbl; for(; page_index < page_index_end; page_index++) { bamboo_cache_policy_t policy = {0}; unsigned int block = 0; @@ -314,7 +188,7 @@ void cacheAdapt_policy_hottest(int coren){ unsigned int page_index=page_gap*coren; unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap); VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index; - int * tmp_p = gccachepolicytbl; + unsigned int * tmp_p = gccachepolicytbl; for(; page_index < page_index_end; page_index++) { bamboo_cache_policy_t policy = {0}; unsigned int hottestcore = 0; @@ -345,7 +219,7 @@ void cacheAdapt_policy_dominate(int coren){ unsigned int page_index=page_gap*coren; unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap); VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index; - int * tmp_p = gccachepolicytbl; + unsigned int * tmp_p = gccachepolicytbl; for(; page_index < page_index_end; page_index++) { bamboo_cache_policy_t policy = {0}; unsigned int hottestcore = 0; @@ -394,7 +268,7 @@ unsigned int cacheAdapt_decision(int coren) { void cacheAdapt_mutator() { BAMBOO_CACHE_MF(); // check the changes and adapt them - int * tmp_p = gccachepolicytbl; + unsigned int * tmp_p = gccachepolicytbl; unsigned int page_sva = gcbaseva; for(; page_svaptr; void *origbound=orig->bound; - while(origptrptr; + void * tmpto=to->ptr; + + while(true) { //call compactblocks using the page boundaries at the current bounds minimumbytes=compactblocks(orig, to); if(minimumbytes == 0) { - //update cacheadpate information and the page bounds - origptr=orig->ptr; - void *toptr=to->ptr; - orig->pagebound=(void *)((int)(((int)origptr)&(~(BAMBOO_PAGE_SIZE-1)))+BAMBOO_PAGE_SIZE); - to->pagebound=(void *)((int)(((int)toptr)&(~(BAMBOO_PAGE_SIZE-1)))+BAMBOO_PAGE_SIZE); - // close the last destination page - CACHEADAPT_COMPLETE_PAGE_CONVERT(origptr, toptr, toptr); + //bump the orig page bound... + //use old orig pointer to make sure we get correct block + CACHEADAPT_FINISH_SRC_PAGE(tmporig, tmpto, to->ptr); + if (orig->ptrptr; + tmpto=to->ptr; + orig->pagebound=orig->pagebound+BAMBOO_PAGE_SIZE; + } else { + return 0; + } } else { // require more memory - return minimumbytes; - } + void *endtoptr=to->ptr+minimumbytes; + if (endtoptr>to->bound) { + CACHEADAPT_FINISH_DST_PAGE(orig->ptr, tmpto, to->ptr, 0); + return minimumbytes; + } else { + CACHEADAPT_FINISH_DST_PAGE(orig->ptr, tmpto, to->ptr, minimumbytes); + to->pagebound=((endtoptr-1)&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE; + //update pointers to avoid double counting the stuff we already added in + tmporig=orig->ptr+minimumbytes; + tmpto=to->ptr+minimumbytes; + } + } } - // when you move to a different block return to the compacthelper - return minimumbytes; } #endif @@ -393,21 +407,18 @@ unsigned int compactblockshelper(struct moveHelper * orig, struct moveHelper * t unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) { void *toptrinit=to->ptr; void *toptr=toptrinit; - void *tobound=to->bound; void *origptr=orig->ptr; #ifdef GC_CACHE_ADAPT void *origbound=orig->pagebound; - void *topagebound=to->pagebound; + void *tobound=to->pagebound; #else void *origbound=orig->bound; + void *tobound=to->bound; #endif unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origbound-gcbaseva)); unsigned int objlength; -#ifdef GC_CACHE_ADAPT - while((origptr=origendoffset) { //finished with block(a page in CACHE_ADAPT version)... - origptr=origbound; to->ptr=toptr; - orig->ptr=origptr; + orig->ptr=origbound; gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit); return 0; } } while(!gcmarktbl[arrayoffset]); origptr=CONVERTTABLEINDEXTOPTR(arrayoffset); } - + //Scan more carefully next objlength=getMarkedLength(origptr); @@ -452,19 +462,15 @@ unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) { void *endtoptr=toptr+length; if (endtoptr>tobound) { - gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit); - to->ptr=tobound; + gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit); + to->ptr=toptr; orig->ptr=origptr; -#ifdef GC_CACHE_ADAPT - // close a destination page, update the revise profiling info - CACHEADAPT_COMPLETE_PAGE_CONVERT(origptr, tobound, toptr); -#endif return length; } //good to move objects and update pointers - + gcmappingtbl[OBJMAPPINGINDEX(origptr)]=toptr; - + origptr+=length; toptr=endtoptr; } else diff --git a/Robust/src/Runtime/bamboo/multicoremem.h b/Robust/src/Runtime/bamboo/multicoremem.h index 1d8f5aa3..21fb53df 100644 --- a/Robust/src/Runtime/bamboo/multicoremem.h +++ b/Robust/src/Runtime/bamboo/multicoremem.h @@ -31,7 +31,7 @@ #endif #endif -#define BAMBOO_SHARED_RUNTIME_PAGE_SIZE (1<<24) //16M +#define BAMBOO_SHARED_RUNTIME_PAGE_SIZE ((unsigned int)(1<<24)) //16M #define BAMBOO_PAGE_SIZE ((unsigned int)(64 * 1024)) // 64K #define BAMBOO_PAGE_SIZE_BITS (16)