mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-20 14:16:33 +00:00
重写SMP模块 (#633)
* 修复cpumask的迭代器的错误。 * 能进系统(AP核心还没有初始化自身) * 初始化ap core * 修改percpu * 删除无用的cpu.c * riscv64编译通过
This commit is contained in:
@ -33,7 +33,7 @@ pub mod syscall;
|
||||
pub mod ucontext;
|
||||
|
||||
/// 内核INIT进程的用户地址空间结构体(仅在process_init中初始化)
|
||||
static mut __INITIAL_PROCESS_ADDRESS_SPACE: Option<Arc<AddressSpace>> = None;
|
||||
static mut __IDLE_PROCESS_ADDRESS_SPACE: Option<Arc<AddressSpace>> = None;
|
||||
|
||||
bitflags! {
|
||||
/// Virtual memory flags
|
||||
@ -74,29 +74,29 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取内核INIT进程的用户地址空间结构体
|
||||
/// 获取内核IDLE进程的用户地址空间结构体
|
||||
#[allow(non_snake_case)]
|
||||
#[inline(always)]
|
||||
pub fn INITIAL_PROCESS_ADDRESS_SPACE() -> Arc<AddressSpace> {
|
||||
pub fn IDLE_PROCESS_ADDRESS_SPACE() -> Arc<AddressSpace> {
|
||||
unsafe {
|
||||
return __INITIAL_PROCESS_ADDRESS_SPACE
|
||||
return __IDLE_PROCESS_ADDRESS_SPACE
|
||||
.as_ref()
|
||||
.expect("INITIAL_PROCESS_ADDRESS_SPACE is null")
|
||||
.expect("IDLE_PROCESS_ADDRESS_SPACE is null")
|
||||
.clone();
|
||||
}
|
||||
}
|
||||
|
||||
/// 设置内核INIT进程的用户地址空间结构体全局变量
|
||||
/// 设置内核IDLE进程的用户地址空间结构体全局变量
|
||||
#[allow(non_snake_case)]
|
||||
pub unsafe fn set_INITIAL_PROCESS_ADDRESS_SPACE(address_space: Arc<AddressSpace>) {
|
||||
pub unsafe fn set_IDLE_PROCESS_ADDRESS_SPACE(address_space: Arc<AddressSpace>) {
|
||||
static INITIALIZED: AtomicBool = AtomicBool::new(false);
|
||||
if INITIALIZED
|
||||
.compare_exchange(false, true, Ordering::SeqCst, Ordering::Acquire)
|
||||
.is_err()
|
||||
{
|
||||
panic!("INITIAL_PROCESS_ADDRESS_SPACE is already initialized");
|
||||
panic!("IDLE_PROCESS_ADDRESS_SPACE is already initialized");
|
||||
}
|
||||
__INITIAL_PROCESS_ADDRESS_SPACE = Some(address_space);
|
||||
__IDLE_PROCESS_ADDRESS_SPACE = Some(address_space);
|
||||
}
|
||||
|
||||
/// @brief 将内核空间的虚拟地址转换为物理地址
|
||||
|
@ -3,9 +3,11 @@ use core::sync::atomic::AtomicU32;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::{
|
||||
include::bindings::bindings::smp_get_total_cpu,
|
||||
libs::lazy_init::Lazy,
|
||||
smp::{core::smp_get_processor_id, cpu::ProcessorId},
|
||||
smp::{
|
||||
core::smp_get_processor_id,
|
||||
cpu::{smp_cpu_manager, ProcessorId},
|
||||
},
|
||||
};
|
||||
|
||||
/// 系统中的CPU数量
|
||||
@ -29,8 +31,9 @@ impl PerCpu {
|
||||
if CPU_NUM.load(core::sync::atomic::Ordering::SeqCst) != 0 {
|
||||
panic!("PerCpu::init() called twice");
|
||||
}
|
||||
let cpus = unsafe { smp_get_total_cpu() };
|
||||
assert!(cpus > 0, "PerCpu::init(): smp_get_total_cpu() returned 0");
|
||||
let cpus = smp_cpu_manager().present_cpus_count();
|
||||
assert!(cpus > 0, "PerCpu::init(): present_cpus_count() returned 0");
|
||||
|
||||
CPU_NUM.store(cpus, core::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
@ -80,17 +83,19 @@ impl<T> PerCpuVar<T> {
|
||||
&self.inner[cpu_id.data() as usize]
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
pub fn get_mut(&self) -> &mut T {
|
||||
let cpu_id = smp_get_processor_id();
|
||||
&mut self.inner[cpu_id.data() as usize]
|
||||
unsafe {
|
||||
&mut (self as *const Self as *mut Self).as_mut().unwrap().inner[cpu_id.data() as usize]
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn force_get(&self, cpu_id: ProcessorId) -> &T {
|
||||
&self.inner[cpu_id.data() as usize]
|
||||
}
|
||||
|
||||
pub unsafe fn force_get_mut(&mut self, cpu_id: ProcessorId) -> &mut T {
|
||||
&mut self.inner[cpu_id.data() as usize]
|
||||
pub unsafe fn force_get_mut(&self, cpu_id: ProcessorId) -> &mut T {
|
||||
&mut (self as *const Self as *mut Self).as_mut().unwrap().inner[cpu_id.data() as usize]
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user