implement margins for scheduler

hopefully this does not break anything
This commit is contained in:
RSDuck 2021-09-27 03:29:54 +02:00
parent 1471c73ea6
commit 737171c906
1 changed files with 10 additions and 5 deletions

View File

@ -88,6 +88,7 @@ u64 FrameStartTimestamp;
int CurCPU;
const s32 kMaxIterationCycles = 64;
const s32 kIterationCycleMargin = 8;
u32 ARM9ClockShift;
@ -917,7 +918,7 @@ void RelocateSave(const char* path, bool write)
u64 NextTarget()
{
u64 ret = SysTimestamp + kMaxIterationCycles;
u64 minEvent = UINT64_MAX;
u32 mask = SchedListMask;
for (int i = 0; i < Event_MAX; i++)
@ -925,14 +926,19 @@ u64 NextTarget()
if (!mask) break;
if (mask & 0x1)
{
if (SchedList[i].Timestamp < ret)
ret = SchedList[i].Timestamp;
if (SchedList[i].Timestamp < minEvent)
minEvent = SchedList[i].Timestamp;
}
mask >>= 1;
}
return ret;
u64 max = SysTimestamp + kMaxIterationCycles;
if (minEvent < max + kIterationCycleMargin)
return minEvent;
return max;
}
void RunSystem(u64 timestamp)
@ -969,7 +975,6 @@ u32 RunFrame()
while (Running && GPU::TotalScanlines==0)
{
// TODO: give it some margin, so it can directly do 17 cycles instead of 16 then 1
u64 target = NextTarget();
ARM9Target = target << ARM9ClockShift;
CurCPU = 0;