From 72fb3ba794c8956aa33b3e7e396c8ac75e4e84e6 Mon Sep 17 00:00:00 2001 From: Eladash Date: Tue, 30 Jul 2019 17:15:15 +0300 Subject: [PATCH] perf hotfix for sys_timer_usleep --- rpcs3/Emu/Cell/lv2/lv2.cpp | 10 ++++------ rpcs3/Emu/Cell/lv2/sys_sync.h | 4 ++++ rpcs3/Emu/Cell/lv2/sys_timer.cpp | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index d1feb0c420..4829104f6b 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -1040,21 +1040,19 @@ void lv2_obj::sleep_timeout(cpu_thread& thread, u64 timeout) ppu->start_time = start_time; } - if (timeout && g_cfg.core.sleep_timers_accuracy != sleep_timers_accuracy_level::_all_timers) + if (timeout) { const u64 wait_until = start_time + timeout; // Register timeout if necessary - for (auto it = g_waiting.begin(), end = g_waiting.end(); it != end; it++) + for (auto it = g_waiting.cbegin(), end = g_waiting.cend();; it++) { - if (it->first > wait_until) + if (it == end || it->first > wait_until) { g_waiting.emplace(it, wait_until, &thread); - return; + break; } } - - g_waiting.emplace_back(wait_until, &thread); } schedule_all(); diff --git a/rpcs3/Emu/Cell/lv2/sys_sync.h b/rpcs3/Emu/Cell/lv2/sys_sync.h index 599747a727..a4d28f4d25 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sync.h +++ b/rpcs3/Emu/Cell/lv2/sys_sync.h @@ -218,6 +218,10 @@ struct lv2_obj template static bool wait_timeout(u64 usec, cpu_thread* const cpu = nullptr) { + // Clamp to max timeout accepted (also solves potential oveflows when scaling) + if (usec > cond_variable::max_timeout) usec = cond_variable::max_timeout; + + // Now scale the result usec = (usec * g_cfg.core.clocks_scale) / 100; #ifdef __linux__ diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index 5a6b5f0246..ddcbf5ed9b 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -307,7 +307,7 @@ error_code sys_timer_usleep(ppu_thread& ppu, u64 sleep_time) if (sleep_time) { - lv2_obj::sleep(ppu, 0); + lv2_obj::sleep(ppu, sleep_time); lv2_obj::wait_timeout(sleep_time);