-
-
Notifications
You must be signed in to change notification settings - Fork 158
重写调度模块 #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
重写调度模块 #679
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码好多,人给看麻了。
ps: 目前还有一些warning需要解决。
kernel/src/new_sched/mod.rs
Outdated
} | ||
|
||
lazy_static! { | ||
pub static ref SCHED_FEATURES: SchedFeature = SchedFeature::GENTLE_FAIR_SLEEPERS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这东西不用lazy_static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为内部bitflags不是const的,所以不用lazy不行
kernel/src/new_sched/mod.rs
Outdated
static mut CPU_IRQ_TIME: Option<Vec<&'static mut IrqTime>> = None; | ||
|
||
// 这里虽然rq是percpu的,但是在负载均衡的时候需要修改对端cpu的rq,所以仍需加锁 | ||
static CPU_RUNQUEUE: Lazy<Vec<Arc<CpuRunQueue>>> = Lazy::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所有的per cpu的都能使用PerCpuVar这个来做,就不要自己写一遍了。毕竟这样破坏了封装性。很容易出安全问题。
kernel/src/new_sched/mod.rs
Outdated
#[allow(dead_code)] | ||
#[derive(Debug)] | ||
pub struct CpuRunQueue { | ||
lock: SpinLock<()>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥要这样写lock?这样我们就能轻而易举的“不加锁就访问数据”。
可以参考KernelMapper的写法。那样会更安全。
https://code.dragonos.org.cn/xref/DragonOS/kernel/src/mm/kernel_mapper.rs?r=e28411791f090c421fe4b6fa5956fb1bd362a8d9#39
kernel/src/new_sched/mod.rs
Outdated
const WF_CURRENT_CPU = 0x40; /* Prefer to move the wakee to the current CPU. */ | ||
} | ||
|
||
pub struct SchedMode: u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个加注释
kernel/src/new_sched/mod.rs
Outdated
/// 此函数与schedule的区别为,该函数不会检查preempt_count | ||
/// 适用于时钟中断等场景 | ||
#[inline] | ||
pub fn __schedule(sched_mod: SchedMode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这个和上面的函数,二选一inline就行,不然的话这些代码要被copy到好多地方。挺占内存&占用栈空间的。
kernel/src/new_sched/mod.rs
Outdated
} | ||
} | ||
|
||
pub fn sched_fork(pcb: &Arc<ProcessControlBlock>) -> Result<(), SystemError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加注释。
kernel/src/new_sched/fair.rs
Outdated
} | ||
|
||
#[allow(clippy::mut_from_ref)] | ||
pub fn force_mut(&self) -> &mut Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数最好还是写成unsafe fn。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个如果unsafe的话,外面调用的地方都得unsafe,有点多哈哈哈,你觉得呢
kernel/src/new_sched/fair.rs
Outdated
|
||
#[inline] | ||
#[allow(clippy::mut_from_ref)] | ||
pub fn force_mut(&self) -> &mut Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同理,这也标为unsafe.
kernel/src/new_sched/fair.rs
Outdated
|
||
/// 遍历se组,如果返回false则需要调用的函数return, | ||
/// 会将se指向其顶层parent | ||
pub fn for_each_in_group( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数需要写参数的注释,尤其是那个函数闭包返回的两个bool是啥意思?
@dragonosbot author |
warning将会在最后merge时候更改,因为现在warning都是因为禁用了旧的sched |
@GnoCiYeH 有冲突,解决一下之后,差不多就合并吧哈哈哈 |
PR:重写调度模块
完成的部分
需要后续接力的部分
目前也只是一个简单的框架,后续功能需要同学接力。
东西还没改完,需要进一步测试才能merge