view VMS.h @ 232:421bde2a07d7

REMOVED work-stealing, and all references to gates
author Some Random Person <seanhalle@yahoo.com>
date Thu, 15 Mar 2012 20:47:54 -0700
parents 88fd85921d7f
children a0ac58d8201c
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;
46 typedef SlaveVP *(*SlaveAssigner) ( void *, SchedSlot*); //semEnv, slot for HW info
47 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
48 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
49 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
50 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
52 //============================ HW Dependent Fns ================================
54 #include "Hardware_Dependent/VMS__HW_measurement.h"
55 #include "Hardware_Dependent/VMS__primitives.h"
57 //============================= Statistics ==================================
59 inline TSCount getTSCount();
61 //============= Request Related ===========
62 //
64 enum VMSReqstType //avoid starting enums at 0, for debug reasons
65 {
66 semantic = 1,
67 createReq,
68 dissipate,
69 VMSSemantic //goes with VMSSemReqst below
70 };
72 struct _VMSReqst
73 {
74 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
75 void *semReqData;
77 VMSReqst *nextReqst;
78 };
79 //VMSReqst
81 enum VMSSemReqstType //These are equivalent to semantic requests, but for
82 { // VMS's services available directly to app, like OS
83 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
84 openFile,
85 otherIO
86 };
88 typedef struct
89 { enum VMSSemReqstType reqType;
90 SlaveVP *requestingSlv;
91 char *nameStr; //for create probe
92 }
93 VMSSemReq;
96 //==================== Core data structures ===================
98 typedef struct
99 {
100 //for future expansion
101 }
102 SlotPerfInfo;
104 struct _SchedSlot
105 {
106 int workIsDone;
107 int needsSlaveAssigned;
108 SlaveVP *slaveAssignedToSlot;
110 int slotIdx; //needed by Holistic Model's data gathering
111 int coreOfSlot;
112 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
113 };
114 //SchedSlot
116 /*WARNING: re-arranging this data structure could cause Slv switching
117 * assembly code to fail -- hard-codes offsets of fields
118 */
119 struct _SlaveVP
120 { int slaveID; //each slave given a unique ID
121 int coreAnimatedBy;
122 void *startOfStack;
123 void *stackPtr;
124 void *framePtr;
125 void *resumeInstrPtr;
127 void *coreCtlrStartPt; //allows proto-runtime to be linked later
128 void *coreCtlrFramePtr; //restore before jmp back to core controller
129 void *coreCtlrStackPtr; //restore before jmp back to core controller
131 SchedSlot *schedSlot;
132 VMSReqst *requests;
134 void *semanticData; //this is live for the life of Slv
135 void *dataRetFromReq;//Used to return vals from plugin to Wrapper Lib
137 //=========== MEASUREMENT STUFF ==========
138 MEAS__Insert_Meas_Fields_into_Slave;
139 //========================================
141 float64 createPtInSecs; //have space but don't use on some configs
142 };
143 //SlaveVP
145 /*The one and only global variable, holds many odds and ends
146 */
147 typedef struct
148 { //The offsets of these fields are hard-coded into assembly
149 void *coreCtlrReturnPt; //offset of field used in asm
150 int32 masterLock __align_to_cacheline__; //used in asm
152 //============ below this, no asm uses the field offsets =============
154 //Basic VMS infrastructure
155 SlaveVP **masterVPs;
156 SchedSlot ***allSchedSlots;
158 //plugin related
159 SlaveAssigner slaveAssigner;
160 RequestHandler requestHandler;
161 void *semanticEnv;
163 //Slave creation
164 int32 numSlavesCreated; //gives ordering to processor creation
165 int32 numSlavesAlive; //used to detect fail-safe shutdown
167 //Initialization related
168 int32 setupComplete; //use while starting up coreCtlr
170 //Memory management related
171 MallocArrays *freeLists;
172 int32 amtOfOutstandingMem;//total currently allocated
174 //=========== MEASUREMENT STUFF =============
175 IntervalProbe **intervalProbes;
176 PrivDynArrayInfo *dynIntervalProbesInfo;
177 HashTable *probeNameHashTbl;
178 int32 masterCreateProbeID;
179 float64 createPtInSecs; //real-clock time VMS initialized
180 Histogram **measHists;
181 PrivDynArrayInfo *measHistsInfo;
182 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
183 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
184 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
185 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
186 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
187 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
188 //==========================================
189 }
190 MasterEnv;
192 //========================= Extra Stuff Data Strucs =======================
193 typedef struct
194 {
196 }
197 VMSExcp;
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 animationMaster( 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 */