mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
把调度器实例的裸指针改为Option (#262)
This commit is contained in:
parent
bfafc10279
commit
49249f4ec9
@ -4,7 +4,7 @@
|
||||
|
||||
## 1. CFSQueue 介绍
|
||||
|
||||
   CFSQueue是用来存放普通进程的调度队列,每个CPU维护一个RTQueue,主要使用Vec作为主要存储结构来实现。
|
||||
   CFSQueue是用来存放普通进程的调度队列,每个CPU维护一个CFSQueue,主要使用Vec作为主要存储结构来实现。
|
||||
|
||||
### 1.1 主要函数
|
||||
1. enqueue(): 将pcb入队列
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
### 2.1 主要函数
|
||||
|
||||
1. sched(): 是对于Scheduler trait的sched()实现,是实时进程进行调度时的逻辑处理,该函数会返回接下来要执行的pcb,若没有符合要求的pcb,返回None
|
||||
1. sched(): 是对于Scheduler trait的sched()实现,是普通进程进行调度时的逻辑处理,该函数会返回接下来要执行的pcb,若没有符合要求的pcb,返回None
|
||||
2. enqueue(): 同样是对于Scheduler trait的sched()实现,将一个pcb加入调度器的调度队列
|
||||
3. update_cpu_exec_proc_jiffies(): 更新这个cpu上,这个进程的可执行时间。
|
||||
4. timer_update_jiffies(): 时钟中断到来时,由sched的core模块中的函数,调用本函数,更新CFS进程的可执行时间
|
||||
|
@ -15,8 +15,7 @@ use crate::{
|
||||
use super::core::{sched_enqueue, Scheduler};
|
||||
|
||||
/// 声明全局的cfs调度器实例
|
||||
|
||||
pub static mut CFS_SCHEDULER_PTR: *mut SchedulerCFS = null_mut();
|
||||
pub static mut CFS_SCHEDULER_PTR: Option<Box<SchedulerCFS>> = None;
|
||||
|
||||
/// @brief 获取cfs调度器实例的可变引用
|
||||
#[inline]
|
||||
@ -26,18 +25,18 @@ pub fn __get_cfs_scheduler() -> &'static mut SchedulerCFS {
|
||||
|
||||
/// @brief 初始化cfs调度器
|
||||
pub unsafe fn sched_cfs_init() {
|
||||
if CFS_SCHEDULER_PTR.is_null() {
|
||||
CFS_SCHEDULER_PTR = Box::leak(Box::new(SchedulerCFS::new()));
|
||||
if CFS_SCHEDULER_PTR.is_none() {
|
||||
CFS_SCHEDULER_PTR = Some(Box::new(SchedulerCFS::new()));
|
||||
} else {
|
||||
kBUG!("Try to init CFS Scheduler twice.");
|
||||
panic!("Try to init CFS Scheduler twice.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief CFS队列(per-cpu的)
|
||||
#[derive(Debug)]
|
||||
struct CFSQueue {
|
||||
/// 当前cpu上执行的进程,剩余的时间片
|
||||
/// 当前cpu上执行的进程剩余的时间片
|
||||
cpu_exec_proc_jiffies: i64,
|
||||
/// 队列的锁
|
||||
lock: RawSpinlock,
|
||||
@ -100,7 +99,7 @@ impl CFSQueue {
|
||||
}
|
||||
}
|
||||
/// 获取运行队列的长度
|
||||
pub fn get_cfs_queue_size(&mut self) -> usize {
|
||||
fn get_cfs_queue_size(&mut self) -> usize {
|
||||
return self.queue.len();
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ use crate::{
|
||||
use super::core::{sched_enqueue, Scheduler};
|
||||
|
||||
/// 声明全局的rt调度器实例
|
||||
|
||||
pub static mut RT_SCHEDULER_PTR: *mut SchedulerRT = null_mut();
|
||||
pub static mut RT_SCHEDULER_PTR: Option<Box<SchedulerRT>> = None;
|
||||
|
||||
/// @brief 获取rt调度器实例的可变引用
|
||||
#[inline]
|
||||
@ -26,14 +25,13 @@ pub fn __get_rt_scheduler() -> &'static mut SchedulerRT {
|
||||
/// @brief 初始化rt调度器
|
||||
pub unsafe fn sched_rt_init() {
|
||||
kdebug!("rt scheduler init");
|
||||
if RT_SCHEDULER_PTR.is_null() {
|
||||
RT_SCHEDULER_PTR = Box::leak(Box::new(SchedulerRT::new()));
|
||||
if RT_SCHEDULER_PTR.is_none() {
|
||||
RT_SCHEDULER_PTR = Some(Box::new(SchedulerRT::new()));
|
||||
} else {
|
||||
kBUG!("Try to init RT Scheduler twice.");
|
||||
panic!("Try to init RT Scheduler twice.");
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief RT队列(per-cpu的)
|
||||
#[derive(Debug)]
|
||||
struct RTQueue {
|
||||
|
Loading…
x
Reference in New Issue
Block a user