Bug 198139 - timer2sbintime() Loss of precision during conversion
Summary: timer2sbintime() Loss of precision during conversion
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-01 19:37 UTC by Justin T. Gibbs
Modified: 2019-01-21 10:03 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin T. Gibbs freebsd_committer freebsd_triage 2015-03-01 19:37:08 UTC
The conversion error in timer2sbintime() is very high, almost 7% for timers using NOTE_NSECONDS.  A nanosecond takes 4.294967296 "sbintimes", but the conversion truncates this to 4 through its multiplication by the constant SBT_1NS.  Similar, but much smaller, error is introduced for the NOTE_USECONDS and NOTE_MSECONDS conversions.
Comment 1 commit-hook freebsd_committer freebsd_triage 2016-03-12 23:03:31 UTC
A commit references this bug:

Author: gibbs
Date: Sat Mar 12 23:02:53 UTC 2016
New revision: 296775
URL: https://svnweb.freebsd.org/changeset/base/296775

Log:
  Provide high precision conversion from ns,us,ms -> sbintime in kevent

  In timer2sbintime(), calculate the second and fractional second portions of
  the sbintime separately. When calculating the the fractional second portion,
  use a 64bit multiply to prevent excess truncation. This avoids the ~7% error
  in the original conversion for ns, and smaller errors of the same type for us
  and ms.

  PR: 198139
  Reviewed by: jhb
  MFC after: 1 week
  Differential Revision:    https://reviews.freebsd.org/D5397

Changes:
  head/sys/kern/kern_event.c
Comment 2 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-21 10:03:50 UTC
There is a commit referencing this PR, but it's still not closed and has been inactive for some time. Closing the PR as fixed but feel free to re-open it if the issue hasn't been completely resolved.

Thanks