view VMS.h @ 225:309559064073

Working on shutdown bug -- shutdown puts shutdown slaves direct into sched slots
author Some Random Person <seanhalle@yahoo.com>
date Thu, 15 Mar 2012 04:11:55 -0700
parents b0b93147adfb
children ea70fa57776e
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 *, int, SchedSlot *); //semEnv, coreIdx, 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 struct _SchedSlot
100 {
101 int slotIdx; //needed by Holistic Model's data gathering
102 int workIsDone;
103 int needsSlaveAssigned;
104 SlaveVP *slaveAssignedToSlot;
105 };
106 //SchedSlot
108 /*WARNING: re-arranging this data structure could cause Slv switching
109 * assembly code to fail -- hard-codes offsets of fields
110 */
111 struct _SlaveVP
112 { int slaveID; //each slave given a unique ID
113 int coreAnimatedBy;
114 void *startOfStack;
115 void *stackPtr;
116 void *framePtr;
117 void *resumeInstrPtr;
119 void *coreCtlrStartPt; //allows proto-runtime to be linked later
120 void *coreCtlrFramePtr; //restore before jmp back to core controller
121 void *coreCtlrStackPtr; //restore before jmp back to core controller
123 SchedSlot *schedSlot;
124 VMSReqst *requests;
126 void *semanticData; //this is live for the life of Slv
127 void *dataRetFromReq;//Used to return vals from plugin to Wrapper Lib
129 //=========== MEASUREMENT STUFF ==========
130 MEAS__Insert_Meas_Fields_into_Slave;
131 //========================================
133 float64 createPtInSecs; //have space but don't use on some configs
134 };
135 //SlaveVP
138 /*WARNING: re-arranging this data structure could cause Slv-switching
139 * assembly code to fail -- hard-codes offsets of fields
140 * (because -O3 messes with things otherwise)
141 */
142 typedef struct
143 {
144 SlaveAssigner slaveAssigner;
145 RequestHandler requestHandler;
147 SchedSlot ***allSchedSlots;
148 SlaveVP **masterVPs;
150 void *semanticEnv;
151 void *OSEventStruc; //for future, when add I/O to BLIS
152 MallocArrays *freeLists;
153 int32 amtOfOutstandingMem; //total currently allocated
155 void *coreCtlrReturnPt;//addr to jump to to re-enter coreCtlr
157 int32 setupComplete;
158 int32 masterLock __align_to_cacheline__;
159 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
160 int32 workStealingLock;
162 int32 numSlavesCreated; //gives ordering to processor creation
163 int32 numSlavesAlive; //used to detect when to shutdown
165 //=========== MEASUREMENT STUFF =============
166 IntervalProbe **intervalProbes;
167 PrivDynArrayInfo *dynIntervalProbesInfo;
168 HashTable *probeNameHashTbl;
169 int32 masterCreateProbeID;
170 float64 createPtInSecs;
171 Histogram **measHists;
172 PrivDynArrayInfo *measHistsInfo;
173 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
174 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
175 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
176 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
177 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
178 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
179 //==========================================
180 }
181 MasterEnv;
183 //========================= Extra Stuff Data Strucs =======================
184 typedef struct
185 {
187 }
188 VMSExcp;
190 struct _GateStruc
191 {
192 int32 gateClosed;
193 int32 preGateProgress;
194 int32 waitProgress;
195 int32 exitProgress;
196 };
197 //GateStruc
199 //======================= OS Thread related ===============================
201 void * coreController( void *paramsIn ); //standard PThreads fn prototype
202 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
203 void schedulingMaster( void *initData, SlaveVP *masterVP );
206 typedef struct
207 {
208 void *endThdPt;
209 unsigned int coreNum;
210 }
211 ThdParams;
213 //============================= Global Vars ================================
215 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
217 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
218 ThdParams *coreCtlrThdParams [ NUM_CORES ];
220 pthread_mutex_t suspendLock;
221 pthread_cond_t suspendCond;
223 //========================= Function Prototypes ===========================
225 /* MEANING OF WL PI SS int
226 * These indicate which places the function is safe to use. They stand for:
227 * WL: Wrapper Library
228 * PI: Plugin
229 * SS: Startup and Shutdown
230 * int: internal to the VMS implementation
231 */
233 //========== Setup and shutdown ==========
234 void
235 VMS_SS__init();
237 void
238 VMS_SS__start_the_work_then_wait_until_done();
240 void
241 VMS_SS__shutdown();
243 void
244 VMS_SS__cleanup_at_end_of_shutdown();
247 //============== ===============
249 inline SlaveVP *
250 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
251 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
252 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
254 //Use this to create processor inside entry point & other places outside
255 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
256 SlaveVP *
257 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
259 inline SlaveVP *
260 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
261 void *dataParam, void *stackLocs );
263 inline void
264 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
265 void *dataParam);
267 void
268 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
269 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
270 //WL: dissipate a SlaveVP by sending a request
272 void
273 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
275 void
276 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
277 #define VMS_PI__throw_exception VMS_int__throw_exception
278 #define VMS_WL__throw_exception VMS_int__throw_exception
280 void *
281 VMS_int__give_sem_env_for( SlaveVP *animSlv );
282 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
283 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
284 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
286 //============== Request Related ===============
288 void
289 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
291 inline void
292 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
294 inline void
295 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
297 void
298 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
300 void inline
301 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
303 inline void
304 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
306 VMSReqst *
307 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
309 inline void *
310 VMS_PI__take_sem_reqst_from( VMSReqst *req );
312 void inline
313 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
314 ResumeSlvFnPtr resumeSlvFnPtr );
316 //======================== MEASUREMENT ======================
317 uint64
318 VMS_WL__give_num_plugin_cycles();
319 uint32
320 VMS_WL__give_num_plugin_animations();
323 //========================= Utilities =======================
324 inline char *
325 VMS_int__strDup( char *str );
328 //========================= Probes =======================
329 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
331 //================================================
332 #endif /* _VMS_H */