This PR introduces a new way of performing cooperative timeslicing that is intended to replace the "fuel" mechanism. The tradeoff is that this mechanism interrupts with less precision: not at deterministic points where fuel runs out, but rather when the Engine enters a new epoch. The generated code instrumentation is substantially faster, however, because it does not need to do as much work as when tracking fuel; it only loads the global "epoch counter" and does a compare-and-branch at backedges and function prologues. This change has been measured as ~twice as fast as fuel-based timeslicing for some workloads, especially control-flow-intensive workloads such as the SpiderMonkey JS interpreter on Wasm/WASI. The intended interface is that the embedder of the `Engine` performs an `engine.increment_epoch()` call periodically, e.g. once per millisecond. An async invocation of a Wasm guest on a `Store` can specify a number of epoch-ticks that are allowed before an async yield back to the executor's event loop. (The initial amount and automatic "refills" are configured on the `Store`, just as for fuel.) This call does only signal-safe work (it increments an `AtomicU64`) so could be invoked from a periodic signal, or from a thread that wakes up once per period.
61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
mod async_functions;
|
|
mod call_hook;
|
|
mod cli_tests;
|
|
mod custom_signal_handler;
|
|
mod debug;
|
|
mod epoch_interruption;
|
|
mod externals;
|
|
mod fuel;
|
|
mod func;
|
|
mod funcref;
|
|
mod gc;
|
|
mod globals;
|
|
mod host_funcs;
|
|
mod iloop;
|
|
mod import_calling_export;
|
|
mod import_indexes;
|
|
mod instance;
|
|
mod invoke_func_via_table;
|
|
mod limits;
|
|
mod linker;
|
|
mod memory;
|
|
mod memory_creator;
|
|
mod module;
|
|
mod module_linking;
|
|
mod module_serialize;
|
|
mod name;
|
|
mod pooling_allocator;
|
|
mod relocs;
|
|
mod stack_overflow;
|
|
mod store;
|
|
mod table;
|
|
mod traps;
|
|
mod wast;
|
|
|
|
/// A helper to compile a module in a new store with reference types enabled.
|
|
pub(crate) fn ref_types_module(
|
|
source: &str,
|
|
) -> anyhow::Result<(wasmtime::Store<()>, wasmtime::Module)> {
|
|
use wasmtime::*;
|
|
|
|
let _ = env_logger::try_init();
|
|
|
|
let mut config = Config::new();
|
|
config.wasm_reference_types(true);
|
|
|
|
let engine = Engine::new(&config)?;
|
|
let store = Store::new(&engine, ());
|
|
|
|
let module = Module::new(&engine, source)?;
|
|
|
|
Ok((store, module))
|
|
}
|
|
|
|
/// A helper determining whether the pooling allocator tests should be skipped.
|
|
pub(crate) fn skip_pooling_allocator_tests() -> bool {
|
|
// There are a couple of issues when running the pooling allocator tests under QEMU:
|
|
// - high memory usage that may exceed the limits imposed by the environment (e.g. CI)
|
|
// - https://github.com/bytecodealliance/wasmtime/pull/2518#issuecomment-747280133
|
|
std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok()
|
|
}
|