twizzler-operating-system / twizzler

The Twizzler Operating System
BSD 3-Clause "New" or "Revised" License
68 stars 15 forks source link

Port smol (async runtime) #175

Closed dbittman closed 5 months ago

dbittman commented 5 months ago

This PR implements the necessary interfaces for smol, an async runtime, and fixes a number of bugs.

smol is an async runtime, designed to be "small and fast". By porting smol, we can rely on it to implement the complexity of an async runtime, and not on twizzler's existing, bespoke one. This will save a huge amount of technical debt and maintenance effort.

The interesting part of the smol port lies in two crates that I needed to modify to support Twizzler: async-io, and polling. Polling implements the OS-specific interface for causing a thread to wait on a number of events. For unix, this is implemented via file descriptors (things that can be waited on) and epoll (or poll). On Twizzler, the "things that can be waited on" are implementers of twizzler-futures::TwizzlerWaitable. These return ThreadSync instructions that can be passed to sys_thread_sync. The async-io crate interfaces with the polling crate to provide abstracted ways of performing async IO.

In the repo's root Cargo.toml, we have a [patch] section that allows us to replace references to smol crates on crates.io with our ported versions. Since the crate 'smol' is just a wrapper around these other crates (async-io, polling, etc), it requires no modification for Twizzler, and will pick up our ported versions automatically.

The following bugs are fixed:

  1. x86_64 interrupt handlers had a chance of corrupting the stack, causing (rare) crashes.
  2. On return from sys_thread_sync, the kernel now removes pending timeouts for the calling thread. This fixes a bug where a thread could be enqueued twice, and is the correct behavior anyway.
  3. 42