From 987038e31d2f36b3836eed7cabfce571ad109f05 Mon Sep 17 00:00:00 2001 From: Sanchit Sahay Date: Fri, 27 Feb 2026 13:41:31 -0500 Subject: [PATCH 1/3] threei-lind-perf: init --- src/lind-boot/src/perf.rs | 16 +++++++++------- src/threei/src/lib.rs | 2 ++ src/threei/src/perf.rs | 7 +++++++ src/threei/src/threei.rs | 20 +++++++++++++++++++- 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/threei/src/perf.rs diff --git a/src/lind-boot/src/perf.rs b/src/lind-boot/src/perf.rs index 356cbdb19..f599eded8 100644 --- a/src/lind-boot/src/perf.rs +++ b/src/lind-boot/src/perf.rs @@ -17,27 +17,26 @@ pub static TYPED_FUNC_CALL: Counter = Counter::new("lind_boot::typed_func_call") // enables exactly one counter name from this list. pub static LIND_BOOT_COUNTERS: &[&Counter] = &[&GRATE_CALLBACK_TRAMPOLINE, &TYPED_FUNC_CALL]; +pub static ALL_COUNTERS: &[&Counter] = [LIND_BOOT_COUNTERS, threei::perf::ALL_COUNTERS].concat(); + /// Initialize counters for all modules, involves setting the TimerKind and resetting the /// counts. pub fn perf_init(kind: TimerKind) { // Configure timer backend (Clock or TSC) for all local counters. - lind_perf::set_timer(LIND_BOOT_COUNTERS, kind); + lind_perf::set_timer(ALL_COUNTERS, kind); // Reset all accumulated measurements before benchmark runs begin. - lind_perf::reset_all_counters(LIND_BOOT_COUNTERS); + lind_perf::reset_all_counters(ALL_COUNTERS); } /// Finds a counter by it's name and searches for it across modules to enable it. Disables all /// other counters. pub fn enable_one_counter(name: &str) { - lind_perf::enable_counter_by_name(LIND_BOOT_COUNTERS, name); + lind_perf::enable_counter_by_name(ALL_COUNTERS, name); } /// Get a list of all counter names. pub fn all_counter_names() -> Vec<&'static str> { - LIND_BOOT_COUNTERS - .iter() - .filter_map(|c| c.get_name()) - .collect() + ALL_COUNTERS.iter().filter_map(|c| c.get_name()).collect() } /// Print a report for every module. @@ -46,4 +45,7 @@ pub fn perf_report() { // its internal `enabled` feature. lind_perf::report_header(format!("LIND-BOOT")); lind_perf::report(LIND_BOOT_COUNTERS); + + lind_perf::report_header(format!("THREE-I")); + lind_perf::report(threei::perf::ALL_COUNTERS); } diff --git a/src/threei/src/lib.rs b/src/threei/src/lib.rs index 7de0715c2..63e854d6b 100644 --- a/src/threei/src/lib.rs +++ b/src/threei/src/lib.rs @@ -1,6 +1,8 @@ pub mod handler_table; +pub mod perf; pub mod threei; pub mod threei_const; +pub use perf::*; pub use threei::*; pub use 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 a65340d4b..f1c66b30e 100644 --- a/src/threei/src/threei.rs +++ b/src/threei/src/threei.rs @@ -14,6 +14,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 const EXIT_SYSCALL: u64 = 60; // exit syscall number. Public for tests. @@ -201,6 +202,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!( @@ -412,6 +415,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 + }; + // Return error if the target cage/grate is exiting. We need to add this check beforehead, because make_syscall will also // contain cases that can directly redirect a syscall when self_cageid == target_id, which will bypass the handlertable check if EXITING_TABLE.contains(&target_cageid) && syscall_num != EXIT_SYSCALL { @@ -428,9 +438,14 @@ 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 + }; let func: RawCallFunc = unsafe { std::mem::transmute::(in_grate_fn_ptr_u64) }; - return func( + let r = func( self_cageid, arg1, arg1_cageid, @@ -445,6 +460,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 { From fe848516c4c63276f4cc2ed8b8dd3ba6ea5b5429 Mon Sep 17 00:00:00 2001 From: Sanchit Sahay Date: Fri, 27 Feb 2026 14:40:59 -0500 Subject: [PATCH 2/3] Add threei to all_counters --- src/lind-boot/src/perf.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lind-boot/src/perf.rs b/src/lind-boot/src/perf.rs index b267898f2..cfbd5293d 100644 --- a/src/lind-boot/src/perf.rs +++ b/src/lind-boot/src/perf.rs @@ -34,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. @@ -47,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")); } From 12e1524c0ce8927525de8be6bdd086c4bd330587 Mon Sep 17 00:00:00 2001 From: Sanchit Sahay Date: Mon, 9 Mar 2026 00:44:01 -0400 Subject: [PATCH 3/3] Remove redundant pub use ::* --- src/threei/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/threei/src/lib.rs b/src/threei/src/lib.rs index 63e854d6b..7c7bbd263 100644 --- a/src/threei/src/lib.rs +++ b/src/threei/src/lib.rs @@ -3,6 +3,5 @@ pub mod perf; pub mod threei; pub mod threei_const; -pub use perf::*; pub use threei::*; pub use threei_const::*;