view VMS.h @ 208:eaf7e4c58c9e

Create common_ancestor brch -- all branches will be closed, then new ones created with this as the common ancestor of all branches -- it is incomplete! only code that is common to all HW and Feat and FeatDev branches is in here
author Some Random Person <seanhalle@yahoo.com>
date Wed, 22 Feb 2012 11:39:12 -0800
parents
children 0c83ea8adefc
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 "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, animPr
50 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animPr
51 typedef void (*ResumeVPFnPtr) ( SlaveVP *, void * );
53 //============================= Statistics ==================================
55 inline TSCount getTSCount();
57 //============= Request Related ===========
58 //
60 enum VMSReqstType //avoid starting enums at 0, for debug reasons
61 {
62 semantic = 1,
63 createReq,
64 dissipate,
65 VMSSemantic //goes with VMSSemReqst below
66 };
68 struct _VMSReqst
69 {
70 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
71 void *semReqData;
73 VMSReqst *nextReqst;
74 };
75 //VMSReqst
77 enum VMSSemReqstType //These are equivalent to semantic requests, but for
78 { // VMS's services available directly to app, like OS
79 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
80 openFile,
81 otherIO
82 };
84 typedef struct
85 { enum VMSSemReqstType reqType;
86 SlaveVP *requestingPr;
87 char *nameStr; //for create probe
88 }
89 VMSSemReq;
92 //==================== Core data structures ===================
94 struct _SchedSlot
95 {
96 int workIsDone;
97 int needsProcrAssigned;
98 SlaveVP *procrAssignedToSlot;
99 };
100 //SchedSlot
102 /*WARNING: re-arranging this data structure could cause VP switching
103 * assembly code to fail -- hard-codes offsets of fields
104 */
105 struct _SlaveVP
106 { int procrID; //for debugging -- count up each time create
107 int coreAnimatedBy;
108 void *startOfStack;
109 void *stackPtr;
110 void *framePtr;
111 void *resumeInstrPtr;
113 void *coreLoopStartPt; //allows proto-runtime to be linked later
114 void *coreLoopFramePtr; //restore before jmp back to core loop
115 void *coreLoopStackPtr; //restore before jmp back to core loop
117 SchedSlot *schedSlot;
118 VMSReqst *requests;
120 void *semanticData; //this livesUSE_GNU here for the life of VP
121 void *dataRetFromReq;//values returned from plugin to VP go here
123 //=========== MEASUREMENT STUFF ==========
124 #ifdef MEAS__TIME_STAMP_SUSP
125 uint32 preSuspTSCLow;
126 uint32 postSuspTSCLow;
127 #endif
128 #ifdef MEAS__TIME_MASTER /* in SlaveVP because multiple masterVPs*/
129 uint32 startMasterTSCLow;USE_GNU
130 uint32 endMasterTSCLow;
131 #endif
132 #ifdef MEAS__TIME_2011_SYS
133 TSCountLowHigh startSusp;
134 uint64 totalSuspCycles;
135 uint32 numGoodSusp;
136 #endif
137 //========================================
139 float64 createPtInSecs; //have space but don't use on some configs
140 };
141 //SlaveVP
144 /*WARNING: re-arranging this data structure could cause VP-switching
145 * assembly code to fail -- hard-codes offsets of fields
146 * (because -O3 messes with things otherwise)
147 */
148 typedef struct
149 {
150 union{ //adds padding to put masterLock on its own cache-line to elim
151 // false sharing (masterLock is most-accessed var in VMS)
152 volatile int32 masterLock;
153 char padding[CACHE_LINE_SZ];
154 } masterLockUnion;
155 Sched_Assigner slaveSchedAssigner;
156 RequestHandler requestHandler;
158 SchedSlot ***allSchedSlots;
159 VMSQueueStruc **readyToAnimateQs;
160 SlaveVP **masterVPs;
162 void *semanticEnv;
163 void *OSEventStruc; //for future, when add I/O to BLIS
164 MallocArrays *freeLists;
165 int32 amtOfOutstandingMem; //total currently allocated
167 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
169 int32 setupComplete;
170 //int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
171 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
172 int32 workStealingLock;
174 int32 numVPsCreated; //gives ordering to processor creation
176 //=========== MEASUREMENT STUFF =============
177 IntervalProbe **intervalProbes;
178 PrivDynArrayInfo *dynIntervalProbesInfo;
179 HashTable *probeNameHashTbl;
180 int32 masterCreateProbeID;
181 float64 createPtInSecs;
182 Histogram **measHists;
183 PrivDynArrayInfo *measHistsInfo;
184 #ifdef MEAS__TIME_PLUGIN
185 Histogram *reqHdlrLowTimeHist;
186 Histogram *reqHdlrHighTimeHist;
187 #endif
188 #ifdef MEAS__TIME_MALLOC
189 Histogram *mallocTimeHist;
190 Histogram *freeTimeHist;
191 #endif
192 #ifdef MEAS__TIME_MASTER_LOCK
193 Histogram *masterLockLowTimeHist;
194 Histogram *masterLockHighTimeHist;
195 #endif
196 #ifdef MEAS__TIME_2011_SYS
197 TSCountLowHigh startMaster;
198 uint64 totalMasterCycles;
199 uint32 numMasterAnimations;
200 TSCountLowHigh startReqHdlr;
201 uint64 totalPluginCycles;
202 uint32 numPluginAnimations;
203 uint64 cyclesTillStartMasterLoop;
204 TSCountLowHigh endMasterLoop;
205 #endif
206 //==========================================
207 }
208 MasterEnv;
210 //========================= Extra Stuff Data Strucs =======================
211 typedef struct
212 {
214 }
215 VMSExcp;
217 struct _GateStruc
218 {
219 int32 gateClosed;
220 int32 preGateProgress;
221 int32 waitProgress;
222 int32 exitProgress;
223 };
224 //GateStruc
226 //======================= OS Thread related ===============================
228 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
229 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
230 void masterLoop( void *initData, SlaveVP *masterVP );
233 typedef struct
234 {
235 void *endThdPt;
236 unsigned int coreNum;
237 }
238 ThdParams;
240 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
241 ThdParams *coreLoopThdParams [ NUM_CORES ];
242 pthread_mutex_t suspendLock;
243 pthread_cond_t suspend_cond;
247 //============================= Global Vars ================================
249 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
254 //========================= Function Prototypes ===========================
257 //========== Setup and shutdown ==========
258 void
259 VMS_int__init();
261 Fix seed-procr creation -- put box around language, have lang register stuff
262 with VMS.
263 have main program explicitly INIT Lang! -- makes more sense to
264 C programmers -- makes it clear that there's a transition.
265 (might need to have the pthreads remain waiting for
266 cond until work is scheduled)
267 Have main do call to tell language to perform work -- like did with DKU
269 Ex: "HWSim__run_a_simulation(netlist, paramBag);"
270 "processID = SSR__run_program(seed_fn, seedData); "
271 "SSR__Wait_for_program_to_end(processID);"
272 "SSR__run_program_and_wait_till_it_ends(seed_fn, seedData);"
274 allows multiple languages to be started, and programs run in several,
275 overlapped, or one program to be run that uses multiple langs..?
276 So, each program is in separate directory:
277 "HWSim_ArchDef__PingPong" "SSR_Program__Blocked_Matrix_Mult"
279 Those programs can talk to each other, via VMS, by handles they each
280 return
281 "processIDs[0] = SSR__run_program(seed_fn1, seedData1);"
282 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
283 "SSR__link_programs(processIDs, 2);"
284 or even
285 "processIDs[0] = Vthread__run_program(seed_fn1, seedData1);"
286 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
287 "VMS__link_programs(processIDs, 2);"
288 Then, the programs just know they sync with other prog, but use own
289 lang's sync constructs -- VMS uses message system to establish tie-pt,
290 each lang defines what a tie-point means to it.. (work with the
291 diff semantics?)
292 void
293 VMS_WL__start_the_work_then_wait_until_done();
295 void
296 VMS_int__shutdown();
298 void
299 VMS_int__cleanup_at_end_of_shutdown();
302 //============== ===============
304 inline SlaveVP *
305 VMS_int__create_procr( TopLevelFnPtr fnPtr, void *dataParam );
307 inline void
308 VMS_int__point_slave_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
309 void *dataParam);
311 void
312 VMS_int__save_return_addr_into_ptd_to_loc(void *ptrToReturnAddrHoldingLoc);
314 void
315 VMS_int__write_return_addr_from_ptd_to_loc(void *ptrToReturnAddrHoldingLoc);
317 void
318 VMS_int__dissipate_procr( SlaveVP *procrToDissipate );
320 //Use this to create processor inside entry point & other places outside
321 // the VMS system boundary (IE, not run in slave nor Master)
322 SlaveVP *
323 VMS_ext__create_procr( TopLevelFnPtr fnPtr, void *dataParam );
325 void
326 VMS_ext__dissipate_procr( SlaveVP *procrToDissipate );
328 void
329 VMS_PI__throw_exception( char *msgStr, SlaveVP *reqstPr, VMSExcp *excpData );
331 void *
332 VMS_WL__give_sem_env_for( SlaveVP *animPr );
334 //============== Request Related ===============
336 void
337 VMS_int__suspend_procr( SlaveVP *callingPr );
339 inline void
340 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingPr );
342 inline void
343 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingPr );
345 void
346 VMS_WL__send_create_procr_req( void *semReqData, SlaveVP *reqstingPr );
348 void inline
349 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
351 inline void
352 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingPr );
354 VMSReqst *
355 VMS_PI__take_next_request_out_of( SlaveVP *procrWithReq );
357 inline void *
358 VMS_PI__take_sem_reqst_from( VMSReqst *req );
360 void inline
361 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingPr, void *semEnv,
362 ResumeVPFnPtr resumePrFnPtr );
364 //======================== MEASUREMENT ======================
365 uint64
366 VMS_WL__give_num_plugin_cycles();
367 uint32
368 VMS_WL__give_num_plugin_animations();
372 #include "VMS__HW_dependent.h"
373 #include "probes.h"
374 #include "vutilities.h"
376 #endif /* _VMS_H */