os gettime syscall consistent with user mod

pull/37/head
zhanghx0905 4 years ago
parent 5df22c8f87
commit 9be29f3c14

@ -14,7 +14,7 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
SYSCALL_WRITE => sys_write(args[0], args[1] as *const u8, args[2]),
SYSCALL_EXIT => sys_exit(args[0] as i32),
SYSCALL_YIELD => sys_yield(),
SYSCALL_GET_TIME => sys_get_time(),
SYSCALL_GET_TIME => sys_get_time(args[0] as *mut TimeVal, args[1]),
_ => panic!("Unsupported syscall_id: {}", syscall_id),
}
}

@ -2,7 +2,14 @@ use crate::task::{
suspend_current_and_run_next,
exit_current_and_run_next,
};
use crate::timer::get_time_ms;
use crate::timer::get_time_us;
#[repr(C)]
#[derive(Debug)]
pub struct TimeVal {
pub sec: usize,
pub usec: usize,
}
pub fn sys_exit(exit_code: i32) -> ! {
println!("[kernel] Application exited with code {}", exit_code);
@ -15,6 +22,17 @@ pub fn sys_yield() -> isize {
0
}
pub fn sys_get_time() -> isize {
get_time_ms() as isize
// pub fn sys_get_time() -> isize {
// get_time_ms() as isize
// }
pub fn sys_get_time(ts: *mut TimeVal, _tz: usize) -> isize {
let us = get_time_us();
unsafe {
*ts = TimeVal {
sec: us / 1_000_000,
usec: us % 1_000_000,
};
}
0
}

@ -1,16 +1,16 @@
use riscv::register::time;
use crate::sbi::set_timer;
use crate::config::CLOCK_FREQ;
use crate::sbi::set_timer;
use riscv::register::time;
const TICKS_PER_SEC: usize = 100;
const MSEC_PER_SEC: usize = 1000;
const MICRO_PER_SEC: usize = 1_000_000;
pub fn get_time() -> usize {
time::read()
}
pub fn get_time_ms() -> usize {
time::read() / (CLOCK_FREQ / MSEC_PER_SEC)
pub fn get_time_us() -> usize {
time::read() / (CLOCK_FREQ / MICRO_PER_SEC)
}
pub fn set_next_trigger() {

Loading…
Cancel
Save