Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 78:521c75d64cef
Version before optimization
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 04 Jul 2011 19:45:43 +0200 |
| parents | fe5ec83f1baf |
| children | 97e26095c01f |
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
98 //==============================
100 #define SUCCESS 0
102 #define writeVMSQ writePrivQ
103 #define readVMSQ readPrivQ
104 #define makeVMSQ makeVMSPrivQ
105 #define numInVMSQ numInPrivQ
106 #define VMSQueueStruc PrivQueueStruc
110 //===========================================================================
111 typedef unsigned long long TSCount;
113 typedef struct _SchedSlot SchedSlot;
114 typedef struct _VMSReqst VMSReqst;
115 typedef struct _VirtProcr VirtProcr;
116 typedef struct _IntervalProbe IntervalProbe;
117 typedef struct _GateStruc GateStruc;
120 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
121 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
122 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
123 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
124 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
127 //============= Requests ===========
128 //
130 enum VMSReqstType //avoid starting enums at 0, for debug reasons
131 {
132 semantic = 1,
133 createReq,
134 dissipate,
135 VMSSemantic //goes with VMSSemReqst below
136 };
138 struct _VMSReqst
139 {
140 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
141 void *semReqData;
143 VMSReqst *nextReqst;
144 };
145 //VMSReqst
147 enum VMSSemReqstType //These are equivalent to semantic requests, but for
148 { // VMS's services available directly to app, like OS
149 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
150 openFile,
151 otherIO
152 };
154 typedef struct
155 { enum VMSSemReqstType reqType;
156 VirtProcr *requestingPr;
157 char *nameStr; //for create probe
158 }
159 VMSSemReq;
162 //==================== Core data structures ===================
164 struct _SchedSlot
165 {
166 int workIsDone;
167 int needsProcrAssigned;
168 VirtProcr *procrAssignedToSlot;
169 };
170 //SchedSlot
172 /*WARNING: re-arranging this data structure could cause VP switching
173 * assembly code to fail -- hard-codes offsets of fields
174 */
175 struct _VirtProcr
176 { int procrID; //for debugging -- count up each time create
177 int coreAnimatedBy;
178 void *startOfStack;
179 void *stackPtr;
180 void *framePtr;
181 void *nextInstrPt;
183 void *coreLoopStartPt; //allows proto-runtime to be linked later
184 void *coreLoopFramePtr; //restore before jmp back to core loop
185 void *coreLoopStackPtr; //restore before jmp back to core loop
187 void *initialData;
189 SchedSlot *schedSlot;
190 VMSReqst *requests;
192 void *semanticData; //this livesUSE_GNU here for the life of VP
193 void *dataRetFromReq;//values returned from plugin to VP go here
195 //=========== MEASUREMENT STUFF ==========
196 #ifdef MEAS__TIME_STAMP_SUSP
197 unsigned int preSuspTSCLow;
198 unsigned int postSuspTSCLow;
199 #endif
200 #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
201 unsigned int startMasterTSCLow;USE_GNU
202 unsigned int endMasterTSCLow;
203 #endif
204 //========================================
206 float64 createPtInSecs; //have space but don't use on some configs
207 };
208 //VirtProcr
211 /*WARNING: re-arranging this data structure could cause VP-switching
212 * assembly code to fail -- hard-codes offsets of fields
213 * (because -O3 messes with things otherwise)
214 */
215 typedef struct
216 {
217 SlaveScheduler slaveScheduler;
218 RequestHandler requestHandler;
220 SchedSlot ***allSchedSlots;
221 VMSQueueStruc **readyToAnimateQs;
222 VirtProcr **masterVPs;
224 void *semanticEnv;
225 void *OSEventStruc; //for future, when add I/O to BLIS
226 MallocProlog *freeListHead;
227 int32 amtOfOutstandingMem; //total currently allocated
229 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
231 int32 setupComplete;
232 volatile int32 masterLock;
234 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
235 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
236 int32 workStealingLock;
238 int32 numProcrsCreated; //gives ordering to processor creation
240 //=========== MEASUREMENT STUFF =============
241 IntervalProbe **intervalProbes;
242 PrivDynArrayInfo *dynIntervalProbesInfo;
243 HashTable *probeNameHashTbl;
244 int32 masterCreateProbeID;
245 float64 createPtInSecs;
246 Histogram **measHists;
247 PrivDynArrayInfo *measHistsInfo;
248 #ifdef MEAS__TIME_PLUGIN
249 Histogram *reqHdlrLowTimeHist;
250 Histogram *reqHdlrHighTimeHist;
251 #endif
252 #ifdef MEAS__TIME_MALLOC
253 Histogram *mallocTimeHist;
254 Histogram *freeTimeHist;
255 #endif
256 #ifdef MEAS__TIME_MASTER_LOCK
257 Histogram *masterLockLowTimeHist;
258 Histogram *masterLockHighTimeHist;
259 #endif
260 }
261 MasterEnv;
263 //========================= Extra Stuff Data Strucs =======================
264 typedef struct
265 {
267 }
268 VMSExcp;
270 struct _GateStruc
271 {
272 int32 gateClosed;
273 int32 preGateProgress;
274 int32 waitProgress;
275 int32 exitProgress;
276 };
277 //GateStruc
279 //======================= OS Thread related ===============================
281 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
282 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
283 void masterLoop( void *initData, VirtProcr *masterPr );
286 typedef struct
287 {
288 void *endThdPt;
289 unsigned int coreNum;
290 }
291 ThdParams;
293 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
294 ThdParams *coreLoopThdParams [ NUM_CORES ];
295 pthread_mutex_t suspendLock;
296 pthread_cond_t suspend_cond;
300 //===================== Global Vars ===================
302 volatile MasterEnv *_VMSMasterEnv;
307 //=========================== Function Prototypes =========================
310 //========== Setup and shutdown ==========
311 void
312 VMS__init();
314 void
315 VMS__init_Seq();
317 void
318 VMS__start_the_work_then_wait_until_done();
320 void
321 VMS__start_the_work_then_wait_until_done_Seq();
323 inline VirtProcr *
324 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
326 void
327 VMS__dissipate_procr( VirtProcr *procrToDissipate );
329 //Use this to create processor inside entry point & other places outside
330 // the VMS system boundary (IE, not run in slave nor Master)
331 VirtProcr *
332 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
334 void
335 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
337 void
338 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
340 void
341 VMS__shutdown();
343 void
344 VMS__cleanup_at_end_of_shutdown();
346 void *
347 VMS__give_sem_env_for( VirtProcr *animPr );
350 //============== Request Related ===============
352 void
353 VMS__suspend_procr( VirtProcr *callingPr );
355 inline void
356 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
358 inline void
359 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
361 void
362 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
364 void inline
365 VMS__send_dissipate_req( VirtProcr *prToDissipate );
367 inline void
368 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
370 VMSReqst *
371 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
373 inline void *
374 VMS__take_sem_reqst_from( VMSReqst *req );
376 void inline
377 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
378 ResumePrFnPtr resumePrFnPtr );
380 //======================== STATS ======================
382 //===== RDTSC wrapper ===== //Also runs with x86_64 code
384 #define saveTimeStampCountInto(low, high) \
385 asm volatile("RDTSC; \
386 movl %%eax, %0; \
387 movl %%edx, %1;" \
388 /* outputs */ : "=m" (low), "=m" (high)\
389 /* inputs */ : \
390 /* clobber */ : "%eax", "%edx" \
391 );
393 #define saveLowTimeStampCountInto(low) \
394 asm volatile("RDTSC; \
395 movl %%eax, %0;" \
396 /* outputs */ : "=m" (low) \
397 /* inputs */ : \
398 /* clobber */ : "%eax", "%edx" \
399 );
401 //====================
402 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
403 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
404 _VMSMasterEnv->measHists[idx] = \
405 makeFixedBinHist( numBins, startVal, binWidth, name );
408 #define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/
410 #ifdef VPTHREAD
412 //VPThread
413 #define createHistIdx 1
414 #define mutexLockHistIdx 2
415 #define mutexUnlockHistIdx 3
416 #define condWaitHistIdx 4
417 #define condSignalHistIdx 5
419 #define MakeTheMeasHists() \
420 _VMSMasterEnv->measHistsInfo = \
421 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
422 makeAMeasHist( createHistIdx, "create", 50, 0, 1000 ) \
423 makeAMeasHist( mutexLockHistIdx, "mutex_lock", 50, 0, 100 ) \
424 makeAMeasHist( mutexUnlockHistIdx, "mutex_unlock", 50, 0, 100 ) \
425 makeAMeasHist( condWaitHistIdx, "cond_wait", 50, 0, 100 ) \
426 makeAMeasHist( condSignalHistIdx, "cond_signal", 50, 0, 100 )
428 #endif
431 #ifdef VCILK
433 //VCilk
434 #define spawnHistIdx 1
435 #define syncHistIdx 2
437 #define MakeTheMeasHists() \
438 _VMSMasterEnv->measHistsInfo = \
439 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
440 makeAMeasHist( spawnHistIdx, "Spawn", 50, 0, 200 ) \
441 makeAMeasHist( syncHistIdx, "Sync", 50, 0, 200 )
444 #endif
446 #ifdef SSR
448 //SSR
449 #define SendFromToHistIdx 1
450 #define SendOfTypeHistIdx 2
451 #define ReceiveFromToHistIdx 3
452 #define ReceiveOfTypeHistIdx 4
454 #define MakeTheMeasHists() \
455 _VMSMasterEnv->measHistsInfo = \
456 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
457 makeAMeasHist( SendFromToHistIdx, "SendFromTo", 50, 0, 100 ) \
458 makeAMeasHist( SendOfTypeHistIdx, "SendOfType", 50, 0, 100 ) \
459 makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
460 makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
462 #endif
464 //===========================================================================
465 //VPThread
468 #define Meas_startCreate \
469 int32 startStamp, endStamp; \
470 saveLowTimeStampCountInto( startStamp ); \
472 #define Meas_endCreate \
473 saveLowTimeStampCountInto( endStamp ); \
474 addIntervalToHist( startStamp, endStamp, \
475 _VMSMasterEnv->measHists[ createHistIdx ] );
477 #define Meas_startMutexLock \
478 int32 startStamp, endStamp; \
479 saveLowTimeStampCountInto( startStamp ); \
481 #define Meas_endMutexLock \
482 saveLowTimeStampCountInto( endStamp ); \
483 addIntervalToHist( startStamp, endStamp, \
484 _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
486 #define Meas_startMutexUnlock \
487 int32 startStamp, endStamp; \
488 saveLowTimeStampCountInto( startStamp ); \
490 #define Meas_endMutexUnlock \
491 saveLowTimeStampCountInto( endStamp ); \
492 addIntervalToHist( startStamp, endStamp, \
493 _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
495 #define Meas_startCondWait \
496 int32 startStamp, endStamp; \
497 saveLowTimeStampCountInto( startStamp ); \
499 #define Meas_endCondWait \
500 saveLowTimeStampCountInto( endStamp ); \
501 addIntervalToHist( startStamp, endStamp, \
502 _VMSMasterEnv->measHists[ condWaitHistIdx ] );
504 #define Meas_startCondSignal \
505 int32 startStamp, endStamp; \
506 saveLowTimeStampCountInto( startStamp ); \
508 #define Meas_endCondSignal \
509 saveLowTimeStampCountInto( endStamp ); \
510 addIntervalToHist( startStamp, endStamp, \
511 _VMSMasterEnv->measHists[ condSignalHistIdx ] );
513 //===========================================================================
514 // VCilk
515 #define Meas_startSpawn \
516 int32 startStamp, endStamp; \
517 saveLowTimeStampCountInto( startStamp ); \
519 #define Meas_endSpawn \
520 saveLowTimeStampCountInto( endStamp ); \
521 addIntervalToHist( startStamp, endStamp, \
522 _VMSMasterEnv->measHists[ spawnHistIdx ] );
524 #define Meas_startSync \
525 int32 startStamp, endStamp; \
526 saveLowTimeStampCountInto( startStamp ); \
528 #define Meas_endSync \
529 saveLowTimeStampCountInto( endStamp ); \
530 addIntervalToHist( startStamp, endStamp, \
531 _VMSMasterEnv->measHists[ syncHistIdx ] );
533 //===========================================================================
534 // SSR
535 #define Meas_startSendFromTo \
536 int32 startStamp, endStamp; \
537 saveLowTimeStampCountInto( startStamp ); \
539 #define Meas_endSendFromTo \
540 saveLowTimeStampCountInto( endStamp ); \
541 addIntervalToHist( startStamp, endStamp, \
542 _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
544 #define Meas_startSendOfType \
545 int32 startStamp, endStamp; \
546 saveLowTimeStampCountInto( startStamp ); \
548 #define Meas_endSendOfType \
549 saveLowTimeStampCountInto( endStamp ); \
550 addIntervalToHist( startStamp, endStamp, \
551 _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
553 #define Meas_startReceiveFromTo \
554 int32 startStamp, endStamp; \
555 saveLowTimeStampCountInto( startStamp ); \
557 #define Meas_endReceiveFromTo \
558 saveLowTimeStampCountInto( endStamp ); \
559 addIntervalToHist( startStamp, endStamp, \
560 _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
562 #define Meas_startReceiveOfType \
563 int32 startStamp, endStamp; \
564 saveLowTimeStampCountInto( startStamp ); \
566 #define Meas_endReceiveOfType \
567 saveLowTimeStampCountInto( endStamp ); \
568 addIntervalToHist( startStamp, endStamp, \
569 _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
571 //=====
573 #include "ProcrContext.h"
574 #include "probes.h"
575 #include "vutilities.h"
577 #endif /* _VMS_H */
