Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 134:a9b72021f053
Distributed memory management w/o free requests working
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Fri, 16 Sep 2011 16:19:24 +0200 |
| parents | dbfc8382d546 |
| children | 0b49fd35afc1 |
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 */
8 #ifndef _VMS_H
9 #define _VMS_H
10 #define _GNU_SOURCE
12 #include <pthread.h>
13 #include <sys/time.h>
15 #include "VMS_primitive_data_types.h"
16 #include "Queue_impl/PrivateQueue.h"
17 #include "Histogram/Histogram.h"
18 #include "DynArray/DynArray.h"
19 #include "Hash_impl/PrivateHash.h"
20 #include "vmalloc.h"
21 #include "requests.h"
23 //=============================== Debug ===================================
24 //
25 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
26 // It still does co-routines and all the mechanisms are the same, it just
27 // has only a single thread and animates VPs one at a time
28 //#define SEQUENTIAL
30 //#define USE_WORK_STEALING
32 //turns on the probe-instrumentation in the application -- when not
33 // defined, the calls to the probe functions turn into comments
34 #define STATS__ENABLE_PROBES
35 //#define TURN_ON_DEBUG_PROBES
37 //These defines turn types of bug messages on and off
38 // be sure debug messages are un-commented (next block of defines)
39 #define dbgAppFlow TRUE /* Top level flow of application code -- general*/
40 #define dbgProbes FALSE /* for issues inside probes themselves*/
41 #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
42 #define dbgRqstHdlr FALSE /* in request handler code*/
44 //Comment or un- the substitute half to turn on/off types of debug message
45 #define DEBUG( bool, msg) \
46 // if( bool){ printf(msg); fflush(stdin);}
47 #define DEBUG1( bool, msg, param) \
48 // if(bool){printf(msg, param); fflush(stdin);}
49 #define DEBUG2( bool, msg, p1, p2) \
50 // if(bool) {printf(msg, p1, p2); fflush(stdin);}
52 #define ERROR(msg) printf(msg);
53 #define ERROR1(msg, param) printf(msg, param);
54 #define ERROR2(msg, p1, p2) printf(msg, p1, p2);
56 //=========================== STATS =======================
58 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
59 // compiled-in that saves the low part of the time stamp count just before
60 // 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
61 // saved into a field added to VirtProcr. Have to sanity-check for
62 // rollover of low portion into high portion.
63 //#define MEAS__TIME_STAMP_SUSP
64 //#define MEAS__TIME_MASTER
65 #define MEAS__TIME_PLUGIN
66 #define MEAS__TIME_MALLOC
67 //#define MEAS__TIME_MASTER_LOCK
68 #define MEAS__NUM_TIMES_TO_RUN 100000
70 //For code that calculates normalization-offset between TSC counts of
71 // different cores.
72 #define NUM_TSC_ROUND_TRIPS 10
75 //========================= Hardware related Constants =====================
76 //This value is the number of hardware threads in the shared memory
77 // machine
78 #define NUM_CORES 8
80 // tradeoff amortizing master fixed overhead vs imbalance potential
81 // when work-stealing, can make bigger, at risk of losing cache affinity
82 #define NUM_SCHED_SLOTS 5
84 #define MIN_WORK_UNIT_CYCLES 20000
86 #define MASTERLOCK_RETRIES 10000
88 // stack size in virtual processors created
89 #define VIRT_PROCR_STACK_SIZE 0x8000 /* 32K */
91 // memory for VMS__malloc
92 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x4000000 /* 64M */
94 #define CACHE_LINE 64
95 #define PAGE_SIZE 4096
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 _IntervalProbe IntervalProbe;
114 typedef struct _GateStruc GateStruc;
117 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
118 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
119 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
122 //==================== Core data structures ===================
124 /*Master Env is the only global variable -- has entry points for any other
125 * data needed.
126 */
127 typedef struct
128 {
129 SlaveScheduler slaveScheduler;
130 RequestHandler requestHandler;
132 SchedSlot ***allSchedSlots;
133 VMSQueueStruc **readyToAnimateQs;
134 VirtProcr **masterVPs;
136 void *semanticEnv;
137 void *OSEventStruc; //for future, when add I/O to BLIS
139 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
141 int32 setupComplete;
142 volatile int32 masterLock;
144 MallocProlog *freeListHead[NUM_CORES];
145 int32 amtOfOutstandingMem; //total currently allocated
147 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
148 GateStruc *workStealingGates[NUM_CORES]; //concurrent work-steal
149 int32 workStealingLock;
151 InterMasterReqst* interMasterRequestsFor[NUM_CORES];
152 RequestHandler interPluginReqHdlr;
154 int32 numProcrsCreated; //gives ordering to processor creation
156 int32 currentMasterProcrID;
158 //=========== MEASUREMENT STUFF =============
159 IntervalProbe **intervalProbes;
160 PrivDynArrayInfo *dynIntervalProbesInfo;
161 HashTable *probeNameHashTbl;
162 int32 masterCreateProbeID;
163 float64 createPtInSecs;
164 Histogram **measHists;
165 PrivDynArrayInfo *measHistsInfo;
166 #ifdef MEAS__TIME_PLUGIN
167 Histogram *reqHdlrLowTimeHist;
168 Histogram *reqHdlrHighTimeHist;
169 #endif
170 #ifdef MEAS__TIME_MALLOC
171 Histogram *mallocTimeHist;
172 Histogram *freeTimeHist;
173 #endif
174 #ifdef MEAS__TIME_MASTER_LOCK
175 Histogram *masterLockLowTimeHist;
176 Histogram *masterLockHighTimeHist;
177 #endif
178 }
179 MasterEnv;
181 //========================= Extra Stuff Data Strucs =======================
182 typedef struct
183 {
185 }
186 VMSExcp;
188 struct _GateStruc
189 {
190 int32 gateClosed;
191 int32 preGateProgress;
192 int32 waitProgress;
193 int32 exitProgress;
194 };
195 //GateStruc
197 //======================= OS Thread related ===============================
199 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
200 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
201 void masterLoop( void *initData, VirtProcr *masterPr );
204 typedef struct
205 {
206 void *endThdPt;
207 unsigned int coreNum;
208 }
209 ThdParams;
211 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
212 ThdParams *coreLoopThdParams [ NUM_CORES ];
213 pthread_mutex_t suspendLock;
214 pthread_cond_t suspend_cond;
218 //===================== Global Vars ===================
220 volatile MasterEnv *_VMSMasterEnv;
223 //=========================== Function Prototypes =========================
226 //========== Setup and shutdown ==========
227 void
228 VMS__init();
230 void
231 VMS__init_Seq();
233 void
234 VMS__start_the_work_then_wait_until_done();
236 void
237 VMS__start_the_work_then_wait_until_done_Seq();
239 inline VirtProcr *
240 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
242 void
243 VMS__dissipate_procr( VirtProcr *procrToDissipate );
245 //Use this to create processor inside entry point & other places outside
246 // the VMS system boundary (IE, not run in slave nor Master)
247 VirtProcr *
248 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
250 void
251 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
253 void
254 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
256 void
257 VMS__shutdown();
259 void
260 VMS__cleanup_at_end_of_shutdown();
262 void *
263 VMS__give_sem_env_for( VirtProcr *animPr );
266 //============== Request Related ===============
268 void
269 VMS__suspend_procr( VirtProcr *callingPr );
271 inline void
272 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
274 inline void
275 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
277 void
278 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
280 void inline
281 VMS__send_dissipate_req( VirtProcr *prToDissipate );
283 inline void
284 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
287 void inline
288 VMS__send_inter_plugin_req( void *reqData, int32 targetMaster,
289 VirtProcr *requestingMaster );
290 void inline
291 VMS__send_inter_VMSCore_req( InterVMSCoreReqst *reqData, int32 targetMaster,
292 VirtProcr *requestingMaster );
294 VMSReqst *
295 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
297 inline void *
298 VMS__take_sem_reqst_from( VMSReqst *req );
300 void inline
301 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
302 ResumePrFnPtr resumePrFnPtr );
304 //======================== STATS ======================
306 //===== RDTSC wrapper ===== //Also runs with x86_64 code
308 #define saveTimeStampCountInto(low, high) \
309 asm volatile("RDTSC; \
310 movl %%eax, %0; \
311 movl %%edx, %1;" \
312 /* outputs */ : "=m" (low), "=m" (high)\
313 /* inputs */ : \
314 /* clobber */ : "%eax", "%edx" \
315 );
317 #define saveLowTimeStampCountInto(low) \
318 asm volatile("RDTSC; \
319 movl %%eax, %0;" \
320 /* outputs */ : "=m" (low) \
321 /* inputs */ : \
322 /* clobber */ : "%eax", "%edx" \
323 );
325 //====================
326 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
327 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
328 _VMSMasterEnv->measHists[idx] = \
329 makeFixedBinHist( numBins, startVal, binWidth, name );
332 #define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/
334 #ifdef VPTHREAD
336 //VPThread
337 #define createHistIdx 1
338 #define mutexLockHistIdx 2
339 #define mutexUnlockHistIdx 3
340 #define condWaitHistIdx 4
341 #define condSignalHistIdx 5
343 #define MakeTheMeasHists() \
344 _VMSMasterEnv->measHistsInfo = \
345 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
346 makeAMeasHist( createHistIdx, "create", 250, 0, 100 ) \
347 makeAMeasHist( mutexLockHistIdx, "mutex_lock", 50, 0, 100 ) \
348 makeAMeasHist( mutexUnlockHistIdx, "mutex_unlock", 50, 0, 100 ) \
349 makeAMeasHist( condWaitHistIdx, "cond_wait", 50, 0, 100 ) \
350 makeAMeasHist( condSignalHistIdx, "cond_signal", 50, 0, 100 )
352 #endif
355 #ifdef VCILK
357 //VCilk
358 #define spawnHistIdx 1
359 #define syncHistIdx 2
361 #define MakeTheMeasHists() \
362 _VMSMasterEnv->measHistsInfo = \
363 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
364 makeAMeasHist( spawnHistIdx, "Spawn", 50, 0, 200 ) \
365 makeAMeasHist( syncHistIdx, "Sync", 50, 0, 200 )
368 #endif
370 #ifdef SSR
372 //SSR
373 #define SendFromToHistIdx 1
374 #define SendOfTypeHistIdx 2
375 #define ReceiveFromToHistIdx 3
376 #define ReceiveOfTypeHistIdx 4
378 #define MakeTheMeasHists() \
379 _VMSMasterEnv->measHistsInfo = \
380 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
381 makeAMeasHist( SendFromToHistIdx, "SendFromTo", 50, 0, 100 ) \
382 makeAMeasHist( SendOfTypeHistIdx, "SendOfType", 50, 0, 100 ) \
383 makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
384 makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
386 #endif
388 //===========================================================================
389 //VPThread
392 #define Meas_startCreate \
393 int32 startStamp, endStamp; \
394 saveLowTimeStampCountInto( startStamp ); \
396 #define Meas_endCreate \
397 saveLowTimeStampCountInto( endStamp ); \
398 addIntervalToHist( startStamp, endStamp, \
399 _VMSMasterEnv->measHists[ createHistIdx ] );
401 #define Meas_startMutexLock \
402 int32 startStamp, endStamp; \
403 saveLowTimeStampCountInto( startStamp ); \
405 #define Meas_endMutexLock \
406 saveLowTimeStampCountInto( endStamp ); \
407 addIntervalToHist( startStamp, endStamp, \
408 _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
410 #define Meas_startMutexUnlock \
411 int32 startStamp, endStamp; \
412 saveLowTimeStampCountInto( startStamp ); \
414 #define Meas_endMutexUnlock \
415 saveLowTimeStampCountInto( endStamp ); \
416 addIntervalToHist( startStamp, endStamp, \
417 _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
419 #define Meas_startCondWait \
420 int32 startStamp, endStamp; \
421 saveLowTimeStampCountInto( startStamp ); \
423 #define Meas_endCondWait \
424 saveLowTimeStampCountInto( endStamp ); \
425 addIntervalToHist( startStamp, endStamp, \
426 _VMSMasterEnv->measHists[ condWaitHistIdx ] );
428 #define Meas_startCondSignal \
429 int32 startStamp, endStamp; \
430 saveLowTimeStampCountInto( startStamp ); \
432 #define Meas_endCondSignal \
433 saveLowTimeStampCountInto( endStamp ); \
434 addIntervalToHist( startStamp, endStamp, \
435 _VMSMasterEnv->measHists[ condSignalHistIdx ] );
437 //===========================================================================
438 // VCilk
439 #define Meas_startSpawn \
440 int32 startStamp, endStamp; \
441 saveLowTimeStampCountInto( startStamp ); \
443 #define Meas_endSpawn \
444 saveLowTimeStampCountInto( endStamp ); \
445 addIntervalToHist( startStamp, endStamp, \
446 _VMSMasterEnv->measHists[ spawnHistIdx ] );
448 #define Meas_startSync \
449 int32 startStamp, endStamp; \
450 saveLowTimeStampCountInto( startStamp ); \
452 #define Meas_endSync \
453 saveLowTimeStampCountInto( endStamp ); \
454 addIntervalToHist( startStamp, endStamp, \
455 _VMSMasterEnv->measHists[ syncHistIdx ] );
457 //===========================================================================
458 // SSR
459 #define Meas_startSendFromTo \
460 int32 startStamp, endStamp; \
461 saveLowTimeStampCountInto( startStamp ); \
463 #define Meas_endSendFromTo \
464 saveLowTimeStampCountInto( endStamp ); \
465 addIntervalToHist( startStamp, endStamp, \
466 _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
468 #define Meas_startSendOfType \
469 int32 startStamp, endStamp; \
470 saveLowTimeStampCountInto( startStamp ); \
472 #define Meas_endSendOfType \
473 saveLowTimeStampCountInto( endStamp ); \
474 addIntervalToHist( startStamp, endStamp, \
475 _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
477 #define Meas_startReceiveFromTo \
478 int32 startStamp, endStamp; \
479 saveLowTimeStampCountInto( startStamp ); \
481 #define Meas_endReceiveFromTo \
482 saveLowTimeStampCountInto( endStamp ); \
483 addIntervalToHist( startStamp, endStamp, \
484 _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
486 #define Meas_startReceiveOfType \
487 int32 startStamp, endStamp; \
488 saveLowTimeStampCountInto( startStamp ); \
490 #define Meas_endReceiveOfType \
491 saveLowTimeStampCountInto( endStamp ); \
492 addIntervalToHist( startStamp, endStamp, \
493 _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
495 //=====
497 #include "probes.h"
498 #include "vutilities.h"
500 #endif /* _VMS_H */
