-
Notifications
You must be signed in to change notification settings - Fork 393
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
Consider CLOCK_BOOTTIME (monotonic, but accurate over suspend) over CLOCK_MONOTONIC #369
Comments
Hmm this is an interesting situation. If you have a countdown and you suspend your system, you would want to resume the countdown right? vs just going boom when you unsuspend! :D Wouldn't it make more sense to add this databases tracking outside of suspending vm? |
Yes, but again, it all depends on the application context. Some applications might want a timeout N hours into the future, and might want this to reflect the passing of actual time, not just non-suspend time. Others might not. It depends. The argument cuts both ways. The kernel was actually going to switch the behavior of |
It would be nice if you can set your own flags, Like there is a It would be nice if you could pass It could also be that @axboe had already planned for this and just forgot to mention/implement it |
@YoSTEALTH that would be perfect. |
Tags @axboe |
I think we should just change it, should be identical apart from the suspend aspect (which is important). |
What I'm saying is that my initial reaction was to make it selectable, but is there really any point in that? Should just use CLOCK_BOOTTIME. |
Well, I guess there is risk in that... Something like this should work, just set IORING_TIMEOUT_BOOTTIME in the timeout_flags. I would prefer just making it the default, but I can see valid use cases for both - eg a request that wants monotonic behavior across suspend, vs a request that has a hard timeout and should just be failed immediately on resume if too much time has passed.
|
Could you not make it so developers can pass their own |
The only way to do that would be to set aside some timeout flags to do just that. Which is indeed possible, we currently have ~12 clock sources, which would mean 4 bits in the flags. It's a bit ugly though, but would be more flexible. |
Giving user that flexibility and not breaking current timeout is a +1 |
The proposed patch doesn't risk any breakage, but it does only allow choosing monotonic or boottime. My worry here is the interface, then you'll have to do things like:
and some flags might conflict with the clock source, and the clock source would have to be validated as well. I'm just worried it's too much flexibility or over-designing it, when monotonic/boottime might be the only truly useful cases because a lot of the other sources don't really make sense for this use case. realtime might be an exception, not sure. |
Wait, I actually use the realtime/CLOCK_REALTIME/ ok then, how about realtime, monotonic, boottime for now then add other feature as users request it? It would also be nice to get another person or two's point of view. |
Since I think REALTIME is the only other sane option, it actually ends up not being too bad as we can just keep them as bits. Here's an updated version: https://lore.kernel.org/io-uring/0e110ae2-f744-df44-e017-bf603f481348@kernel.dk/ |
I might be wrong here but don't you already have relative / |
Relative is independent of clocksource, it can be set or not for either clocksource. Don't confuse the bit values in the timeout mask with the absolute clock source values, that's why io_timeout_get_clock() translates them. The posted patch will break nothing, the default behavior is the same as before. If you set nothing, then monotonic is used. If you set _ABS, then absolute values is used for monotonic. |
True, was confusing Thank for the patch and clarification :) |
Certain use cases want to use CLOCK_BOOTTIME or CLOCK_REALTIME rather than CLOCK_MONOTONIC, instead of the default CLOCK_MONOTONIC. Add an IORING_TIMEOUT_BOOTTIME and IORING_TIMEOUT_REALTIME flag that allows timeouts and linked timeouts to use the selected clock source. Only one clock source may be selected, and we -EINVAL the request if more than one is given. If neither BOOTIME nor REALTIME are selected, the previous default of MONOTONIC is used. Link: axboe/liburing#369 Signed-off-by: Jens Axboe <axboe@kernel.dk>
Thanks @axboe and @YoSTEALTH, awesome to see this. |
Certain use cases want to use CLOCK_BOOTTIME or CLOCK_REALTIME rather than CLOCK_MONOTONIC, instead of the default CLOCK_MONOTONIC. Add an IORING_TIMEOUT_BOOTTIME and IORING_TIMEOUT_REALTIME flag that allows timeouts and linked timeouts to use the selected clock source. Only one clock source may be selected, and we -EINVAL the request if more than one is given. If neither BOOTIME nor REALTIME are selected, the previous default of MONOTONIC is used. Link: axboe/liburing#369 Signed-off-by: Jens Axboe <axboe@kernel.dk>
@axboe close, thanks. |
I understand that io_uring currently uses
CLOCK_MONOTONIC
internally for measuring elapsed time for the purpose of timeouts.This is mostly fine, but where timeouts are long-lived, e.g. an hour or two, and where the system or VM is suspended, then io_uring will measure these timeout intervals incorrectly, because
CLOCK_MONOTONIC
excludes the elapsed time during the suspend.CLOCK_BOOTTIME
might be a better choice because it's the higher resolution, more resilient interface of the two. For example, any system that needs to measure monotonic time intervals that also correspond to actual time passing across systems, such as a distributed databases tracking leader leases, would probably want to useCLOCK_BOOTTIME
when submitting timeouts to io_uring.The text was updated successfully, but these errors were encountered: