diff VMS.c @ 38:17d20e5cf924

measures coreloop and masterVP times
author Me
date Tue, 07 Sep 2010 18:40:57 -0700
parents e69579a0e797
children 1df8d7f2c9b1
line diff
     1.1 --- a/VMS.c	Wed Sep 01 08:23:39 2010 -0700
     1.2 +++ b/VMS.c	Tue Sep 07 18:40:57 2010 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright 2010  OpenSourceCodeStewardshipFoundation
     1.6 + * Copyright 2010  OpenSourceStewardshipFoundation
     1.7   *
     1.8   * Licensed under BSD
     1.9   */
    1.10 @@ -10,6 +10,7 @@
    1.11  
    1.12  #include "VMS.h"
    1.13  #include "Queue_impl/BlockingQueue.h"
    1.14 +#include "Histogram/Histogram.h"
    1.15  
    1.16  
    1.17  #define thdAttrs NULL
    1.18 @@ -126,6 +127,17 @@
    1.19     // in the master, taking from this massive chunk.
    1.20  
    1.21  //   initFreeList();
    1.22 +
    1.23 +   //============================= MEASUREMENT STUFF ========================
    1.24 +   #ifdef MEAS__TIME_STAMP_SUSP
    1.25 +   _VMSMasterEnv->measSuspHist   = makeHistogram( 25, 110, 135 );
    1.26 +   #endif
    1.27 +
    1.28 +   #ifdef MEAS__TIME_MASTER
    1.29 +   _VMSMasterEnv->measMasterHist = makeHistogram( 25, 500, 800 );
    1.30 +   #endif
    1.31 +   //========================================================================
    1.32 +
    1.33   }
    1.34  
    1.35  /*
    1.36 @@ -293,6 +305,7 @@
    1.37     newPr->nextInstrPt = fnPtr;
    1.38     newPr->initialData = initialData;
    1.39     newPr->requests    = NULL;
    1.40 +   newPr->schedSlot   = NULL;
    1.41  //   newPr->coreLoopStartPt = _VMSMasterEnv->coreLoopStartPt;
    1.42  
    1.43        //fnPtr takes two params -- void *initData & void *animProcr
    1.44 @@ -324,7 +337,7 @@
    1.45   * next work-unit for that procr.
    1.46   */
    1.47  void
    1.48 -VMS__suspend_procr( VirtProcr *callingPr )
    1.49 +VMS__suspend_procr( VirtProcr *animatingPr )
    1.50   { void *jmpPt, *stackPtrAddr, *framePtrAddr, *coreLoopStackPtr;
    1.51     void *coreLoopFramePtr;
    1.52  
    1.53 @@ -332,21 +345,19 @@
    1.54        // scheduled again at some future point -- to resume, core loop jumps
    1.55        // to the resume point (below), which causes restore of saved regs and
    1.56        // "return" from this call.
    1.57 -   callingPr->nextInstrPt = &&ResumePt;
    1.58 +   animatingPr->nextInstrPt = &&ResumePt;
    1.59  
    1.60        //return ownership of the virt procr and sched slot to Master virt pr
    1.61 -   callingPr->schedSlot->workIsDone = TRUE;
    1.62 +   animatingPr->schedSlot->workIsDone = TRUE;
    1.63  //   coreIdx = callingPr->coreAnimatedBy;
    1.64  
    1.65 -   stackPtrAddr      = &(callingPr->stackPtr);
    1.66 -   framePtrAddr      = &(callingPr->framePtr);
    1.67 +   stackPtrAddr      = &(animatingPr->stackPtr);
    1.68 +   framePtrAddr      = &(animatingPr->framePtr);
    1.69  
    1.70     jmpPt             = _VMSMasterEnv->coreLoopStartPt;
    1.71 -   coreLoopFramePtr  = callingPr->coreLoopFramePtr;//need this only
    1.72 -   coreLoopStackPtr  = callingPr->coreLoopStackPtr;//shouldn't need -- safety
    1.73 +   coreLoopFramePtr  = animatingPr->coreLoopFramePtr;//need this only
    1.74 +   coreLoopStackPtr  = animatingPr->coreLoopStackPtr;//safety
    1.75  
    1.76 -      //Eclipse's compilation sequence complains -- so break into two
    1.77 -      // separate in-line assembly pieces
    1.78        //Save the virt procr's stack and frame ptrs,
    1.79     asm volatile("movl %0,     %%eax;  \
    1.80                   movl %%esp, (%%eax); \
    1.81 @@ -357,6 +368,16 @@
    1.82     /* clobber */ : "%eax" \
    1.83                  );
    1.84  
    1.85 +   #ifdef MEAS__TIME_STAMP_SUSP
    1.86 +      //record time stamp into animating procr: compared to time-stamp
    1.87 +      // recorded below, at the resume pt.
    1.88 +      //NOTE: doing minimal work here 'cause only a few instrs executed in
    1.89 +      // core loop, so only using bottom half of time-stamp -- have to
    1.90 +      // externally do sanity check & throw out absurd values due to rollover
    1.91 +
    1.92 +   saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
    1.93 +   #endif
    1.94 +
    1.95        //restore coreloop's frame ptr, then jump back to "start" of core loop
    1.96        //Note, GCC compiles to assembly that saves esp and ebp in the stack
    1.97        // frame -- so have to explicitly do assembly that saves to memory
    1.98 @@ -372,18 +393,23 @@
    1.99                     // assembly, so that stack pointer is correct, before jmp
   1.100  
   1.101  ResumePt:
   1.102 +   #ifdef MEAS__TIME_STAMP_SUSP
   1.103 +   saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
   1.104 +      //Take difference between the pre-suspend and post-suspend times
   1.105 +      // and do sanity check to see if rollover happened between
   1.106 +   int  diff = animatingPr->postSuspTSCLow - animatingPr->preSuspTSCLow;
   1.107 +   if( diff > 1000000 ) diff = 0;
   1.108 +   addToHist( diff, _VMSMasterEnv->measSuspHist );
   1.109 +
   1.110 +   #endif
   1.111 +
   1.112     return;
   1.113   }
   1.114  
   1.115  
   1.116  
   1.117  
   1.118 -/*Not sure yet the form going to put "dissipate" in, so this is the third
   1.119 - * possibility -- the semantic layer can just make a macro that looks like
   1.120 - * a call to its name, then expands to a call to this.
   1.121 - *
   1.122 - *As of June 30, 2010  this looks like the top choice..
   1.123 - *
   1.124 +/*
   1.125   *This adds a request to dissipate, then suspends the processor so that the
   1.126   * request handler will receive the request.  The request handler is what
   1.127   * does the work of freeing memory and removing the processor from the
   1.128 @@ -433,32 +459,8 @@
   1.129   }
   1.130  
   1.131  
   1.132 -
   1.133 -//TODO: add a semantic-layer supplied "freer" for the semantic-data portion
   1.134 -// of a request -- IE call with both a virt procr and a fn-ptr to request
   1.135 -// freer (or maybe put request freer as a field in virt procr?)
   1.136 -void
   1.137 -VMS__remove_and_free_top_request( VirtProcr *procrWithReq )
   1.138 - { VMSReqst *req;
   1.139 -
   1.140 -   req = procrWithReq->requests;
   1.141 -   if( req == NULL ) return;
   1.142 -   procrWithReq->requests = procrWithReq->requests->nextReqst;
   1.143 -   VMS__free_request( req );
   1.144 - }
   1.145 -
   1.146 -
   1.147 -//TODO: add a semantic-layer supplied "freer" for the semantic-data portion
   1.148 -// of a request -- IE call with both a virt procr and a fn-ptr to request
   1.149 -// freer (also maybe put sem request freer as a field in virt procr?)
   1.150 -//SSR relies right now on this only freeing VMS layer of request -- the
   1.151 -// semantic portion of request is alloc'd and freed by request handler
   1.152 -void
   1.153 -VMS__free_request( VMSReqst *req )
   1.154 - { 
   1.155 -   free( req );
   1.156 - }
   1.157 -
   1.158 +/*Use this to get first request before starting request handler's loop
   1.159 + */
   1.160  VMSReqst *
   1.161  VMS__take_top_request_from( VirtProcr *procrWithReq )
   1.162   { VMSReqst *req;
   1.163 @@ -470,18 +472,36 @@
   1.164     return req;
   1.165   }
   1.166  
   1.167 +/*A subtle bug due to freeing then accessing "next" after freed caused this
   1.168 + * form of call to be put in -- so call this at end of request handler loop
   1.169 + * that iterates through the requests.
   1.170 + */
   1.171  VMSReqst *
   1.172  VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq )
   1.173   { VMSReqst *req;
   1.174  
   1.175     req = procrWithReq->requests;
   1.176 -   if( req == NULL ) return req;
   1.177 +   if( req == NULL ) return NULL;
   1.178  
   1.179     procrWithReq->requests = procrWithReq->requests->nextReqst;
   1.180     VMS__free_request( req );
   1.181     return procrWithReq->requests;
   1.182   }
   1.183  
   1.184 +
   1.185 +//TODO: add a semantic-layer supplied "freer" for the semantic-data portion
   1.186 +// of a request -- IE call with both a virt procr and a fn-ptr to request
   1.187 +// freer (also maybe put sem request freer as a field in virt procr?)
   1.188 +//MeasVMS relies right now on this only freeing VMS layer of request -- the
   1.189 +// semantic portion of request is alloc'd and freed by request handler
   1.190 +void
   1.191 +VMS__free_request( VMSReqst *req )
   1.192 + {
   1.193 +   free( req );
   1.194 + }
   1.195 +
   1.196 +
   1.197 +
   1.198  inline int
   1.199  VMS__isSemanticReqst( VMSReqst *req )
   1.200   {
   1.201 @@ -508,7 +528,7 @@
   1.202   }
   1.203  
   1.204  void
   1.205 -VMS__send_register_new_procr_request(VirtProcr *newPr, VirtProcr *reqstingPr)
   1.206 +VMS__send_req_to_register_new_procr(VirtProcr *newPr, VirtProcr *reqstingPr)
   1.207   { VMSReqst *req;
   1.208  
   1.209     req                  = malloc( sizeof(VMSReqst) );
   1.210 @@ -547,7 +567,7 @@
   1.211  //TODO: implement VMS__malloc system, including "give up ownership"
   1.212  
   1.213        //The dissipate request might still be attached, so remove and free it
   1.214 -   VMS__remove_and_free_top_request( animatingPr );
   1.215 +   VMS__free_top_and_give_next_request_from( animatingPr );
   1.216  
   1.217        //NOTE: initialData was given to the processor, so should either have
   1.218        // been alloc'd with VMS__malloc, or freed by the level above animPr.