Parallelize the cache adpation
[IRC.git] / Robust / src / Runtime / bamboo / multicoremem.h
index c6974bd1b6a525597740f44db57063fcb4d50400..83cb5a6f41aa67b4186e92671c2f7a68bd0842b5 100644 (file)
@@ -1,28 +1,35 @@
-#ifndef MULTICORE_MEM_H
-#define MULTICORE_MEM_H
+#ifndef BAMBOO_MULTICORE_MEM_H
+#define BAMBOO_MULTICORE_MEM_H
+#include "multicore.h"
 #include "Queue.h"
 #include "SimpleHash.h"
 
-#ifndef bool
-#define bool int
-#define true 1
-#define false 0
-#endif
-
 // data structures for shared memory allocation
 #ifdef TILERA_BME
-#define BAMBOO_BASE_VA 0x600000  //0xd000000
+#ifdef MGC
+#define BAMBOO_BASE_VA 0x600000  
+#else 
+#define BAMBOO_BASE_VA 0xd000000
+#endif
 #elif defined TILERA_ZLINUX
 #ifdef MULTICORE_GC
-#define BAMBOO_BASE_VA 0x1000000 //0xd000000
+#ifdef MGC
+#define BAMBOO_BASE_VA 0x600000 
+#else 
+#define BAMBOO_BASE_VA 0xd000000
+#endif
 #endif // MULTICORE_GC
 #endif // TILERA_BME
 
 #ifdef BAMBOO_MEMPROF
 #define GC_BAMBOO_NUMCORES 56
 #else
+#ifdef MGC
+#define GC_BAMBOO_NUMCORES (NUMCORES)
+#else
 #define GC_BAMBOO_NUMCORES 62
 #endif
+#endif
 
 #ifdef GC_DEBUG
 #include "structdefs.h"
@@ -34,6 +41,8 @@
 #elif defined GC_CACHE_ADAPT
 #ifdef GC_LARGESHAREDHEAP
 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+24)))
+#elif defined MGC
+#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(72))) // 72M per core
 #else
 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+14)))
 #endif
 #elif defined GC_SMALLPAGESIZE
 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
 #elif defined GC_SMALLPAGESIZE2
-#define BAMBOO_PAGE_SIZE ((unsigned int)(16 * 1024))  // (4096)
+//#define BAMBOO_PAGE_SIZE ((unsigned int)(16 * 1024))  // (4096)
 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
 #elif defined GC_LARGEPAGESIZE2
 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 64 * 1024)) // 64K
 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
+#elif defined MGC
+#define BAMBOO_SMEM_SIZE ((unsigned int)(16*(BAMBOO_PAGE_SIZE)))  // 1M
 #else
 #define BAMBOO_SMEM_SIZE ((unsigned int)(4 * (BAMBOO_PAGE_SIZE)))
 #endif // GC_LARGEPAGESIZE
 
 #else // GC_DEBUG
 #ifdef GC_LARGESHAREDHEAP
-#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2)))
-#elif defined GC_LARGESHAREDHEAP2
-#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2)))
+#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+5)))
+#elif defined MGC
+#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*72)) // 72M per core
 #else
-#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+57/*3*/))) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5)  3G
+#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2))) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5)  3G
 #endif
 #ifdef GC_LARGEPAGESIZE
 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 1024 * 1024))  // (4096)
@@ -69,7 +80,7 @@
 #define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024))  // (4096)
 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
 #elif defined GC_SMALLPAGESIZE2
-#define BAMBOO_PAGE_SIZE ((unsigned int)(64 * 1024))  // (4096)
+#define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024))  // (4096) 64
 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
 #else
 #define BAMBOO_PAGE_SIZE ((unsigned int)(1024 * 1024))  // (4096)
 #endif // GC_DEBUG
 
 #ifdef MULTICORE_GC
-#include "multicoregarbage.h"
+#ifdef GC_SMALLPAGESIZE
+// memory for globals
+#define BAMBOO_GLOBAL_DEFS_SIZE (1024 * 1024)
+#define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (1024 * 512)
+// memory for thread queue
+#define BAMBOO_THREAD_QUEUE_SIZE (1024 * 1024)
+#else
+// memory for globals
+#define BAMBOO_GLOBAL_DEFS_SIZE (BAMBOO_SMEM_SIZE)
+#define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (BAMBOO_SMEM_SIZE/2)
+// memory for thread queue
+#define BAMBOO_THREAD_QUEUE_SIZE (BAMBOO_SMEM_SIZE) // (45 * 16 * 1024)
+#endif // GC_SMALLPAGESIZE
+
+volatile bool gc_localheap_s;
 
 typedef enum {
   SMEMLOCAL = 0x0,// 0x0, using local mem only
@@ -107,10 +132,23 @@ struct freeMemList {
                                    // only maintain 1 freemMemItem
 };
 
+// Zero out the remaining bamboo_cur_msp. Only zero out the first 4 bytes 
+// of the remaining memory
+#define BAMBOO_CLOSE_CUR_MSP() \
+  { \
+    if((bamboo_cur_msp!=0)&&(bamboo_smem_zero_top==bamboo_cur_msp) \
+        &&(bamboo_smem_size>0)) { \
+      *((int *)bamboo_cur_msp) = 0; \
+    } \
+  }
+
 // table recording the number of allocated bytes on each block
 // Note: this table resides on the bottom of the shared heap for all cores
 //       to access
 volatile unsigned int * bamboo_smemtbl;
+#ifdef GC_TBL_DEBUG
+// the length of the bamboo_smemtbl is gcnumblock
+#endif
 volatile unsigned int bamboo_free_block;
 unsigned int bamboo_reserved_smem; // reserved blocks on the top of the shared 
                                    // heap e.g. 20% of the heap and should not 
@@ -126,4 +164,4 @@ volatile bool smemflag;
 volatile unsigned int bamboo_cur_msp;
 volatile int bamboo_smem_size;
 
-#endif
+#endif // BAMBOO_MULTICORE_MEM_H