Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 222:c88ce1db91ef
Compiles, but does not run properly -- and changed MasterLoop to SchedulingMaster
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Tue, 13 Mar 2012 10:02:06 -0700 |
| parents | 8059fb8d5465 |
| children | b0b93147adfb |
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 "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 "Hardware_Dependent/VMS__HW_measurement.h"
56 #include "Hardware_Dependent/VMS__primitives.h"
58 //============================= Statistics ==================================
60 inline TSCount getTSCount();
62 //============= Request Related ===========
63 //
65 enum VMSReqstType //avoid starting enums at 0, for debug reasons
66 {
67 semantic = 1,
68 createReq,
69 dissipate,
70 VMSSemantic //goes with VMSSemReqst below
71 };
73 struct _VMSReqst
74 {
75 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
76 void *semReqData;
78 VMSReqst *nextReqst;
79 };
80 //VMSReqst
82 enum VMSSemReqstType //These are equivalent to semantic requests, but for
83 { // VMS's services available directly to app, like OS
84 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
85 openFile,
86 otherIO
87 };
89 typedef struct
90 { enum VMSSemReqstType reqType;
91 SlaveVP *requestingSlv;
92 char *nameStr; //for create probe
93 }
94 VMSSemReq;
97 //==================== Core data structures ===================
99 struct _SchedSlot
100 {
101 int workIsDone;
102 int needsSlaveAssigned;
103 SlaveVP *slaveAssignedToSlot;
104 };
105 //SchedSlot
107 /*WARNING: re-arranging this data structure could cause Slv switching
108 * assembly code to fail -- hard-codes offsets of fields
109 */
110 struct _SlaveVP
111 { int slaveID; //each slave given a unique ID
112 int coreAnimatedBy;
113 void *startOfStack;
114 void *stackPtr;
115 void *framePtr;
116 void *resumeInstrPtr;
118 void *coreCtlrStartPt; //allows proto-runtime to be linked later
119 void *coreCtlrFramePtr; //restore before jmp back to core controller
120 void *coreCtlrStackPtr; //restore before jmp back to core controller
122 SchedSlot *schedSlot;
123 VMSReqst *requests;
125 void *semanticData; //this is live for the life of Slv
126 void *dataRetFromReq;//Used to return vals from plugin to Wrapper Lib
128 //=========== MEASUREMENT STUFF ==========
129 MEAS__Insert_Meas_Fields_into_Slave;
130 //========================================
132 float64 createPtInSecs; //have space but don't use on some configs
133 };
134 //SlaveVP
137 /*WARNING: re-arranging this data structure could cause Slv-switching
138 * assembly code to fail -- hard-codes offsets of fields
139 * (because -O3 messes with things otherwise)
140 */
141 typedef struct
142 {
143 Sched_Assigner slaveAssigner;
144 RequestHandler requestHandler;
146 SchedSlot ***allSchedSlots;
147 VMSQueueStruc **readyToAnimateQs;
148 SlaveVP **masterVPs;
150 void *semanticEnv;
151 void *OSEventStruc; //for future, when add I/O to BLIS
152 MallocArrays *freeLists;
153 int32 amtOfOutstandingMem; //total currently allocated
155 void *coreCtlrReturnPt;//addr to jump to to re-enter coreCtlr
157 int32 setupComplete;
158 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
159 int32 masterLock __align_to_cacheline__;
160 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
161 int32 workStealingLock;
163 int32 numSlavesCreated; //gives ordering to processor creation
164 int32 numSlavesAlive; //used to detect when to shutdown
166 //=========== MEASUREMENT STUFF =============
167 IntervalProbe **intervalProbes;
168 PrivDynArrayInfo *dynIntervalProbesInfo;
169 HashTable *probeNameHashTbl;
170 int32 masterCreateProbeID;
171 float64 createPtInSecs;
172 Histogram **measHists;
173 PrivDynArrayInfo *measHistsInfo;
174 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
175 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
176 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
177 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
178 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
179 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
180 //==========================================
181 }
182 MasterEnv;
184 //========================= Extra Stuff Data Strucs =======================
185 typedef struct
186 {
188 }
189 VMSExcp;
191 struct _GateStruc
192 {
193 int32 gateClosed;
194 int32 preGateProgress;
195 int32 waitProgress;
196 int32 exitProgress;
197 };
198 //GateStruc
200 //======================= OS Thread related ===============================
202 void * coreController( void *paramsIn ); //standard PThreads fn prototype
203 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
204 void schedulingMaster( void *initData, SlaveVP *masterVP );
207 typedef struct
208 {
209 void *endThdPt;
210 unsigned int coreNum;
211 }
212 ThdParams;
214 //============================= Global Vars ================================
216 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
218 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
219 ThdParams *coreCtlrThdParams [ NUM_CORES ];
221 pthread_mutex_t suspendLock;
222 pthread_cond_t suspendCond;
224 //========================= Function Prototypes ===========================
226 /* MEANING OF WL PI SS int
227 * These indicate which places the function is safe to use. They stand for:
228 * WL: Wrapper Library
229 * PI: Plugin
230 * SS: Startup and Shutdown
231 * int: internal to the VMS implementation
232 */
234 //========== Setup and shutdown ==========
235 void
236 VMS_SS__init();
238 //Fix;
239 /*seed-slaveVP creation -- put box around language, have lang register stuff
240 with VMS.
241 have main program explicitly INIT Lang! -- makes more sense to
242 C programmers -- makes it clear that there's a transition.
243 (might need to have the pthreads remain waiting for
244 cond until work is scheduled)
245 Have main do call to tell language to perform work -- like did with DKU
247 Ex: "HWSim__run_a_simulation(netlist, paramBag);"
248 "processID = SSR__run_program(seed_fn, seedData); "
249 "SSR__Wait_for_program_to_end(processID);"
250 "SSR__run_program_and_wait_till_it_ends(seed_fn, seedData);"
252 allows multiple languages to be started, and programs run in several,
253 overlapped, or one program to be run that uses multiple langs..?
254 So, each program is in separate directory:
255 "HWSim_ArchDef__PingPong" "SSR_Program__Blocked_Matrix_Mult"
257 Those programs can talk to each other, via VMS, by handles they each
258 return
259 "processIDs[0] = SSR__run_program(seed_fn1, seedData1);"
260 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
261 "SSR__link_programs(processIDs, 2);"
262 or even
263 "processIDs[0] = Vthread__run_program(seed_fn1, seedData1);"
264 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
265 "VMS__link_programs(processIDs, 2);"
266 Then, the programs just know they sync with other prog, but use own
267 lang's sync constructs -- VMS uses message system to establish tie-pt,
268 each lang defines what a tie-point means to it.. (work with the
269 diff semantics?)
270 */
271 void
272 VMS_SS__start_the_work_then_wait_until_done();
274 void
275 VMS_SS__shutdown();
277 void
278 VMS_SS__cleanup_at_end_of_shutdown();
281 //============== ===============
283 inline SlaveVP *
284 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
285 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
286 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
288 //Use this to create processor inside entry point & other places outside
289 // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
290 SlaveVP *
291 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
293 inline SlaveVP *
294 VMS_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr,
295 void *dataParam, void *stackLocs );
297 inline void
298 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
299 void *dataParam);
301 void
302 VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
303 #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
304 //WL: dissipate a SlaveVP by sending a request
306 void
307 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
309 void
310 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
311 #define VMS_PI__throw_exception VMS_int__throw_exception
312 #define VMS_WL__throw_exception VMS_int__throw_exception
314 void *
315 VMS_int__give_sem_env_for( SlaveVP *animSlv );
316 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
317 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
318 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
320 //============== Request Related ===============
322 void
323 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
325 inline void
326 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
328 inline void
329 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
331 void
332 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
334 void inline
335 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
337 inline void
338 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
340 VMSReqst *
341 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
343 inline void *
344 VMS_PI__take_sem_reqst_from( VMSReqst *req );
346 void inline
347 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
348 ResumeSlvFnPtr resumeSlvFnPtr );
350 //======================== MEASUREMENT ======================
351 uint64
352 VMS_WL__give_num_plugin_cycles();
353 uint32
354 VMS_WL__give_num_plugin_animations();
357 //========================= Utilities =======================
358 inline char *
359 VMS_int__strDup( char *str );
362 //========================= Probes =======================
363 #include "Probes/probes.h"
365 //================================================
366 #endif /* _VMS_H */
