]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Ensure that all values of ns, us and ms work for {n,u,m}stosbt
authorWarner Losh <imp@FreeBSD.org>
Tue, 20 Nov 2018 07:11:23 +0000 (07:11 +0000)
committerWarner Losh <imp@FreeBSD.org>
Tue, 20 Nov 2018 07:11:23 +0000 (07:11 +0000)
commit68f57679d66016ba4625f5bf8a99447bbae84fda
treed74f60434f30b4822358b52e866ddc56d77fed6e
parent75772b69f26e22d98a2203c12aaac755fc94a768
Ensure that all values of ns, us and ms work for {n,u,m}stosbt

Integer overflows and wrong constants limited the accuracy of these
functions and created situatiosn where sbttoXs(Xstosbt(Y)) != Y. This
was especailly true in the ns case where we had millions of values
that were wrong.

Instead, used fixed constants because there's no way to say ceil(X)
for integer math. Document what these crazy constants are.

Also, use a shift one fewer left to avoid integer overflow causing
incorrect results, and adjust the equasion accordingly. Document this.

Allow times >= 1s to be well defined for these conversion functions
(at least the Xstosbt). There's too many users in the tree that they
work for >= 1s.

This fixes a failure on boot to program firmware on the mlx4
NIC. There was a msleep(1000) in the code. Prior to my recent rounding
changes, msleep(1000) worked, but msleep(1001) did not because the old
code rounded to just below 2^64 and the new code rounds to just above
it (overflowing, causing the msleep(1000) to really sleep 1ms).

A test program to test all cases will be committed shortly. The test
exaustively tries every value (thanks to bde for the test).

Sponsored by: Netflix, Inc
Differential Revision: https://reviews.freebsd.org/D18051
sys/sys/time.h