add timing for syscall
This commit is contained in:
parent
9c9d1eed3a
commit
76f9ff380b
@ -15,6 +15,7 @@ rcore-fs-sefs = { path = "../../deps/sefs/rcore-fs-sefs" }
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
syscall_timing = []
|
||||||
|
|
||||||
[target.'cfg(not(target_env = "sgx"))'.dependencies]
|
[target.'cfg(not(target_env = "sgx"))'.dependencies]
|
||||||
xmas-elf = { path = "../../deps/xmas-elf" }
|
xmas-elf = { path = "../../deps/xmas-elf" }
|
||||||
|
@ -29,6 +29,8 @@ use std::any::Any;
|
|||||||
|
|
||||||
mod consts;
|
mod consts;
|
||||||
|
|
||||||
|
static mut SYSCALL_TIMING: [usize; 361] = [0; 361];
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[deny(unreachable_patterns)]
|
#[deny(unreachable_patterns)]
|
||||||
pub extern "C" fn dispatch_syscall(
|
pub extern "C" fn dispatch_syscall(
|
||||||
@ -44,6 +46,14 @@ pub extern "C" fn dispatch_syscall(
|
|||||||
"syscall {}: {:#x}, {:#x}, {:#x}, {:#x}, {:#x}, {:#x}",
|
"syscall {}: {:#x}, {:#x}, {:#x}, {:#x}, {:#x}, {:#x}",
|
||||||
num, arg0, arg1, arg2, arg3, arg4, arg5
|
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 {
|
let ret = match num {
|
||||||
// file
|
// file
|
||||||
SYS_OPEN => do_open(arg0 as *const i8, arg1 as u32, arg2 as u32),
|
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),
|
_ => 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);
|
info!("=> {:?}", ret);
|
||||||
|
|
||||||
match 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)]
|
#[allow(non_camel_case_types)]
|
||||||
pub struct iovec_t {
|
pub struct iovec_t {
|
||||||
base: *const c_void,
|
base: *const c_void,
|
||||||
|
@ -16,6 +16,12 @@ pub struct timeval_t {
|
|||||||
usec: suseconds_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 {
|
pub fn do_gettimeofday() -> timeval_t {
|
||||||
let mut tv: timeval_t = Default::default();
|
let mut tv: timeval_t = Default::default();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
Loading…
Reference in New Issue
Block a user