From e0816f12ef4cb3de22fd011e02930a6a842bb445 Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi <18193363+elad335@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:02:20 +0300 Subject: [PATCH] SPU: More SPURS limiter fixes --- rpcs3/Emu/Cell/SPUThread.cpp | 48 ++++++++++++++---------------------- rpcs3/Emu/Cell/SPUThread.h | 1 - 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 449aec7afd41..a3bc73309cc4 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1678,7 +1678,6 @@ void spu_thread::cpu_init() spurs_average_task_duration = 0; spurs_waited = false; spurs_entered_wait = false; - spurs_read_events = false; int_ctrl[0].clear(); int_ctrl[1].clear(); @@ -4897,21 +4896,10 @@ bool spu_thread::process_mfc_cmd() // Avoid logging useless commands if there is no reservation const bool dump = g_cfg.core.mfc_debug && raddr; - const bool is_spurs_task_wait = pc == 0x11e4; + const bool is_spurs_task_wait = pc == 0x11e4 && spurs_addr; - do + if (is_spurs_task_wait && spurs_addr == raddr && g_cfg.core.max_spurs_threads != g_cfg.core.max_spurs_threads.def && !spurs_waited && !(_ref((ch_mfc_cmd.lsa & -128) + 0x73) & (1u << index))) { - if (!is_spurs_task_wait) - { - break; - } - - if (spurs_addr != raddr || g_cfg.core.max_spurs_threads == g_cfg.core.max_spurs_threads.def || spurs_waited || spurs_read_events) - { - spurs_read_events = false; - break; - } - // Wait for other threads to complete their tasks (temporarily) u32 max_run = group->max_run; @@ -4957,10 +4945,19 @@ bool spu_thread::process_mfc_cmd() spurs_waited = true; spurs_entered_wait = true; - // Wait the duration of 4 tasks - const u64 spurs_wait_time = std::clamp(spurs_average_task_duration / spurs_task_count_to_calculate * 4, 3000, 100'000); + // Wait the duration of 2 tasks + const u64 spurs_wait_time = std::clamp(spurs_average_task_duration / spurs_task_count_to_calculate * 2, 10000, 100'000); spurs_wait_duration_last = spurs_wait_time; + if (spurs_last_task_timestamp) + { + const u64 avg_entry = spurs_average_task_duration / spurs_task_count_to_calculate; + spurs_average_task_duration -= avg_entry; + spurs_average_task_duration += std::min(45'000, before - spurs_last_task_timestamp); + spu_log.trace("duration: %d, avg=%d", current - spurs_last_task_timestamp, spurs_average_task_duration / spurs_task_count_to_calculate); + spurs_last_task_timestamp = 0; + } + while (true) { if (is_stopped()) @@ -5005,7 +5002,6 @@ bool spu_thread::process_mfc_cmd() static_cast(test_stopped()); } } - while (false); if (do_putllc(ch_mfc_cmd)) { @@ -5018,12 +5014,13 @@ bool spu_thread::process_mfc_cmd() if (spurs_last_task_timestamp) { const u64 avg_entry = spurs_average_task_duration / spurs_task_count_to_calculate; - spurs_average_task_duration -= spurs_waited && !is_stopped() ? spurs_wait_duration_last + avg_entry : avg_entry; + spurs_average_task_duration -= avg_entry; + spu_log.trace("duration: %d, avg=%d", current - spurs_last_task_timestamp, spurs_average_task_duration / spurs_task_count_to_calculate); + spurs_average_task_duration -= avg_entry; spurs_average_task_duration += std::min(45'000, current - spurs_last_task_timestamp); } spurs_last_task_timestamp = current; - spurs_read_events = false; spurs_waited = false; spurs_entered_wait = false; } @@ -5626,23 +5623,16 @@ s64 spu_thread::get_ch_value(u32 ch) auto events = get_events(mask1, false, true); - const bool is_spurs_task_wait = pc == 0x11a8 && spurs_addr == raddr; - if (events.count) { - if (is_spurs_task_wait) - { - spurs_read_events = true; - } - return events.events & mask1; } + const bool is_spurs_task_wait = pc == 0x11a8 && spurs_addr == raddr; + if (is_spurs_task_wait) { - spurs_read_events = true; - - if (g_cfg.core.max_spurs_threads != g_cfg.core.max_spurs_threads.def && !spurs_entered_wait) + if (g_cfg.core.max_spurs_threads != g_cfg.core.max_spurs_threads.def && !spurs_entered_wait && (static_cast(rdata[0x73]) & (1u << index))) { const u32 prev_running = group->spurs_running.fetch_op([](u32& x) { diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index ecbab0538909..7172b8848afd 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -769,7 +769,6 @@ class spu_thread : public cpu_thread u32 spurs_addr = 0; bool spurs_waited = false; bool spurs_entered_wait = false; - bool spurs_read_events = false; u64 spurs_wait_duration_last = 0; u64 spurs_average_task_duration = 0; u64 spurs_last_task_timestamp = 0;