1 #ifndef BABMOO_MULTICORE_MEM_H
2 #define BAMBOO_MULTICORE_MEM_H
5 #include "SimpleHash.h"
7 // data structures for shared memory allocation
10 #define BAMBOO_BASE_VA 0x600000
12 #define BAMBOO_BASE_VA 0xd000000
14 #elif defined TILERA_ZLINUX
17 #define BAMBOO_BASE_VA 0x600000
19 #define BAMBOO_BASE_VA 0xd000000
21 #endif // MULTICORE_GC
25 #define GC_BAMBOO_NUMCORES 56
28 #define GC_BAMBOO_NUMCORES (NUMCORES)
30 #define GC_BAMBOO_NUMCORES 62
35 #include "structdefs.h"
36 #define BAMBOO_NUM_BLOCKS (NUMCORES4GC*(2+1)+3)
37 #define BAMBOO_PAGE_SIZE (64 * 64)
38 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
39 #define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) *(BAMBOO_NUM_BLOCKS)))
41 #elif defined GC_CACHE_ADAPT
42 #ifdef GC_LARGESHAREDHEAP
43 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+24)))
45 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(72))) // 72M per core
47 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+14)))
49 #define BAMBOO_PAGE_SIZE ((unsigned int)(64 * 1024)) // 64K
50 #ifdef GC_LARGEPAGESIZE
51 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 64 * 1024))
52 #define BAMBOO_SMEM_SIZE ((unsigned int)(4 * (BAMBOO_PAGE_SIZE)))
53 #elif defined GC_SMALLPAGESIZE
54 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
55 #elif defined GC_SMALLPAGESIZE2
56 #define BAMBOO_PAGE_SIZE ((unsigned int)(16 * 1024)) // (4096)
57 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
58 #elif defined GC_LARGEPAGESIZE2
59 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 64 * 1024)) // 64K
60 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
62 #define BAMBOO_SMEM_SIZE ((unsigned int)(16*(BAMBOO_PAGE_SIZE))) // 1M
64 #define BAMBOO_SMEM_SIZE ((unsigned int)(4 * (BAMBOO_PAGE_SIZE)))
65 #endif // GC_LARGEPAGESIZE
66 #define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS)))
69 #ifdef GC_LARGESHAREDHEAP
70 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2)))
71 #elif defined GC_LARGESHAREDHEAP2
72 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2)))
74 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*72)) // 72M per core
76 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+3))) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5) 3G
78 #ifdef GC_LARGEPAGESIZE
79 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 1024 * 1024)) // (4096)
80 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
81 #elif defined GC_SMALLPAGESIZE
82 #define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024)) // (4096)
83 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
84 #elif defined GC_SMALLPAGESIZE2
85 #define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024)) // (4096) 64
86 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
88 #define BAMBOO_PAGE_SIZE ((unsigned int)(1024 * 1024)) // (4096)
89 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
90 #endif // GC_LARGEPAGESIZE
91 #define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS))) //(1024 * 1024 * 240) //((unsigned long long int)(3.0 * 1024 * 1024 * 1024)) // 3G
95 #ifdef GC_SMALLPAGESIZE
97 #define BAMBOO_GLOBAL_DEFS_SIZE (1024 * 1024)
98 #define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (1024 * 512)
99 // memory for thread queue
100 #define BAMBOO_THREAD_QUEUE_SIZE (1024 * 1024)
102 // memory for globals
103 #define BAMBOO_GLOBAL_DEFS_SIZE (BAMBOO_SMEM_SIZE)
104 #define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (BAMBOO_SMEM_SIZE/2)
105 // memory for thread queue
106 #define BAMBOO_THREAD_QUEUE_SIZE (BAMBOO_SMEM_SIZE) // (45 * 16 * 1024)
107 #endif // GC_SMALLPAGESIZE
109 volatile bool gc_localheap_s;
110 #include "multicoregarbage.h"
113 SMEMLOCAL = 0x0,// 0x0, using local mem only
114 SMEMFIXED, // 0x1, use local mem in lower address space(1 block only)
115 // and global mem in higher address space
116 SMEMMIXED, // 0x2, like FIXED mode but use a threshold to control
117 SMEMGLOBAL, // 0x3, using global mem only
121 SMEMSTRATEGY bamboo_smem_mode; //-DSMEML: LOCAL; -DSMEMF: FIXED;
122 //-DSMEMM: MIXED; -DSMEMG: GLOBAL;
129 struct freeMemItem * next;
133 struct freeMemItem * head;
134 struct freeMemItem * backuplist; // hold removed freeMemItem for reuse;
135 // only maintain 1 freemMemItem
138 // Zero out the remaining bamboo_cur_msp. Only zero out the first 4 bytes
139 // of the remaining memory
140 #define BAMBOO_CLOSE_CUR_MSP() \
142 if((bamboo_cur_msp!=0)&&(bamboo_smem_zero_top==bamboo_cur_msp) \
143 &&(bamboo_smem_size>0)) { \
144 *((int *)bamboo_cur_msp) = 0; \
148 // table recording the number of allocated bytes on each block
149 // Note: this table resides on the bottom of the shared heap for all cores
151 volatile unsigned int * bamboo_smemtbl;
153 // the length of the bamboo_smemtbl is gcnumblock
155 volatile unsigned int bamboo_free_block;
156 unsigned int bamboo_reserved_smem; // reserved blocks on the top of the shared
157 // heap e.g. 20% of the heap and should not
158 // be allocated otherwise gc is invoked
159 volatile unsigned int bamboo_smem_zero_top;
160 #define BAMBOO_SMEM_ZERO_UNIT_SIZE ((unsigned int)(4 * 1024)) // 4KB
162 //volatile mspace bamboo_free_msp;
163 unsigned int bamboo_free_smemp;
164 int bamboo_free_smem_size;
165 #endif // MULTICORE_GC
166 volatile bool smemflag;
167 volatile unsigned int bamboo_cur_msp;
168 volatile int bamboo_smem_size;
170 #endif // BAMBOO_MULTICORE_MEM_H