You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
yield to executor when polling with zero-duration wait (#13085)
* yield to executor when polling with zero-duration wait
This addresses #13040 for `wasmtime-wasi`'s WASIp2 implementation by calling
`tokio::task::yield_now` in `<Deadline as Pollable>::ready` when `self` is a
`Deadline::Past`. Previously, it did nothing, which had the effect of starving
other pollables that rely on yielding control to `mio` in order to progress,
e.g. when the guest polls with a zero timeout in a busy loop.
This also addresses that issue for `wasmtime`'s `thread.yield` implementation by
modifying the `poll_until` event loop in `concurrent.rs` to yield to the
executor prior to executing any low-priority tasks. This works because
`thread.yield` operates by queueing a low-priority task to resume the calling
fiber just prior to suspending it.
Note that, because the `wasmtime` crate does not depend on Tokio, we can't
directly call `tokio::task::yield_now`. Instead, we return a `Future` which,
when polled for the first time, wakes the `Context`'s `Waker` and returns
`Poll::Pending`; then it returns `Poll::Ready(())` for subsequent polls. That's
enough to ensure `mio` has a chance to run when using `tokio`. Once we have a
mechanism to allow the embedder to configure a custom yield function, we'll be
able to use that instead.
Fixes#13040
* remove obsolete assertions from `p2_sleep` test
Now that zero-duration `monotonic_clock` waits yield to the executor, they
aren't ready immediately, so the assertions in this test are no longer
appropriate.
* address review feedback
- Expand comments regarding why we yield to the runtime in `wasmtime` and `wasmtime-wasi`
- Move `yield_to_executor` to `StoreOpaque::yield_now` and remove `vm/async_yield` in favor of the new function
- Revert `take_low_priority` performance tweak (will open a separate PR for that)
- Inline `collect_work_itmes_to_run` for clarity
0 commit comments