Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 43 additions & 0 deletions src/hyperlight_host/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

use std::sync::Mutex;

use criterion::{Criterion, criterion_group, criterion_main};
use flatbuffers::FlatBufferBuilder;
use hyperlight_common::flatbuffer_wrappers::function_call::{FunctionCall, FunctionCallType};
Expand Down Expand Up @@ -74,6 +76,47 @@ fn guest_call_benchmark(c: &mut Criterion) {
});
});

// same as guest_call, but the call will be made on different thread
group.bench_function("guest_call_on_different_thread", |b| {
use std::sync::{Arc, Barrier};
use std::thread;
use std::time::Instant;

b.iter_custom(|iters| {
let mut total_duration = std::time::Duration::ZERO;
let sbox = Arc::new(Mutex::new(create_multiuse_sandbox()));

for _ in 0..iters {
// Ensure vcpu is "bound" on this main thread
{
let mut sbox = sbox.lock().unwrap();
sbox.call::<String>("Echo", "warmup\n".to_string()).unwrap();
}

let barrier = Arc::new(Barrier::new(2));
let barrier_clone = Arc::clone(&barrier);
let sbox_clone = Arc::clone(&sbox);

let handle = thread::spawn(move || {
barrier_clone.wait();

let mut sbox = sbox_clone.lock().unwrap();
let start = Instant::now();
// Measure the first call after thread switch
// According to KVM docs, this should show performance impact
sbox.call::<String>("Echo", "hello\n".to_string()).unwrap();
start.elapsed()
});

barrier.wait();

total_duration += handle.join().unwrap();
}

total_duration
});
});

group.finish();
}

Expand Down
4 changes: 2 additions & 2 deletions src/tests/rust_guests/witguest/Cargo.lock

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

Loading