view VMS.h @ 242:b4f684e98d0b

add cache miss counter
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Tue, 08 May 2012 18:58:41 +0200
parents ce1f57e10fac
children 227cd4d33d94
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;
34 typedef struct _AnimSlot AnimSlot;
35 typedef struct _VMSReqst VMSReqst;
36 typedef struct _SlaveVP SlaveVP;
37 typedef struct _MasterVP MasterVP;
38 typedef struct _IntervalProbe IntervalProbe;
41 typedef SlaveVP *(*SlaveAssigner) ( void *, AnimSlot*); //semEnv, slot for HW info
42 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
43 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
44 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
45 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
46 //=========== MEASUREMENT STUFF ==========
47 MEAS__Insert_Counter_Handler
48 //========================================
50 //============================ HW Dependent Fns ================================
52 #include "Hardware_Dependent/VMS__HW_measurement.h"
53 #include "Hardware_Dependent/VMS__primitives.h"
56 //============= Request Related ===========
57 //
59 enum VMSReqstType //avoid starting enums at 0, for debug reasons
60 {
61 semantic = 1,
62 createReq,
63 dissipate,
64 VMSSemantic //goes with VMSSemReqst below
65 };
67 struct _VMSReqst
68 {
69 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
70 void *semReqData;
72 VMSReqst *nextReqst;
73 };
74 //VMSReqst
76 enum VMSSemReqstType //These are equivalent to semantic requests, but for
77 { // VMS's services available directly to app, like OS
78 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
79 openFile,
80 otherIO
81 };
83 typedef struct
84 { enum VMSSemReqstType reqType;
85 SlaveVP *requestingSlv;
86 char *nameStr; //for create probe
87 }
88 VMSSemReq;
91 //==================== Core data structures ===================
93 typedef struct
94 {
95 //for future expansion
96 }
97 SlotPerfInfo;
99 struct _AnimSlot
100 {
101 int workIsDone;
102 int needsSlaveAssigned;
103 SlaveVP *slaveAssignedToSlot;
105 int slotIdx; //needed by Holistic Model's data gathering
106 int coreSlotIsOn;
107 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
108 };
109 //AnimSlot
111 enum VPtype {
112 Slave = 1, //default
113 Master,
114 Shutdown,
115 Idle
116 };
118 /*This structure embodies the state of a slaveVP. It is reused for masterVP
119 * and shutdownVPs.
120 */
121 struct _SlaveVP
122 { //The offsets of these fields are hard-coded into assembly
123 void *stackPtr; //save the core's stack ptr when suspend
124 void *framePtr; //save core's frame ptr when suspend
125 void *resumeInstrPtr; //save core's program-counter when suspend
126 void *coreCtlrFramePtr; //restore before jmp back to core controller
127 void *coreCtlrStackPtr; //restore before jmp back to core controller
129 //============ below this, no fields are used in asm =============
131 int slaveID; //each slave given a globally unique ID
132 int coreAnimatedBy;
133 void *startOfStack; //used to free, and to point slave to Fn
134 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
135 int assignCount; //Each assign is for one work-unit, so IDs it
136 //note, a scheduling decision is uniquely identified by the triple:
137 // <slaveID, coreAnimatedBy, assignCount> -- used in record & replay
139 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
140 AnimSlot *animSlotAssignedTo;
141 VMSReqst *requests; //wrapper lib puts in requests, plugin takes out
142 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
144 //For using Slave as carrier for data
145 void *semanticData; //Lang saves lang-specific things in slave here
147 //=========== MEASUREMENT STUFF ==========
148 MEAS__Insert_Meas_Fields_into_Slave;
149 float64 createPtInSecs; //time VP created, in seconds
150 //========================================
151 };
152 //SlaveVP
155 /* The one and only global variable, holds many odds and ends
156 */
157 typedef struct
158 { //The offsets of these fields are hard-coded into assembly
159 void *coreCtlrReturnPt; //offset of field used in asm
160 int8 falseSharePad1[256 - sizeof(void*)];
161 int32 masterLock; //offset of field used in asm
162 int8 falseSharePad2[256 - sizeof(int32)];
163 //============ below this, no fields are used in asm =============
165 //Basic VMS infrastructure
166 SlaveVP **masterVPs;
167 AnimSlot ***allAnimSlots;
169 //plugin related
170 SlaveAssigner slaveAssigner;
171 RequestHandler requestHandler;
172 void *semanticEnv;
174 //Slave creation
175 int32 numSlavesCreated; //gives ordering to processor creation
176 int32 numSlavesAlive; //used to detect fail-safe shutdown
178 //Initialization related
179 int32 setupComplete; //use while starting up coreCtlr
181 //Memory management related
182 MallocArrays *freeLists;
183 int32 amtOfOutstandingMem;//total currently allocated
185 //=========== MEASUREMENT STUFF =============
186 IntervalProbe **intervalProbes;
187 PrivDynArrayInfo *dynIntervalProbesInfo;
188 HashTable *probeNameHashTbl;
189 int32 masterCreateProbeID;
190 float64 createPtInSecs; //real-clock time VMS initialized
191 Histogram **measHists;
192 PrivDynArrayInfo *measHistsInfo;
193 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
194 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
195 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
196 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
197 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
198 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
199 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
200 //==========================================
201 }
202 MasterEnv;
204 //========================= Extra Stuff Data Strucs =======================
205 typedef struct
206 {
208 }
209 VMSExcp;
211 //======================= OS Thread related ===============================
213 void * coreController( void *paramsIn ); //standard PThreads fn prototype
214 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
215 void animationMaster( void *initData, SlaveVP *masterVP );
218 typedef struct
219 {
220 void *endThdPt;
221 unsigned int coreNum;
222 }
223 ThdParams;
225 //============================= Global Vars ================================
227 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
229 //these are global, but only used for startup and shutdown
230 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
231 ThdParams *coreCtlrThdParams [ NUM_CORES ];
233 pthread_mutex_t suspendLock;
234 pthread_cond_t suspendCond;
236 //========================= Function Prototypes ===========================
237 /* MEANING OF WL PI SS int VMSOS
238 * These indicate which places the function is safe to use. They stand for:
239 *
240 * WL Wrapper Library -- wrapper lib code should only use these
241 * PI Plugin -- plugin code should only use these
242 * SS Startup and Shutdown -- designates these relate to startup & shutdown
243 * int internal to VMS -- should not be used in wrapper lib or plugin
244 * VMSOS means "OS functions for applications to use"
245 *
246 * VMS_int__ functions touch internal VMS data structs and are only safe
247 * to be used inside the master lock. However, occasionally, they appear
248 * in wrapper-lib or plugin code. In those cases, very careful analysis
249 * has been done to be sure no concurrency issues could arise.
250 *
251 * VMS_WL__ functions are all safe for use outside the master lock.
252 *
253 * VMSOS are only safe for applications to use -- they're like a second
254 * language mixed in -- but they can't be used inside plugin code, and
255 * aren't meant for use in wrapper libraries, because they are themselves
256 * wrapper-library calls!
257 */
258 //========== Startup and shutdown ==========
259 void
260 VMS_SS__init();
262 void
263 VMS_SS__start_the_work_then_wait_until_done();
265 SlaveVP*
266 VMS_SS__create_shutdown_slave();
268 void
269 VMS_SS__shutdown();
271 void
272 VMS_SS__cleanup_at_end_of_shutdown();
275 //============== ===============
277 inline SlaveVP *
278 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
279 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
280 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
282 //Use this to create processor inside entry point & other places outside
283 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
284 SlaveVP *
285 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
287 inline SlaveVP *
288 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
289 void *dataParam, void *stackLocs );
291 inline void
292 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
293 void *dataParam);
295 void
296 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
297 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
298 //WL: dissipate a SlaveVP by sending a request
300 void
301 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
303 void
304 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
305 #define VMS_PI__throw_exception VMS_int__throw_exception
306 #define VMS_WL__throw_exception VMS_int__throw_exception
308 void *
309 VMS_int__give_sem_env_for( SlaveVP *animSlv );
310 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
311 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
312 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
314 //============== Request Related ===============
316 void
317 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
319 inline void
320 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
322 inline void
323 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
325 void
326 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
328 void inline
329 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
331 inline void
332 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
334 VMSReqst *
335 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
337 inline void *
338 VMS_PI__take_sem_reqst_from( VMSReqst *req );
340 void inline
341 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
342 ResumeSlvFnPtr resumeSlvFnPtr );
344 //======================== MEASUREMENT ======================
345 uint64
346 VMS_WL__give_num_plugin_cycles();
347 uint32
348 VMS_WL__give_num_plugin_animations();
351 //========================= Utilities =======================
352 inline char *
353 VMS_int__strDup( char *str );
356 //========================= Probes =======================
357 #include "Services_Offered_by_VMS/Measurement_and_Stats/probes.h"
359 //================================================
360 #endif /* _VMS_H */