Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 214:64737d3deeb4
Cleanup system measurement macros
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Fri, 09 Mar 2012 10:46:36 -0800 |
| parents | a18539c0bc37 |
| children | 10a72bcedbf0 |
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 "C_Libraries/DynArray/DynArray.h"
15 #include "C_Libraries/Hash_impl/PrivateHash.h"
16 #include "C_Libraries/Histogram/Histogram.h"
17 #include "C_Libraries/Queue_impl/PrivateQueue.h"
18 #include "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__main.h"
30 //================================ Typedefs =================================
31 //
32 typedef unsigned long long TSCount;
33 typedef union
34 { uint32 lowHigh[2];
35 uint64 longVal;
36 }
37 TSCountLowHigh;
39 typedef struct _SchedSlot SchedSlot;
40 typedef struct _VMSReqst VMSReqst;
41 typedef struct _SlaveVP SlaveVP;
42 typedef struct _MasterVP MasterVP;
43 typedef struct _IntervalProbe IntervalProbe;
44 typedef struct _GateStruc GateStruc;
47 typedef SlaveVP * (*Sched_Assigner) ( void *, int ); //semEnv, coreIdx
48 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
49 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
50 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
51 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
53 //============================ HW Dependent Fns ================================
55 #include "VMS__HW_dependent.h"
57 //============================= Statistics ==================================
59 inline TSCount getTSCount();
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 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
84 openFile,
85 otherIO
86 };
88 typedef struct
89 { enum VMSSemReqstType reqType;
90 SlaveVP *requestingSlv;
91 char *nameStr; //for create probe
92 }
93 VMSSemReq;
96 //==================== Core data structures ===================
98 struct _SchedSlot
99 {
100 int workIsDone;
101 int needsSlaveAssigned;
102 SlaveVP *slaveAssignedToSlot;
103 };
104 //SchedSlot
106 /*WARNING: re-arranging this data structure could cause Slv switching
107 * assembly code to fail -- hard-codes offsets of fields
108 */
109 struct _SlaveVP
110 { int procrID; //each slave given a unique ID
111 int coreAnimatedBy;
112 void *startOfStack;
113 void *stackPtr;
114 void *framePtr;
115 void *resumeInstrPtr;
117 void *coreLoopStartPt; //allows proto-runtime to be linked later
118 void *coreLoopFramePtr; //restore before jmp back to core loop
119 void *coreLoopStackPtr; //restore before jmp back to core loop
121 SchedSlot *schedSlot;
122 VMSReqst *requests;
124 void *semanticData; //this is live for the life of Slv
125 void *dataRetFromReq;//Used to return vals from plugin to Wrapper Lib
127 //=========== MEASUREMENT STUFF ==========
128 MEAS__Insert_Meas_Fields_into_Slave;
129 //========================================
131 float64 createPtInSecs; //have space but don't use on some configs
132 };
133 //SlaveVP
136 /*WARNING: re-arranging this data structure could cause Slv-switching
137 * assembly code to fail -- hard-codes offsets of fields
138 * (because -O3 messes with things otherwise)
139 */
140 typedef struct
141 {
142 Sched_Assigner slaveAssigner;
143 RequestHandler requestHandler;
145 SchedSlot ***allSchedSlots;
146 VMSQueueStruc **readyToAnimateQs;
147 SlaveVP **masterVPs;
149 void *semanticEnv;
150 void *OSEventStruc; //for future, when add I/O to BLIS
151 MallocArrays *freeLists;
152 int32 amtOfOutstandingMem; //total currently allocated
154 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
156 int32 setupComplete;
157 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
158 int32 masterLock __align_to_cacheline__;
159 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
160 int32 workStealingLock;
162 int32 numSlavesCreated; //gives ordering to processor creation
163 int32 numSlavesAlive; //used to detect when to shutdown
165 //=========== MEASUREMENT STUFF =============
166 IntervalProbe **intervalProbes;
167 PrivDynArrayInfo *dynIntervalProbesInfo;
168 HashTable *probeNameHashTbl;
169 int32 masterCreateProbeID;
170 float64 createPtInSecs;
171 Histogram **measHists;
172 PrivDynArrayInfo *measHistsInfo;
173 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
174 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
175 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
176 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
177 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
178 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
179 //==========================================
180 }
181 MasterEnv;
183 //========================= Extra Stuff Data Strucs =======================
184 typedef struct
185 {
187 }
188 VMSExcp;
190 struct _GateStruc
191 {
192 int32 gateClosed;
193 int32 preGateProgress;
194 int32 waitProgress;
195 int32 exitProgress;
196 };
197 //GateStruc
199 //======================= OS Thread related ===============================
201 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
202 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
203 void masterLoop( void *initData, SlaveVP *masterVP );
206 typedef struct
207 {
208 void *endThdPt;
209 unsigned int coreNum;
210 }
211 ThdParams;
213 //============================= Global Vars ================================
215 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
216 ThdParams *coreLoopThdParams [ NUM_CORES ];
217 pthread_mutex_t suspendLock;
218 pthread_cond_t suspend_cond;
220 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
222 pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER;
223 pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
225 //========================= Function Prototypes ===========================
227 /* MEANING OF WL PI SS int
228 * These indicate which places the function is safe to use. They stand for:
229 * WL: Wrapper Library
230 * PI: Plugin
231 * SS: Startup and Shutdown
232 * int: internal to the VMS implementation
233 */
235 //========== Setup and shutdown ==========
236 void
237 VMS_SS__init();
239 //Fix;
240 /*seed-procr creation -- put box around language, have lang register stuff
241 with VMS.
242 have main program explicitly INIT Lang! -- makes more sense to
243 C programmers -- makes it clear that there's a transition.
244 (might need to have the pthreads remain waiting for
245 cond until work is scheduled)
246 Have main do call to tell language to perform work -- like did with DKU
248 Ex: "HWSim__run_a_simulation(netlist, paramBag);"
249 "processID = SSR__run_program(seed_fn, seedData); "
250 "SSR__Wait_for_program_to_end(processID);"
251 "SSR__run_program_and_wait_till_it_ends(seed_fn, seedData);"
253 allows multiple languages to be started, and programs run in several,
254 overlapped, or one program to be run that uses multiple langs..?
255 So, each program is in separate directory:
256 "HWSim_ArchDef__PingPong" "SSR_Program__Blocked_Matrix_Mult"
258 Those programs can talk to each other, via VMS, by handles they each
259 return
260 "processIDs[0] = SSR__run_program(seed_fn1, seedData1);"
261 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
262 "SSR__link_programs(processIDs, 2);"
263 or even
264 "processIDs[0] = Vthread__run_program(seed_fn1, seedData1);"
265 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
266 "VMS__link_programs(processIDs, 2);"
267 Then, the programs just know they sync with other prog, but use own
268 lang's sync constructs -- VMS uses message system to establish tie-pt,
269 each lang defines what a tie-point means to it.. (work with the
270 diff semantics?)
271 */
272 void
273 VMS_SS__start_the_work_then_wait_until_done();
275 void
276 VMS_SS__shutdown();
278 void
279 VMS_SS__cleanup_at_end_of_shutdown();
282 //============== ===============
284 inline SlaveVP *
285 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
286 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
287 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
289 //Use this to create processor inside entry point & other places outside
290 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
291 SlaveVP *
292 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
294 inline SlaveVP *
295 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
296 void *dataParam, void *stackLocs );
298 inline void
299 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
300 void *dataParam);
302 void
303 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
304 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
305 //WL: dissipate a SlaveVP by sending a request
307 void
308 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
310 void
311 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
312 #define VMS_PI__throw_exception VMS_int__throw_exception
313 #define VMS_WL__throw_exception VMS_int__throw_exception
315 void *
316 VMS_int__give_sem_env_for( SlaveVP *animSlv );
317 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
318 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
319 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
321 //============== Request Related ===============
323 void
324 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
326 inline void
327 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
329 inline void
330 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
332 void
333 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
335 void inline
336 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
338 inline void
339 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
341 VMSReqst *
342 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
344 inline void *
345 VMS_PI__take_sem_reqst_from( VMSReqst *req );
347 void inline
348 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
349 ResumeSlvFnPtr resumeSlvFnPtr );
351 //======================== MEASUREMENT ======================
352 uint64
353 VMS_WL__give_num_plugin_cycles();
354 uint32
355 VMS_WL__give_num_plugin_animations();
358 //========================= Utilities =======================
359 inline char *
360 VMS_int__strDup( char *str );
363 //========================= Probes =======================
364 #include "Probes/probes.h"
366 //================================================
367 #endif /* _VMS_H */
