Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 64:5cb919ac890f
added "VMS__give_semantic_env_for"
| author | Me |
|---|---|
| date | Sat, 13 Nov 2010 14:39:40 -0800 |
| parents | dd3e60aeae26 |
| children | 13b22ffb8a2f |
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 __USE_GNU
13 #include "VMS_primitive_data_types.h"
14 #include "Queue_impl/PrivateQueue.h"
15 #include "Histogram/Histogram.h"
16 #include "DynArray/DynArray.h"
17 #include "Hash_impl/PrivateHash.h"
18 #include "vmalloc.h"
20 #include <pthread.h>
21 #include <sys/time.h>
24 //=============================== Debug ===================================
25 //
26 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
27 // It still does co-routines and all the mechanisms are the same, it just
28 // has only a single thread and animates VPs one at a time
29 //#define SEQUENTIAL
31 //#define USE_WORK_STEALING
33 //turns on the probe-instrumentation in the application -- when not
34 // defined, the calls to the probe functions turn into comments
35 #define STATS__ENABLE_PROBES
36 //#define TURN_ON_DEBUG_PROBES
38 //These defines turn types of bug messages on and off
39 // be sure debug messages are un-commented (next block of defines)
40 #define dbgProbes FALSE /* for issues inside probes themselves*/
41 #define dbgAppFlow FALSE /* Top level flow of application code -- general*/
42 #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
43 #define dbgRqstHdlr FALSE /* in request handler code*/
45 //Comment or un- the substitute half to turn on/off types of debug message
46 #define DEBUG( bool, msg) \
47 // if( bool){ printf(msg); fflush(stdin);}
48 #define DEBUG1( bool, msg, param) \
49 // if(bool){printf(msg, param); fflush(stdin);}
50 #define DEBUG2( bool, msg, p1, p2) \
51 // if(bool) {printf(msg, p1, p2); fflush(stdin);}
53 #define ERROR(msg) printf(msg); fflush(stdin);
54 #define ERROR1(msg, param) printf(msg, param); fflush(stdin);
55 #define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
57 //=========================== STATS =======================
59 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
60 // compiled-in that saves the low part of the time stamp count just before
61 // suspending a processor and just after resuming that processor. It is
62 // saved into a field added to VirtProcr. Have to sanity-check for
63 // rollover of low portion into high portion.
64 #define MEAS__TIME_STAMP_SUSP
65 #define MEAS__TIME_MASTER
66 #define MEAS__NUM_TIMES_TO_RUN 100000
68 //For code that calculates normalization-offset between TSC counts of
69 // different cores.
70 #define NUM_TSC_ROUND_TRIPS 10
73 //========================= Hardware related Constants =====================
74 //This value is the number of hardware threads in the shared memory
75 // machine
76 #define NUM_CORES 4
78 // tradeoff amortizing master fixed overhead vs imbalance potential
79 // when work-stealing, can make bigger, at risk of losing cache affinity
80 #define NUM_SCHED_SLOTS 5
82 #define MIN_WORK_UNIT_CYCLES 20000
84 #define MASTERLOCK_RETRIES 10000
86 // stack size in virtual processors created
87 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
89 // memory for VMS__malloc
90 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
93 //==============================
95 #define SUCCESS 0
97 #define writeVMSQ writePrivQ
98 #define readVMSQ readPrivQ
99 #define makeVMSQ makeVMSPrivQ
100 #define numInVMSQ numInPrivQ
101 #define VMSQueueStruc PrivQueueStruc
105 //===========================================================================
106 typedef unsigned long long TSCount;
108 typedef struct _SchedSlot SchedSlot;
109 typedef struct _VMSReqst VMSReqst;
110 typedef struct _VirtProcr VirtProcr;
111 typedef struct _IntervalProbe IntervalProbe;
112 typedef struct _GateStruc GateStruc;
115 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
116 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
117 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
118 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
119 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
122 //============= Requests ===========
123 //
125 enum VMSReqstType //avoid starting enums at 0, for debug reasons
126 {
127 semantic = 1,
128 createReq,
129 dissipate,
130 VMSSemantic //goes with VMSSemReqst below
131 };
133 struct _VMSReqst
134 {
135 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
136 void *semReqData;
138 VMSReqst *nextReqst;
139 };
140 //VMSReqst
142 enum VMSSemReqstType //These are equivalent to semantic requests, but for
143 { // VMS's services available directly to app, like OS
144 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
145 openFile,
146 otherIO
147 };
149 typedef struct
150 { enum VMSSemReqstType reqType;
151 VirtProcr *requestingPr;
152 char *nameStr; //for create probe
153 }
154 VMSSemReq;
157 //==================== Core data structures ===================
159 struct _SchedSlot
160 {
161 int workIsDone;
162 int needsProcrAssigned;
163 VirtProcr *procrAssignedToSlot;
164 };
165 //SchedSlot
167 /*WARNING: re-arranging this data structure could cause VP switching
168 * assembly code to fail -- hard-codes offsets of fields
169 */
170 struct _VirtProcr
171 { int procrID; //for debugging -- count up each time create
172 int coreAnimatedBy;
173 void *startOfStack;
174 void *stackPtr;
175 void *framePtr;
176 void *nextInstrPt;
178 void *coreLoopStartPt; //allows proto-runtime to be linked later
179 void *coreLoopFramePtr; //restore before jmp back to core loop
180 void *coreLoopStackPtr; //restore before jmp back to core loop
182 void *initialData;
184 SchedSlot *schedSlot;
185 VMSReqst *requests;
187 void *semanticData; //this lives here for the life of VP
188 void *dataRetFromReq;//values returned from plugin to VP go here
190 //=========== MEASUREMENT STUFF ==========
191 #ifdef MEAS__TIME_STAMP_SUSP
192 unsigned int preSuspTSCLow;
193 unsigned int postSuspTSCLow;
194 #endif
195 #ifdef MEAS__TIME_MASTER
196 unsigned int startMasterTSCLow;
197 unsigned int endMasterTSCLow;
198 #endif
200 float64 createPtInSecs; //have space but don't use on some configs
201 };
202 //VirtProcr
205 /*WARNING: re-arranging this data structure could cause VP-switching
206 * assembly code to fail -- hard-codes offsets of fields
207 * (because -O3 messes with things otherwise)
208 */
209 typedef struct
210 {
211 SlaveScheduler slaveScheduler;
212 RequestHandler requestHandler;
214 SchedSlot ***allSchedSlots;
215 VMSQueueStruc **readyToAnimateQs;
216 VirtProcr **masterVPs;
218 void *semanticEnv;
219 void *OSEventStruc; //for future, when add I/O to BLIS
220 MallocProlog *freeListHead;
221 int32 amtOfOutstandingMem; //total currently allocated
223 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
224 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
226 int32 setupComplete;
227 int32 masterLock;
229 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
230 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
231 int32 workStealingLock;
233 int32 numProcrsCreated; //gives ordering to processor creation
235 //=========== MEASUREMENT STUFF =============
236 IntervalProbe **intervalProbes;
237 PrivDynArrayInfo *dynIntervalProbesInfo;
238 HashTable *probeNameHashTbl;
239 int32 masterCreateProbeID;
240 float64 createPtInSecs;
241 }
242 MasterEnv;
244 //========================= Extra Stuff Data Strucs =======================
245 typedef struct
246 {
248 }
249 VMSExcp;
251 struct _GateStruc
252 {
253 int32 gateClosed;
254 int32 preGateProgress;
255 int32 waitProgress;
256 int32 exitProgress;
257 };
258 //GateStruc
260 //======================= OS Thread related ===============================
262 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
263 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
264 void masterLoop( void *initData, VirtProcr *masterPr );
267 typedef struct
268 {
269 void *endThdPt;
270 unsigned int coreNum;
271 }
272 ThdParams;
274 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
275 ThdParams *coreLoopThdParams [ NUM_CORES ];
276 pthread_mutex_t suspendLock;
277 pthread_cond_t suspend_cond;
281 //===================== Global Vars ===================
283 volatile MasterEnv *_VMSMasterEnv;
288 //=========================== Function Prototypes =========================
291 //========== Setup and shutdown ==========
292 void
293 VMS__init();
295 void
296 VMS__init_Seq();
298 void
299 VMS__start_the_work_then_wait_until_done();
301 void
302 VMS__start_the_work_then_wait_until_done_Seq();
304 VirtProcr *
305 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
307 void
308 VMS__dissipate_procr( VirtProcr *procrToDissipate );
310 //Use this to create processor inside entry point & other places outside
311 // the VMS system boundary (IE, not run in slave nor Master)
312 VirtProcr *
313 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
315 void
316 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
318 void
319 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
321 void
322 VMS__shutdown();
324 void
325 VMS__cleanup_at_end_of_shutdown();
327 void *
328 VMS__give_sem_env_for( VirtProcr *animPr );
331 //============== Request Related ===============
333 void
334 VMS__suspend_procr( VirtProcr *callingPr );
336 inline void
337 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
339 inline void
340 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
342 void
343 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
345 void inline
346 VMS__send_dissipate_req( VirtProcr *prToDissipate );
348 inline void
349 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
351 VMSReqst *
352 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
354 inline void *
355 VMS__take_sem_reqst_from( VMSReqst *req );
357 //======================== STATS ======================
359 //===== RDTSC wrapper =====
361 #define saveTimeStampCountInto(low, high) \
362 asm volatile("RDTSC; \
363 movl %%eax, %0; \
364 movl %%edx, %1;" \
365 /* outputs */ : "=m" (low), "=m" (high)\
366 /* inputs */ : \
367 /* clobber */ : "%eax", "%edx" \
368 );
370 #define saveLowTimeStampCountInto(low) \
371 asm volatile("RDTSC; \
372 movl %%eax, %0;" \
373 /* outputs */ : "=m" (low) \
374 /* inputs */ : \
375 /* clobber */ : "%eax", "%edx" \
376 );
377 //=====
379 #include "SwitchAnimators.h"
380 #include "probes.h"
382 #endif /* _VMS_H */
