diff options
| author | 2023-03-01 19:43:00 -0500 | |
|---|---|---|
| committer | 2023-03-05 02:36:31 -0500 | |
| commit | 7fffdf83b70ec5f0ead804cb2c16b9029f7e0cfa (patch) | |
| tree | 7444e4f15fb5a7b49004d1bca34779545dab3ce0 /src | |
| parent | common: Implement a method to change the Windows timer resolution (diff) | |
| download | yuzu-7fffdf83b70ec5f0ead804cb2c16b9029f7e0cfa.tar.gz yuzu-7fffdf83b70ec5f0ead804cb2c16b9029f7e0cfa.tar.xz yuzu-7fffdf83b70ec5f0ead804cb2c16b9029f7e0cfa.zip | |
wall_clock: Make use of SteadyClock
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/wall_clock.cpp | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp index ae07f2811..6d972d136 100644 --- a/src/common/wall_clock.cpp +++ b/src/common/wall_clock.cpp | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "common/steady_clock.h" | ||
| 4 | #include "common/uint128.h" | 5 | #include "common/uint128.h" |
| 5 | #include "common/wall_clock.h" | 6 | #include "common/wall_clock.h" |
| 6 | 7 | ||
| @@ -11,45 +12,32 @@ | |||
| 11 | 12 | ||
| 12 | namespace Common { | 13 | namespace Common { |
| 13 | 14 | ||
| 14 | using base_timer = std::chrono::steady_clock; | ||
| 15 | using base_time_point = std::chrono::time_point<base_timer>; | ||
| 16 | |||
| 17 | class StandardWallClock final : public WallClock { | 15 | class StandardWallClock final : public WallClock { |
| 18 | public: | 16 | public: |
| 19 | explicit StandardWallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_) | 17 | explicit StandardWallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_) |
| 20 | : WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, false) { | 18 | : WallClock{emulated_cpu_frequency_, emulated_clock_frequency_, false}, |
| 21 | start_time = base_timer::now(); | 19 | start_time{SteadyClock::Now()} {} |
| 22 | } | ||
| 23 | 20 | ||
| 24 | std::chrono::nanoseconds GetTimeNS() override { | 21 | std::chrono::nanoseconds GetTimeNS() override { |
| 25 | base_time_point current = base_timer::now(); | 22 | return SteadyClock::Now() - start_time; |
| 26 | auto elapsed = current - start_time; | ||
| 27 | return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed); | ||
| 28 | } | 23 | } |
| 29 | 24 | ||
| 30 | std::chrono::microseconds GetTimeUS() override { | 25 | std::chrono::microseconds GetTimeUS() override { |
| 31 | base_time_point current = base_timer::now(); | 26 | return std::chrono::duration_cast<std::chrono::microseconds>(GetTimeNS()); |
| 32 | auto elapsed = current - start_time; | ||
| 33 | return std::chrono::duration_cast<std::chrono::microseconds>(elapsed); | ||
| 34 | } | 27 | } |
| 35 | 28 | ||
| 36 | std::chrono::milliseconds GetTimeMS() override { | 29 | std::chrono::milliseconds GetTimeMS() override { |
| 37 | base_time_point current = base_timer::now(); | 30 | return std::chrono::duration_cast<std::chrono::milliseconds>(GetTimeNS()); |
| 38 | auto elapsed = current - start_time; | ||
| 39 | return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed); | ||
| 40 | } | 31 | } |
| 41 | 32 | ||
| 42 | u64 GetClockCycles() override { | 33 | u64 GetClockCycles() override { |
| 43 | std::chrono::nanoseconds time_now = GetTimeNS(); | 34 | const u128 temp = Common::Multiply64Into128(GetTimeNS().count(), emulated_clock_frequency); |
| 44 | const u128 temporary = | 35 | return Common::Divide128On32(temp, NS_RATIO).first; |
| 45 | Common::Multiply64Into128(time_now.count(), emulated_clock_frequency); | ||
| 46 | return Common::Divide128On32(temporary, 1000000000).first; | ||
| 47 | } | 36 | } |
| 48 | 37 | ||
| 49 | u64 GetCPUCycles() override { | 38 | u64 GetCPUCycles() override { |
| 50 | std::chrono::nanoseconds time_now = GetTimeNS(); | 39 | const u128 temp = Common::Multiply64Into128(GetTimeNS().count(), emulated_cpu_frequency); |
| 51 | const u128 temporary = Common::Multiply64Into128(time_now.count(), emulated_cpu_frequency); | 40 | return Common::Divide128On32(temp, NS_RATIO).first; |
| 52 | return Common::Divide128On32(temporary, 1000000000).first; | ||
| 53 | } | 41 | } |
| 54 | 42 | ||
| 55 | void Pause([[maybe_unused]] bool is_paused) override { | 43 | void Pause([[maybe_unused]] bool is_paused) override { |
| @@ -57,7 +45,7 @@ public: | |||
| 57 | } | 45 | } |
| 58 | 46 | ||
| 59 | private: | 47 | private: |
| 60 | base_time_point start_time; | 48 | SteadyClock::time_point start_time; |
| 61 | }; | 49 | }; |
| 62 | 50 | ||
| 63 | #ifdef ARCHITECTURE_x86_64 | 51 | #ifdef ARCHITECTURE_x86_64 |