summaryrefslogtreecommitdiffstats
path: root/src/core/host_timing.cpp
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2020-02-09 21:53:22 +0100
committerFernando Sahmkow <fsahmkow27@gmail.com>2020-06-18 22:29:17 +0200
commit234b5ff6a999d7d69cdcdf214e0c3984cdab11cf (patch)
tree4f0ef41d7738b53d1b81ac2f7072bec1ba5fe8f1 /src/core/host_timing.cpp
parentTests: Add base tests to host timing (diff)
downloadyuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar.gz
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar.bz2
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar.lz
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar.xz
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar.zst
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.zip
Diffstat (limited to 'src/core/host_timing.cpp')
-rw-r--r--src/core/host_timing.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/core/host_timing.cpp b/src/core/host_timing.cpp
index d9514b2c5..ef9977b76 100644
--- a/src/core/host_timing.cpp
+++ b/src/core/host_timing.cpp
@@ -35,7 +35,11 @@ struct CoreTiming::Event {
}
};
-CoreTiming::CoreTiming() = default;
+CoreTiming::CoreTiming() {
+ Common::WallClock* wall = Common::CreateBestMatchingClock(Core::Timing::BASE_CLOCK_RATE, Core::Timing::CNTFREQ);
+ clock = std::unique_ptr<Common::WallClock>(wall);
+}
+
CoreTiming::~CoreTiming() = default;
void CoreTiming::ThreadEntry(CoreTiming& instance) {
@@ -46,7 +50,6 @@ void CoreTiming::Initialize() {
event_fifo_id = 0;
const auto empty_timed_callback = [](u64, s64) {};
ev_lost = CreateEvent("_lost_event", empty_timed_callback);
- start_time = std::chrono::steady_clock::now();
timer_thread = std::make_unique<std::thread>(ThreadEntry, std::ref(*this));
}
@@ -108,13 +111,11 @@ void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u
}
u64 CoreTiming::GetCPUTicks() const {
- std::chrono::nanoseconds time_now = GetGlobalTimeNs();
- return Core::Timing::nsToCycles(time_now);
+ return clock->GetCPUCycles();
}
u64 CoreTiming::GetClockTicks() const {
- std::chrono::nanoseconds time_now = GetGlobalTimeNs();
- return Core::Timing::nsToClockCycles(time_now);
+ return clock->GetClockCycles();
}
void CoreTiming::ClearPendingEvents() {
@@ -174,15 +175,11 @@ void CoreTiming::Advance() {
}
std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const {
- sys_time_point current = std::chrono::steady_clock::now();
- auto elapsed = current - start_time;
- return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed);
+ return clock->GetTimeNS();
}
std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
- sys_time_point current = std::chrono::steady_clock::now();
- auto elapsed = current - start_time;
- return std::chrono::duration_cast<std::chrono::microseconds>(elapsed);
+ return clock->GetTimeUS();
}
} // namespace Core::Timing