Delete historical interruptable support in Wasmtime (#3925)
* Delete historical interruptable support in Wasmtime This commit removes the `Config::interruptable` configuration along with the `InterruptHandle` type from the `wasmtime` crate. The original support for adding interruption to WebAssembly was added pretty early on in the history of Wasmtime when there was no other method to prevent an infinite loop from the host. Nowadays, however, there are alternative methods for interruption such as fuel or epoch-based interruption. One of the major downsides of `Config::interruptable` is that even when it's not enabled it forces an atomic swap to happen when entering WebAssembly code. This technically could be a non-atomic swap if the configuration option isn't enabled but that produces even more branch-y code on entry into WebAssembly which is already something we try to optimize. Calling into WebAssembly is on the order of a dozens of nanoseconds at this time and an atomic swap, even uncontended, can add up to 5ns on some platforms. The main goal of this PR is to remove this atomic swap on entry into WebAssembly. This is done by removing the `Config::interruptable` field entirely, moving all existing consumers to epochs instead which are suitable for the same purposes. This means that the stack overflow check is no longer entangled with the interruption check and perhaps one day we could continue to optimize that further as well. Some consequences of this change are: * Epochs are now the only method of remote-thread interruption. * There are no more Wasmtime traps that produces the `Interrupted` trap code, although we may wish to move future traps to this so I left it in place. * The C API support for interrupt handles was also removed and bindings for epoch methods were added. * Function-entry checks for interruption are a tiny bit less efficient since one check is performed for the stack limit and a second is performed for the epoch as opposed to the `Config::interruptable` style of bundling the stack limit and the interrupt check in one. It's expected though that this is likely to not really be measurable. * The old `VMInterrupts` structure is renamed to `VMRuntimeLimits`.
This commit is contained in:
@@ -107,9 +107,6 @@ pub enum Timeout {
|
||||
/// No timeout is used, it should be guaranteed via some other means that
|
||||
/// the input does not infinite loop.
|
||||
None,
|
||||
/// A time-based timeout is used with a sleeping thread sending a signal
|
||||
/// after the specified duration.
|
||||
Time(Duration),
|
||||
/// Fuel-based timeouts are used where the specified fuel is all that the
|
||||
/// provided wasm module is allowed to consume.
|
||||
Fuel(u64),
|
||||
@@ -143,12 +140,6 @@ pub fn instantiate(wasm: &[u8], known_valid: bool, config: &generators::Config,
|
||||
// This prevents us from creating a huge number of sleeping threads if
|
||||
// this function is executed in a loop, like it does on nightly fuzzing
|
||||
// infrastructure.
|
||||
Timeout::Time(timeout) => {
|
||||
let handle = store.interrupt_handle().unwrap();
|
||||
timeout_state.spawn_timeout(timeout, move || handle.interrupt());
|
||||
}
|
||||
// Similar to above, but we bump the epoch rather than set the
|
||||
// interrupt flag.
|
||||
Timeout::Epoch(timeout) => {
|
||||
let engine = store.engine().clone();
|
||||
timeout_state.spawn_timeout(timeout, move || engine.increment_epoch());
|
||||
|
||||
Reference in New Issue
Block a user