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