changeset 75:f6990e1ba998

new sequential version
author Merten Sach <msach@mailbox.tu-berlin.de>
date Thu, 02 Jun 2011 13:55:51 +0200
parents 77df6692bb29
children 9ddbb071142d
files CoreLoop.c VMS.c contextSwitch.s
diffstat 3 files changed, 34 insertions(+), 32 deletions(-) [+]
line diff
     1.1 --- a/CoreLoop.c	Thu Jun 02 12:45:02 2011 +0200
     1.2 +++ b/CoreLoop.c	Thu Jun 02 13:55:51 2011 +0200
     1.3 @@ -76,7 +76,8 @@
     1.4  
     1.5     
     1.6     //Save the return address in the SwitchVP function
     1.7 -   saveCoreLoopReturnAddr(&(_VMSMasterEnv->coreLoopReturnPt));
     1.8 
     1.9 +   saveCoreLoopReturnAddr(&(_VMSMasterEnv->coreLoopReturnPt));
    1.10 +
    1.11     
    1.12     while(1){
    1.13     
    1.14 @@ -152,6 +153,7 @@
    1.15     }//CoreLoop      
    1.16   }
    1.17  
    1.18 +
    1.19  void *
    1.20  terminateCoreLoop(VirtProcr *currPr){
    1.21     //first free shutdown VP that jumped here -- it first restores the
    1.22 @@ -161,6 +163,7 @@
    1.23  }
    1.24  
    1.25  
    1.26 +
    1.27  #ifdef SEQUENTIAL
    1.28  
    1.29  //===========================================================================
    1.30 @@ -180,24 +183,11 @@
    1.31  //   thisCoresIdx = coreLoopThdParams->coreNum;
    1.32     thisCoresIdx = 0;
    1.33  
    1.34 +   //Save the return address in the SwitchVP function
    1.35 +   saveCoreLoopReturnAddr(&(_VMSMasterEnv->coreLoopReturnPt));
    1.36  
    1.37 -      //Save addr of "end core loop" label - jump to it to shut down coreloop
    1.38 -      //To get label addr in non-gcc compiler, can trick it by making a call
    1.39 -      // to a fn that does asm that pulls the "return"
    1.40 -      // addr off the stack and stores it in a pointed-to location.
    1.41 -   _VMSMasterEnv->coreLoopStartPt = &&SeqCoreLoopStartPt;
    1.42 -   _VMSMasterEnv->coreLoopEndPt   = &&SeqCoreLoopEndPt;
    1.43 -
    1.44 -      //Core loop has no values live upon CoreLoopStartPt except readyToAnimateQ
    1.45 -      // every value in the code is defined by a statement in core loop,
    1.46 -      // after the start point -- with the one exception of _VMSWorkQ
    1.47 -
    1.48 -
    1.49 -      // Get to work!  --  virt procr jumps back here when done or suspends
    1.50 -      //Note, have to restore the frame-pointer before jump to here, to get
    1.51 -      // this code to work right (readyToAnimateQ and so forth are frame-ptr relative)
    1.52 -SeqCoreLoopStartPt:
    1.53 -
    1.54 +   
    1.55 +   while(1){
    1.56        //Get virtual processor from queue
    1.57        //_VMSWorkQ must be a global, static volatile var, so not kept in reg,
    1.58        // which forces reloading the pointer after each jmp to this point
    1.59 @@ -214,18 +204,8 @@
    1.60        _VMSMasterEnv->numMasterInARow[thisCoresIdx] = 0;
    1.61  
    1.62  
    1.63 -   SwitchToVP( currPr )
    1.64 -
    1.65 -   //========================================================================
    1.66 -      //jmp to here when want to shut down the VMS system.  A shutdown VP is
    1.67 -      // made, one for each core loop -- its function sets the stack back
    1.68 -      // to the core loop's stack then jumps to here.  This causes the thread
    1.69 -      // to exit, and so the entry point function, which has been waiting for
    1.70 -      // all the threads to die will proceed, gather the result, and
    1.71 -      // return to the calling application.
    1.72 -SeqCoreLoopEndPt:
    1.73 -   VMS__dissipate_procr( currPr ); //free shutdown pr, that jmpd here
    1.74 -   return;
    1.75 +   switchToVP( currPr );
    1.76 +   flushRegisters();
    1.77 +   }
    1.78   }
    1.79 -
    1.80  #endif
     2.1 --- a/VMS.c	Thu Jun 02 12:45:02 2011 +0200
     2.2 +++ b/VMS.c	Thu Jun 02 13:55:51 2011 +0200
     2.3 @@ -276,6 +276,7 @@
     2.4           //Instead of un-suspending threads, just call the one and only
     2.5           // core loop (sequential version), in the main thread.
     2.6        coreLoop_Seq( NULL );
     2.7 +      flushRegisters();
     2.8  
     2.9   }
    2.10  #endif
    2.11 @@ -704,7 +705,11 @@
    2.12  void
    2.13  endOSThreadFn( void *initData, VirtProcr *animatingPr )
    2.14   { 
    2.15 +#ifdef SEQUENTIAL
    2.16 +    asmTerminateCoreLoopSeq(animatingPr);
    2.17 +#else
    2.18      asmTerminateCoreLoop(animatingPr);
    2.19 +#endif
    2.20   }
    2.21  
    2.22  
     3.1 --- a/contextSwitch.s	Thu Jun 02 12:45:02 2011 +0200
     3.2 +++ b/contextSwitch.s	Thu Jun 02 13:55:51 2011 +0200
     3.3 @@ -121,5 +121,22 @@
     3.4      movl    0x20(%ecx), %esp         #restore stack pointer
     3.5      movl    0x1c(%ecx), %ebp         #restore frame pointer
     3.6      movl    $terminateCoreLoop, %eax
     3.7 -    jmp     *%eax                    #jmp to CoreLoop 
     3.8 +    jmp     *%eax                    #jmp to CoreLoop
     3.9 +
    3.10 +
    3.11 +/*
    3.12 + * This one for the sequential version is special. It discards the current stack
    3.13 + * and returns directly from the coreLoop after VMS__dissipate_procr was called
    3.14 + */
    3.15 +.globl asmTerminateCoreLoopSeq
    3.16 +asmTerminateCoreLoopSeq:
    3.17 +    movl    0x4(%esp) , %ecx         #get VirtProcr
    3.18 +    movl    0x20(%ecx), %esp         #restore stack pointer
    3.19 +    movl    0x1c(%ecx), %ebp         #restore frame pointer
    3.20 +    sub     $0x4      , %esp
    3.21 +    movl    %ecx      , (%esp)       #put argument on stack
    3.22 +    call    VMS__dissipate_procr
    3.23 +    movl    %ebp      , %esp        #goto the coreLoops stack
    3.24 +    pop     %ebp        #restore the old framepointer
    3.25 +    ret                 #return from core loop
    3.26