1665df4f5e8807b27cf760a34950ed13b4f1fb7e
[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 void cacheadapt_finish_compact(void *toptr);
44 void cacheadapt_finish_src_page(void *srcptr, void *tostart, void *tofinish);
45 void cacheadapt_finish_dst_page(void *origptr, void *tostart, void *toptr, unsigned int bytesneeded);
46 void cacheAdapt_gc(bool isgccachestage);
47 void cacheAdapt_master();
48 void cacheAdapt_mutator();
49 void cacheAdapt_phase_client();
50 void cacheAdapt_phase_master();
51 void gc_output_cache_sampling();
52 void gc_output_cache_sampling_r();
53
54 #ifdef GC_CACHE_SAMPLING
55 // enable the timer interrupt
56 #define CACHEADAPT_ENABLE_TIMER() \
57   { \
58     bamboo_tile_timer_set_next_event(GC_TILE_TIMER_EVENT_SETTING); \
59     bamboo_unmask_timer_intr(); \
60     bamboo_dtlb_sampling_process(); \
61   }
62 #else
63 #define CACHEADAPT_ENABLE_TIMER() 
64 #endif
65 // disable the TILE_TIMER interrupt
66 #define CACHEADAPT_DISABLE_TIMER() bamboo_mask_timer_intr() 
67
68 #ifdef GC_CACHE_SAMPLING
69 // reset the sampling arrays
70 #define CACHEADAPT_SAMPLING_RESET()  bamboo_dtlb_sampling_reset()
71 #else // GC_CACHE_SAMPING
72 #define CACHEADAPT_SAMPLING_RESET() 
73 #endif
74
75 #define CACHEADAPT_FINISH_SRC_PAGE(a,b,c) cacheadapt_finish_src_page(a,b,c);
76 #define CACHEADAPT_FINISH_DST_PAGE(a,b,c,d) cacheadapt_finish_dst_page(a,b,c,d);
77 #define CACHEADAPT_FINISH_COMPACT(a) cacheadapt_finish_compact(a);
78
79 #define CACHEADAPT_GC(b) cacheAdapt_gc(b)
80 #define CACHEADAPT_MASTER() cacheAdapt_master()
81 #define CACHEADAPT_PHASE_CLIENT() cacheAdapt_phase_client()
82 #define CACHEADAPT_PHASE_MASTER() cacheAdapt_phase_master()
83
84 #ifdef GC_CACHE_ADAPT_OUTPUT
85 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING() gc_output_cache_sampling()
86 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() gc_output_cache_sampling_r()
87 #else
88 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
89 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() 
90 #endif
91
92 #ifdef GC_CACHE_ADAPT_OUTPUT_POLICY
93 #ifdef MGC_SPEC
94 #define CACHEADAPT_OUTPUT_CACHE_POLICY() \
95   { \
96     if(gc_profile_flag) { \
97       bamboo_output_cache_policy(); \
98     } \
99   }
100 #else // MGC_SPEC
101 #define CACHEADAPT_OUTPUT_CACHE_POLICY() bamboo_output_cache_policy()
102 #endif // MGC_SPEC
103 #else // GC_CACHE_ADAPT_OUTPUT_POLICY
104 #define CACHEADAPT_OUTPUT_CACHE_POLICY() 
105 #endif // GC_CACHE_ADAPT_OUTPUT
106
107 #else // GC_CACHE_ADAPT
108 #define CACHEADAPT_ENABLE_TIMER() 
109 #define CACHEADAPT_DISABLE_TIMER() 
110 #define CACHEADAPT_SAMPING_RESET()
111 #define CACHEADAPT_FINISH_SRC_PAGE(a,b,c)
112 #define CACHEADAPT_FINISH_DST_PAGE(a,b,c,d)
113 #define CACHEADAPT_FINISH_COMPACT(a)
114 #define CACHEADAPT_GC(b)
115 #define CACHEADAPT_MASTER()
116 #define CACHEADAPT_PHASE_CLIENT() 
117 #define CACHEADAPT_PHASE_MASTER() 
118 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
119 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() 
120 #define CACHEADAPT_OUTPUT_CACHE_POLICY() 
121 #endif // GC_CACHE_ADAPT
122 #else // MULTICORE_GC
123 #define CACHEADAPT_ENABLE_TIMER() 
124 #define CACHEADAPT_DISABLE_TIMER()
125 #endif // MULTICORE_GC
126
127 #endif // BAMBOO_MULTICORE_CACHE_H