]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Finish the fix for overflow in calcru1().
authorbde <bde@FreeBSD.org>
Thu, 14 Feb 2019 19:07:08 +0000 (19:07 +0000)
committerbde <bde@FreeBSD.org>
Thu, 14 Feb 2019 19:07:08 +0000 (19:07 +0000)
commit24c8af8da848430c7c7b0c7cfdcb8b128b74bba2
treeaee219c0f3c504f1dbd8fbe4a683d2d83c262db5
parente437b09b0885ead5351cf73e289d1a6d11d43a64
Finish the fix for overflow in calcru1().

The previous fix was unnecessarily very slow up to 105 hours where the
simple formula used previously worked, and unnecessarily slow by a factor
of about 5/3 up to 388 days, and didn't work above 388 days.  388 days is
not a long time, since it is a reasonable uptime, and for processes the
times being calculated are aggregated over all threads, so with N CPUs
running the same thread a runtime of 388 days is reachable after only
388 / N physical days.

The PRs document overflow at 388 days, but don't try to fix it.

Use the simple formula up to 76 hours.  Then use a complicated general
method that reduces to the simple formula up to a bit less than 105
hours, then reduces to the previous method without its extra work up
to almost 388 days, then does more complicated reductions, usually
many bits at a time so that this is not slow.  This works up to half
of maximum representable time (292271 years), with accumulated rounding
errors of at most 32 usec.

amd64 can do all this with no avoidable rounding errors in an inline
asm with 2 instructions, but this is too special to use.  __uint128_t
can do the same with 100's of instructions on 64-bit arches.  Long
doubles with at least 64 bits of precision are the easiest method to
use on i386 userland, but are hard to use in the kernel.

PR: 76972 and duplicates
Reviewed by: kib
sys/kern/kern_resource.c