| rev |
line source |
|
Me@178
|
1 /*
|
|
Me@178
|
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
|
|
Me@178
|
3 * Licensed under GNU General Public License version 2
|
|
Me@178
|
4 *
|
|
Me@178
|
5 * Author: seanhalle@yahoo.com
|
|
Me@178
|
6 *
|
|
Me@178
|
7 */
|
|
Me@178
|
8
|
|
Me@178
|
9 #ifndef _VMS_H
|
|
Me@178
|
10 #define _VMS_H
|
|
Me@178
|
11 #define _GNU_SOURCE
|
|
Me@178
|
12
|
|
Me@178
|
13 #include "VMS_primitive_data_types.h"
|
|
hausers@192
|
14 #include "../../C_Libraries/DynArray/DynArray.h"
|
|
hausers@192
|
15 #include "../../C_Libraries/Hash_impl/PrivateHash.h"
|
|
Me@200
|
16 #include "../../C_Libraries/Histogram/Histogram.h"
|
|
Me@200
|
17 #include "../../C_Libraries/Queue_impl/PrivateQueue.h"
|
|
Me@178
|
18 #include "vmalloc.h"
|
|
Me@178
|
19
|
|
Me@178
|
20 #include <pthread.h>
|
|
Me@178
|
21 #include <sys/time.h>
|
|
Me@178
|
22
|
|
Me@200
|
23 //================= Defines: included from separate files =================
|
|
Me@200
|
24 //
|
|
Me@200
|
25 // Note: ALL defines are in other files, none are in here
|
|
Me@200
|
26 //
|
|
Me@200
|
27 #include "VMS_defs.h"
|
|
Me@178
|
28
|
|
Me@200
|
29
|
|
Me@200
|
30
|
|
Me@200
|
31 //================================ Typedefs =================================
|
|
Me@178
|
32 //
|
|
Me@178
|
33 typedef unsigned long long TSCount;
|
|
Me@200
|
34 typedef union
|
|
Me@200
|
35 { uint32 lowHigh[2];
|
|
Me@200
|
36 uint64 longVal;
|
|
Me@200
|
37 }
|
|
Me@200
|
38 TSCountLowHigh;
|
|
Me@178
|
39
|
|
Me@178
|
40 typedef struct _SchedSlot SchedSlot;
|
|
Me@178
|
41 typedef struct _VMSReqst VMSReqst;
|
|
Me@200
|
42 typedef struct _SlaveVP SlaveVP;
|
|
Me@178
|
43 typedef struct _IntervalProbe IntervalProbe;
|
|
Me@178
|
44 typedef struct _GateStruc GateStruc;
|
|
Me@178
|
45
|
|
Me@178
|
46
|
|
Me@200
|
47 typedef SlaveVP * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
|
|
Me@200
|
48 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
|
|
Me@200
|
49 typedef void (*VirtProcrFnPtr) ( void *, SlaveVP * ); //initData, animPr
|
|
Me@200
|
50 typedef void VirtProcrFn ( void *, SlaveVP * ); //initData, animPr
|
|
Me@200
|
51 typedef void (*ResumeVPFnPtr) ( SlaveVP *, void * );
|
|
Me@178
|
52
|
|
Me@178
|
53
|
|
Me@200
|
54 //============= Request Related ===========
|
|
Me@178
|
55 //
|
|
Me@178
|
56
|
|
Me@178
|
57 enum VMSReqstType //avoid starting enums at 0, for debug reasons
|
|
Me@178
|
58 {
|
|
Me@178
|
59 semantic = 1,
|
|
Me@178
|
60 createReq,
|
|
Me@178
|
61 dissipate,
|
|
Me@178
|
62 VMSSemantic //goes with VMSSemReqst below
|
|
Me@178
|
63 };
|
|
Me@178
|
64
|
|
Me@178
|
65 struct _VMSReqst
|
|
Me@178
|
66 {
|
|
Me@178
|
67 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
|
|
Me@178
|
68 void *semReqData;
|
|
Me@178
|
69
|
|
Me@178
|
70 VMSReqst *nextReqst;
|
|
Me@178
|
71 };
|
|
Me@178
|
72 //VMSReqst
|
|
Me@178
|
73
|
|
Me@178
|
74 enum VMSSemReqstType //These are equivalent to semantic requests, but for
|
|
Me@178
|
75 { // VMS's services available directly to app, like OS
|
|
Me@178
|
76 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
|
|
Me@178
|
77 openFile,
|
|
Me@178
|
78 otherIO
|
|
Me@178
|
79 };
|
|
Me@178
|
80
|
|
Me@178
|
81 typedef struct
|
|
Me@178
|
82 { enum VMSSemReqstType reqType;
|
|
Me@200
|
83 SlaveVP *requestingPr;
|
|
Me@178
|
84 char *nameStr; //for create probe
|
|
Me@178
|
85 }
|
|
Me@178
|
86 VMSSemReq;
|
|
Me@178
|
87
|
|
Me@178
|
88
|
|
Me@178
|
89 //==================== Core data structures ===================
|
|
Me@178
|
90
|
|
Me@178
|
91 struct _SchedSlot
|
|
Me@178
|
92 {
|
|
Me@178
|
93 int workIsDone;
|
|
Me@178
|
94 int needsProcrAssigned;
|
|
Me@200
|
95 SlaveVP *procrAssignedToSlot;
|
|
Me@178
|
96 };
|
|
Me@178
|
97 //SchedSlot
|
|
Me@178
|
98
|
|
Me@178
|
99 /*WARNING: re-arranging this data structure could cause VP switching
|
|
Me@178
|
100 * assembly code to fail -- hard-codes offsets of fields
|
|
Me@178
|
101 */
|
|
Me@200
|
102 struct _SlaveVP
|
|
Me@178
|
103 { int procrID; //for debugging -- count up each time create
|
|
Me@178
|
104 int coreAnimatedBy;
|
|
Me@178
|
105 void *startOfStack;
|
|
Me@178
|
106 void *stackPtr;
|
|
Me@178
|
107 void *framePtr;
|
|
Me@178
|
108 void *nextInstrPt;
|
|
Me@178
|
109
|
|
Me@178
|
110 void *coreLoopStartPt; //allows proto-runtime to be linked later
|
|
Me@178
|
111 void *coreLoopFramePtr; //restore before jmp back to core loop
|
|
Me@178
|
112 void *coreLoopStackPtr; //restore before jmp back to core loop
|
|
Me@178
|
113
|
|
Me@178
|
114 void *initialData;
|
|
Me@178
|
115
|
|
Me@178
|
116 SchedSlot *schedSlot;
|
|
Me@178
|
117 VMSReqst *requests;
|
|
Me@178
|
118
|
|
Me@178
|
119 void *semanticData; //this livesUSE_GNU here for the life of VP
|
|
Me@178
|
120 void *dataRetFromReq;//values returned from plugin to VP go here
|
|
Me@178
|
121
|
|
Me@178
|
122 //=========== MEASUREMENT STUFF ==========
|
|
Me@200
|
123 #ifdef MEAS__TIME_STAMP_SUSP
|
|
Me@200
|
124 uint32 preSuspTSCLow;
|
|
Me@200
|
125 uint32 postSuspTSCLow;
|
|
Me@200
|
126 #endif
|
|
Me@200
|
127 #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
|
|
Me@200
|
128 uint32 startMasterTSCLow;USE_GNU
|
|
Me@200
|
129 uint32 endMasterTSCLow;
|
|
Me@200
|
130 #endif
|
|
Me@200
|
131 #ifdef MEAS__TIME_2011_SYS
|
|
Me@200
|
132 TSCountLowHigh startSusp;
|
|
Me@200
|
133 uint64 totalSuspCycles;
|
|
Me@200
|
134 uint32 numGoodSusp;
|
|
Me@200
|
135 #endif
|
|
Me@178
|
136 //========================================
|
|
Me@178
|
137
|
|
Me@178
|
138 float64 createPtInSecs; //have space but don't use on some configs
|
|
Me@178
|
139 };
|
|
Me@178
|
140 //VirtProcr
|
|
Me@178
|
141
|
|
Me@178
|
142
|
|
Me@178
|
143 /*WARNING: re-arranging this data structure could cause VP-switching
|
|
Me@178
|
144 * assembly code to fail -- hard-codes offsets of fields
|
|
Me@178
|
145 * (because -O3 messes with things otherwise)
|
|
Me@178
|
146 */
|
|
Me@178
|
147 typedef struct
|
|
Me@178
|
148 {
|
|
Me@200
|
149 union{ //adds padding to put masterLock on its own cache-line to elim
|
|
Me@200
|
150 // false sharing (masterLock is most-accessed var in VMS)
|
|
Me@200
|
151 volatile int32 masterLock;
|
|
Me@200
|
152 char padding[CACHELINE_SIZE];
|
|
Me@200
|
153 } masterLockUnion;
|
|
Me@178
|
154 SlaveScheduler slaveScheduler;
|
|
Me@178
|
155 RequestHandler requestHandler;
|
|
Me@178
|
156
|
|
Me@178
|
157 SchedSlot ***allSchedSlots;
|
|
Me@178
|
158 VMSQueueStruc **readyToAnimateQs;
|
|
Me@200
|
159 SlaveVP **masterVPs;
|
|
Me@178
|
160
|
|
Me@178
|
161 void *semanticEnv;
|
|
Me@178
|
162 void *OSEventStruc; //for future, when add I/O to BLIS
|
|
Me@200
|
163 MallocArrays *freeLists;
|
|
Me@178
|
164 int32 amtOfOutstandingMem; //total currently allocated
|
|
Me@178
|
165
|
|
Me@178
|
166 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
|
|
Me@178
|
167
|
|
Me@178
|
168 int32 setupComplete;
|
|
Me@200
|
169 //int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
|
|
Me@178
|
170 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
|
|
Me@178
|
171 int32 workStealingLock;
|
|
Me@178
|
172
|
|
Me@200
|
173 int32 numVPsCreated; //gives ordering to processor creation
|
|
Me@178
|
174
|
|
Me@178
|
175 //=========== MEASUREMENT STUFF =============
|
|
Me@200
|
176 IntervalProbe **intervalProbes;
|
|
Me@200
|
177 PrivDynArrayInfo *dynIntervalProbesInfo;
|
|
Me@200
|
178 HashTable *probeNameHashTbl;
|
|
Me@200
|
179 int32 masterCreateProbeID;
|
|
Me@200
|
180 float64 createPtInSecs;
|
|
Me@200
|
181 Histogram **measHists;
|
|
Me@200
|
182 PrivDynArrayInfo *measHistsInfo;
|
|
Me@200
|
183 #ifdef MEAS__TIME_PLUGIN
|
|
Me@200
|
184 Histogram *reqHdlrLowTimeHist;
|
|
Me@200
|
185 Histogram *reqHdlrHighTimeHist;
|
|
Me@200
|
186 #endif
|
|
Me@200
|
187 #ifdef MEAS__TIME_MALLOC
|
|
Me@200
|
188 Histogram *mallocTimeHist;
|
|
Me@200
|
189 Histogram *freeTimeHist;
|
|
Me@200
|
190 #endif
|
|
Me@200
|
191 #ifdef MEAS__TIME_MASTER_LOCK
|
|
Me@200
|
192 Histogram *masterLockLowTimeHist;
|
|
Me@200
|
193 Histogram *masterLockHighTimeHist;
|
|
Me@200
|
194 #endif
|
|
Me@200
|
195 #ifdef MEAS__TIME_2011_SYS
|
|
Me@200
|
196 TSCountLowHigh startMaster;
|
|
Me@200
|
197 uint64 totalMasterCycles;
|
|
Me@200
|
198 uint32 numMasterAnimations;
|
|
Me@200
|
199 TSCountLowHigh startReqHdlr;
|
|
Me@200
|
200 uint64 totalPluginCycles;
|
|
Me@200
|
201 uint32 numPluginAnimations;
|
|
Me@200
|
202 uint64 cyclesTillStartMasterLoop;
|
|
Me@200
|
203 TSCountLowHigh endMasterLoop;
|
|
Me@200
|
204 #endif
|
|
Me@200
|
205 //==========================================
|
|
Me@178
|
206 }
|
|
Me@178
|
207 MasterEnv;
|
|
Me@178
|
208
|
|
Me@178
|
209 //========================= Extra Stuff Data Strucs =======================
|
|
Me@178
|
210 typedef struct
|
|
Me@178
|
211 {
|
|
Me@178
|
212
|
|
Me@178
|
213 }
|
|
Me@178
|
214 VMSExcp;
|
|
Me@178
|
215
|
|
Me@178
|
216 struct _GateStruc
|
|
Me@178
|
217 {
|
|
Me@178
|
218 int32 gateClosed;
|
|
Me@178
|
219 int32 preGateProgress;
|
|
Me@178
|
220 int32 waitProgress;
|
|
Me@178
|
221 int32 exitProgress;
|
|
Me@178
|
222 };
|
|
Me@178
|
223 //GateStruc
|
|
Me@178
|
224
|
|
Me@178
|
225 //======================= OS Thread related ===============================
|
|
Me@178
|
226
|
|
Me@178
|
227 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@178
|
228 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@200
|
229 void masterLoop( void *initData, SlaveVP *masterVP );
|
|
Me@178
|
230
|
|
Me@178
|
231
|
|
Me@178
|
232 typedef struct
|
|
Me@178
|
233 {
|
|
Me@178
|
234 void *endThdPt;
|
|
Me@178
|
235 unsigned int coreNum;
|
|
Me@178
|
236 }
|
|
Me@178
|
237 ThdParams;
|
|
Me@178
|
238
|
|
Me@178
|
239 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
|
|
Me@178
|
240 ThdParams *coreLoopThdParams [ NUM_CORES ];
|
|
Me@178
|
241 pthread_mutex_t suspendLock;
|
|
Me@178
|
242 pthread_cond_t suspend_cond;
|
|
Me@178
|
243
|
|
Me@178
|
244
|
|
Me@178
|
245
|
|
Me@200
|
246 //============================= Global Vars ================================
|
|
Me@178
|
247
|
|
Me@200
|
248 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
|
|
Me@178
|
249
|
|
Me@178
|
250
|
|
Me@178
|
251
|
|
Me@178
|
252
|
|
Me@200
|
253 //========================= Function Prototypes ===========================
|
|
Me@178
|
254
|
|
Me@178
|
255
|
|
Me@178
|
256 //========== Setup and shutdown ==========
|
|
Me@178
|
257 void
|
|
Me@200
|
258 VMS_int__init();
|
|
Me@178
|
259
|
|
Me@178
|
260 void
|
|
Me@200
|
261 VMS_int__init_Seq();
|
|
Me@178
|
262
|
|
Me@178
|
263 void
|
|
Me@200
|
264 VMS_WL__start_the_work_then_wait_until_done();
|
|
Me@178
|
265
|
|
Me@178
|
266 void
|
|
Me@200
|
267 VMS_WL__start_the_work_then_wait_until_done_Seq();
|
|
Me@178
|
268
|
|
Me@200
|
269 inline SlaveVP *
|
|
Me@200
|
270 VMS_int__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
|
|
Me@178
|
271
|
|
Me@178
|
272 void
|
|
Me@200
|
273 VMS_int__dissipate_procr( SlaveVP *procrToDissipate );
|
|
Me@178
|
274
|
|
Me@178
|
275 //Use this to create processor inside entry point & other places outside
|
|
Me@178
|
276 // the VMS system boundary (IE, not run in slave nor Master)
|
|
Me@200
|
277 SlaveVP *
|
|
Me@178
|
278 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
|
|
Me@178
|
279
|
|
Me@178
|
280 void
|
|
Me@200
|
281 VMS_ext__dissipate_procr( SlaveVP *procrToDissipate );
|
|
Me@178
|
282
|
|
Me@178
|
283 void
|
|
Me@200
|
284 VMS_PI__throw_exception( char *msgStr, SlaveVP *reqstPr, VMSExcp *excpData );
|
|
Me@178
|
285
|
|
Me@178
|
286 void
|
|
Me@200
|
287 VMS_int__shutdown();
|
|
Me@178
|
288
|
|
Me@178
|
289 void
|
|
Me@200
|
290 VMS_int__cleanup_at_end_of_shutdown();
|
|
Me@178
|
291
|
|
Me@178
|
292 void *
|
|
Me@200
|
293 VMS_WL__give_sem_env_for( SlaveVP *animPr );
|
|
Me@178
|
294
|
|
Me@178
|
295
|
|
Me@178
|
296 //============== Request Related ===============
|
|
Me@178
|
297
|
|
Me@178
|
298 void
|
|
Me@200
|
299 VMS_int__suspend_procr( SlaveVP *callingPr );
|
|
Me@178
|
300
|
|
Me@178
|
301 inline void
|
|
Me@200
|
302 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingPr );
|
|
Me@178
|
303
|
|
Me@178
|
304 inline void
|
|
Me@200
|
305 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingPr );
|
|
Me@178
|
306
|
|
Me@178
|
307 void
|
|
Me@200
|
308 VMS_WL__send_create_procr_req( void *semReqData, SlaveVP *reqstingPr );
|
|
Me@178
|
309
|
|
Me@178
|
310 void inline
|
|
Me@200
|
311 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
|
|
Me@178
|
312
|
|
Me@178
|
313 inline void
|
|
Me@200
|
314 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingPr );
|
|
Me@178
|
315
|
|
Me@178
|
316 VMSReqst *
|
|
Me@200
|
317 VMS_PI__take_next_request_out_of( SlaveVP *procrWithReq );
|
|
Me@178
|
318
|
|
Me@178
|
319 inline void *
|
|
Me@200
|
320 VMS_PI__take_sem_reqst_from( VMSReqst *req );
|
|
Me@178
|
321
|
|
Me@178
|
322 void inline
|
|
Me@200
|
323 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingPr, void *semEnv,
|
|
Me@200
|
324 ResumeVPFnPtr resumePrFnPtr );
|
|
Me@178
|
325
|
|
Me@200
|
326 //======================== MEASUREMENT ======================
|
|
Me@200
|
327 uint64
|
|
Me@200
|
328 VMS_WL__give_num_plugin_cycles();
|
|
Me@200
|
329 uint32
|
|
Me@200
|
330 VMS_WL__give_num_plugin_animations();
|
|
Me@178
|
331
|
|
Me@178
|
332
|
|
Me@178
|
333
|
|
Me@178
|
334 #include "ProcrContext.h"
|
|
Me@178
|
335 #include "probes.h"
|
|
Me@178
|
336 #include "vutilities.h"
|
|
Me@178
|
337
|
|
Me@178
|
338 #endif /* _VMS_H */
|
|
Me@178
|
339
|