Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 152:9661b8cc8318
removed NUM_CORES to move it to Makefile
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Thu, 06 Oct 2011 14:36:31 +0200 |
| parents | c433e4524281 |
| children | d7c0c0a8187a c1784868dcea |
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 "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 dbgAppFlow TRUE /* Top level flow of application code -- general*/
41 #define dbgProbes FALSE /* for issues inside probes themselves*/
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);
54 #define ERROR1(msg, param) printf(msg, param);
55 #define ERROR2(msg, p1, p2) printf(msg, p1, p2);
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 processorsrc/VPThread_lib/VMS/VMS.h:322: warning: previous declaration of ‘VMS__create_procr’ was here. 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__TIME_PLUGIN
67 #define MEAS__TIME_MALLOC
68 //#define MEAS__TIME_MASTER_LOCK
69 #define MEAS__NUM_TIMES_TO_RUN 100000
71 //For code that calculates normalization-offset between TSC counts of
72 // different cores.
73 #define NUM_TSC_ROUND_TRIPS 10
76 //========================= Hardware related Constants =====================
77 //This value is the number of hardware threads in the shared memory
78 // machine
79 //#define NUM_CORES 8
81 // tradeoff amortizing master fixed overhead vs imbalance potential
82 // when work-stealing, can make bigger, at risk of losing cache affinity
83 #define NUM_SCHED_SLOTS 5
85 #define MIN_WORK_UNIT_CYCLES 20000
87 #define MASTERLOCK_RETRIES 10000
89 // stack size in virtual processors created
90 #define VIRT_PROCR_STACK_SIZE 0x8000 /* 32K */
92 // memory for VMS__malloc
93 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
95 #define CACHE_LINE 64
96 #define PAGE_SIZE 4096
99 //==============================
101 #define SUCCESS 0
103 #define writeVMSQ writePrivQ
104 #define readVMSQ readPrivQ
105 #define makeVMSQ makeVMSPrivQ
106 #define numInVMSQ numInPrivQ
107 #define VMSQueueStruc PrivQueueStruc
111 //===========================================================================
112 typedef unsigned long long TSCount;
114 typedef struct _SchedSlot SchedSlot;
115 typedef struct _VMSReqst VMSReqst;
116 typedef struct _VirtProcr VirtProcr;
117 typedef struct _IntervalProbe IntervalProbe;
118 typedef struct _GateStruc GateStruc;
121 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
122 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
123 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
124 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
125 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
128 //============= Requests ===========
129 //
131 enum VMSReqstType //avoid starting enums at 0, for debug reasons
132 {
133 semantic = 1,
134 createReq,
135 dissipate,
136 VMSSemantic //goes with VMSSemReqst below
137 };
139 struct _VMSReqst
140 {
141 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
142 void *semReqData;
144 VMSReqst *nextReqst;
145 };
146 //VMSReqst
148 enum VMSSemReqstType //These are equivalent to semantic requests, but for
149 { // VMS's services available directly to app, like OS
150 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
151 openFile,
152 otherIO
153 };
155 typedef struct
156 { enum VMSSemReqstType reqType;
157 VirtProcr *requestingPr;
158 char *nameStr; //for create probe
159 }
160 VMSSemReq;
163 //==================== Core data structures ===================
165 struct _SchedSlot
166 {
167 int workIsDone;
168 int needsProcrAssigned;
169 VirtProcr *procrAssignedToSlot;
170 };
171 //SchedSlot
173 /*WARNING: re-arranging this data structure could cause VP switching
174 * assembly code to fail -- hard-codes offsets of fields
175 */
176 struct _VirtProcr
177 { int procrID; //for debugging -- count up each time create
178 int coreAnimatedBy;
179 void *startOfStack;
180 void *stackPtr;
181 void *framePtr;
182 void *nextInstrPt;
184 void *coreLoopStartPt; //allows proto-runtime to be linked later
185 void *coreLoopFramePtr; //restore before jmp back to core loop
186 void *coreLoopStackPtr; //restore before jmp back to core loop
188 void *initialData;
190 SchedSlot *schedSlot;
191 VMSReqst *requests;
193 void *semanticData; //this livesUSE_GNU here for the life of VP
194 void *dataRetFromReq;//values returned from plugin to VP go here
196 //=========== MEASUREMENT STUFF ==========
197 #ifdef MEAS__TIME_STAMP_SUSP
198 unsigned int preSuspTSCLow;
199 unsigned int postSuspTSCLow;
200 #endif
201 #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
202 unsigned int startMasterTSCLow;USE_GNU
203 unsigned int endMasterTSCLow;
204 #endif
205 //========================================
207 float64 createPtInSecs; //have space but don't use on some configs
208 };
209 //VirtProcr
212 /*WARNING: re-arranging this data structure could cause VP-switching
213 * assembly code to fail -- hard-codes offsets of fields
214 * (because -O3 messes with things otherwise)
215 */
216 typedef struct
217 {
218 SlaveScheduler slaveScheduler;
219 RequestHandler requestHandler;
221 SchedSlot ***allSchedSlots;
222 VMSQueueStruc **readyToAnimateQs;
223 VirtProcr **masterVPs;
225 void *semanticEnv;
226 void *OSEventStruc; //for future, when add I/O to BLIS
227 MallocProlog *freeListHead;
228 int32 amtOfOutstandingMem; //total currently allocated
230 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
232 int32 setupComplete;
233 volatile int32 masterLock;
235 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
236 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
237 int32 workStealingLock;
239 int32 numProcrsCreated; //gives ordering to processor creation
241 //=========== MEASUREMENT STUFF =============
242 IntervalProbe **intervalProbes;
243 PrivDynArrayInfo *dynIntervalProbesInfo;
244 HashTable *probeNameHashTbl;
245 int32 masterCreateProbeID;
246 float64 createPtInSecs;
247 Histogram **measHists;
248 PrivDynArrayInfo *measHistsInfo;
249 #ifdef MEAS__TIME_PLUGIN
250 Histogram *reqHdlrLowTimeHist;
251 Histogram *reqHdlrHighTimeHist;
252 #endif
253 #ifdef MEAS__TIME_MALLOC
254 Histogram *mallocTimeHist;
255 Histogram *freeTimeHist;
256 #endif
257 #ifdef MEAS__TIME_MASTER_LOCK
258 Histogram *masterLockLowTimeHist;
259 Histogram *masterLockHighTimeHist;
260 #endif
261 }
262 MasterEnv;
264 //========================= Extra Stuff Data Strucs =======================
265 typedef struct
266 {
268 }
269 VMSExcp;
271 struct _GateStruc
272 {
273 int32 gateClosed;
274 int32 preGateProgress;
275 int32 waitProgress;
276 int32 exitProgress;
277 };
278 //GateStruc
280 //======================= OS Thread related ===============================
282 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
283 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
284 void masterLoop( void *initData, VirtProcr *masterPr );
287 typedef struct
288 {
289 void *endThdPt;
290 unsigned int coreNum;
291 }
292 ThdParams;
294 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
295 ThdParams *coreLoopThdParams [ NUM_CORES ];
296 pthread_mutex_t suspendLock;
297 pthread_cond_t suspend_cond;
301 //===================== Global Vars ===================
303 volatile MasterEnv *_VMSMasterEnv;
308 //=========================== Function Prototypes =========================
311 //========== Setup and shutdown ==========
312 void
313 VMS__init();
315 void
316 VMS__init_Seq();
318 void
319 VMS__start_the_work_then_wait_until_done();
321 void
322 VMS__start_the_work_then_wait_until_done_Seq();
324 inline VirtProcr *
325 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
327 void
328 VMS__dissipate_procr( VirtProcr *procrToDissipate );
330 //Use this to create processor inside entry point & other places outside
331 // the VMS system boundary (IE, not run in slave nor Master)
332 VirtProcr *
333 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
335 void
336 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
338 void
339 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
341 void
342 VMS__shutdown();
344 void
345 VMS__cleanup_at_end_of_shutdown();
347 void *
348 VMS__give_sem_env_for( VirtProcr *animPr );
351 //============== Request Related ===============
353 void
354 VMS__suspend_procr( VirtProcr *callingPr );
356 inline void
357 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
359 inline void
360 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
362 void
363 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
365 void inline
366 VMS__send_dissipate_req( VirtProcr *prToDissipate );
368 inline void
369 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
371 VMSReqst *
372 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
374 inline void *
375 VMS__take_sem_reqst_from( VMSReqst *req );
377 void inline
378 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
379 ResumePrFnPtr resumePrFnPtr );
381 //======================== STATS ======================
383 //===== RDTSC wrapper ===== //Also runs with x86_64 code
385 #define saveTimeStampCountInto(low, high) \
386 asm volatile("RDTSC; \
387 movl %%eax, %0; \
388 movl %%edx, %1;" \
389 /* outputs */ : "=m" (low), "=m" (high)\
390 /* inputs */ : \
391 /* clobber */ : "%eax", "%edx" \
392 );
394 #define saveLowTimeStampCountInto(low) \
395 asm volatile("RDTSC; \
396 movl %%eax, %0;" \
397 /* outputs */ : "=m" (low) \
398 /* inputs */ : \
399 /* clobber */ : "%eax", "%edx" \
400 );
402 //====================
403 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
404 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
405 _VMSMasterEnv->measHists[idx] = \
406 makeFixedBinHist( numBins, startVal, binWidth, name );
409 #define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/
411 #ifdef VPTHREAD
413 //VPThread
414 #define createHistIdx 0
415 #define mutexLockHistIdx 1
416 #define mutexUnlockHistIdx 2
417 #define condWaitHistIdx 3
418 #define condSignalHistIdx 4
420 #define MakeTheMeasHists() \
421 _VMSMasterEnv->measHistsInfo = \
422 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
423 makeAMeasHist( createHistIdx, "create", 250, 0, 100 ) \
424 makeAMeasHist( mutexLockHistIdx, "mutex_lock", 50, 0, 100 ) \
425 makeAMeasHist( mutexUnlockHistIdx, "mutex_unlock", 50, 0, 100 ) \
426 makeAMeasHist( condWaitHistIdx, "cond_wait", 50, 0, 100 ) \
427 makeAMeasHist( condSignalHistIdx, "cond_signal", 50, 0, 100 )
429 #endif
432 #ifdef VCILK
434 //VCilk
435 #define spawnHistIdx 0
436 #define syncHistIdx 1
438 #define MakeTheMeasHists() \
439 _VMSMasterEnv->measHistsInfo = \
440 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
441 makeAMeasHist( spawnHistIdx, "Spawn", 50, 0, 200 ) \
442 makeAMeasHist( syncHistIdx, "Sync", 50, 0, 200 )
445 #endif
447 #ifdef SSR
449 //SSR
450 #define SendFromToHistIdx 0
451 #define SendOfTypeHistIdx 1
452 #define ReceiveFromToHistIdx 2
453 #define ReceiveOfTypeHistIdx 3
455 #define MakeTheMeasHists() \
456 _VMSMasterEnv->measHistsInfo = \
457 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
458 makeAMeasHist( SendFromToHistIdx, "SendFromTo", 50, 0, 100 ) \
459 makeAMeasHist( SendOfTypeHistIdx, "SendOfType", 50, 0, 100 ) \
460 makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
461 makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
463 #endif
465 //===========================================================================
466 //VPThread
469 #define Meas_startCreate \
470 int32 startStamp, endStamp; \
471 saveLowTimeStampCountInto( startStamp ); \
473 #define Meas_endCreate \
474 saveLowTimeStampCountInto( endStamp ); \
475 addIntervalToHist( startStamp, endStamp, \
476 _VMSMasterEnv->measHists[ createHistIdx ] );
478 #define Meas_startMutexLock \
479 int32 startStamp, endStamp; \
480 saveLowTimeStampCountInto( startStamp ); \
482 #define Meas_endMutexLock \
483 saveLowTimeStampCountInto( endStamp ); \
484 addIntervalToHist( startStamp, endStamp, \
485 _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
487 #define Meas_startMutexUnlock \
488 int32 startStamp, endStamp; \
489 saveLowTimeStampCountInto( startStamp ); \
491 #define Meas_endMutexUnlock \
492 saveLowTimeStampCountInto( endStamp ); \
493 addIntervalToHist( startStamp, endStamp, \
494 _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
496 #define Meas_startCondWait \
497 int32 startStamp, endStamp; \
498 saveLowTimeStampCountInto( startStamp ); \
500 #define Meas_endCondWait \
501 saveLowTimeStampCountInto( endStamp ); \
502 addIntervalToHist( startStamp, endStamp, \
503 _VMSMasterEnv->measHists[ condWaitHistIdx ] );
505 #define Meas_startCondSignal \
506 int32 startStamp, endStamp; \
507 saveLowTimeStampCountInto( startStamp ); \
509 #define Meas_endCondSignal \
510 saveLowTimeStampCountInto( endStamp ); \
511 addIntervalToHist( startStamp, endStamp, \
512 _VMSMasterEnv->measHists[ condSignalHistIdx ] );
514 //===========================================================================
515 // VCilk
516 #define Meas_startSpawn \
517 int32 startStamp, endStamp; \
518 saveLowTimeStampCountInto( startStamp ); \
520 #define Meas_endSpawn \
521 saveLowTimeStampCountInto( endStamp ); \
522 addIntervalToHist( startStamp, endStamp, \
523 _VMSMasterEnv->measHists[ spawnHistIdx ] );
525 #define Meas_startSync \
526 int32 startStamp, endStamp; \
527 saveLowTimeStampCountInto( startStamp ); \
529 #define Meas_endSync \
530 saveLowTimeStampCountInto( endStamp ); \
531 addIntervalToHist( startStamp, endStamp, \
532 _VMSMasterEnv->measHists[ syncHistIdx ] );
534 //===========================================================================
535 // SSR
536 #define Meas_startSendFromTo \
537 int32 startStamp, endStamp; \
538 saveLowTimeStampCountInto( startStamp ); \
540 #define Meas_endSendFromTo \
541 saveLowTimeStampCountInto( endStamp ); \
542 addIntervalToHist( startStamp, endStamp, \
543 _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
545 #define Meas_startSendOfType \
546 int32 startStamp, endStamp; \
547 saveLowTimeStampCountInto( startStamp ); \
549 #define Meas_endSendOfType \
550 saveLowTimeStampCountInto( endStamp ); \
551 addIntervalToHist( startStamp, endStamp, \
552 _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
554 #define Meas_startReceiveFromTo \
555 int32 startStamp, endStamp; \
556 saveLowTimeStampCountInto( startStamp ); \
558 #define Meas_endReceiveFromTo \
559 saveLowTimeStampCountInto( endStamp ); \
560 addIntervalToHist( startStamp, endStamp, \
561 _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
563 #define Meas_startReceiveOfType \
564 int32 startStamp, endStamp; \
565 saveLowTimeStampCountInto( startStamp ); \
567 #define Meas_endReceiveOfType \
568 saveLowTimeStampCountInto( endStamp ); \
569 addIntervalToHist( startStamp, endStamp, \
570 _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
572 //=====
574 #include "ProcrContext.h"
575 #include "probes.h"
576 #include "vutilities.h"
578 #endif /* _VMS_H */
