使用Rust重构CFS调度器 (#131)

* 新建调度器的文件

* 把softirq vector移动到c文件中(原来在.h)

* 将进程切换方式改为“中断返回时切换”

* new:使用rust重构CFS

* 删除已经在smp中废弃的HPET中断转发函数

* 代码格式化

* 删除多余的dunce依赖
This commit is contained in:
login
2022-12-31 17:26:12 +08:00
committed by GitHub
parent 156949680c
commit d4f3de93a2
37 changed files with 464 additions and 1027 deletions

View File

@ -18,5 +18,6 @@ $(kernel_arch_x86_64_subdirs): ECHO
all: $(kernel_arch_x86_64_objs) $(kernel_arch_x86_64_subdirs)
clean:
echo "Done."

View File

@ -0,0 +1,19 @@
use crate::include::bindings::bindings::{process_control_block, switch_proc};
use core::sync::atomic::compiler_fence;
/// @brief 切换进程的上下文(没有切换页表的动作)
///
/// @param next 下一个进程的pcb
/// @param trap_frame 中断上下文的栈帧
#[inline(always)]
pub fn switch_process(
prev: &'static mut process_control_block,
next: &'static mut process_control_block,
) {
compiler_fence(core::sync::atomic::Ordering::SeqCst);
unsafe {
switch_proc(prev, next);
}
compiler_fence(core::sync::atomic::Ordering::SeqCst);
}

View File

@ -0,0 +1,23 @@
#![allow(dead_code)]
use core::arch::asm;
#[inline(always)]
pub fn mfence(){
unsafe{
asm!("mfence");
}
}
#[inline(always)]
pub fn lfence(){
unsafe{
asm!("lfence");
}
}
#[inline(always)]
pub fn sfence(){
unsafe{
asm!("sfence");
}
}

View File

@ -0,0 +1,28 @@
pub mod barrier;
use crate::include::bindings::bindings::process_control_block;
use core::arch::asm;
use core::ptr::read_volatile;
use self::barrier::mfence;
/// @brief 切换进程的页表
///
/// @param 下一个进程的pcb。将会把它的页表切换进来。
///
/// @return 下一个进程的pcb(把它return的目的主要是为了归还所有权)
#[inline(always)]
#[allow(dead_code)]
pub fn switch_mm(
next_pcb: &'static mut process_control_block,
) -> &'static mut process_control_block {
mfence();
// kdebug!("to get pml4t");
let pml4t = unsafe { read_volatile(&next_pcb.mm.as_ref().unwrap().pgd) };
unsafe {
asm!("mov cr3, {}", in(reg) pml4t);
}
mfence();
return next_pcb;
}

View File

@ -1,4 +1,7 @@
#[macro_use]
pub mod asm;
pub mod cpu;
pub mod interrupt;
pub mod interrupt;
pub mod mm;
pub mod context;
pub mod sched;

View File

@ -0,0 +1,10 @@
use crate::include::bindings::bindings::{enter_syscall_int, SYS_SCHED};
/// @brief 若内核代码不处在中断上下文中那么将可以使用本函数发起一个sys_sched系统调用然后运行调度器。
/// 由于只能在中断上下文中进行进程切换因此需要发起一个系统调用SYS_SCHED。
#[no_mangle]
pub extern "C" fn sched() {
unsafe {
enter_syscall_int(SYS_SCHED.into(), 0, 0, 0, 0, 0, 0, 0, 0);
}
}