-
Notifications
You must be signed in to change notification settings - Fork 35
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
⏱️ At a hostcall to get the amount of vcpu time that has passed in the guest, in milliseconds #412
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1921c03
Basic implementation, works outside of the component universe.
acw db6a806
Actually add the component bindings.
acw 34f5007
Merge branch 'main' into awick/get-vcpu-ms
acw 06114ee
Not sure how these got lost?
acw ff726ec
fastly_vcpu -> fastly_compute_runtime
acw 596e5eb
fix formatting
3cd26ca
widen the sleep time to try to make tests reliable
acw 5b2327c
remove a spurious println
acw 5e33c12
Merge branch 'main' into awick/get-vcpu-ms
acw b63eef1
Update lib/src/session.rs
acw 476214e
Merge branch 'main' into awick/get-vcpu-ms
acw 08d436d
Merge branch 'main' into awick/get-vcpu-ms
acw 7684564
Merge branch 'main' into awick/get-vcpu-ms
acw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ mod upstream; | |
mod upstream_async; | ||
mod upstream_dynamic; | ||
mod upstream_streaming; | ||
mod vcpu_time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::{ | ||
common::{Test, TestResult}, | ||
viceroy_test, | ||
}; | ||
use hyper::{Request, Response, StatusCode}; | ||
|
||
viceroy_test!(vcpu_time_getter_works, |is_component| { | ||
let req = Request::get("/") | ||
.header("Accept", "text/html") | ||
.body("Hello, world!") | ||
.unwrap(); | ||
|
||
let resp = Test::using_fixture("vcpu_time_test.wasm") | ||
.adapt_component(is_component) | ||
.backend("slow-server", "/", None, |_| { | ||
std::thread::sleep(std::time::Duration::from_millis(4000)); | ||
Response::builder() | ||
.status(StatusCode::OK) | ||
.body(vec![]) | ||
.unwrap() | ||
}) | ||
.await | ||
.against(req) | ||
.await?; | ||
|
||
assert_eq!(resp.status(), StatusCode::OK); | ||
Ok(()) | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,3 +358,4 @@ | |
(typename $has u32) | ||
|
||
(typename $body_length u64) | ||
(typename $vcpu_ms u64) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use super::fastly::api::{compute_runtime, types}; | ||
use crate::session::Session; | ||
use std::sync::atomic::Ordering; | ||
|
||
#[async_trait::async_trait] | ||
impl compute_runtime::Host for Session { | ||
async fn get_vcpu_ms(&mut self) -> Result<u64, types::Error> { | ||
Ok(self.active_cpu_time_us.load(Ordering::SeqCst) / 1000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::error::Error; | ||
use crate::session::Session; | ||
use crate::wiggle_abi::fastly_compute_runtime::FastlyComputeRuntime; | ||
use std::sync::atomic::Ordering; | ||
use wiggle::GuestMemory; | ||
|
||
impl FastlyComputeRuntime for Session { | ||
fn get_vcpu_ms(&mut self, _memory: &mut GuestMemory<'_>) -> Result<u64, Error> { | ||
// we internally track microseconds, because our wasmtime tick length | ||
// is too short for ms to work. but we want to shrink this to ms to | ||
// try to minimize timing attacks. | ||
Ok(self.active_cpu_time_us.load(Ordering::SeqCst) / 1000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1086,6 +1086,14 @@ interface reactor { | |
serve: func(req: request-handle, body: body-handle) -> result; | ||
} | ||
|
||
interface compute-runtime { | ||
use types.{error}; | ||
|
||
type vcpu-ms = u64; | ||
|
||
get-vcpu-ms: func() -> result<vcpu-ms, error>; | ||
} | ||
|
||
world compute { | ||
import wasi:clocks/[email protected]; | ||
import wasi:clocks/[email protected]; | ||
|
@@ -1101,6 +1109,7 @@ world compute { | |
import async-io; | ||
import backend; | ||
import cache; | ||
import compute-runtime; | ||
import dictionary; | ||
import geo; | ||
import device-detection; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you rerun
make adapter
after merging main so that this includes both the vcpu hostcall and the inspect hostcall?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! Rerunning it now shows me no changes with this PR.