- Timestamp:
- Jan 16, 2021 12:15:01 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 142251
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/TMAllCpu.cpp
r82968 r87292 25 25 #include <VBox/vmm/dbgf.h> 26 26 #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 28 32 #include "TMInternal.h" 29 33 #include <VBox/vmm/vmcc.h> … … 37 41 38 42 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 */ 53 DECLINLINE(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 39 62 /** 40 63 * Gets the raw cpu tick from current virtual time. … … 45 68 DECLINLINE(uint64_t) tmCpuTickGetRawVirtual(PVMCC pVM, bool fCheckTimers) 46 69 { 47 uint64_t u64;48 70 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)); 53 73 } 54 74 … … 289 309 * exact opposite of what the hardware implements. */ 290 310 #ifdef IN_RING3 291 *poffRealTsc = 0 - pVCpu->tm.s.offTSCRawSrc -SUPGetTscDelta();311 *poffRealTsc = (uint64_t)0 - pVCpu->tm.s.offTSCRawSrc - (uint64_t)SUPGetTscDelta(); 292 312 #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); 294 314 #endif 295 315 return true; … … 353 373 if (RT_UNLIKELY(cNsToDeadline >= TMCLOCK_FREQ_VIRTUAL)) 354 374 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); 356 377 if (cTicks > 4000) 357 378 cTicks -= 4000; /* fudge to account for overhead */ … … 392 413 * exact opposite of what the hardware implements. */ 393 414 #ifdef IN_RING3 394 *poffRealTsc = 0 - pVCpu->tm.s.offTSCRawSrc -SUPGetTscDelta();415 *poffRealTsc = (uint64_t)0 - pVCpu->tm.s.offTSCRawSrc - (uint64_t)SUPGetTscDelta(); 395 416 #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); 397 418 #endif 398 419 *pfOffsettedTsc = true; … … 411 432 uint64_t cNsToDeadline; 412 433 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); 414 435 u64Now -= pVCpu->tm.s.offTSCRawSrc; 415 436 *poffRealTsc = u64Now - ASMReadTSC(); … … 582 603 uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGip(g_pSUPGlobalInfoPage); 583 604 #elif defined(IN_RING0) 584 uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGipBySetIndex(g_pSUPGlobalInfoPage, RTMpCpuIdToSetIndex(RTMpCpuId()));605 uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGipBySetIndex(g_pSUPGlobalInfoPage, (uint32_t)RTMpCpuIdToSetIndex(RTMpCpuId())); 585 606 #else 586 607 uint64_t cTSCTicksPerSecond = SUPGetCpuHzFromGipBySetIndex(g_pSUPGlobalInfoPage, VMMGetCpu(pVM)->iHostCpuSet);
Note:
See TracChangeset
for help on using the changeset viewer.