Skip to content
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

loadbalance pr1 #89

Open
wants to merge 72 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
080b1b3
添加负载均衡功能,支持线程窃取和每个线程在生成时选择队列,还在调
githubmomoko May 13, 2023
417b2d7
正在调试
githubmomoko May 13, 2023
62513ab
放弃了“
githubmomoko May 19, 2023
eccb447
qwq
githubmomoko May 20, 2023
e093737
第一个 bug“
githubmomoko May 20, 2023
4b1bb47
看起来能窃取了,还有 bug“
githubmomoko May 20, 2023
042b8dc
qwq
githubmomoko May 20, 2023
5fd9158
修改前暂存
githubmomoko May 20, 2023
f663052
没有 irq 的版本修好了
githubmomoko May 20, 2023
c793681
bug 修好了,现在跑 parallel 能正确多核并行
githubmomoko May 20, 2023
4999dbd
bug 修好了,现在跑 parallel 能正确多核并行
githubmomoko May 20, 2023
0a53eaa
尝试修改 preempt 相关,还没调完
githubmomoko May 20, 2023
ba1d10d
修改了一下 unbalance 测例
githubmomoko May 20, 2023
af7b596
修改了一点测例
githubmomoko May 20, 2023
73cffc0
暂存
githubmomoko May 24, 2023
b6f862d
暂存
githubmomoko May 25, 2023
bbeaea0
qwq
githubmomoko May 25, 2023
2a87244
暂存
githubmomoko May 26, 2023
a3a0495
MLE:喵喵喵?
githubmomoko May 26, 2023
c30f093
暂存
githubmomoko May 26, 2023
8f2cb3e
暂存
githubmomoko May 26, 2023
fb4f37c
暂存
githubmomoko May 26, 2023
19b1a77
暂存
githubmomoko May 26, 2023
43ba660
我的 resched 被 DDoS 了 qwq
githubmomoko May 27, 2023
6b6cf14
我的 resched 被 DDoS 了 qwq
githubmomoko May 27, 2023
8915476
我的 resched 被 DDoS 了 qwq
githubmomoko May 27, 2023
aa9f753
好歹调通双核了
githubmomoko May 27, 2023
0543458
好歹调通单核了
githubmomoko May 27, 2023
957daaa
暂存:
githubmomoko May 27, 2023
e2f8e9f
弃疗了
githubmomoko May 27, 2023
c3f218a
bug修复
githubmomoko May 28, 2023
8b5bf74
增加笔记
githubmomoko Jun 2, 2023
ef197b8
Merge remote-tracking branch 'upstream/main' into loadbalance_new
githubmomoko Jun 2, 2023
2b8bbb3
完成 unbalance 测例,测试得到,在四核和 unbalance 测例的设定下,线程窃取能增加 10%的性能
githubmomoko Jun 2, 2023
fd196c5
添加 wakeup 测例
githubmomoko Jun 2, 2023
f41087d
调整 wakeup 测例
githubmomoko Jun 2, 2023
23129f7
wakeup?
githubmomoko Jun 2, 2023
caf50e4
Merge remote-tracking branch 'upstream/main' into loadbalance_new
githubmomoko Jun 2, 2023
79ba3bc
添加测试
githubmomoko Jun 2, 2023
c23c3d6
修改一些格式
githubmomoko Jun 2, 2023
f3681f0
remove qwq.txt
githubmomoko Jun 2, 2023
7488c42
delete some files
githubmomoko Jun 2, 2023
0a50cb3
OK
githubmomoko Jun 2, 2023
e805a74
fix some ci
githubmomoko Jun 3, 2023
27541a0
暂存
githubmomoko Jun 4, 2023
9560932
修复 yield test 触发的 bug
githubmomoko Jun 4, 2023
7b1deb0
???
githubmomoko Jun 5, 2023
1061277
修了一个大 bug
githubmomoko Jun 6, 2023
844ad5e
暂存“
githubmomoko Jun 6, 2023
a7a11f9
qwq
githubmomoko Jun 6, 2023
0e5f123
Merge branch 'main' into loadbalance_pr1
equation314 Jun 6, 2023
41167ab
format some codes
equation314 Jun 6, 2023
2c1980e
修改成闭包形式,不知道对不对
githubmomoko Jun 6, 2023
a293812
Merge branch 'loadbalance_pr1' of github.com:131131yhx/arceos into lo…
githubmomoko Jun 6, 2023
e634133
除了 priority 似乎没问题?刚才可能是电脑坏了
githubmomoko Jun 6, 2023
2822e4f
fix bug
githubmomoko Jun 7, 2023
c1a97a3
???
githubmomoko Jun 7, 2023
73e641e
大改前更新
githubmomoko Jun 7, 2023
b7e8443
fix ci, close threadsteal
githubmomoko Jun 7, 2023
0bbb6f4
check gc task
githubmomoko Jun 7, 2023
604df8d
gc task problem fixed
githubmomoko Jun 7, 2023
f115677
fix format
githubmomoko Jun 7, 2023
54f3519
暂存
githubmomoko Jun 7, 2023
468ce47
暂存“
githubmomoko Jun 7, 2023
8a39025
enlarge stack size in axtask/tests.rs
githubmomoko Jun 7, 2023
59856e5
enlarge stack size in axtask/tests.rs
githubmomoko Jun 7, 2023
3f5c541
fix clippy
githubmomoko Jun 7, 2023
38edaa0
fix format
githubmomoko Jun 7, 2023
99678e5
fix format
githubmomoko Jun 7, 2023
bfde7ab
shrink stack size in axconfig
githubmomoko Jun 7, 2023
e811f36
remove a flag check in if_empty_steal
githubmomoko Jun 8, 2023
5e23df0
fix ci
githubmomoko Jun 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
暂存
githubmomoko committed May 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 73cffc0a7a1ec10425f5328da5bc1b42c4fd82be
2 changes: 2 additions & 0 deletions modules/axruntime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -152,6 +152,8 @@ pub extern "C" fn rust_main(cpu_id: usize, dtb: usize) -> ! {
info!("Initialize platform devices...");
axhal::platform_init();

info!("tmptmp");

#[cfg(feature = "multitask")]
axtask::init_scheduler();

3 changes: 3 additions & 0 deletions modules/axruntime/src/mp.rs
Original file line number Diff line number Diff line change
@@ -44,12 +44,15 @@ pub extern "C" fn rust_main_secondary(cpu_id: usize) -> ! {

info!("Secondary CPU {} init OK.", cpu_id);
super::INITED_CPUS.fetch_add(1, Ordering::Relaxed);
info!("tmp1");

while !super::is_init_ok() {
core::hint::spin_loop();
}
info!("tmp2");

axhal::arch::enable_irqs();
info!("tmp3");

#[cfg(feature = "multitask")]
axtask::run_idle();
2 changes: 1 addition & 1 deletion modules/axtask/src/api.rs
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ where
let task = TaskInner::new(f, "", axconfig::TASK_STACK_SIZE);
let target_cpu = LOAD_BALANCE_ARR[get_current_cpu_id()].find_target_cpu();
//info!("exit 233");
task.set_queue_id(target_cpu);
//task.set_queue_id(target_cpu);
RUN_QUEUE[target_cpu].add_task(task);
//info!("exit 234");
}
31 changes: 24 additions & 7 deletions modules/axtask/src/run_queue.rs
Original file line number Diff line number Diff line change
@@ -38,14 +38,17 @@ impl AxRunQueue {
let gc_task = TaskInner::new(gc_entry, "gc", axconfig::TASK_STACK_SIZE);
let mut scheduler = SpinNoIrq::new(Scheduler::new());

gc_task.set_queue_id(id as isize);
scheduler.lock().add_task(gc_task);
Self { scheduler, id}
}

pub fn add_task(&self, task: AxTaskRef) {
task.set_queue_id(self.id as isize);
debug!("task spawn: {}", task.id_name());
assert!(task.is_ready());
LOAD_BALANCE_ARR[self.id].add_weight(1);
trace!("load balance weight for id {}: {}", self.id, LOAD_BALANCE_ARR[self.id].get_weight());
trace!("add task in queue {}, now the weight is {}", self.id, LOAD_BALANCE_ARR[self.id].get_weight());
self.scheduler.lock().add_task(task);
}
@@ -116,10 +119,10 @@ impl AxRunQueue {
where
F: FnOnce(AxTaskRef),
{
debug!("block_current 1");
info!("block_current 1");
let curr = crate::current();
debug!("task block: {}", curr.id_name());
debug!("block_current 2");
info!("task block: {}", curr.id_name());
info!("block_current 2");
assert!(curr.is_running());
assert!(!curr.is_idle());

@@ -128,11 +131,11 @@ impl AxRunQueue {
assert!(curr.can_preempt(1));

curr.set_state(TaskState::Blocked);
debug!("block_current 3");
info!("block_current 3");
wait_queue_push(curr.clone());
debug!("block_current 4");
info!("block_current 4");
self.resched_inner(false);
debug!("block_current 5");
info!("block_current 5");
}

pub fn unblock_task(&self, task: AxTaskRef, resched: bool) {
@@ -141,8 +144,10 @@ impl AxRunQueue {
debug!("123");
task.set_state(TaskState::Ready);
debug!("234");
task.set_queue_id(self.id as isize);
self.scheduler.lock().add_task(task); // TODO: priority
LOAD_BALANCE_ARR[self.id].add_weight(1);
trace!("load balance weight for id {}: {}", self.id, LOAD_BALANCE_ARR[self.id].get_weight());
debug!("345");
if resched {
#[cfg(feature = "preempt")]
@@ -187,11 +192,14 @@ impl AxRunQueue {
debug!("steal 2");
// 这里可能有同步问题,简单起见,如果 task 是 None 那么就不窃取。
if let Some(tk) = task {
tk.set_queue_id(self.id as isize);
queuelock.add_task(tk);
debug!("steal 3");
LOAD_BALANCE_ARR[next as usize].add_weight(-1);
trace!("load balance weight for id {}: {}", next as usize, LOAD_BALANCE_ARR[next as usize].get_weight());
debug!("steal 4");
LOAD_BALANCE_ARR[id].add_weight(1);
trace!("load balance weight for id {}: {}", id, LOAD_BALANCE_ARR[id].get_weight());
debug!("steal 5");
}
}
@@ -207,18 +215,27 @@ impl AxRunQueue {
debug!("resched inner 4");
if !prev.is_idle() {
debug!("resched inner 5");
prev.set_queue_id(self.id as isize);
self.scheduler.lock().put_prev_task(prev.clone(), preempt);
LOAD_BALANCE_ARR[self.id].add_weight(-1); //?
LOAD_BALANCE_ARR[self.id].add_weight(1); //?
trace!("load balance weight for id {}: {}", self.id, LOAD_BALANCE_ARR[self.id].get_weight());
debug!("resched inner 6");
}
}
debug!("resched inner 7");
let mut flag = false;
let next = self.scheduler.lock().pick_next_task().unwrap_or_else(|| unsafe {
// Safety: IRQs must be disabled at this time.
LOAD_BALANCE_ARR[self.id].add_weight(1); // 后面需要减一,由于是 IDLE 所以不用减,先加一
trace!("load balance weight for id {}: {}", self.id, LOAD_BALANCE_ARR[self.id].get_weight());
flag = true;
IDLE_TASK.current_ref_raw().get_unchecked().clone()
});
if !flag {
next.set_queue_id(-1);
}
LOAD_BALANCE_ARR[self.id].add_weight(-1); //?
trace!("load balance weight for id {}: {}", self.id, LOAD_BALANCE_ARR[self.id].get_weight());
debug!("resched inner 8");
// TODO: 注意需要对所有 pick_next_task 后面都要判断是否队列空,如果是则需要执行线程窃取
self.if_empty_steal();
18 changes: 10 additions & 8 deletions modules/axtask/src/task.rs
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ impl TaskInner {
}

/// set queue id
pub fn set_queue_id(&self, id: usize) {
pub fn set_queue_id(&self, id: isize) {
self.in_which_queue.store(id as isize, Ordering::Release);
}
}
@@ -230,24 +230,26 @@ impl TaskInner {
pub(crate) fn enable_preempt(&self, resched: bool) {
if self.preempt_disable_count.fetch_sub(1, Ordering::Relaxed) == 1 && resched {
// If current task is pending to be preempted, do rescheduling.
self.current_check_preempt_pending();
Self::current_check_preempt_pending();
}
}

#[cfg(feature = "preempt")]
fn current_check_preempt_pending(&self) {
fn current_check_preempt_pending() {
let curr = crate::current();
if curr.need_resched.load(Ordering::Acquire) && curr.can_preempt(0) {
//let mut rq = crate::RUN_QUEUE.lock();
if curr.need_resched.load(Ordering::Acquire) {
//assert!(self.in_which_queue.load(Ordering::Acquire) >= 0);
if self.in_which_queue.load(Ordering::Acquire) >= 0 {
crate::RUN_QUEUE[self.in_which_queue.load(Ordering::Acquire) as usize].resched();
if curr.in_which_queue.load(Ordering::Acquire) >= 0 {
info!("qwq1 {}", curr.in_which_queue.load(Ordering::Acquire));
crate::RUN_QUEUE[curr.in_which_queue.load(Ordering::Acquire) as usize].resched();
} else {
// qwq???
//for i in 0..axconfig.SMP {
// crate::RUN_QUEUE[i].resched();
//}
info!("qwq2");
/*for i in 0..axconfig::SMP {
crate::RUN_QUEUE[i].resched();
}*/
}
}
}
2 changes: 1 addition & 1 deletion modules/axtask/src/timers.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ impl TimerEvent for TaskWakeupEvent {
fn callback(self, _now: TimeValue) {
self.0.set_in_timer_list(false);
let target_cpu = LOAD_BALANCE_ARR[get_current_cpu_id()].find_target_cpu();
self.0.set_queue_id(target_cpu);
//self.0.set_queue_id(target_cpu);
RUN_QUEUE[target_cpu].unblock_task(self.0, true);
}
}
12 changes: 6 additions & 6 deletions modules/axtask/src/wait_queue.rs
Original file line number Diff line number Diff line change
@@ -69,12 +69,12 @@ impl WaitQueue {
/// Blocks the current task and put it into the wait queue, until other task
/// notifies it.
pub fn wait(&self) {
debug!("lock begin 7");
info!("lock begin 7");
RUN_QUEUE[get_current_cpu_id()].block_current(|task| {
task.set_in_wait_queue(true);
self.queue.lock().push_back((task, get_current_cpu_id()))
});
debug!("lock end 7");
info!("lock end 7");
self.cancel_events(crate::current());
}

@@ -112,12 +112,12 @@ impl WaitQueue {
);
crate::timers::set_alarm_wakeup(deadline, curr.clone());

debug!("lock begin 5");
info!("lock begin 5");
RUN_QUEUE[get_current_cpu_id()].block_current(|task| {
task.set_in_wait_queue(true);
self.queue.lock().push_back((task, get_current_cpu_id()))
});
debug!("lock end 5");
info!("lock end 5");
let timeout = curr.in_wait_queue(); // still in the wait queue, must have timed out
self.cancel_events(curr);
timeout
@@ -207,7 +207,7 @@ impl WaitQueue {
task.set_in_wait_queue(false);
let target_cpu = LOAD_BALANCE_ARR[get_current_cpu_id()].find_target_cpu();
let task = wq.remove(index).unwrap().0;
task.set_queue_id(target_cpu);
//task.set_queue_id(target_cpu);
RUN_QUEUE[target_cpu].unblock_task(task, resched);
//info!("exit 4");
true
@@ -222,7 +222,7 @@ impl WaitQueue {
//info!("111 {} {}", get_current_cpu_id(), tmp[0].1);
for i in 0..tmp.len() {
tmp[i].0.set_in_wait_queue(false);
tmp[i].0.set_queue_id(queueid);
//tmp[i].0.set_queue_id(queueid);
rq.unblock_task(tmp[i].0.clone(), resched);
drop(tmp);
return true;