code towards PMC compiling
[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 #ifdef GC_DEBUG
35 #include "structdefs.h"
36 #define BAMBOO_NUM_BLOCKS (NUMCORES4GC*(2+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+5)))
71 #elif defined MGC
72 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*72)) // 72M per core
73 #else
74 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2))) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5)  3G
75 #endif
76 #ifdef GC_LARGEPAGESIZE
77 #define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 1024 * 1024))  // (4096)
78 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
79 #elif defined GC_SMALLPAGESIZE
80 #define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024))  // (4096)
81 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
82 #elif defined GC_SMALLPAGESIZE2
83 #define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024))  // (4096) 64
84 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
85 #else
86 #define BAMBOO_PAGE_SIZE ((unsigned int)(1024 * 1024))  // (4096)
87 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
88 #endif // GC_LARGEPAGESIZE
89 #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 
90 #endif // GC_DEBUG
91
92 #if defined(MULTICORE_GC)||defined(PMC_GC)
93 #if defined(GC_SMALLPAGESIZE)||defined(PMC_GC)
94 // memory for globals
95 #define BAMBOO_GLOBAL_DEFS_SIZE (1024 * 1024)
96 #define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (1024 * 512)
97 // memory for thread queue
98 #define BAMBOO_THREAD_QUEUE_SIZE (1024 * 1024)
99 #else
100 // memory for globals
101 #define BAMBOO_GLOBAL_DEFS_SIZE (BAMBOO_SMEM_SIZE)
102 #define BAMBOO_GLOBAL_DEFS_PRIM_SIZE (BAMBOO_SMEM_SIZE/2)
103 // memory for thread queue
104 #define BAMBOO_THREAD_QUEUE_SIZE (BAMBOO_SMEM_SIZE) // (45 * 16 * 1024)
105 #endif // GC_SMALLPAGESIZE
106
107 //keeps track of the top address that has been zero'd by the allocator
108 volatile void * bamboo_smem_zero_top;
109 volatile unsigned int totalbytestozero;
110
111 //BAMBOO_SMEM_ZERO_UNIT_SIZE must evenly divide the page size and be a
112 //power of two(we rely on both in the allocation function)
113 #define BAMBOO_SMEM_ZERO_UNIT_SIZE 4096
114 #else
115 //This is for memory allocation with no garbage collection
116 unsigned int bamboo_free_smemp;
117 int bamboo_free_smem_size;
118 #endif // MULTICORE_GC
119 //This flag indicates that a memory request was services
120 volatile bool smemflag;
121 //Pointer to new block of memory after request
122 volatile void * bamboo_cur_msp;
123 //Number of bytes in new block of memory
124 volatile unsigned INTPTR bamboo_smem_size;
125
126 void * localmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
127 void * fixedmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
128 void * mixedmalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
129 void * globalmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
130 void * smemalloc(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
131 void * smemalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
132
133
134 #endif // BAMBOO_MULTICORE_MEM_H