lv2: Reimplement sys_timer_usleep
- Matches ps3 accuracy for all tested values with few exceptions - Do not enter the host OS kernel if waiting for less than 500us to avoid scheduler issues
This commit is contained in:
@@ -122,6 +122,12 @@ struct lv2_obj
|
|||||||
sleep_timeout(thread, timeout);
|
sleep_timeout(thread, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void yield(cpu_thread& thread)
|
||||||
|
{
|
||||||
|
vm::temporary_unlock(thread);
|
||||||
|
awake(thread, -4);
|
||||||
|
}
|
||||||
|
|
||||||
// Schedule the thread
|
// Schedule the thread
|
||||||
static void awake(cpu_thread&, u32 prio);
|
static void awake(cpu_thread&, u32 prio);
|
||||||
|
|
||||||
|
|||||||
@@ -294,14 +294,28 @@ error_code sys_timer_usleep(ppu_thread& ppu, u64 sleep_time)
|
|||||||
|
|
||||||
sys_timer.trace("sys_timer_usleep(sleep_time=0x%llx)", sleep_time);
|
sys_timer.trace("sys_timer_usleep(sleep_time=0x%llx)", sleep_time);
|
||||||
|
|
||||||
u64 passed = 0;
|
if (sleep_time)
|
||||||
|
|
||||||
lv2_obj::sleep(ppu, std::max<u64>(1, sleep_time));
|
|
||||||
|
|
||||||
while (sleep_time >= passed)
|
|
||||||
{
|
{
|
||||||
thread_ctrl::wait_for(std::max<u64>(1, sleep_time - passed));
|
u64 passed = 0;
|
||||||
passed = get_system_time() - ppu.start_time;
|
u64 remaining;
|
||||||
|
|
||||||
|
lv2_obj::sleep(ppu, sleep_time);
|
||||||
|
|
||||||
|
while (sleep_time > passed)
|
||||||
|
{
|
||||||
|
remaining = sleep_time - passed;
|
||||||
|
|
||||||
|
if (remaining > 500)
|
||||||
|
thread_ctrl::wait_for(remaining - (remaining % 500));
|
||||||
|
else
|
||||||
|
busy_wait(4000);
|
||||||
|
|
||||||
|
passed = (get_system_time() - ppu.start_time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lv2_obj::yield(ppu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CELL_OK;
|
return CELL_OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user