diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-04-23 00:01:08 -0400 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-06-07 21:44:42 -0400 |
commit | 8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf (patch) | |
tree | 2bb7be86aafe9986811758b508a7581d2efe8ac4 /src/common/wall_clock.h | |
parent | bbd502f67adb17b00b33f1b7158cfff2b2fa8a3e (diff) |
core_timing: Use CNTPCT as the guest CPU tick
Previously, we were mixing the raw CPU frequency and CNTFRQ.
The raw CPU frequency (1020 MHz) should've never been used as CNTPCT (whose frequency is CNTFRQ) is the only counter available.
Diffstat (limited to 'src/common/wall_clock.h')
-rw-r--r-- | src/common/wall_clock.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h index a73e6e644..56c18ca25 100644 --- a/src/common/wall_clock.h +++ b/src/common/wall_clock.h @@ -38,6 +38,22 @@ public: /// @returns Whether the clock directly uses the host's hardware clock. virtual bool IsNative() const = 0; + static inline u64 NSToCNTPCT(u64 ns) { + return ns * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den; + } + + static inline u64 USToCNTPCT(u64 us) { + return us * UsToCNTPCTRatio::num / UsToCNTPCTRatio::den; + } + + static inline u64 CNTPCTToNS(u64 cntpct) { + return cntpct * NsToCNTPCTRatio::den / NsToCNTPCTRatio::num; + } + + static inline u64 CNTPCTToUS(u64 cntpct) { + return cntpct * UsToCNTPCTRatio::den / UsToCNTPCTRatio::num; + } + protected: using NsRatio = std::nano; using UsRatio = std::micro; @@ -46,6 +62,7 @@ protected: using NsToUsRatio = std::ratio_divide<std::nano, std::micro>; using NsToMsRatio = std::ratio_divide<std::nano, std::milli>; using NsToCNTPCTRatio = std::ratio<CNTFRQ, std::nano::den>; + using UsToCNTPCTRatio = std::ratio<CNTFRQ, std::micro::den>; }; std::unique_ptr<WallClock> CreateOptimalClock(); |