view VMS.h @ 234:0ee1a3c8972d

Merged Nina's fix of assembly with Sean's comments and cleanup
author Some Random Person <seanhalle@yahoo.com>
date Fri, 16 Mar 2012 10:43:15 -0700
parents a0ac58d8201c 125f0f90a0d3
children ecbf6992dab4
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 _SchedSlot SchedSlot;
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 *, SchedSlot*); //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 _SchedSlot
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 //SchedSlot
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 =============
129 int slaveID; //each slave given a globally unique ID
130 int coreAnimatedBy;
131 void *startOfStack; //used to free, and to point slave to Fn
133 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
134 SchedSlot *schedSlotAssignedTo;
135 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
136 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
138 //Slave used as carrier for data
139 void *semanticData; //Lang saves lang-specific things in slave here
141 //=========== MEASUREMENT STUFF ==========
142 MEAS__Insert_Meas_Fields_into_Slave;
143 //========================================
145 enum VPtype type;
146 int numTimesAssigned;
148 float64 createPtInSecs; //have space but don't use on some configs
149 };
150 //SlaveVP
153 /* The one and only global variable, holds many odds and ends
154 */
155 typedef struct
156 { //The offsets of these fields are hard-coded into assembly
157 void *coreCtlrReturnPt; //offset of field used in asm
158 int32 masterLock __align_to_cacheline__; //used in asm
160 //============ below this, no fields are used in asm =============
162 //Basic VMS infrastructure
163 SlaveVP **masterVPs;
164 SchedSlot ***allSchedSlots;
166 //plugin related
167 SlaveAssigner slaveAssigner;
168 RequestHandler requestHandler;
169 void *semanticEnv;
171 //Slave creation
172 int32 numSlavesCreated; //gives ordering to processor creation
173 int32 numSlavesAlive; //used to detect fail-safe shutdown
175 //Initialization related
176 int32 setupComplete; //use while starting up coreCtlr
178 //Memory management related
179 MallocArrays *freeLists;
180 int32 amtOfOutstandingMem;//total currently allocated
182 //=========== MEASUREMENT STUFF =============
183 IntervalProbe **intervalProbes;
184 PrivDynArrayInfo *dynIntervalProbesInfo;
185 HashTable *probeNameHashTbl;
186 int32 masterCreateProbeID;
187 float64 createPtInSecs; //real-clock time VMS initialized
188 Histogram **measHists;
189 PrivDynArrayInfo *measHistsInfo;
190 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
191 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
192 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
193 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
194 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
195 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
196 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
197 //==========================================
198 }
199 MasterEnv;
201 //========================= Extra Stuff Data Strucs =======================
202 typedef struct
203 {
205 }
206 VMSExcp;
208 //======================= OS Thread related ===============================
210 void * coreController( void *paramsIn ); //standard PThreads fn prototype
211 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
212 void animationMaster( void *initData, SlaveVP *masterVP );
215 typedef struct
216 {
217 void *endThdPt;
218 unsigned int coreNum;
219 }
220 ThdParams;
222 //============================= Global Vars ================================
224 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
226 //these are global, but only used for startup and shutdown
227 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
228 ThdParams *coreCtlrThdParams [ NUM_CORES ];
230 pthread_mutex_t suspendLock;
231 pthread_cond_t suspendCond;
233 //========================= Function Prototypes ===========================
234 /* MEANING OF WL PI SS int VMSOS
235 * These indicate which places the function is safe to use. They stand for:
236 *
237 * WL Wrapper Library -- wrapper lib code should only use these
238 * PI Plugin -- plugin code should only use these
239 * SS Startup and Shutdown -- designates these relate to startup & shutdown
240 * int internal to VMS -- should not be used in wrapper lib or plugin
241 * VMSOS means "OS functions for applications to use"
242 *
243 * VMS_int__ functions touch internal VMS data structs and are only safe
244 * to be used inside the master lock. However, occasionally, they appear
245 * in wrapper-lib or plugin code. In those cases, very careful analysis
246 * has been done to be sure no concurrency issues could arise.
247 *
248 * VMS_WL__ functions are all safe for use outside the master lock.
249 *
250 * VMSOS are only safe for applications to use -- they're like a second
251 * language mixed in -- but they can't be used inside plugin code, and
252 * aren't meant for use in wrapper libraries, because they are themselves
253 * wrapper-library calls!
254 */
255 //========== Startup and shutdown ==========
256 void
257 VMS_SS__init();
259 void
260 VMS_SS__start_the_work_then_wait_until_done();
262 SlaveVP*
263 VMS_SS__create_shutdown_slave();
265 void
266 VMS_SS__shutdown();
268 void
269 VMS_SS__cleanup_at_end_of_shutdown();
272 //============== ===============
274 inline SlaveVP *
275 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
276 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
277 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
279 //Use this to create processor inside entry point & other places outside
280 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
281 SlaveVP *
282 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
284 inline SlaveVP *
285 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
286 void *dataParam, void *stackLocs );
288 inline void
289 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
290 void *dataParam);
292 void
293 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
294 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
295 //WL: dissipate a SlaveVP by sending a request
297 void
298 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
300 void
301 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
302 #define VMS_PI__throw_exception VMS_int__throw_exception
303 #define VMS_WL__throw_exception VMS_int__throw_exception
305 void *
306 VMS_int__give_sem_env_for( SlaveVP *animSlv );
307 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
308 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
309 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
311 //============== Request Related ===============
313 void
314 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
316 inline void
317 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
319 inline void
320 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
322 void
323 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
325 void inline
326 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
328 inline void
329 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
331 VMSReqst *
332 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
334 inline void *
335 VMS_PI__take_sem_reqst_from( VMSReqst *req );
337 void inline
338 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
339 ResumeSlvFnPtr resumeSlvFnPtr );
341 //======================== MEASUREMENT ======================
342 uint64
343 VMS_WL__give_num_plugin_cycles();
344 uint32
345 VMS_WL__give_num_plugin_animations();
348 //========================= Utilities =======================
349 inline char *
350 VMS_int__strDup( char *str );
353 //========================= Probes =======================
354 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
356 //================================================
357 #endif /* _VMS_H */