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:
@@ -24,14 +24,6 @@ pub struct Tunables {
|
||||
/// Whether or not to retain DWARF sections in compiled modules.
|
||||
pub parse_wasm_debuginfo: bool,
|
||||
|
||||
/// Whether or not to enable the ability to interrupt wasm code dynamically.
|
||||
///
|
||||
/// More info can be found about the implementation in
|
||||
/// crates/environ/src/cranelift.rs. Note that you can't interrupt host
|
||||
/// calls and interrupts are implemented through the `VMInterrupts`
|
||||
/// structure, or `InterruptHandle` in the `wasmtime` crate.
|
||||
pub interruptable: bool,
|
||||
|
||||
/// Whether or not fuel is enabled for generated code, meaning that fuel
|
||||
/// will be consumed every time a wasm instruction is executed.
|
||||
pub consume_fuel: bool,
|
||||
@@ -89,7 +81,6 @@ impl Default for Tunables {
|
||||
|
||||
generate_native_debuginfo: false,
|
||||
parse_wasm_debuginfo: true,
|
||||
interruptable: false,
|
||||
consume_fuel: false,
|
||||
epoch_interruption: false,
|
||||
static_memory_bound_is_maximum: false,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Currently the `VMContext` allocation by field looks like this:
|
||||
//
|
||||
// struct VMContext {
|
||||
// interrupts: *const VMInterrupts,
|
||||
// runtime_limits: *const VMRuntimeLimits,
|
||||
// externref_activations_table: *mut VMExternRefActivationsTable,
|
||||
// store: *mut dyn Store,
|
||||
// builtins: *mut VMBuiltinFunctionsArray,
|
||||
@@ -74,7 +74,7 @@ pub struct VMOffsets<P> {
|
||||
pub num_escaped_funcs: u32,
|
||||
|
||||
// precalculated offsets of various member fields
|
||||
interrupts: u32,
|
||||
runtime_limits: u32,
|
||||
epoch_ptr: u32,
|
||||
externref_activations_table: u32,
|
||||
store: u32,
|
||||
@@ -221,7 +221,7 @@ impl<P: PtrSize> VMOffsets<P> {
|
||||
store: "jit store state",
|
||||
externref_activations_table: "jit host externref state",
|
||||
epoch_ptr: "jit current epoch state",
|
||||
interrupts: "jit interrupt state",
|
||||
runtime_limits: "jit runtime limits state",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,7 @@ impl<P: PtrSize> From<VMOffsetsFields<P>> for VMOffsets<P> {
|
||||
num_defined_memories: fields.num_defined_memories,
|
||||
num_defined_globals: fields.num_defined_globals,
|
||||
num_escaped_funcs: fields.num_escaped_funcs,
|
||||
interrupts: 0,
|
||||
runtime_limits: 0,
|
||||
epoch_ptr: 0,
|
||||
externref_activations_table: 0,
|
||||
store: 0,
|
||||
@@ -286,7 +286,7 @@ impl<P: PtrSize> From<VMOffsetsFields<P>> for VMOffsets<P> {
|
||||
}
|
||||
|
||||
fields! {
|
||||
size(interrupts) = ret.ptr.size(),
|
||||
size(runtime_limits) = ret.ptr.size(),
|
||||
size(epoch_ptr) = ret.ptr.size(),
|
||||
size(externref_activations_table) = ret.ptr.size(),
|
||||
size(store) = ret.ptr.size() * 2,
|
||||
@@ -483,23 +483,23 @@ impl<P: PtrSize> VMOffsets<P> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Offsets for `VMInterrupts`.
|
||||
/// Offsets for `VMRuntimeLimits`.
|
||||
impl<P: PtrSize> VMOffsets<P> {
|
||||
/// Return the offset of the `stack_limit` field of `VMInterrupts`
|
||||
/// Return the offset of the `stack_limit` field of `VMRuntimeLimits`
|
||||
#[inline]
|
||||
pub fn vminterrupts_stack_limit(&self) -> u8 {
|
||||
pub fn vmruntime_limits_stack_limit(&self) -> u8 {
|
||||
0
|
||||
}
|
||||
|
||||
/// Return the offset of the `fuel_consumed` field of `VMInterrupts`
|
||||
/// Return the offset of the `fuel_consumed` field of `VMRuntimeLimits`
|
||||
#[inline]
|
||||
pub fn vminterrupts_fuel_consumed(&self) -> u8 {
|
||||
pub fn vmruntime_limits_fuel_consumed(&self) -> u8 {
|
||||
self.pointer_size()
|
||||
}
|
||||
|
||||
/// Return the offset of the `epoch_deadline` field of `VMInterrupts`
|
||||
/// Return the offset of the `epoch_deadline` field of `VMRuntimeLimits`
|
||||
#[inline]
|
||||
pub fn vminterupts_epoch_deadline(&self) -> u8 {
|
||||
pub fn vmruntime_limits_epoch_deadline(&self) -> u8 {
|
||||
self.pointer_size() + 8 // `stack_limit` is a pointer; `fuel_consumed` is an `i64`
|
||||
}
|
||||
}
|
||||
@@ -535,10 +535,10 @@ impl<P: PtrSize> VMOffsets<P> {
|
||||
|
||||
/// Offsets for `VMContext`.
|
||||
impl<P: PtrSize> VMOffsets<P> {
|
||||
/// Return the offset to the `VMInterrupts` structure
|
||||
/// Return the offset to the `VMRuntimeLimits` structure
|
||||
#[inline]
|
||||
pub fn vmctx_interrupts(&self) -> u32 {
|
||||
self.interrupts
|
||||
pub fn vmctx_runtime_limits(&self) -> u32 {
|
||||
self.runtime_limits
|
||||
}
|
||||
|
||||
/// Return the offset to the `*const AtomicU64` epoch-counter
|
||||
|
||||
Reference in New Issue
Block a user