annotate VMS.h @ 68:9c3107044f86

Added measurement hists macros
author Me
date Sat, 20 Nov 2010 08:19:05 +0100
parents 2377967a2732
children 11bfe9d136ed a49f02980151
rev   line source
Me@42 1 /*
Me@42 2 * Copyright 2009 OpenSourceStewardshipFoundation.org
Me@42 3 * Licensed under GNU General Public License version 2
Me@42 4 *
Me@42 5 * Author: seanhalle@yahoo.com
Me@42 6 *
Me@42 7 */
Me@42 8
Me@42 9 #ifndef _VMS_H
Me@42 10 #define _VMS_H
Me@42 11 #define __USE_GNU
Me@42 12
Me@42 13 #include "VMS_primitive_data_types.h"
Me@55 14 #include "Queue_impl/PrivateQueue.h"
Me@42 15 #include "Histogram/Histogram.h"
Me@50 16 #include "DynArray/DynArray.h"
Me@50 17 #include "Hash_impl/PrivateHash.h"
Me@50 18 #include "vmalloc.h"
Me@50 19
Me@42 20 #include <pthread.h>
Me@50 21 #include <sys/time.h>
Me@42 22
Me@50 23
Me@50 24 //=============================== Debug ===================================
Me@55 25 //
Me@45 26 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
Me@42 27 // It still does co-routines and all the mechanisms are the same, it just
Me@42 28 // has only a single thread and animates VPs one at a time
Me@45 29 //#define SEQUENTIAL
Me@42 30
Me@55 31 //#define USE_WORK_STEALING
Me@55 32
Me@52 33 //turns on the probe-instrumentation in the application -- when not
Me@52 34 // defined, the calls to the probe functions turn into comments
Me@52 35 #define STATS__ENABLE_PROBES
Me@60 36 //#define TURN_ON_DEBUG_PROBES
Me@52 37
Me@55 38 //These defines turn types of bug messages on and off
Me@55 39 // be sure debug messages are un-commented (next block of defines)
Me@68 40 #define dbgAppFlow TRUE /* Top level flow of application code -- general*/
Me@60 41 #define dbgProbes FALSE /* for issues inside probes themselves*/
Me@60 42 #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
Me@60 43 #define dbgRqstHdlr FALSE /* in request handler code*/
Me@52 44
Me@55 45 //Comment or un- the substitute half to turn on/off types of debug message
Me@55 46 #define DEBUG( bool, msg) \
Me@68 47 // if( bool){ printf(msg); fflush(stdin);}
Me@55 48 #define DEBUG1( bool, msg, param) \
Me@60 49 // if(bool){printf(msg, param); fflush(stdin);}
Me@55 50 #define DEBUG2( bool, msg, p1, p2) \
Me@60 51 // if(bool) {printf(msg, p1, p2); fflush(stdin);}
Me@45 52
Me@55 53 #define ERROR(msg) printf(msg); fflush(stdin);
Me@55 54 #define ERROR1(msg, param) printf(msg, param); fflush(stdin);
Me@55 55 #define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
Me@50 56
Me@50 57 //=========================== STATS =======================
Me@50 58
Me@45 59 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
Me@42 60 // compiled-in that saves the low part of the time stamp count just before
Me@42 61 // suspending a processor and just after resuming that processor. It is
Me@42 62 // saved into a field added to VirtProcr. Have to sanity-check for
Me@42 63 // rollover of low portion into high portion.
Me@65 64 //#define MEAS__TIME_STAMP_SUSP
Me@65 65 //#define MEAS__TIME_MASTER
Me@67 66 #define MEAS__TIME_PLUGIN
Me@67 67 #define MEAS__TIME_MALLOC
Me@68 68 //#define MEAS__TIME_MASTER_LOCK
Me@42 69 #define MEAS__NUM_TIMES_TO_RUN 100000
Me@42 70
Me@55 71 //For code that calculates normalization-offset between TSC counts of
Me@55 72 // different cores.
Me@45 73 #define NUM_TSC_ROUND_TRIPS 10
Me@45 74
Me@50 75
Me@50 76 //========================= Hardware related Constants =====================
Me@42 77 //This value is the number of hardware threads in the shared memory
Me@42 78 // machine
Me@42 79 #define NUM_CORES 4
Me@42 80
Me@55 81 // tradeoff amortizing master fixed overhead vs imbalance potential
Me@55 82 // when work-stealing, can make bigger, at risk of losing cache affinity
Me@55 83 #define NUM_SCHED_SLOTS 5
Me@42 84
Me@45 85 #define MIN_WORK_UNIT_CYCLES 20000
Me@45 86
Me@53 87 #define MASTERLOCK_RETRIES 10000
Me@42 88
Me@54 89 // stack size in virtual processors created
Me@54 90 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
Me@42 91
Me@54 92 // memory for VMS__malloc
Me@54 93 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
Me@42 94
Me@50 95
Me@50 96 //==============================
Me@42 97
Me@42 98 #define SUCCESS 0
Me@42 99
Me@55 100 #define writeVMSQ writePrivQ
Me@55 101 #define readVMSQ readPrivQ
Me@64 102 #define makeVMSQ makeVMSPrivQ
Me@55 103 #define numInVMSQ numInPrivQ
Me@55 104 #define VMSQueueStruc PrivQueueStruc
Me@42 105
Me@42 106
Me@50 107
Me@50 108 //===========================================================================
Me@50 109 typedef unsigned long long TSCount;
Me@50 110
Me@50 111 typedef struct _SchedSlot SchedSlot;
Me@50 112 typedef struct _VMSReqst VMSReqst;
Me@50 113 typedef struct _VirtProcr VirtProcr;
Me@50 114 typedef struct _IntervalProbe IntervalProbe;
Me@55 115 typedef struct _GateStruc GateStruc;
Me@55 116
Me@42 117
Me@42 118 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
Me@42 119 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
Me@42 120 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
Me@42 121 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
Me@50 122 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
Me@50 123
Me@50 124
Me@50 125 //============= Requests ===========
Me@50 126 //
Me@50 127
Me@50 128 enum VMSReqstType //avoid starting enums at 0, for debug reasons
Me@50 129 {
Me@50 130 semantic = 1,
Me@50 131 createReq,
Me@50 132 dissipate,
Me@50 133 VMSSemantic //goes with VMSSemReqst below
Me@50 134 };
Me@50 135
Me@50 136 struct _VMSReqst
Me@50 137 {
Me@50 138 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
Me@50 139 void *semReqData;
Me@50 140
Me@50 141 VMSReqst *nextReqst;
Me@50 142 };
Me@50 143 //VMSReqst
Me@50 144
Me@50 145 enum VMSSemReqstType //These are equivalent to semantic requests, but for
Me@50 146 { // VMS's services available directly to app, like OS
Me@50 147 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
Me@50 148 openFile,
Me@50 149 otherIO
Me@50 150 };
Me@42 151
Me@42 152 typedef struct
Me@50 153 { enum VMSSemReqstType reqType;
Me@50 154 VirtProcr *requestingPr;
Me@50 155 char *nameStr; //for create probe
Me@42 156 }
Me@50 157 VMSSemReq;
Me@42 158
Me@42 159
Me@50 160 //==================== Core data structures ===================
Me@50 161
Me@42 162 struct _SchedSlot
Me@42 163 {
Me@42 164 int workIsDone;
Me@42 165 int needsProcrAssigned;
Me@42 166 VirtProcr *procrAssignedToSlot;
Me@42 167 };
Me@42 168 //SchedSlot
Me@42 169
Me@62 170 /*WARNING: re-arranging this data structure could cause VP switching
Me@64 171 * assembly code to fail -- hard-codes offsets of fields
Me@62 172 */
Me@42 173 struct _VirtProcr
Me@42 174 { int procrID; //for debugging -- count up each time create
Me@42 175 int coreAnimatedBy;
Me@42 176 void *startOfStack;
Me@42 177 void *stackPtr;
Me@42 178 void *framePtr;
Me@42 179 void *nextInstrPt;
Me@42 180
Me@42 181 void *coreLoopStartPt; //allows proto-runtime to be linked later
Me@42 182 void *coreLoopFramePtr; //restore before jmp back to core loop
Me@42 183 void *coreLoopStackPtr; //restore before jmp back to core loop
Me@42 184
Me@42 185 void *initialData;
Me@42 186
Me@42 187 SchedSlot *schedSlot;
Me@42 188 VMSReqst *requests;
Me@42 189
Me@50 190 void *semanticData; //this lives here for the life of VP
Me@53 191 void *dataRetFromReq;//values returned from plugin to VP go here
Me@42 192
Me@50 193 //=========== MEASUREMENT STUFF ==========
Me@42 194 #ifdef MEAS__TIME_STAMP_SUSP
Me@42 195 unsigned int preSuspTSCLow;
Me@42 196 unsigned int postSuspTSCLow;
Me@42 197 #endif
Me@65 198 #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
Me@42 199 unsigned int startMasterTSCLow;
Me@42 200 unsigned int endMasterTSCLow;
Me@42 201 #endif
Me@65 202 //========================================
Me@50 203
Me@50 204 float64 createPtInSecs; //have space but don't use on some configs
Me@42 205 };
Me@42 206 //VirtProcr
Me@42 207
Me@42 208
Me@62 209 /*WARNING: re-arranging this data structure could cause VP-switching
Me@62 210 * assembly code to fail -- hard-codes offsets of fields
Me@62 211 * (because -O3 messes with things otherwise)
Me@62 212 */
Me@42 213 typedef struct
Me@42 214 {
Me@42 215 SlaveScheduler slaveScheduler;
Me@42 216 RequestHandler requestHandler;
Me@42 217
Me@42 218 SchedSlot ***allSchedSlots;
Me@55 219 VMSQueueStruc **readyToAnimateQs;
Me@42 220 VirtProcr **masterVPs;
Me@42 221
Me@42 222 void *semanticEnv;
Me@42 223 void *OSEventStruc; //for future, when add I/O to BLIS
Me@50 224 MallocProlog *freeListHead;
Me@50 225 int32 amtOfOutstandingMem; //total currently allocated
Me@42 226
Me@42 227 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
Me@42 228 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
Me@42 229
Me@50 230 int32 setupComplete;
Me@50 231 int32 masterLock;
Me@42 232
Me@50 233 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
Me@59 234 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
Me@55 235 int32 workStealingLock;
Me@55 236
Me@50 237 int32 numProcrsCreated; //gives ordering to processor creation
Me@50 238
Me@50 239 //=========== MEASUREMENT STUFF =============
Me@50 240 IntervalProbe **intervalProbes;
Me@53 241 PrivDynArrayInfo *dynIntervalProbesInfo;
Me@50 242 HashTable *probeNameHashTbl;
Me@50 243 int32 masterCreateProbeID;
Me@50 244 float64 createPtInSecs;
Me@68 245 Histogram **measHists;
Me@68 246 PrivDynArrayInfo *measHistsInfo;
Me@65 247 #ifdef MEAS__TIME_PLUGIN
Me@68 248 Histogram *reqHdlrLowTimeHist;
Me@68 249 Histogram *reqHdlrHighTimeHist;
Me@65 250 #endif
Me@65 251 #ifdef MEAS__TIME_MALLOC
Me@65 252 Histogram *mallocTimeHist;
Me@65 253 Histogram *freeTimeHist;
Me@65 254 #endif
Me@65 255 #ifdef MEAS__TIME_MASTER_LOCK
Me@65 256 Histogram *masterLockLowTimeHist;
Me@65 257 Histogram *masterLockHighTimeHist;
Me@65 258 #endif
Me@42 259 }
Me@42 260 MasterEnv;
Me@42 261
Me@55 262 //========================= Extra Stuff Data Strucs =======================
Me@54 263 typedef struct
Me@54 264 {
Me@42 265
Me@54 266 }
Me@54 267 VMSExcp;
Me@50 268
Me@55 269 struct _GateStruc
Me@55 270 {
Me@55 271 int32 gateClosed;
Me@55 272 int32 preGateProgress;
Me@55 273 int32 waitProgress;
Me@55 274 int32 exitProgress;
Me@55 275 };
Me@55 276 //GateStruc
Me@50 277
Me@50 278 //======================= OS Thread related ===============================
Me@42 279
Me@42 280 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
Me@42 281 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
Me@42 282 void masterLoop( void *initData, VirtProcr *masterPr );
Me@42 283
Me@42 284
Me@50 285 typedef struct
Me@50 286 {
Me@50 287 void *endThdPt;
Me@50 288 unsigned int coreNum;
Me@50 289 }
Me@50 290 ThdParams;
Me@42 291
Me@42 292 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
Me@42 293 ThdParams *coreLoopThdParams [ NUM_CORES ];
Me@42 294 pthread_mutex_t suspendLock;
Me@42 295 pthread_cond_t suspend_cond;
Me@42 296
Me@50 297
Me@50 298
Me@50 299 //===================== Global Vars ===================
Me@50 300
Me@42 301 volatile MasterEnv *_VMSMasterEnv;
Me@42 302
Me@50 303
Me@50 304
Me@50 305
Me@50 306 //=========================== Function Prototypes =========================
Me@50 307
Me@53 308
Me@53 309 //========== Setup and shutdown ==========
Me@42 310 void
Me@42 311 VMS__init();
Me@42 312
Me@42 313 void
Me@42 314 VMS__init_Seq();
Me@42 315
Me@42 316 void
Me@42 317 VMS__start_the_work_then_wait_until_done();
Me@42 318
Me@42 319 void
Me@42 320 VMS__start_the_work_then_wait_until_done_Seq();
Me@42 321
Me@42 322 VirtProcr *
Me@42 323 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@42 324
Me@53 325 void
Me@53 326 VMS__dissipate_procr( VirtProcr *procrToDissipate );
Me@53 327
Me@50 328 //Use this to create processor inside entry point & other places outside
Me@50 329 // the VMS system boundary (IE, not run in slave nor Master)
Me@50 330 VirtProcr *
Me@50 331 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@50 332
Me@53 333 void
Me@53 334 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
Me@42 335
Me@50 336 void
Me@54 337 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
Me@54 338
Me@54 339 void
Me@53 340 VMS__shutdown();
Me@53 341
Me@53 342 void
Me@53 343 VMS__cleanup_at_end_of_shutdown();
Me@50 344
Me@64 345 void *
Me@64 346 VMS__give_sem_env_for( VirtProcr *animPr );
Me@64 347
Me@50 348
Me@50 349 //============== Request Related ===============
Me@50 350
Me@50 351 void
Me@50 352 VMS__suspend_procr( VirtProcr *callingPr );
Me@50 353
Me@42 354 inline void
Me@53 355 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
Me@53 356
Me@53 357 inline void
Me@53 358 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
Me@42 359
Me@42 360 void
Me@50 361 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
Me@42 362
Me@53 363 void inline
Me@53 364 VMS__send_dissipate_req( VirtProcr *prToDissipate );
Me@53 365
Me@52 366 inline void
Me@52 367 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
Me@52 368
Me@42 369 VMSReqst *
Me@50 370 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
Me@42 371
Me@42 372 inline void *
Me@42 373 VMS__take_sem_reqst_from( VMSReqst *req );
Me@42 374
Me@53 375 //======================== STATS ======================
Me@42 376
Me@53 377 //===== RDTSC wrapper =====
Me@42 378
Me@42 379 #define saveTimeStampCountInto(low, high) \
Me@42 380 asm volatile("RDTSC; \
Me@42 381 movl %%eax, %0; \
Me@42 382 movl %%edx, %1;" \
Me@42 383 /* outputs */ : "=m" (low), "=m" (high)\
Me@42 384 /* inputs */ : \
Me@42 385 /* clobber */ : "%eax", "%edx" \
Me@42 386 );
Me@42 387
Me@42 388 #define saveLowTimeStampCountInto(low) \
Me@42 389 asm volatile("RDTSC; \
Me@42 390 movl %%eax, %0;" \
Me@42 391 /* outputs */ : "=m" (low) \
Me@42 392 /* inputs */ : \
Me@42 393 /* clobber */ : "%eax", "%edx" \
Me@42 394 );
Me@68 395
Me@68 396 //====================
Me@68 397 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
Me@68 398 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
Me@68 399 _VMSMasterEnv->measHists[idx] = \
Me@68 400 makeFixedBinHist( numBins, startVal, binWidth, name );
Me@68 401
Me@68 402
Me@68 403 #define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/
Me@68 404 #define createHistIdx 1
Me@68 405 #define mutexLockHistIdx 2
Me@68 406 #define mutexUnlockHistIdx 3
Me@68 407 #define condWaitHistIdx 4
Me@68 408 #define condSignalHistIdx 5
Me@68 409
Me@68 410
Me@68 411 #define MakeTheMeasHists \
Me@68 412 _VMSMasterEnv->measHistsInfo = \
Me@68 413 makePrivDynArrayOfSize( &(_VMSMasterEnv->measHists), 200);\
Me@68 414 makeAMeasHist( createHistIdx, "Create", 50, 0, 200 ) \
Me@68 415 makeAMeasHist( mutexLockHistIdx, "mutex lock", 50, 0, 100 ) \
Me@68 416 makeAMeasHist( mutexUnlockHistIdx, "mutex unlock", 50, 0, 100 ) \
Me@68 417 makeAMeasHist( condWaitHistIdx, "cond wait", 50, 0, 100 ) \
Me@68 418 makeAMeasHist( condSignalHistIdx, "cond signal", 50, 0, 100 )
Me@68 419
Me@68 420 #define Meas_startCreate \
Me@68 421 int32 startStamp, endStamp; \
Me@68 422 saveLowTimeStampCountInto( startStamp ); \
Me@68 423
Me@68 424 #define Meas_endCreate \
Me@68 425 saveLowTimeStampCountInto( endStamp ); \
Me@68 426 addIntervalToHist( startStamp, endStamp, \
Me@68 427 _VMSMasterEnv->measHists[ createHistIdx ] );
Me@68 428
Me@68 429 #define Meas_startMutexLock \
Me@68 430 int32 startStamp, endStamp; \
Me@68 431 saveLowTimeStampCountInto( startStamp ); \
Me@68 432
Me@68 433 #define Meas_endMutexLock \
Me@68 434 saveLowTimeStampCountInto( endStamp ); \
Me@68 435 addIntervalToHist( startStamp, endStamp, \
Me@68 436 _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
Me@68 437
Me@68 438 #define Meas_startMutexUnlock \
Me@68 439 int32 startStamp, endStamp; \
Me@68 440 saveLowTimeStampCountInto( startStamp ); \
Me@68 441
Me@68 442 #define Meas_endMutexUnlock \
Me@68 443 saveLowTimeStampCountInto( endStamp ); \
Me@68 444 addIntervalToHist( startStamp, endStamp, \
Me@68 445 _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
Me@68 446
Me@68 447 #define Meas_startCondWait \
Me@68 448 int32 startStamp, endStamp; \
Me@68 449 saveLowTimeStampCountInto( startStamp ); \
Me@68 450
Me@68 451 #define Meas_endCondWait \
Me@68 452 saveLowTimeStampCountInto( endStamp ); \
Me@68 453 addIntervalToHist( startStamp, endStamp, \
Me@68 454 _VMSMasterEnv->measHists[ condWaitHistIdx ] );
Me@68 455
Me@68 456 #define Meas_startCondSignal \
Me@68 457 int32 startStamp, endStamp; \
Me@68 458 saveLowTimeStampCountInto( startStamp ); \
Me@68 459
Me@68 460 #define Meas_endCondSignal \
Me@68 461 saveLowTimeStampCountInto( endStamp ); \
Me@68 462 addIntervalToHist( startStamp, endStamp, \
Me@68 463 _VMSMasterEnv->measHists[ condSignalHistIdx ] );
Me@68 464
Me@68 465
Me@53 466 //=====
Me@42 467
Me@55 468 #include "SwitchAnimators.h"
Me@50 469 #include "probes.h"
Me@65 470 #include "vutilities.h"
Me@42 471
Me@42 472 #endif /* _VMS_H */
Me@42 473