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