diff MasterLoop.c @ 70:f9b60012fd74

working ucontext version
author Merten Sach <msach@mailbox.tu-berlin.de>
date Fri, 27 May 2011 12:35:40 +0200
parents 11bfe9d136ed
children efb55f1b5fb9
line diff
     1.1 --- a/MasterLoop.c	Wed May 11 16:13:24 2011 +0200
     1.2 +++ b/MasterLoop.c	Fri May 27 12:35:40 2011 +0200
     1.3 @@ -20,7 +20,6 @@
     1.4  //===========================================================================
     1.5  
     1.6  
     1.7 -
     1.8  /*This code is animated by the virtual Master processor.
     1.9   *
    1.10   *Polls each sched slot exactly once, hands any requests made by a newly
    1.11 @@ -84,16 +83,12 @@
    1.12  
    1.13     int32           thisCoresIdx;
    1.14     VirtProcr      *masterPr;
    1.15 -   volatile        VirtProcr *volatileMasterPr;
    1.16 -   
    1.17 -   volatileMasterPr = animatingPr;
    1.18 -   masterPr         = (VirtProcr*)volatileMasterPr; //used to force re-define after jmp
    1.19  
    1.20        //First animation of each MasterVP will in turn animate this part
    1.21        // of setup code.. (VP creator sets up the stack as if this function
    1.22        // was called normally, but actually get here by jmp)
    1.23        //So, setup values about stack ptr, jmp pt and all that
    1.24 -   masterPr->nextInstrPt = &&masterLoopStartPt;
    1.25 +   masterPr         = animatingPr;  //just to make sure after jmp
    1.26  
    1.27  
    1.28        //Note, got rid of writing the stack and frame ptr up here, because
    1.29 @@ -102,9 +97,21 @@
    1.30        // new frame and stack ptr to the MasterVP storage before a second
    1.31        // version of that MasterVP can get animated on a different core.
    1.32        //Also got rid of the busy-wait.
    1.33 +   
    1.34 +   masterEnv        = (MasterEnv*)_VMSMasterEnv;
    1.35 +   
    1.36 +   thisCoresIdx     = masterPr->coreAnimatedBy;
    1.37 +   readyToAnimateQ  = masterEnv->readyToAnimateQs[thisCoresIdx];
    1.38 +   schedSlots       = masterEnv->allSchedSlots[thisCoresIdx];
    1.39 +
    1.40 +   requestHandler   = masterEnv->requestHandler;
    1.41 +   slaveScheduler   = masterEnv->slaveScheduler;
    1.42 +   semanticEnv      = masterEnv->semanticEnv;
    1.43 +
    1.44  
    1.45     
    1.46 -   masterLoopStartPt:
    1.47 +   while(1){
    1.48 +   
    1.49     //============================= MEASUREMENT STUFF ========================
    1.50     #ifdef MEAS__TIME_MASTER
    1.51        //Total Master time includes one coreloop time -- just assume the core
    1.52 @@ -114,20 +121,7 @@
    1.53     #endif
    1.54     //========================================================================
    1.55  
    1.56 -   masterEnv        = (MasterEnv*)_VMSMasterEnv;
    1.57 -   
    1.58 -      //GCC may optimize so doesn't always re-define from frame-storage
    1.59 -   masterPr         = (VirtProcr*)volatileMasterPr;  //just to make sure after jmp
    1.60 -   thisCoresIdx     = masterPr->coreAnimatedBy;
    1.61 -   readyToAnimateQ  = masterEnv->readyToAnimateQs[thisCoresIdx];
    1.62 -   schedSlots       = masterEnv->allSchedSlots[thisCoresIdx];
    1.63 -
    1.64 -   requestHandler   = masterEnv->requestHandler;
    1.65 -   slaveScheduler   = masterEnv->slaveScheduler;
    1.66 -   semanticEnv      = masterEnv->semanticEnv;
    1.67 -
    1.68 -
    1.69 -      //Poll each slot's Done flag
    1.70 +   //Poll each slot's Done flag
    1.71     numSlotsFilled = 0;
    1.72     for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++)
    1.73      {
    1.74 @@ -185,39 +179,16 @@
    1.75     saveLowTimeStampCountInto( masterPr->endMasterTSCLow );
    1.76     #endif
    1.77  
    1.78 -
    1.79 -
    1.80 -/* VirtProcr  offsets:
    1.81 - * 0xc  stackPtr
    1.82 - * 0x10 framePtr
    1.83 - * 0x14 nextInstrPt
    1.84 - * 0x1c coreLoopFramePtr
    1.85 - * 0x20 coreLoopStackPtr
    1.86 - *
    1.87 - * _VMSMasterEnv  offsets:
    1.88 - * 0x24 coreLoopStartPt
    1.89 - * 0x28 coreLoopEndPt
    1.90 - * 0x30 masterLock
    1.91 - */
    1.92 -//   masterSwitchToCoreLoop( masterPr )
    1.93 -   asm volatile("movl         %0,       %%ebx;  \
    1.94 -                 movl         %1,       %%ecx;  \
    1.95 -                 movl      %%esp,  0x0c(%%ecx); \
    1.96 -                 movl      %%ebp,  0x10(%%ecx); \
    1.97 -                 movl 0x24(%%ebx),      %%eax;  \
    1.98 -                 movl 0x20(%%ecx),      %%esp;  \
    1.99 -                 movl 0x1c(%%ecx),      %%ebp;  \
   1.100 -                 movl $0x0,        0x30(%%ebx); \
   1.101 -                 jmp                    %%eax"  \
   1.102 -   /* outputs */ :                              \
   1.103 -   /* inputs  */ : "g"(_VMSMasterEnv), "g"(masterPr)                        \
   1.104 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   1.105 -                );
   1.106 +   //Clear lock
   1.107 +   _VMSMasterEnv->masterLock = 0;
   1.108 +   
   1.109 +   //Swap to coreLoop
   1.110 +   swapcontext(masterPr->savedVPStatus,masterPr->savedCoreLoopStatus);
   1.111 +   }
   1.112  
   1.113   }
   1.114  
   1.115  
   1.116 -
   1.117  /*This has a race condition -- the coreloops are accessing their own queues
   1.118   * at the same time that this work-stealer on a different core is trying to
   1.119   */