|
|
|
@ -33,20 +33,20 @@ fn get_epoch_usec() -> u64 {
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
|
pub struct TimeVal {
|
|
|
|
|
sec: u64,
|
|
|
|
|
usec: u64,
|
|
|
|
|
sec: usize,
|
|
|
|
|
usec: usize,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TimeVal {
|
|
|
|
|
pub fn to_msec(&self) -> u64 {
|
|
|
|
|
self.sec * MSEC_PER_SEC + self.usec / USEC_PER_MSEC
|
|
|
|
|
(self.sec as u64) * MSEC_PER_SEC + (self.usec as u64) / USEC_PER_MSEC
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_epoch() -> Self {
|
|
|
|
|
let usec = get_epoch_usec();
|
|
|
|
|
TimeVal {
|
|
|
|
|
sec: usec / USEC_PER_SEC,
|
|
|
|
|
usec: usec % USEC_PER_SEC,
|
|
|
|
|
sec: (usec / USEC_PER_SEC) as usize,
|
|
|
|
|
usec: (usec % USEC_PER_SEC) as usize,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -54,24 +54,24 @@ impl TimeVal {
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
|
pub struct TimeSpec {
|
|
|
|
|
sec: u64,
|
|
|
|
|
nsec: u64,
|
|
|
|
|
sec: usize,
|
|
|
|
|
nsec: usize,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TimeSpec {
|
|
|
|
|
pub fn to_msec(&self) -> u64 {
|
|
|
|
|
self.sec * MSEC_PER_SEC + self.nsec / NSEC_PER_MSEC
|
|
|
|
|
(self.sec as u64) * MSEC_PER_SEC + (self.nsec as u64) / NSEC_PER_MSEC
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn to_duration(&self) -> Duration {
|
|
|
|
|
Duration::new(self.sec, self.nsec as u32)
|
|
|
|
|
Duration::new(self.sec as u64, self.nsec as u32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_epoch() -> Self {
|
|
|
|
|
let usec = get_epoch_usec();
|
|
|
|
|
TimeSpec {
|
|
|
|
|
sec: usec / USEC_PER_SEC,
|
|
|
|
|
nsec: usec % USEC_PER_SEC * NSEC_PER_USEC,
|
|
|
|
|
sec: (usec / USEC_PER_SEC) as usize,
|
|
|
|
|
nsec: (usec % USEC_PER_SEC * NSEC_PER_USEC) as usize,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -135,12 +135,12 @@ pub fn sys_getrusage(who: usize, rusage: *mut RUsage) -> SysResult {
|
|
|
|
|
let usec = (tick - tick_base) * USEC_PER_TICK as u64;
|
|
|
|
|
let new_rusage = RUsage {
|
|
|
|
|
utime: TimeVal {
|
|
|
|
|
sec: usec / USEC_PER_SEC,
|
|
|
|
|
usec: usec % USEC_PER_SEC,
|
|
|
|
|
sec: (usec / USEC_PER_SEC) as usize,
|
|
|
|
|
usec: (usec % USEC_PER_SEC) as usize,
|
|
|
|
|
},
|
|
|
|
|
stime: TimeVal {
|
|
|
|
|
sec: usec / USEC_PER_SEC,
|
|
|
|
|
usec: usec % USEC_PER_SEC,
|
|
|
|
|
sec: (usec / USEC_PER_SEC) as usize,
|
|
|
|
|
usec: (usec % USEC_PER_SEC) as usize,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
unsafe { *rusage = new_rusage };
|
|
|
|
|