view VMS.h @ 280:67b684afa736

hide animating VP and entry point
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Wed, 15 May 2013 15:21:46 +0200
parents a6005210f581
children b58fb1343377
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 TopLevelFn ( void * ); //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
188 int32 shutdownInitiated;
190 //Memory management related
191 MallocArrays *freeLists;
192 int32 amtOfOutstandingMem;//total currently allocated
194 //Random number seeds -- random nums used in various places
195 uint32_t seed1;
196 uint32_t seed2;
198 //=========== MEASUREMENT STUFF =============
199 IntervalProbe **intervalProbes;
200 PrivDynArrayInfo *dynIntervalProbesInfo;
201 HashTable *probeNameHashTbl;
202 int32 masterCreateProbeID;
203 float64 createPtInSecs; //real-clock time VMS initialized
204 Histogram **measHists;
205 PrivDynArrayInfo *measHistsInfo;
206 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
207 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
208 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
209 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
210 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
211 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
212 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
213 //==========================================
214 }
215 MasterEnv;
217 //========================= Extra Stuff Data Strucs =======================
218 typedef struct
219 {
221 }
222 VMSExcp;
224 //======================= OS Thread related ===============================
226 void * coreController( void *paramsIn ); //standard PThreads fn prototype
227 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
228 void animationMaster( void *initData, SlaveVP *masterVP );
231 typedef struct
232 {
233 void *endThdPt;
234 unsigned int coreNum;
235 }
236 ThdParams;
238 //============================= Global Vars ================================
240 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
241 extern __thread SlaveVP* currVP;
243 //these are global, but only used for startup and shutdown
244 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
245 ThdParams *coreCtlrThdParams [ NUM_CORES ];
247 pthread_mutex_t suspendLock;
248 pthread_cond_t suspendCond;
250 //========================= Function Prototypes ===========================
251 /* MEANING OF WL PI SS int VMSOS
252 * These indicate which places the function is safe to use. They stand for:
253 *
254 * WL Wrapper Library -- wrapper lib code should only use these
255 * PI Plugin -- plugin code should only use these
256 * SS Startup and Shutdown -- designates these relate to startup & shutdown
257 * int internal to VMS -- should not be used in wrapper lib or plugin
258 * VMSOS means "OS functions for applications to use"
259 *
260 * VMS_int__ functions touch internal VMS data structs and are only safe
261 * to be used inside the master lock. However, occasionally, they appear
262 * in wrapper-lib or plugin code. In those cases, very careful analysis
263 * has been done to be sure no concurrency issues could arise.
264 *
265 * VMS_WL__ functions are all safe for use outside the master lock.
266 *
267 * VMSOS are only safe for applications to use -- they're like a second
268 * language mixed in -- but they can't be used inside plugin code, and
269 * aren't meant for use in wrapper libraries, because they are themselves
270 * wrapper-library calls!
271 */
272 //========== Startup and shutdown ==========
273 void
274 VMS_SS__init();
276 void
277 VMS_SS__start_the_work_then_wait_until_done();
279 SlaveVP*
280 VMS_SS__create_shutdown_slave();
282 void
283 VMS_SS__shutdown();
285 void
286 VMS_SS__cleanup_at_end_of_shutdown();
289 //============== ===============
291 SlaveVP *
292 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
293 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
294 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
296 //Use this to create processor inside entry point & other places outside
297 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
298 SlaveVP *
299 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
301 SlaveVP *
302 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
303 void *dataParam, void *stackLocs );
305 void
306 VMS_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
307 void *dataParam);
309 void
310 VMS_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr,
311 void *param);
313 void
314 VMS_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr,
315 void *param1, void *param2);
317 void
318 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
319 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
320 //WL: dissipate a SlaveVP by sending a request
322 void
323 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
325 void
326 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
327 #define VMS_PI__throw_exception VMS_int__throw_exception
328 void
329 VMS_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
330 #define VMS_App__throw_exception VMS_WL__throw_exception
332 void *
333 VMS_int__give_sem_env_for( SlaveVP *animSlv );
334 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
335 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
336 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
339 void
340 VMS_int__get_master_lock();
342 #define VMS_int__release_master_lock() _VMSMasterEnv->masterLock = UNLOCKED
344 uint32_t
345 VMS_int__randomNumber();
347 //============== Request Related ===============
349 void
350 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
352 void
353 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
355 void
356 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
358 void
359 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
361 void
362 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
364 void
365 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
367 VMSReqst *
368 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
369 //#define VMS_PI__take_next_request_out_of( slave ) slave->requests
371 //void *
372 //VMS_PI__take_sem_reqst_from( VMSReqst *req );
373 #define VMS_PI__take_sem_reqst_from( req ) req->semReqData
375 void
376 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
377 ResumeSlvFnPtr resumeSlvFnPtr );
379 //======================== MEASUREMENT ======================
380 uint64
381 VMS_WL__give_num_plugin_cycles();
382 uint32
383 VMS_WL__give_num_plugin_animations();
386 //========================= Utilities =======================
387 char *
388 VMS_int__strDup( char *str );
391 //========================= Probes =======================
392 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
394 //================================================
395 #endif /* _VMS_H */