|
|
|
@ -6,7 +6,7 @@ use crate::loader::{get_num_app, init_app_cx};
|
|
|
|
|
use crate::println;
|
|
|
|
|
use crate::task::context::TaskContext;
|
|
|
|
|
use crate::task::switch::__switch;
|
|
|
|
|
use crate::timer::get_time_ms;
|
|
|
|
|
use crate::timer::{get_time_ms, get_time_us};
|
|
|
|
|
|
|
|
|
|
mod context;
|
|
|
|
|
mod switch;
|
|
|
|
@ -20,6 +20,24 @@ pub struct TaskManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TaskManager {
|
|
|
|
|
// 即将进入用户态, 把之前使用的内核时间统计
|
|
|
|
|
pub fn user_time_start(&self){
|
|
|
|
|
let mut inner = self.inner.exclusive_access();
|
|
|
|
|
let current_task_id = inner.current_task_id;
|
|
|
|
|
let kernel_use_time = inner.refresh_stop_clock();
|
|
|
|
|
|
|
|
|
|
inner.tasks[current_task_id].kernel_time += kernel_use_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn kernel_time_start(&self){
|
|
|
|
|
let mut inner = self.inner.exclusive_access();
|
|
|
|
|
let current_task_id = inner.current_task_id;
|
|
|
|
|
let user_use_time = inner.refresh_stop_clock();
|
|
|
|
|
|
|
|
|
|
inner.tasks[current_task_id].user_time += user_use_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn run_first_task(&self){
|
|
|
|
|
// 得到下一个需要执行的任务,的上下文 这里我们由于第一次执行, 下一个任务我们指定为0下标的任务即可
|
|
|
|
|
let next_task_context_ptr = {
|
|
|
|
@ -57,7 +75,7 @@ impl TaskManager {
|
|
|
|
|
|
|
|
|
|
// 统计内核时间, 并输出这个任务 花费了多少内核时间
|
|
|
|
|
current_task.kernel_time += kernel_use_time;
|
|
|
|
|
println!("task {:?}, exit, use: {:?}ms", current_task_id, current_task.kernel_time);
|
|
|
|
|
println!("task {:?}, exit, kernel_time: {:?}ms, user_time: {:?}ms", current_task_id, current_task.kernel_time/1000, current_task.user_time/1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 挂起当前任务
|
|
|
|
@ -133,7 +151,7 @@ impl TaskManagerInner {
|
|
|
|
|
// 上次停表的时间
|
|
|
|
|
let start_time = self.stop_clock_time;
|
|
|
|
|
// 当前时间
|
|
|
|
|
self.stop_clock_time = get_time_ms();
|
|
|
|
|
self.stop_clock_time = get_time_us();
|
|
|
|
|
// 返回 当前时间 - 上次停表时间 = 时间间距
|
|
|
|
|
self.stop_clock_time - start_time
|
|
|
|
|
}
|
|
|
|
|