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 <[email protected]> --- MdeModulePkg/Core/Dxe/Misc/Stall.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Misc/Stall.c b/MdeModulePkg/Core/Dxe/Misc/Stall.c index 73e9078..aae54fd 100644 --- a/MdeModulePkg/Core/Dxe/Misc/Stall.c +++ b/MdeModulePkg/Core/Dxe/Misc/Stall.c @@ -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; } -- 1.8.3.1 ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
