diff --git a/src/libos/Cargo.toml b/src/libos/Cargo.toml index 71e1fec9..1627c480 100644 --- a/src/libos/Cargo.toml +++ b/src/libos/Cargo.toml @@ -15,6 +15,7 @@ rcore-fs-sefs = { path = "../../deps/sefs/rcore-fs-sefs" } [features] default = [] +syscall_timing = [] [target.'cfg(not(target_env = "sgx"))'.dependencies] xmas-elf = { path = "../../deps/xmas-elf" } diff --git a/src/libos/src/syscall/mod.rs b/src/libos/src/syscall/mod.rs index 81a0b076..fabb966a 100644 --- a/src/libos/src/syscall/mod.rs +++ b/src/libos/src/syscall/mod.rs @@ -29,6 +29,8 @@ use std::any::Any; mod consts; +static mut SYSCALL_TIMING: [usize; 361] = [0; 361]; + #[no_mangle] #[deny(unreachable_patterns)] pub extern "C" fn dispatch_syscall( @@ -44,6 +46,14 @@ pub extern "C" fn dispatch_syscall( "syscall {}: {:#x}, {:#x}, {:#x}, {:#x}, {:#x}, {:#x}", num, arg0, arg1, arg2, arg3, arg4, arg5 ); + #[cfg(feature = "syscall_timing")] + let time_start = { + if crate::process::current_pid() == 1 && num == SYS_EXIT { + print_syscall_timing(); + } + crate::time::do_gettimeofday().as_usec() + }; + let ret = match num { // file SYS_OPEN => do_open(arg0 as *const i8, arg1 as u32, arg2 as u32), @@ -256,6 +266,16 @@ pub extern "C" fn dispatch_syscall( _ => do_unknown(num, arg0, arg1, arg2, arg3, arg4, arg5), }; + + #[cfg(feature = "syscall_timing")] + { + let time_end = crate::time::do_gettimeofday().as_usec(); + let time = time_end - time_start; + unsafe { + SYSCALL_TIMING[num as usize] += time as usize; + } + } + info!("=> {:?}", ret); match ret { @@ -264,6 +284,17 @@ pub extern "C" fn dispatch_syscall( } } +#[cfg(feature = "syscall_timing")] +fn print_syscall_timing() { + println!("syscall timing:"); + for (i, &time) in unsafe { SYSCALL_TIMING }.iter().enumerate() { + if time == 0 { + continue; + } + println!("{:>3}: {:>6} us", i, time); + } +} + #[allow(non_camel_case_types)] pub struct iovec_t { base: *const c_void, diff --git a/src/libos/src/time/mod.rs b/src/libos/src/time/mod.rs index 8fd99706..d458a319 100644 --- a/src/libos/src/time/mod.rs +++ b/src/libos/src/time/mod.rs @@ -16,6 +16,12 @@ pub struct timeval_t { usec: suseconds_t, } +impl timeval_t { + pub fn as_usec(&self) -> usize { + (self.sec * 1000000 + self.usec) as usize + } +} + pub fn do_gettimeofday() -> timeval_t { let mut tv: timeval_t = Default::default(); unsafe {