changes
authorbdemsky <bdemsky>
Wed, 22 Jun 2011 08:08:00 +0000 (08:08 +0000)
committerbdemsky <bdemsky>
Wed, 22 Jun 2011 08:08:00 +0000 (08:08 +0000)
Robust/src/Runtime/bamboo/multicorecache.c
Robust/src/Runtime/bamboo/multicoregarbage.c
Robust/src/Runtime/bamboo/multicoregarbage.h
Robust/src/Runtime/bamboo/multicoregccompact.c
Robust/src/Runtime/bamboo/multicoregcflush.c
Robust/src/Runtime/bamboo/multicoremem.c
Robust/src/Runtime/bamboo/multicoremsg.c
Robust/src/Runtime/mem.c

index f25d4813d13e13c80e7b77dd04b28394f8b868b6..10ee1be10f9489d0ad961d8462282093a3e76e8d 100644 (file)
@@ -439,7 +439,7 @@ void cacheAdapt_phase_master() {
   GC_PRINTF("Start cachepolicy phase \n");
   // cache adapt phase
   cacheAdapt_decision(BAMBOO_NUM_OF_CORE);
-  GC_CHECK_ALL_CORE_STATUS(CACHEPOLICYPHASE==gc_status_info.gcphase);
+  GC_CHECK_ALL_CORE_STATUS();
   BAMBOO_CACHE_MF();
 
   // let all cores to adopt new policies
@@ -450,7 +450,7 @@ void cacheAdapt_phase_master() {
   // cache adapt phase
   cacheAdapt_mutator();
   cacheAdapt_gc(false);
-  GC_CHECK_ALL_CORE_STATUS(PREFINISHPHASE==gc_status_info.gcphase);
+  GC_CHECK_ALL_CORE_STATUS();
 
   CACHEADAPT_SAMPING_RESET();
   if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
index 3f7d1fb00d6ab9111b629e094bbe257e6449b8a9..dd0788f54da90256966897a92d15a5bd5a675c02 100644 (file)
@@ -285,10 +285,10 @@ void gc_collect(struct garbagelist * stackptr) {
 
   WAITFORGCPHASE(UPDATEPHASE);
 
-  GC_PRINTF("Start flush phase\n");
+  GC_PRINTF("Start update phase\n");
   GCPROFILE_INFO_2_MASTER();
   update(stackptr);
-  GC_PRINTF("Finish flush phase\n");
+  GC_PRINTF("Finish update phase\n");
 
   CACHEADAPT_PHASE_CLIENT();
 
@@ -321,15 +321,15 @@ void gc_nocollect(struct garbagelist * stackptr) {
 
   GC_PRINTF("Start mark phase\n"); 
   mark(stackptr);
-  GC_PRINTF("Finish mark phase, wait for flush\n");
+  GC_PRINTF("Finish mark phase, wait for update\n");
 
   // non-gc core collector routine
   WAITFORGCPHASE(UPDATEPHASE);
 
-  GC_PRINTF("Start flush phase\n");
+  GC_PRINTF("Start update phase\n");
   GCPROFILE_INFO_2_MASTER();
   update(stackptr);
-  GC_PRINTF("Finish flush phase\n"); 
+  GC_PRINTF("Finish update phase\n"); 
 
   CACHEADAPT_PHASE_CLIENT();
 
@@ -375,11 +375,11 @@ void master_updaterefs(struct garbagelist * stackptr) {
   gc_status_info.gcphase = UPDATEPHASE;
   GC_SEND_MSG_1_TO_CLIENT(GCSTARTUPDATE);
   GCPROFILE_ITEM();
-  GC_PRINTF("Start flush phase \n");
-  // flush phase
+  GC_PRINTF("Start update phase \n");
+  // update phase
   update(stackptr);
-  GC_CHECK_ALL_CORE_STATUS(UPDATEPHASE==gc_status_info.gcphase);
-  GC_PRINTF("Finish flush phase \n");
+  GC_CHECK_ALL_CORE_STATUS();
+  GC_PRINTF("Finish update phase \n");
 }
 
 void master_finish() {
@@ -424,7 +424,7 @@ void gc_master(struct garbagelist * stackptr) {
   GC_SEND_MSG_1_TO_CLIENT(GCSTARTINIT);
   CACHEADAPT_GC(true);
   GC_PRINTF("Check core status \n");
-  GC_CHECK_ALL_CORE_STATUS(true);
+  GC_CHECK_ALL_CORE_STATUS();
   GCPROFILE_ITEM();
   unsigned long long tmpt = BAMBOO_GET_EXE_TIME();
   CACHEADAPT_OUTPUT_CACHE_SAMPLING();
@@ -441,7 +441,7 @@ void gc_master(struct garbagelist * stackptr) {
   
   // update the references
   master_updaterefs(stackptr);
-
+  GC_PRINTF("gc master finished update   \n");
   // do cache adaptation
   CACHEADAPT_PHASE_MASTER();
 
index e8dd7a446709d2629bad9756828781b2463e01c0..b50f91c0d3619317b393c5b71e6a2df0207eb4b8 100644 (file)
@@ -112,7 +112,6 @@ void * gcbaseva; // base va for shared memory without reserved sblocks
 static bool gc_checkCoreStatus() {
   for(int i = 0; i < NUMCORES4GC; i++) {
     if(gccorestatus[i]) {
-      printf("CHECK\n");
       return false;
     }
   }  
@@ -281,15 +280,8 @@ INLINE static unsigned int hostcore(void * ptr) {
 #define NEXTTOPCORE(b) (gc_block2core[((b)+1)%(NUMCORES4GC*2)])
 
 // check if all cores are stall now
-#define GC_CHECK_ALL_CORE_STATUS(f) \
-  { \
-    gccorestatus[BAMBOO_NUM_OF_CORE] = 0; \
-    while(f) { \
-      if(gc_checkCoreStatus()) { \
-        break; \
-      } \
-    } \
-  }
+#define GC_CHECK_ALL_CORE_STATUS() gccorestatus[BAMBOO_NUM_OF_CORE] = 0; \
+  while(!gc_checkCoreStatus()) ;
 
 // send a 1-word msg to all clients
 #define GC_SEND_MSG_1_TO_CLIENT(m) \
index b21410bab17b614360a9206f409ed1f292d04b11..51a255a24aaf886de3af3decb51785bd55f1cfc5 100644 (file)
@@ -37,14 +37,72 @@ void getSpaceLocally(struct moveHelper *to) {
   to->bound = to->base + BLOCKSIZE(to->localblocknum);
 }
 
+//This function is called on the master core only...and typically by
+//the message interrupt handler
+
+void handleReturnMem_I(unsigned int cnum, void *heaptop) {
+  unsigned int blockindex;
+  BLOCKINDEX(blockindex, heaptop);
+  unsigned INTPTR localblocknum=GLOBALBLOCK2LOCAL(blockindex);
+
+  //this core is done as far as memory usage is concerned
+  returnedmem[cnum]=0;
+
+  struct blockrecord * blockrecord=&allocationinfo.blocktable[blockindex];
+
+  blockrecord->status=BS_FREE;
+  blockrecord->usedspace=(unsigned INTPTR)(heaptop-OFFSET2BASEVA(blockindex));
+  blockrecord->freespace=BLOCKSIZE(localblocknum)-blockrecord->usedspace;
+  /* Update the lowest free block */
+  if (blockindex < allocationinfo.lowestfreeblock) {
+    blockindex=allocationinfo.lowestfreeblock;
+  }
+
+  /* This is our own block...means we should mark other blocks above us as free*/
+  if (cnum==blockrecord->corenum) {
+    unsigned INTPTR nextlocalblocknum=localblocknum+1;
+    for(;nextlocalblocknum<numblockspercore;nextlocalblocknum++) {
+      unsigned INTPTR blocknum=BLOCKINDEX2(cnum, nextlocalblocknum);
+      struct blockrecord * nextblockrecord=&allocationinfo.blocktable[blockindex];
+      nextblockrecord->status=BS_FREE;
+      nextblockrecord->usedspace=0;
+      //this is true because this cannot be the lowest block
+      nextblockrecord->freespace=BLOCKSIZE(1);
+    }
+  }
+}
+
+void handleReturnMem(unsigned int cnum, void *heaptop) {
+  BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
+  handleReturnMem_I(cnum, heaptop);
+  BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
+}
+
 void getSpaceRemotely(struct moveHelper *to, unsigned int minimumbytes) {
   //need to get another block from elsewhere
   //set flag to wait for memory
-  gctomove=false;
-  //send request for memory
-  send_msg_4(STARTUPCORE,GCFINISHCOMPACT,BAMBOO_NUM_OF_CORE, minimumbytes, gccurr_heaptop);
-  //wait for flag to be set that we received message
-  while(!gctomove) ;
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    printf("A: %d\n", BAMBOO_NUM_OF_CORE);
+
+    gctomove=false;
+    BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
+    void *startaddr=handlegcfinishcompact_I(BAMBOO_NUM_OF_CORE, minimumbytes, gccurr_heaptop);
+    BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
+    if (startaddr) {
+      gcmovestartaddr=startaddr;
+    } else {
+      while(!gctomove) ;
+    }
+    printf("B: %d\n", BAMBOO_NUM_OF_CORE);
+  } else {
+    printf("C: %d\n", BAMBOO_NUM_OF_CORE);
+    gctomove=false;
+    //send request for memory
+    send_msg_4(STARTUPCORE,GCFINISHCOMPACT,BAMBOO_NUM_OF_CORE, minimumbytes, gccurr_heaptop);
+    //wait for flag to be set that we received message
+    while(!gctomove) ;
+    printf("D: %d\n", BAMBOO_NUM_OF_CORE);
+  }
 
   //store pointer
   to->ptr = gcmovestartaddr;
@@ -71,11 +129,14 @@ void compacthelper(struct moveHelper * orig,struct moveHelper * to) {
   while(true) {
     if ((gccurr_heaptop < ((unsigned INTPTR)(to->bound-to->ptr)))&&!senttopmessage) {
       //This block is the last for this core...let the startup know
-      send_msg_3(STARTUPCORE, GCRETURNMEM, BAMBOO_NUM_OF_CORE, to->ptr+gccurr_heaptop);
+      if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+       handleReturnMem(BAMBOO_NUM_OF_CORE, to->ptr+gccurr_heaptop);
+      } else {
+       send_msg_3(STARTUPCORE, GCRETURNMEM, BAMBOO_NUM_OF_CORE, to->ptr+gccurr_heaptop);
+      }
       //Only send the message once
       senttopmessage=true;
     }
-
     unsigned int minimumbytes=compactblocks(orig, to);
     if (orig->ptr==orig->bound) {
       //need more data to compact
@@ -91,8 +152,15 @@ void compacthelper(struct moveHelper * orig,struct moveHelper * to) {
       getSpace(to, minimumbytes);
     }
   }
-  
-  send_msg_4(STARTUPCORE,GCFINISHCOMPACT,BAMBOO_NUM_OF_CORE, 0, 0);
+
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
+    handlegcfinishcompact_I(BAMBOO_NUM_OF_CORE, 0, 0);
+    BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
+  } else {
+    send_msg_4(STARTUPCORE,GCFINISHCOMPACT,BAMBOO_NUM_OF_CORE, 0, 0);
+  }
+
 }
 
 void * checkNeighbors_I(int corenum, unsigned INTPTR requiredmem, unsigned INTPTR desiredmem) {
@@ -233,7 +301,7 @@ void * gcfindSpareMem_I(unsigned INTPTR requiredmem, unsigned INTPTR desiredmem,
 
 unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) {
   void *toptrinit=to->ptr;
-  void *toptr=toptr;
+  void *toptr=toptrinit;
   void *tobound=to->bound;
   void *origptr=orig->ptr;
   void *origbound=orig->bound;
@@ -334,10 +402,12 @@ void master_compact() {
   // compact phase
   compact();
   /* wait for all cores to finish compacting */
+  tprintf("MASTER WAITING\n");
 
   while(!gc_checkCoreStatus())
     ;
 
+  tprintf("POST_WAIT\n");
   GCPROFILE_ITEM();
 
   //just in case we didn't get blocks back...
index 1cf5d42255adc79457779c310561b1b0cde7642c..fc89108fa19b28875c89baeaaee215574c14e08b 100644 (file)
@@ -29,7 +29,7 @@ extern struct lockvector bamboo_threadlocks;
 #define UPDATEOBJ(obj, tt) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) obj=updateObj(updatetmpptr);}
 #define UPDATEOBJNONNULL(obj, tt) {void *updatetmpptr=obj; obj=updateObj(updatetmpptr);}
 
-
+#define dbpr() if (STARTUPCORE==BAMBOO_NUM_OF_CORE) tprintf("FL: %d\n", __LINE__);
 
 INLINE void updategarbagelist(struct garbagelist *listptr) {
   for(;listptr!=NULL; listptr=listptr->next) {
@@ -212,6 +212,14 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
       if (endtoptr>tobound||endtoptr<tobase) {
        //get use the next block of memory
        orig->ptr=origptr;
+       if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+         tprintf("dstptr=%x\n",dstptr);
+         tprintf("endtoptrptr=%x\n",endtoptr);
+         tprintf("tobound=%x\n",tobound);
+         tprintf("tobase=%x\n",tobase);
+         tprintf("origptr=%x\n",origptr);
+         tprintf("length=%d\n",length);
+       }
        return dstptr;
       }
       
@@ -255,9 +263,13 @@ void updateOrigPtr(void *currtop) {
 
 void updatehelper(struct moveHelper * orig,struct moveHelper * to) {
   while(true) {
+    dbpr();
     void *dstptr=updateblocks(orig, to);
+    dbpr();
     if (dstptr) {
-      //need more memory to compact into
+      dbpr();
+      printf("M: %x\n", dstptr);
+   //need more memory to compact into
       block_t blockindex;
       BLOCKINDEX(blockindex, dstptr);
       unsigned int corenum;
@@ -274,7 +286,9 @@ void updatehelper(struct moveHelper * orig,struct moveHelper * to) {
          ;
       }
     }
+    dbpr();
     if (orig->ptr==orig->bound) {
+      dbpr();
       //inform others that we are done with previous block
       updateOrigPtr(orig->bound);
 
@@ -285,30 +299,32 @@ void updatehelper(struct moveHelper * orig,struct moveHelper * to) {
       update_origblockptr=orig->base;
       orig->ptr=orig->base;
       orig->bound = orig->base + BLOCKSIZE(orig->localblocknum);
-      if (orig->base >= gcbaseva+BAMBOO_SHARED_MEM_SIZE)
+      if (orig->base >= gcbaseva+BAMBOO_SHARED_MEM_SIZE) {
+       //free our entire memory for others to use
        break;
+      }
     }
+    dbpr();
   }
 }
 
 void updateheap() {
-  BAMBOO_CACHE_MF();
-
   // initialize structs for compacting
   struct moveHelper orig={0,NULL,NULL,0,NULL,0,0,0,0};
   struct moveHelper to={0,NULL,NULL,0,NULL,0,0,0,0};
+  dbpr();
   initOrig_Dst(&orig, &to);
-
+  dbpr();
   updatehelper(&orig, &to);
+  dbpr();
 }
 
 void update(struct garbagelist * stackptr) {
-  BAMBOO_CACHE_MF();
-
+  dbpr();
   updateRuntimePtrs(stackptr);
-
+  dbpr();
   updateheap();
-
+  dbpr();
   // send update finish message to core coordinator
   if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
     gccorestatus[BAMBOO_NUM_OF_CORE] = 0;
index 145398bb85d3ce033c8ab0bf9f601b7f950ffed7..f84ac4506ed3b6fc67d347c86db1cddbcd59aea8 100644 (file)
@@ -57,6 +57,7 @@ void * mixedmalloc_I(int coren,
 void * globalmalloc_I(int coren, unsigned INTPTR memcheck, int * allocsize) {
   block_t firstfree=NOFREEBLOCK;
   block_t lowestblock=allocationinfo.lowestfreeblock;
+
   for(block_t searchblock=lowestblock;searchblock<GCNUMBLOCK;searchblock++) {
     struct blockrecord * block=&allocationinfo.blocktable[searchblock];
     if (block->status==BS_FREE) {
index 1a6d596f83fbc35721652d53bda5ca21f06a78d2..b2f1e869d7607956cd7605b5f085745cffa05a72 100644 (file)
@@ -527,57 +527,17 @@ void processmsg_returnmem_I() {
   MSG_INDEXINC_I();  
   void * heaptop = (void *) msgdata[msgdataindex];
   MSG_INDEXINC_I();   
-  unsigned int blockindex;
-  BLOCKINDEX(blockindex, heaptop);
-  unsigned INTPTR localblocknum=GLOBALBLOCK2LOCAL(blockindex);
 
-  //this core is done as far as memory usage is concerned
-  returnedmem[cnum]=0;
-
-  struct blockrecord * blockrecord=&allocationinfo.blocktable[blockindex];
-
-  blockrecord->status=BS_FREE;
-  blockrecord->usedspace=(unsigned INTPTR)(heaptop-OFFSET2BASEVA(blockindex));
-  blockrecord->freespace=BLOCKSIZE(localblocknum)-blockrecord->usedspace;
-  /* Update the lowest free block */
-  if (blockindex < allocationinfo.lowestfreeblock) {
-    blockindex=allocationinfo.lowestfreeblock;
-  }
-
-  /* This is our own block...means we should mark other blocks above us as free*/
-  if (cnum==blockrecord->corenum) {
-    unsigned INTPTR nextlocalblocknum=localblocknum+1;
-    for(;nextlocalblocknum<numblockspercore;nextlocalblocknum++) {
-      unsigned INTPTR blocknum=BLOCKINDEX2(cnum, nextlocalblocknum);
-      struct blockrecord * nextblockrecord=&allocationinfo.blocktable[blockindex];
-      nextblockrecord->status=BS_FREE;
-      nextblockrecord->usedspace=0;
-      //this is true because this cannot be the lowest block
-      nextblockrecord->freespace=BLOCKSIZE(1);
-    }
-  }
+  handleReturnMem_I(cnum, heaptop);
 }
 
-INLINE void processmsg_gcfinishcompact_I() {
-  BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE);
-
-  int cnum = msgdata[msgdataindex];
-  MSG_INDEXINC_I();  
-  unsigned int bytesneeded = msgdata[msgdataindex];
-  MSG_INDEXINC_I(); 
-  unsigned int maxbytesneeded = msgdata[msgdataindex];
-  MSG_INDEXINC_I();
-
+void * handlegcfinishcompact_I(int cnum, unsigned int bytesneeded, unsigned int maxbytesneeded) {
   if(bytesneeded > 0) {
     // ask for more mem
     void * startaddr = gcfindSpareMem_I(bytesneeded, maxbytesneeded, cnum);
     if(startaddr) {
       // cache the msg first
-      if(BAMBOO_CHECK_SEND_MODE()) {
-       cache_msg_2_I(cnum,GCMOVESTART,startaddr);
-      } else {
-       send_msg_2_I(cnum,GCMOVESTART,startaddr);
-      }
+      return startaddr;
     } else {
       maxusefulmems[cnum]=maxbytesneeded;
       gcrequiredmems[cnum]=bytesneeded;
@@ -586,6 +546,25 @@ INLINE void processmsg_gcfinishcompact_I() {
     //done with compacting
     gccorestatus[cnum] = 0;
   }
+  return NULL;
+}
+
+void processmsg_gcfinishcompact_I() {
+  int cnum = msgdata[msgdataindex];
+  MSG_INDEXINC_I();  
+  unsigned int bytesneeded = msgdata[msgdataindex];
+  MSG_INDEXINC_I(); 
+  unsigned int maxbytesneeded = msgdata[msgdataindex];
+  MSG_INDEXINC_I();
+
+  void * startaddr=handlegcfinishcompact_I(cnum, bytesneeded, maxbytesneeded);
+  if (startaddr) {
+    if(BAMBOO_CHECK_SEND_MODE()) {
+      cache_msg_2_I(cnum,GCMOVESTART,startaddr);
+    } else {
+      send_msg_2_I(cnum,GCMOVESTART,startaddr);
+    }
+  }
 }
 
 INLINE void processmsg_gcfinishupdate_I() {
index 972b96c18d3c0761095133385ef1281e69ff8af4..bc5216fa9f7056e9ff3dfdd81cd10e6f5fef902d 100644 (file)
@@ -10,7 +10,6 @@
 extern volatile bool gcflag;
 void * mycalloc_share(struct garbagelist * stackptr, int size) {
   void * p = NULL;
-
   int isize = ((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
   int hasgc = 0;