view VMS.h @ 231:88fd85921d7f

made compilable -- fixed couple naming bugs
author Some Random Person <seanhalle@yahoo.com>
date Thu, 15 Mar 2012 20:35:18 -0700
parents f2a7831352dc
children 421bde2a07d7
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;
33 typedef union
34 { uint32 lowHigh[2];
35 uint64 longVal;
36 }
37 TSCountLowHigh;
39 typedef struct _SchedSlot SchedSlot;
40 typedef struct _VMSReqst VMSReqst;
41 typedef struct _SlaveVP SlaveVP;
42 typedef struct _MasterVP MasterVP;
43 typedef struct _IntervalProbe IntervalProbe;
44 typedef struct _GateStruc GateStruc;
47 typedef SlaveVP *(*SlaveAssigner) ( void *, SchedSlot*); //semEnv, slot for HW info
48 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
49 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
50 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
51 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
53 //============================ HW Dependent Fns ================================
55 #include "Hardware_Dependent/VMS__HW_measurement.h"
56 #include "Hardware_Dependent/VMS__primitives.h"
58 //============================= Statistics ==================================
60 inline TSCount getTSCount();
62 //============= Request Related ===========
63 //
65 enum VMSReqstType //avoid starting enums at 0, for debug reasons
66 {
67 semantic = 1,
68 createReq,
69 dissipate,
70 VMSSemantic //goes with VMSSemReqst below
71 };
73 struct _VMSReqst
74 {
75 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
76 void *semReqData;
78 VMSReqst *nextReqst;
79 };
80 //VMSReqst
82 enum VMSSemReqstType //These are equivalent to semantic requests, but for
83 { // VMS's services available directly to app, like OS
84 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
85 openFile,
86 otherIO
87 };
89 typedef struct
90 { enum VMSSemReqstType reqType;
91 SlaveVP *requestingSlv;
92 char *nameStr; //for create probe
93 }
94 VMSSemReq;
97 //==================== Core data structures ===================
99 typedef struct
100 {
101 //for future expansion
102 }
103 SlotPerfInfo;
105 struct _SchedSlot
106 {
107 int workIsDone;
108 int needsSlaveAssigned;
109 SlaveVP *slaveAssignedToSlot;
111 int slotIdx; //needed by Holistic Model's data gathering
112 int coreOfSlot;
113 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
114 };
115 //SchedSlot
117 /*WARNING: re-arranging this data structure could cause Slv switching
118 * assembly code to fail -- hard-codes offsets of fields
119 */
120 struct _SlaveVP
121 { int slaveID; //each slave given a unique ID
122 int coreAnimatedBy;
123 void *startOfStack;
124 void *stackPtr;
125 void *framePtr;
126 void *resumeInstrPtr;
128 void *coreCtlrStartPt; //allows proto-runtime to be linked later
129 void *coreCtlrFramePtr; //restore before jmp back to core controller
130 void *coreCtlrStackPtr; //restore before jmp back to core controller
132 SchedSlot *schedSlot;
133 VMSReqst *requests;
135 void *semanticData; //this is live for the life of Slv
136 void *dataRetFromReq;//Used to return vals from plugin to Wrapper Lib
138 //=========== MEASUREMENT STUFF ==========
139 MEAS__Insert_Meas_Fields_into_Slave;
140 //========================================
142 float64 createPtInSecs; //have space but don't use on some configs
143 };
144 //SlaveVP
146 /*The one and only global variable, holds many odds and ends
147 */
148 typedef struct
149 { //The offsets of these fields are hard-coded into assembly
150 void *coreCtlrReturnPt; //offset of field used in asm
151 int32 masterLock __align_to_cacheline__; //used in asm
153 //============ below this, no asm uses the field offsets =============
155 //Basic VMS infrastructure
156 SlaveVP **masterVPs;
157 SchedSlot ***allSchedSlots;
159 //plugin related
160 SlaveAssigner slaveAssigner;
161 RequestHandler requestHandler;
162 void *semanticEnv;
164 //Slave creation
165 int32 numSlavesCreated; //gives ordering to processor creation
166 int32 numSlavesAlive; //used to detect fail-safe shutdown
168 //Initialization related
169 int32 setupComplete; //use while starting up coreCtlr
171 //Memory management related
172 MallocArrays *freeLists;
173 int32 amtOfOutstandingMem;//total currently allocated
175 //Work-stealing related
176 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
177 int32 workStealingLock;
180 //=========== MEASUREMENT STUFF =============
181 IntervalProbe **intervalProbes;
182 PrivDynArrayInfo *dynIntervalProbesInfo;
183 HashTable *probeNameHashTbl;
184 int32 masterCreateProbeID;
185 float64 createPtInSecs; //real-clock time VMS initialized
186 Histogram **measHists;
187 PrivDynArrayInfo *measHistsInfo;
188 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
189 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
190 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
191 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
192 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
193 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
194 //==========================================
195 }
196 MasterEnv;
198 //========================= Extra Stuff Data Strucs =======================
199 typedef struct
200 {
202 }
203 VMSExcp;
205 struct _GateStruc
206 {
207 int32 gateClosed;
208 int32 preGateProgress;
209 int32 waitProgress;
210 int32 exitProgress;
211 };
212 //GateStruc
214 //======================= OS Thread related ===============================
216 void * coreController( void *paramsIn ); //standard PThreads fn prototype
217 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
218 void animationMaster( void *initData, SlaveVP *masterVP );
221 typedef struct
222 {
223 void *endThdPt;
224 unsigned int coreNum;
225 }
226 ThdParams;
228 //============================= Global Vars ================================
230 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
232 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
233 ThdParams *coreCtlrThdParams [ NUM_CORES ];
235 pthread_mutex_t suspendLock;
236 pthread_cond_t suspendCond;
238 //========================= Function Prototypes ===========================
240 /* MEANING OF WL PI SS int
241 * These indicate which places the function is safe to use. They stand for:
242 * WL: Wrapper Library
243 * PI: Plugin
244 * SS: Startup and Shutdown
245 * int: internal to the VMS implementation
246 */
248 //========== Setup and shutdown ==========
249 void
250 VMS_SS__init();
252 void
253 VMS_SS__start_the_work_then_wait_until_done();
255 void
256 VMS_SS__shutdown();
258 void
259 VMS_SS__cleanup_at_end_of_shutdown();
262 //============== ===============
264 inline SlaveVP *
265 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
266 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
267 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
269 //Use this to create processor inside entry point & other places outside
270 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
271 SlaveVP *
272 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
274 inline SlaveVP *
275 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
276 void *dataParam, void *stackLocs );
278 inline void
279 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
280 void *dataParam);
282 void
283 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
284 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
285 //WL: dissipate a SlaveVP by sending a request
287 void
288 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
290 void
291 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
292 #define VMS_PI__throw_exception VMS_int__throw_exception
293 #define VMS_WL__throw_exception VMS_int__throw_exception
295 void *
296 VMS_int__give_sem_env_for( SlaveVP *animSlv );
297 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
298 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
299 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
301 //============== Request Related ===============
303 void
304 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
306 inline void
307 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
309 inline void
310 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
312 void
313 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
315 void inline
316 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
318 inline void
319 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
321 VMSReqst *
322 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
324 inline void *
325 VMS_PI__take_sem_reqst_from( VMSReqst *req );
327 void inline
328 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
329 ResumeSlvFnPtr resumeSlvFnPtr );
331 //======================== MEASUREMENT ======================
332 uint64
333 VMS_WL__give_num_plugin_cycles();
334 uint32
335 VMS_WL__give_num_plugin_animations();
338 //========================= Utilities =======================
339 inline char *
340 VMS_int__strDup( char *str );
343 //========================= Probes =======================
344 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
346 //================================================
347 #endif /* _VMS_H */