From 555866f8dcb98897688d5d7b0e6c6cca55ac069f Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Mon, 9 Sep 2019 21:37:29 -0400 Subject: Core Timing: Rework Core Timing to run all cores evenly. --- src/core/core_timing.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/core/core_timing.h') diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 161c7007d..ec0a6d2c0 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -104,7 +105,19 @@ public: std::chrono::microseconds GetGlobalTimeUs() const; - int GetDowncount() const; + void ResetRun(); + + s64 GetDowncount() const; + + void SwitchContext(u64 new_context) { + current_context = new_context; + } + + bool CurrentContextCanRun() const { + return time_slice[current_context] > 0; + } + + std::optional NextAvailableCore(const s64 needed_ticks) const; private: struct Event; @@ -112,10 +125,15 @@ private: /// Clear all pending events. This should ONLY be done on exit. void ClearPendingEvents(); + static constexpr u64 num_cpu_cores = 4; + s64 global_timer = 0; s64 idled_cycles = 0; - int slice_length = 0; - int downcount = 0; + s64 slice_length = 0; + std::array downcounts{}; + // Slice of time assigned to each core per run. + std::array time_slice{}; + u64 current_context = 0; // Are we in a function that has been called from Advance() // If events are scheduled from a function that gets called from Advance(), -- cgit v1.2.3 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.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/core_timing.h') 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 From e0650a2034026d8292196128d2f9decb50eeb0f3 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Fri, 11 Oct 2019 14:44:14 -0400 Subject: Core_Timing: Address Feedback and suppress warnings. --- src/core/core_timing.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/core_timing.h') diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 8bba45beb..3bb88c810 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h @@ -113,7 +113,7 @@ public: current_context = new_context; } - bool CurrentContextCanRun() const { + bool CanCurrentContextRun() const { return time_slice[current_context] > 0; } -- cgit v1.2.3