xref: /DragonOS/kernel/src/arch/x86_64/sched.rs (revision 52da9a59374752b4d01907b052135a0d317781dd)
1 use crate::{
2     exception::InterruptArch, include::bindings::bindings::enter_syscall_int, sched::SchedArch,
3     syscall::SYS_SCHED,
4 };
5 
6 use super::CurrentIrqArch;
7 
8 /// @brief 若内核代码不处在中断上下文中,那么将可以使用本函数,发起一个sys_sched系统调用,然后运行调度器。
9 /// 由于只能在中断上下文中进行进程切换,因此需要发起一个系统调用SYS_SCHED。
10 #[no_mangle]
11 pub extern "C" fn sched() {
12     unsafe {
13         enter_syscall_int(SYS_SCHED as u64, 0, 0, 0, 0, 0, 0);
14     }
15 }
16 
17 extern "C" {
18     fn apic_timer_init();
19 }
20 
21 pub struct X86_64SchedArch;
22 
23 impl SchedArch for X86_64SchedArch {
24     fn enable_sched_local() {
25         // fixme: 这里将来可能需要更改,毕竟这个直接开关中断有点暴力。
26         unsafe { CurrentIrqArch::interrupt_enable() };
27     }
28 
29     fn disable_sched_local() {
30         unsafe {
31             CurrentIrqArch::interrupt_disable();
32         }
33     }
34 
35     fn initial_setup_sched_local() {
36         unsafe {
37             apic_timer_init();
38         }
39     }
40 }
41