Skip to content

Conversation

GnoCiYeH
Copy link
Member

PR:重写调度模块


完成的部分

  • 实现cfs调度策略
  • 搭建框架,后续功能可以迭代开发
  • 目前能跑,未测试性能

需要后续接力的部分

  • 实现组内调度(task_group)
  • 实现跨核负载均衡(pelt算法)
  • 接入sysfs,实现参数动态调节(sched_stat等)
  • nice值以及priority等参数的设置及调优

目前也只是一个简单的框架,后续功能需要同学接力。

东西还没改完,需要进一步测试才能merge

@dragonosbot
Copy link
Contributor

r? @chiichen

dragonosbot has assigned @chiichen.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@dragonosbot dragonosbot added O-x86_64 Target: x86_64 S-等待审查 Status: 等待assignee以及相关方的审查。 T-driver Relevant to the driver team, which will review and decide on the PR/issue. labels Mar 31, 2024
@GnoCiYeH GnoCiYeH requested review from fslongjin and chiichen March 31, 2024 17:32
@dragonosbot dragonosbot added the O-riscv64 Target: riscv64 label Apr 2, 2024
Copy link
Member

@fslongjin fslongjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码好多,人给看麻了。
ps: 目前还有一些warning需要解决。

}

lazy_static! {
pub static ref SCHED_FEATURES: SchedFeature = SchedFeature::GENTLE_FAIR_SLEEPERS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这东西不用lazy_static

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为内部bitflags不是const的,所以不用lazy不行

static mut CPU_IRQ_TIME: Option<Vec<&'static mut IrqTime>> = None;

// 这里虽然rq是percpu的,但是在负载均衡的时候需要修改对端cpu的rq,所以仍需加锁
static CPU_RUNQUEUE: Lazy<Vec<Arc<CpuRunQueue>>> = Lazy::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所有的per cpu的都能使用PerCpuVar这个来做,就不要自己写一遍了。毕竟这样破坏了封装性。很容易出安全问题。

#[allow(dead_code)]
#[derive(Debug)]
pub struct CpuRunQueue {
lock: SpinLock<()>,
Copy link
Member

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

const WF_CURRENT_CPU = 0x40; /* Prefer to move the wakee to the current CPU. */
}

pub struct SchedMode: u8 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个加注释

/// 此函数与schedule的区别为,该函数不会检查preempt_count
/// 适用于时钟中断等场景
#[inline]
pub fn __schedule(sched_mod: SchedMode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这个和上面的函数,二选一inline就行,不然的话这些代码要被copy到好多地方。挺占内存&占用栈空间的。

}
}

pub fn sched_fork(pcb: &Arc<ProcessControlBlock>) -> Result<(), SystemError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加注释。

}

#[allow(clippy::mut_from_ref)]
pub fn force_mut(&self) -> &mut Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数最好还是写成unsafe fn。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个如果unsafe的话,外面调用的地方都得unsafe,有点多哈哈哈,你觉得呢


#[inline]
#[allow(clippy::mut_from_ref)]
pub fn force_mut(&self) -> &mut Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同理,这也标为unsafe.


/// 遍历se组,如果返回false则需要调用的函数return,
/// 会将se指向其顶层parent
pub fn for_each_in_group(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数需要写参数的注释,尤其是那个函数闭包返回的两个bool是啥意思?

@fslongjin
Copy link
Member

@dragonosbot author

@dragonosbot dragonosbot added S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 and removed S-等待审查 Status: 等待assignee以及相关方的审查。 labels Apr 4, 2024
@GnoCiYeH
Copy link
Member Author

GnoCiYeH commented Apr 4, 2024

warning将会在最后merge时候更改,因为现在warning都是因为禁用了旧的sched

@fslongjin
Copy link
Member

@GnoCiYeH 有冲突,解决一下之后,差不多就合并吧哈哈哈

@fslongjin fslongjin added A-sched Area: 调度子系统 and removed O-riscv64 Target: riscv64 labels Apr 4, 2024
@dragonosbot dragonosbot added A-fs Area: 文件系统 O-riscv64 Target: riscv64 labels Apr 4, 2024
@fslongjin
Copy link
Member

运行http_server &报错:

image

@fslongjin fslongjin added this to the DragonOS 0.1.10 milestone Apr 5, 2024
@fslongjin
Copy link
Member

#571

@fslongjin fslongjin merged commit f0c87a8 into DragonOS-Community:master Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fs Area: 文件系统 A-sched Area: 调度子系统 O-riscv64 Target: riscv64 O-x86_64 Target: x86_64 S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 T-driver Relevant to the driver team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants