From 148edc005a45b21c4c9c8250ed8548e05a368516 Mon Sep 17 00:00:00 2001 From: "Elad.Ash" <18193363+elad335@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:16:01 +0200 Subject: [PATCH] Improve cpu_flag::yield handling --- rpcs3/Emu/CPU/CPUThread.cpp | 2 +- rpcs3/Emu/Cell/lv2/lv2.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index af195ed770..53fc8ddb06 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -952,7 +952,7 @@ bool cpu_thread::check_state() noexcept continue; } - if (state0 & cpu_flag::yield && cpu_flag::wait - state0 && cpu_can_stop) + if (state0 & cpu_flag::yield && cpu_can_stop) { if (auto spu = try_get()) { diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index e82efc1c88..f8db392ef6 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -1763,9 +1763,13 @@ void lv2_obj::schedule_all(u64 current_time) if (target->state & cpu_flag::suspend) { ppu_log.trace("schedule(): %s", target->id); + + // Remove yield if it was sleeping until now + const bs_t remove_yield = target->start_time == 0 ? +cpu_flag::suspend : (cpu_flag::yield + cpu_flag::preempt); + target->start_time = 0; - if ((target->state.fetch_op(FN(x += cpu_flag::signal, x -= cpu_flag::suspend, void())) & (cpu_flag::wait + cpu_flag::signal)) != cpu_flag::wait) + if ((target->state.fetch_op(FN(x += cpu_flag::signal, x -= cpu_flag::suspend, x-= remove_yield, void())) & (cpu_flag::wait + cpu_flag::signal)) != cpu_flag::wait) { continue; }