mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
使用Rust重构CFS调度器 (#131)
* 新建调度器的文件 * 把softirq vector移动到c文件中(原来在.h) * 将进程切换方式改为“中断返回时切换” * new:使用rust重构CFS * 删除已经在smp中废弃的HPET中断转发函数 * 代码格式化 * 删除多余的dunce依赖
This commit is contained in:
@ -18,5 +18,6 @@ $(kernel_arch_x86_64_subdirs): ECHO
|
||||
all: $(kernel_arch_x86_64_objs) $(kernel_arch_x86_64_subdirs)
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
echo "Done."
|
19
kernel/src/arch/x86_64/context.rs
Normal file
19
kernel/src/arch/x86_64/context.rs
Normal 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);
|
||||
}
|
23
kernel/src/arch/x86_64/mm/barrier.rs
Normal file
23
kernel/src/arch/x86_64/mm/barrier.rs
Normal 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");
|
||||
}
|
||||
}
|
28
kernel/src/arch/x86_64/mm/mod.rs
Normal file
28
kernel/src/arch/x86_64/mm/mod.rs
Normal 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;
|
||||
}
|
@ -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;
|
10
kernel/src/arch/x86_64/sched.rs
Normal file
10
kernel/src/arch/x86_64/sched.rs
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user