try to make update phase work...need to ask for permission to write into memory blocks
authorbdemsky <bdemsky>
Tue, 21 Jun 2011 22:59:36 +0000 (22:59 +0000)
committerbdemsky <bdemsky>
Tue, 21 Jun 2011 22:59:36 +0000 (22:59 +0000)
Robust/src/Runtime/bamboo/multicoregarbage.c
Robust/src/Runtime/bamboo/multicoregarbage.h
Robust/src/Runtime/bamboo/multicoregcflush.c
Robust/src/Runtime/bamboo/multicoregcmark.c
Robust/src/Runtime/bamboo/multicoregcmark.h
Robust/src/Runtime/bamboo/multicoremsg.c
Robust/src/Runtime/bamboo/multicoremsg.h

index c23a78dd73f9931c8f93b1268648e646ad589ee2..3f7d1fb00d6ab9111b629e094bbe257e6449b8a9 100644 (file)
@@ -20,7 +20,7 @@ void dumpSMem() {
   int block = 0;
   int sblock = 0;
   unsigned int j = 0;
-  void * i = 0;
+  unsigned int i = 0;
   int coren = 0;
   int x = 0;
   int y = 0;
@@ -28,7 +28,7 @@ void dumpSMem() {
   // reserved blocks for sblocktbl
   printf("(%x,%x) ++++ reserved sblocks ++++ \n", udn_tile_coord_x(),
         udn_tile_coord_y());
-  for(i=BAMBOO_BASE_VA; (unsinged int)i<(unsigned int)gcbaseva; i+= 4*16) {
+  for(i=BAMBOO_BASE_VA; i<gcbaseva; i+= 4*16) {
     printf("(%x,%x) 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \n",
         udn_tile_coord_x(), udn_tile_coord_y(),
         *((int *)(i)), *((int *)(i + 4)),
@@ -115,6 +115,12 @@ void initmulticoregcdata() {
     buildCore2Test();
   }
 
+  //initialize update structures
+  origarraycount=0;
+  for(int i=0;i<NUMCORES4GC;i++) {
+    origblockarray[i]=NULL;
+  }
+
   INIT_MULTICORE_GCPROFILE_DATA();
 }
 
@@ -145,7 +151,7 @@ void initGC() {
   gcblock2fill = 0;
   gcmovepending = 0;
   gccurr_heaptop = 0;
-
+  update_origblockptr=NULL;
   gc_queueinit();
 
   MGCHashreset(gcforwardobjtbl);
index 2d95c3d6792ac60b44acdbc50d05961cc4fa2ae2..e8dd7a446709d2629bad9756828781b2463e01c0 100644 (file)
@@ -7,11 +7,11 @@
 #include "structdefs.h"
 #include "multicoregcprofile.h"
 
-#ifdef GC_DEBUG
+//#ifdef GC_DEBUG
 #define GC_PRINTF tprintf
-#else
-#define GC_PRINTF if(0) tprintf
-#endif 
+//#else
+//#define GC_PRINTF if(0) tprintf
+//#endif 
 
 // data structures for GC
 #define BAMBOO_SMEM_SIZE_L (BAMBOO_SMEM_SIZE * 2)
@@ -86,6 +86,13 @@ volatile unsigned int maxusefulmems[NUMCORES4GC]; //record pending mem requests
 volatile unsigned int gcrequiredmems[NUMCORES4GC]; //record pending mem requests
 volatile unsigned int gcmovepending;
 
+//keep track of current base block pointer for orig block
+volatile void * update_origblockptr;
+volatile void * origblockarray[NUMCORES4GC];
+volatile int origarraycount;
+volatile bool blockgranted;
+
+
 // shared memory pointer for pointer mapping tbls
 // In GC version, this block of memory is located at the bottom of the 
 // shared memory, right on the top of the smem tbl.
@@ -206,6 +213,14 @@ unsigned int size_cachepolicytbl;
     } \
   }
 
+#define BLOCK2CORE(c, b) {                     \
+    if(1 == (NUMCORES4GC)) {                   \
+      c = 0;                                   \
+    } else {                                   \
+      c = gc_block2core[(b%(NUMCORES4GC*2))];  \
+    }                                          \
+  }
+
 INLINE static unsigned int hostcore(void * ptr) {
   // check the host core of ptr
   unsigned int host;
index 7b72e258efe42578e265032cf91beba581a93608..1cf5d42255adc79457779c310561b1b0cde7642c 100644 (file)
@@ -195,7 +195,7 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
          //finished with block...
          origptr=origbound;
          orig->ptr=origptr;
-         return 0;
+         return NULL;
        }
       } while(!gcmarktbl[arrayoffset]);
       origptr=CONVERTTABLEINDEXTOPTR(arrayoffset);
@@ -211,7 +211,6 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
 
       if (endtoptr>tobound||endtoptr<tobase) {
        //get use the next block of memory
-       to->ptr=tobound;
        orig->ptr=origptr;
        return dstptr;
       }
@@ -236,22 +235,59 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
   }
 }
 
+void updateOrigPtr(void *currtop) {
+  //Ordering is important...
+  //Update heap top first...
+  update_origblockptr=currtop;
+
+  //Then check for waiting cores
+  if (origarraycount>0) {
+    for(int i=0;i<NUMCORES4GC;i++) {
+      void *ptr=origblockarray[i];
+      if (ptr!=NULL&&ptr<currtop) {
+       origarraycount--;
+       origblockarray[i]=NULL;
+       send_msg_1(i,GCGRANTBLOCK);
+      }
+    }
+  }
+}
+
 void updatehelper(struct moveHelper * orig,struct moveHelper * to) {
   while(true) {
-    unsigned int minimumbytes=updateblocks(orig, to);
+    void *dstptr=updateblocks(orig, to);
+    if (dstptr) {
+      //need more memory to compact into
+      block_t blockindex;
+      BLOCKINDEX(blockindex, dstptr);
+      unsigned int corenum;
+      BLOCK2CORE(corenum, blockindex);
+      to->base=OFFSET2BASEVA(blockindex)+gcbaseva;
+      to->bound=BOUNDPTR(blockindex)+gcbaseva;
+      if (corenum!=BAMBOO_NUM_OF_CORE) {
+       //we have someone elses memory...need to ask to use it
+       //first set flag to false
+       blockgranted=false;
+       send_msg_3(corenum,GCREQBLOCK, BAMBOO_NUM_OF_CORE, to->bound);
+       //wait for permission
+       while(!blockgranted)
+         ;
+      }
+    }
     if (orig->ptr==orig->bound) {
+      //inform others that we are done with previous block
+      updateOrigPtr(orig->bound);
+
       //need more data to compact
       //increment the core
       orig->localblocknum++;
       BASEPTR(orig->base,BAMBOO_NUM_OF_CORE, orig->localblocknum);
+      update_origblockptr=orig->base;
       orig->ptr=orig->base;
       orig->bound = orig->base + BLOCKSIZE(orig->localblocknum);
       if (orig->base >= gcbaseva+BAMBOO_SHARED_MEM_SIZE)
        break;
     }
-    if (minimumbytes!=0) {
-      getSpace(to, minimumbytes);
-    }
   }
 }
 
index 72ff2ec96ed3b9f017146bce1be9d98761962a17..0dfa1a78fdb00e7b49ef101f155c3c01342a94c6 100644 (file)
@@ -47,19 +47,6 @@ INLINE bool isLarge(void * ptr, int * ttype, unsigned int * tsize) {
   return (*tsize) > blocksize;
 }
 
-INLINE unsigned int hostcore(void * ptr) {
-  // check the host core of ptr
-  unsigned int host = 0;
-  if(1 == (NUMCORES4GC)) { 
-    host = 0; 
-  } else { 
-    unsigned int t = (unsigned int)ptr - (unsigned int)gcbaseva; 
-    unsigned int b = (t < BAMBOO_LARGE_SMEM_BOUND) ? t / (BAMBOO_SMEM_SIZE_L) : NUMCORES4GC+((t-(BAMBOO_LARGE_SMEM_BOUND))/(BAMBOO_SMEM_SIZE));
-    host = gc_block2core[(b%(NUMCORES4GC*2))];
-  }
-  return host;
-}
-
 //push the null check into the mark macro
 //#define MARKOBJ(objptr, ii) {void * marktmpptr=objptr; if (marktmpptr!=NULL) markObj(marktmpptr, __LINE__, ii);}
 //#define MARKOBJNONNULL(objptr, ii) {markObj(objptr, __LINE__, ii);}
index 2d91b93ed17e9493f3d922173a920087e6444132..3bed08a57e5eaa8e5b24b25253320b14e0ef7da3 100644 (file)
@@ -5,7 +5,6 @@
 
 INLINE void gettype_size(void * ptr, int * ttype, unsigned int * tsize);
 INLINE bool isLarge(void * ptr, int * ttype, unsigned int * tsize);
-INLINE unsigned int hostcore(void * ptr);
 INLINE void markgarbagelist(struct garbagelist * listptr);
 INLINE void tomark(struct garbagelist * stackptr);
 INLINE void scanPtrsInObj(void * ptr, int type);
index 202fcdbed7e41d3acbf09daedb382c8f9e95f545..1a6d596f83fbc35721652d53bda5ca21f06a78d2 100644 (file)
@@ -44,8 +44,10 @@ int msgsizearray[] = {
   5, //GCMARKREPORT,          // 0xEe
   2, //GCMARKEDOBJ,           // 0xEf
   2, //GCMOVESTART,           // 0xF0
-  1, //GCLOBJREQUEST,         // 0xF1   
- -1, //GCLOBJINFO,            // 0xF2
+  1, //GCLOBJREQUEST,         // 0xF1
+  3, //GCREQBLOCK,
+  1, //GCGRANTBLOCK,  
+  -1, //GCLOBJINFO,            // 0xF2
 #ifdef GC_PROFILE
   4, //GCPROFILES,            // 0xF3
 #endif // GC_PROFILE
@@ -470,6 +472,30 @@ INLINE void processmsg_gcfinishinit_I() {
   }
 }
 
+INLINE void processmsg_reqblock_I() {
+  int cnum=msgdata[msgdataindex];
+  MSG_INDEXINC_I();
+  void * topptr=msgdata[msgdataindex];
+  MSG_INDEXINC_I();
+  if (topptr<=update_origblockptr) {
+    //send message
+    if(BAMBOO_CHECK_SEND_MODE()) {
+      cache_msg_1_I(cnum,GCGRANTBLOCK);
+    } else {
+      send_msg_1_I(cnum,GCGRANTBLOCK);
+    }
+  } else {
+    //store message
+    origblockarray[cnum]=topptr;
+    origarraycount++;
+  }
+}
+
+INLINE void processmsg_grantblock_I() {
+  blockgranted=true;
+}
+
+
 INLINE void processmsg_gcfinishmark_I() {
   int data1 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
@@ -965,6 +991,16 @@ processmsg:
       break;
     } 
 
+    case GCREQBLOCK: {
+      processmsg_reqblock_I();
+      break;
+    }
+
+    case GCGRANTBLOCK: {
+      processmsg_grantblock_I();
+      break;
+    }
+
     case GCLOBJINFO: {
       // received a large objs info response msg
       processmsg_gclobjinfo_I(msglength);
index b18708a779c30cfa47de140223d5ee90ee8e65cf..03fa5c554d5ab2cddfa8ac6303d8643c7d109b09 100644 (file)
@@ -188,6 +188,8 @@ typedef enum {
   GCMARKEDOBJ,           // 0xEf
   GCMOVESTART,           // 0xF0
   GCLOBJREQUEST,         // 0xF1   
+  GCREQBLOCK,
+  GCGRANTBLOCK,  
   GCLOBJINFO,            // 0xF2
 #ifdef GC_PROFILE
   GCPROFILES,            // 0xF3