diff options
Diffstat (limited to 'src/core/core_timing.cpp')
| -rw-r--r-- | src/core/core_timing.cpp | 36 |
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; | |||
| 57 | static s64 last_global_time_ticks; | 57 | static s64 last_global_time_ticks; |
| 58 | static s64 last_global_time_us; | 58 | static s64 last_global_time_us; |
| 59 | 59 | ||
| 60 | static s64 down_count = 0; ///< A decreasing counter of remaining cycles before the next event, | ||
| 61 | /// decreased by the cpu run loop | ||
| 62 | |||
| 60 | static std::recursive_mutex external_event_section; | 63 | static 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 | ||
| 148 | void Init() { | 151 | void 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 | ||
| 191 | void AddTicks(u64 ticks) { | ||
| 192 | down_count -= ticks; | ||
| 193 | if (down_count < 0) { | ||
| 194 | Advance(); | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 188 | u64 GetTicks() { | 198 | u64 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 | ||
| 192 | u64 GetIdleTicks() { | 202 | u64 GetIdleTicks() { |
| @@ -460,18 +470,18 @@ void MoveEvents() { | |||
| 460 | } | 470 | } |
| 461 | 471 | ||
| 462 | void ForceCheck() { | 472 | void 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 | ||
| 471 | void Advance() { | 481 | void 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 | ||
| 508 | void Idle(int max_idle) { | 518 | void 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 | ||
| 534 | std::string GetScheduledEventsSummary() { | 544 | std::string GetScheduledEventsSummary() { |