Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 281:b58fb1343377
remove need for end_thread()
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Fri, 17 May 2013 17:49:35 +0200 |
| parents | 67b684afa736 |
| children |
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 * ); //initData, animSlv
48 typedef void (*TopLevelFnWrapper)( TopLevelFnPtr, void*); //(*fn)(arg)
49 typedef void TopLevelFn ( void * ); //initData, animSlv
50 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
51 //=========== MEASUREMENT STUFF ==========
52 MEAS__Insert_Counter_Handler
53 //========================================
55 //============================ HW Dependent Fns ================================
57 #include "HW_Dependent_Primitives/VMS__HW_measurement.h"
58 #include "HW_Dependent_Primitives/VMS__primitives.h"
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 make_probe = 1, // and probe services -- like a VMS-wide built-in lang
84 throw_excp,
85 openFile,
86 otherIO
87 };
89 typedef struct
90 { enum VMSSemReqstType reqType;
91 SlaveVP *requestingSlv;
92 char *nameStr; //for create probe
93 char *msgStr; //for exception
94 void *exceptionData;
95 }
96 VMSSemReq;
99 //==================== Core data structures ===================
101 typedef struct
102 {
103 //for future expansion
104 }
105 SlotPerfInfo;
107 struct _AnimSlot
108 {
109 int workIsDone;
110 int needsSlaveAssigned;
111 SlaveVP *slaveAssignedToSlot;
113 int slotIdx; //needed by Holistic Model's data gathering
114 int coreSlotIsOn;
115 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
116 };
117 //AnimSlot
119 enum VPtype {
120 Slave = 1, //default
121 Master,
122 Shutdown,
123 Idle
124 };
126 /*This structure embodies the state of a slaveVP. It is reused for masterVP
127 * and shutdownVPs.
128 */
129 struct _SlaveVP
130 { //The offsets of these fields are hard-coded into assembly
131 void *stackPtr; //save the core's stack ptr when suspend
132 void *framePtr; //save core's frame ptr when suspend
133 void *resumeInstrPtr; //save core's program-counter when suspend
134 void *coreCtlrFramePtr; //restore before jmp back to core controller
135 void *coreCtlrStackPtr; //restore before jmp back to core controller
137 //============ below this, no fields are used in asm =============
139 int slaveID; //each slave given a globally unique ID
140 int coreAnimatedBy;
141 void *startOfStack; //used to free, and to point slave to Fn
142 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
143 int assignCount; //Each assign is for one work-unit, so IDs it
144 //note, a scheduling decision is uniquely identified by the triple:
145 // <slaveID, coreAnimatedBy, assignCount> -- used in record & replay
147 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
148 AnimSlot *animSlotAssignedTo;
149 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
150 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
152 //For using Slave as carrier for data
153 void *semanticData; //Lang saves lang-specific things in slave here
155 //=========== MEASUREMENT STUFF ==========
156 MEAS__Insert_Meas_Fields_into_Slave;
157 float64 createPtInSecs; //time VP created, in seconds
158 //========================================
159 };
160 //SlaveVP
163 /* The one and only global variable, holds many odds and ends
164 */
165 typedef struct
166 { //The offsets of these fields are hard-coded into assembly
167 void *coreCtlrReturnPt; //offset to this field used in asm
168 int8 falseSharePad1[256 - sizeof(void*)];
169 int32 masterLock; //offset to this field used in asm
170 int8 falseSharePad2[256 - sizeof(int32)];
171 //============ below this, no fields are used in asm =============
173 //Basic VMS infrastructure
174 SlaveVP **masterVPs;
175 AnimSlot ***allAnimSlots;
177 //plugin related
178 SlaveAssigner slaveAssigner;
179 RequestHandler requestHandler;
180 void *semanticEnv;
182 //Slave creation
183 int32 numSlavesCreated; //gives ordering to processor creation
184 int32 numSlavesAlive; //used to detect fail-safe shutdown
185 int32 numAnimatedSlaves;
187 //Initialization related
188 int32 setupComplete; //use while starting up coreCtlr
189 int32 shutdownInitiated;
191 //Memory management related
192 MallocArrays *freeLists;
193 int32 amtOfOutstandingMem;//total currently allocated
195 //Random number seeds -- random nums used in various places
196 uint32_t seed1;
197 uint32_t seed2;
199 //=========== MEASUREMENT STUFF =============
200 IntervalProbe **intervalProbes;
201 PrivDynArrayInfo *dynIntervalProbesInfo;
202 HashTable *probeNameHashTbl;
203 int32 masterCreateProbeID;
204 float64 createPtInSecs; //real-clock time VMS initialized
205 Histogram **measHists;
206 PrivDynArrayInfo *measHistsInfo;
207 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
208 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
209 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
210 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
211 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
212 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
213 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
214 //==========================================
215 }
216 MasterEnv;
218 //========================= Extra Stuff Data Strucs =======================
219 typedef struct
220 {
222 }
223 VMSExcp;
225 //======================= OS Thread related ===============================
227 void * coreController( void *paramsIn ); //standard PThreads fn prototype
228 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
229 void animationMaster( void *initData, SlaveVP *masterVP );
232 typedef struct
233 {
234 void *endThdPt;
235 unsigned int coreNum;
236 }
237 ThdParams;
239 //============================= Global Vars ================================
241 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
242 extern __thread SlaveVP* currVP;
244 //these are global, but only used for startup and shutdown
245 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
246 ThdParams *coreCtlrThdParams [ NUM_CORES ];
248 pthread_mutex_t suspendLock;
249 pthread_cond_t suspendCond;
251 //========================= Function Prototypes ===========================
252 /* MEANING OF WL PI SS int VMSOS
253 * These indicate which places the function is safe to use. They stand for:
254 *
255 * WL Wrapper Library -- wrapper lib code should only use these
256 * PI Plugin -- plugin code should only use these
257 * SS Startup and Shutdown -- designates these relate to startup & shutdown
258 * int internal to VMS -- should not be used in wrapper lib or plugin
259 * VMSOS means "OS functions for applications to use"
260 *
261 * VMS_int__ functions touch internal VMS data structs and are only safe
262 * to be used inside the master lock. However, occasionally, they appear
263 * in wrapper-lib or plugin code. In those cases, very careful analysis
264 * has been done to be sure no concurrency issues could arise.
265 *
266 * VMS_WL__ functions are all safe for use outside the master lock.
267 *
268 * VMSOS are only safe for applications to use -- they're like a second
269 * language mixed in -- but they can't be used inside plugin code, and
270 * aren't meant for use in wrapper libraries, because they are themselves
271 * wrapper-library calls!
272 */
273 //========== Startup and shutdown ==========
274 void
275 VMS_SS__init();
277 void
278 VMS_SS__start_the_work_then_wait_until_done();
280 SlaveVP*
281 VMS_SS__create_shutdown_slave();
283 void
284 VMS_SS__shutdown();
286 void
287 VMS_SS__cleanup_at_end_of_shutdown();
290 //============== ===============
292 SlaveVP *
293 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
294 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
295 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
297 SlaveVP *
298 VMS_int__create_slaveVP_with_wrapper( TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr, void *dataParam );
300 //Use this to create processor inside entry point & other places outside
301 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
302 SlaveVP *
303 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
305 SlaveVP *
306 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
307 void *dataParam, void *stackLocs );
309 SlaveVP *
310 VMS_int__create_slaveVP_helper_with_wrapper( SlaveVP *newSlv, TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr,
311 void *dataParam, void *stackLocs );
313 void
314 VMS_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
315 void *dataParam);
317 void
318 VMS_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr,
319 void *param);
321 void
322 VMS_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr,
323 void *param1, void *param2);
325 void
326 VMS_int__reset_slaveVP_to_TopLvlFnWrapper( SlaveVP *slaveVP, TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr,
327 void *dataParam);
329 void
330 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
331 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
332 //WL: dissipate a SlaveVP by sending a request
334 void
335 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
337 void
338 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
339 #define VMS_PI__throw_exception VMS_int__throw_exception
340 void
341 VMS_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
342 #define VMS_App__throw_exception VMS_WL__throw_exception
344 void *
345 VMS_int__give_sem_env_for( SlaveVP *animSlv );
346 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
347 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
348 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
351 void
352 VMS_int__get_master_lock();
354 #define VMS_int__release_master_lock() _VMSMasterEnv->masterLock = UNLOCKED
356 uint32_t
357 VMS_int__randomNumber();
359 //============== Request Related ===============
361 void
362 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
364 void
365 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
367 void
368 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
370 void
371 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
373 void
374 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
376 void
377 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
379 VMSReqst *
380 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
381 //#define VMS_PI__take_next_request_out_of( slave ) slave->requests
383 //void *
384 //VMS_PI__take_sem_reqst_from( VMSReqst *req );
385 #define VMS_PI__take_sem_reqst_from( req ) req->semReqData
387 void
388 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
389 ResumeSlvFnPtr resumeSlvFnPtr );
391 //======================== MEASUREMENT ======================
392 uint64
393 VMS_WL__give_num_plugin_cycles();
394 uint32
395 VMS_WL__give_num_plugin_animations();
398 //========================= Utilities =======================
399 char *
400 VMS_int__strDup( char *str );
403 //========================= Probes =======================
404 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
406 //================================================
407 #endif /* _VMS_H */
