# HG changeset patch # User Merten Sach # Date 1326451745 -3600 # Node ID c66137e4dc2f65ebdfbee157987e95cf86544511 # Parent cf5faa15cb4d32633c81addff92664a5a08e6843 random wait time between tries to aquire master lock, because of performance penalties due to lock contention diff -r cf5faa15cb4d -r c66137e4dc2f CoreLoop.c --- a/CoreLoop.c Tue Dec 20 19:42:42 2011 +0100 +++ b/CoreLoop.c Fri Jan 13 11:49:05 2012 +0100 @@ -18,6 +18,9 @@ void *terminateCoreLoop(VirtProcr *currVP); +inline uint32_t +randomNumber(uint32_t* seed1, uint32_t* seed2); + /*This is the loop that runs in the OS Thread pinned to each core *Get virt procr from queue, * save state of current animator, then load in state of virt procr, using @@ -45,6 +48,10 @@ volatile int32 *masterLock; VirtProcr *masterVP; + // init random number generator for retries + uint32_t seed1 = rand()%1000; + uint32_t seed2 = rand()%1000; + //work-stealing struc on stack to prevent false-sharing in cache-line volatile GateStruc gate; //preGateProgress, waitProgress, exitProgress, gateClosed; @@ -67,6 +74,8 @@ &suspendLock ); } pthread_mutex_unlock( &suspendLock ); + + //coreLoopThdParams->wait_iterations_hist = makeHistogram( 100, 0, 10000 ); //printf( "\nCore unsuspended: %d\n", coreLoopThdParams->coreNum ); @@ -128,9 +137,15 @@ #endif //===================================================================== int tries = 0; int gotLock = 0; + unsigned int wait_iterations=0; while( currVP == NULL ) //if queue was empty, enter get masterLock loop { //queue was empty, so get master lock + if(numMasterInARow > 2){ + wait_iterations=(randomNumber(&seed1, &seed2) % (numMasterInARow*numMasterInARow))*100; + int i; + for(i=0; iwait_iterations_hist ); + int i; + for(i=0; i MASTERLOCK_RETRIES ) { tries = 0; pthread_yield(); } } + //============================= MEASUREMENT STUFF ===================== #ifdef MEAS__TIME_MASTER_LOCK saveLowTimeStampCountInto( endStamp ); @@ -181,11 +202,19 @@ }//CoreLoop } +inline uint32_t +randomNumber(uint32_t* seed1, uint32_t* seed2){ + *seed1 = 36969 * (*seed1 & 65535) + (*seed1 >> 16); + *seed2 = 18000 * (*seed2 & 65535) + (*seed2 >> 16); + return (*seed1 << 16) + *seed2; +} + void * terminateCoreLoop(VirtProcr *currVP){ //first free shutdown VP that jumped here -- it first restores the // coreloop's stack, so addr of currVP in stack frame is still correct + //printHist(coreLoopThdParams[currVP->coreAnimatedBy]->wait_iterations_hist); VMS__dissipate_procr( currVP ); pthread_exit( NULL ); }