Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 129:ce02441b77cf
dependency tracking
| author | Nina Engelhardt |
|---|---|
| date | Mon, 29 Aug 2011 19:12:06 +0200 |
| parents | 73fc5aafbe45 |
| children | 395f58384a5c |
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"
19 #include "Counters/Counters.h"
20 #include "dependency.h"
22 #include <pthread.h>
23 #include <sys/time.h>
26 //=============================== Debug ===================================
27 //
28 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
29 // It still does co-routines and all the mechanisms are the same, it just
30 // has only a single thread and animates VPs one at a time
31 //#define SEQUENTIAL
33 //#define USE_WORK_STEALING
35 //turns on the probe-instrumentation in the application -- when not
36 // defined, the calls to the probe functions turn into comments
37 //#define STATS__ENABLE_PROBES
38 //#define TURN_ON_DEBUG_PROBES
40 //These defines turn types of bug messages on and off
41 // be sure debug messages are un-commented (next block of defines)
42 #define dbgAppFlow FALSE /* Top level flow of application code -- general*/
43 #define dbgProbes FALSE /* for issues inside probes themselves*/
44 #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
45 #define dbgRqstHdlr FALSE /* in request handler code*/
46 #define dbgDependency TRUE /* in request handler code, print dependencies */
48 //Comment or un- the substitute half to turn on/off types of debug message
49 #define DEBUG( bool, msg) \
50 if( bool){ printf(msg); fflush(stdin);}
51 #define DEBUG1( bool, msg, param) \
52 if(bool){printf(msg, param); fflush(stdin);}
53 #define DEBUG2( bool, msg, p1, p2) \
54 if(bool) {printf(msg, p1, p2); fflush(stdin);}
56 #define ERROR(msg) printf(msg);
57 #define ERROR1(msg, param) printf(msg, param);
58 #define ERROR2(msg, p1, p2) printf(msg, p1, p2);
60 //=========================== STATS =======================
62 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
63 // compiled-in that saves the low part of the time stamp count just before
64 // suspending a processor and just after resuming that processor. It is
65 // saved into a field added to VirtProcr. Have to sanity-check for
66 // rollover of low portion into high portion.
67 //#define MEAS__TIME_STAMP_SUSP
68 //#define MEAS__TIME_MASTER
69 //#define MEAS__TIME_PLUGIN
70 //#define MEAS__TIME_MALLOC
71 //#define MEAS__TIME_MASTER_LOCK
72 //#define MEAS__NUM_TIMES_TO_RUN 100000
74 //For code that calculates normalization-offset between TSC counts of
75 // different cores.
76 //#define NUM_TSC_ROUND_TRIPS 10
78 #define MEAS__PERF_COUNTERS
79 #define DETECT_DEPENDENCIES
81 //========================= Hardware related Constants =====================
82 //This value is the number of hardware threads in the shared memory
83 // machine
84 #define NUM_CORES 2
86 // tradeoff amortizing master fixed overhead vs imbalance potential
87 // when work-stealing, can make bigger, at risk of losing cache affinity
88 #define NUM_SCHED_SLOTS 5
90 #define MIN_WORK_UNIT_CYCLES 20000
92 #define MASTERLOCK_RETRIES 10000
94 // stack size in virtual processors created
95 #define VIRT_PROCR_STACK_SIZE 0x8000 /* 32K */
97 // memory for VMS__malloc
98 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
100 #define CACHE_LINE 64
101 #define PAGE_SIZE 4096
104 //==============================
106 #define SUCCESS 0
108 #define writeVMSQ writePrivQ
109 #define readVMSQ readPrivQ
110 #define makeVMSQ makeVMSPrivQ
111 #define numInVMSQ numInPrivQ
112 #define VMSQueueStruc PrivQueueStruc
116 //===========================================================================
117 typedef unsigned long long TSCount;
119 typedef struct _SchedSlot SchedSlot;
120 typedef struct _VMSReqst VMSReqst;
121 typedef struct _VirtProcr VirtProcr;
122 typedef struct _IntervalProbe IntervalProbe;
123 typedef struct _GateStruc GateStruc;
126 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
127 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
128 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
129 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
130 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
133 //============= Requests ===========
134 //
136 enum VMSReqstType //avoid starting enums at 0, for debug reasons
137 {
138 semantic = 1,
139 createReq,
140 dissipate,
141 VMSSemantic //goes with VMSSemReqst below
142 };
144 struct _VMSReqst
145 {
146 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
147 void *semReqData;
149 VMSReqst *nextReqst;
150 };
151 //VMSReqst
153 enum VMSSemReqstType //These are equivalent to semantic requests, but for
154 { // VMS's services available directly to app, like OS
155 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
156 openFile,
157 otherIO
158 };
160 typedef struct
161 { enum VMSSemReqstType reqType;
162 VirtProcr *requestingPr;
163 char *nameStr; //for create probe
164 }
165 VMSSemReq;
168 //==================== Core data structures ===================
170 struct _SchedSlot
171 {
172 int workIsDone;
173 int needsProcrAssigned;
174 VirtProcr *procrAssignedToSlot;
175 };
176 //SchedSlot
178 /*WARNING: re-arranging this data structure could cause VP switching
179 * assembly code to fail -- hard-codes offsets of fields
180 */
181 struct _VirtProcr
182 { int procrID; //for debugging -- count up each time create
183 int coreAnimatedBy;
184 void *startOfStack;
185 void *stackPtr;
186 void *framePtr;
187 void *nextInstrPt;
189 void *coreLoopStartPt; //allows proto-runtime to be linked later
190 void *coreLoopFramePtr; //restore before jmp back to core loop
191 void *coreLoopStackPtr; //restore before jmp back to core loop
193 void *initialData;
195 SchedSlot *schedSlot;
196 VMSReqst *requests;
198 void *semanticData; //this livesUSE_GNU here for the life of VP
199 void *dataRetFromReq;//values returned from plugin to VP go here
201 //=========== MEASUREMENT STUFF ==========
202 #ifdef MEAS__TIME_STAMP_SUSP
203 unsigned int preSuspTSCLow;
204 unsigned int postSuspTSCLow;
205 #endif
206 #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
207 unsigned int startMasterTSCLow;USE_GNU
208 unsigned int endMasterTSCLow;
209 #endif
210 #ifdef MEAS__PERF_COUNTERS //
211 CounterRecord** counter_history;
212 PrivDynArrayInfo* counter_history_array_info;
213 #endif
214 //========================================
216 float64 createPtInSecs; //have space but don't use on some configs
217 };
218 //VirtProcr
221 /*WARNING: re-arranging this data structure could cause VP-switching
222 * assembly code to fail -- hard-codes offsets of fields
223 * (because -O3 messes with things otherwise)
224 */
225 typedef struct
226 {
227 SlaveScheduler slaveScheduler;
228 RequestHandler requestHandler;
230 SchedSlot ***allSchedSlots;
231 VMSQueueStruc **readyToAnimateQs;
232 VirtProcr **masterVPs;
234 void *semanticEnv;
235 void *OSEventStruc; //for future, when add I/O to BLIS
236 MallocProlog *freeListHead;
237 int32 amtOfOutstandingMem; //total currently allocated
239 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
241 int32 setupComplete;
242 volatile int32 masterLock;
244 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
245 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
246 int32 workStealingLock;
248 int32 numProcrsCreated; //gives ordering to processor creation
250 //=========== MEASUREMENT STUFF =============
251 IntervalProbe **intervalProbes;
252 PrivDynArrayInfo *dynIntervalProbesInfo;
253 HashTable *probeNameHashTbl;
254 int32 masterCreateProbeID;
255 float64 createPtInSecs;
256 Histogram **measHists;
257 PrivDynArrayInfo *measHistsInfo;
258 #ifdef MEAS__TIME_PLUGIN
259 Histogram *reqHdlrLowTimeHist;
260 Histogram *reqHdlrHighTimeHist;
261 #endif
262 #ifdef MEAS__TIME_MALLOC
263 Histogram *mallocTimeHist;
264 Histogram *freeTimeHist;
265 #endif
266 #ifdef MEAS__TIME_MASTER_LOCK
267 Histogram *masterLockLowTimeHist;
268 Histogram *masterLockHighTimeHist;
269 #endif
270 #ifdef MEAS__PERF_COUNTERS
271 int cycles_counter_fd[NUM_CORES];
272 int instrs_counter_fd[NUM_CORES];
273 FILE* counteroutput;
274 #endif
275 #ifdef DETECT_DEPENDENCIES
276 Dependency** dependencies;
277 PrivDynArrayInfo* dependenciesInfo;
278 #endif
279 }
280 MasterEnv;
282 //========================= Extra Stuff Data Strucs =======================
283 typedef struct
284 {
286 }
287 VMSExcp;
289 struct _GateStruc
290 {
291 int32 gateClosed;
292 int32 preGateProgress;
293 int32 waitProgress;
294 int32 exitProgress;
295 };
296 //GateStruc
298 //======================= OS Thread related ===============================
300 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
301 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
302 void masterLoop( void *initData, VirtProcr *masterPr );
305 typedef struct
306 {
307 void *endThdPt;
308 unsigned int coreNum;
309 }
310 ThdParams;
312 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
313 ThdParams *coreLoopThdParams [ NUM_CORES ];
314 pthread_mutex_t suspendLock;
315 pthread_cond_t suspend_cond;
319 //===================== Global Vars ===================
321 volatile MasterEnv *_VMSMasterEnv;
326 //=========================== Function Prototypes =========================
329 //========== Setup and shutdown ==========
330 void
331 VMS__init();
333 void
334 VMS__init_Seq();
336 void
337 VMS__start_the_work_then_wait_until_done();
339 void
340 VMS__start_the_work_then_wait_until_done_Seq();
342 inline VirtProcr *
343 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
345 void
346 VMS__dissipate_procr( VirtProcr *procrToDissipate );
348 //Use this to create processor inside entry point & other places outside
349 // the VMS system boundary (IE, not run in slave nor Master)
350 VirtProcr *
351 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
353 void
354 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
356 void
357 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
359 void
360 VMS__shutdown();
362 void
363 VMS__cleanup_at_end_of_shutdown();
365 void *
366 VMS__give_sem_env_for( VirtProcr *animPr );
369 //============== Request Related ===============
371 void
372 VMS__suspend_procr( VirtProcr *callingPr );
374 inline void
375 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
377 /*inline*/ __attribute__ ((noinline)) void
378 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
380 void
381 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
383 void /*inline**/ __attribute__ ((noinline))
384 VMS__send_dissipate_req( VirtProcr *prToDissipate );
386 /*inline**/ __attribute__ ((noinline)) void
387 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
389 VMSReqst *
390 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
392 inline void *
393 VMS__take_sem_reqst_from( VMSReqst *req );
395 void inline
396 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
397 ResumePrFnPtr resumePrFnPtr );
399 //======================== STATS ======================
401 //===== RDTSC wrapper ===== //Also runs with x86_64 code
403 #define saveTimeStampCountInto(low, high) \
404 asm volatile("RDTSC; \
405 movl %%eax, %0; \
406 movl %%edx, %1;" \
407 /* outputs */ : "=m" (low), "=m" (high)\
408 /* inputs */ : \
409 /* clobber */ : "%eax", "%edx" \
410 );
412 #define saveLowTimeStampCountInto(low) \
413 asm volatile("RDTSC; \
414 movl %%eax, %0;" \
415 /* outputs */ : "=m" (low) \
416 /* inputs */ : \
417 /* clobber */ : "%eax", "%edx" \
418 );
420 //====================
421 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
422 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
423 _VMSMasterEnv->measHists[idx] = \
424 makeFixedBinHist( numBins, startVal, binWidth, name );
426 #define saveCyclesAndInstrs(core,cycles,instrs) do{ \
427 int cycles_fd = _VMSMasterEnv->cycles_counter_fd[core]; \
428 int instrs_fd = _VMSMasterEnv->instrs_counter_fd[core]; \
429 int nread; \
430 \
431 nread = read(cycles_fd,&(cycles),sizeof(cycles)); \
432 if(nread<0){ \
433 perror("Error reading cycles counter"); \
434 cycles = 0; \
435 } \
436 \
437 nread = read(instrs_fd,&(instrs),sizeof(instrs)); \
438 if(nread<0){ \
439 perror("Error reading cycles counter"); \
440 instrs = 0; \
441 } \
442 } while (0)
444 #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) do{ \
445 void* frame_ptr0 = vp_ptr->framePtr; \
446 void* frame_ptr1 = *((void**)frame_ptr0); \
447 void* frame_ptr2 = *((void**)frame_ptr1); \
448 void* frame_ptr3 = *((void**)frame_ptr2); \
449 void* ret_addr = *((void**)frame_ptr3 + 1); \
450 *res_ptr = ret_addr; \
451 } while (0)
453 #define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/
455 #ifdef VPTHREAD
457 //VPThread
458 #define createHistIdx 1
459 #define mutexLockHistIdx 2
460 #define mutexUnlockHistIdx 3
461 #define condWaitHistIdx 4
462 #define condSignalHistIdx 5
464 #define MakeTheMeasHists() \
465 _VMSMasterEnv->measHistsInfo = \
466 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
467 makeAMeasHist( createHistIdx, "create", 250, 0, 100 ) \
468 makeAMeasHist( mutexLockHistIdx, "mutex_lock", 50, 0, 100 ) \
469 makeAMeasHist( mutexUnlockHistIdx, "mutex_unlock", 50, 0, 100 ) \
470 makeAMeasHist( condWaitHistIdx, "cond_wait", 50, 0, 100 ) \
471 makeAMeasHist( condSignalHistIdx, "cond_signal", 50, 0, 100 )
473 #endif
476 #ifdef VCILK
478 //VCilk
479 #define spawnHistIdx 1
480 #define syncHistIdx 2
482 #define MakeTheMeasHists() \
483 _VMSMasterEnv->measHistsInfo = \
484 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
485 makeAMeasHist( spawnHistIdx, "Spawn", 50, 0, 200 ) \
486 makeAMeasHist( syncHistIdx, "Sync", 50, 0, 200 )
489 #endif
491 #ifdef SSR
493 //SSR
494 #define SendFromToHistIdx 1
495 #define SendOfTypeHistIdx 2
496 #define ReceiveFromToHistIdx 3
497 #define ReceiveOfTypeHistIdx 4
499 #define MakeTheMeasHists() \
500 _VMSMasterEnv->measHistsInfo = \
501 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
502 makeAMeasHist( SendFromToHistIdx, "SendFromTo", 50, 0, 100 ) \
503 makeAMeasHist( SendOfTypeHistIdx, "SendOfType", 50, 0, 100 ) \
504 makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
505 makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
507 #endif
509 //===========================================================================
510 //VPThread
513 #define Meas_startCreate \
514 int32 startStamp, endStamp; \
515 saveLowTimeStampCountInto( startStamp ); \
517 #define Meas_endCreate \
518 saveLowTimeStampCountInto( endStamp ); \
519 addIntervalToHist( startStamp, endStamp, \
520 _VMSMasterEnv->measHists[ createHistIdx ] );
522 #define Meas_startMutexLock \
523 int32 startStamp, endStamp; \
524 saveLowTimeStampCountInto( startStamp ); \
526 #define Meas_endMutexLock \
527 saveLowTimeStampCountInto( endStamp ); \
528 addIntervalToHist( startStamp, endStamp, \
529 _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
531 #define Meas_startMutexUnlock \
532 int32 startStamp, endStamp; \
533 saveLowTimeStampCountInto( startStamp ); \
535 #define Meas_endMutexUnlock \
536 saveLowTimeStampCountInto( endStamp ); \
537 addIntervalToHist( startStamp, endStamp, \
538 _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
540 #define Meas_startCondWait \
541 int32 startStamp, endStamp; \
542 saveLowTimeStampCountInto( startStamp ); \
544 #define Meas_endCondWait \
545 saveLowTimeStampCountInto( endStamp ); \
546 addIntervalToHist( startStamp, endStamp, \
547 _VMSMasterEnv->measHists[ condWaitHistIdx ] );
549 #define Meas_startCondSignal \
550 int32 startStamp, endStamp; \
551 saveLowTimeStampCountInto( startStamp ); \
553 #define Meas_endCondSignal \
554 saveLowTimeStampCountInto( endStamp ); \
555 addIntervalToHist( startStamp, endStamp, \
556 _VMSMasterEnv->measHists[ condSignalHistIdx ] );
558 //===========================================================================
559 // VCilk
560 #define Meas_startSpawn \
561 int32 startStamp, endStamp; \
562 saveLowTimeStampCountInto( startStamp ); \
564 #define Meas_endSpawn \
565 saveLowTimeStampCountInto( endStamp ); \
566 addIntervalToHist( startStamp, endStamp, \
567 _VMSMasterEnv->measHists[ spawnHistIdx ] );
569 #define Meas_startSync \
570 int32 startStamp, endStamp; \
571 saveLowTimeStampCountInto( startStamp ); \
573 #define Meas_endSync \
574 saveLowTimeStampCountInto( endStamp ); \
575 addIntervalToHist( startStamp, endStamp, \
576 _VMSMasterEnv->measHists[ syncHistIdx ] );
578 //===========================================================================
579 // SSR
580 #define Meas_startSendFromTo \
581 int32 startStamp, endStamp; \
582 saveLowTimeStampCountInto( startStamp ); \
584 #define Meas_endSendFromTo \
585 saveLowTimeStampCountInto( endStamp ); \
586 addIntervalToHist( startStamp, endStamp, \
587 _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
589 #define Meas_startSendOfType \
590 int32 startStamp, endStamp; \
591 saveLowTimeStampCountInto( startStamp ); \
593 #define Meas_endSendOfType \
594 saveLowTimeStampCountInto( endStamp ); \
595 addIntervalToHist( startStamp, endStamp, \
596 _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
598 #define Meas_startReceiveFromTo \
599 int32 startStamp, endStamp; \
600 saveLowTimeStampCountInto( startStamp ); \
602 #define Meas_endReceiveFromTo \
603 saveLowTimeStampCountInto( endStamp ); \
604 addIntervalToHist( startStamp, endStamp, \
605 _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
607 #define Meas_startReceiveOfType \
608 int32 startStamp, endStamp; \
609 saveLowTimeStampCountInto( startStamp ); \
611 #define Meas_endReceiveOfType \
612 saveLowTimeStampCountInto( endStamp ); \
613 addIntervalToHist( startStamp, endStamp, \
614 _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
616 //=====
618 #include "ProcrContext.h"
619 #include "probes.h"
620 #include "vutilities.h"
622 #endif /* _VMS_H */
