Page MenuHomeFreeBSD

time: use precise callout for clock_nanosleep(2) and nanosleep(2)
AcceptedPublic

Authored by glebius on Tue, Apr 29, 4:53 PM.

Details

Summary

Don't apply tc_precexp (a derivative of kern.timecounter.alloweddeviation)
to sleep callout when processing the default and precise clocks. The
default timer deviation of 5% is our internal optimization in the kernel,
and we shouldn't leak that into the POSIX APIs. Note that application
doesn't have any control to cancel the deviation, only a superuser can
change the global tunable [with side effects].

Leave the deviation for CLOCK_*_FAST and CLOCK_SECOND that are documented
as imprecise.

Note: although this change cancels the gargantuan 5% deviation, some sleep
precision tests would still provide better results on a system with
kern.timecounter.alloweddeviation=0. This could be explained by other
events aggregated into buckets of our precise events, producing some
effect.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 63789
Build 60673: arc lint + arc unit

Event Timeline

This looks good to me.

sys/kern/kern_time.c
523

need a fallthrough marking?

538

here too?

This revision is now accepted and ready to land.Tue, Apr 29, 5:01 PM

I would add a knob to allow user to restore current behavior. Might be, *_PRECISE must be always precise indeed, and CLOCK_REALTIME/MONOTONIC/UPTIME managed by this knob.

Also eliminate TIMESEL() for precise APIs. Now that becomes truly precise.

From mav@.

This revision now requires review to proceed.Tue, Apr 29, 5:52 PM
  • Initialize sbt properly (fixup of last update).
  • Add sysctl to switch to the old behavior.
  • Improve documentation.
This revision is now accepted and ready to land.Tue, Apr 29, 8:23 PM
ziaee requested changes to this revision.Tue, Apr 29, 8:51 PM

Apropos is showing me all the clocks throughout the manual are unmarked or Dvs (including other places on this page), so we should keep them together I think.

lib/libsys/nanosleep.2
105

It should probably be another commit, and I'm happy to do it if you want, but these are Dvs.

129
131
137
140
142
148
247

These need to be on their own lines to register correctly. But they aren't Va, in the rest of the manual they're Dv. You can check with apropos Va=CLOCK_MONOTONIC and try different mdoc macros.

This revision now requires changes to proceed.Tue, Apr 29, 8:51 PM

Use .Dv for clocks in the manual page.

lib/libsys/nanosleep.2
140

This still registers as a single defined variable in the whatis database called "CLOCK_MONTONIC, CLOCK_REALTIME". Nit, oxford comma

One more place where to values were on same line.

Accept as manpages, sorry for the nits.

This revision is now accepted and ready to land.Tue, Apr 29, 10:11 PM