Process events when idle or switching threads.

Fixes hrydgard/ppsspp#104, so things execute more accurately.
This commit is contained in:
Unknown W. Brackets 2012-11-30 23:06:27 -08:00
parent 998104e2eb
commit a2ee736793
2 changed files with 23 additions and 1 deletions

View File

@ -500,6 +500,20 @@ void Idle(int maxIdle)
if (maxIdle != 0 && cyclesDown > maxIdle)
cyclesDown = maxIdle;
if (first && cyclesDown > 0)
{
int cyclesExecuted = slicelength - downcount;
int cyclesNextEvent = (int) (first->time - globalTimer);
if (cyclesNextEvent < cyclesExecuted + cyclesDown)
{
cyclesDown = cyclesNextEvent - cyclesExecuted;
// Now, now... no time machines, please.
if (cyclesDown < 0)
cyclesDown = 0;
}
}
DEBUG_LOG(CPU, "Idle for %i cycles! (%f ms)", cyclesDown, cyclesDown / (float)(CPU_HZ * 0.001f));
idledCycles += cyclesDown;
@ -520,7 +534,7 @@ std::string GetScheduledEventsSummary()
if (!name)
name = "[unknown]";
char temp[512];
sprintf(temp, "%s : %i %08x%08x\n", event_types[ptr->type].name, (int)ptr->time, (u32)(ptr->userdata >> 32), (u32)(ptr->userdata));
sprintf(temp, "%s : %i %08x%08x\n", name, (int)ptr->time, (u32)(ptr->userdata >> 32), (u32)(ptr->userdata));
text += temp;
ptr = ptr->next;
}

View File

@ -730,6 +730,14 @@ void __KernelReSchedule(const char *reason)
return;
}
// Execute any pending events while we're doing scheduling.
CoreTiming::Advance();
if (__IsInInterrupt() || __KernelInCallback())
{
reason = "In Interrupt Or Callback";
return;
}
retry:
Thread *nextThread = __KernelNextThread();