tokio
tokio copied to clipboard
runtime: add on_task_poll_start hook
This hook will allow users to have a callback run before tasks are polled. Eventually this should be accompanied on_task_poll_stop, and maybe a few other callbacks.
This was implemented in order to allow tokio-uring to run a periodic maintenance loop.
If this is for tokio-uring, then why not a maintenance hook? Then it would run at the same interval as when Tokio runs its IO driver.
I think I agree with Alice; while polling callbacks seem like they could potentially be desirable, if the goal is to add hooks for running occasional maintenance tasks, we should just add a maintenance callback. I can see that being useful for other libraries as well (e.g., QSBR-based data structures I'd like to write...).
@Darksonn @hawkw the original motivation was so that tokio-uring
could occasionally do the equivalent of tokio's periodic epoll_wait(0)
and just submit whatever SQEs it is holding and process any arrived CQEs, but @carllerche and I realized that this could have other uses.
I commented in discord, but the issue w/ a maintenance hook is it won't be called often enough for tokio-uring. Tasks schedule IO ops by pushing events into the submission queue. The kernel is not able to start the I/O task until it gets flushed. There is a balance between flushing too often and not enough. Flushing at the end of each task poll seems like a good balance. Flushing in a maintenance hook would mean that, at worse, I/O events don't start until 64 other tasks poll.
Got it, yeah, thanks for clarifying that. I saw the phrase "periodic maintenance loop" and assumed this was background maintenance work that would run less frequently.
What is the status on this? As far as I can tell, this PR needs to use task IDs and be marked unstable as per the discussion above.
@Darksonn that is correct, I got side-tracked by a bunch of stuff after I made this, and this ended up not quite the correct way of doing what I need to do for tokio-uring. I'll resolve the conflicts later, add the unstable flag, and add in task id support.