Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 233:a0ac58d8201c
cleaning -- more general rearrangement, moving things and adding comments
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Fri, 16 Mar 2012 09:39:53 -0700 |
| parents | 421bde2a07d7 |
| 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;
34 typedef struct _SchedSlot SchedSlot;
35 typedef struct _VMSReqst VMSReqst;
36 typedef struct _SlaveVP SlaveVP;
37 typedef struct _MasterVP MasterVP;
38 typedef struct _IntervalProbe IntervalProbe;
41 typedef SlaveVP *(*SlaveAssigner) ( void *, SchedSlot*); //semEnv, slot for HW info
42 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
43 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
44 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
45 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
47 //============================ HW Dependent Fns ================================
49 #include "Hardware_Dependent/VMS__HW_measurement.h"
50 #include "Hardware_Dependent/VMS__primitives.h"
53 //============= Request Related ===========
54 //
56 enum VMSReqstType //avoid starting enums at 0, for debug reasons
57 {
58 semantic = 1,
59 createReq,
60 dissipate,
61 VMSSemantic //goes with VMSSemReqst below
62 };
64 struct _VMSReqst
65 {
66 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
67 void *semReqData;
69 VMSReqst *nextReqst;
70 };
71 //VMSReqst
73 enum VMSSemReqstType //These are equivalent to semantic requests, but for
74 { // VMS's services available directly to app, like OS
75 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
76 openFile,
77 otherIO
78 };
80 typedef struct
81 { enum VMSSemReqstType reqType;
82 SlaveVP *requestingSlv;
83 char *nameStr; //for create probe
84 }
85 VMSSemReq;
88 //==================== Core data structures ===================
90 typedef struct
91 {
92 //for future expansion
93 }
94 SlotPerfInfo;
96 struct _SchedSlot
97 {
98 int workIsDone;
99 int needsSlaveAssigned;
100 SlaveVP *slaveAssignedToSlot;
102 int slotIdx; //needed by Holistic Model's data gathering
103 int coreOfSlot;
104 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
105 };
106 //SchedSlot
108 /*This structure embodies the state of a slaveVP. It is reused for masterVP
109 * and shutdownVPs.
110 */
111 struct _SlaveVP
112 { //The offsets of these fields are hard-coded into assembly
113 void *stackPtr; //save the core's stack ptr when suspend
114 void *framePtr; //save core's frame ptr when suspend
115 void *resumeInstrPtr; //save core's program-counter when suspend
116 void *coreCtlrFramePtr; //restore before jmp back to core controller
117 void *coreCtlrStackPtr; //restore before jmp back to core controller
119 //============ below this, no fields are used in asm =============
120 int slaveID; //each slave given a globally unique ID
121 int coreAnimatedBy;
122 void *startOfStack; //used to free, and to point slave to Fn
124 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
125 SchedSlot *schedSlotAssignedTo;
126 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
127 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
129 //Slave used as carrier for data
130 void *semanticData; //Lang saves lang-specific things in slave here
132 //=========== MEASUREMENT STUFF ==========
133 MEAS__Insert_Meas_Fields_into_Slave;
134 //========================================
136 float64 createPtInSecs; //have space but don't use on some configs
137 };
138 //SlaveVP
141 /* The one and only global variable, holds many odds and ends
142 */
143 typedef struct
144 { //The offsets of these fields are hard-coded into assembly
145 void *coreCtlrReturnPt; //offset of field used in asm
146 int32 masterLock __align_to_cacheline__; //used in asm
148 //============ below this, no fields are used in asm =============
150 //Basic VMS infrastructure
151 SlaveVP **masterVPs;
152 SchedSlot ***allSchedSlots;
154 //plugin related
155 SlaveAssigner slaveAssigner;
156 RequestHandler requestHandler;
157 void *semanticEnv;
159 //Slave creation
160 int32 numSlavesCreated; //gives ordering to processor creation
161 int32 numSlavesAlive; //used to detect fail-safe shutdown
163 //Initialization related
164 int32 setupComplete; //use while starting up coreCtlr
166 //Memory management related
167 MallocArrays *freeLists;
168 int32 amtOfOutstandingMem;//total currently allocated
170 //=========== MEASUREMENT STUFF =============
171 IntervalProbe **intervalProbes;
172 PrivDynArrayInfo *dynIntervalProbesInfo;
173 HashTable *probeNameHashTbl;
174 int32 masterCreateProbeID;
175 float64 createPtInSecs; //real-clock time VMS initialized
176 Histogram **measHists;
177 PrivDynArrayInfo *measHistsInfo;
178 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
179 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
180 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
181 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
182 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
183 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
184 //==========================================
185 }
186 MasterEnv;
188 //========================= Extra Stuff Data Strucs =======================
189 typedef struct
190 {
192 }
193 VMSExcp;
195 //======================= OS Thread related ===============================
197 void * coreController( void *paramsIn ); //standard PThreads fn prototype
198 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
199 void animationMaster( void *initData, SlaveVP *masterVP );
202 typedef struct
203 {
204 void *endThdPt;
205 unsigned int coreNum;
206 }
207 ThdParams;
209 //============================= Global Vars ================================
211 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
213 //these are global, but only used for startup and shutdown
214 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
215 ThdParams *coreCtlrThdParams [ NUM_CORES ];
217 pthread_mutex_t suspendLock;
218 pthread_cond_t suspendCond;
220 //========================= Function Prototypes ===========================
221 /* MEANING OF WL PI SS int VMSOS
222 * These indicate which places the function is safe to use. They stand for:
223 *
224 * WL Wrapper Library -- wrapper lib code should only use these
225 * PI Plugin -- plugin code should only use these
226 * SS Startup and Shutdown -- designates these relate to startup & shutdown
227 * int internal to VMS -- should not be used in wrapper lib or plugin
228 * VMSOS means "OS functions for applications to use"
229 *
230 * VMS_int__ functions touch internal VMS data structs and are only safe
231 * to be used inside the master lock. However, occasionally, they appear
232 * in wrapper-lib or plugin code. In those cases, very careful analysis
233 * has been done to be sure no concurrency issues could arise.
234 *
235 * VMS_WL__ functions are all safe for use outside the master lock.
236 *
237 * VMSOS are only safe for applications to use -- they're like a second
238 * language mixed in -- but they can't be used inside plugin code, and
239 * aren't meant for use in wrapper libraries, because they are themselves
240 * wrapper-library calls!
241 */
242 //========== Startup and shutdown ==========
243 void
244 VMS_SS__init();
246 void
247 VMS_SS__start_the_work_then_wait_until_done();
249 void
250 VMS_SS__shutdown();
252 void
253 VMS_SS__cleanup_at_end_of_shutdown();
256 //============== ===============
258 inline SlaveVP *
259 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
260 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
261 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
263 //Use this to create processor inside entry point & other places outside
264 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
265 SlaveVP *
266 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
268 inline SlaveVP *
269 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
270 void *dataParam, void *stackLocs );
272 inline void
273 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
274 void *dataParam);
276 void
277 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
278 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
279 //WL: dissipate a SlaveVP by sending a request
281 void
282 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
284 void
285 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
286 #define VMS_PI__throw_exception VMS_int__throw_exception
287 #define VMS_WL__throw_exception VMS_int__throw_exception
289 void *
290 VMS_int__give_sem_env_for( SlaveVP *animSlv );
291 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
292 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
293 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
295 //============== Request Related ===============
297 void
298 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
300 inline void
301 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
303 inline void
304 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
306 void
307 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
309 void inline
310 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
312 inline void
313 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
315 VMSReqst *
316 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
318 inline void *
319 VMS_PI__take_sem_reqst_from( VMSReqst *req );
321 void inline
322 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
323 ResumeSlvFnPtr resumeSlvFnPtr );
325 //======================== MEASUREMENT ======================
326 uint64
327 VMS_WL__give_num_plugin_cycles();
328 uint32
329 VMS_WL__give_num_plugin_animations();
332 //========================= Utilities =======================
333 inline char *
334 VMS_int__strDup( char *str );
337 //========================= Probes =======================
338 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
340 //================================================
341 #endif /* _VMS_H */
