Skip to content

Conversation

@teskje
Copy link
Contributor

@teskje teskje commented Nov 1, 2025

The tokio runtime builder provides rng_seed as a way to make "certain parts" of the runtime deterministic. We can use it to make turmoil simulations more deterministic. Turmoil already allows specifying a custom seeded world rng through Builder::build_with_rng. We just have to make sure that rng is used to seed the tokio runtime.

I've taken the approach of introducing a new rt::Config struct, to avoid having to juggle two config arguments (enable_io and rng) in multiple places. Though the juggling wouldn't be too bad either, so happy to drop the rt::Config struct if that's preferred.

Caveats

  • tokio::runtime::Builder::rng_seed is only available under the tokio_unstable config. Nothing we can do about that.
  • The implementation skips manually seeding tokio in the Rt::no_software constructor. I think for now that's fine since no-software runtimes are only used for timekeeping currently. Once we start using it for more, we'll need to reconsider.

In preparation for making tokio's rng seed configurable, introduce a new
`rt::Config` struct that holds configuration for creating tokio
runtimes and pass that around instead of the bare `enable_io` bool.
@teskje teskje marked this pull request as ready for review November 1, 2025 11:10
If the `tokio_unstable` flag is set, seed host and client runtimes using
the world rng. This makes the simulation more deterministic. In
particular, the order in which tokio polls `select!` branches is
determined by this seed.
@mcches mcches merged commit d048f20 into tokio-rs:main Nov 3, 2025
5 checks passed
@teskje teskje deleted the tokio-rng-seed branch November 4, 2025 09:09
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

Successfully merging this pull request may close these issues.

2 participants