Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 243:227cd4d33d94
fixed pointing slave to a TLF, added ones that don't trash stack fixed names
| author | Sean <seanhalle@yahoo.com> |
|---|---|
| date | Thu, 17 May 2012 20:39:44 +0200 |
| parents | 7ed97c961901 |
| children | f1267bc7b342 |
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 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
80 openFile,
81 otherIO
82 };
84 typedef struct
85 { enum VMSSemReqstType reqType;
86 SlaveVP *requestingSlv;
87 char *nameStr; //for create probe
88 }
89 VMSSemReq;
92 //==================== Core data structures ===================
94 typedef struct
95 {
96 //for future expansion
97 }
98 SlotPerfInfo;
100 struct _AnimSlot
101 {
102 int workIsDone;
103 int needsSlaveAssigned;
104 SlaveVP *slaveAssignedToSlot;
106 int slotIdx; //needed by Holistic Model's data gathering
107 int coreSlotIsOn;
108 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
109 };
110 //AnimSlot
112 enum VPtype {
113 Slave = 1, //default
114 Master,
115 Shutdown,
116 Idle
117 };
119 /*This structure embodies the state of a slaveVP. It is reused for masterVP
120 * and shutdownVPs.
121 */
122 struct _SlaveVP
123 { //The offsets of these fields are hard-coded into assembly
124 void *stackPtr; //save the core's stack ptr when suspend
125 void *framePtr; //save core's frame ptr when suspend
126 void *resumeInstrPtr; //save core's program-counter when suspend
127 void *coreCtlrFramePtr; //restore before jmp back to core controller
128 void *coreCtlrStackPtr; //restore before jmp back to core controller
130 //============ below this, no fields are used in asm =============
132 int slaveID; //each slave given a globally unique ID
133 int coreAnimatedBy;
134 void *startOfStack; //used to free, and to point slave to Fn
135 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
136 int assignCount; //Each assign is for one work-unit, so IDs it
137 //note, a scheduling decision is uniquely identified by the triple:
138 // <slaveID, coreAnimatedBy, assignCount> -- used in record & replay
140 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
141 AnimSlot *animSlotAssignedTo;
142 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
143 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
145 //For using Slave as carrier for data
146 void *semanticData; //Lang saves lang-specific things in slave here
148 //=========== MEASUREMENT STUFF ==========
149 MEAS__Insert_Meas_Fields_into_Slave;
150 float64 createPtInSecs; //time VP created, in seconds
151 //========================================
152 };
153 //SlaveVP
156 /* The one and only global variable, holds many odds and ends
157 */
158 typedef struct
159 { //The offsets of these fields are hard-coded into assembly
160 void *coreCtlrReturnPt; //offset to this field used in asm
161 int8 falseSharePad1[256 - sizeof(void*)];
162 int32 masterLock; //offset to this field used in asm
163 int8 falseSharePad2[256 - sizeof(int32)];
164 //============ below this, no fields are used in asm =============
166 //Basic VMS infrastructure
167 SlaveVP **masterVPs;
168 AnimSlot ***allAnimSlots;
170 //plugin related
171 SlaveAssigner slaveAssigner;
172 RequestHandler requestHandler;
173 void *semanticEnv;
175 //Slave creation
176 int32 numSlavesCreated; //gives ordering to processor creation
177 int32 numSlavesAlive; //used to detect fail-safe shutdown
179 //Initialization related
180 int32 setupComplete; //use while starting up coreCtlr
182 //Memory management related
183 MallocArrays *freeLists;
184 int32 amtOfOutstandingMem;//total currently allocated
186 //=========== MEASUREMENT STUFF =============
187 IntervalProbe **intervalProbes;
188 PrivDynArrayInfo *dynIntervalProbesInfo;
189 HashTable *probeNameHashTbl;
190 int32 masterCreateProbeID;
191 float64 createPtInSecs; //real-clock time VMS initialized
192 Histogram **measHists;
193 PrivDynArrayInfo *measHistsInfo;
194 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
195 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
196 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
197 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
198 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
199 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
200 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
201 //==========================================
202 }
203 MasterEnv;
205 //========================= Extra Stuff Data Strucs =======================
206 typedef struct
207 {
209 }
210 VMSExcp;
212 //======================= OS Thread related ===============================
214 void * coreController( void *paramsIn ); //standard PThreads fn prototype
215 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
216 void animationMaster( void *initData, SlaveVP *masterVP );
219 typedef struct
220 {
221 void *endThdPt;
222 unsigned int coreNum;
223 }
224 ThdParams;
226 //============================= Global Vars ================================
228 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
230 //these are global, but only used for startup and shutdown
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 ===========================
238 /* MEANING OF WL PI SS int VMSOS
239 * These indicate which places the function is safe to use. They stand for:
240 *
241 * WL Wrapper Library -- wrapper lib code should only use these
242 * PI Plugin -- plugin code should only use these
243 * SS Startup and Shutdown -- designates these relate to startup & shutdown
244 * int internal to VMS -- should not be used in wrapper lib or plugin
245 * VMSOS means "OS functions for applications to use"
246 *
247 * VMS_int__ functions touch internal VMS data structs and are only safe
248 * to be used inside the master lock. However, occasionally, they appear
249 * in wrapper-lib or plugin code. In those cases, very careful analysis
250 * has been done to be sure no concurrency issues could arise.
251 *
252 * VMS_WL__ functions are all safe for use outside the master lock.
253 *
254 * VMSOS are only safe for applications to use -- they're like a second
255 * language mixed in -- but they can't be used inside plugin code, and
256 * aren't meant for use in wrapper libraries, because they are themselves
257 * wrapper-library calls!
258 */
259 //========== Startup and shutdown ==========
260 void
261 VMS_SS__init();
263 void
264 VMS_SS__start_the_work_then_wait_until_done();
266 SlaveVP*
267 VMS_SS__create_shutdown_slave();
269 void
270 VMS_SS__shutdown();
272 void
273 VMS_SS__cleanup_at_end_of_shutdown();
276 //============== ===============
278 inline SlaveVP *
279 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
280 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
281 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
283 //Use this to create processor inside entry point & other places outside
284 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
285 SlaveVP *
286 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
288 inline SlaveVP *
289 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
290 void *dataParam, void *stackLocs );
292 inline void
293 VMS_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
294 void *dataParam);
296 inline void
297 VMS_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr,
298 void *param);
300 inline void
301 VMS_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr,
302 void *param1, void *param2);
304 void
305 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
306 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
307 //WL: dissipate a SlaveVP by sending a request
309 void
310 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
312 void
313 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
314 #define VMS_PI__throw_exception VMS_int__throw_exception
315 #define VMS_WL__throw_exception VMS_int__throw_exception
317 void *
318 VMS_int__give_sem_env_for( SlaveVP *animSlv );
319 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
320 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
321 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
323 //============== Request Related ===============
325 void
326 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
328 inline void
329 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
331 inline void
332 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
334 void
335 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
337 void inline
338 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
340 inline void
341 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
343 VMSReqst *
344 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
346 inline void *
347 VMS_PI__take_sem_reqst_from( VMSReqst *req );
349 void inline
350 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
351 ResumeSlvFnPtr resumeSlvFnPtr );
353 //======================== MEASUREMENT ======================
354 uint64
355 VMS_WL__give_num_plugin_cycles();
356 uint32
357 VMS_WL__give_num_plugin_animations();
360 //========================= Utilities =======================
361 inline char *
362 VMS_int__strDup( char *str );
365 //========================= Probes =======================
366 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
368 //================================================
369 #endif /* _VMS_H */
