Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed epoch_interruption on new wasm instance creation #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/wasmtime/crates/lind-multi-process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;
use std::sync::atomic::{AtomicU32, AtomicU64, Ordering};
use std::sync::{Arc, Barrier};
use std::thread;
use wasmtime::{AsContext, AsContextMut, Caller, ExternType, Linker, Module, SharedMemory, Store, Val, OnCalledAction, RewindingReturn, StoreOpaque, InstanceId};
use wasmtime::{AsContext, AsContextMut, Caller, Engine, ExternType, InstanceId, Linker, Module, OnCalledAction, RewindingReturn, SharedMemory, Store, StoreOpaque, Val};

use wasmtime_environ::MemoryIndex;

Expand Down Expand Up @@ -316,6 +316,7 @@ impl<T: Clone + Send + 'static + std::marker::Sync, U: Clone + Send + 'static +

let lind_manager = child_ctx.lind_manager.clone();
let mut store = Store::new_with_inner(&engine, child_host, store_inner);
store.set_epoch_deadline(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a one line comment here about what this is doing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these comments don't really explain why we would do this or what this is


// if parent is a thread, so does the child
if is_parent_thread {
Expand Down Expand Up @@ -556,6 +557,7 @@ impl<T: Clone + Send + 'static + std::marker::Sync, U: Clone + Send + 'static +
let instance_pre = Arc::new(child_ctx.linker.instantiate_pre(&child_ctx.module).unwrap());

let mut store = Store::new_with_inner(&engine, child_host, store_inner);
store.set_epoch_deadline(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


// mark as thread
store.set_is_thread(true);
Expand Down
4 changes: 4 additions & 0 deletions src/wasmtime/crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ impl Engine {
self.inner.epoch.fetch_add(1, Ordering::Relaxed);
}

pub fn decrement_epoch(&self) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also comment this

self.inner.epoch.fetch_sub(1, Ordering::Relaxed);
}

/// Returns a [`std::hash::Hash`] that can be used to check precompiled WebAssembly compatibility.
///
/// The outputs of [`Engine::precompile_module`] and [`Engine::precompile_component`]
Expand Down
4 changes: 4 additions & 0 deletions src/wasmtime/crates/wasmtime/src/runtime/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,10 @@ impl<T> Store<T> {
self.inner.set_epoch_deadline(ticks_beyond_current);
}

pub fn get_epoch_deadline(&self) -> u64 {
self.inner.get_epoch_deadline()
}

/// Configures epoch-deadline expiration to trap.
///
/// When epoch-interruption-instrumented code is executed on this
Expand Down
4 changes: 3 additions & 1 deletion src/wasmtime/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::sync::atomic::AtomicU64;
use std::sync::{Arc, Mutex};
use std::thread;
use wasi_common::sync::{ambient_authority, Dir, TcpListener, WasiCtxBuilder};
use wasmtime::{AsContextMut, Engine, Func, Module, Store, StoreLimits, Val, ValType};
use wasmtime::{AsContextMut, Engine, Func, Module, Store, StoreLimits, UpdateDeadline, Val, ValType};
use wasmtime_wasi::WasiView;

use wasmtime_lind_utils::LindCageManager;
Expand Down Expand Up @@ -424,6 +424,8 @@ impl RunCommand {
thread::sleep(timeout);
engine.increment_epoch();
});
} else if self.run.common.wasm.epoch_interruption.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good comment

store.set_epoch_deadline(1);
}

Ok(Box::new(|_store| {}))
Expand Down