eio icon indicating copy to clipboard operation
eio copied to clipboard

Nanoseconds precision clocks : system and mono

Open bikallem opened this issue 2 years ago • 1 comments

This PR add two nanoseconds precision clocks to eio.

  1. system_clock () - A system, real-time wall clock. It gives time relative to unix epoch time.
  2. mono_clock () - A monotonic clock that increments continuously - including during system sleep and hibernation.

The OSes supported are Linux, MacOS, BSDs and Windows (The CI is for MacOS and Windows will be another PR).

Additionally, sleep_until is now implemented using the given clock(either system or mono) and does not use Unix.gettimeofday.

The PR doesn't change the representation of time from float(fractional seconds) to minimize the diff. However, now that we can do nanoseconds precision, we could perhaps use nanoseconds as the default time measurement for the two clocks and provide a helper function to do nanoseconds to fractional seconds (as used by OCaml stdlib).

At the moment we use int64 to represent nanoseconds. I believe this is unboxed due to using @unboxed attribute in the external declaration. I didn't use Optint.t since int64 is already unboxed.

bikallem avatar Jul 05 '22 09:07 bikallem

@talex5 This PR is ready for next round of reviews. I am working on moving some of the monotonic clock functionality to mtime. However, that will probably be another PR.

bikallem avatar Jul 21 '22 16:07 bikallem

Closing this in support of https://github.com/ocaml-multicore/eio/pull/308

bikallem avatar Sep 06 '22 11:09 bikallem