diff options
| author | 2024-01-25 14:19:01 -0500 | |
|---|---|---|
| committer | 2024-01-25 14:19:01 -0500 | |
| commit | d45561ace069024f47ed710d1165b607644d1ec3 (patch) | |
| tree | a316f59c5a722dc15fe5c49b3641d9801c264970 /src/common/x64/native_clock.cpp | |
| parent | Merge pull request #12781 from goldenx86/dozen (diff) | |
| parent | Rework time service to fix time passing offline. (diff) | |
| download | yuzu-d45561ace069024f47ed710d1165b607644d1ec3.tar.gz yuzu-d45561ace069024f47ed710d1165b607644d1ec3.tar.xz yuzu-d45561ace069024f47ed710d1165b607644d1ec3.zip | |
Merge pull request #12499 from Kelebek1/time
Rework time services
Diffstat (limited to 'src/common/x64/native_clock.cpp')
| -rw-r--r-- | src/common/x64/native_clock.cpp | 26 |
1 files changed, 11 insertions, 15 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 { |