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