bench-api: Allow multiple instantiations per compilation

We used to allow at most one instantiation per compilation, but there is no
fundamental reason why that should be the case. Allowing multiple instantiations
per compilation allows us to, for example, benchmark repeated instantiation
within Wasmtime's pooling allocator.

This additionally switches to using host functions for WASI and for
`bench_{start,end}` rather than defining them on the linker, this way we can use
a new store for every instantiation and don't need to keep other instances alive
when instantiating new instances.

Finally, we switch all timing to be done through callback functions, rather than
having the bench API caller implicitly start/end timers around bench API
calls. This allows us to more precisely measure phases and exclude things like
file I/O performed when creating a WASI context.
This commit is contained in:
Nick Fitzgerald
2021-05-24 16:00:15 -07:00
parent ba6635dba0
commit 18fabd7700
2 changed files with 261 additions and 131 deletions

View File

@@ -0,0 +1,19 @@
#[derive(Clone, Copy)]
pub struct UnsafeSendSync<T>(T);
impl<T> UnsafeSendSync<T> {
/// Create a new `UnsafeSendSync` wrapper around the given value.
///
/// The result is a type that is `Send` and `Sync` regardless of whether `T:
/// Send + Sync`, so this constructor is unsafe.
pub unsafe fn new(val: T) -> Self {
UnsafeSendSync(val)
}
pub fn get(&self) -> &T {
&self.0
}
}
unsafe impl<T> Send for UnsafeSendSync<T> {}
unsafe impl<T> Sync for UnsafeSendSync<T> {}