|
|
|
@ -8,7 +8,7 @@ use crate::println;
|
|
|
|
|
use crate::sbi::shutdown;
|
|
|
|
|
use crate::task::context::TaskContext;
|
|
|
|
|
use crate::task::manager::{add_task, TASK_MANAGER};
|
|
|
|
|
use crate::task::processor::{schedule, take_current_task};
|
|
|
|
|
use crate::task::processor::{kernel_time_start, refresh_stop_clock, schedule, take_current_task};
|
|
|
|
|
use crate::task::switch::__switch;
|
|
|
|
|
use crate::timer::{get_time_ms, get_time_us};
|
|
|
|
|
use crate::trap::TrapContext;
|
|
|
|
@ -38,6 +38,7 @@ pub fn add_initproc() {
|
|
|
|
|
|
|
|
|
|
// 挂起当前运行下一个, 需要把当前任务 从Process中 take 取出来, 然后再 push回 全局的任务管理器
|
|
|
|
|
pub fn suspend_current_and_run_next() {
|
|
|
|
|
|
|
|
|
|
// 必须有一个程序在运行,
|
|
|
|
|
let task = take_current_task().unwrap();
|
|
|
|
|
|
|
|
|
@ -47,6 +48,11 @@ pub fn suspend_current_and_run_next() {
|
|
|
|
|
let task_cx_ptr = &mut task_inner.task_cx as *mut TaskContext;
|
|
|
|
|
// Change status to Ready
|
|
|
|
|
task_inner.task_status = TaskStatus::Ready;
|
|
|
|
|
|
|
|
|
|
// 统计内核时间
|
|
|
|
|
let kernel_time = refresh_stop_clock();
|
|
|
|
|
task_inner.kernel_time += kernel_time;
|
|
|
|
|
|
|
|
|
|
drop(task_inner);
|
|
|
|
|
// ---- release current PCB
|
|
|
|
|
|
|
|
|
@ -98,11 +104,18 @@ pub fn exit_current_and_run_next(exit_code: i32) {
|
|
|
|
|
|
|
|
|
|
inner.children.clear(); // 子进程引用计数-1 现在又变成1了
|
|
|
|
|
|
|
|
|
|
// 统计内核时间
|
|
|
|
|
let kernel_time = refresh_stop_clock();
|
|
|
|
|
inner.kernel_time += kernel_time;
|
|
|
|
|
println!("[kernel] user_time: {}ms, kernel_time: {}ms", inner.user_time /1000, inner.kernel_time / 1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 释放当前地址空间中, 逻辑段清空, areas->MapArea->data_frames->FrameTracker 执行析构, 过程是把areas中的物理页帧 根据 RAII还给操作系统
|
|
|
|
|
// 注意 页表本身占用的 三级页表的物理帧(page_table->frames), 还没有被释放, 因为我们还需要使用, 这需要父进程管理进行释放
|
|
|
|
|
inner.memory_set.recycle_data_pages();
|
|
|
|
|
drop(inner);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 手动删除tcb, 后面这里永远不会执行了, 我们智能指针需要手动释放(这里需要给引用计数-1)
|
|
|
|
|
drop(task);
|
|
|
|
|
|
|
|
|
@ -111,5 +124,7 @@ pub fn exit_current_and_run_next(exit_code: i32) {
|
|
|
|
|
|
|
|
|
|
// 这个进程不会被执行了, 我们当前栈帧随便创建一个上下文就好了
|
|
|
|
|
let mut _unused = TaskContext::new();
|
|
|
|
|
|
|
|
|
|
// 输出一下
|
|
|
|
|
schedule(&mut _unused as *mut _);
|
|
|
|
|
}
|
|
|
|
|