-
Notifications
You must be signed in to change notification settings - Fork 411
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
Add support for absolute timeouts to io_uring_getevents_arg-based io_uring_enter calls #1162
Comments
That's a bad option
right, it's relative
I can take a look, it's easy to add a flag telling whether it's relative or not
This one might be more complicated to fit in. Maybe it should be a ring global option set separately via the io_uring register syscall, i.e. if you request the waiting syscall timeout's to be in abs mode, than we'll use that registered beforehand value to decide what clock mode it should use. I can't imagine that an app would be switching b/w abs modes at runtime. |
Actually, after re reading your use case I take it back, that's what OP_TIMEOUT is there for. You also have multishot timeouts if that works with you, you queue just one request and it'll produce a CQE each time the required interval passes. The wait argument might be faster though in some cases, so the question is what the performance looks like in your app comparing two options (while simulating abs through relative modes)? |
If I queue an OP_TIMEOUT with a
A multishot timeout doesn't work for my use-case. I have a whole bunch of single-shot tasks that need to be executed at specific times. I compute the earliest such time and when I don't have anything else to do I want to wait for events until that time arrives. Once the task(s) scheduled for that time have been executed I look at the next earliest time in the queue and, when idle, I want to wait for events until that next earliest time arrives. The times are not necessarily periodic.
I'll try to get some measurements for you. |
Please don't, With that said, I don't see what you want to achieve by using it. IIRC there was a hack breaking the waiting loop if there is at least one timeout completed regardless of the nr you pass to waiting, but I need to double check and it's probably unreliable. |
One case I have in mind is where I currently have an earliest scheduled time that is, say, 5s in the future (T+5) and I don't have anything else to do until either an I/O completes or that time 5s in the future arrives, so I am blocked in io_uring_enter() waiting for at least one CQE. Then I/O completion-event arrives, say at T+0.5, and But since the So this ends up needing two The goal of setting the I only just noticed that Regardless, I think having the ability to pass an absolute time into |
For an example of some of the challenges using OP_TIMEOUT, see #1164 |
That's an interesting use case, but still please avoid using that count feature. Unfortunately, it's racy, and the timeout might get stuck.
Not sure how
Fair enough, I'll take a look |
The idea was to apply the As you say, it would still post a CQE in the case that the update failed, but in this case you probably wanted to wake up due to the timer elapsing anyway. |
Merged, should be in 6.12 when it comes out |
I have been working on implementing an io_uring-based execution context with support for timers where I manage a priority-queue of user-provided timers and compute the earliest due time at which I have work scheduled to run.
Ideally, I would like to be able to call
io_uring_enter2()
and have that block until either I have a completion-event to process or the earliest due time has elapsed.Currently, the
io_uring_getevents_arg
structure seems to require passing a relative time.While the documentation does not specify whether the time is relative or not, looking at the implementation, the
io_cqring_wait()
function seems to be adding the current kernel time to the value passed.While I can convert the absolute time I have to a relative time by calling
clock_gettime()
just before callingio_uring_enter2()
, this approach has a couple of limitations.clock_gettime()
andio_uring_enter2()
then the computed relative timeout can be an over-estimate and can result in additional delay to theio_uring_enter2()
call returning.Would it be possible to add support for passing an absolute timeout time to the
io_uring_enter2()
syscall or to theio_uring_wait_cqe_timeout()
orio_uring_submit_and_wait_timeout()
functions?Ideally, with the ability to specify which clock to use (e.g.
CLOCK_BOOTTIME
orCLOCK_MONOTONIC
).Or am I better off trying to use the
IORING_OP_TIMEOUT
op-code for this use-case?The text was updated successfully, but these errors were encountered: