* 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`.
41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
use crate::wasm_config_t;
|
|
use wasmtime::Engine;
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone)]
|
|
pub struct wasm_engine_t {
|
|
pub(crate) engine: Engine,
|
|
}
|
|
|
|
wasmtime_c_api_macros::declare_own!(wasm_engine_t);
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
|
// Enable the `env_logger` crate since this is as good a place as any to
|
|
// support some "top level initialization" for the C API. Almost all support
|
|
// should go through this one way or another, so this ensures that
|
|
// `RUST_LOG` should work reasonably well.
|
|
//
|
|
// Note that we `drop` the result here since this fails after the first
|
|
// initialization attempt. We don't mind that though because this function
|
|
// can be called multiple times, so we just ignore the result.
|
|
drop(env_logger::try_init());
|
|
|
|
Box::new(wasm_engine_t {
|
|
engine: Engine::default(),
|
|
})
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn wasm_engine_new_with_config(c: Box<wasm_config_t>) -> Box<wasm_engine_t> {
|
|
let config = c.config;
|
|
Box::new(wasm_engine_t {
|
|
engine: Engine::new(&config).unwrap(),
|
|
})
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn wasmtime_engine_increment_epoch(engine: &wasm_engine_t) {
|
|
engine.engine.increment_epoch();
|
|
}
|