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