Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 264:3740ac9cffee
Added communication system, given from VMS to the plugin, for use by assigner
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Fri, 09 Nov 2012 04:20:31 -0800 |
| parents | 4c7414df4f0e |
| children |
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;
177 VMSCommNode *commSystemTopNode; //performance info for assigner
179 //Slave creation
180 int32 numSlavesCreated; //gives ordering to processor creation
181 int32 numSlavesAlive; //used to detect fail-safe shutdown
183 //Initialization related
184 int32 setupComplete; //use while starting up coreCtlr
186 //Memory management related
187 MallocArrays *freeLists;
188 int32 amtOfOutstandingMem;//total currently allocated
190 //Random number seeds -- random nums used in various places
191 uint32_t seed1;
192 uint32_t seed2;
194 //=========== MEASUREMENT STUFF =============
195 IntervalProbe **intervalProbes;
196 PrivDynArrayInfo *dynIntervalProbesInfo;
197 HashTable *probeNameHashTbl;
198 int32 masterCreateProbeID;
199 float64 createPtInSecs; //real-clock time VMS initialized
200 Histogram **measHists;
201 PrivDynArrayInfo *measHistsInfo;
202 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
203 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
204 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
205 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
206 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
207 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
208 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
209 //==========================================
210 }
211 MasterEnv;
213 //========================= Extra Stuff Data Strucs =======================
214 typedef struct
215 {
217 }
218 VMSExcp;
220 //======================= OS Thread related ===============================
222 void * coreController( void *paramsIn ); //standard PThreads fn prototype
223 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
224 void animationMaster( void *initData, SlaveVP *masterVP );
227 typedef struct
228 {
229 void *endThdPt;
230 unsigned int coreNum;
231 }
232 ThdParams;
234 //============================= Global Vars ================================
236 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
238 //these are global, but only used for startup and shutdown
239 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
240 ThdParams *coreCtlrThdParams [ NUM_CORES ];
242 pthread_mutex_t suspendLock;
243 pthread_cond_t suspendCond;
245 //========================= Function Prototypes ===========================
246 /* MEANING OF WL PI SS int VMSOS
247 * These indicate which places the function is safe to use. They stand for:
248 *
249 * WL Wrapper Library -- wrapper lib code should only use these
250 * PI Plugin -- plugin code should only use these
251 * SS Startup and Shutdown -- designates these relate to startup & shutdown
252 * int internal to VMS -- should not be used in wrapper lib or plugin
253 * VMSOS means "OS functions for applications to use"
254 *
255 * VMS_int__ functions touch internal VMS data structs and are only safe
256 * to be used inside the master lock. However, occasionally, they appear
257 * in wrapper-lib or plugin code. In those cases, very careful analysis
258 * has been done to be sure no concurrency issues could arise.
259 *
260 * VMS_WL__ functions are all safe for use outside the master lock.
261 *
262 * VMSOS are only safe for applications to use -- they're like a second
263 * language mixed in -- but they can't be used inside plugin code, and
264 * aren't meant for use in wrapper libraries, because they are themselves
265 * wrapper-library calls!
266 */
267 //========== Startup and shutdown ==========
268 void
269 VMS_SS__init();
271 void
272 VMS_SS__start_the_work_then_wait_until_done();
274 SlaveVP*
275 VMS_SS__create_shutdown_slave();
277 void
278 VMS_SS__shutdown();
280 void
281 VMS_SS__cleanup_at_end_of_shutdown();
284 //============== ===============
286 inline SlaveVP *
287 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
288 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
289 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
291 //Use this to create processor inside entry point & other places outside
292 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
293 SlaveVP *
294 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
296 inline SlaveVP *
297 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
298 void *dataParam, void *stackLocs );
300 inline void
301 VMS_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
302 void *dataParam);
304 inline void
305 VMS_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr,
306 void *param);
308 inline void
309 VMS_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr,
310 void *param1, void *param2);
312 void
313 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
314 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
315 //WL: dissipate a SlaveVP by sending a request
317 void
318 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
320 void
321 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
322 #define VMS_PI__throw_exception VMS_int__throw_exception
323 void
324 VMS_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
325 #define VMS_App__throw_exception VMS_WL__throw_exception
327 void *
328 VMS_int__give_sem_env_for( SlaveVP *animSlv );
329 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
330 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
331 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
334 inline void
335 VMS_int__get_master_lock();
337 #define VMS_int__release_master_lock() _VMSMasterEnv->masterLock = UNLOCKED
339 inline uint32_t
340 VMS_int__randomNumber();
342 //============== Request Related ===============
344 void
345 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
347 inline void
348 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
350 inline void
351 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
353 void
354 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
356 void inline
357 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
359 inline void
360 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
362 VMSReqst *
363 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
364 //#define VMS_PI__take_next_request_out_of( slave ) slave->requests
366 //inline void *
367 //VMS_PI__take_sem_reqst_from( VMSReqst *req );
368 #define VMS_PI__take_sem_reqst_from( req ) req->semReqData
370 void inline
371 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
372 ResumeSlvFnPtr resumeSlvFnPtr );
374 //======================== MEASUREMENT ======================
375 uint64
376 VMS_WL__give_num_plugin_cycles();
377 uint32
378 VMS_WL__give_num_plugin_animations();
381 //========================= Utilities =======================
382 inline char *
383 VMS_int__strDup( char *str );
386 //========================= Probes =======================
387 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
389 //================================================
390 #endif /* _VMS_H */
