VMS/VMS_Implementations/VMS_impls/VMS__MC_shared_impl

view VMS.h @ 248:da08f9717024

Moved VMS_defs__turn_on_and_off.h outside of VMS repo, into project repo
author Sean Halle <seanhalle@yahoo.com>
date Sat, 21 Jul 2012 15:20:40 -0700
parents f1267bc7b342
children f5b110414453 3740ac9cffee
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 "DynArray/DynArray.h"
14 #include "Hash_impl/PrivateHash.h"
15 #include "Histogram/Histogram.h"
16 #include "Queue_impl/PrivateQueue.h"
18 #include "VMS_primitive_data_types.h"
19 #include "Services_Offered_by_VMS/Memory_Handling/vmalloc.h"
21 #include <pthread.h>
22 #include <sys/time.h>
24 //================= Defines: included from separate files =================
25 //
26 // Note: ALL defines are in other files, none are in here
27 //
28 #include "Defines/VMS_defs.h"
31 //================================ Typedefs =================================
32 //
33 typedef unsigned long long TSCount;
35 typedef struct _AnimSlot AnimSlot;
36 typedef struct _VMSReqst VMSReqst;
37 typedef struct _SlaveVP SlaveVP;
38 typedef struct _MasterVP MasterVP;
39 typedef struct _IntervalProbe IntervalProbe;
42 typedef SlaveVP *(*SlaveAssigner) ( void *, AnimSlot*); //semEnv, slot for HW info
43 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
44 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
45 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
46 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
47 //=========== MEASUREMENT STUFF ==========
48 MEAS__Insert_Counter_Handler
49 //========================================
51 //============================ HW Dependent Fns ================================
53 #include "HW_Dependent_Primitives/VMS__HW_measurement.h"
54 #include "HW_Dependent_Primitives/VMS__primitives.h"
57 //============= Request Related ===========
58 //
60 enum VMSReqstType //avoid starting enums at 0, for debug reasons
61 {
62 semantic = 1,
63 createReq,
64 dissipate,
65 VMSSemantic //goes with VMSSemReqst below
66 };
68 struct _VMSReqst
69 {
70 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
71 void *semReqData;
73 VMSReqst *nextReqst;
74 };
75 //VMSReqst
77 enum VMSSemReqstType //These are equivalent to semantic requests, but for
78 { // VMS's services available directly to app, like OS
79 make_probe = 1, // and probe services -- like a VMS-wide built-in lang
80 throw_excp,
81 openFile,
82 otherIO
83 };
85 typedef struct
86 { enum VMSSemReqstType reqType;
87 SlaveVP *requestingSlv;
88 char *nameStr; //for create probe
89 char *msgStr; //for exception
90 void *exceptionData;
91 }
92 VMSSemReq;
95 //==================== Core data structures ===================
97 typedef struct
98 {
99 //for future expansion
100 }
101 SlotPerfInfo;
103 struct _AnimSlot
104 {
105 int workIsDone;
106 int needsSlaveAssigned;
107 SlaveVP *slaveAssignedToSlot;
109 int slotIdx; //needed by Holistic Model's data gathering
110 int coreSlotIsOn;
111 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
112 };
113 //AnimSlot
115 enum VPtype {
116 Slave = 1, //default
117 Master,
118 Shutdown,
119 Idle
120 };
122 /*This structure embodies the state of a slaveVP. It is reused for masterVP
123 * and shutdownVPs.
124 */
125 struct _SlaveVP
126 { //The offsets of these fields are hard-coded into assembly
127 void *stackPtr; //save the core's stack ptr when suspend
128 void *framePtr; //save core's frame ptr when suspend
129 void *resumeInstrPtr; //save core's program-counter when suspend
130 void *coreCtlrFramePtr; //restore before jmp back to core controller
131 void *coreCtlrStackPtr; //restore before jmp back to core controller
133 //============ below this, no fields are used in asm =============
135 int slaveID; //each slave given a globally unique ID
136 int coreAnimatedBy;
137 void *startOfStack; //used to free, and to point slave to Fn
138 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
139 int assignCount; //Each assign is for one work-unit, so IDs it
140 //note, a scheduling decision is uniquely identified by the triple:
141 // <slaveID, coreAnimatedBy, assignCount> -- used in record & replay
143 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
144 AnimSlot *animSlotAssignedTo;
145 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
146 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
148 //For using Slave as carrier for data
149 void *semanticData; //Lang saves lang-specific things in slave here
151 //=========== MEASUREMENT STUFF ==========
152 MEAS__Insert_Meas_Fields_into_Slave;
153 float64 createPtInSecs; //time VP created, in seconds
154 //========================================
155 };
156 //SlaveVP
159 /* The one and only global variable, holds many odds and ends
160 */
161 typedef struct
162 { //The offsets of these fields are hard-coded into assembly
163 void *coreCtlrReturnPt; //offset to this field used in asm
164 int8 falseSharePad1[256 - sizeof(void*)];
165 int32 masterLock; //offset to this field used in asm
166 int8 falseSharePad2[256 - sizeof(int32)];
167 //============ below this, no fields are used in asm =============
169 //Basic VMS infrastructure
170 SlaveVP **masterVPs;
171 AnimSlot ***allAnimSlots;
173 //plugin related
174 SlaveAssigner slaveAssigner;
175 RequestHandler requestHandler;
176 void *semanticEnv;
178 //Slave creation
179 int32 numSlavesCreated; //gives ordering to processor creation
180 int32 numSlavesAlive; //used to detect fail-safe shutdown
182 //Initialization related
183 int32 setupComplete; //use while starting up coreCtlr
185 //Memory management related
186 MallocArrays *freeLists;
187 int32 amtOfOutstandingMem;//total currently allocated
189 //Random number seeds -- random nums used in various places
190 uint32_t seed1;
191 uint32_t seed2;
193 //=========== MEASUREMENT STUFF =============
194 IntervalProbe **intervalProbes;
195 PrivDynArrayInfo *dynIntervalProbesInfo;
196 HashTable *probeNameHashTbl;
197 int32 masterCreateProbeID;
198 float64 createPtInSecs; //real-clock time VMS initialized
199 Histogram **measHists;
200 PrivDynArrayInfo *measHistsInfo;
201 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
202 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
203 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
204 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
205 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
206 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
207 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
208 //==========================================
209 }
210 MasterEnv;
212 //========================= Extra Stuff Data Strucs =======================
213 typedef struct
214 {
216 }
217 VMSExcp;
219 //======================= OS Thread related ===============================
221 void * coreController( void *paramsIn ); //standard PThreads fn prototype
222 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
223 void animationMaster( void *initData, SlaveVP *masterVP );
226 typedef struct
227 {
228 void *endThdPt;
229 unsigned int coreNum;
230 }
231 ThdParams;
233 //============================= Global Vars ================================
235 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
237 //these are global, but only used for startup and shutdown
238 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
239 ThdParams *coreCtlrThdParams [ NUM_CORES ];
241 pthread_mutex_t suspendLock;
242 pthread_cond_t suspendCond;
244 //========================= Function Prototypes ===========================
245 /* MEANING OF WL PI SS int VMSOS
246 * These indicate which places the function is safe to use. They stand for:
247 *
248 * WL Wrapper Library -- wrapper lib code should only use these
249 * PI Plugin -- plugin code should only use these
250 * SS Startup and Shutdown -- designates these relate to startup & shutdown
251 * int internal to VMS -- should not be used in wrapper lib or plugin
252 * VMSOS means "OS functions for applications to use"
253 *
254 * VMS_int__ functions touch internal VMS data structs and are only safe
255 * to be used inside the master lock. However, occasionally, they appear
256 * in wrapper-lib or plugin code. In those cases, very careful analysis
257 * has been done to be sure no concurrency issues could arise.
258 *
259 * VMS_WL__ functions are all safe for use outside the master lock.
260 *
261 * VMSOS are only safe for applications to use -- they're like a second
262 * language mixed in -- but they can't be used inside plugin code, and
263 * aren't meant for use in wrapper libraries, because they are themselves
264 * wrapper-library calls!
265 */
266 //========== Startup and shutdown ==========
267 void
268 VMS_SS__init();
270 void
271 VMS_SS__start_the_work_then_wait_until_done();
273 SlaveVP*
274 VMS_SS__create_shutdown_slave();
276 void
277 VMS_SS__shutdown();
279 void
280 VMS_SS__cleanup_at_end_of_shutdown();
283 //============== ===============
285 inline SlaveVP *
286 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
287 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
288 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
290 //Use this to create processor inside entry point & other places outside
291 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
292 SlaveVP *
293 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
295 inline SlaveVP *
296 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
297 void *dataParam, void *stackLocs );
299 inline void
300 VMS_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
301 void *dataParam);
303 inline void
304 VMS_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr,
305 void *param);
307 inline void
308 VMS_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr,
309 void *param1, void *param2);
311 void
312 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
313 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
314 //WL: dissipate a SlaveVP by sending a request
316 void
317 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
319 void
320 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
321 #define VMS_PI__throw_exception VMS_int__throw_exception
322 void
323 VMS_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
324 #define VMS_App__throw_exception VMS_WL__throw_exception
326 void *
327 VMS_int__give_sem_env_for( SlaveVP *animSlv );
328 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
329 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
330 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
333 inline void
334 VMS_int__get_master_lock();
336 #define VMS_int__release_master_lock() _VMSMasterEnv->masterLock = UNLOCKED
338 inline uint32_t
339 VMS_int__randomNumber();
341 //============== Request Related ===============
343 void
344 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
346 inline void
347 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
349 inline void
350 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
352 void
353 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
355 void inline
356 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
358 inline void
359 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
361 VMSReqst *
362 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
363 //#define VMS_PI__take_next_request_out_of( slave ) slave->requests
365 //inline void *
366 //VMS_PI__take_sem_reqst_from( VMSReqst *req );
367 #define VMS_PI__take_sem_reqst_from( req ) req->semReqData
369 void inline
370 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
371 ResumeSlvFnPtr resumeSlvFnPtr );
373 //======================== MEASUREMENT ======================
374 uint64
375 VMS_WL__give_num_plugin_cycles();
376 uint32
377 VMS_WL__give_num_plugin_animations();
380 //========================= Utilities =======================
381 inline char *
382 VMS_int__strDup( char *str );
385 //========================= Probes =======================
386 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
388 //================================================
389 #endif /* _VMS_H */