VirtualBox

Changeset 23366 in vbox


Ignore:
Timestamp:
Sep 28, 2009 12:31:50 PM (15 years ago)
Author:
vboxsync
Message:

Wait for the target VCPU to finish its world switch.

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

Legend:

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

    r23244 r23366  
    406406
    407407#ifdef VBOX_WITH_STATISTICS
    408     STAM_REG(pVM, &pVM->hwaccm.s.StatTPRPatchSuccess, STAMTYPE_COUNTER,   "/HWACCM/TPR/Patch/Success", STAMUNIT_OCCURENCES, "Number of times an instruction was successfully patched.");
    409     STAM_REG(pVM, &pVM->hwaccm.s.StatTPRPatchFailure, STAMTYPE_COUNTER,   "/HWACCM/TPR/Patch/Failed",  STAMUNIT_OCCURENCES, "Number of unsuccessful patch attempts.");
    410     STAM_REG(pVM, &pVM->hwaccm.s.StatTPRReplaceSuccess, STAMTYPE_COUNTER, "/HWACCM/TPR/Replace/Success", STAMUNIT_OCCURENCES, "Number of times an instruction was successfully patched.");
    411     STAM_REG(pVM, &pVM->hwaccm.s.StatTPRReplaceFailure, STAMTYPE_COUNTER, "/HWACCM/TPR/Replace/Failed",  STAMUNIT_OCCURENCES, "Number of unsuccessful patch attempts.");
     408    STAM_REG(pVM, &pVM->hwaccm.s.StatTPRPatchSuccess,   STAMTYPE_COUNTER, "/HWACCM/TPR/Patch/Success",  STAMUNIT_OCCURENCES,    "Number of times an instruction was successfully patched.");
     409    STAM_REG(pVM, &pVM->hwaccm.s.StatTPRPatchFailure,   STAMTYPE_COUNTER, "/HWACCM/TPR/Patch/Failed",   STAMUNIT_OCCURENCES,    "Number of unsuccessful patch attempts.");
     410    STAM_REG(pVM, &pVM->hwaccm.s.StatTPRReplaceSuccess, STAMTYPE_COUNTER, "/HWACCM/TPR/Replace/Success",STAMUNIT_OCCURENCES,    "Number of times an instruction was successfully patched.");
     411    STAM_REG(pVM, &pVM->hwaccm.s.StatTPRReplaceFailure, STAMTYPE_COUNTER, "/HWACCM/TPR/Replace/Failed", STAMUNIT_OCCURENCES,    "Number of unsuccessful patch attempts.");
    412412
    413413    /*
     
    419419        int    rc;
    420420
     421        rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatSpinPoke, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode entry",
     422                             "/PROF/HWACCM/CPU%d/PokeWait", i);
     423        AssertRC(rc);
     424        rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatSpinPokeFailed, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode entry",
     425                             "/PROF/HWACCM/CPU%d/PokeWaitFailed", i);
     426        AssertRC(rc);
    421427        rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatEntry, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode entry",
    422428                             "/PROF/HWACCM/CPU%d/SwitchToGC", i);
  • trunk/src/VBox/VMM/HWACCMInternal.h

    r22429 r23366  
    548548    bool                        fActive;
    549549
     550    /** Set when the TLB has been checked until we return from the world switch. */
     551    volatile uint8_t            fCheckedTLBFlush;
     552    uint8_t                     bAlignment[3];
     553
    550554    /** HWACCM_CHANGED_* flags. */
    551555    RTUINT                      fContextUseFlags;
    552556
    553     /* Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
     557    /** Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
    554558    RTCPUID                     idLastCpu;
    555559
    556     /* TLB flush count */
     560    /** TLB flush count */
    557561    RTUINT                      cTLBFlushes;
    558562
    559     /* Current ASID in use by the VM */
     563    /** Current ASID in use by the VM */
    560564    RTUINT                      uCurrentASID;
     565
     566    /** World switch exit counter. */
     567    volatile uint32_t           cWorldSwitchExit;
    561568
    562569    struct
     
    758765    STAMPROFILEADV          StatWorldSwitch3264;
    759766#endif
     767    STAMPROFILEADV          StatSpinPoke;
     768    STAMPROFILEADV          StatSpinPokeFailed;
    760769
    761770    STAMCOUNTER             StatIntInject;
  • trunk/src/VBox/VMM/VMMAll/HWACCMAll.cpp

    r23201 r23366  
    5959    VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
    6060#else
     61    Be very careful when activating this code!
    6162    if (iPage == RT_ELEMENTS(pVCpu->hwaccm.s.TlbShootdown.aPages))
    6263        VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
     
    118119 *
    119120 */
    120 void hwaccmMpPokeCpu(RTCPUID idHostCpu)
    121 {
     121void hwaccmMpPokeCpu(PVMCPU pVCpu, RTCPUID idHostCpu)
     122{
     123    uint32_t cWorldSwitchExit = pVCpu->hwaccm.s.cWorldSwitchExit;
     124
    122125    int rc = RTMpPokeCpu(idHostCpu);
    123 # ifndef RT_OS_WINDOWS
    124126    /* Not implemented on some platforms (Darwin, Linux kernel < 2.6.19); fall back to a less efficient implementation (broadcast). */
    125127    if (rc == VERR_NOT_SUPPORTED)
     128    {
     129        /* synchronous. */
    126130        RTMpOnSpecific(idHostCpu, hwaccmFlushHandler, 0, 0);
    127 # endif
     131    }
     132    else
     133    {
     134        if (rc == VINF_SUCCESS)
     135            STAM_PROFILE_ADV_START(&pVCpu->hwaccm.s.StatSpinPoke, z);
     136        else
     137            STAM_PROFILE_ADV_START(&pVCpu->hwaccm.s.StatSpinPokeFailed, z);
     138           
     139        /* Spin until the VCPU has switched back. */
     140        while (     VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC
     141               &&   pVCpu->hwaccm.s.fCheckedTLBFlush
     142               &&   cWorldSwitchExit == pVCpu->hwaccm.s.cWorldSwitchExit)
     143        {
     144            ASMNopPause();
     145        }
     146        if (rc == VINF_SUCCESS)
     147            STAM_PROFILE_ADV_STOP(&pVCpu->hwaccm.s.StatSpinPoke, z);
     148        else
     149            STAM_PROFILE_ADV_STOP(&pVCpu->hwaccm.s.StatSpinPokeFailed, z);
     150    }
    128151}
    129152#endif
     
    152175        {
    153176            hwaccmQueueInvlPage(pVCpu, GCPtr);
    154             if (VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC)
     177            if (    VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC
     178                &&  pVCpu->hwaccm.s.fCheckedTLBFlush)
    155179            {
    156180                STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTlbShootdown);
     
    158182                RTCPUID idHostCpu = pVCpu->hwaccm.s.idEnteredCpu;
    159183                if (idHostCpu != NIL_RTCPUID)
    160                     hwaccmMpPokeCpu(idHostCpu);
     184                    hwaccmMpPokeCpu(pVCpu, idHostCpu);
    161185#else
    162186                VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_POKE);
     
    197221            continue;
    198222
    199         if (VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC)
     223        if (    VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC
     224            &&  pVCpu->hwaccm.s.fCheckedTLBFlush)
    200225        {
    201226            STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTlbShootdownFlush);
     
    203228            RTCPUID idHostCpu = pVCpu->hwaccm.s.idEnteredCpu;
    204229            if (idHostCpu != NIL_RTCPUID)
    205                 hwaccmMpPokeCpu(idHostCpu);
     230                hwaccmMpPokeCpu(pVCpu, idHostCpu);
    206231#else
    207232            VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_POKE);
     
    272297
    273298            VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
    274             if (VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC)
     299            if (    VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC
     300                &&  pVCpu->hwaccm.s.fCheckedTLBFlush)
    275301            {
    276302                STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTlbShootdownFlush);
     
    278304                RTCPUID idHostCpu = pVCpu->hwaccm.s.idEnteredCpu;
    279305                if (idHostCpu != NIL_RTCPUID)
    280                     hwaccmMpPokeCpu(idHostCpu);
     306                    hwaccmMpPokeCpu(pVCpu, idHostCpu);
    281307# else
    282308                VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_POKE);
  • trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp

    r23220 r23366  
    11861186    pVCpu->hwaccm.s.idLastCpu = pCpu->idCpu;
    11871187
     1188    /** Set TLB flush state as checked until we return from the world switch. */
     1189    ASMAtomicWriteU8(&pVCpu->hwaccm.s.fCheckedTLBFlush, true);
     1190
    11881191    /* Check for tlb shootdown flushes. */
    11891192    if (VMCPU_FF_TESTANDCLEAR(pVCpu, VMCPU_FF_TLB_FLUSH))
     
    12621265    pVCpu->hwaccm.s.svm.pfnVMRun(pVCpu->hwaccm.s.svm.pVMCBHostPhys, pVCpu->hwaccm.s.svm.pVMCBPhys, pCtx, pVM, pVCpu);
    12631266#endif
     1267    ASMAtomicWriteU8(&pVCpu->hwaccm.s.fCheckedTLBFlush, false);
     1268    ASMAtomicIncU32(&pVCpu->hwaccm.s.cWorldSwitchExit);
    12641269    /* Possibly the last TSC value seen by the guest (too high) (only when we're in tsc offset mode). */
    12651270    if (!(pVMCB->ctrl.u32InterceptCtrl1 & SVM_CTRL1_INTERCEPT_RDTSC))
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r23220 r23366  
    25512551#endif
    25522552
    2553     /* Deal with tagged TLB setup and invalidation. */
    2554     pVM->hwaccm.s.vmx.pfnSetupTaggedTLB(pVM, pVCpu);
    2555 
    25562553    /* Non-register state Guest Context */
    25572554    /** @todo change me according to cpu state */
    25582555    rc = VMXWriteVMCS(VMX_VMCS32_GUEST_ACTIVITY_STATE,           VMX_CMS_GUEST_ACTIVITY_ACTIVE);
    25592556    AssertRC(rc);
     2557
     2558    /** Set TLB flush state as checked until we return from the world switch. */
     2559    ASMAtomicWriteU8(&pVCpu->hwaccm.s.fCheckedTLBFlush, true);
     2560    /* Deal with tagged TLB setup and invalidation. */
     2561    pVM->hwaccm.s.vmx.pfnSetupTaggedTLB(pVM, pVCpu);
    25602562
    25612563    STAM_STATS({ STAM_PROFILE_ADV_STOP(&pVCpu->hwaccm.s.StatEntry, x); fStatEntryStarted = false; });
     
    25732575     */
    25742576
    2575 
    25762577    /* All done! Let's start VM execution. */
    25772578    STAM_PROFILE_ADV_START(&pVCpu->hwaccm.s.StatInGC, z);
     
    25892590    rc = pVCpu->hwaccm.s.vmx.pfnStartVM(pVCpu->hwaccm.s.fResumeVM, pCtx, &pVCpu->hwaccm.s.vmx.VMCSCache, pVM, pVCpu);
    25902591#endif
     2592    ASMAtomicWriteU8(&pVCpu->hwaccm.s.fCheckedTLBFlush, false);
     2593    ASMAtomicIncU32(&pVCpu->hwaccm.s.cWorldSwitchExit);
    25912594    /* Possibly the last TSC value seen by the guest (too high) (only when we're in tsc offset mode). */
    25922595    if (!(pVCpu->hwaccm.s.vmx.proc_ctls & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT))
  • trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp

    r23056 r23366  
    365365    CHECK_MEMBER_ALIGNMENT(HWACCM, StatTPRPatchSuccess, 8);
    366366    CHECK_MEMBER_ALIGNMENT(HWACCMCPU, StatEntry, 8);
     367    CHECK_MEMBER_ALIGNMENT(HWACCMCPU, vmx.pVMCSPhys, sizeof(RTHCPHYS));
    367368    CHECK_MEMBER_ALIGNMENT(HWACCMCPU, vmx.proc_ctls, 8);
    368369    CHECK_MEMBER_ALIGNMENT(HWACCMCPU, Event.intInfo, 8);
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