summaryrefslogtreecommitdiff
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2017-10-09 23:56:20 -0400
committerGravatar bunnei2017-10-09 23:56:20 -0400
commitb1d5db1cf60344b6b081c9d03cb6ccc3264326cd (patch)
treefde377c4ba3c0f92c032e6f5ec8627aae37270ef /src/core/core_timing.cpp
parentloader: Various improvements for NSO/NRO loaders. (diff)
parentMerge pull request #2996 from MerryMage/split-travis (diff)
downloadyuzu-b1d5db1cf60344b6b081c9d03cb6ccc3264326cd.tar.gz
yuzu-b1d5db1cf60344b6b081c9d03cb6ccc3264326cd.tar.xz
yuzu-b1d5db1cf60344b6b081c9d03cb6ccc3264326cd.zip
Merge remote-tracking branch 'upstream/master' into nx
# Conflicts: # src/core/CMakeLists.txt # src/core/arm/dynarmic/arm_dynarmic.cpp # src/core/arm/dyncom/arm_dyncom.cpp # src/core/hle/kernel/process.cpp # src/core/hle/kernel/thread.cpp # src/core/hle/kernel/thread.h # src/core/hle/kernel/vm_manager.cpp # src/core/loader/3dsx.cpp # src/core/loader/elf.cpp # src/core/loader/ncch.cpp # src/core/memory.cpp # src/core/memory.h # src/core/memory_setup.h
Diffstat (limited to 'src/core/core_timing.cpp')
-rw-r--r--src/core/core_timing.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 276ecfdf6..5e2a5d00f 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -57,6 +57,9 @@ static s64 idled_cycles;
57static s64 last_global_time_ticks; 57static s64 last_global_time_ticks;
58static s64 last_global_time_us; 58static s64 last_global_time_us;
59 59
60static s64 down_count = 0; ///< A decreasing counter of remaining cycles before the next event,
61 /// decreased by the cpu run loop
62
60static std::recursive_mutex external_event_section; 63static std::recursive_mutex external_event_section;
61 64
62// Warning: not included in save state. 65// Warning: not included in save state.
@@ -146,7 +149,7 @@ void UnregisterAllEvents() {
146} 149}
147 150
148void Init() { 151void Init() {
149 Core::CPU().down_count = INITIAL_SLICE_LENGTH; 152 down_count = INITIAL_SLICE_LENGTH;
150 g_slice_length = INITIAL_SLICE_LENGTH; 153 g_slice_length = INITIAL_SLICE_LENGTH;
151 global_timer = 0; 154 global_timer = 0;
152 idled_cycles = 0; 155 idled_cycles = 0;
@@ -185,8 +188,15 @@ void Shutdown() {
185 } 188 }
186} 189}
187 190
191void AddTicks(u64 ticks) {
192 down_count -= ticks;
193 if (down_count < 0) {
194 Advance();
195 }
196}
197
188u64 GetTicks() { 198u64 GetTicks() {
189 return (u64)global_timer + g_slice_length - Core::CPU().down_count; 199 return (u64)global_timer + g_slice_length - down_count;
190} 200}
191 201
192u64 GetIdleTicks() { 202u64 GetIdleTicks() {
@@ -460,18 +470,18 @@ void MoveEvents() {
460} 470}
461 471
462void ForceCheck() { 472void ForceCheck() {
463 s64 cycles_executed = g_slice_length - Core::CPU().down_count; 473 s64 cycles_executed = g_slice_length - down_count;
464 global_timer += cycles_executed; 474 global_timer += cycles_executed;
465 // This will cause us to check for new events immediately. 475 // This will cause us to check for new events immediately.
466 Core::CPU().down_count = 0; 476 down_count = 0;
467 // But let's not eat a bunch more time in Advance() because of this. 477 // But let's not eat a bunch more time in Advance() because of this.
468 g_slice_length = 0; 478 g_slice_length = 0;
469} 479}
470 480
471void Advance() { 481void Advance() {
472 s64 cycles_executed = g_slice_length - Core::CPU().down_count; 482 s64 cycles_executed = g_slice_length - down_count;
473 global_timer += cycles_executed; 483 global_timer += cycles_executed;
474 Core::CPU().down_count = g_slice_length; 484 down_count = g_slice_length;
475 485
476 if (has_ts_events) 486 if (has_ts_events)
477 MoveEvents(); 487 MoveEvents();
@@ -480,7 +490,7 @@ void Advance() {
480 if (!first) { 490 if (!first) {
481 if (g_slice_length < 10000) { 491 if (g_slice_length < 10000) {
482 g_slice_length += 10000; 492 g_slice_length += 10000;
483 Core::CPU().down_count += g_slice_length; 493 down_count += g_slice_length;
484 } 494 }
485 } else { 495 } else {
486 // Note that events can eat cycles as well. 496 // Note that events can eat cycles as well.
@@ -490,7 +500,7 @@ void Advance() {
490 500
491 const int diff = target - g_slice_length; 501 const int diff = target - g_slice_length;
492 g_slice_length += diff; 502 g_slice_length += diff;
493 Core::CPU().down_count += diff; 503 down_count += diff;
494 } 504 }
495 if (advance_callback) 505 if (advance_callback)
496 advance_callback(static_cast<int>(cycles_executed)); 506 advance_callback(static_cast<int>(cycles_executed));
@@ -506,12 +516,12 @@ void LogPendingEvents() {
506} 516}
507 517
508void Idle(int max_idle) { 518void Idle(int max_idle) {
509 s64 cycles_down = Core::CPU().down_count; 519 s64 cycles_down = down_count;
510 if (max_idle != 0 && cycles_down > max_idle) 520 if (max_idle != 0 && cycles_down > max_idle)
511 cycles_down = max_idle; 521 cycles_down = max_idle;
512 522
513 if (first && cycles_down > 0) { 523 if (first && cycles_down > 0) {
514 s64 cycles_executed = g_slice_length - Core::CPU().down_count; 524 s64 cycles_executed = g_slice_length - down_count;
515 s64 cycles_next_event = first->time - global_timer; 525 s64 cycles_next_event = first->time - global_timer;
516 526
517 if (cycles_next_event < cycles_executed + cycles_down) { 527 if (cycles_next_event < cycles_executed + cycles_down) {
@@ -526,9 +536,9 @@ void Idle(int max_idle) {
526 cycles_down / (float)(g_clock_rate_arm11 * 0.001f)); 536 cycles_down / (float)(g_clock_rate_arm11 * 0.001f));
527 537
528 idled_cycles += cycles_down; 538 idled_cycles += cycles_down;
529 Core::CPU().down_count -= cycles_down; 539 down_count -= cycles_down;
530 if (Core::CPU().down_count == 0) 540 if (down_count == 0)
531 Core::CPU().down_count = -1; 541 down_count = -1;
532} 542}
533 543
534std::string GetScheduledEventsSummary() { 544std::string GetScheduledEventsSummary() {