changeset 2:02d5a446d506

Compiles with assembly -- warning about jmp w/o '*'?
author Me
date Mon, 31 May 2010 14:23:38 -0700
parents cf5007e51b96
children 2a6fd371c333
files CoreLoop.c
diffstat 1 files changed, 36 insertions(+), 34 deletions(-) [+]
line diff
     1.1 --- a/CoreLoop.c	Mon May 31 14:11:14 2010 -0700
     1.2 +++ b/CoreLoop.c	Mon May 31 14:23:38 2010 -0700
     1.3 @@ -5,9 +5,6 @@
     1.4   */
     1.5  
     1.6  
     1.7 -
     1.8 -
     1.9 -
    1.10  #include "VMS.h"
    1.11  #include "Queue_impl/BlockingQueue.h"
    1.12  
    1.13 @@ -22,41 +19,46 @@
    1.14   * write the slave's "Done" flag and repeat.
    1.15   */
    1.16  //pthread_create requires ptr to func that takes void * and returns void *
    1.17 -void * coreLoop( void *paramsIn )
    1.18 - { time_t startTime, endTime, timeToExecute;
    1.19 -   WorkUnit   *currWorkUnit;
    1.20 -   foobar     *workFn;
    1.21 -   SlaveReqst *requestsFromSlave;
    1.22 -   
    1.23 -   ThdParams  *thdParams;
    1.24 -   QueueStruc *workQ;
    1.25 +void *
    1.26 +coreLoop( void *paramsIn )
    1.27 + {   
    1.28 +   ThdParams   *thdParams;
    1.29 +   VirtProcr   *currPr;
    1.30 +   QueueStruc  *workQ;
    1.31     
    1.32        // Get the communication queues out of the param passed in
    1.33     thdParams = (ThdParams *)paramsIn;
    1.34 +
    1.35 +      //Core loop has no values live upon CoreLoopStartPt except workQ
    1.36 +      // every value in the code is defined by a statement in core loop,
    1.37 +      // after the start point, before being used -- with the one exception
    1.38 +      // of _VMSWorkQ
    1.39 + 
    1.40     
    1.41 -   workQ = thdParams -> workQ;
    1.42 +      // Get to work!  --  virt procr jumps back here when done or suspends
    1.43 +   CoreLoopStartPt:
    1.44     
    1.45 -      // Get to work!
    1.46 -   while( TRUE )
    1.47 -    {    
    1.48 -         // get work-unit struc from queue
    1.49 -      currWorkUnit = (WorkUnit *) readQ( workQ );
    1.50 -      workFn  = currWorkUnit->ptrToWorkFunc;
    1.51 +      //Get virtual processor from queue
    1.52 +      //_VMSWorkQ must be a global, static volatile var, so not kept in reg,
    1.53 +      // which forces reloading the pointer after each jmp to this point
    1.54 +   workQ  = _VMSWorkQ;
    1.55 +   currPr = (VirtProcr *) readQ( workQ );
    1.56 +   currPr->coreLoopStartPt = &&CoreLoopStartPt;  //just to be sure..
    1.57  
    1.58 -            time(&startTime);  //put time at call into var
    1.59 -      
    1.60 -         // call function-ptr, passing it pointer to data
    1.61 -      requestsFromSlave =
    1.62 -      (*workFn)( currWorkUnit->workData );
    1.63 -
    1.64 -            time(&endTime);
    1.65 -            timeToExecute = endTime - startTime;
    1.66 -
    1.67 -            printf( "timeToComputePiece: %s", ctime(&timeToExecute) );
    1.68 -
    1.69 -         // transfer return value to slave's "requests" pointer
    1.70 -      currWorkUnit->slaveAssignedTo->requestsToMaster = requestsFromSlave;
    1.71 -         // write the slave's "Done" flag and repeat.
    1.72 -      currWorkUnit->slaveAssignedTo->doneFlag = TRUE;
    1.73 -    }
    1.74 +      //switch to virt procr's stack and frame ptr then jump to virt procr
    1.75 +   void *stackPtr, *framePtr, *jmpPt;
    1.76 +   
    1.77 +   stackPtr = currPr->stackPtr;
    1.78 +   framePtr = currPr->framePtr;
    1.79 +   jmpPt    = currPr->nextInstrPt;
    1.80 +   
    1.81 +   __asm__ volatile("movl %0, %%esp; movl %1, %%ebp; jmp  %2"
    1.82 +   /* outputs */ :
    1.83 +   /* inputs  */ : "g" (stackPtr), "g" (framePtr), "g" (jmpPt)
    1.84 +   /* clobber */ : "memory" /*just in case, Q: tell about esp, ebp?*/
    1.85 +                );
    1.86   }
    1.87 +   //Note: will only exit this when application dies -- so core loop's stack
    1.88 +   // can be safely ignored -- it's a user-process virtual chunk allocated
    1.89 +   // by PThread lib call that created the thread.. so no cleanup is needed..
    1.90 +   // it's never used anywhere, except upon startup of the thread