summaryrefslogtreecommitdiff
path: root/src/common/wall_clock.h
diff options
context:
space:
mode:
authorGravatar Morph2023-04-23 00:01:08 -0400
committerGravatar Morph2023-06-07 21:44:42 -0400
commit8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf (patch)
tree2bb7be86aafe9986811758b508a7581d2efe8ac4 /src/common/wall_clock.h
parentnvnflinger: Acquire lock prior to signaling the vsync variable (diff)
downloadyuzu-8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf.tar.gz
yuzu-8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf.tar.xz
yuzu-8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf.zip
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.h17
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:
38 /// @returns Whether the clock directly uses the host's hardware clock. 38 /// @returns Whether the clock directly uses the host's hardware clock.
39 virtual bool IsNative() const = 0; 39 virtual bool IsNative() const = 0;
40 40
41 static inline u64 NSToCNTPCT(u64 ns) {
42 return ns * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den;
43 }
44
45 static inline u64 USToCNTPCT(u64 us) {
46 return us * UsToCNTPCTRatio::num / UsToCNTPCTRatio::den;
47 }
48
49 static inline u64 CNTPCTToNS(u64 cntpct) {
50 return cntpct * NsToCNTPCTRatio::den / NsToCNTPCTRatio::num;
51 }
52
53 static inline u64 CNTPCTToUS(u64 cntpct) {
54 return cntpct * UsToCNTPCTRatio::den / UsToCNTPCTRatio::num;
55 }
56
41protected: 57protected:
42 using NsRatio = std::nano; 58 using NsRatio = std::nano;
43 using UsRatio = std::micro; 59 using UsRatio = std::micro;
@@ -46,6 +62,7 @@ protected:
46 using NsToUsRatio = std::ratio_divide<std::nano, std::micro>; 62 using NsToUsRatio = std::ratio_divide<std::nano, std::micro>;
47 using NsToMsRatio = std::ratio_divide<std::nano, std::milli>; 63 using NsToMsRatio = std::ratio_divide<std::nano, std::milli>;
48 using NsToCNTPCTRatio = std::ratio<CNTFRQ, std::nano::den>; 64 using NsToCNTPCTRatio = std::ratio<CNTFRQ, std::nano::den>;
65 using UsToCNTPCTRatio = std::ratio<CNTFRQ, std::micro::den>;
49}; 66};
50 67
51std::unique_ptr<WallClock> CreateOptimalClock(); 68std::unique_ptr<WallClock> CreateOptimalClock();