Skip to content

Commit

Permalink
Merge pull request #1568 from ergo720/timer_slow_cpu
Browse files Browse the repository at this point in the history
Fix a bug in KiClockIsr affecting slower host CPUs
  • Loading branch information
PatrickvL committed Mar 20, 2019
2 parents b31f412 + d370c89 commit 528ec0c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/kernel/exports/EmuKrnlKi.cpp
Expand Up @@ -135,6 +135,7 @@ xboxkrnl::VOID xboxkrnl::KiClockIsr(
LARGE_INTEGER InterruptTime;
LARGE_INTEGER HostSystemTime;
ULONG Hand;
DWORD OldKeTickCount;

OldIrql = KfRaiseIrql(CLOCK_LEVEL);

Expand All @@ -156,6 +157,7 @@ xboxkrnl::VOID xboxkrnl::KiClockIsr(
KeSystemTime.High1Time = HostSystemTime.u.HighPart;

// Update the tick counter
OldKeTickCount = KeTickCount;
KeTickCount += ScalingFactor;

// Because this function must be fast to continuously update the kernel clocks, if somebody else is currently
Expand All @@ -166,7 +168,7 @@ xboxkrnl::VOID xboxkrnl::KiClockIsr(
Hand = KeTickCount & (TIMER_TABLE_SIZE - 1);
if (KiTimerTableListHead[Hand].Entry.Flink != &KiTimerTableListHead[Hand].Entry &&
(ULONGLONG)InterruptTime.QuadPart >= KiTimerTableListHead[Hand].Time.QuadPart) {
KeInsertQueueDpc(&KiTimerExpireDpc, (PVOID)&KeTickCount, 0);
KeInsertQueueDpc(&KiTimerExpireDpc, (PVOID)OldKeTickCount, 0);
}
KiTimerMtx.Acquired = false;
KiTimerMtx.Mtx.unlock();
Expand Down

0 comments on commit 528ec0c

Please sign in to comment.