Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 226:ea70fa57776e
fixed last bug that shows up in sequential mode -- still a race of some kind
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Thu, 15 Mar 2012 05:29:07 -0700 |
| parents | 309559064073 |
| children | 5c475c4b7b49 |
line source
1 /*
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 *
7 */
9 #ifndef _VMS_H
10 #define _VMS_H
11 #define _GNU_SOURCE
13 #include "VMS_primitive_data_types.h"
14 #include "DynArray/DynArray.h"
15 #include "Hash_impl/PrivateHash.h"
16 #include "Histogram/Histogram.h"
17 #include "Queue_impl/PrivateQueue.h"
18 #include "Services_Offered_by_VMS/Memory_Handling/vmalloc.h"
20 #include <pthread.h>
21 #include <sys/time.h>
23 //================= Defines: included from separate files =================
24 //
25 // Note: ALL defines are in other files, none are in here
26 //
27 #include "Defines/VMS_defs.h"
30 //================================ Typedefs =================================
31 //
32 typedef unsigned long long TSCount;
33 typedef union
34 { uint32 lowHigh[2];
35 uint64 longVal;
36 }
37 TSCountLowHigh;
39 typedef struct _SchedSlot SchedSlot;
40 typedef struct _VMSReqst VMSReqst;
41 typedef struct _SlaveVP SlaveVP;
42 typedef struct _MasterVP MasterVP;
43 typedef struct _IntervalProbe IntervalProbe;
44 typedef struct _GateStruc GateStruc;
47 typedef SlaveVP *(*SlaveAssigner) ( void *, int, SchedSlot *); //semEnv, coreIdx, slot for HW info
48 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
49 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
50 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
51 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
53 //============================ HW Dependent Fns ================================
55 #include "Hardware_Dependent/VMS__HW_measurement.h"
56 #include "Hardware_Dependent/VMS__primitives.h"
58 //============================= Statistics ==================================
60 inline TSCount getTSCount();
62 //============= Request Related ===========
63 //
65 enum VMSReqstType //avoid starting enums at 0, for debug reasons
66 {
67 semantic = 1,
68 createReq,
69 dissipate,
70 VMSSemantic //goes with VMSSemReqst below
71 };
73 struct _VMSReqst
74 {
75 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
76 void *semReqData;
78 VMSReqst *nextReqst;
79 };
80 //VMSReqst
82 enum VMSSemReqstType //These are equivalent to semantic requests, but for
83 { // VMS's services available directly to app, like OS
84 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
85 openFile,
86 otherIO
87 };
89 typedef struct
90 { enum VMSSemReqstType reqType;
91 SlaveVP *requestingSlv;
92 char *nameStr; //for create probe
93 }
94 VMSSemReq;
97 //==================== Core data structures ===================
99 struct _SchedSlot
100 {
101 int slotIdx; //needed by Holistic Model's data gathering
102 int workIsDone;
103 int needsSlaveAssigned;
104 SlaveVP *slaveAssignedToSlot;
105 };
106 //SchedSlot
108 /*WARNING: re-arranging this data structure could cause Slv switching
109 * assembly code to fail -- hard-codes offsets of fields
110 */
111 struct _SlaveVP
112 { int slaveID; //each slave given a unique ID
113 int coreAnimatedBy;
114 void *startOfStack;
115 void *stackPtr;
116 void *framePtr;
117 void *resumeInstrPtr;
119 void *coreCtlrStartPt; //allows proto-runtime to be linked later
120 void *coreCtlrFramePtr; //restore before jmp back to core controller
121 void *coreCtlrStackPtr; //restore before jmp back to core controller
123 SchedSlot *schedSlot;
124 VMSReqst *requests;
126 void *semanticData; //this is live for the life of Slv
127 void *dataRetFromReq;//Used to return vals from plugin to Wrapper Lib
129 //=========== MEASUREMENT STUFF ==========
130 MEAS__Insert_Meas_Fields_into_Slave;
131 //========================================
133 float64 createPtInSecs; //have space but don't use on some configs
134 };
135 //SlaveVP
138 /*WARNING: re-arranging this data structure could cause Slv-switching
139 * assembly code to fail -- hard-codes offsets of fields
140 * (because -O3 messes with things otherwise)
141 */
142 typedef struct
143 { //The offset of these fields is hard-coded into assembly
144 void *coreCtlrReturnPt; //offset of field used in asm
145 int32 masterLock __align_to_cacheline__; //used in asm
147 //below this, no asm uses the field offsets
148 SlaveAssigner slaveAssigner;
149 RequestHandler requestHandler;
151 SchedSlot ***allSchedSlots;
152 SlaveVP **masterVPs;
154 void *semanticEnv;
155 void *OSEventStruc; //for future, when add I/O to BLIS
156 MallocArrays *freeLists;
157 int32 amtOfOutstandingMem; //total currently allocated
159 int32 setupComplete;
160 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
161 int32 workStealingLock;
163 int32 numSlavesCreated; //gives ordering to processor creation
164 int32 numSlavesAlive; //used to detect when to shutdown
166 //=========== MEASUREMENT STUFF =============
167 IntervalProbe **intervalProbes;
168 PrivDynArrayInfo *dynIntervalProbesInfo;
169 HashTable *probeNameHashTbl;
170 int32 masterCreateProbeID;
171 float64 createPtInSecs;
172 Histogram **measHists;
173 PrivDynArrayInfo *measHistsInfo;
174 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
175 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
176 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
177 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
178 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
179 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
180 //==========================================
181 }
182 MasterEnv;
184 //========================= Extra Stuff Data Strucs =======================
185 typedef struct
186 {
188 }
189 VMSExcp;
191 struct _GateStruc
192 {
193 int32 gateClosed;
194 int32 preGateProgress;
195 int32 waitProgress;
196 int32 exitProgress;
197 };
198 //GateStruc
200 //======================= OS Thread related ===============================
202 void * coreController( void *paramsIn ); //standard PThreads fn prototype
203 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
204 void schedulingMaster( void *initData, SlaveVP *masterVP );
207 typedef struct
208 {
209 void *endThdPt;
210 unsigned int coreNum;
211 }
212 ThdParams;
214 //============================= Global Vars ================================
216 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
218 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
219 ThdParams *coreCtlrThdParams [ NUM_CORES ];
221 pthread_mutex_t suspendLock;
222 pthread_cond_t suspendCond;
224 //========================= Function Prototypes ===========================
226 /* MEANING OF WL PI SS int
227 * These indicate which places the function is safe to use. They stand for:
228 * WL: Wrapper Library
229 * PI: Plugin
230 * SS: Startup and Shutdown
231 * int: internal to the VMS implementation
232 */
234 //========== Setup and shutdown ==========
235 void
236 VMS_SS__init();
238 void
239 VMS_SS__start_the_work_then_wait_until_done();
241 void
242 VMS_SS__shutdown();
244 void
245 VMS_SS__cleanup_at_end_of_shutdown();
248 //============== ===============
250 inline SlaveVP *
251 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
252 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
253 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
255 //Use this to create processor inside entry point & other places outside
256 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
257 SlaveVP *
258 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
260 inline SlaveVP *
261 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
262 void *dataParam, void *stackLocs );
264 inline void
265 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
266 void *dataParam);
268 void
269 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
270 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
271 //WL: dissipate a SlaveVP by sending a request
273 void
274 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
276 void
277 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
278 #define VMS_PI__throw_exception VMS_int__throw_exception
279 #define VMS_WL__throw_exception VMS_int__throw_exception
281 void *
282 VMS_int__give_sem_env_for( SlaveVP *animSlv );
283 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
284 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
285 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
287 //============== Request Related ===============
289 void
290 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
292 inline void
293 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
295 inline void
296 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
298 void
299 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
301 void inline
302 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
304 inline void
305 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
307 VMSReqst *
308 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
310 inline void *
311 VMS_PI__take_sem_reqst_from( VMSReqst *req );
313 void inline
314 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
315 ResumeSlvFnPtr resumeSlvFnPtr );
317 //======================== MEASUREMENT ======================
318 uint64
319 VMS_WL__give_num_plugin_cycles();
320 uint32
321 VMS_WL__give_num_plugin_animations();
324 //========================= Utilities =======================
325 inline char *
326 VMS_int__strDup( char *str );
329 //========================= Probes =======================
330 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
332 //================================================
333 #endif /* _VMS_H */
