lv2: Ease the pain of lower end CPUs

- Avoid busy waiting in usleep code as much as possible, instead yield
- Also avoid busy_wait for SPU concurrency choker
This commit is contained in:
kd-11 2018-05-28 16:52:21 +03:00 committed by kd-11
parent 83f9be2524
commit d48f391b41
2 changed files with 15 additions and 7 deletions

View file

@ -159,10 +159,8 @@ namespace spu
{ {
if (remaining >= native_jiffy_duration_us) if (remaining >= native_jiffy_duration_us)
std::this_thread::sleep_for(1ms); std::this_thread::sleep_for(1ms);
else if (remaining > 100)
std::this_thread::yield();
else else
busy_wait(); std::this_thread::yield();
const auto now = get_system_time(); const auto now = get_system_time();
const auto elapsed = now - start; const auto elapsed = now - start;

View file

@ -296,19 +296,29 @@ error_code sys_timer_usleep(ppu_thread& ppu, u64 sleep_time)
if (sleep_time) if (sleep_time)
{ {
// Host scheduler quantum for windows (worst case)
// NOTE: On ps3 this function has very high accuracy
const u32 host_min_quantum = 500;
u64 passed = 0; u64 passed = 0;
u64 remaining; u64 remaining;
lv2_obj::sleep(ppu, sleep_time); lv2_obj::sleep(ppu, sleep_time);
while (sleep_time > passed) while (sleep_time >= passed)
{ {
remaining = sleep_time - passed; remaining = sleep_time - passed;
if (remaining > 500) if (remaining > host_min_quantum)
thread_ctrl::wait_for(remaining - (remaining % 500)); {
// Wait on multiple of min quantum for large durations
thread_ctrl::wait_for(remaining - (remaining % host_min_quantum));
}
else else
busy_wait(4000); {
// Try yielding. May cause long wake latency but helps weaker CPUs a lot by alleviating resource pressure
std::this_thread::yield();
}
passed = (get_system_time() - ppu.start_time); passed = (get_system_time() - ppu.start_time);
} }