Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 228:125f0f90a0d3
integrating holistic model in common ancestor - not finished yet
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Thu, 15 Mar 2012 18:28:29 +0100 |
| parents | 5c475c4b7b49 |
| children | 0ee1a3c8972d |
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 * );
52 //=========== MEASUREMENT STUFF ==========
53 MEAS__Insert_Counter_Handler
54 //========================================
56 //============================ HW Dependent Fns ================================
58 #include "Hardware_Dependent/VMS__HW_measurement.h"
59 #include "Hardware_Dependent/VMS__primitives.h"
61 //============================= Statistics ==================================
63 inline TSCount getTSCount();
65 //============= Request Related ===========
66 //
68 enum VMSReqstType //avoid starting enums at 0, for debug reasons
69 {
70 semantic = 1,
71 createReq,
72 dissipate,
73 VMSSemantic //goes with VMSSemReqst below
74 };
76 struct _VMSReqst
77 {
78 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
79 void *semReqData;
81 VMSReqst *nextReqst;
82 };
83 //VMSReqst
85 enum VMSSemReqstType //These are equivalent to semantic requests, but for
86 { // VMS's services available directly to app, like OS
87 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
88 openFile,
89 otherIO
90 };
92 typedef struct
93 { enum VMSSemReqstType reqType;
94 SlaveVP *requestingSlv;
95 char *nameStr; //for create probe
96 }
97 VMSSemReq;
100 //==================== Core data structures ===================
102 struct _SchedSlot
103 {
104 int slotIdx; //needed by Holistic Model's data gathering
105 int workIsDone;
106 int needsSlaveAssigned;
107 SlaveVP *slaveAssignedToSlot;
108 };
109 //SchedSlot
111 enum VPtype {
112 Slave = 1, //default
113 Master,
114 Shutdown
115 };
117 /*WARNING: re-arranging this data structure could cause Slv switching
118 * assembly code to fail -- hard-codes offsets of fields
119 */
120 struct _SlaveVP
121 { int slaveID; //each slave given a unique ID
122 int coreAnimatedBy;
123 void *startOfStack;
124 void *stackPtr;
125 void *framePtr;
126 void *resumeInstrPtr;
128 void *coreCtlrStartPt; //allows proto-runtime to be linked later
129 void *coreCtlrFramePtr; //restore before jmp back to core controller
130 void *coreCtlrStackPtr; //restore before jmp back to core controller
132 SchedSlot *schedSlot;
133 VMSReqst *requests;
135 void *semanticData; //this is live for the life of Slv
136 void *dataRetFromReq;//Used to return vals from plugin to Wrapper Lib
138 //=========== MEASUREMENT STUFF ==========
139 MEAS__Insert_Meas_Fields_into_Slave;
140 //========================================
142 enum VPtype type;
143 int numTimesAssigned;
145 float64 createPtInSecs; //have space but don't use on some configs
146 };
147 //SlaveVP
150 /*WARNING: re-arranging this data structure could cause Slv-switching
151 * assembly code to fail -- hard-codes offsets of fields
152 * (because -O3 messes with things otherwise)
153 */
154 typedef struct
155 { //The offset of these fields is hard-coded into assembly
156 void *coreCtlrReturnPt; //offset of field used in asm
157 int32 masterLock __align_to_cacheline__; //used in asm
159 //below this, no asm uses the field offsets
160 SlaveAssigner slaveAssigner;
161 RequestHandler requestHandler;
163 SchedSlot ***allSchedSlots;
164 SlaveVP **masterVPs;
166 void *semanticEnv;
167 void *OSEventStruc; //for future, when add I/O to BLIS
168 MallocArrays *freeLists;
169 int32 amtOfOutstandingMem; //total currently allocated
171 int32 setupComplete; //use while starting up coreCtlr
172 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
173 int32 workStealingLock;
175 int32 numSlavesCreated; //gives ordering to processor creation
176 int32 numSlavesAlive; //used to detect when to shutdown
178 //=========== MEASUREMENT STUFF =============
179 IntervalProbe **intervalProbes;
180 PrivDynArrayInfo *dynIntervalProbesInfo;
181 HashTable *probeNameHashTbl;
182 int32 masterCreateProbeID;
183 float64 createPtInSecs;
184 Histogram **measHists;
185 PrivDynArrayInfo *measHistsInfo;
186 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
187 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
188 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
189 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
190 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
191 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
192 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
193 //==========================================
194 }
195 MasterEnv;
197 //========================= Extra Stuff Data Strucs =======================
198 typedef struct
199 {
201 }
202 VMSExcp;
204 struct _GateStruc
205 {
206 int32 gateClosed;
207 int32 preGateProgress;
208 int32 waitProgress;
209 int32 exitProgress;
210 };
211 //GateStruc
213 //======================= OS Thread related ===============================
215 void * coreController( void *paramsIn ); //standard PThreads fn prototype
216 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
217 void schedulingMaster( void *initData, SlaveVP *masterVP );
220 typedef struct
221 {
222 void *endThdPt;
223 unsigned int coreNum;
224 }
225 ThdParams;
227 //============================= Global Vars ================================
229 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
231 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
232 ThdParams *coreCtlrThdParams [ NUM_CORES ];
234 pthread_mutex_t suspendLock;
235 pthread_cond_t suspendCond;
237 //========================= Function Prototypes ===========================
239 /* MEANING OF WL PI SS int
240 * These indicate which places the function is safe to use. They stand for:
241 * WL: Wrapper Library
242 * PI: Plugin
243 * SS: Startup and Shutdown
244 * int: internal to the VMS implementation
245 */
247 //========== Setup and shutdown ==========
248 void
249 VMS_SS__init();
251 void
252 VMS_SS__start_the_work_then_wait_until_done();
254 SlaveVP*
255 VMS_SS__create_shutdown_slave();
257 void
258 VMS_SS__shutdown();
260 void
261 VMS_SS__cleanup_at_end_of_shutdown();
264 //============== ===============
266 inline SlaveVP *
267 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
268 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
269 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
271 //Use this to create processor inside entry point & other places outside
272 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
273 SlaveVP *
274 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
276 inline SlaveVP *
277 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
278 void *dataParam, void *stackLocs );
280 inline void
281 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
282 void *dataParam);
284 void
285 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
286 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
287 //WL: dissipate a SlaveVP by sending a request
289 void
290 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
292 void
293 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
294 #define VMS_PI__throw_exception VMS_int__throw_exception
295 #define VMS_WL__throw_exception VMS_int__throw_exception
297 void *
298 VMS_int__give_sem_env_for( SlaveVP *animSlv );
299 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
300 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
301 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
303 //============== Request Related ===============
305 void
306 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
308 inline void
309 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
311 inline void
312 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
314 void
315 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
317 void inline
318 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
320 inline void
321 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
323 VMSReqst *
324 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
326 inline void *
327 VMS_PI__take_sem_reqst_from( VMSReqst *req );
329 void inline
330 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
331 ResumeSlvFnPtr resumeSlvFnPtr );
333 //======================== MEASUREMENT ======================
334 uint64
335 VMS_WL__give_num_plugin_cycles();
336 uint32
337 VMS_WL__give_num_plugin_animations();
340 //========================= Utilities =======================
341 inline char *
342 VMS_int__strDup( char *str );
345 //========================= Probes =======================
346 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
348 //================================================
349 #endif /* _VMS_H */
