Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using boottime crate for timers and timeouts? #2

Open
link2xt opened this issue Dec 23, 2023 · 3 comments
Open

Using boottime crate for timers and timeouts? #2

link2xt opened this issue Dec 23, 2023 · 3 comments

Comments

@link2xt
Copy link

link2xt commented Dec 23, 2023

This crate allows to measure time, but can it be used as a replacement for std clocks to create timers?
E.g. as suggested in tokio-rs/tokio#3185

I think it is not possible, but would be nice to get a confirmation. To close the issue I suggest writing this in the README so potential users know whether this crate solves their problem or not.

@DXist
Copy link
Owner

DXist commented Dec 24, 2023

@link2txt, the interface is the same as std::time::Instant so client code could use it as a replacement to implement suspend-aware timers in best effort manner.

I've decided to create this crate to support boot time in the completion-style IO driver.

But it's used only for Windows (IOCP) and BSD-like targets (kqueue). Linux implementation (io_uring) sets the native CLOCK_BOOTTIME flag for Timeout op and relies on kernel-side high resolution timers.

To answer the question whether this crate solves potential users problem - it depends on the used OS primitives.

For Linux and io_uring there is no problem at all. For other platforms this crate could be used as a fallback.

@Tokarak
Copy link

Tokarak commented Jan 16, 2024

Is there a way for this crate to be "dropped in" into Tokio's sleep function (as well as other functions) without forking Tokio?
I tried to pass this crate's implementation of Duration to Tokio, but that didn't work.
Note: here is my code redlib-org/redlib#23

@DXist
Copy link
Owner

DXist commented Jan 17, 2024

Support of suspend-aware timers depends not on this crate but on used system interfaces. Tokio uses Mio as IO backend. Mio doesn't use IOCP on Windows nor Timeout operation on Linux+io_uring.

As I mentioned earlier this crate is not needed on Linux/io_uring when kernel side timers are used. I've used this crate in application-side timer wheel for IOCP/kqueue backends.

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

No branches or pull requests

3 participants