0b29f7c92f6641967db530b3f7d2028dec180d9d
[IRC.git] / Robust / src / Runtime / bamboo / multicoremem.h
1 #ifndef BABMOO_MULTICORE_MEM_H
2 #define BAMBOO_MULTICORE_MEM_H
3 #include "multicore.h"
4 #include "Queue.h"
5 #include "SimpleHash.h"
6
7 // data structures for shared memory allocation
8 #ifdef TILERA_BME
9 #ifdef MGC
10 #define BAMBOO_BASE_VA 0x600000  
11 #else 
12 #define BAMBOO_BASE_VA 0xd000000
13 #endif
14 #elif defined TILERA_ZLINUX
15 #ifdef MULTICORE_GC
16 #ifdef MGC
17 #define BAMBOO_BASE_VA 0x600000 
18 #else 
19 #define BAMBOO_BASE_VA 0xd000000
20 #endif
21 #endif // MULTICORE_GC
22 #endif // TILERA_BME
23
24 #ifdef BAMBOO_MEMPROF
25 #define GC_BAMBOO_NUMCORES 56
26 #else
27 #ifdef MGC
28 #define GC_BAMBOO_NUMCORES (NUMCORES)
29 #else
30 #define GC_BAMBOO_NUMCORES 62
31 #endif
32 #endif
33
34 #ifdef GC_DEBUG
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)))
40
41 #elif defined GC_CACHE_ADAPT
42 #ifdef GC_LARGESHAREDHEAP
43 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+24)))
44 #elif defined MGC
45 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(72))) // 72M per core
46 #else
47 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+14)))
48 #endif
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))
61 #elif defined MGC
62 #define BAMBOO_SMEM_SIZE ((unsigned int)(16*(BAMBOO_PAGE_SIZE)))  // 1M
63 #else
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)))
67
68 #else // GC_DEBUG
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)))
73 #elif defined MGC
74 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*72)) // 72M per core
75 #else
76 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+3))) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5)  3G
77 #endif
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))
87 #else
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 
92 #endif // GC_DEBUG
93
94 #ifdef MULTICORE_GC
95 #ifdef GC_SMALLPAGESIZE
96 // memory for globals
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)
101 #else
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
108
109 volatile bool gc_localheap_s;
110 #include "multicoregarbage.h"
111
112 typedef enum {
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
118   SMEMEND
119 } SMEMSTRATEGY;
120
121 SMEMSTRATEGY bamboo_smem_mode; //-DSMEML: LOCAL; -DSMEMF: FIXED;
122                                //-DSMEMM: MIXED; -DSMEMG: GLOBAL;
123
124 struct freeMemItem {
125   unsigned int ptr;
126   int size;
127   int startblock;
128   int endblock;
129   struct freeMemItem * next;
130 };
131
132 struct freeMemList {
133   struct freeMemItem * head;
134   struct freeMemItem * backuplist; // hold removed freeMemItem for reuse;
135                                    // only maintain 1 freemMemItem
136 };
137
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() \
141   { \
142     if((bamboo_cur_msp!=0)&&(bamboo_smem_zero_top==bamboo_cur_msp) \
143         &&(bamboo_smem_size>0)) { \
144       *((int *)bamboo_cur_msp) = 0; \
145     } \
146   }
147
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
150 //       to access
151 volatile unsigned int * bamboo_smemtbl;
152 #ifdef GC_TBL_DEBUG
153 // the length of the bamboo_smemtbl is gcnumblock
154 #endif
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
161 #else
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;
169
170 #endif // BAMBOO_MULTICORE_MEM_H