diff options
| author | 2023-10-29 13:50:55 +0000 | |
|---|---|---|
| committer | 2024-01-24 04:26:55 +0000 | |
| commit | e4915fb7d2077584a11a15141bc81d28ed2b0125 (patch) | |
| tree | 1783055dc2e98eaf9099e8e7b194b55f8f607747 /src/common/x64 | |
| parent | Merge pull request #12678 from german77/settings_impl (diff) | |
| download | yuzu-e4915fb7d2077584a11a15141bc81d28ed2b0125.tar.gz yuzu-e4915fb7d2077584a11a15141bc81d28ed2b0125.tar.xz yuzu-e4915fb7d2077584a11a15141bc81d28ed2b0125.zip | |
Rework time service to fix time passing offline.
Diffstat (limited to 'src/common/x64')
| -rw-r--r-- | src/common/x64/native_clock.cpp | 26 | ||||
| -rw-r--r-- | src/common/x64/native_clock.h | 9 |
2 files changed, 14 insertions, 21 deletions
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp index 7d2a26bd9..d2d27fafe 100644 --- a/src/common/x64/native_clock.cpp +++ b/src/common/x64/native_clock.cpp | |||
| @@ -8,39 +8,35 @@ | |||
| 8 | namespace Common::X64 { | 8 | namespace Common::X64 { |
| 9 | 9 | ||
| 10 | NativeClock::NativeClock(u64 rdtsc_frequency_) | 10 | NativeClock::NativeClock(u64 rdtsc_frequency_) |
| 11 | : start_ticks{FencedRDTSC()}, rdtsc_frequency{rdtsc_frequency_}, | 11 | : rdtsc_frequency{rdtsc_frequency_}, ns_rdtsc_factor{GetFixedPoint64Factor(NsRatio::den, |
| 12 | ns_rdtsc_factor{GetFixedPoint64Factor(NsRatio::den, rdtsc_frequency)}, | 12 | rdtsc_frequency)}, |
| 13 | us_rdtsc_factor{GetFixedPoint64Factor(UsRatio::den, rdtsc_frequency)}, | 13 | us_rdtsc_factor{GetFixedPoint64Factor(UsRatio::den, rdtsc_frequency)}, |
| 14 | ms_rdtsc_factor{GetFixedPoint64Factor(MsRatio::den, rdtsc_frequency)}, | 14 | ms_rdtsc_factor{GetFixedPoint64Factor(MsRatio::den, rdtsc_frequency)}, |
| 15 | cntpct_rdtsc_factor{GetFixedPoint64Factor(CNTFRQ, rdtsc_frequency)}, | 15 | cntpct_rdtsc_factor{GetFixedPoint64Factor(CNTFRQ, rdtsc_frequency)}, |
| 16 | gputick_rdtsc_factor{GetFixedPoint64Factor(GPUTickFreq, rdtsc_frequency)} {} | 16 | gputick_rdtsc_factor{GetFixedPoint64Factor(GPUTickFreq, rdtsc_frequency)} {} |
| 17 | 17 | ||
| 18 | std::chrono::nanoseconds NativeClock::GetTimeNS() const { | 18 | std::chrono::nanoseconds NativeClock::GetTimeNS() const { |
| 19 | return std::chrono::nanoseconds{MultiplyHigh(GetHostTicksElapsed(), ns_rdtsc_factor)}; | 19 | return std::chrono::nanoseconds{MultiplyHigh(GetUptime(), ns_rdtsc_factor)}; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | std::chrono::microseconds NativeClock::GetTimeUS() const { | 22 | std::chrono::microseconds NativeClock::GetTimeUS() const { |
| 23 | return std::chrono::microseconds{MultiplyHigh(GetHostTicksElapsed(), us_rdtsc_factor)}; | 23 | return std::chrono::microseconds{MultiplyHigh(GetUptime(), us_rdtsc_factor)}; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | std::chrono::milliseconds NativeClock::GetTimeMS() const { | 26 | std::chrono::milliseconds NativeClock::GetTimeMS() const { |
| 27 | return std::chrono::milliseconds{MultiplyHigh(GetHostTicksElapsed(), ms_rdtsc_factor)}; | 27 | return std::chrono::milliseconds{MultiplyHigh(GetUptime(), ms_rdtsc_factor)}; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | u64 NativeClock::GetCNTPCT() const { | 30 | s64 NativeClock::GetCNTPCT() const { |
| 31 | return MultiplyHigh(GetHostTicksElapsed(), cntpct_rdtsc_factor); | 31 | return MultiplyHigh(GetUptime(), cntpct_rdtsc_factor); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | u64 NativeClock::GetGPUTick() const { | 34 | s64 NativeClock::GetGPUTick() const { |
| 35 | return MultiplyHigh(GetHostTicksElapsed(), gputick_rdtsc_factor); | 35 | return MultiplyHigh(GetUptime(), gputick_rdtsc_factor); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | u64 NativeClock::GetHostTicksNow() const { | 38 | s64 NativeClock::GetUptime() const { |
| 39 | return FencedRDTSC(); | 39 | return static_cast<s64>(FencedRDTSC()); |
| 40 | } | ||
| 41 | |||
| 42 | u64 NativeClock::GetHostTicksElapsed() const { | ||
| 43 | return FencedRDTSC() - start_ticks; | ||
| 44 | } | 40 | } |
| 45 | 41 | ||
| 46 | bool NativeClock::IsNative() const { | 42 | bool NativeClock::IsNative() const { |
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h index 334415eff..b2629b031 100644 --- a/src/common/x64/native_clock.h +++ b/src/common/x64/native_clock.h | |||
| @@ -17,18 +17,15 @@ public: | |||
| 17 | 17 | ||
| 18 | std::chrono::milliseconds GetTimeMS() const override; | 18 | std::chrono::milliseconds GetTimeMS() const override; |
| 19 | 19 | ||
| 20 | u64 GetCNTPCT() const override; | 20 | s64 GetCNTPCT() const override; |
| 21 | 21 | ||
| 22 | u64 GetGPUTick() const override; | 22 | s64 GetGPUTick() const override; |
| 23 | 23 | ||
| 24 | u64 GetHostTicksNow() const override; | 24 | s64 GetUptime() const override; |
| 25 | |||
| 26 | u64 GetHostTicksElapsed() const override; | ||
| 27 | 25 | ||
| 28 | bool IsNative() const override; | 26 | bool IsNative() const override; |
| 29 | 27 | ||
| 30 | private: | 28 | private: |
| 31 | u64 start_ticks; | ||
| 32 | u64 rdtsc_frequency; | 29 | u64 rdtsc_frequency; |
| 33 | 30 | ||
| 34 | u64 ns_rdtsc_factor; | 31 | u64 ns_rdtsc_factor; |