mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-24 21:33:27 +00:00
重写调度模块 (#679)
## PR:重写调度模块 --- ### 完成的部分 - 实现cfs调度策略 - 搭建框架,后续功能可以迭代开发 - 目前能跑,未测试性能 ### 需要后续接力的部分 - 实现组内调度(task_group) - 实现跨核负载均衡(pelt算法) - 接入sysfs,实现参数动态调节(sched_stat等) - nice值以及priority等参数的设置及调优
This commit is contained in:
@ -15,7 +15,7 @@ use system_error::SystemError;
|
||||
use unified_init::macros::unified_init;
|
||||
|
||||
use crate::{
|
||||
arch::{sched::sched, CurrentIrqArch},
|
||||
arch::CurrentIrqArch,
|
||||
exception::InterruptArch,
|
||||
init::initcall::INITCALL_LATE,
|
||||
kdebug, kinfo,
|
||||
@ -24,6 +24,7 @@ use crate::{
|
||||
kthread::{KernelThreadClosure, KernelThreadMechanism},
|
||||
ProcessControlBlock, ProcessManager,
|
||||
},
|
||||
sched::{schedule, SchedMode},
|
||||
};
|
||||
|
||||
use super::{
|
||||
@ -823,7 +824,7 @@ pub fn clocksource_watchdog_kthread() -> i32 {
|
||||
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
|
||||
ProcessManager::mark_sleep(true).expect("clocksource_watchdog_kthread:mark sleep failed");
|
||||
drop(irq_guard);
|
||||
sched();
|
||||
schedule(SchedMode::SM_NONE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ lazy_static! {
|
||||
pub const JIFFIES_SHIFT: u32 = 8;
|
||||
pub const LATCH: u32 = (CLOCK_TICK_RATE + (HZ as u32) / 2) / HZ as u32;
|
||||
pub const ACTHZ: u32 = sh_div(CLOCK_TICK_RATE, LATCH, 8);
|
||||
pub const TICK_NESC: u32 = (NSEC_PER_SEC + (HZ as u32) / 2) / HZ as u32;
|
||||
//TODO 编写测试,保证始终跳动间隔与现实一致(两种时钟源进行对拍)
|
||||
pub const NSEC_PER_JIFFY: u32 = (((NSEC_PER_SEC as u64) << 8) / ACTHZ as u64) as u32;
|
||||
pub const fn sh_div(nom: u32, den: u32, lsh: u32) -> u32 {
|
||||
|
@ -4,10 +4,11 @@ use alloc::{boxed::Box, sync::Arc};
|
||||
use system_error::SystemError;
|
||||
|
||||
use crate::{
|
||||
arch::{sched::sched, CurrentIrqArch, CurrentTimeArch},
|
||||
arch::{CurrentIrqArch, CurrentTimeArch},
|
||||
exception::InterruptArch,
|
||||
include::bindings::bindings::useconds_t,
|
||||
process::ProcessManager,
|
||||
sched::{schedule, SchedMode},
|
||||
time::timekeeping::getnstimeofday,
|
||||
};
|
||||
|
||||
@ -53,7 +54,7 @@ pub fn nanosleep(sleep_time: TimeSpec) -> Result<TimeSpec, SystemError> {
|
||||
timer.activate();
|
||||
|
||||
drop(irq_guard);
|
||||
sched();
|
||||
schedule(SchedMode::SM_NONE);
|
||||
|
||||
let end_time = getnstimeofday();
|
||||
// 返回正确的剩余时间
|
||||
|
@ -12,7 +12,7 @@ use alloc::{
|
||||
use system_error::SystemError;
|
||||
|
||||
use crate::{
|
||||
arch::{sched::sched, CurrentIrqArch},
|
||||
arch::CurrentIrqArch,
|
||||
exception::{
|
||||
softirq::{softirq_vectors, SoftirqNumber, SoftirqVec},
|
||||
InterruptArch,
|
||||
@ -20,6 +20,7 @@ use crate::{
|
||||
kerror, kinfo,
|
||||
libs::spinlock::{SpinLock, SpinLockGuard},
|
||||
process::{ProcessControlBlock, ProcessManager},
|
||||
sched::{schedule, SchedMode},
|
||||
};
|
||||
|
||||
use super::{jiffies::NSEC_PER_JIFFY, timekeeping::update_wall_time};
|
||||
@ -258,7 +259,7 @@ pub fn schedule_timeout(mut timeout: i64) -> Result<i64, SystemError> {
|
||||
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
|
||||
ProcessManager::mark_sleep(true).ok();
|
||||
drop(irq_guard);
|
||||
sched();
|
||||
schedule(SchedMode::SM_PREEMPT);
|
||||
return Ok(MAX_TIMEOUT);
|
||||
} else if timeout < 0 {
|
||||
kerror!("timeout can't less than 0");
|
||||
@ -277,7 +278,7 @@ pub fn schedule_timeout(mut timeout: i64) -> Result<i64, SystemError> {
|
||||
|
||||
drop(irq_guard);
|
||||
|
||||
sched();
|
||||
schedule(SchedMode::SM_PREEMPT);
|
||||
let time_remaining: i64 = timeout - TIMER_JIFFIES.load(Ordering::SeqCst) as i64;
|
||||
if time_remaining >= 0 {
|
||||
// 被提前唤醒,返回剩余时间
|
||||
|
Reference in New Issue
Block a user