view VMS.h @ 271:68212347d1d8

count active VPs for deadlock detection
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Fri, 01 Feb 2013 17:16:39 +0100
parents 094ad1bdeaec
children a6005210f581
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
12 #ifndef _GNU_SOURCE
13 #define _GNU_SOURCE
14 #endif
16 #include "DynArray/DynArray.h"
17 #include "Hash_impl/PrivateHash.h"
18 #include "Histogram/Histogram.h"
19 #include "Queue_impl/PrivateQueue.h"
21 #include "VMS_primitive_data_types.h"
22 #include "Services_Offered_by_VMS/Memory_Handling/vmalloc.h"
24 #include <pthread.h>
25 #include <sys/time.h>
27 //================= Defines: included from separate files =================
28 //
29 // Note: ALL defines are in other files, none are in here
30 //
31 #include "Defines/VMS_defs.h"
34 //================================ Typedefs =================================
35 //
36 typedef unsigned long long TSCount;
38 typedef struct _AnimSlot AnimSlot;
39 typedef struct _VMSReqst VMSReqst;
40 typedef struct _SlaveVP SlaveVP;
41 typedef struct _MasterVP MasterVP;
42 typedef struct _IntervalProbe IntervalProbe;
45 typedef SlaveVP *(*SlaveAssigner) ( void *, AnimSlot*); //semEnv, slot for HW info
46 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
47 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
48 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
49 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
50 //=========== MEASUREMENT STUFF ==========
51 MEAS__Insert_Counter_Handler
52 //========================================
54 //============================ HW Dependent Fns ================================
56 #include "HW_Dependent_Primitives/VMS__HW_measurement.h"
57 #include "HW_Dependent_Primitives/VMS__primitives.h"
60 //============= Request Related ===========
61 //
63 enum VMSReqstType //avoid starting enums at 0, for debug reasons
64 {
65 semantic = 1,
66 createReq,
67 dissipate,
68 VMSSemantic //goes with VMSSemReqst below
69 };
71 struct _VMSReqst
72 {
73 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
74 void *semReqData;
76 VMSReqst *nextReqst;
77 };
78 //VMSReqst
80 enum VMSSemReqstType //These are equivalent to semantic requests, but for
81 { // VMS's services available directly to app, like OS
82 make_probe = 1, // and probe services -- like a VMS-wide built-in lang
83 throw_excp,
84 openFile,
85 otherIO
86 };
88 typedef struct
89 { enum VMSSemReqstType reqType;
90 SlaveVP *requestingSlv;
91 char *nameStr; //for create probe
92 char *msgStr; //for exception
93 void *exceptionData;
94 }
95 VMSSemReq;
98 //==================== Core data structures ===================
100 typedef struct
101 {
102 //for future expansion
103 }
104 SlotPerfInfo;
106 struct _AnimSlot
107 {
108 int workIsDone;
109 int needsSlaveAssigned;
110 SlaveVP *slaveAssignedToSlot;
112 int slotIdx; //needed by Holistic Model's data gathering
113 int coreSlotIsOn;
114 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
115 };
116 //AnimSlot
118 enum VPtype {
119 Slave = 1, //default
120 Master,
121 Shutdown,
122 Idle
123 };
125 /*This structure embodies the state of a slaveVP. It is reused for masterVP
126 * and shutdownVPs.
127 */
128 struct _SlaveVP
129 { //The offsets of these fields are hard-coded into assembly
130 void *stackPtr; //save the core's stack ptr when suspend
131 void *framePtr; //save core's frame ptr when suspend
132 void *resumeInstrPtr; //save core's program-counter when suspend
133 void *coreCtlrFramePtr; //restore before jmp back to core controller
134 void *coreCtlrStackPtr; //restore before jmp back to core controller
136 //============ below this, no fields are used in asm =============
138 int slaveID; //each slave given a globally unique ID
139 int coreAnimatedBy;
140 void *startOfStack; //used to free, and to point slave to Fn
141 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
142 int assignCount; //Each assign is for one work-unit, so IDs it
143 //note, a scheduling decision is uniquely identified by the triple:
144 // <slaveID, coreAnimatedBy, assignCount> -- used in record & replay
146 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
147 AnimSlot *animSlotAssignedTo;
148 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
149 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
151 //For using Slave as carrier for data
152 void *semanticData; //Lang saves lang-specific things in slave here
154 //=========== MEASUREMENT STUFF ==========
155 MEAS__Insert_Meas_Fields_into_Slave;
156 float64 createPtInSecs; //time VP created, in seconds
157 //========================================
158 };
159 //SlaveVP
162 /* The one and only global variable, holds many odds and ends
163 */
164 typedef struct
165 { //The offsets of these fields are hard-coded into assembly
166 void *coreCtlrReturnPt; //offset to this field used in asm
167 int8 falseSharePad1[256 - sizeof(void*)];
168 int32 masterLock; //offset to this field used in asm
169 int8 falseSharePad2[256 - sizeof(int32)];
170 //============ below this, no fields are used in asm =============
172 //Basic VMS infrastructure
173 SlaveVP **masterVPs;
174 AnimSlot ***allAnimSlots;
176 //plugin related
177 SlaveAssigner slaveAssigner;
178 RequestHandler requestHandler;
179 void *semanticEnv;
181 //Slave creation
182 int32 numSlavesCreated; //gives ordering to processor creation
183 int32 numSlavesAlive; //used to detect fail-safe shutdown
184 int32 numAnimatedSlaves;
186 //Initialization related
187 int32 setupComplete; //use while starting up coreCtlr
189 //Memory management related
190 MallocArrays *freeLists;
191 int32 amtOfOutstandingMem;//total currently allocated
193 //Random number seeds -- random nums used in various places
194 uint32_t seed1;
195 uint32_t seed2;
197 //=========== MEASUREMENT STUFF =============
198 IntervalProbe **intervalProbes;
199 PrivDynArrayInfo *dynIntervalProbesInfo;
200 HashTable *probeNameHashTbl;
201 int32 masterCreateProbeID;
202 float64 createPtInSecs; //real-clock time VMS initialized
203 Histogram **measHists;
204 PrivDynArrayInfo *measHistsInfo;
205 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
206 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
207 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
208 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
209 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
210 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
211 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
212 //==========================================
213 }
214 MasterEnv;
216 //========================= Extra Stuff Data Strucs =======================
217 typedef struct
218 {
220 }
221 VMSExcp;
223 //======================= OS Thread related ===============================
225 void * coreController( void *paramsIn ); //standard PThreads fn prototype
226 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
227 void animationMaster( void *initData, SlaveVP *masterVP );
230 typedef struct
231 {
232 void *endThdPt;
233 unsigned int coreNum;
234 }
235 ThdParams;
237 //============================= Global Vars ================================
239 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
241 //these are global, but only used for startup and shutdown
242 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
243 ThdParams *coreCtlrThdParams [ NUM_CORES ];
245 pthread_mutex_t suspendLock;
246 pthread_cond_t suspendCond;
248 //========================= Function Prototypes ===========================
249 /* MEANING OF WL PI SS int VMSOS
250 * These indicate which places the function is safe to use. They stand for:
251 *
252 * WL Wrapper Library -- wrapper lib code should only use these
253 * PI Plugin -- plugin code should only use these
254 * SS Startup and Shutdown -- designates these relate to startup & shutdown
255 * int internal to VMS -- should not be used in wrapper lib or plugin
256 * VMSOS means "OS functions for applications to use"
257 *
258 * VMS_int__ functions touch internal VMS data structs and are only safe
259 * to be used inside the master lock. However, occasionally, they appear
260 * in wrapper-lib or plugin code. In those cases, very careful analysis
261 * has been done to be sure no concurrency issues could arise.
262 *
263 * VMS_WL__ functions are all safe for use outside the master lock.
264 *
265 * VMSOS are only safe for applications to use -- they're like a second
266 * language mixed in -- but they can't be used inside plugin code, and
267 * aren't meant for use in wrapper libraries, because they are themselves
268 * wrapper-library calls!
269 */
270 //========== Startup and shutdown ==========
271 void
272 VMS_SS__init();
274 void
275 VMS_SS__start_the_work_then_wait_until_done();
277 SlaveVP*
278 VMS_SS__create_shutdown_slave();
280 void
281 VMS_SS__shutdown();
283 void
284 VMS_SS__cleanup_at_end_of_shutdown();
287 //============== ===============
289 SlaveVP *
290 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
291 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
292 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
294 //Use this to create processor inside entry point & other places outside
295 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
296 SlaveVP *
297 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
299 SlaveVP *
300 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
301 void *dataParam, void *stackLocs );
303 void
304 VMS_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
305 void *dataParam);
307 void
308 VMS_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr,
309 void *param);
311 void
312 VMS_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr,
313 void *param1, void *param2);
315 void
316 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
317 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
318 //WL: dissipate a SlaveVP by sending a request
320 void
321 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
323 void
324 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
325 #define VMS_PI__throw_exception VMS_int__throw_exception
326 void
327 VMS_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
328 #define VMS_App__throw_exception VMS_WL__throw_exception
330 void *
331 VMS_int__give_sem_env_for( SlaveVP *animSlv );
332 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
333 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
334 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
337 void
338 VMS_int__get_master_lock();
340 #define VMS_int__release_master_lock() _VMSMasterEnv->masterLock = UNLOCKED
342 uint32_t
343 VMS_int__randomNumber();
345 //============== Request Related ===============
347 void
348 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
350 void
351 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
353 void
354 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
356 void
357 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
359 void
360 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
362 void
363 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
365 VMSReqst *
366 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
367 //#define VMS_PI__take_next_request_out_of( slave ) slave->requests
369 //void *
370 //VMS_PI__take_sem_reqst_from( VMSReqst *req );
371 #define VMS_PI__take_sem_reqst_from( req ) req->semReqData
373 void
374 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
375 ResumeSlvFnPtr resumeSlvFnPtr );
377 //======================== MEASUREMENT ======================
378 uint64
379 VMS_WL__give_num_plugin_cycles();
380 uint32
381 VMS_WL__give_num_plugin_animations();
384 //========================= Utilities =======================
385 char *
386 VMS_int__strDup( char *str );
389 //========================= Probes =======================
390 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
392 //================================================
393 #endif /* _VMS_H */