Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 75:f6990e1ba998
new sequential version
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Thu, 02 Jun 2011 13:55:51 +0200 |
| parents | 5ff1631c26ed |
| children | 9ddbb071142d |
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 <stdio.h>
21 #include <pthread.h>
22 #include <sys/time.h>
25 //=============================== Debug ===================================
26 //
27 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
28 // It still does co-routines and all the mechanisms are the same, it just
29 // has only a single thread and animates VPs one at a time
30 //#define SEQUENTIAL
32 //#define USE_WORK_STEALING
34 //turns on the probe-instrumentation in the application -- when not
35 // defined, the calls to the probe functions turn into comments
36 #define STATS__ENABLE_PROBES
37 //#define TURN_ON_DEBUG_PROBES
39 //These defines turn types of bug messages on and off
40 // be sure debug messages are un-commented (next block of defines)
41 #define dbgAppFlow TRUE /* Top level flow of application code -- general*/
42 #define dbgProbes FALSE /* for issues inside probes themselves*/
43 #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
44 #define dbgRqstHdlr FALSE /* in request handler code*/
46 //Comment or un- the substitute half to turn on/off types of debug message
47 #define DEBUG( bool, msg) \
48 // if( bool){ printf(msg); fflush(stdin);}
49 #define DEBUG1( bool, msg, param) \
50 // if(bool){printf(msg, param); fflush(stdin);}
51 #define DEBUG2( bool, msg, p1, p2) \
52 // if(bool) {printf(msg, p1, p2); fflush(stdin);}
54 #define ERROR(msg) printf(msg); //fflush(stdin);
55 #define ERROR1(msg, param) printf(msg, param); fflush(stdin);
56 #define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
58 //=========================== STATS =======================
60 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
61 // compiled-in that saves the low part of the time stamp count just before
62 // suspending a processor and just after resuming that processor. It is
63 // saved into a field added to VirtProcr. Have to sanity-check for
64 // rollover of low portion into high portion.
65 //#define MEAS__TIME_STAMP_SUSP
66 //#define MEAS__TIME_MASTER
67 #define MEAS__TIME_PLUGIN
68 #define MEAS__TIME_MALLOC
69 //#define MEAS__TIME_MASTER_LOCK
70 #define MEAS__NUM_TIMES_TO_RUN 100000
72 //For code that calculates normalization-offset between TSC counts of
73 // different cores.
74 #define NUM_TSC_ROUND_TRIPS 10
77 //========================= Hardware related Constants =====================
78 //This value is the number of hardware threads in the shared memory
79 // machine
80 #define NUM_CORES 8
82 // tradeoff amortizing master fixed overhead vs imbalance potential
83 // when work-stealing, can make bigger, at risk of losing cache affinity
84 #define NUM_SCHED_SLOTS 5
86 #define MIN_WORK_UNIT_CYCLES 20000
88 #define MASTERLOCK_RETRIES 10000
90 // stack size in virtual processors created
91 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
93 // memory for VMS__malloc
94 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
97 //==============================
99 #define SUCCESS 0
101 #define writeVMSQ writePrivQ
102 #define readVMSQ readPrivQ
103 #define makeVMSQ makeVMSPrivQ
104 #define numInVMSQ numInPrivQ
105 #define VMSQueueStruc PrivQueueStruc
109 //===========================================================================
110 typedef unsigned long long TSCount;
112 typedef struct _SchedSlot SchedSlot;
113 typedef struct _VMSReqst VMSReqst;
114 typedef struct _VirtProcr VirtProcr;
115 typedef struct _IntervalProbe IntervalProbe;
116 typedef struct _GateStruc GateStruc;
119 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
120 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
121 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
122 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
123 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
126 //============= Requests ===========
127 //
129 enum VMSReqstType //avoid starting enums at 0, for debug reasons
130 {
131 semantic = 1,
132 createReq,
133 dissipate,
134 VMSSemantic //goes with VMSSemReqst below
135 };
137 struct _VMSReqst
138 {
139 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
140 void *semReqData;
142 VMSReqst *nextReqst;
143 };
144 //VMSReqst
146 enum VMSSemReqstType //These are equivalent to semantic requests, but for
147 { // VMS's services available directly to app, like OS
148 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
149 openFile,
150 otherIO
151 };
153 typedef struct
154 { enum VMSSemReqstType reqType;
155 VirtProcr *requestingPr;
156 char *nameStr; //for create probe
157 }
158 VMSSemReq;
161 //==================== Core data structures ===================
163 struct _SchedSlot
164 {
165 int workIsDone;
166 int needsProcrAssigned;
167 VirtProcr *procrAssignedToSlot;
168 };
169 //SchedSlot
171 /*WARNING: re-arranging this data structure could cause VP switching
172 * assembly code to fail -- hard-codes offsets of fields
173 */
174 struct _VirtProcr
175 { int procrID; //for debugging -- count up each time create
176 int coreAnimatedBy;
177 void *startOfStack;
178 void *stackPtr;
179 void *framePtr;
180 void *nextInstrPt;
182 void *coreLoopStartPt; //allows proto-runtime to be linked later
183 void *coreLoopFramePtr; //restore before jmp back to core loop
184 void *coreLoopStackPtr; //restore before jmp back to core loop
186 void *initialData;
188 SchedSlot *schedSlot;
189 VMSReqst *requests;
191 void *semanticData; //this lives here for the life of VP
192 void *dataRetFromReq;//values returned from plugin to VP go here
194 //=========== MEASUREMENT STUFF ==========
195 #ifdef MEAS__TIME_STAMP_SUSP
196 unsigned int preSuspTSCLow;
197 unsigned int postSuspTSCLow;
198 #endif
199 #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
200 unsigned int startMasterTSCLow;
201 unsigned int endMasterTSCLow;
202 #endif
203 //========================================
205 float64 createPtInSecs; //have space but don't use on some configs
206 };
207 //VirtProcr
210 /*WARNING: re-arranging this data structure could cause VP-switching
211 * assembly code to fail -- hard-codes offsets of fields
212 * (because -O3 messes with things otherwise)
213 */
214 typedef struct
215 {
216 SlaveScheduler slaveScheduler;
217 RequestHandler requestHandler;
219 SchedSlot ***allSchedSlots;
220 VMSQueueStruc **readyToAnimateQs;
221 VirtProcr **masterVPs;
223 void *semanticEnv;
224 void *OSEventStruc; //for future, when add I/O to BLIS
225 MallocProlog *freeListHead;
226 int32 amtOfOutstandingMem; //total currently allocated
228 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
230 int32 setupComplete;
231 volatile int32 masterLock;
233 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
234 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
235 int32 workStealingLock;
237 int32 numProcrsCreated; //gives ordering to processor creation
239 //=========== MEASUREMENT STUFF =============
240 IntervalProbe **intervalProbes;
241 PrivDynArrayInfo *dynIntervalProbesInfo;
242 HashTable *probeNameHashTbl;
243 int32 masterCreateProbeID;
244 float64 createPtInSecs;
245 Histogram **measHists;
246 PrivDynArrayInfo *measHistsInfo;
247 #ifdef MEAS__TIME_PLUGIN
248 Histogram *reqHdlrLowTimeHist;
249 Histogram *reqHdlrHighTimeHist;
250 #endif
251 #ifdef MEAS__TIME_MALLOC
252 Histogram *mallocTimeHist;
253 Histogram *freeTimeHist;
254 #endif
255 #ifdef MEAS__TIME_MASTER_LOCK
256 Histogram *masterLockLowTimeHist;
257 Histogram *masterLockHighTimeHist;
258 #endif
259 }
260 MasterEnv;
262 //========================= Extra Stuff Data Strucs =======================
263 typedef struct
264 {
266 }
267 VMSExcp;
269 struct _GateStruc
270 {
271 int32 gateClosed;
272 int32 preGateProgress;
273 int32 waitProgress;
274 int32 exitProgress;
275 };
276 //GateStruc
278 //======================= OS Thread related ===============================
280 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
281 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
282 void masterLoop( void *initData, VirtProcr *masterPr );
285 typedef struct
286 {
287 void *endThdPt;
288 unsigned int coreNum;
289 }
290 ThdParams;
292 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
293 ThdParams *coreLoopThdParams [ NUM_CORES ];
294 pthread_mutex_t suspendLock;
295 pthread_cond_t suspend_cond;
299 //===================== Global Vars ===================
301 volatile MasterEnv *_VMSMasterEnv;
306 //=========================== Function Prototypes =========================
309 //========== Setup and shutdown ==========
310 void
311 VMS__init();
313 void
314 VMS__init_Seq();
316 void
317 VMS__start_the_work_then_wait_until_done();
319 void
320 VMS__start_the_work_then_wait_until_done_Seq();
322 VirtProcr *
323 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
325 void
326 VMS__dissipate_procr( VirtProcr *procrToDissipate );
328 //Use this to create processor inside entry point & other places outside
329 // the VMS system boundary (IE, not run in slave nor Master)
330 VirtProcr *
331 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
333 void
334 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
336 void
337 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
339 void
340 VMS__shutdown();
342 void
343 VMS__cleanup_at_end_of_shutdown();
345 void *
346 VMS__give_sem_env_for( VirtProcr *animPr );
349 //============== Request Related ===============
351 void
352 VMS__suspend_procr( VirtProcr *callingPr );
354 inline void
355 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
357 inline void
358 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
360 void
361 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
363 void inline
364 VMS__send_dissipate_req( VirtProcr *prToDissipate );
366 inline void
367 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
369 VMSReqst *
370 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
372 inline void *
373 VMS__take_sem_reqst_from( VMSReqst *req );
375 //======================== STATS ======================
377 //===== RDTSC wrapper =====
379 #define saveTimeStampCountInto(low, high) \
380 asm volatile("RDTSC; \
381 movl %%eax, %0; \
382 movl %%edx, %1;" \
383 /* outputs */ : "=m" (low), "=m" (high)\
384 /* inputs */ : \
385 /* clobber */ : "%eax", "%edx" \
386 );
388 #define saveLowTimeStampCountInto(low) \
389 asm volatile("RDTSC; \
390 movl %%eax, %0;" \
391 /* outputs */ : "=m" (low) \
392 /* inputs */ : \
393 /* clobber */ : "%eax", "%edx" \
394 );
396 //====================
397 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
398 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
399 _VMSMasterEnv->measHists[idx] = \
400 makeFixedBinHist( numBins, startVal, binWidth, name );
403 #define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/
405 #ifdef VPTHREAD
407 //VPThread
408 #define createHistIdx 1
409 #define mutexLockHistIdx 2
410 #define mutexUnlockHistIdx 3
411 #define condWaitHistIdx 4
412 #define condSignalHistIdx 5
414 #define MakeTheMeasHists \
415 _VMSMasterEnv->measHistsInfo = \
416 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
417 makeAMeasHist( createHistIdx, "Create", 50, 0, 100 ) \
418 makeAMeasHist( mutexLockHistIdx, "mutex lock", 50, 0, 100 ) \
419 makeAMeasHist( mutexUnlockHistIdx, "mutex unlock", 50, 0, 100 ) \
420 makeAMeasHist( condWaitHistIdx, "cond wait", 50, 0, 100 ) \
421 makeAMeasHist( condSignalHistIdx, "cond signal", 50, 0, 100 )
423 #endif
426 #ifdef VCILK
428 //VCilk
429 #define spawnHistIdx 1
430 #define syncHistIdx 2
432 #define MakeTheMeasHists \
433 _VMSMasterEnv->measHistsInfo = \
434 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
435 makeAMeasHist( spawnHistIdx, "Spawn", 50, 0, 200 ) \
436 makeAMeasHist( syncHistIdx, "Sync", 50, 0, 200 )
439 #endif
441 #ifdef SSR
443 //SSR
444 #define SendFromToHistIdx 1
445 #define SendOfTypeHistIdx 2
446 #define ReceiveFromToHistIdx 3
447 #define ReceiveOfTypeHistIdx 4
449 #define MakeTheMeasHists \
450 _VMSMasterEnv->measHistsInfo = \
451 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
452 makeAMeasHist( SendFromToHistIdx, "SendFromTo", 50, 0, 100 ) \
453 makeAMeasHist( SendOfTypeHistIdx, "SendOfType", 50, 0, 100 ) \
454 makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
455 makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
457 #endif
459 //===========================================================================
460 //VPThread
463 #define Meas_startCreate \
464 int32 startStamp, endStamp; \
465 saveLowTimeStampCountInto( startStamp ); \
467 #define Meas_endCreate \
468 saveLowTimeStampCountInto( endStamp ); \
469 addIntervalToHist( startStamp, endStamp, \
470 _VMSMasterEnv->measHists[ createHistIdx ] );
472 #define Meas_startMutexLock \
473 int32 startStamp, endStamp; \
474 saveLowTimeStampCountInto( startStamp ); \
476 #define Meas_endMutexLock \
477 saveLowTimeStampCountInto( endStamp ); \
478 addIntervalToHist( startStamp, endStamp, \
479 _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
481 #define Meas_startMutexUnlock \
482 int32 startStamp, endStamp; \
483 saveLowTimeStampCountInto( startStamp ); \
485 #define Meas_endMutexUnlock \
486 saveLowTimeStampCountInto( endStamp ); \
487 addIntervalToHist( startStamp, endStamp, \
488 _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
490 #define Meas_startCondWait \
491 int32 startStamp, endStamp; \
492 saveLowTimeStampCountInto( startStamp ); \
494 #define Meas_endCondWait \
495 saveLowTimeStampCountInto( endStamp ); \
496 addIntervalToHist( startStamp, endStamp, \
497 _VMSMasterEnv->measHists[ condWaitHistIdx ] );
499 #define Meas_startCondSignal \
500 int32 startStamp, endStamp; \
501 saveLowTimeStampCountInto( startStamp ); \
503 #define Meas_endCondSignal \
504 saveLowTimeStampCountInto( endStamp ); \
505 addIntervalToHist( startStamp, endStamp, \
506 _VMSMasterEnv->measHists[ condSignalHistIdx ] );
508 //===========================================================================
509 // VCilk
510 #define Meas_startSpawn \
511 int32 startStamp, endStamp; \
512 saveLowTimeStampCountInto( startStamp ); \
514 #define Meas_endSpawn \
515 saveLowTimeStampCountInto( endStamp ); \
516 addIntervalToHist( startStamp, endStamp, \
517 _VMSMasterEnv->measHists[ spawnHistIdx ] );
519 #define Meas_startSync \
520 int32 startStamp, endStamp; \
521 saveLowTimeStampCountInto( startStamp ); \
523 #define Meas_endSync \
524 saveLowTimeStampCountInto( endStamp ); \
525 addIntervalToHist( startStamp, endStamp, \
526 _VMSMasterEnv->measHists[ syncHistIdx ] );
528 //===========================================================================
529 // SSR
530 #define Meas_startSendFromTo \
531 int32 startStamp, endStamp; \
532 saveLowTimeStampCountInto( startStamp ); \
534 #define Meas_endSendFromTo \
535 saveLowTimeStampCountInto( endStamp ); \
536 addIntervalToHist( startStamp, endStamp, \
537 _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
539 #define Meas_startSendOfType \
540 int32 startStamp, endStamp; \
541 saveLowTimeStampCountInto( startStamp ); \
543 #define Meas_endSendOfType \
544 saveLowTimeStampCountInto( endStamp ); \
545 addIntervalToHist( startStamp, endStamp, \
546 _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
548 #define Meas_startReceiveFromTo \
549 int32 startStamp, endStamp; \
550 saveLowTimeStampCountInto( startStamp ); \
552 #define Meas_endReceiveFromTo \
553 saveLowTimeStampCountInto( endStamp ); \
554 addIntervalToHist( startStamp, endStamp, \
555 _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
557 #define Meas_startReceiveOfType \
558 int32 startStamp, endStamp; \
559 saveLowTimeStampCountInto( startStamp ); \
561 #define Meas_endReceiveOfType \
562 saveLowTimeStampCountInto( endStamp ); \
563 addIntervalToHist( startStamp, endStamp, \
564 _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
566 //=====
568 #include "SwitchAnimators.h"
569 #include "probes.h"
570 #include "vutilities.h"
572 #endif /* _VMS_H */
