Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 235:ecbf6992dab4
debugging -- made master lock padding arch indep -- changed schedSlot to animSlot
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Fri, 16 Mar 2012 23:40:55 -0700 |
| parents | 0ee1a3c8972d |
| children | ce1f57e10fac |
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 _AnimSlot AnimSlot;
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 *, AnimSlot*); //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 * );
46 //=========== MEASUREMENT STUFF ==========
47 MEAS__Insert_Counter_Handler
48 //========================================
50 //============================ HW Dependent Fns ================================
52 #include "Hardware_Dependent/VMS__HW_measurement.h"
53 #include "Hardware_Dependent/VMS__primitives.h"
56 //============= Request Related ===========
57 //
59 enum VMSReqstType //avoid starting enums at 0, for debug reasons
60 {
61 semantic = 1,
62 createReq,
63 dissipate,
64 VMSSemantic //goes with VMSSemReqst below
65 };
67 struct _VMSReqst
68 {
69 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
70 void *semReqData;
72 VMSReqst *nextReqst;
73 };
74 //VMSReqst
76 enum VMSSemReqstType //These are equivalent to semantic requests, but for
77 { // VMS's services available directly to app, like OS
78 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
79 openFile,
80 otherIO
81 };
83 typedef struct
84 { enum VMSSemReqstType reqType;
85 SlaveVP *requestingSlv;
86 char *nameStr; //for create probe
87 }
88 VMSSemReq;
91 //==================== Core data structures ===================
93 typedef struct
94 {
95 //for future expansion
96 }
97 SlotPerfInfo;
99 struct _AnimSlot
100 {
101 int workIsDone;
102 int needsSlaveAssigned;
103 SlaveVP *slaveAssignedToSlot;
105 int slotIdx; //needed by Holistic Model's data gathering
106 int coreOfSlot;
107 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
108 };
109 //AnimSlot
111 enum VPtype {
112 Slave = 1, //default
113 Master,
114 Shutdown
115 };
117 /*This structure embodies the state of a slaveVP. It is reused for masterVP
118 * and shutdownVPs.
119 */
120 struct _SlaveVP
121 { //The offsets of these fields are hard-coded into assembly
122 void *stackPtr; //save the core's stack ptr when suspend
123 void *framePtr; //save core's frame ptr when suspend
124 void *resumeInstrPtr; //save core's program-counter when suspend
125 void *coreCtlrFramePtr; //restore before jmp back to core controller
126 void *coreCtlrStackPtr; //restore before jmp back to core controller
128 //============ below this, no fields are used in asm =============
130 int slaveID; //each slave given a globally unique ID
131 int coreAnimatedBy;
132 void *startOfStack; //used to free, and to point slave to Fn
133 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
134 int assignCount; //Each assign is for one work-unit, so IDs it
135 //note, a scheduling decision is uniquely identified by the triple:
136 // <slaveID, coreAnimatedBy, assignCount> -- used in record & replay
138 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
139 AnimSlot *animSlotAssignedTo;
140 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
141 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
143 //For using Slave as carrier for data
144 void *semanticData; //Lang saves lang-specific things in slave here
146 //=========== MEASUREMENT STUFF ==========
147 MEAS__Insert_Meas_Fields_into_Slave;
148 float64 createPtInSecs; //time VP created, in seconds
149 //========================================
150 };
151 //SlaveVP
154 /* The one and only global variable, holds many odds and ends
155 */
156 typedef struct
157 { //The offsets of these fields are hard-coded into assembly
158 void *coreCtlrReturnPt; //offset of field used in asm
159 int8 falseSharePad1[256 - sizeof(void*)];
160 int32 masterLock; //offset of field used in asm
161 int8 falseSharePad2[256 - sizeof(int32)];
162 //============ below this, no fields are used in asm =============
164 //Basic VMS infrastructure
165 SlaveVP **masterVPs;
166 AnimSlot ***allAnimSlots;
168 //plugin related
169 SlaveAssigner slaveAssigner;
170 RequestHandler requestHandler;
171 void *semanticEnv;
173 //Slave creation
174 int32 numSlavesCreated; //gives ordering to processor creation
175 int32 numSlavesAlive; //used to detect fail-safe shutdown
177 //Initialization related
178 int32 setupComplete; //use while starting up coreCtlr
180 //Memory management related
181 MallocArrays *freeLists;
182 int32 amtOfOutstandingMem;//total currently allocated
184 //=========== MEASUREMENT STUFF =============
185 IntervalProbe **intervalProbes;
186 PrivDynArrayInfo *dynIntervalProbesInfo;
187 HashTable *probeNameHashTbl;
188 int32 masterCreateProbeID;
189 float64 createPtInSecs; //real-clock time VMS initialized
190 Histogram **measHists;
191 PrivDynArrayInfo *measHistsInfo;
192 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
193 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
194 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
195 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
196 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
197 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
198 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
199 //==========================================
200 }
201 MasterEnv;
203 //========================= Extra Stuff Data Strucs =======================
204 typedef struct
205 {
207 }
208 VMSExcp;
210 //======================= OS Thread related ===============================
212 void * coreController( void *paramsIn ); //standard PThreads fn prototype
213 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
214 void animationMaster( void *initData, SlaveVP *masterVP );
217 typedef struct
218 {
219 void *endThdPt;
220 unsigned int coreNum;
221 }
222 ThdParams;
224 //============================= Global Vars ================================
226 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
228 //these are global, but only used for startup and shutdown
229 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
230 ThdParams *coreCtlrThdParams [ NUM_CORES ];
232 pthread_mutex_t suspendLock;
233 pthread_cond_t suspendCond;
235 //========================= Function Prototypes ===========================
236 /* MEANING OF WL PI SS int VMSOS
237 * These indicate which places the function is safe to use. They stand for:
238 *
239 * WL Wrapper Library -- wrapper lib code should only use these
240 * PI Plugin -- plugin code should only use these
241 * SS Startup and Shutdown -- designates these relate to startup & shutdown
242 * int internal to VMS -- should not be used in wrapper lib or plugin
243 * VMSOS means "OS functions for applications to use"
244 *
245 * VMS_int__ functions touch internal VMS data structs and are only safe
246 * to be used inside the master lock. However, occasionally, they appear
247 * in wrapper-lib or plugin code. In those cases, very careful analysis
248 * has been done to be sure no concurrency issues could arise.
249 *
250 * VMS_WL__ functions are all safe for use outside the master lock.
251 *
252 * VMSOS are only safe for applications to use -- they're like a second
253 * language mixed in -- but they can't be used inside plugin code, and
254 * aren't meant for use in wrapper libraries, because they are themselves
255 * wrapper-library calls!
256 */
257 //========== Startup and shutdown ==========
258 void
259 VMS_SS__init();
261 void
262 VMS_SS__start_the_work_then_wait_until_done();
264 SlaveVP*
265 VMS_SS__create_shutdown_slave();
267 void
268 VMS_SS__shutdown();
270 void
271 VMS_SS__cleanup_at_end_of_shutdown();
274 //============== ===============
276 inline SlaveVP *
277 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
278 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
279 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
281 //Use this to create processor inside entry point & other places outside
282 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
283 SlaveVP *
284 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
286 inline SlaveVP *
287 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
288 void *dataParam, void *stackLocs );
290 inline void
291 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
292 void *dataParam);
294 void
295 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
296 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
297 //WL: dissipate a SlaveVP by sending a request
299 void
300 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
302 void
303 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
304 #define VMS_PI__throw_exception VMS_int__throw_exception
305 #define VMS_WL__throw_exception VMS_int__throw_exception
307 void *
308 VMS_int__give_sem_env_for( SlaveVP *animSlv );
309 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
310 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
311 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
313 //============== Request Related ===============
315 void
316 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
318 inline void
319 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
321 inline void
322 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
324 void
325 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
327 void inline
328 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
330 inline void
331 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
333 VMSReqst *
334 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
336 inline void *
337 VMS_PI__take_sem_reqst_from( VMSReqst *req );
339 void inline
340 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
341 ResumeSlvFnPtr resumeSlvFnPtr );
343 //======================== MEASUREMENT ======================
344 uint64
345 VMS_WL__give_num_plugin_cycles();
346 uint32
347 VMS_WL__give_num_plugin_animations();
350 //========================= Utilities =======================
351 inline char *
352 VMS_int__strDup( char *str );
355 //========================= Probes =======================
356 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
358 //================================================
359 #endif /* _VMS_H */
