VirtualBox

Changeset 87292 in vbox for trunk/src


Ignore:
Timestamp:
Jan 16, 2021 12:15:01 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142251
Message:

TMAllCpu: > 4GHz CPU fun. Adjustments for bugref:9898.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/TMAllCpu.cpp

    r82968 r87292  
    2525#include <VBox/vmm/dbgf.h>
    2626#include <VBox/vmm/nem.h>
    27 #include <iprt/asm-amd64-x86.h> /* for SUPGetCpuHzFromGIP */
     27#if   defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     28# include <iprt/asm-amd64-x86.h> /* for SUPGetCpuHzFromGIP; ASMReadTSC */
     29#elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     30# include <iprt/asm-arm.h>
     31#endif
    2832#include "TMInternal.h"
    2933#include <VBox/vmm/vmcc.h>
     
    3741
    3842
     43
     44/**
     45 * Converts from virtual time to raw CPU ticks.
     46 *
     47 * Mainly to have the ASMMultU64ByU32DivByU32 overflow trickery in one place.
     48 *
     49 * @returns raw CPU ticks.
     50 * @param   pVM             The cross context VM structure.
     51 * @param   u64VirtualTime  The virtual time to convert.
     52 */
     53DECLINLINE(uint64_t) tmCpuTickCalcFromVirtual(PVMCC pVM, uint64_t u64VirtualTime)
     54{
     55    if (pVM->tm.s.cTSCTicksPerSecond <= UINT32_MAX)
     56        return ASMMultU64ByU32DivByU32(u64VirtualTime, (uint32_t)pVM->tm.s.cTSCTicksPerSecond, TMCLOCK_FREQ_VIRTUAL);
     57    Assert(pVM->tm.s.cTSCTicksPerSecond <= ((uint64_t)UINT32_MAX << 2)); /* <= 15.99 GHz */
     58    return ASMMultU64ByU32DivByU32(u64VirtualTime, (uint32_t)(pVM->tm.s.cTSCTicksPerSecond >> 2), TMCLOCK_FREQ_VIRTUAL >> 2);
     59}
     60
     61
    3962/**
    4063 * Gets the raw cpu tick from current virtual time.
     
    4568DECLINLINE(uint64_t) tmCpuTickGetRawVirtual(PVMCC pVM, bool fCheckTimers)
    4669{
    47     uint64_t u64;
    4870    if (fCheckTimers)
    49         u64 = TMVirtualSyncGet(pVM);
    50     else
    51         u64 = TMVirtualSyncGetNoCheck(pVM);
    52     return ASMMultU64ByU32DivByU32(u64, pVM->tm.s.cTSCTicksPerSecond, TMCLOCK_FREQ_VIRTUAL);
     71        return tmCpuTickCalcFromVirtual(pVM, TMVirtualSyncGet(pVM));
     72    return tmCpuTickCalcFromVirtual(pVM, TMVirtualSyncGetNoCheck(pVM));
    5373}
    5474
     
    289309         *        exact opposite of what the hardware implements. */
    290310#ifdef IN_RING3
    291         *poffRealTsc = 0 - pVCpu->tm.s.offTSCRawSrc - SUPGetTscDelta();
     311        *poffRealTsc = (uint64_t)0 - pVCpu->tm.s.offTSCRawSrc - (uint64_t)SUPGetTscDelta();
    292312#else
    293         *poffRealTsc = 0 - pVCpu->tm.s.offTSCRawSrc - SUPGetTscDeltaByCpuSetIndex(pVCpu->iHostCpuSet);
     313        *poffRealTsc = (uint64_t)0 - pVCpu->tm.s.offTSCRawSrc - (uint64_t)SUPGetTscDeltaByCpuSetIndex(pVCpu->iHostCpuSet);
    294314#endif
    295315        return true;
     
    353373    if (RT_UNLIKELY(cNsToDeadline >= TMCLOCK_FREQ_VIRTUAL))
    354374        return uCpuHz;
    355     uint64_t cTicks = ASMMultU64ByU32DivByU32(uCpuHz, cNsToDeadline, TMCLOCK_FREQ_VIRTUAL);
     375    AssertCompile(TMCLOCK_FREQ_VIRTUAL <= UINT32_MAX);
     376    uint64_t cTicks = ASMMultU64ByU32DivByU32(uCpuHz, (uint32_t)cNsToDeadline, TMCLOCK_FREQ_VIRTUAL);
    356377    if (cTicks > 4000)
    357378        cTicks -= 4000; /* fudge to account for overhead */
     
    392413         *        exact opposite of what the hardware implements. */
    393414#ifdef IN_RING3
    394         *poffRealTsc     = 0 - pVCpu->tm.s.offTSCRawSrc - SUPGetTscDelta();
     415        *poffRealTsc     = (uint64_t)0 - pVCpu->tm.s.offTSCRawSrc - (uint64_t)SUPGetTscDelta();
    395416#else
    396         *poffRealTsc     = 0 - pVCpu->tm.s.offTSCRawSrc - SUPGetTscDeltaByCpuSetIndex(pVCpu->iHostCpuSet);
     417        *poffRealTsc     = (uint64_t)0 - pVCpu->tm.s.offTSCRawSrc - (uint64_t)SUPGetTscDeltaByCpuSetIndex(pVCpu->iHostCpuSet);
    397418#endif
    398419        *pfOffsettedTsc  = true;
     
    411432        uint64_t cNsToDeadline;
    412433        uint64_t u64NowVirtSync = TMVirtualSyncGetWithDeadlineNoCheck(pVM, &cNsToDeadline);
    413         uint64_t u64Now = ASMMultU64ByU32DivByU32(u64NowVirtSync, pVM->tm.s.cTSCTicksPerSecond, TMCLOCK_FREQ_VIRTUAL);
     434        uint64_t u64Now = tmCpuTickCalcFromVirtual(pVM, u64NowVirtSync);
    414435        u64Now -= pVCpu->tm.s.offTSCRawSrc;
    415436        *poffRealTsc     = u64Now - ASMReadTSC();
     
    582603        uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGip(g_pSUPGlobalInfoPage);
    583604#elif defined(IN_RING0)
    584         uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGipBySetIndex(g_pSUPGlobalInfoPage, RTMpCpuIdToSetIndex(RTMpCpuId()));
     605        uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGipBySetIndex(g_pSUPGlobalInfoPage, (uint32_t)RTMpCpuIdToSetIndex(RTMpCpuId()));
    585606#else
    586607        uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGipBySetIndex(g_pSUPGlobalInfoPage, VMMGetCpu(pVM)->iHostCpuSet);
Note: See TracChangeset for help on using the changeset viewer.

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