@@ -97,17 +97,30 @@ CoreStall (
//
Counter = DivU64x32Remainder (
MultU64x32 (Microseconds, 10),
gMetronome->TickPeriod,
&Remainder
);
if (Remainder != 0) {
//
// If Remainder is not zero, then round Counter up by one tick.
//
+ // This is safe, because the "worst case" (the largest quotient) emerges
+ // from the following values (largest numerator, smallest denominator):
+ //
+ // Microseconds == 0x1999_9999_9999_9999; therefore
+ // Numerator == 0xFFFF_FFFF_FFFF_FFFA, after multiplying by 0xA.
+ //
+ // Denominator == TickPeriod == 2 (with TickPeriod == 1, Remainder would
+ // be zero); therefore
+ // Quotient == 0x7FFF_FFFF_FFFF_FFFD, after division by 2.
+ //
+ // Hence the maximum pre-increment value of Counter is
+ // 0x7FFF_FFFF_FFFF_FFFD.
+ //
Counter++;
}
CoreInternalWaitForTick (Counter);
}
return EFI_SUCCESS;
}
The non-iterating branch of CoreStall() rounds up the number of ticks if Remainder is nonzero. Explain in a comment why this is safe. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- MdeModulePkg/Core/Dxe/Misc/Stall.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)