Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 209:0c83ea8adefc
Close to compilable version of common_ancestor -- still includes HW dep stuff
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Sun, 04 Mar 2012 14:26:35 -0800 |
| parents | eaf7e4c58c9e |
| children | a18539c0bc37 |
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 #ifndef _LANG_NAME_
24 #define _LANG_NAME_ ""
25 #endif
27 //================= Defines: included from separate files =================
28 //
29 // Note: ALL defines are in other files, none are in here
30 //
31 #include "VMS_defs__main.h"
34 //================================ Typedefs =================================
35 //
36 typedef unsigned long long TSCount;
37 typedef union
38 { uint32 lowHigh[2];
39 uint64 longVal;
40 }
41 TSCountLowHigh;
43 typedef struct _SchedSlot SchedSlot;
44 typedef struct _VMSReqst VMSReqst;
45 typedef struct _SlaveVP SlaveVP;
46 typedef struct _MasterVP MasterVP;
47 typedef struct _IntervalProbe IntervalProbe;
48 typedef struct _GateStruc GateStruc;
51 typedef SlaveVP * (*Sched_Assigner) ( void *, int ); //semEnv, coreIdx
52 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
53 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
54 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
55 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
57 //============================ HW Dependent Fns ================================
59 #include "VMS__HW_dependent.h"
61 //============================= Statistics ==================================
63 inline TSCount getTSCount();
65 //============= Request Related ===========
66 //
68 enum VMSReqstType //avoid starting enums at 0, for debug reasons
69 {
70 semantic = 1,
71 createReq,
72 dissipate,
73 VMSSemantic //goes with VMSSemReqst below
74 };
76 struct _VMSReqst
77 {
78 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
79 void *semReqData;
81 VMSReqst *nextReqst;
82 };
83 //VMSReqst
85 enum VMSSemReqstType //These are equivalent to semantic requests, but for
86 { // VMS's services available directly to app, like OS
87 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
88 openFile,
89 otherIO
90 };
92 typedef struct
93 { enum VMSSemReqstType reqType;
94 SlaveVP *requestingSlv;
95 char *nameStr; //for create probe
96 }
97 VMSSemReq;
100 //==================== Core data structures ===================
102 struct _SchedSlot
103 {
104 int workIsDone;
105 int needsSlaveAssigned;
106 SlaveVP *slaveAssignedToSlot;
107 };
108 //SchedSlot
110 /*WARNING: re-arranging this data structure could cause Slv switching
111 * assembly code to fail -- hard-codes offsets of fields
112 */
113 struct _SlaveVP
114 { int procrID; //for debugging -- count up each time create
115 int coreAnimatedBy;
116 void *startOfStack;
117 void *stackPtr;
118 void *framePtr;
119 void *resumeInstrPtr;
121 void *coreLoopStartPt; //allows proto-runtime to be linked later
122 void *coreLoopFramePtr; //restore before jmp back to core loop
123 void *coreLoopStackPtr; //restore before jmp back to core loop
125 SchedSlot *schedSlot;
126 VMSReqst *requests;
128 void *semanticData; //this livesUSE_GNU here for the life of Slv
129 void *dataRetFromReq;//values returned from plugin to Slv go here
131 //=========== MEASUREMENT STUFF ==========
132 MEAS__Insert_Meas_Fields_into_Slave;
133 //========================================
135 float64 createPtInSecs; //have space but don't use on some configs
136 };
137 //SlaveVP
140 /*WARNING: re-arranging this data structure could cause Slv-switching
141 * assembly code to fail -- hard-codes offsets of fields
142 * (because -O3 messes with things otherwise)
143 */
144 typedef struct
145 {
146 Sched_Assigner slaveAssigner;
147 RequestHandler requestHandler;
149 SchedSlot ***allSchedSlots;
150 VMSQueueStruc **readyToAnimateQs;
151 SlaveVP **masterVPs;
153 void *semanticEnv;
154 void *OSEventStruc; //for future, when add I/O to BLIS
155 MallocArrays *freeLists;
156 int32 amtOfOutstandingMem; //total currently allocated
158 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
160 int32 setupComplete;
161 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
162 int32 masterLock __align_to_cacheline__;
163 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
164 int32 workStealingLock;
166 int32 numSlavesCreated; //gives ordering to processor creation
167 int32 numSlavesAlive; //used to detect when to shutdown
169 //=========== MEASUREMENT STUFF =============
170 IntervalProbe **intervalProbes;
171 PrivDynArrayInfo *dynIntervalProbesInfo;
172 HashTable *probeNameHashTbl;
173 int32 masterCreateProbeID;
174 float64 createPtInSecs;
175 Histogram **measHists;
176 PrivDynArrayInfo *measHistsInfo;
177 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
178 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
179 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
180 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
181 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
182 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
183 //==========================================
184 }
185 MasterEnv;
187 //========================= Extra Stuff Data Strucs =======================
188 typedef struct
189 {
191 }
192 VMSExcp;
194 struct _GateStruc
195 {
196 int32 gateClosed;
197 int32 preGateProgress;
198 int32 waitProgress;
199 int32 exitProgress;
200 };
201 //GateStruc
203 //======================= OS Thread related ===============================
205 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
206 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
207 void masterLoop( void *initData, SlaveVP *masterVP );
210 typedef struct
211 {
212 void *endThdPt;
213 unsigned int coreNum;
214 }
215 ThdParams;
217 //============================= Global Vars ================================
219 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
220 ThdParams *coreLoopThdParams [ NUM_CORES ];
221 pthread_mutex_t suspendLock;
222 pthread_cond_t suspend_cond;
224 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
227 //========================= Function Prototypes ===========================
229 /* MEANING OF WL PI SS int
230 * These indicate which places the function is safe to use. They stand for:
231 * WL: Wrapper Library
232 * PI: Plugin
233 * SS: Startup and Shutdown
234 * int: internal to the VMS implementation
235 */
237 //========== Setup and shutdown ==========
238 void
239 VMS_SS__init();
241 //Fix;
242 /*seed-procr creation -- put box around language, have lang register stuff
243 with VMS.
244 have main program explicitly INIT Lang! -- makes more sense to
245 C programmers -- makes it clear that there's a transition.
246 (might need to have the pthreads remain waiting for
247 cond until work is scheduled)
248 Have main do call to tell language to perform work -- like did with DKU
250 Ex: "HWSim__run_a_simulation(netlist, paramBag);"
251 "processID = SSR__run_program(seed_fn, seedData); "
252 "SSR__Wait_for_program_to_end(processID);"
253 "SSR__run_program_and_wait_till_it_ends(seed_fn, seedData);"
255 allows multiple languages to be started, and programs run in several,
256 overlapped, or one program to be run that uses multiple langs..?
257 So, each program is in separate directory:
258 "HWSim_ArchDef__PingPong" "SSR_Program__Blocked_Matrix_Mult"
260 Those programs can talk to each other, via VMS, by handles they each
261 return
262 "processIDs[0] = SSR__run_program(seed_fn1, seedData1);"
263 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
264 "SSR__link_programs(processIDs, 2);"
265 or even
266 "processIDs[0] = Vthread__run_program(seed_fn1, seedData1);"
267 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
268 "VMS__link_programs(processIDs, 2);"
269 Then, the programs just know they sync with other prog, but use own
270 lang's sync constructs -- VMS uses message system to establish tie-pt,
271 each lang defines what a tie-point means to it.. (work with the
272 diff semantics?)
273 */
274 void
275 VMS_SS__start_the_work_then_wait_until_done();
277 void
278 VMS_SS__shutdown();
280 void
281 VMS_SS__cleanup_at_end_of_shutdown();
284 //============== ===============
286 inline SlaveVP *
287 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
288 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
289 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
291 inline void
292 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
293 void *dataParam);
294 #define VMS_PI__point_slaveVP_to_Fn VMS_int__point_slaveVP_to_Fn
295 #define VMS_WL__point_slaveVP_to_Fn VMS_int__point_slaveVP_to_Fn
297 void
298 VMS_int__dissipate_SlaveVP( SlaveVP *slaveToDissipate );
299 #define VMS_PI__dissipate_SlaveVP VMS_int__dissipateSlaveVP
300 //From WL, dissipate a SlaveVP by sending a request
302 //Use this to create processor inside entry point & other places outside
303 // the VMS system boundary (IE, not run in slave nor Master)
304 SlaveVP *
305 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
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 #include "probes.h"
359 #include "vutilities.h"
361 #endif /* _VMS_H */
