Skip to content

Conversation

bikallem
Copy link
Contributor

@bikallem bikallem commented Jul 5, 2022

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 bikallem requested a review from talex5 July 5, 2022 09:56
Copy link
Collaborator

@talex5 talex5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to add a type parameter to clocks to say what kind of time they return. That would allow having e.g. sys_clock : Ptime.t Clock.t and mono_clock : Mtime.t Clock.t.

@bikallem
Copy link
Contributor Author

@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
Copy link
Contributor Author

bikallem commented Sep 6, 2022

Closing this in support of #308

@bikallem bikallem closed this Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants