重写SMP模块 (#633)

* 修复cpumask的迭代器的错误。

* 能进系统(AP核心还没有初始化自身)

* 初始化ap core

* 修改percpu

* 删除无用的cpu.c

* riscv64编译通过
This commit is contained in:
LoGin
2024-03-21 19:19:32 +08:00
committed by GitHub
parent 1d37ca6d17
commit 8cb2e9b344
44 changed files with 544 additions and 654 deletions

View File

@ -1,18 +1,18 @@
use system_error::SystemError;
use crate::{
arch::interrupt::ipi::send_ipi,
arch::{interrupt::ipi::send_ipi, CurrentSMPArch},
exception::ipi::{IpiKind, IpiTarget},
};
use self::{
core::smp_get_processor_id,
cpu::{smp_cpu_manager_init, ProcessorId},
cpu::{smp_cpu_manager, smp_cpu_manager_init, CpuHpCpuState, ProcessorId},
};
pub mod c_adapter;
pub mod core;
pub mod cpu;
pub mod init;
pub fn kick_cpu(cpu_id: ProcessorId) -> Result<(), SystemError> {
// todo: 增加对cpu_id的有效性检查
@ -27,10 +27,17 @@ pub trait SMPArch {
/// 该函数需要标记为 `#[inline(never)]`
fn prepare_cpus() -> Result<(), SystemError>;
/// 初始化SMP
/// 在smp初始化结束后执行一些必要的操作
///
/// 该函数需要标记为 `#[inline(never)]`
fn init() -> Result<(), SystemError>;
fn post_init() -> Result<(), SystemError> {
return Ok(());
}
/// 向目标CPU发送启动信号
///
/// 如果目标CPU已经启动返回Ok。
fn start_cpu(cpu_id: ProcessorId, hp_state: &CpuHpCpuState) -> Result<(), SystemError>;
}
/// 早期SMP初始化
@ -40,3 +47,10 @@ pub fn early_smp_init() -> Result<(), SystemError> {
return Ok(());
}
#[inline(never)]
pub fn smp_init() {
smp_cpu_manager().bringup_nonboot_cpus();
CurrentSMPArch::post_init().expect("SMP post init failed");
}