perf hotfix for sys_timer_usleep

This commit is contained in:
Eladash 2019-07-30 17:15:15 +03:00
parent f0bd0b5a7c
commit 72fb3ba794
3 changed files with 9 additions and 7 deletions

View File

@ -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();

View File

@ -218,6 +218,10 @@ struct lv2_obj
template<bool is_usleep = false>
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__

View File

@ -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<true>(sleep_time);