VirtualBox

Changeset 100001 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
May 30, 2023 6:11:02 AM (20 months ago)
Author:
vboxsync
Message:

VMM/NEMR3Native-darwin-armv8: Set the vTimer expiration time when halting due to a WFI/WFE instruction and the vTimer is active, reduces host load when the guest idling which would consume a full core before, bugref:10390

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/NEMR3Native-darwin-armv8.cpp

    r99976 r100001  
    5151#include <iprt/asm.h>
    5252#include <iprt/asm-arm.h>
     53#include <iprt/asm-math.h>
    5354#include <iprt/ldr.h>
    5455#include <iprt/mem.h>
     
    10361037            return nemR3DarwinHandleExitExceptionTrappedHvcInsn(pVM, pVCpu, uIss);
    10371038        case ARMV8_ESR_EL2_EC_TRAPPED_WFX:
    1038             return VINF_SUCCESS; /** @todo VINF_EM_HALT; We don't get notified about the vTimer if halting here currently leading to a guest hang...*/
     1039        {
     1040            /* No need to halt if there is an interrupt pending already. */
     1041            if (VMCPU_FF_IS_ANY_SET(pVCpu, (VMCPU_FF_INTERRUPT_IRQ | VMCPU_FF_INTERRUPT_FIQ)))
     1042                return VINF_SUCCESS;
     1043
     1044            /* Set the vTimer expiration in order to get out of the halt at the right point in time. */
     1045            if (   (pVCpu->cpum.GstCtx.CntvCtlEl0 & ARMV8_CNTV_CTL_EL0_AARCH64_ENABLE)
     1046                && !(pVCpu->cpum.GstCtx.CntvCtlEl0 & ARMV8_CNTV_CTL_EL0_AARCH64_IMASK))
     1047            {
     1048                uint64_t cTicksVTimer = ASMReadTSC() - pVCpu->nem.s.u64VTimerOff;
     1049
     1050                /* Check whether it expired and start executing guest code. */
     1051                if (cTicksVTimer >= pVCpu->cpum.GstCtx.CntvCValEl0)
     1052                    return VINF_SUCCESS;
     1053
     1054                uint64_t cTicksVTimerToExpire = pVCpu->cpum.GstCtx.CntvCValEl0 - cTicksVTimer;
     1055                uint64_t cNanoSecsVTimerToExpire = ASMMultU64ByU32DivByU32(cTicksVTimerToExpire, RT_NS_1SEC, (uint32_t)pVM->nem.s.u64CntFrqHz);
     1056
     1057                /* Our halt method doesn't work with sub millisecond granularity at the moment causing a huge slowdown. */
     1058                if (cNanoSecsVTimerToExpire < 20 * RT_NS_1MS)
     1059                    return VINF_SUCCESS;
     1060
     1061                TMCpuSetVTimerNextActivation(pVCpu, cNanoSecsVTimerToExpire);
     1062            }
     1063            else
     1064                TMCpuSetVTimerNextActivation(pVCpu, UINT64_MAX);
     1065
     1066            return VINF_EM_HALT;
     1067        }
    10391068        case ARMV8_ESR_EL2_EC_UNKNOWN:
    10401069        default:
     
    10761105            return nemR3DarwinHandleExitException(pVM, pVCpu, pExit);
    10771106        case HV_EXIT_REASON_VTIMER_ACTIVATED:
     1107        {
     1108            LogFlowFunc(("vTimer got activated\n"));
     1109            TMCpuSetVTimerNextActivation(pVCpu, UINT64_MAX);
    10781110            pVCpu->nem.s.fVTimerActivated = true;
    10791111            return GICPpiSet(pVCpu, NEM_DARWIN_VTIMER_GIC_PPI_IRQ, true /*fAsserted*/);
     1112        }
    10801113        default:
    10811114            AssertReleaseFailed();
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