From 65aff6930bdfe1ecbf7e3c7eec967c2c6149aaef Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 8 Oct 2019 17:18:06 -0400 Subject: Core Timing: General corrections and added tests. --- src/core/core_timing.cpp | 15 +++++++++++---- src/core/core_timing.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 6da2dcfb4..0ed6f9b19 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -13,6 +13,8 @@ #include "common/thread.h" #include "core/core_timing_util.h" +#pragma optoimize("", off) + namespace Core::Timing { constexpr int MAX_SLICE_LENGTH = 10000; @@ -114,7 +116,7 @@ void CoreTiming::UnscheduleEvent(const EventType* event_type, u64 userdata) { u64 CoreTiming::GetTicks() const { u64 ticks = static_cast(global_timer); if (!is_global_timer_sane) { - ticks += time_slice[current_context] - downcounts[current_context]; + ticks += accumulated_ticks; } return ticks; } @@ -124,6 +126,7 @@ u64 CoreTiming::GetIdleTicks() const { } void CoreTiming::AddTicks(u64 ticks) { + accumulated_ticks += ticks; downcounts[current_context] -= static_cast(ticks); } @@ -151,7 +154,6 @@ void CoreTiming::ForceExceptionCheck(s64 cycles) { // downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int // here. Account for cycles already executed by adjusting the g.slice_length - slice_length -= downcounts[current_context] - static_cast(cycles); downcounts[current_context] = static_cast(cycles); } @@ -172,8 +174,8 @@ std::optional CoreTiming::NextAvailableCore(const s64 needed_ticks) const { void CoreTiming::Advance() { std::unique_lock guard(inner_mutex); - const int cycles_executed = time_slice[current_context] - downcounts[current_context]; - time_slice[current_context] = std::max(0, downcounts[current_context]); + const int cycles_executed = accumulated_ticks; + time_slice[current_context] = std::max(0, time_slice[current_context] - accumulated_ticks); global_timer += cycles_executed; is_global_timer_sane = true; @@ -198,6 +200,8 @@ void CoreTiming::Advance() { } } + accumulated_ticks = 0; + downcounts[current_context] = time_slice[current_context]; } @@ -212,6 +216,9 @@ void CoreTiming::ResetRun() { s64 needed_ticks = std::min(event_queue.front().time - global_timer, MAX_SLICE_LENGTH); downcounts[current_context] = needed_ticks; } + + is_global_timer_sane = false; + accumulated_ticks = 0; } void CoreTiming::Idle() { diff --git a/src/core/core_timing.h b/src/core/core_timing.h index ec0a6d2c0..8bba45beb 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h @@ -130,6 +130,7 @@ private: s64 global_timer = 0; s64 idled_cycles = 0; s64 slice_length = 0; + u64 accumulated_ticks = 0; std::array downcounts{}; // Slice of time assigned to each core per run. std::array time_slice{}; -- cgit v1.2.3