diff --git a/src/lind-boot/src/perf.rs b/src/lind-boot/src/perf.rs index 42b0038c4..cfbd5293d 100644 --- a/src/lind-boot/src/perf.rs +++ b/src/lind-boot/src/perf.rs @@ -21,6 +21,7 @@ pub static LIND_BOOT_COUNTERS: &[&Counter] = &[&GRATE_CALLBACK_TRAMPOLINE, &TYPE /// counts. pub fn perf_init(kind: TimerKind) { // Configure timer backend (Clock or TSC) for all local counters. + lind_perf::set_timer(all_counters(), kind); // Reset all accumulated measurements before benchmark runs begin. lind_perf::reset_all_counters(all_counters()); @@ -33,7 +34,10 @@ pub fn enable_one_counter(name: &str) { } fn all_counters() -> impl Iterator { - LIND_BOOT_COUNTERS.iter().copied() + LIND_BOOT_COUNTERS + .iter() + .copied() + .chain(threei::perf::ALL_COUNTERS.iter().copied()) } /// Get a list of all counter names. @@ -46,4 +50,5 @@ pub fn perf_report() { // Note: `lind_perf::report*` are no-ops when lind-perf is built without // its internal `enabled` feature. lind_perf::report(LIND_BOOT_COUNTERS, format!("LIND-BOOT")); + lind_perf::report(threei::perf::ALL_COUNTERS, format!("THREE-I")); } diff --git a/src/threei/src/lib.rs b/src/threei/src/lib.rs index 7de0715c2..7c7bbd263 100644 --- a/src/threei/src/lib.rs +++ b/src/threei/src/lib.rs @@ -1,4 +1,5 @@ pub mod handler_table; +pub mod perf; pub mod threei; pub mod threei_const; diff --git a/src/threei/src/perf.rs b/src/threei/src/perf.rs new file mode 100644 index 000000000..03552419d --- /dev/null +++ b/src/threei/src/perf.rs @@ -0,0 +1,7 @@ +use lind_perf::Counter; + +pub static CALL_GRATE_FUNC: Counter = Counter::new("threei::_call_grate_func"); +pub static MAKE_SYSCALL: Counter = Counter::new("threei::make_syscall"); +pub static RAWPOSIX_DISPATCH: Counter = Counter::new("threei::rawposix_dispatch"); + +pub static ALL_COUNTERS: &[&Counter] = &[&CALL_GRATE_FUNC, &MAKE_SYSCALL, &RAWPOSIX_DISPATCH]; diff --git a/src/threei/src/threei.rs b/src/threei/src/threei.rs index 45bb02ba8..47b997309 100644 --- a/src/threei/src/threei.rs +++ b/src/threei/src/threei.rs @@ -16,6 +16,7 @@ use crate::handler_table::{ _check_cage_handler_exists, _get_handler, _rm_cage_from_handler, _rm_grate_from_handler, copy_handler_table_to_cage_impl, print_handler_table, register_handler_impl, }; +use crate::perf; use crate::threei_const; pub use sysdefs::constants::sys_const::{EXIT_GROUP_SYSCALL, EXIT_SYSCALL}; @@ -215,6 +216,8 @@ fn _call_grate_func( arg6: u64, arg6_cageid: u64, ) -> Option { + let _timer = lind_perf::get_timer!(perf::CALL_GRATE_FUNC); + let runtimeid = match get_cage_runtime(grateid) { Some(r) => r, None => panic!( @@ -426,6 +429,13 @@ pub fn make_syscall( arg6: u64, arg6_cageid: u64, ) -> i32 { + // Only enable timers for syscalls that are explicitly benchmarking related (2000-3000) + let _timer = if syscall_num > 2000 && syscall_num < 3000 { + Some(lind_perf::get_timer!(perf::MAKE_SYSCALL)) + } else { + None + }; + // Block cross-cage calls to a dead or removed cage (e.g. grate-forwarded // syscalls). The cage's own threads are allowed to keep making // syscalls until the epoch kill fires — without the self != target @@ -451,6 +461,12 @@ pub fn make_syscall( if grateid == lind_platform_const::RAWPOSIX_CAGEID || grateid == lind_platform_const::WASMTIME_CAGEID { + let _rpx_dispatch_timer = if syscall_num > 2000 && syscall_num < 3000 { + Some(lind_perf::get_timer!(perf::RAWPOSIX_DISPATCH)) + } else { + None + }; + // Second check: catch in-flight grate-forwarded calls that // passed the initial check before is_dead was set or the cage // was removed. @@ -478,6 +494,9 @@ pub fn make_syscall( arg6, arg6_cageid, ); + drop(_rpx_dispatch_timer); + + return r; } // Threei special case: if the call is an interposed 3i call if grateid == lind_platform_const::THREEI_CAGEID {