towards fixing bugs...
[IRC.git] / Robust / src / Runtime / bamboo / multicoremem.h
1 #ifndef BAMBOO_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 0x1000000  
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 0x1000000 
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 #define BAMBOO_SHARED_RUNTIME_PAGE_SIZE ((unsigned int)(1<<24))  //16M
35
36 #define BAMBOO_PAGE_SIZE ((unsigned int)(64 * 1024)) // 64K
37 #define BAMBOO_PAGE_SIZE_BITS (16)
38 #ifdef GC_LARGEPAGESIZE
39 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 64 * 1024))
40 #define BAMBOO_PAGE_SIZE_BITS (18)
41 #elif defined GC_LARGEPAGESIZE2
42 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 64 * 1024)) // 64K
43 #define BAMBOO_PAGE_SIZE_BITS (18)
44 #endif
45
46 #ifdef GC_DEBUG
47 #include "structdefs.h"
48 #define BAMBOO_NUM_BLOCKS (NUMCORES4GC*(2+3))
49 #define BAMBOO_PAGE_SIZE (64 * 64)
50 #define BAMBOO_PAGE_SIZE_BITS (12)
51 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
52 #define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) *(BAMBOO_NUM_BLOCKS)))
53
54 #elif defined GC_CACHE_ADAPT
55 #ifdef GC_LARGESHAREDHEAP
56 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+24)))
57 #elif defined MGC
58 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*72)) // 72M per core
59 #else
60 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+14)))
61 #endif
62 #ifdef GC_LARGEPAGESIZE
63 #define BAMBOO_SMEM_SIZE ((unsigned int)(4 * (BAMBOO_PAGE_SIZE)))
64 #elif defined GC_SMALLPAGESIZE
65 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
66 #elif defined GC_SMALLPAGESIZE2
67 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
68 #elif defined GC_LARGEPAGESIZE2
69 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
70 #elif defined MGC
71 #define BAMBOO_SMEM_SIZE ((unsigned int)(16*(BAMBOO_PAGE_SIZE)))  // 1M
72 #else
73 #define BAMBOO_SMEM_SIZE ((unsigned int)(4 * (BAMBOO_PAGE_SIZE)))
74 #endif // GC_LARGEPAGESIZE
75 #define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS)))
76
77 #else // GC_DEBUG
78 #ifdef GC_LARGESHAREDHEAP
79 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+5)))
80 #elif defined MGC
81 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*72)) // 72M per core
82 #else
83 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2))) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5)  3G
84 #endif
85 #ifdef GC_LARGEPAGESIZE
86 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE*16))
87 #elif defined GC_SMALLPAGESIZE
88 #define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024))  // (4096)
89 #define BAMBOO_PAGE_SIZE_BITS (18)
90 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
91 #elif defined GC_SMALLPAGESIZE2
92 #define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024))  // (4096) 64
93 #define BAMBOO_PAGE_SIZE_BITS (18)
94 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
95 #else
96 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE*16))
97 #endif // GC_LARGEPAGESIZE
98 #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 
99 #endif // GC_DEBUG
100
101 #if defined(MULTICORE_GC)||defined(PMC_GC)
102 #if defined(GC_SMALLPAGESIZE)||defined(PMC_GC)
103 // memory for globals
104 #define BAMBOO_GLOBAL_DEFS_SIZE (1024 * 1024)
105 #define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (1024 * 512)
106 // memory for thread queue
107 #define BAMBOO_THREAD_QUEUE_SIZE (1024 * 1024)
108 #else
109 // memory for globals
110 #define BAMBOO_GLOBAL_DEFS_SIZE (BAMBOO_SMEM_SIZE)
111 #define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (BAMBOO_SMEM_SIZE/2)
112 // memory for thread queue
113 #define BAMBOO_THREAD_QUEUE_SIZE (BAMBOO_SMEM_SIZE) // (45 * 16 * 1024)
114 #endif // GC_SMALLPAGESIZE
115
116 //keeps track of the top address that has been zero'd by the allocator
117 volatile void * bamboo_smem_zero_top;
118 volatile unsigned int totalbytestozero;
119
120 //BAMBOO_SMEM_ZERO_UNIT_SIZE must evenly divide the page size and be a
121 //power of two(we rely on both in the allocation function)
122 #define BAMBOO_SMEM_ZERO_UNIT_SIZE 4096
123 #else
124 //This is for memory allocation with no garbage collection
125 unsigned int bamboo_free_smemp;
126 int bamboo_free_smem_size;
127 #endif // MULTICORE_GC
128 //This flag indicates that a memory request was services
129 volatile bool smemflag;
130 //Pointer to new block of memory after request
131 volatile void * bamboo_cur_msp;
132 //Number of bytes in new block of memory
133 volatile unsigned INTPTR bamboo_smem_size;
134
135 void * localmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
136 void * fixedmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
137 void * mixedmalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
138 void * globalmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
139 void * smemalloc(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
140 void * smemalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
141
142
143 #endif // BAMBOO_MULTICORE_MEM_H