1 #ifndef BAMBOO_MULTICORE_CACHE_H
2 #define BAMBOO_MULTICORE_CACHE_H
5 #include "multicoremem.h"
6 #include "multicoregccompact.h"
7 #include "multicoregarbage.h"
10 #define GC_CACHE_SAMPLING_UNIT 100000000
11 #define GC_TILE_TIMER_EVENT_SETTING 10000000 //0
13 // should be consistent with multicoreruntime.h
20 unsigned int cache_mode : 2;
22 unsigned int __reserved_0 : 6;
23 // Location Override Target Y
24 unsigned int lotar_y : 4;
26 unsigned int __reserved_1 : 4;
27 // Location Override Target X
28 unsigned int lotar_x : 4;
30 unsigned int __reserved_2 : 12;
32 } bamboo_cache_policy_t;
34 #define BAMBOO_CACHE_MODE_LOCAL 0
35 #define BAMBOO_CACHE_MODE_HASH 1
36 #define BAMBOO_CACHE_MODE_NONE 2
37 #define BAMBOO_CACHE_MODE_COORDS 3
39 typedef struct gc_cache_revise_info {
40 unsigned int orig_page_start_va;
41 unsigned int orig_page_end_va;
42 unsigned int orig_page_index;
43 unsigned int to_page_start_va;
44 unsigned int to_page_end_va;
45 unsigned int to_page_index;
46 unsigned int revised_sampling[NUMCORESACTIVE];
47 } gc_cache_revise_info_t;
49 extern gc_cache_revise_info_t gc_cache_revise_information;
51 INLINE static void samplingDataReviseInit(struct moveHelper * orig,struct moveHelper * to) {
52 gc_cache_revise_information.to_page_start_va=(unsigned int)to->ptr;
53 unsigned int toindex=(unsigned int)(to->base-gcbaseva)/(BAMBOO_PAGE_SIZE);
54 gc_cache_revise_information.to_page_end_va=gcbaseva+(BAMBOO_PAGE_SIZE)*(toindex+1);
55 gc_cache_revise_information.to_page_index=toindex;
56 gc_cache_revise_information.orig_page_start_va=(unsigned int)orig->ptr;
57 gc_cache_revise_information.orig_page_end_va=gcbaseva+(BAMBOO_PAGE_SIZE)*(((unsigned int)(orig->ptr)-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
58 gc_cache_revise_information.orig_page_index=((unsigned int)(orig->blockbase)-gcbaseva)/(BAMBOO_PAGE_SIZE);
61 INLINE static void samplingDataConvert(unsigned int current_ptr) {
62 unsigned int tmp_factor=current_ptr-gc_cache_revise_information.to_page_start_va;
63 unsigned int topage=gc_cache_revise_information.to_page_index;
64 unsigned int oldpage=gc_cache_revise_information.orig_page_index;
65 int * newtable=&gccachesamplingtbl_r[topage];
66 int * oldtable=&gccachesamplingtbl[oldpage];
68 for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
69 (*newtable)=((*newtable)+(*oldtable)*tmp_factor);
70 newtable=(int*)(((char *)newtable)+size_cachesamplingtbl_local_r);
71 oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
75 INLINE static void completePageConvert(struct moveHelper * orig,struct moveHelper * to,unsigned int current_ptr,bool closeToPage) {
77 unsigned int tocompare=0;
80 tocompare=gc_cache_revise_information.to_page_end_va;
83 tocompare=gc_cache_revise_information.orig_page_end_va;
85 if((unsigned int)ptr>=(unsigned int)tocompare) {
86 // end of an orig/to page
87 // compute the impact of this page for the new page
88 samplingDataConvert(current_ptr);
89 // prepare for an new orig page
90 unsigned int tmp_index=(unsigned int)((unsigned int)orig->ptr-gcbaseva)/(BAMBOO_PAGE_SIZE);
91 gc_cache_revise_information.orig_page_start_va=orig->ptr;
92 gc_cache_revise_information.orig_page_end_va=gcbaseva+(BAMBOO_PAGE_SIZE)*(unsigned int)(tmp_index+1);
93 gc_cache_revise_information.orig_page_index=tmp_index;
94 gc_cache_revise_information.to_page_start_va=to->ptr;
96 gc_cache_revise_information.to_page_end_va=gcbaseva+(BAMBOO_PAGE_SIZE)*(((unsigned int)(to->ptr)-gcbaseva)/(BAMBOO_PAGE_SIZE)+1);
97 gc_cache_revise_information.to_page_index=((unsigned int)(to->ptr)-gcbaseva)/(BAMBOO_PAGE_SIZE);
102 void cacheAdapt_gc(bool isgccachestage);
103 void cacheAdapt_master();
104 void cacheAdapt_mutator();
105 void cacheAdapt_phase_client();
106 void cacheAdapt_phase_master();
107 void gc_output_cache_sampling();
108 void gc_output_cache_sampling_r();
110 #ifdef GC_CACHE_SAMPLING
111 // enable the timer interrupt
112 #define CACHEADAPT_ENABLE_TIMER() \
114 bamboo_tile_timer_set_next_event(GC_TILE_TIMER_EVENT_SETTING); \
115 bamboo_unmask_timer_intr(); \
116 bamboo_dtlb_sampling_process(); \
119 #define CACHEADAPT_ENABLE_TIMER()
121 // disable the TILE_TIMER interrupt
122 #define CACHEADAPT_DISABLE_TIMER() bamboo_mask_timer_intr()
124 #ifdef GC_CACHE_SAMPLING
125 // reset the sampling arrays
126 #define CACHEADAPT_SAMPING_RESET() bamboo_dtlb_sampling_reset()
127 #else // GC_CACHE_SAMPING
128 #define CACHEADAPT_SAMPING_RESET()
131 #define CACHEADAPT_SAMPLING_DATA_REVISE_INIT(o,t) \
132 samplingDataReviseInit((o),(t))
133 #define CACHEADAPT_SAMPLING_DATA_CONVERT(p) samplingDataConvert((p))
134 #define CACHEADAPT_COMPLETE_PAGE_CONVERT(o, t, p, b) \
135 completePageConvert((o), (t), (p), (b));
137 #define CACHEADAPT_GC(b) cacheAdapt_gc(b)
138 #define CACHEADAPT_MASTER() cacheAdapt_master()
139 #define CACHEADAPT_PHASE_CLIENT() cacheAdapt_phase_client()
140 #define CACHEADAPT_PHASE_MASTER() cacheAdapt_phase_master()
142 #ifdef GC_CACHE_ADAPT_OUTPUT
143 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING() gc_output_cache_sampling()
144 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R() gc_output_cache_sampling_r()
146 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
147 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R()
150 #ifdef GC_CACHE_ADAPT_OUTPUT_POLICY
152 #define CACHEADAPT_OUTPUT_CACHE_POLICY() \
154 if(gc_profile_flag) { \
155 bamboo_output_cache_policy(); \
159 #define CACHEADAPT_OUTPUT_CACHE_POLICY() bamboo_output_cache_policy()
161 #else // GC_CACHE_ADAPT_OUTPUT_POLICY
162 #define CACHEADAPT_OUTPUT_CACHE_POLICY()
163 #endif // GC_CACHE_ADAPT_OUTPUT
165 #else // GC_CACHE_ADAPT
166 #define CACHEADAPT_ENABLE_TIMER()
167 #define CACHEADAPT_DISABLE_TIMER()
168 #define CACHEADAPT_SAMPING_RESET()
169 #define CACHEADAPT_SAMPLING_DATA_REVISE_INIT(o,t)
170 #define CACHEADAPT_SAMPLING_DATA_CONVERT(p)
171 #define CACHEADAPT_COMPLETE_PAGE_CONVERT(o, t, p, b)
172 #define CACHEADAPT_GC(b)
173 #define CACHEADAPT_MASTER()
174 #define CACHEADAPT_PHASE_CLIENT()
175 #define CACHEADAPT_PHASE_MASTER()
176 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING()
177 #define CACHEADAPT_OUTPUT_CACHE_SAMPLING_R()
178 #define CACHEADAPT_OUTPUT_CACHE_POLICY()
179 #endif // GC_CACHE_ADAPT
180 #else // MULTICORE_GC
181 #define CACHEADAPT_ENABLE_TIMER()
182 #define CACHEADAPT_DISABLE_TIMER()
183 #endif // MULTICORE_GC
185 #endif // BAMBOO_MULTICORE_CACHE_H