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