Add the runtime for multicore gc version w/o tasks. Now can start multiple threads...
[IRC.git] / Robust / src / Runtime / bamboo / multicoremem.h
1 #ifndef MULTICORE_MEM_H
2 #define MULTICORE_MEM_H
3 #include "Queue.h"
4 #include "SimpleHash.h"
5
6 #ifndef INTPTR
7 #ifdef BIT64
8 #define INTPTR long
9 #define INTPTRSHIFT 3
10 #else
11 #define INTPTR int
12 #define INTPTRSHIFT 2
13 #endif
14 #endif
15
16 #ifndef bool
17 #define bool int
18 #define true 1
19 #define false 0
20 #endif
21
22 // data structures for shared memory allocation
23 #ifdef TILERA_BME
24 #define BAMBOO_BASE_VA 0xd000000
25 #elif defined TILERA_ZLINUX
26 #ifdef MULTICORE_GC
27 #define BAMBOO_BASE_VA 0xd000000
28 #endif // MULTICORE_GC
29 #endif // TILERA_BME
30
31 #ifdef BAMBOO_MEMPROF
32 #define GC_BAMBOO_NUMCORES 56
33 #else
34 #define GC_BAMBOO_NUMCORES 62
35 #endif
36
37 #ifdef GC_DEBUG
38 #include "structdefs.h"
39 #define BAMBOO_NUM_BLOCKS (NUMCORES4GC*(2+1)+3)
40 #define BAMBOO_PAGE_SIZE (64 * 64)
41 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
42 #define BAMBOO_SHARED_MEM_SIZE ((BAMBOO_SMEM_SIZE) *(BAMBOO_NUM_BLOCKS))
43
44 #elif defined GC_CACHE_ADAPT
45 #ifdef GC_LARGESHAREDHEAP
46 #define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+24))
47 #else
48 #define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+14))
49 #endif
50 #define BAMBOO_PAGE_SIZE (64 * 1024) // 64K
51 #ifdef GC_LARGEPAGESIZE
52 #define BAMBOO_PAGE_SIZE (4 * 64 * 1024)
53 #define BAMBOO_SMEM_SIZE (4 * (BAMBOO_PAGE_SIZE))
54 #elif defined GC_SMALLPAGESIZE
55 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
56 #elif defined GC_SMALLPAGESIZE2
57 #define BAMBOO_PAGE_SIZE (16 * 1024)  // (4096)
58 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
59 #elif defined GC_LARGEPAGESIZE2
60 #define BAMBOO_PAGE_SIZE (4 * 64 * 1024) // 64K
61 #define BAMBOO_SMEM_SIZE ((BAMBOO_PAGE_SIZE))
62 #else
63 #define BAMBOO_SMEM_SIZE (4 * (BAMBOO_PAGE_SIZE))
64 #endif // GC_LARGEPAGESIZE
65 #define BAMBOO_SHARED_MEM_SIZE ((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS))
66
67 #else // GC_DEBUG
68 #ifdef GC_LARGESHAREDHEAP
69 #define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+2))
70 #elif defined GC_LARGESHAREDHEAP2
71 #define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+2))
72 #else
73 #define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+3)) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5)  3G
74 #endif
75 #ifdef GC_LARGEPAGESIZE
76 #define BAMBOO_PAGE_SIZE (4 * 1024 * 1024)  // (4096)
77 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
78 #elif defined GC_SMALLPAGESIZE
79 #define BAMBOO_PAGE_SIZE (256 * 1024)  // (4096)
80 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
81 #elif defined GC_SMALLPAGESIZE2
82 #define BAMBOO_PAGE_SIZE (64 * 1024)  // (4096)
83 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
84 #else
85 #define BAMBOO_PAGE_SIZE (1024 * 1024)  // (4096)
86 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
87 #endif // GC_LARGEPAGESIZE
88 #define BAMBOO_SHARED_MEM_SIZE ((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS)) //(1024 * 1024 * 240) //((unsigned long long int)(3.0 * 1024 * 1024 * 1024)) // 3G 
89 #endif // GC_DEBUG
90
91 #ifdef MULTICORE_GC
92 volatile bool gc_localheap_s;
93 #include "multicoregarbage.h"
94
95 typedef enum {
96   SMEMLOCAL = 0x0,// 0x0, using local mem only
97   SMEMFIXED,      // 0x1, use local mem in lower address space(1 block only)
98                   //      and global mem in higher address space
99   SMEMMIXED,      // 0x2, like FIXED mode but use a threshold to control
100   SMEMGLOBAL,     // 0x3, using global mem only
101   SMEMEND
102 } SMEMSTRATEGY;
103
104 SMEMSTRATEGY bamboo_smem_mode; //-DSMEML: LOCAL; -DSMEMF: FIXED;
105                                //-DSMEMM: MIXED; -DSMEMG: GLOBAL;
106
107 struct freeMemItem {
108   INTPTR ptr;
109   int size;
110   int startblock;
111   int endblock;
112   struct freeMemItem * next;
113 };
114
115 struct freeMemList {
116   struct freeMemItem * head;
117   struct freeMemItem * backuplist; // hold removed freeMemItem for reuse;
118                                    // only maintain 1 freemMemItem
119 };
120
121 // table recording the number of allocated bytes on each block
122 // Note: this table resides on the bottom of the shared heap for all cores
123 //       to access
124 volatile int * bamboo_smemtbl;
125 volatile int bamboo_free_block;
126 unsigned int bamboo_reserved_smem; // reserved blocks on the top of the shared 
127                                    // heap e.g. 20% of the heap and should not 
128                                                                    // be allocated otherwise gc is invoked
129 volatile INTPTR bamboo_smem_zero_top;
130 #define BAMBOO_SMEM_ZERO_UNIT_SIZE (4 * 1024) // 4KB
131 #else
132 //volatile mspace bamboo_free_msp;
133 INTPTR bamboo_free_smemp;
134 int bamboo_free_smem_size;
135 #endif // MULTICORE_GC
136 volatile bool smemflag;
137 volatile INTPTR bamboo_cur_msp;
138 volatile int bamboo_smem_size;
139
140 #endif