changeset 66:bf08108405cc recycle_pool

Added recycle pool -- will merge later -- need to get PLDI results for now
author Me
date Mon, 15 Nov 2010 12:11:24 -0800
parents 13b22ffb8a2f
children
files CoreLoop.c SwitchAnimators.h VMS.c VMS.h vmalloc.c vmalloc.h
diffstat 6 files changed, 137 insertions(+), 34 deletions(-) [+]
line diff
     1.1 --- a/CoreLoop.c	Sun Nov 14 11:17:52 2010 -0800
     1.2 +++ b/CoreLoop.c	Mon Nov 15 12:11:24 2010 -0800
     1.3 @@ -144,44 +144,25 @@
     1.4              break;  //end while -- have a VP to animate now
     1.5            }
     1.6  
     1.7 -         tries++;      //if too many, means master on other core taking too long
     1.8 -         if( tries > MASTERLOCK_RETRIES ) { tries = 0; pthread_yield(); }
     1.9 +         tries++;   //if too many, means master on other core taking too long
    1.10 +         if( tries > MASTERLOCK_RETRIES )
    1.11 +          { tries = 0; pthread_yield(); }
    1.12         }
    1.13        //============================= MEASUREMENT STUFF =====================
    1.14        #ifdef MEAS__TIME_MASTER_LOCK
    1.15        saveLowTimeStampCountInto( endStamp );
    1.16 +      //addIntervalToHist( startStamp, endStamp,
    1.17 +      //                   _VMSMasterEnv->masterLockLowTimeHist );
    1.18        addIntervalToHist( startStamp, endStamp,
    1.19 -                         _VMSMasterEnv->masterLockLowTimeHist );
    1.20 -      addIntervalToHist( startStamp, endStamp,
    1.21 -                         _VMSMasterEnv->masterLockHighTimeHist );
    1.22 +                         _VMSMasterEnv->masterLockHighTimeHist);
    1.23        #endif
    1.24        //=====================================================================
    1.25  
    1.26      }
    1.27 -/* VirtProcr  offsets:
    1.28 - * 0xc  stackPtr
    1.29 - * 0x10 framePtr
    1.30 - * 0x14 nextInstrPt
    1.31 - * 0x1c coreLoopFramePtr
    1.32 - * 0x20 coreLoopStackPtr
    1.33 - *
    1.34 - * _VMSMasterEnv  offsets:
    1.35 - * 0x24 coreLoopStartPt
    1.36 - * 0x28 coreLoopEndPt
    1.37 - * 0x30 masterLock
    1.38 - */
    1.39 -//   SwitchToVP( currPr )
    1.40 -   asm volatile("movl         %0,      %%ebx;  \
    1.41 -                 movl      %%esp, 0x20(%%ebx); \
    1.42 -                 movl      %%ebp, 0x1c(%%ebx); \
    1.43 -                 movl 0x14(%%ebx),     %%eax;  \
    1.44 -                 movl 0x0c(%%ebx),     %%esp;  \
    1.45 -                 movl 0x10(%%ebx),     %%ebp;  \
    1.46 -                 jmp                  *%%eax"  \
    1.47 -   /* outputs */ :                             \
    1.48 -   /* inputs  */ : "g"(currPr)                 \
    1.49 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
    1.50 -                );
    1.51 +
    1.52 +   
    1.53 +   SwitchToVP( currPr )
    1.54 +
    1.55  
    1.56  
    1.57     //=========== jmp to here when want to shut down the VMS system ==========
     2.1 --- a/SwitchAnimators.h	Sun Nov 14 11:17:52 2010 -0800
     2.2 +++ b/SwitchAnimators.h	Mon Nov 15 12:11:24 2010 -0800
     2.3 @@ -185,9 +185,33 @@
     2.4  
     2.5  
     2.6        //switch to virt procr's stack and frame ptr then jump to virt procr fn
     2.7 +/* VirtProcr  offsets:
     2.8 + * 0xc  stackPtr
     2.9 + * 0x10 framePtr
    2.10 + * 0x14 nextInstrPt
    2.11 + * 0x1c coreLoopFramePtr
    2.12 + * 0x20 coreLoopStackPtr
    2.13 + *
    2.14 + * _VMSMasterEnv  offsets:
    2.15 + * 0x24 coreLoopStartPt
    2.16 + * 0x28 coreLoopEndPt
    2.17 + * 0x30 masterLock
    2.18 + */
    2.19  
    2.20  #define SwitchToVP( currPr ) \
    2.21 -   void *stackPtr, *framePtr, *jmpPt; \
    2.22 +   asm volatile("movl         %0,      %%ebx;  \
    2.23 +                 movl      %%esp, 0x20(%%ebx); \
    2.24 +                 movl      %%ebp, 0x1c(%%ebx); \
    2.25 +                 movl 0x14(%%ebx),     %%eax;  \
    2.26 +                 movl 0x0c(%%ebx),     %%esp;  \
    2.27 +                 movl 0x10(%%ebx),     %%ebp;  \
    2.28 +                 jmp                  *%%eax"  \
    2.29 +   /* outputs */ :                             \
    2.30 +   /* inputs  */ : "g"(currPr)                 \
    2.31 +   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
    2.32 +                );
    2.33 +
    2.34 +//   void *stackPtr, *framePtr, *jmpPt; \
    2.35  \
    2.36     stackPtr = currPr->stackPtr; \
    2.37     framePtr = currPr->framePtr; \
     3.1 --- a/VMS.c	Sun Nov 14 11:17:52 2010 -0800
     3.2 +++ b/VMS.c	Mon Nov 15 12:11:24 2010 -0800
     3.3 @@ -776,7 +776,7 @@
     3.4     freeHistExt( _VMSMasterEnv->freeTimeHist   );
     3.5     #endif
     3.6     #ifdef MEAS__TIME_MASTER_LOCK
     3.7 -   printHist( _VMSMasterEnv->masterLockLowTimeHist );
     3.8 +//   printHist( _VMSMasterEnv->masterLockLowTimeHist );
     3.9     printHist( _VMSMasterEnv->masterLockHighTimeHist );
    3.10     #endif
    3.11     #ifdef MEAS__TIME_MASTER
     4.1 --- a/VMS.h	Sun Nov 14 11:17:52 2010 -0800
     4.2 +++ b/VMS.h	Mon Nov 15 12:11:24 2010 -0800
     4.3 @@ -37,8 +37,8 @@
     4.4  
     4.5     //These defines turn types of bug messages on and off
     4.6     // be sure debug messages are un-commented (next block of defines)
     4.7 +#define dbgAppFlow   TRUE /* Top level flow of application code -- general*/
     4.8  #define dbgProbes    FALSE /* for issues inside probes themselves*/
     4.9 -#define dbgAppFlow   FALSE /* Top level flow of application code -- general*/
    4.10  #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
    4.11  #define dbgRqstHdlr  FALSE /* in request handler code*/
    4.12  
    4.13 @@ -63,9 +63,9 @@
    4.14     // rollover of low portion into high portion.
    4.15  //#define MEAS__TIME_STAMP_SUSP
    4.16  //#define MEAS__TIME_MASTER
    4.17 -//#define MEAS__TIME_PLUGIN
    4.18 +#define MEAS__TIME_PLUGIN
    4.19  //#define MEAS__TIME_MALLOC
    4.20 -#define MEAS__TIME_MASTER_LOCK
    4.21 +//#define MEAS__TIME_MASTER_LOCK
    4.22  #define MEAS__NUM_TIMES_TO_RUN 100000
    4.23  
    4.24     //For code that calculates normalization-offset between TSC counts of
     5.1 --- a/vmalloc.c	Sun Nov 14 11:17:52 2010 -0800
     5.2 +++ b/vmalloc.c	Mon Nov 15 12:11:24 2010 -0800
     5.3 @@ -11,6 +11,8 @@
     5.4  #include <stdlib.h>
     5.5  
     5.6  #include "VMS.h"
     5.7 +#include "DynArray/DynArray.h"
     5.8 +#include "Queue_impl/PrivateQueue.h"
     5.9  
    5.10  /*Helper function
    5.11   *Insert a newly generated free chunk into the first spot on the free list.
    5.12 @@ -352,3 +354,72 @@
    5.13     // array when all the free lists linked from it have already been freed
    5.14   }
    5.15  
    5.16 +
    5.17 +
    5.18 +void
    5.19 +add_array_to_recycle_pool( VMSRecyclePool *pool )
    5.20 + { void  *newArray;
    5.21 +   int32  idxToNewArray;
    5.22 + 
    5.23 +   newArray = VMS__malloc( pool->currArraySize );
    5.24 +   idxToNewArray = addToDynArray( newArray, pool->arraysInfo );
    5.25 +   
    5.26 +   pool->ptrToNextStruct = pool->arrays[ idxToNewArray ];
    5.27 +   pool->ptrToTopOfCurrArray = pool->ptrToNextStruct + 
    5.28 +                               pool->currArraySize - 1;
    5.29 +
    5.30 +   pool->currArraySize += pool->currArraySize >> 2; //mult by 1.25
    5.31 +   pool->hasNewStructs = TRUE;
    5.32 + }
    5.33 +
    5.34 +VMSRecyclePool *
    5.35 +VMS__make_recycle_pool( int32 sizeOfStructsToHold )
    5.36 + { VMSRecyclePool *pool;
    5.37 +
    5.38 +   pool = VMS__malloc( sizeof(VMSRecyclePool) );
    5.39 +   pool->recycleQ = makeVMSPrivQ();
    5.40 +   pool->arraysInfo = makePrivDynArrayOfSize( &(pool->arrays), 64 );
    5.41 +   pool->sizeOfStructs = sizeOfStructsToHold;
    5.42 +   pool->currArraySize = 64 * sizeOfStructsToHold; //64 makes aligned as well
    5.43 +   add_array_to_recycle_pool( pool );
    5.44 + }
    5.45 +
    5.46 +void *
    5.47 +VMS__get_from_recycle_pool( VMSRecyclePool *pool )
    5.48 + { void *retStruct;
    5.49 +
    5.50 +   if( pool->hasNewStructs )
    5.51 +    {
    5.52 +      ReStart:
    5.53 +      retStruct = pool->ptrToNextStruct;
    5.54 +      pool->ptrToNextStruct += pool->sizeOfStructs;
    5.55 +      if( pool->ptrToNextStruct < pool->ptrToTopOfCurrArray )
    5.56 +       return retStruct;
    5.57 +      else
    5.58 +       { pool->hasNewStructs = FALSE;
    5.59 +         //fall-through to code after top IF
    5.60 +       }
    5.61 +    }
    5.62 +
    5.63 +   retStruct = readPrivQ( pool->recycleQ );
    5.64 +   if( retStruct != NULL ) return retStruct;
    5.65 +   else
    5.66 +    { add_array_to_recycle_pool( pool );
    5.67 +      goto ReStart;
    5.68 +    }
    5.69 + }
    5.70 +
    5.71 +void
    5.72 +VMS__recycle( void *chunkToRecycle, VMSRecyclePool *pool )
    5.73 + {    //PrivQ self-expands when writing
    5.74 +   writePrivQ( chunkToRecycle, pool->recycleQ );
    5.75 + }
    5.76 +
    5.77 +void
    5.78 +VMS__free_recycle_pool( VMSRecyclePool *pool )
    5.79 + { int32 i;
    5.80 + 
    5.81 +   freeDynArrayDeep( pool->arraysInfo, &VMS__free );
    5.82 +   freePrivQ( pool->recycleQ );
    5.83 +   VMS__free( pool );
    5.84 + }
     6.1 --- a/vmalloc.h	Sun Nov 14 11:17:52 2010 -0800
     6.2 +++ b/vmalloc.h	Mon Nov 15 12:11:24 2010 -0800
     6.3 @@ -31,6 +31,19 @@
     6.4   }
     6.5  FreeListHead;
     6.6  
     6.7 +typedef struct
     6.8 + {
     6.9 +  int32  hasNewStructs;
    6.10 +  int32  sizeOfStructs;
    6.11 +  int32  currArraySize;
    6.12 +  void **arrays;
    6.13 +  PrivDynArrayInfo *arraysInfo;
    6.14 +  char  *ptrToNextStruct;
    6.15 +  char  *ptrToTopOfCurrArray;
    6.16 +  PrivQueueStruc *recycleQ;
    6.17 + }
    6.18 +VMSRecyclePool;
    6.19 +
    6.20  void *
    6.21  VMS__malloc( int32 sizeRequested );
    6.22  
    6.23 @@ -54,4 +67,18 @@
    6.24  void
    6.25  VMS_ext__free_free_list( MallocProlog *freeListHead );
    6.26  
    6.27 +//==========================================================================
    6.28 +
    6.29 +VMSRecyclePool *
    6.30 +VMS__make_recycle_pool( int32 sizeOfStructsToHold );
    6.31 +
    6.32 +void *
    6.33 +VMS__get_from_recycle_pool( VMSRecyclePool *pool );
    6.34 +
    6.35 +void
    6.36 +VMS__recycle( void *chunkToRecycle, VMSRecyclePool *pool );
    6.37 +
    6.38 +void
    6.39 +VMS__free_recycle_pool( VMSRecyclePool *pool );
    6.40 +
    6.41  #endif
    6.42 \ No newline at end of file