Bug 198139 - timer2sbintime() Loss of precision during conversion
Summary: timer2sbintime() Loss of precision during conversion
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs mailing list
Depends on:
Reported: 2015-03-01 19:37 UTC by Justin T. Gibbs
Modified: 2016-03-12 23:03 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Justin T. Gibbs freebsd_committer 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 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

  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