c3e42b7feafb754bc28fd85c2c9b0cf48dc06c6e
[IRC.git] / Robust / src / Runtime / bamboo / multicorecache.h
1 #ifndef BAMBOO_MULTICORE_CACHE_H
2 #define BAMBOO_MULTICORE_CACHE_H
3 #ifdef MULTICORE_GC
4 #include "multicore.h"
5 #include "multicoremem.h"
6 #include "multicoregccompact.h"
7 #include "multicoregarbage.h"
8
9 #ifdef GC_CACHE_ADAPT
10 // sampling unit to compute access frequency, this should be consistent all the
11 // time.
12 #define GC_CACHE_SAMPLING_UNIT 0x1000000 
13 // freqeuency to trigger timer interrupt
14 #define GC_TILE_TIMER_EVENT_SETTING 10000000  
15
16 // data structure to record policy information for a page
17 // should be consistent with multicoreruntime.h
18 typedef union
19 {
20   unsigned int word;
21   struct
22   {
23     // policy type, should be enough to accommodate all 4 possible polices
24     unsigned int cache_mode   : 3;
25     // Reserved.
26     unsigned int __reserved_0 : 5;
27     // Location Override Target Y
28     unsigned int lotar_y      : 4;
29     // Reserved.
30     unsigned int __reserved_1 : 4;
31     // Location Override Target X
32     unsigned int lotar_x      : 4;
33     // Reserved.
34     unsigned int __reserved_2 : 12;
35   };
36 } bamboo_cache_policy_t;
37
38 #define BAMBOO_CACHE_MODE_LOCAL 1  // locally cached
39 #define BAMBOO_CACHE_MODE_HASH 2   // hash-for-home
40 #define BAMBOO_CACHE_MODE_NONE 3   // no caching
41 #define BAMBOO_CACHE_MODE_COORDS 4 // cached on a specific core
42
43 // data structure to hold page information while calculating revised sampling 
44 // info during compaction
45 typedef struct gc_cache_revise_info {
46   // the start address in current original page to be compacted to current 
47   // destination page
48   void * orig_page_start_va; 
49   // the end of current original page to be compacted
50   void * orig_page_end_va;
51   // the index of current original page
52   unsigned int orig_page_index;
53   // the start address in current destination page to where the current original
54   // page is compacted
55   void * to_page_start_va;
56   // the end of current destination page
57   void * to_page_end_va;
58   // the index of current destination page
59   unsigned int to_page_index;
60 } gc_cache_revise_info_t;
61
62 // global variable holding page information to compute revised sampling info
63 extern gc_cache_revise_info_t gc_cache_revise_information;
64
65 void samplingDataReviseInit(struct moveHelper * orig,struct moveHelper * to);
66 void completePageConvert(void * origptr, void * toptr, void * current_ptr); 
67 void cacheAdapt_gc(bool isgccachestage);
68 void cacheAdapt_master();
69 void cacheAdapt_mutator();
70 void cacheAdapt_phase_client();
71 void cacheAdapt_phase_master();
72 void gc_output_cache_sampling();
73 void gc_output_cache_sampling_r();
74
75 #ifdef GC_CACHE_SAMPLING
76 // enable the timer interrupt
77 #define CACHEADAPT_ENABLE_TIMER() \
78   { \
79     bamboo_tile_timer_set_next_event(GC_TILE_TIMER_EVENT_SETTING); \
80     bamboo_unmask_timer_intr(); \
81     bamboo_dtlb_sampling_process(); \
82   }
83 #else
84 #define CACHEADAPT_ENABLE_TIMER() 
85 #endif
86 // disable the TILE_TIMER interrupt
87 #define CACHEADAPT_DISABLE_TIMER() bamboo_mask_timer_intr() 
88
89 #ifdef GC_CACHE_SAMPLING
90 // reset the sampling arrays
91 #define CACHEADAPT_SAMPLING_RESET()  bamboo_dtlb_sampling_reset()
92 #else // GC_CACHE_SAMPING
93 #define CACHEADAPT_SAMPLING_RESET() 
94 #endif
95
96 #define CACHEADAPT_SAMPLING_DATA_REVISE_INIT(o,t) \
97   samplingDataReviseInit((o),(t))
98 //#define CACHEADAPT_SAMPLING_DATA_CONVERT(p) samplingDataConvert((p))
99 #define CACHEADAPT_COMPLETE_PAGE_CONVERT(o, t, p) \
100   completePageConvert((o), (t), (p));
101
102 #define CACHEADAPT_GC(b) cacheAdapt_gc(b)
103 #define CACHEADAPT_MASTER() cacheAdapt_master()
104 #define CACHEADAPT_PHASE_CLIENT() cacheAdapt_phase_client()
105 #define CACHEADAPT_PHASE_MASTER() cacheAdapt_phase_master()
106
107 #ifdef GC_CACHE_ADAPT_OUTPUT
108 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING() gc_output_cache_sampling()
109 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() gc_output_cache_sampling_r()
110 #else
111 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
112 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() 
113 #endif
114
115 #ifdef GC_CACHE_ADAPT_OUTPUT_POLICY
116 #ifdef MGC_SPEC
117 #define CACHEADAPT_OUTPUT_CACHE_POLICY() \
118   { \
119     if(gc_profile_flag) { \
120       bamboo_output_cache_policy(); \
121     } \
122   }
123 #else // MGC_SPEC
124 #define CACHEADAPT_OUTPUT_CACHE_POLICY() bamboo_output_cache_policy()
125 #endif // MGC_SPEC
126 #else // GC_CACHE_ADAPT_OUTPUT_POLICY
127 #define CACHEADAPT_OUTPUT_CACHE_POLICY() 
128 #endif // GC_CACHE_ADAPT_OUTPUT
129
130 #else // GC_CACHE_ADAPT
131 #define CACHEADAPT_ENABLE_TIMER() 
132 #define CACHEADAPT_DISABLE_TIMER() 
133 #define CACHEADAPT_SAMPING_RESET()
134 #define CACHEADAPT_SAMPLING_DATA_REVISE_INIT(o,t) 
135 #define CACHEADAPT_SAMPLING_DATA_CONVERT(p) 
136 #define CACHEADAPT_COMPLETE_PAGE_CONVERT(o, t, p, b) 
137 #define CACHEADAPT_GC(b)
138 #define CACHEADAPT_MASTER()
139 #define CACHEADAPT_PHASE_CLIENT() 
140 #define CACHEADAPT_PHASE_MASTER() 
141 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
142 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() 
143 #define CACHEADAPT_OUTPUT_CACHE_POLICY() 
144 #endif // GC_CACHE_ADAPT
145 #else // MULTICORE_GC
146 #define CACHEADAPT_ENABLE_TIMER() 
147 #define CACHEADAPT_DISABLE_TIMER()
148 #endif // MULTICORE_GC
149
150 #endif // BAMBOO_MULTICORE_CACHE_H