From 0beda6fa8943608c73ae3ad7f5457a444ffc47ea Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 11 Mar 2023 11:51:30 +0200 Subject: [PATCH] Savestates: Fix deadlock on savestate load --- rpcs3/Emu/Cell/lv2/lv2.cpp | 11 +++++++++-- rpcs3/Emu/Cell/lv2/sys_sync.h | 2 ++ rpcs3/Emu/System.cpp | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index 24ccf2da91..1482fa7a3f 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -1218,7 +1218,7 @@ static std::deque> g_waiting; // Threads which must call lv2_obj::sleep before the scheduler starts static std::deque g_to_sleep; - +static atomic_t g_scheduler_ready = false; static atomic_t s_yield_frequency = 0; static atomic_t s_max_allowed_yield_tsc = 0; static u64 s_last_yield_tsc = 0; @@ -1596,6 +1596,7 @@ bool lv2_obj::awake_unlocked(cpu_thread* cpu, s32 prio) void lv2_obj::cleanup() { g_ppu = nullptr; + g_scheduler_ready = false; g_to_sleep.clear(); g_waiting.clear(); g_pending = 0; @@ -1606,7 +1607,7 @@ void lv2_obj::schedule_all(u64 current_time) { usz notify_later_idx = 0; - if (!g_pending && g_to_sleep.empty()) + if (!g_pending && g_scheduler_ready) { auto target = +g_ppu; @@ -1727,6 +1728,12 @@ void lv2_obj::schedule_all(u64 current_time) } } +void lv2_obj::make_scheduler_ready() +{ + g_scheduler_ready.release(true); + lv2_obj::awake_all(); +} + ppu_thread_status lv2_obj::ppu_state(ppu_thread* ppu, bool lock_idm, bool lock_lv2) { std::optional opt_lock[2]; diff --git a/rpcs3/Emu/Cell/lv2/sys_sync.h b/rpcs3/Emu/Cell/lv2/sys_sync.h index 9774e36512..e0b12392f4 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sync.h +++ b/rpcs3/Emu/Cell/lv2/sys_sync.h @@ -242,6 +242,8 @@ public: g_to_awake.clear(); } + static void make_scheduler_ready(); + static ppu_thread_status ppu_state(ppu_thread* ppu, bool lock_idm = true, bool lock_lv2 = true); static inline void append(cpu_thread* const thread) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 19aca5fcce..9ed39b4d54 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -2249,7 +2249,7 @@ void Emulator::FinalizeRunRequest() idm::select>(on_select); - lv2_obj::awake_all(); + lv2_obj::make_scheduler_ready(); m_state.compare_and_swap_test(system_state::starting, system_state::running); }