From 31afd046b0b9b9fc8427b14a966299a2826087cf Mon Sep 17 00:00:00 2001 From: Malcolm Jestadt Date: Tue, 18 Jun 2019 18:37:44 -0400 Subject: [PATCH] lv2: sys_timer_usleep improvements for linux -The minimum quantum on linux appears to be 50 microseconds by default, not 100 -Do not wait for the last quantum to avoid sleeping too long --- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index c07f738be1..989b3e207f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -294,7 +294,8 @@ error_code sys_timer_usleep(ppu_thread& ppu, u64 sleep_time) if (sleep_time) { #ifdef __linux__ - constexpr u32 host_min_quantum = 100; + // TODO: Confirm whether Apple or any BSD can benefit from this as well + constexpr u32 host_min_quantum = 50; #else // Host scheduler quantum for windows (worst case) // NOTE: On ps3 this function has very high accuracy @@ -317,8 +318,13 @@ error_code sys_timer_usleep(ppu_thread& ppu, u64 sleep_time) if (remaining > host_min_quantum) { - // Wait on multiple of min quantum for large durations +#ifdef __linux__ + // Do not wait for the last quantum to avoid loss of accuracy + thread_ctrl::wait_for(remaining - ((remaining % host_min_quantum) + host_min_quantum)); +#else + // Wait on multiple of min quantum for large durations to avoid overloading low thread cpus thread_ctrl::wait_for(remaining - (remaining % host_min_quantum)); +#endif } else {