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

Added epoll to WASIX #3830

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
0e0dec2
Added asynchronous IO syscalls for WASIX based on generic wakers
john-sharratt Apr 28, 2023
5b10567
Merge branch 'asynchronous-threading-phase2' into asynchronous-io
john-sharratt May 13, 2023
495d8fa
Merge branch 'asynchronous-threading-phase2' into asynchronous-io
john-sharratt May 13, 2023
32a7e5a
Merge branch 'asynchronous-threading-phase2' into asynchronous-io
john-sharratt May 13, 2023
55861a4
No longer supporting 64bit in this version - other things have to be …
john-sharratt May 13, 2023
89bef74
Merge branch 'asynchronous-threading-phase2' into asynchronous-io
john-sharratt May 13, 2023
bb4e518
Merge branch 'asynchronous-threading-phase2' into asynchronous-io
john-sharratt May 16, 2023
e27bbad
Merge branch 'master' into asynchronous-io
john-sharratt May 16, 2023
b0604fa
Merge branch 'master' into asynchronous-io
john-sharratt Jun 17, 2023
815b181
Clearup of the documentation
john-sharratt Jun 17, 2023
f29f50b
Cleanup of some of the logic, looks ready
john-sharratt Jun 17, 2023
b226ea5
Implemented the socket polling methods and fixed the wakers
john-sharratt Jun 20, 2023
ca30bf1
Fix for linting
john-sharratt Jun 20, 2023
5427c5e
Merge branch 'master' into asynchronous-io
john-sharratt Jun 20, 2023
7a54d76
Merge branch 'master' into asynchronous-io
john-sharratt Jun 20, 2023
51f66b6
Fixes for the waker implementation
john-sharratt Jun 20, 2023
97b71ce
Merge branch 'asynchronous-io' of github.com:wasmerio/wasmer into asy…
john-sharratt Jun 20, 2023
8082549
Minor refactoring
john-sharratt Jun 20, 2023
f1d451e
Fixed an issue with runtimes running in runtimes
john-sharratt Jun 20, 2023
cf3a878
Removed the tokio runtime from the Runtime trait - wasm threads now r…
john-sharratt Jun 21, 2023
cc5c83c
Merge branch 'master' into asynchronous-io
john-sharratt Jun 21, 2023
6f30820
Switched to the threading pool
john-sharratt Jun 21, 2023
1f644f8
Removed the shared tokio runtime
john-sharratt Jun 21, 2023
f842403
Added a fix for the reqwest http client
john-sharratt Jun 21, 2023
fd55348
Tokio context is only coniditonally entered thus allowing for reentrance
john-sharratt Jun 21, 2023
f7b91c4
Implemented epoll for asynchronous IO
john-sharratt Jun 23, 2023
fa47c6a
Now passing through the epoll interest events rather than abstracting it
john-sharratt Jun 25, 2023
0d9ec43
Hiding more of the API's for epoll
john-sharratt Jun 25, 2023
59f8acf
Added waker conversion helper
john-sharratt Jun 25, 2023
057e327
Merge branch 'master' into asynchronous-io
john-sharratt Jun 25, 2023
4f4c6fe
Removed extra pending operation
john-sharratt Jun 25, 2023
1884c62
Resolved compilation regression issues
john-sharratt Jun 25, 2023
8e8d4dd
Fixed a regression issue on Stdout runtimes
john-sharratt Jun 25, 2023
6fb884b
Fixed a regression issue on preview1.sock_accept
john-sharratt Jun 25, 2023
4752cc3
Fixed some integration tests
john-sharratt Jun 25, 2023
d0e08a5
Fixed for nonblocking pipes
john-sharratt Jun 25, 2023
c4c3bca
Added more integration tests
john-sharratt Jun 25, 2023
b54275f
Fixed some linting issues
john-sharratt Jun 27, 2023
fab5c7b
Fixes for capi
john-sharratt Jun 27, 2023
a7f4460
Added fixes for the existing poll_oneoff loop
john-sharratt Jun 27, 2023
6f475ec
More linting fixes
john-sharratt Jun 27, 2023
45825d7
Fixed an issue where capi did not have a tokio runtime
john-sharratt Jun 27, 2023
1becbad
New epoll functionality is now backwards compatible with poll_oneoff
john-sharratt Jun 27, 2023
d86ab4b
Merge branch 'master' into asynchronous-io
theduke Jun 27, 2023
53d3819
Merge branch 'master' into asynchronous-io
john-sharratt Jun 28, 2023
4d707c1
Fixes for the integration and unit tests
john-sharratt Jun 28, 2023
f9e7118
Fixed unit tests for virtual-fs
john-sharratt Jun 28, 2023
bf8d2a3
Fix for linting
john-sharratt Jun 28, 2023
3056cdb
Fix for runtime guard scope
john-sharratt Jun 28, 2023
17047da
Fixes for examples
john-sharratt Jun 28, 2023
1e620ef
Fixed a compile issue with serde
john-sharratt Jun 28, 2023
3d1bccd
Fixes for runtimes in JS
john-sharratt Jun 28, 2023
21755f4
Fix for MIO
john-sharratt Jun 28, 2023
c2e2ad7
Added a runtime startup phase
john-sharratt Jun 28, 2023
3cbcb62
Added dependency needed for examples
john-sharratt Jun 28, 2023
2a0c177
Added dependency needed for examples
john-sharratt Jun 28, 2023
68284bd
Added proper tokio initializtion on wasi_wast tests
ptitSeb Jun 28, 2023
87be930
Merge branch 'master' into asynchronous-io
ptitSeb Jun 28, 2023
d05a92b
Initialze tokio runtime for env_var_errors test
ptitSeb Jun 28, 2023
a65a3a3
This should fix the C-API tests, but will not allows some wasix calls…
ptitSeb Jun 28, 2023
bfb7b81
Fixed nodejs build
ptitSeb Jun 28, 2023
d94b096
Better fix for wasi_wast and the C-API
ptitSeb Jun 28, 2023
cd5c7a1
Fixed lint
ptitSeb Jun 28, 2023
9e2cb84
Merge branch 'master' into asynchronous-io
john-sharratt Jun 29, 2023
7305924
Fixed a compile issue on wasi-web
john-sharratt Jun 29, 2023
9db874b
Merge branch 'master' into asynchronous-io
ptitSeb Jun 30, 2023
eab445c
Fixed CAPI, by transfering ownership of tokio runtime to wasi_env fro…
ptitSeb Jun 30, 2023
151b0ab
Fix for the python use case
john-sharratt Jul 2, 2023
1ce7e04
Added a faster path on the epoll wait with timeout path
john-sharratt Jul 2, 2023
71e1591
Fixed an issue where the notifications were not renewed on epoll enab…
john-sharratt Jul 2, 2023
5c6424b
Disabling 1 test temporarily to see if CI is not stuck
ptitSeb Jul 3, 2023
0e0ab9c
Revert last change, it doesn't fix the CI issue
ptitSeb Jul 3, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 61 additions & 27 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use wasmer_wasix::{
module_cache::{CacheError, ModuleHash},
package_loader::PackageLoader,
resolver::{PackageSpecifier, QueryError},
task_manager::VirtualTaskManagerExt,
},
WasiError,
};
Expand Down Expand Up @@ -104,21 +105,22 @@ impl Run {
wasmer_vm::set_stack_size(self.stack_size.unwrap());
}

let _guard = handle.enter();
let (store, _) = self.store.get_store()?;
let runtime = self
.wasi
.prepare_runtime(store.engine().clone(), &self.env, handle)?;
let runtime =
self.wasi
.prepare_runtime(store.engine().clone(), &self.env, handle.clone())?;

// This is a slow operation, so let's temporarily wrap the runtime with
// something that displays progress
let monitoring_runtime = MonitoringRuntime::new(runtime, pb.clone());
let monitoring_runtime = Arc::new(MonitoringRuntime::new(runtime, pb.clone()));
let runtime: Arc<dyn Runtime + Send + Sync> = monitoring_runtime.runtime.clone();
let monitoring_runtime: Arc<dyn Runtime + Send + Sync> = monitoring_runtime;

let target = self.input.resolve_target(&monitoring_runtime, &pb)?;

pb.finish_and_clear();

let runtime: Arc<dyn Runtime + Send + Sync> = Arc::new(monitoring_runtime.runtime);

let result = {
match target {
ExecutableTarget::WebAssembly { module, path } => {
Expand Down Expand Up @@ -166,7 +168,7 @@ impl Run {
.get_command(id)
.with_context(|| format!("Unable to get metadata for the \"{id}\" command"))?;

let uses = self.load_injected_packages(&*runtime)?;
let uses = self.load_injected_packages(&runtime)?;

if WcgiRunner::can_run_command(cmd.metadata())? {
self.run_wcgi(id, pkg, uses, runtime)
Expand All @@ -183,16 +185,25 @@ impl Run {
}

#[tracing::instrument(level = "debug", skip_all)]
fn load_injected_packages(&self, runtime: &dyn Runtime) -> Result<Vec<BinaryPackage>, Error> {
fn load_injected_packages(
&self,
runtime: &Arc<dyn Runtime + Send + Sync>,
) -> Result<Vec<BinaryPackage>, Error> {
let mut dependencies = Vec::new();

for name in &self.wasi.uses {
let specifier = PackageSpecifier::parse(name)
.with_context(|| format!("Unable to parse \"{name}\" as a package specifier"))?;
let pkg = runtime
.task_manager()
.block_on(BinaryPackage::from_registry(&specifier, runtime))
.with_context(|| format!("Unable to load \"{name}\""))?;
let pkg = {
let specifier = specifier.clone();
let inner_runtime = runtime.clone();
runtime
.task_manager()
.spawn_and_block_on(async move {
BinaryPackage::from_registry(&specifier, inner_runtime.as_ref()).await
})
.with_context(|| format!("Unable to load \"{name}\""))?
};
dependencies.push(pkg);
}

Expand Down Expand Up @@ -461,17 +472,19 @@ impl PackageSource {
/// internet.
fn resolve_target(
&self,
rt: &dyn Runtime,
rt: &Arc<dyn Runtime + Send + Sync>,
pb: &ProgressBar,
) -> Result<ExecutableTarget, Error> {
match self {
PackageSource::File(path) => ExecutableTarget::from_file(path, rt, pb),
PackageSource::Dir(d) => ExecutableTarget::from_dir(d, rt, pb),
PackageSource::Package(pkg) => {
pb.set_message("Loading from the registry");
let pkg = rt
.task_manager()
.block_on(BinaryPackage::from_registry(pkg, rt))?;
let inner_pck = pkg.clone();
let inner_rt = rt.clone();
let pkg = rt.task_manager().spawn_and_block_on(async move {
BinaryPackage::from_registry(&inner_pck, inner_rt.as_ref()).await
})?;
Ok(ExecutableTarget::Package(pkg))
}
}
Expand Down Expand Up @@ -544,23 +557,32 @@ enum ExecutableTarget {
impl ExecutableTarget {
/// Try to load a Wasmer package from a directory containing a `wasmer.toml`
/// file.
fn from_dir(dir: &Path, runtime: &dyn Runtime, pb: &ProgressBar) -> Result<Self, Error> {
fn from_dir(
dir: &Path,
runtime: &Arc<dyn Runtime + Send + Sync>,
pb: &ProgressBar,
) -> Result<Self, Error> {
pb.set_message(format!("Loading \"{}\" into memory", dir.display()));

let webc = construct_webc_in_memory(dir)?;
let container = Container::from_bytes(webc)?;

pb.set_message("Resolving dependencies");
let pkg = runtime
.task_manager()
.block_on(BinaryPackage::from_webc(&container, runtime))?;
let inner_runtime = runtime.clone();
let pkg = runtime.task_manager().spawn_and_block_on(async move {
BinaryPackage::from_webc(&container, inner_runtime.as_ref()).await
})?;

Ok(ExecutableTarget::Package(pkg))
}

/// Try to load a file into something that can be used to run it.
#[tracing::instrument(skip_all)]
fn from_file(path: &Path, runtime: &dyn Runtime, pb: &ProgressBar) -> Result<Self, Error> {
fn from_file(
path: &Path,
runtime: &Arc<dyn Runtime + Send + Sync>,
pb: &ProgressBar,
) -> Result<Self, Error> {
pb.set_message(format!("Loading from \"{}\"", path.display()));

match TargetOnDisk::from_file(path)? {
Expand All @@ -573,7 +595,14 @@ impl ExecutableTarget {
let module_cache = runtime.module_cache();
let module_hash = ModuleHash::sha256(&wasm);

let module = match tasks.block_on(module_cache.load(module_hash, &engine)) {
let ret = {
let module_cache = module_cache.clone();
let engine = engine.clone();
tasks.spawn_and_block_on(async move {
module_cache.load(module_hash, &engine).await
})
};
let module = match ret {
Ok(m) => m,
Err(e) => {
if !matches!(e, CacheError::NotFound) {
Expand Down Expand Up @@ -608,9 +637,11 @@ impl ExecutableTarget {
TargetOnDisk::LocalWebc => {
let container = Container::from_disk(path)?;
pb.set_message("Resolving dependencies");
let pkg = runtime
.task_manager()
.block_on(BinaryPackage::from_webc(&container, runtime))?;

let inner_runtime = runtime.clone();
let pkg = runtime.task_manager().spawn_and_block_on(async move {
BinaryPackage::from_webc(&container, inner_runtime.as_ref()).await
})?;
Ok(ExecutableTarget::Package(pkg))
}
}
Expand Down Expand Up @@ -784,13 +815,16 @@ fn get_exit_code(

#[derive(Debug)]
struct MonitoringRuntime<R> {
runtime: R,
runtime: Arc<R>,
progress: ProgressBar,
}

impl<R> MonitoringRuntime<R> {
fn new(runtime: R, progress: ProgressBar) -> Self {
MonitoringRuntime { runtime, progress }
MonitoringRuntime {
runtime: Arc::new(runtime),
progress,
}
}
}

Expand Down
14 changes: 9 additions & 5 deletions lib/cli/src/commands/run/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use wasmer_wasix::{
FileSystemSource, InMemorySource, MultiSource, PackageSpecifier, Source, WapmSource,
WebSource,
},
task_manager::tokio::TokioTaskManager,
task_manager::{tokio::TokioTaskManager, VirtualTaskManagerExt},
},
types::__WASI_STDIN_FILENO,
wasmer_wasix_types::wasi::Errno,
Expand Down Expand Up @@ -169,10 +169,14 @@ impl Wasi {
for name in &self.uses {
let specifier = PackageSpecifier::parse(name)
.with_context(|| format!("Unable to parse \"{name}\" as a package specifier"))?;
let pkg = rt
.task_manager()
.block_on(BinaryPackage::from_registry(&specifier, &*rt))
.with_context(|| format!("Unable to load \"{name}\""))?;
let pkg = {
let inner_rt = rt.clone();
rt.task_manager()
.spawn_and_block_on(async move {
BinaryPackage::from_registry(&specifier, &*inner_rt).await
})
.with_context(|| format!("Unable to load \"{name}\""))?
};
uses.push(pkg);
}

Expand Down
Loading