2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

wall_clock: Make use of SteadyClock

This commit is contained in:
Morph 2023-03-01 19:43:00 -05:00
parent 1ed49f92dd
commit 7fffdf83b7

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "common/steady_clock.h"
#include "common/uint128.h" #include "common/uint128.h"
#include "common/wall_clock.h" #include "common/wall_clock.h"
@ -11,45 +12,32 @@
namespace Common { namespace Common {
using base_timer = std::chrono::steady_clock;
using base_time_point = std::chrono::time_point<base_timer>;
class StandardWallClock final : public WallClock { class StandardWallClock final : public WallClock {
public: public:
explicit StandardWallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_) explicit StandardWallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_)
: WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, false) { : WallClock{emulated_cpu_frequency_, emulated_clock_frequency_, false},
start_time = base_timer::now(); start_time{SteadyClock::Now()} {}
}
std::chrono::nanoseconds GetTimeNS() override { std::chrono::nanoseconds GetTimeNS() override {
base_time_point current = base_timer::now(); return SteadyClock::Now() - start_time;
auto elapsed = current - start_time;
return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed);
} }
std::chrono::microseconds GetTimeUS() override { std::chrono::microseconds GetTimeUS() override {
base_time_point current = base_timer::now(); return std::chrono::duration_cast<std::chrono::microseconds>(GetTimeNS());
auto elapsed = current - start_time;
return std::chrono::duration_cast<std::chrono::microseconds>(elapsed);
} }
std::chrono::milliseconds GetTimeMS() override { std::chrono::milliseconds GetTimeMS() override {
base_time_point current = base_timer::now(); return std::chrono::duration_cast<std::chrono::milliseconds>(GetTimeNS());
auto elapsed = current - start_time;
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
} }
u64 GetClockCycles() override { u64 GetClockCycles() override {
std::chrono::nanoseconds time_now = GetTimeNS(); const u128 temp = Common::Multiply64Into128(GetTimeNS().count(), emulated_clock_frequency);
const u128 temporary = return Common::Divide128On32(temp, NS_RATIO).first;
Common::Multiply64Into128(time_now.count(), emulated_clock_frequency);
return Common::Divide128On32(temporary, 1000000000).first;
} }
u64 GetCPUCycles() override { u64 GetCPUCycles() override {
std::chrono::nanoseconds time_now = GetTimeNS(); const u128 temp = Common::Multiply64Into128(GetTimeNS().count(), emulated_cpu_frequency);
const u128 temporary = Common::Multiply64Into128(time_now.count(), emulated_cpu_frequency); return Common::Divide128On32(temp, NS_RATIO).first;
return Common::Divide128On32(temporary, 1000000000).first;
} }
void Pause([[maybe_unused]] bool is_paused) override { void Pause([[maybe_unused]] bool is_paused) override {
@ -57,7 +45,7 @@ public:
} }
private: private:
base_time_point start_time; SteadyClock::time_point start_time;
}; };
#ifdef ARCHITECTURE_x86_64 #ifdef ARCHITECTURE_x86_64