changes
[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 0x800000000 
13 // freqeuency to trigger timer interrupt
14 #define GC_TILE_TIMER_EVENT_SETTING 40000000  
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 #if defined(GC_CACHE_SAMPLING)&&(defined(GC_CACHE_ADAPT_POLICY4)||defined(GC_CACHE_ADAPT_POLICY3))
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 // disable the TILE_TIMER interrupt
63 #define CACHEADAPT_DISABLE_TIMER() bamboo_mask_timer_intr() 
64 // reset the sampling arrays
65 #define CACHEADAPT_SAMPLING_RESET()  bamboo_dtlb_sampling_reset()
66 #else // GC_CACHE_SAMPING
67 #define CACHEADAPT_ENABLE_TIMER()
68 #define CACHEADAPT_DISABLE_TIMER()
69 #define CACHEADAPT_SAMPLING_RESET() 
70 #endif
71
72 #if (defined(GC_CACHE_ADAPT_POLICY4)||defined(GC_CACHE_ADAPT_POLICY3))
73 #define CACHEADAPT_FINISH_SRC_PAGE(a,b,c) cacheadapt_finish_src_page(a,b,c);
74 #define CACHEADAPT_FINISH_DST_PAGE(a,b,c,d) cacheadapt_finish_dst_page(a,b,c,d);
75 #define CACHEADAPT_FINISH_COMPACT(a) cacheadapt_finish_compact(a);
76 #else
77 #define CACHEADAPT_FINISH_SRC_PAGE(a,b,c)
78 #define CACHEADAPT_FINISH_DST_PAGE(a,b,c,d)
79 #define CACHEADAPT_FINISH_COMPACT(a)
80 #endif
81
82 #define CACHEADAPT_GC(b) cacheAdapt_gc(b)
83 #define CACHEADAPT_MASTER() cacheAdapt_master()
84 #define CACHEADAPT_PHASE_CLIENT() cacheAdapt_phase_client()
85 #define CACHEADAPT_PHASE_MASTER() cacheAdapt_phase_master()
86
87 #ifdef GC_CACHE_ADAPT_OUTPUT
88 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING() gc_output_cache_sampling()
89 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() gc_output_cache_sampling_r()
90 #else
91 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
92 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() 
93 #endif
94
95 #ifdef GC_CACHE_ADAPT_OUTPUT_POLICY
96 #ifdef MGC_SPEC
97 #define CACHEADAPT_OUTPUT_CACHE_POLICY() \
98   { \
99     if(gc_profile_flag) { \
100       bamboo_output_cache_policy(); \
101     } \
102   }
103 #else // MGC_SPEC
104 #define CACHEADAPT_OUTPUT_CACHE_POLICY() bamboo_output_cache_policy()
105 #endif // MGC_SPEC
106 #else // GC_CACHE_ADAPT_OUTPUT_POLICY
107 #define CACHEADAPT_OUTPUT_CACHE_POLICY() 
108 #endif // GC_CACHE_ADAPT_OUTPUT
109
110 #else // GC_CACHE_ADAPT
111 #define CACHEADAPT_ENABLE_TIMER() 
112 #define CACHEADAPT_DISABLE_TIMER() 
113 #define CACHEADAPT_SAMPING_RESET()
114 #define CACHEADAPT_FINISH_SRC_PAGE(a,b,c)
115 #define CACHEADAPT_FINISH_DST_PAGE(a,b,c,d)
116 #define CACHEADAPT_FINISH_COMPACT(a)
117 #define CACHEADAPT_GC(b)
118 #define CACHEADAPT_MASTER()
119 #define CACHEADAPT_PHASE_CLIENT() 
120 #define CACHEADAPT_PHASE_MASTER() 
121 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
122 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() 
123 #define CACHEADAPT_OUTPUT_CACHE_POLICY() 
124 #endif // GC_CACHE_ADAPT
125 #else // MULTICORE_GC
126 #define CACHEADAPT_ENABLE_TIMER() 
127 #define CACHEADAPT_DISABLE_TIMER()
128 #endif // MULTICORE_GC
129
130 #endif // BAMBOO_MULTICORE_CACHE_H