fix performance bug
[IRC.git] / Robust / src / Runtime / bamboo / multicoregarbage.c
index 02b5d7992e6254158f1c507db739dbe67040a057..9f6f714fedba8c816445a4a035f36d0d3842ae97 100644 (file)
@@ -1878,7 +1878,7 @@ inline bool initOrig_Dst(struct moveHelper * orig,
        ((to->base-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
   gc_cache_revise_infomation.to_page_index = 
        (to->base-gcbaseva)/(BAMBOO_PAGE_SIZE);
-  gc_cache_revise_infomation.orig_page_start_va = -1; 
+  gc_cache_revise_infomation.orig_page_start_va = -1;
 #endif // GC_CACHE_ADAPT
 
   // init the orig ptr
@@ -1961,31 +1961,23 @@ innermoveobj:
   if(orig->ptr >= gc_cache_revise_infomation.orig_page_end_va) {
        // end of an orig page
        // compute the impact of this page for the new page
-       float tmp_factor = 
-         ((float)(to->ptr-gc_cache_revise_infomation.to_page_start_va)); 
-       // /((float)(BAMBOO_PAGE_SIZE));
+       int tmp_factor = to->ptr-gc_cache_revise_infomation.to_page_start_va; 
+       int topage=gc_cache_revise_infomation.to_page_index;
+       int oldpage = gc_cache_revise_infomation.orig_page_index;
+       int * newtable=&gccachesamplingtbl_r[topage];
+       int * oldtable=&gccachesamplingtbl[oldpage];
+       
        for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
-         ((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[
-               gc_cache_revise_infomation.to_page_index] += (int)(
-                  ((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-               gc_cache_revise_infomation.orig_page_index]*tmp_factor/((float)(BAMBOO_PAGE_SIZE)));
-         // TODO
-         /*VA tmp_va = (int)(gcbaseva+(BAMBOO_PAGE_SIZE)*gc_cache_revise_infomation.to_page_index);
-         int block = 0;
-       BLOCKINDEX(tmp_va, &block);
-       int coren = gc_block2core[block%(NUMCORES4GC*2)];         
-         if((((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-               gc_cache_revise_infomation.orig_page_index] != 0) 
-                 && (coren != tt))  {
-               tprintf("++ %x(%d) %d %d(%x, %x, %x, %x)\n", tmp_va, gc_cache_revise_infomation.orig_page_index, tt, ((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)gccachesamplingtbl, (int)gccachesamplingtbl_r, (int)&((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)&((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[gc_cache_revise_infomation.to_page_index]);
-         }*/
+         (*newtable) += (*oldtable)*tmp_factor;
+         newtable=(int*)(((char *)newtable)+size_cachesamplingtbl_local_r);
+         oldtable=(int*)(((char *)oldtable)+size_cachesamplingtbl_local);
        }
        // prepare for an new orig page
+       int tmp_index = (orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
        gc_cache_revise_infomation.orig_page_start_va = orig->ptr;
        gc_cache_revise_infomation.orig_page_end_va = gcbaseva + 
-         (BAMBOO_PAGE_SIZE)*((orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
-       gc_cache_revise_infomation.orig_page_index = 
-         (orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
+         (BAMBOO_PAGE_SIZE)*(tmp_index+1);
+       gc_cache_revise_infomation.orig_page_index = tmp_index;
        gc_cache_revise_infomation.to_page_start_va = to->ptr;
   }
 #endif
@@ -2052,38 +2044,30 @@ innermoveobj:
       nextBlock(to);
 #ifdef GC_CACHE_ADAPT
          if((to->base+to->bound) >= gc_cache_revise_infomation.to_page_end_va) {
-         // end of an to page, wrap up its information
-         float tmp_factor = 
-               ((float)(tmp_ptr-gc_cache_revise_infomation.to_page_start_va));
-         // /((float)(BAMBOO_PAGE_SIZE));
-         for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
-               ((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[
-                 gc_cache_revise_infomation.to_page_index] += (int)(
-                 ((int*)((void*)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-                 gc_cache_revise_infomation.orig_page_index]*tmp_factor/((float)(BAMBOO_PAGE_SIZE)));
-               // TODO
-               /*VA tmp_va = (int)(gcbaseva+(BAMBOO_PAGE_SIZE)*gc_cache_revise_infomation.to_page_index);
-         int block = 0;
-       BLOCKINDEX(tmp_va, &block);
-       int coren = gc_block2core[block%(NUMCORES4GC*2)];         
-         if((((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-               gc_cache_revise_infomation.orig_page_index] != 0) 
-                 && (coren != tt))  {
-               tprintf("-- %x(%d) %d %d(%x, %x, %x, %x)\n", tmp_va, gc_cache_revise_infomation.orig_page_index, tt, ((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)gccachesamplingtbl, (int)gccachesamplingtbl_r, (int)&((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)&((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[gc_cache_revise_infomation.to_page_index]);
-         }*/
-         }
-         // prepare for an new to page
-         gc_cache_revise_infomation.orig_page_start_va = orig->ptr;
-         gc_cache_revise_infomation.orig_page_end_va = gcbaseva + 
-               (BAMBOO_PAGE_SIZE)*((orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
-         gc_cache_revise_infomation.orig_page_index = 
-               (orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
-         gc_cache_revise_infomation.to_page_start_va = to->ptr;
-         gc_cache_revise_infomation.to_page_end_va = gcbaseva + 
-               (BAMBOO_PAGE_SIZE)*((to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
-         gc_cache_revise_infomation.to_page_index = 
-               (to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
-       }
+               // end of an to page, wrap up its information
+               int tmp_factor = tmp_ptr-gc_cache_revise_infomation.to_page_start_va;
+               int topage=gc_cache_revise_infomation.to_page_index;
+               int oldpage = gc_cache_revise_infomation.orig_page_index;
+               int * newtable=&gccachesamplingtbl_r[topage];
+               int * oldtable=&gccachesamplingtbl[oldpage];
+         
+               for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+                 (*newtable)=((*newtable)+(*oldtable)*tmp_factor);
+                 newtable=(int*) (((char *)newtable)+size_cachesamplingtbl_local_r);
+                 oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
+               }
+               // prepare for an new to page
+               int tmp_index = (orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
+               gc_cache_revise_infomation.orig_page_start_va = orig->ptr;
+               gc_cache_revise_infomation.orig_page_end_va = gcbaseva + 
+                 (BAMBOO_PAGE_SIZE)*(tmp_index+1);
+               gc_cache_revise_infomation.orig_page_index = tmp_index;
+               gc_cache_revise_infomation.to_page_start_va = to->ptr;
+               gc_cache_revise_infomation.to_page_end_va = gcbaseva + 
+                 (BAMBOO_PAGE_SIZE)*((to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
+               gc_cache_revise_infomation.to_page_index = 
+                 (to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
+      }
 #endif // GC_CACHE_ADAPT
       if(stopblock == to->numblocks) {
                // already fulfilled the block
@@ -2130,6 +2114,7 @@ innermoveobj:
     to->ptr += isize;
     to->offset += isize;
     to->top += isize;
+#if 0
 #ifdef GC_CACHE_ADAPT
        int tmp_ptr = to->ptr;
 #endif // GC_CACHE_ADAPT
@@ -2138,42 +2123,36 @@ innermoveobj:
       BAMBOO_MEMSET_WH(to->base, '\0', BAMBOO_CACHE_LINE_SIZE);
       (*((int*)(to->base))) = to->offset;
       nextBlock(to);
-    }
 #ifdef GC_CACHE_ADAPT
-       if((to->base+to->bound) >= gc_cache_revise_infomation.to_page_end_va) {
-         // end of an to page, wrap up its information
-         float tmp_factor = 
-               ((float)(tmp_ptr-gc_cache_revise_infomation.to_page_start_va));
-         // /((float)(BAMBOO_PAGE_SIZE));
-         for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
-               ((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[
-                 gc_cache_revise_infomation.to_page_index] += (int)(
-                 ((int*)((void*)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-                 gc_cache_revise_infomation.orig_page_index]*tmp_factor/((float)(BAMBOO_PAGE_SIZE)));
-      // TODO
-         /*VA tmp_va = (int)(gcbaseva+(BAMBOO_PAGE_SIZE)*gc_cache_revise_infomation.to_page_index);
-         int block = 0;
-       BLOCKINDEX(tmp_va, &block);
-       int coren = gc_block2core[block%(NUMCORES4GC*2)];         
-         if((((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-               gc_cache_revise_infomation.orig_page_index] != 0) 
-                 && (coren != tt))  {
-               tprintf("== %x(%d) %d %d(%x, %x, %x, %x)\n", tmp_va, gc_cache_revise_infomation.orig_page_index, tt, ((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)gccachesamplingtbl, (int)gccachesamplingtbl_r, (int)&((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)&((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[gc_cache_revise_infomation.to_page_index]);
-         }*/
+         if((to->base+to->bound) >= gc_cache_revise_infomation.to_page_end_va) {
+               // end of an to page, wrap up its information
+               int tmp_factor = tmp_ptr-gc_cache_revise_infomation.to_page_start_va;
+               int topage=gc_cache_revise_infomation.to_page_index;
+               int oldpage = gc_cache_revise_infomation.orig_page_index;
+               int * newtable=&gccachesamplingtbl_r[topage];
+               int * oldtable=&gccachesamplingtbl[oldpage];
+         
+               for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+                 (*newtable)=((*newtable)+(*oldtable)*tmp_factor);
+                 newtable=(int*) (((char *)newtable)+size_cachesamplingtbl_local_r);
+                 oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
+               }
+               // prepare for an new to page
+               int tmp_index = (orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
+               gc_cache_revise_infomation.orig_page_start_va = orig->ptr;
+               gc_cache_revise_infomation.orig_page_end_va = gcbaseva + 
+                 (BAMBOO_PAGE_SIZE)*((orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
+               gc_cache_revise_infomation.orig_page_index = 
+                 (orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
+               gc_cache_revise_infomation.to_page_start_va = to->ptr;
+               gc_cache_revise_infomation.to_page_end_va = gcbaseva + 
+                 (BAMBOO_PAGE_SIZE)*((to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
+               gc_cache_revise_infomation.to_page_index = 
+                 (to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
          }
-         // prepare for an new to page
-         gc_cache_revise_infomation.orig_page_start_va = orig->ptr;
-         gc_cache_revise_infomation.orig_page_end_va = gcbaseva + 
-               (BAMBOO_PAGE_SIZE)*((orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
-         gc_cache_revise_infomation.orig_page_index = 
-               (orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
-         gc_cache_revise_infomation.to_page_start_va = to->ptr;
-         gc_cache_revise_infomation.to_page_end_va = gcbaseva + 
-               (BAMBOO_PAGE_SIZE)*((to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
-         gc_cache_revise_infomation.to_page_index = 
-               (to->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
-       }
 #endif // GC_CACHE_ADAPT
+    }
+#endif
   } // if(mark == 1)
 #ifdef DEBUG
   BAMBOO_DEBUGPRINT(0xe205);
@@ -2270,26 +2249,18 @@ innercompact:
     }
   }
 #ifdef GC_CACHE_ADAPT
-       // end of an to page, wrap up its information
-       float tmp_factor = 
-         ((float)(to->ptr-gc_cache_revise_infomation.to_page_start_va));
-       // /((float)(BAMBOO_PAGE_SIZE));
-       for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
-         ((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[
-               gc_cache_revise_infomation.to_page_index] += (int)(
-               ((int*)((void*)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-               gc_cache_revise_infomation.orig_page_index]*tmp_factor/((float)(BAMBOO_PAGE_SIZE)));
-         // TODO
-         /*VA tmp_va = (int)(gcbaseva+(BAMBOO_PAGE_SIZE)*gc_cache_revise_infomation.to_page_index);
-         int block = 0;
-       BLOCKINDEX(tmp_va, &block);
-       int coren = gc_block2core[block%(NUMCORES4GC*2)];         
-         if((((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[
-               gc_cache_revise_infomation.orig_page_index] != 0) 
-                 && (coren != tt))  {
-               tprintf("** %x(%d) %d %d(%x, %x, %x, %x)\n", tmp_va, gc_cache_revise_infomation.orig_page_index, tt, ((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)gccachesamplingtbl, (int)gccachesamplingtbl_r, (int)&((int*)((void *)gccachesamplingtbl+tt*size_cachesamplingtbl_local))[gc_cache_revise_infomation.orig_page_index], (int)&((int*)((void*)gccachesamplingtbl_r+tt*size_cachesamplingtbl_local_r))[gc_cache_revise_infomation.to_page_index]);
-         }*/
-       }
+  // end of an to page, wrap up its information
+  int tmp_factor = to->ptr-gc_cache_revise_infomation.to_page_start_va;
+  int topage=gc_cache_revise_infomation.to_page_index;
+  int oldpage = gc_cache_revise_infomation.orig_page_index;
+  int * newtable=&gccachesamplingtbl_r[topage];
+  int * oldtable=&gccachesamplingtbl[oldpage];
+  
+  for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+    (*newtable) = ((*newtable)+(*oldtable)*tmp_factor);
+    newtable=(int*) (((char *)newtable)+size_cachesamplingtbl_local_r);
+    oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
+  }
 #endif // GC_CACHE_ADAPT
   // if no objs have been compact, do nothing,
   // otherwise, fill the header of this block
@@ -2976,7 +2947,7 @@ int cacheAdapt_policy_hotest(){
        for(int i = 0; i < NUMCORESACTIVE; i++) {
          int * local_tbl = (int *)((void *)gccachesamplingtbl_r
                  +size_cachesamplingtbl_local_r*i);
-         int freq = local_tbl[page_index];
+         int freq = local_tbl[page_index]/BAMBOO_PAGE_SIZE;
          // TODO
          // check the freqency, decide if this page is hot for the core
          if(hotfreq < freq) {
@@ -3030,7 +3001,7 @@ int cacheAdapt_policy_dominate(){
        for(int i = 0; i < NUMCORESACTIVE; i++) {
          int * local_tbl = (int *)((void *)gccachesamplingtbl_r
                  +size_cachesamplingtbl_local_r*i);
-         int freq = local_tbl[page_index];
+         int freq = local_tbl[page_index]/BAMBOO_PAGE_SIZE;
          totalfreq += freq;
          // TODO
          // check the freqency, decide if this page is hot for the core
@@ -3133,7 +3104,7 @@ int cacheAdapt_policy_overload(){
        for(int i = 0; i < NUMCORESACTIVE; i++) {
          int * local_tbl = (int *)((void *)gccachesamplingtbl_r
                  +size_cachesamplingtbl_local_r*i);
-         int freq = local_tbl[page_index];
+         int freq = local_tbl[page_index]/BAMBOO_PAGE_SIZE;
          totalfreq += freq;
          // TODO
          // check the freqency, decide if this page is hot for the core
@@ -3242,7 +3213,7 @@ int cacheAdapt_policy_crowd(){
        for(int i = 0; i < NUMCORESACTIVE; i++) {
          int * local_tbl = (int *)((void *)gccachesamplingtbl_r
                  +size_cachesamplingtbl_local_r*i);
-         int freq = local_tbl[page_index];
+         int freq = local_tbl[page_index]/BAMBOO_PAGE_SIZE;
          totalfreq += freq;
          // TODO
          // check the freqency, decide if this page is hot for the core
@@ -3366,9 +3337,9 @@ void cacheAdapt_master() {
   int numchanged = 0;
   // check the statistic data
   // for each page, decide the new cache strategy
-  //numchanged = cacheAdapt_policy_h4h();
+  numchanged = cacheAdapt_policy_h4h();
   //numchanged = cacheAdapt_policy_local();
-  numchanged = cacheAdapt_policy_hotest();
+  //numchanged = cacheAdapt_policy_hotest();
   //numchanged = cacheAdapt_policy_dominate();
   //numchanged = cacheAdapt_policy_overload();
   //numchanged = cacheAdapt_policy_crowd();
@@ -3415,7 +3386,7 @@ void gc_output_cache_sampling() {
        for(int i = 0; i < NUMCORESACTIVE; i++) {
          int * local_tbl = (int *)((void *)gccachesamplingtbl
                  +size_cachesamplingtbl_local*i);
-         int freq = local_tbl[page_index];
+         int freq = local_tbl[page_index]/BAMBOO_PAGE_SIZE;
          printf("%8d ",freq);
        }
        printf("\n");
@@ -3437,7 +3408,7 @@ void gc_output_cache_sampling_r() {
        for(int i = 0; i < NUMCORESACTIVE; i++) {
          int * local_tbl = (int *)((void *)gccachesamplingtbl_r
                  +size_cachesamplingtbl_local_r*i);
-         int freq = local_tbl[page_index];
+         int freq = local_tbl[page_index]/BAMBOO_PAGE_SIZE;
          printf("%8d ",freq);
        }
        printf("\n");