WIP [NTOS:KE/x64] Properly handle KiIdleSummary

TODO: Remove the chunk from KiSystemStartupBootStack? Shouldn't be needed.
What about other instances of KiIdleSummary?
This commit is contained in:
Timo Kreuzer 2023-12-11 17:56:01 +02:00
parent ea711415c4
commit 3b026627e9
2 changed files with 11 additions and 1 deletions

View file

@ -197,7 +197,8 @@ KiSystemStartupBootStack(VOID)
/* If there's no thread scheduled, put this CPU in the Idle summary */
KiAcquirePrcbLock(Prcb);
if (!Prcb->NextThread) KiIdleSummary |= (ULONG_PTR)1 << Prcb->Number;
if (!Prcb->NextThread)
InterlockedBitTestAndSetAffinity(&KiIdleSummary, Prcb->Number);
KiReleasePrcbLock(Prcb);
/* Raise back to HIGH_LEVEL and clear the PRCB for the loader block */

View file

@ -101,6 +101,9 @@ KiIdleLoop(VOID)
PKPRCB Prcb = KeGetCurrentPrcb();
PKTHREAD OldThread, NewThread;
/* Set idle summary bit */
InterlockedBitTestAndSetAffinity(&KiIdleSummary, Prcb->Number);
/* Now loop forever */
while (TRUE)
{
@ -144,9 +147,15 @@ KiIdleLoop(VOID)
KfRaiseIrql(SYNCH_LEVEL);
#endif
/* Clear idle summary bit */
InterlockedBitTestAndResetAffinity(&KiIdleSummary, Prcb->Number);
/* Switch away from the idle thread */
KiSwapContext(APC_LEVEL, OldThread);
/* Set idle summary bit */
InterlockedBitTestAndSetAffinity(&KiIdleSummary, Prcb->Number);
#ifdef CONFIG_SMP
/* Go back to DISPATCH_LEVEL */
KeLowerIrql(DISPATCH_LEVEL);