Consider this sequence of function calls in package runtime:
- timerproc() calculates now := nanotime(), runs any expired timer callbacks, calculates delta := t.when - now for the earliest unexpired timer, and then calls notetsleepg(..., delta)
- notetsleepg() (actually notetsleep_internal()) calculates deadline = nanotime() + ns, then each iteration calls semasleep(ns) or futexsleep(..., ns) and then re-calculates ns = deadline - nanotime()
- semasleep() on {openbsd,netbsd} needs to compute again deadline = nanotime() + ns and call the low-level sleep syscall with deadline, though other OSes seem to natively use the relative timeout ns directly
It seems like all OSes are potentially affected by a bit of deadline drift (e.g., if running timer callbacks takes a non-trivial amount of time), and on openbsd and netbsd in particular most of the nanotime() calls are unnecessary.
Would it make sense to convert this chain of calls to use absolute deadlines throughout, and push the responsibility for calculating deadline - nanotime() (on OSes that need a relative timeout) down into {futex,sema}sleep() where it can also minimize deadline drift? If so, is that a change that's still appropriate for 1.4, or should I file an issue and wait for the next release cycle?