view VMS.h @ 263:094ad1bdeaec

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