Code clean
[IRC.git] / Robust / src / Runtime / bamboo / multicoregcprofile.h
1 #ifndef BAMBOO_MULTICORE_GC_PROFILE_H
2 #define BAMBOO_MULTICORE_GC_PROFILE_H
3 #ifdef MULTICORE_GC
4 #include "multicore.h"
5 #include "runtime_arch.h"
6 #include "structdefs.h"
7
8 #ifdef GC_PROFILE
9 #define GCINFOLENGTH 100
10
11 #ifdef GC_CACHE_ADAPT
12 #define GC_PROFILE_NUM_FIELD 15
13 #else
14 #define GC_PROFILE_NUM_FIELD 14
15 #endif // GC_CACHE_ADAPT
16
17 typedef struct gc_info {
18   unsigned long long time[GC_PROFILE_NUM_FIELD];
19   unsigned int index;
20 } GCInfo;
21
22 GCInfo * gc_infoArray[GCINFOLENGTH];
23 unsigned int gc_infoIndex;
24 bool gc_infoOverflow;
25 unsigned long long gc_num_livespace;
26 unsigned long long gc_num_freespace;
27 unsigned long long gc_num_lobjspace;
28 unsigned int gc_num_lobj;
29
30 unsigned int gc_num_liveobj;
31 unsigned int gc_num_obj;
32 unsigned int gc_num_forwardobj;
33 unsigned int gc_num_profiles;
34
35 #ifdef MGC_SPEC
36 volatile bool gc_profile_flag;
37 #endif
38
39 void initmulticoregcprofiledata(void);
40 void gc_outputProfileData();
41
42 INLINE static void gc_profileInit() {
43   gc_num_livespace = 0;
44   gc_num_freespace = 0;
45   gc_num_lobj = 0;
46   gc_num_lobjspace = 0;
47   gc_num_liveobj = 0;
48   gc_num_forwardobj = 0;
49   gc_num_profiles = NUMCORESACTIVE - 1;
50 }
51
52 INLINE static void gc_profileStart(void) {
53   if(!gc_infoOverflow) {
54     GCInfo* gcInfo = RUNMALLOC(sizeof(struct gc_info));
55     gc_infoArray[gc_infoIndex] = gcInfo;
56     gcInfo->index = 1;
57     gcInfo->time[0] = BAMBOO_GET_EXE_TIME();
58   }
59 }
60
61 INLINE static void gc_profileItem(void) {
62   if(!gc_infoOverflow) {
63     GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
64     gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
65   }
66 }
67
68 INLINE static void gc_profileEnd(void) {
69   if(!gc_infoOverflow) {
70     GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
71     gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
72     gcInfo->time[gcInfo->index++] = gc_num_livespace;
73     gcInfo->time[gcInfo->index++] = gc_num_freespace;
74     gcInfo->time[gcInfo->index++] = gc_num_lobj;
75     gcInfo->time[gcInfo->index++] = gc_num_lobjspace;
76     gcInfo->time[gcInfo->index++] = gc_num_obj;
77     gcInfo->time[gcInfo->index++] = gc_num_liveobj;
78     gcInfo->time[gcInfo->index++] = gc_num_forwardobj;
79     gc_infoIndex++;
80     if(gc_infoIndex == GCINFOLENGTH) {
81       gc_infoOverflow = true;
82     }
83   }
84 }
85
86 #define INIT_MULTICORE_GCPROFILE_DATA() initmulticoregcprofiledata()
87 #define GC_OUTPUT_PROFILE_DATA() gc_outputProfileData()
88 // send the num of obj/liveobj/forwardobj to the startupcore
89 #define GCPROFILE_INFO_2_MASTER() \
90   { \
91     if(STARTUPCORE != BAMBOO_NUM_OF_CORE) { \
92       send_msg_4(STARTUPCORE,GCPROFILES,gc_num_obj,gc_num_liveobj,gc_num_forwardobj); \
93     }\
94     gc_num_obj = 0; \
95   }
96
97 #ifdef MGC_SPEC
98 // record lobj info
99 #define GCPROFILE_RECORD_LOBJ() \
100   { \
101     if(gc_profile_flag) { \
102       gc_num_lobj++; \
103     } \
104   }
105 // record lobj space info
106 #define GCPROFILE_RECORD_LOBJSPACE() \
107   { \
108     if(gc_profile_flag) { \
109       gc_num_lobjspace = sumsize; \
110     } \
111   }
112 // check the live/free space info
113 #define GCPROFILE_RECORD_SPACE() \
114   { \
115     if(gc_profile_flag) { \
116       gc_num_livespace = 0; \
117       for(int tmpi = 0; tmpi < gcnumblock; tmpi++) { \
118         gc_num_livespace += bamboo_smemtbl[tmpi]; \
119       } \
120       gc_num_freespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_livespace; \
121     } \
122   }
123 // record forward obj info
124 #define GCPROFILE_RECORD_FORWARD_OBJ() \
125   { \
126     if(gc_profile_flag) { \
127       gc_num_forwardobj++; \
128     } \
129   }
130 // record live obj info
131 #define GCPROFILE_RECORD_LIVE_OBJ() \
132   { \
133     if(gc_profile_flag) { \
134       gc_num_liveobj++; \
135     } \
136   }
137 #define GCPROFILE_START() \
138   { \
139     if(gc_profile_flag) { \
140       gc_profileStart(); \
141     } \
142   }
143 #define GCPROFILE_ITEM() \
144   { \
145     if(gc_profile_flag) { \
146       gc_profileItem(); \
147     } \
148   }
149 #define GCPROFILE_END() \
150   { \
151     if(gc_profile_flag) { \
152       gc_profileEnd(); \
153     } \
154   }
155 #else // MGC_SPEC
156 #define GCPROFILE_RECORD_LOBJ() (gc_num_lobj++)
157 #define GCPROFILE_RECORD_LOBJSPACE() (gc_num_lobjspace = sumsize)
158 #define GCPROFILE_RECORD_SPACE() \
159   { \
160     gc_num_livespace = 0; \
161     for(int tmpi = 0; tmpi < gcnumblock; tmpi++) { \
162       gc_num_livespace += bamboo_smemtbl[tmpi]; \
163     } \
164     gc_num_freespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_livespace; \
165   }
166 #define GCPROFILE_RECORD_FORWARD_OBJ() (gc_num_forwardobj++)
167 #define GCPROFILE_RECORD_LIVE_OBJ() (gc_num_liveobj++)
168 #define GCPROFILE_START() gc_profileStart()
169 #define GCPROFILE_ITEM() gc_profileItem()
170 #define GCPROFILE_END() gc_profileEnd()
171 #endif // MGC_SPEC
172
173 #define GCPROFILE_INIT() gc_profileInit()
174
175 #else // GC_PROFILE
176 #define INIT_MULTICORE_GCPROFILE_DATA()
177 #define GC_OUTPUT_PROFILE_DATA() 
178 #define GCPROFILE_INFO_2_MASTER() 
179 #define GCPROFILE_RECORD_LOBJ()
180 #define GCPROFILE_RECORD_LOBJSPACE()
181 #define GCPROFILE_RECORD_SPACE()
182 #define GCPROFILE_RECORD_FORWARD_OBJ() 
183 #define GCPROFILE_RECORD_LIVE_OBJ() 
184 #define GCPROFILE_START()
185 #define GCPROFILE_ITEM()
186 #define GCPROFILE_END()
187 #define GCPROFILE_INIT()
188 #endif // GC_PROFILE
189
190 #endif // MULTICORE_GC
191 #endif // BAMBOO_MULTICORE_GC_PROFILE_H