Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 71:5ff1631c26ed
working O3 version
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 30 May 2011 18:28:41 +0200 |
| parents | 11bfe9d136ed |
| children | d8f12351f7cc |
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 *coreLoopStartPt;//addr to jump to to re-enter coreLoop
229 void *coreLoopEndPt; //addr to jump to to shut down a 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 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 //======================== STATS ======================
378 //===== RDTSC wrapper =====
380 #define saveTimeStampCountInto(low, high) \
381 asm volatile("RDTSC; \
382 movl %%eax, %0; \
383 movl %%edx, %1;" \
384 /* outputs */ : "=m" (low), "=m" (high)\
385 /* inputs */ : \
386 /* clobber */ : "%eax", "%edx" \
387 );
389 #define saveLowTimeStampCountInto(low) \
390 asm volatile("RDTSC; \
391 movl %%eax, %0;" \
392 /* outputs */ : "=m" (low) \
393 /* inputs */ : \
394 /* clobber */ : "%eax", "%edx" \
395 );
397 //====================
398 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
399 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
400 _VMSMasterEnv->measHists[idx] = \
401 makeFixedBinHist( numBins, startVal, binWidth, name );
404 #define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/
406 //VPThread
407 #define createHistIdx 1
408 #define mutexLockHistIdx 2
409 #define mutexUnlockHistIdx 3
410 #define condWaitHistIdx 4
411 #define condSignalHistIdx 5
413 //VCilk
414 #define spawnHistIdx 1
415 #define syncHistIdx 2
417 //SSR
418 #define SendFromToHistIdx 1
419 #define SendOfTypeHistIdx 2
420 #define ReceiveFromToHistIdx 3
421 #define ReceiveOfTypeHistIdx 4
424 #define MakeTheMeasHists \
425 _VMSMasterEnv->measHistsInfo = \
426 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200);\
427 makeAMeasHist( spawnHistIdx, "Spawn", 50, 0, 200 ) \
428 makeAMeasHist( syncHistIdx, "Sync", 50, 0, 200 )
430 // makeAMeasHist( createHistIdx, "Create", 50, 0, 100 ) \
431 // makeAMeasHist( mutexLockHistIdx, "mutex lock", 50, 0, 100 ) \
432 // makeAMeasHist( mutexUnlockHistIdx, "mutex unlock", 50, 0, 100 ) \
433 // makeAMeasHist( condWaitHistIdx, "cond wait", 50, 0, 100 ) \
434 // makeAMeasHist( condSignalHistIdx, "cond signal", 50, 0, 100 )
436 // makeAMeasHist( SendFromToHistIdx, "SendFromTo", 50, 0, 100 ) \
437 // makeAMeasHist( SendOfTypeHistIdx, "SendOfType", 50, 0, 100 ) \
438 // makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
439 // makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
442 //===========================================================================
443 //VPThread
446 #define Meas_startCreate \
447 int32 startStamp, endStamp; \
448 saveLowTimeStampCountInto( startStamp ); \
450 #define Meas_endCreate \
451 saveLowTimeStampCountInto( endStamp ); \
452 addIntervalToHist( startStamp, endStamp, \
453 _VMSMasterEnv->measHists[ createHistIdx ] );
455 #define Meas_startMutexLock \
456 int32 startStamp, endStamp; \
457 saveLowTimeStampCountInto( startStamp ); \
459 #define Meas_endMutexLock \
460 saveLowTimeStampCountInto( endStamp ); \
461 addIntervalToHist( startStamp, endStamp, \
462 _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
464 #define Meas_startMutexUnlock \
465 int32 startStamp, endStamp; \
466 saveLowTimeStampCountInto( startStamp ); \
468 #define Meas_endMutexUnlock \
469 saveLowTimeStampCountInto( endStamp ); \
470 addIntervalToHist( startStamp, endStamp, \
471 _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
473 #define Meas_startCondWait \
474 int32 startStamp, endStamp; \
475 saveLowTimeStampCountInto( startStamp ); \
477 #define Meas_endCondWait \
478 saveLowTimeStampCountInto( endStamp ); \
479 addIntervalToHist( startStamp, endStamp, \
480 _VMSMasterEnv->measHists[ condWaitHistIdx ] );
482 #define Meas_startCondSignal \
483 int32 startStamp, endStamp; \
484 saveLowTimeStampCountInto( startStamp ); \
486 #define Meas_endCondSignal \
487 saveLowTimeStampCountInto( endStamp ); \
488 addIntervalToHist( startStamp, endStamp, \
489 _VMSMasterEnv->measHists[ condSignalHistIdx ] );
491 //===========================================================================
492 // VCilk
493 #define Meas_startSpawn \
494 int32 startStamp, endStamp; \
495 saveLowTimeStampCountInto( startStamp ); \
497 #define Meas_endSpawn \
498 saveLowTimeStampCountInto( endStamp ); \
499 addIntervalToHist( startStamp, endStamp, \
500 _VMSMasterEnv->measHists[ spawnHistIdx ] );
502 #define Meas_startSync \
503 int32 startStamp, endStamp; \
504 saveLowTimeStampCountInto( startStamp ); \
506 #define Meas_endSync \
507 saveLowTimeStampCountInto( endStamp ); \
508 addIntervalToHist( startStamp, endStamp, \
509 _VMSMasterEnv->measHists[ syncHistIdx ] );
511 //===========================================================================
512 // SSR
513 #define Meas_startSendFromTo \
514 int32 startStamp, endStamp; \
515 saveLowTimeStampCountInto( startStamp ); \
517 #define Meas_endSendFromTo \
518 saveLowTimeStampCountInto( endStamp ); \
519 addIntervalToHist( startStamp, endStamp, \
520 _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
522 #define Meas_startSendOfType \
523 int32 startStamp, endStamp; \
524 saveLowTimeStampCountInto( startStamp ); \
526 #define Meas_endSendOfType \
527 saveLowTimeStampCountInto( endStamp ); \
528 addIntervalToHist( startStamp, endStamp, \
529 _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
531 #define Meas_startReceiveFromTo \
532 int32 startStamp, endStamp; \
533 saveLowTimeStampCountInto( startStamp ); \
535 #define Meas_endReceiveFromTo \
536 saveLowTimeStampCountInto( endStamp ); \
537 addIntervalToHist( startStamp, endStamp, \
538 _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
540 #define Meas_startReceiveOfType \
541 int32 startStamp, endStamp; \
542 saveLowTimeStampCountInto( startStamp ); \
544 #define Meas_endReceiveOfType \
545 saveLowTimeStampCountInto( endStamp ); \
546 addIntervalToHist( startStamp, endStamp, \
547 _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
549 //=====
551 #include "SwitchAnimators.h"
552 #include "probes.h"
553 #include "vutilities.h"
555 #endif /* _VMS_H */
