VirtualBox

Changeset 19435 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
May 6, 2009 2:01:15 PM (16 years ago)
Author:
vboxsync
Message:

VMM: VMCPU::enmState.

Location:
trunk/src/VBox/VMM
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VM.cpp

    r19428 r19435  
    672672    return rc;
    673673}
     674
    674675
    675676/**
     
    10951096    LogFlow(("vmR3PowerOn: pVM=%p\n", pVM));
    10961097
     1098    /*
     1099     * EMT(0) does the actual power on work *before* the other EMTs
     1100     * get here, they just need to set their state to STARTED so they
     1101     * get out of the EMT loop and into EM.
     1102     */
    10971103    PVMCPU pVCpu = VMMGetCpu(pVM);
    1098     /* Only VCPU 0 does the actual work. */
     1104    VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
    10991105    if (pVCpu->idCpu != 0)
    11001106        return VINF_SUCCESS;
     
    11991205
    12001206    PVMCPU pVCpu = VMMGetCpu(pVM);
    1201     /* Only VCPU 0 does the actual work. */
     1207    /* Only VCPU 0 does the actual work (*after* all the other CPUs has been here). */
    12021208    if (pVCpu->idCpu != 0)
    12031209        return VINF_EM_SUSPEND;
     
    12761282
    12771283    PVMCPU pVCpu = VMMGetCpu(pVM);
    1278     /* Only VCPU 0 does the actual work. */
     1284    /* Only VCPU 0 does the actual work (*before* the others wake up). */
    12791285    if (pVCpu->idCpu != 0)
    12801286        return VINF_EM_RESUME;
     
    13761382     * Change the state and perform the save.
    13771383     */
    1378     /** @todo implement progress support in SSM */
    13791384    vmR3SetState(pVM, VMSTATE_SAVING);
    13801385    int rc = SSMR3Save(pVM, pszFilename, SSMAFTER_CONTINUE, pfnProgress,  pvUser);
     
    15501555    }
    15511556
     1557    /*
     1558     * EMT(0) does the actual power off work here *after* all the other EMTs
     1559     * have been thru and entered the STOPPED state.
     1560     */
    15521561    PVMCPU pVCpu = VMMGetCpu(pVM);
    1553     /* Only VCPU 0 does the actual work. */
     1562    VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STOPPED);
    15541563    if (pVCpu->idCpu != 0)
    15551564        return VINF_EM_OFF;
     
    21542163    PVMREQ pReq = NULL;
    21552164    rc = VMR3ReqCall(pVM, VMCPUID_ALL_REVERSE, &pReq, RT_INDEFINITE_WAIT, (PFNRT)vmR3Reset, 1, pVM);
    2156     /** @note Can this really happen?? */
    2157     while (rc == VERR_TIMEOUT)
    2158         rc = VMR3ReqWait(pReq, RT_INDEFINITE_WAIT);
    2159 
    21602165    if (RT_SUCCESS(rc))
    21612166        rc = pReq->iStatus;
     
    21832188 * Reset request processor.
    21842189 *
    2185  * This is called by the emulation thread as a response to the
     2190 * This is called by the emulation threads as a response to the
    21862191 * reset request issued by VMR3Reset().
    21872192 *
     
    21932198    PVMCPU pVCpu = VMMGetCpu(pVM);
    21942199
    2195     /* Only VCPU 0 does the full cleanup. */
     2200    /*
     2201     * EMT(0) does the full cleanup *after* all the other EMTs has been
     2202     * thru here and been told to enter the EMSTATE_WAIT_SIPI state.
     2203     */
     2204    VMCPU_ASSERT_STATE(pVCpu, VMCPUSTATE_STARTED);
    21962205    if (pVCpu->idCpu != 0)
    21972206        return VINF_EM_RESET;
  • trunk/src/VBox/VMM/VMEmt.cpp

    r19423 r19435  
    8888     */
    8989    rc = VINF_SUCCESS;
    90     volatile VMSTATE enmBefore = VMSTATE_CREATING; /* volatile because of setjmp */
    9190    Log(("vmR3EmulationThread: Emulation thread starting the days work... Thread=%#x pUVM=%p\n", ThreadSelf, pUVM));
     91    VMSTATE enmBefore = VMSTATE_CREATED; /* (only used for logging atm.) */
    9292    for (;;)
    9393    {
    94         /* Requested to exit the EMT thread out of sync? (currently only VMR3WaitForResume) */
    95         if (setjmp(pUVCpu->vm.s.emtJumpEnv) != 0)
    96         {
    97             rc = VINF_SUCCESS;
    98             break;
    99         }
    100 
    10194        /*
    10295         * During early init there is no pVM, so make a special path
     
    148141        else
    149142        {
    150 
    151143            /*
    152144             * Pending requests which needs servicing?
     
    216208
    217209        /*
    218          * Some requests (both VMR3Req* and the DBGF) can potentially
    219          * resume or start the VM, in that case we'll get a change in
    220          * VM status indicating that we're now running.
     210         * Some requests (both VMR3Req* and the DBGF) can potentially resume
     211         * or start the VM, in that case we'll get a change in VM status
     212         * indicating that we're now running.
    221213         */
    222214        if (    RT_SUCCESS(rc)
    223             &&  pUVM->pVM
    224             &&  enmBefore != pUVM->pVM->enmVMState
    225             &&  pUVM->pVM->enmVMState == VMSTATE_RUNNING)
    226         {
    227             PVM    pVM   = pUVM->pVM;
     215            &&  pUVM->pVM)
     216        {
     217            PVM     pVM  = pUVM->pVM;
    228218            PVMCPU pVCpu = &pVM->aCpus[idCpu];
    229 
    230             rc = EMR3ExecuteVM(pVM, pVCpu);
    231             Log(("vmR3EmulationThread: EMR3ExecuteVM() -> rc=%Rrc, enmVMState=%d\n", rc, pVM->enmVMState));
    232             if (   EMGetState(pVCpu) == EMSTATE_GURU_MEDITATION
    233                 && pVM->enmVMState == VMSTATE_RUNNING)
    234                 vmR3SetState(pVM, VMSTATE_GURU_MEDITATION);
     219            if (    pVM->enmVMState == VMSTATE_RUNNING
     220                &&  VMCPUSTATE_IS_STARTED(VMCPU_GET_STATE(pVCpu)))
     221            {
     222                rc = EMR3ExecuteVM(pVM, pVCpu);
     223                Log(("vmR3EmulationThread: EMR3ExecuteVM() -> rc=%Rrc, enmVMState=%d\n", rc, pVM->enmVMState));
     224                if (   EMGetState(pVCpu) == EMSTATE_GURU_MEDITATION
     225                    && pVM->enmVMState == VMSTATE_RUNNING)
     226                    vmR3SetState(pVM, VMSTATE_GURU_MEDITATION);
     227            }
    235228        }
    236229
     
    260253}
    261254
    262 
    263 #if 0 /* not used */
    264 /**
    265  * Wait for VM to be resumed. Handle events like vmR3EmulationThread does.
    266  * In case the VM is stopped, clean up and long jump to the main EMT loop.
    267  *
    268  * @returns VINF_SUCCESS or doesn't return
    269  * @param   pVM             VM handle.
    270  */
    271 VMMR3DECL(int) VMR3WaitForResume(PVM pVM)
    272 {
    273     /*
    274      * The request loop.
    275      */
    276     PUVMCPU pUVCpu;
    277     PUVM    pUVM = pVM->pUVM;
    278     VMSTATE enmBefore;
    279     int     rc;
    280 
    281     pUVCpu = (PUVMCPU)RTTlsGet(pUVM->vm.s.idxTLS);
    282     AssertReturn(pUVCpu, VERR_INTERNAL_ERROR);
    283 
    284     for (;;)
    285     {
    286 
    287         /*
    288          * Pending requests which needs servicing?
    289          *
    290          * We check for state changes in addition to status codes when
    291          * servicing requests. (Look after the ifs.)
    292          */
    293         enmBefore = pVM->enmVMState;
    294         if (    VM_FF_ISSET(pVM, VM_FF_TERMINATE)
    295             ||  pUVM->vm.s.fTerminateEMT)
    296         {
    297             rc = VINF_EM_TERMINATE;
    298             break;
    299         }
    300         else if (pUVM->vm.s.pReqs)
    301         {
    302             /*
    303              * Service execute in EMT request.
    304              */
    305             rc = VMR3ReqProcessU(pUVM, VMCPUID_ANY);
    306             Log(("vmR3EmulationThread: Req rc=%Rrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
    307         }
    308         else if (pUVCpu->vm.s.pReqs)
    309         {
    310             /*
    311              * Service execute in EMT request.
    312              */
    313             rc = VMR3ReqProcessU(pUVM, pUVCpu->idCpu);
    314             Log(("vmR3EmulationThread: Req (cpu=%u) rc=%Rrc, VM state %d -> %d\n", pUVCpu->idCpu, rc, enmBefore, pVM->enmVMState));
    315         }
    316         else if (VM_FF_ISSET(pVM, VM_FF_DBGF))
    317         {
    318             /*
    319              * Service the debugger request.
    320              */
    321             rc = DBGFR3VMMForcedAction(pVM);
    322             Log(("vmR3EmulationThread: Dbg rc=%Rrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
    323         }
    324         else if (VM_FF_TESTANDCLEAR(pVM, VM_FF_RESET_BIT))
    325         {
    326             /*
    327              * Service a delay reset request.
    328              */
    329             rc = VMR3Reset(pVM);
    330             VM_FF_CLEAR(pVM, VM_FF_RESET);
    331             Log(("vmR3EmulationThread: Reset rc=%Rrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
    332         }
    333         else
    334         {
    335             /*
    336              * Nothing important is pending, so wait for something.
    337              */
    338             rc = VMR3WaitU(pUVCpu);
    339             if (RT_FAILURE(rc))
    340                 break;
    341         }
    342 
    343         /*
    344          * Check for termination requests, these are extremely high priority.
    345          */
    346         if (    rc == VINF_EM_TERMINATE
    347             ||  VM_FF_ISSET(pVM, VM_FF_TERMINATE)
    348             ||  pUVM->vm.s.fTerminateEMT)
    349             break;
    350 
    351         /*
    352          * Some requests (both VMR3Req* and the DBGF) can potentially
    353          * resume or start the VM, in that case we'll get a change in
    354          * VM status indicating that we're now running.
    355          */
    356         if (    RT_SUCCESS(rc)
    357             &&  enmBefore != pVM->enmVMState
    358             &&  pVM->enmVMState == VMSTATE_RUNNING)
    359         {
    360             /* Only valid exit reason. */
    361             return VINF_SUCCESS;
    362         }
    363 
    364     } /* forever */
    365 
    366     /* Return to the main loop in vmR3EmulationThread, which will clean up for us. */
    367     longjmp(pUVCpu->vm.s.emtJumpEnv, 1);
    368 }
    369 #endif
    370255
    371256/**
     
    848733    }
    849734    else if (   (fFlags & VMNOTIFYFF_FLAGS_POKE)
    850              && pUVCpu->pUVM->pVM
    851              && pUVCpu->pUVM->pVM->aCpus[pUVCpu->idCpu].enmState == VMCPUSTATE_RUN_EXEC) /** @todo make this easier to access. (pUVCpu->pVCpu) */
     735             && pUVCpu->pVCpu
     736             && pUVCpu->pVCpu->enmState == VMCPUSTATE_STARTED_EXEC)
    852737    {
    853738        int rc = SUPCallVMMR0Ex(pUVCpu->pVM->pVMR0, pUVCpu->idCpu, VMMR0_DO_GVMM_SCHED_POKE, 0, NULL);
     
    11251010     * Do the halt.
    11261011     */
     1012    Assert(VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED);
     1013    VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_HALTED);
    11271014    PUVM pUVM = pUVCpu->pUVM;
    11281015    int rc = g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnHalt(pUVCpu, fMask, u64Now);
     1016    VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
    11291017
    11301018    /*
  • trunk/src/VBox/VMM/VMInternal.h

    r19401 r19435  
    449449    STAMPROFILE                     StatHaltPoll;
    450450    /** @} */
    451 
    452     /** vmR3EmulationThread longjmp buffer. Must be last in the structure. */
    453     jmp_buf                         emtJumpEnv;
    454451} VMINTUSERPERVMCPU;
    455452
  • trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp

    r19406 r19435  
    16691669DECLINLINE(int) gvmmR0SchedPokeOne(PGVM pGVM, PVMCPU pVCpu)
    16701670{
    1671     if (pVCpu->enmState != VMCPUSTATE_RUN_EXEC)
     1671    if (pVCpu->enmState != VMCPUSTATE_STARTED_EXEC)
    16721672        return VINF_GVM_NOT_BUSY_IN_GC;
    16731673
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette