small changes
[IRC.git] / Robust / src / Runtime / bamboo / multicoregarbage.h
index 1e5b6989c5623ee1e23b77b8a047e19859b9857a..7ac1d6ed118dda8ed4892850a8b6617ddf63dc0d 100644 (file)
@@ -1,4 +1,4 @@
-m#ifndef BAMBOO_MULTICORE_GARBAGE_H
+#ifndef BAMBOO_MULTICORE_GARBAGE_H
 #define BAMBOO_MULTICORE_GARBAGE_H
 #ifdef MULTICORE_GC
 #include "multicore.h"
@@ -6,6 +6,7 @@ m#ifndef BAMBOO_MULTICORE_GARBAGE_H
 #include "multicorehelper.h"  // for mappings between core # and block #
 #include "structdefs.h"
 #include "multicoregcprofile.h"
+#include "gctypes.h"
 
 #ifdef GC_DEBUG
 #define GC_PRINTF tprintf
@@ -13,6 +14,12 @@ m#ifndef BAMBOO_MULTICORE_GARBAGE_H
 #define GC_PRINTF if(0) tprintf
 #endif 
 
+#ifdef GC_DEBUG
+#define TR() tprintf("%u\n",__LINE__)
+#else
+#define TR()
+#endif
+
 // data structures for GC
 #define BAMBOO_SMEM_SIZE_L (BAMBOO_SMEM_SIZE * 2)
 #define BAMBOO_LARGE_SMEM_BOUND (BAMBOO_SMEM_SIZE_L*NUMCORES4GC)
@@ -47,6 +54,10 @@ struct MGCHash * gcforwardobjtbl; // cache forwarded objs in mark phase
 volatile unsigned int gccorestatus[NUMCORESACTIVE];//records status of each core
                                                    // 1: running gc
                                                    // 0: stall
+
+volatile unsigned int returnedmem[NUMCORESACTIVE];//records status of each core
+                                                   // 1: running gc
+                                                   // 0: stall
 volatile unsigned int gcnumsendobjs[2][NUMCORESACTIVE];//# of objects sent out
 volatile unsigned int gcnumreceiveobjs[2][NUMCORESACTIVE];//# of objects received
 volatile unsigned int gcnumsrobjs_index;//indicates which entry to record the  
@@ -59,9 +70,8 @@ unsigned int gcself_numsendobjs;
 unsigned int gcself_numreceiveobjs;
 
 // for load balancing
-unsigned int gcheaptop;
 unsigned INTPTR gcloads[NUMCORES4GC];
-unsigned INTPTR numblockspercore;
+block_t numblockspercore;
 
 //Top of each core's heap
 void * topptrs[NUMCORES4GC];
@@ -77,9 +87,17 @@ volatile unsigned int gcmovestartaddr;
 volatile bool gctomove;
 
 //keeps track of memory request master was not able to serve
-unsigned int gcrequiredmems[NUMCORES4GC]; //record pending mem requests
+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.
@@ -92,14 +110,18 @@ void ** gcmappingtbl;
 unsigned int bamboo_rmsp_size;
 
 //mark table....keep track of mark bits
-unsigned int * gcmarktbl;
+volatile unsigned int * gcmarktbl;
+
+bool gc_checkCoreStatus();
+
+void gc_resetCoreStatus();
+
 
-void * gcbaseva; // base va for shared memory without reserved sblocks
 
 /* Structure to keep track of free space in block */
 enum blockstatus {
-  /* BS_INIT indicates that we don't have information for this block yet */
-  BS_INIT,
+  /* BS_USED indicates that we don't have information for this block yet */
+  BS_USED,
   /* BS_LARGEOBJECT indicates that the beginning of this block has a large object*/
   BS_LARGEOBJECT,
   /* BS_FREE indicates that the block is at least partially free */
@@ -109,8 +131,8 @@ enum blockstatus {
 struct blockrecord {
   enum blockstatus status;
   unsigned INTPTR usedspace;
+  unsigned INTPTR freespace;
   unsigned int corenum;
-
 };
 
 #define NOFREEBLOCK 0xffffffff
@@ -122,16 +144,14 @@ struct allocrecord {
 struct allocrecord allocationinfo;
 
 #ifdef GC_CACHE_ADAPT
-void * gctopva; // top va for shared memory without reserved sblocks
-volatile bool gccachestage;
 // table recording the sampling data collected for cache adaption 
-int * gccachesamplingtbl;
-int * gccachesamplingtbl_local;
-unsigned int size_cachesamplingtbl_local;
-int * gccachesamplingtbl_r;
-int * gccachesamplingtbl_local_r;
-unsigned int size_cachesamplingtbl_local_r;
-int * gccachepolicytbl;
+unsigned int * gccachesamplingtbl;
+unsigned int * gccachesamplingtbl_local;// for zeroing memory only
+unsigned int size_cachesamplingtbl_local; // for zeroing memory only
+unsigned int * gccachesamplingtbl_r;
+unsigned int * gccachesamplingtbl_local_r; // for zeroing memory only
+unsigned int size_cachesamplingtbl_local_r; // for zeroing memory only
+unsigned int * gccachepolicytbl;
 unsigned int size_cachepolicytbl;
 #endif
 
@@ -140,6 +160,15 @@ unsigned int size_cachepolicytbl;
 #define GCNUMBLOCK (NUMCORES4GC+(BAMBOO_SHARED_MEM_SIZE-BAMBOO_LARGE_SMEM_BOUND)/BAMBOO_SMEM_SIZE)
 #define GCNUMLOCALBLOCK (GCNUMBLOCK/NUMCORES4GC)
 
+/* Leave the neighboring cores with at least two blocks */
+#define MAXNEIGHBORALLOC (GCNUMLOCALBLOCK-2)
+
+/* This macro defines the smallest memoy chunk the master will hand out to another core during compacting */
+
+#define MINMEMORYCHUNKSIZE 32768
+
+#define ISVALIDPTR(x) ((((unsigned INTPTR)x)>=((unsigned INTPTR)gcbaseva))&&(((unsigned INTPTR)x)<((unsigned INTPTR)(gcbaseva+BAMBOO_SHARED_MEM_SIZE))))
+
 /* This macro waits for the given gc phase */
 #define WAITFORGCPHASE(phase) while(gc_status_info.gcphase != phase) ;
 
@@ -179,6 +208,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;
@@ -205,7 +242,11 @@ INLINE static unsigned int hostcore(void * ptr) {
 
 //This macro takes in a local block number and returns the size of the block
 #define BLOCKSIZE(c) \
-  ((c)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE)
+  ((c)?BAMBOO_SMEM_SIZE:BAMBOO_SMEM_SIZE_L)
+
+//This macro takes in a local block number and returns the size of the block
+#define GLOBALBLOCKSIZE(c) \
+  ((c<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE)
 
 //Takes as input the core number c and the local block index n and
 //returns the global block index
@@ -235,15 +276,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_checkAllCoreStatus()) { \
-        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) \
@@ -260,7 +294,6 @@ INLINE static unsigned int hostcore(void * ptr) {
 
 void initmulticoregcdata();
 void dismulticoregcdata();
-bool gc_checkAllCoreStatus();
 bool gc(struct garbagelist * stackptr); // core coordinator routine
 void gc_collect(struct garbagelist* stackptr); //core collector routine
 void gc_nocollect(struct garbagelist* stackptr); //non-gc core collector routine
@@ -273,7 +306,7 @@ void gc_master(struct garbagelist * stackptr);
 
 
 void transferMarkResults_I();
-void * gcfindSpareMem_I(unsigned int requiredmem,unsigned int requiredcore);
+void * gcfindSpareMem_I(unsigned INTPTR requiredmem, unsigned INTPTR maxbytesneeded, unsigned int requiredcore);
 
 #define INITMULTICOREGCDATA() initmulticoregcdata()
 #define DISMULTICOREGCDATA() dismulticoregcdata()