Skip to content

Commit

Permalink
暂时禁用load balance (#591)
Browse files Browse the repository at this point in the history
原因见issue: #571
  • Loading branch information
fslongjin committed Mar 12, 2024
1 parent 4374bd1 commit 818a64c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions kernel/src/sched/cfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl CFSQueue {
}
}
/// 获取运行队列的长度
#[allow(dead_code)]
pub fn get_cfs_queue_size(
queue: &SpinLockGuard<RBTree<i64, Arc<ProcessControlBlock>>>,
) -> usize {
Expand Down
27 changes: 15 additions & 12 deletions kernel/src/sched/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use core::{
use alloc::{sync::Arc, vec::Vec};

use crate::{
include::bindings::bindings::smp_get_total_cpu,
kinfo,
mm::percpu::PerCpu,
process::{AtomicPid, Pid, ProcessControlBlock, ProcessFlags, ProcessManager, ProcessState},
Expand Down Expand Up @@ -51,6 +50,7 @@ impl CpuExecuting {

// 获取某个cpu的负载情况,返回当前负载,cpu_id 是获取负载的cpu的id
// TODO:将获取负载情况调整为最近一段时间运行进程的数量
#[allow(dead_code)]
pub fn get_cpu_loads(cpu_id: ProcessorId) -> u32 {
let cfs_scheduler = __get_cfs_scheduler();
let rt_scheduler = __get_rt_scheduler();
Expand All @@ -64,19 +64,22 @@ pub fn get_cpu_loads(cpu_id: ProcessorId) -> u32 {
// 负载均衡
pub fn loads_balance(pcb: Arc<ProcessControlBlock>) {
// 对pcb的迁移情况进行调整

// 由于调度器问题,暂时不进行负载均衡,见issue: https://github.com/DragonOS-Community/DragonOS/issues/571
let min_loads_cpu_id = ProcessorId::new(0);

// 获取总的CPU数量
let cpu_num = unsafe { smp_get_total_cpu() };
// let cpu_num = unsafe { smp_get_total_cpu() };
// 获取当前负载最小的CPU的id
let mut min_loads_cpu_id = smp_get_processor_id();
let mut min_loads = get_cpu_loads(smp_get_processor_id());
for cpu_id in 0..cpu_num {
let cpu_id = ProcessorId::new(cpu_id);
let tmp_cpu_loads = get_cpu_loads(cpu_id);
if min_loads - tmp_cpu_loads > 0 {
min_loads_cpu_id = cpu_id;
min_loads = tmp_cpu_loads;
}
}
// let mut min_loads = get_cpu_loads(smp_get_processor_id());
// for cpu_id in 0..cpu_num {
// let cpu_id = ProcessorId::new(cpu_id);
// let tmp_cpu_loads = get_cpu_loads(cpu_id);
// if min_loads - tmp_cpu_loads > 0 {
// min_loads_cpu_id = cpu_id;
// min_loads = tmp_cpu_loads;
// }
// }

let pcb_cpu = pcb.sched_info().on_cpu();
// 将当前pcb迁移到负载最小的CPU
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/sched/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ impl RTQueue {
}
queue.push_front(pcb);
}

#[allow(dead_code)]
pub fn get_rt_queue_size(&mut self) -> usize {
let queue = self.locked_queue.lock_irqsave();
return queue.len();
Expand Down

0 comments on commit 818a64c

Please sign in to comment.