Schedule tasks to APs in aster-nix

This commit is contained in:
Zhang Junyang
2024-08-22 19:23:33 +08:00
committed by Tate, Hongliang Tian
parent 5feb8f5de8
commit 47be0a909b
11 changed files with 548 additions and 481 deletions

View File

@ -35,6 +35,7 @@ use core::sync::atomic::Ordering;
use ostd::{
arch::qemu::{exit_qemu, QemuExitCode},
boot,
cpu::PinCurrentCpu,
};
use process::Process;
@ -83,7 +84,13 @@ pub fn main() {
component::init_all(component::parse_metadata!()).unwrap();
init();
ostd::IN_BOOTSTRAP_CONTEXT.store(false, Ordering::Relaxed);
// Spawn all AP idle threads.
ostd::boot::smp::register_ap_entry(ap_init);
// Spawn the first kernel thread on BSP.
Thread::spawn_kernel_thread(ThreadOptions::new(init_thread));
// Spawning functions in the bootstrap context will not return.
unreachable!()
}
@ -100,6 +107,25 @@ pub fn init() {
process::init();
}
fn ap_init() -> ! {
fn ap_idle_thread() {
let preempt_guard = ostd::task::disable_preempt();
let cpu_id = preempt_guard.current_cpu();
drop(preempt_guard);
log::info!("Kernel idle thread for CPU #{} started.", cpu_id);
loop {
Thread::yield_now();
}
}
let preempt_guard = ostd::task::disable_preempt();
let cpu_id = preempt_guard.current_cpu();
drop(preempt_guard);
Thread::spawn_kernel_thread(ThreadOptions::new(ap_idle_thread).cpu_affinity(cpu_id.into()));
// Spawning functions in the bootstrap context will not return.
unreachable!()
}
fn init_thread() {
println!(
"[kernel] Spawn init thread, tid = {}",