summaryrefslogtreecommitdiff
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-10-08 17:18:06 -0400
committerGravatar FernandoS272019-10-09 12:30:33 -0400
commit65aff6930bdfe1ecbf7e3c7eec967c2c6149aaef (patch)
treed111578abe39248c638283a7f735f5dbc140e21d /src/core/core_timing.cpp
parentTests: Eliminate old Core Timing Tests (diff)
downloadyuzu-65aff6930bdfe1ecbf7e3c7eec967c2c6149aaef.tar.gz
yuzu-65aff6930bdfe1ecbf7e3c7eec967c2c6149aaef.tar.xz
yuzu-65aff6930bdfe1ecbf7e3c7eec967c2c6149aaef.zip
Core Timing: General corrections and added tests.
Diffstat (limited to 'src/core/core_timing.cpp')
-rw-r--r--src/core/core_timing.cpp15
1 files changed, 11 insertions, 4 deletions
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 @@
13#include "common/thread.h" 13#include "common/thread.h"
14#include "core/core_timing_util.h" 14#include "core/core_timing_util.h"
15 15
16#pragma optoimize("", off)
17
16namespace Core::Timing { 18namespace Core::Timing {
17 19
18constexpr int MAX_SLICE_LENGTH = 10000; 20constexpr int MAX_SLICE_LENGTH = 10000;
@@ -114,7 +116,7 @@ void CoreTiming::UnscheduleEvent(const EventType* event_type, u64 userdata) {
114u64 CoreTiming::GetTicks() const { 116u64 CoreTiming::GetTicks() const {
115 u64 ticks = static_cast<u64>(global_timer); 117 u64 ticks = static_cast<u64>(global_timer);
116 if (!is_global_timer_sane) { 118 if (!is_global_timer_sane) {
117 ticks += time_slice[current_context] - downcounts[current_context]; 119 ticks += accumulated_ticks;
118 } 120 }
119 return ticks; 121 return ticks;
120} 122}
@@ -124,6 +126,7 @@ u64 CoreTiming::GetIdleTicks() const {
124} 126}
125 127
126void CoreTiming::AddTicks(u64 ticks) { 128void CoreTiming::AddTicks(u64 ticks) {
129 accumulated_ticks += ticks;
127 downcounts[current_context] -= static_cast<s64>(ticks); 130 downcounts[current_context] -= static_cast<s64>(ticks);
128} 131}
129 132
@@ -151,7 +154,6 @@ void CoreTiming::ForceExceptionCheck(s64 cycles) {
151 154
152 // downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int 155 // downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int
153 // here. Account for cycles already executed by adjusting the g.slice_length 156 // here. Account for cycles already executed by adjusting the g.slice_length
154 slice_length -= downcounts[current_context] - static_cast<int>(cycles);
155 downcounts[current_context] = static_cast<int>(cycles); 157 downcounts[current_context] = static_cast<int>(cycles);
156} 158}
157 159
@@ -172,8 +174,8 @@ std::optional<u64> CoreTiming::NextAvailableCore(const s64 needed_ticks) const {
172void CoreTiming::Advance() { 174void CoreTiming::Advance() {
173 std::unique_lock<std::mutex> guard(inner_mutex); 175 std::unique_lock<std::mutex> guard(inner_mutex);
174 176
175 const int cycles_executed = time_slice[current_context] - downcounts[current_context]; 177 const int cycles_executed = accumulated_ticks;
176 time_slice[current_context] = std::max<s64>(0, downcounts[current_context]); 178 time_slice[current_context] = std::max<s64>(0, time_slice[current_context] - accumulated_ticks);
177 global_timer += cycles_executed; 179 global_timer += cycles_executed;
178 180
179 is_global_timer_sane = true; 181 is_global_timer_sane = true;
@@ -198,6 +200,8 @@ void CoreTiming::Advance() {
198 } 200 }
199 } 201 }
200 202
203 accumulated_ticks = 0;
204
201 downcounts[current_context] = time_slice[current_context]; 205 downcounts[current_context] = time_slice[current_context];
202} 206}
203 207
@@ -212,6 +216,9 @@ void CoreTiming::ResetRun() {
212 s64 needed_ticks = std::min<s64>(event_queue.front().time - global_timer, MAX_SLICE_LENGTH); 216 s64 needed_ticks = std::min<s64>(event_queue.front().time - global_timer, MAX_SLICE_LENGTH);
213 downcounts[current_context] = needed_ticks; 217 downcounts[current_context] = needed_ticks;
214 } 218 }
219
220 is_global_timer_sane = false;
221 accumulated_ticks = 0;
215} 222}
216 223
217void CoreTiming::Idle() { 224void CoreTiming::Idle() {