mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
fix(riscv/process): 把riscv的调度时钟节拍率与HZ同步,并且修复切换到用户态的时候忘了在内核态关中断的bug (#780)
This commit is contained in:
parent
13b057cc0f
commit
942cf26b48
@ -1,3 +1,4 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
pub const CSR_SSTATUS: usize = 0x100;
|
pub const CSR_SSTATUS: usize = 0x100;
|
||||||
pub const CSR_SSCRATCH: usize = 0x140;
|
pub const CSR_SSCRATCH: usize = 0x140;
|
||||||
pub const CSR_SEPC: usize = 0x141;
|
pub const CSR_SEPC: usize = 0x141;
|
||||||
|
@ -62,6 +62,7 @@ pub(super) struct LocalContext {
|
|||||||
pub user_sp: usize,
|
pub user_sp: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
impl LocalContext {
|
impl LocalContext {
|
||||||
pub fn new(cpu: ProcessorId) -> Self {
|
pub fn new(cpu: ProcessorId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -131,7 +132,7 @@ pub(super) fn init_local_context() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SmpCpuManager {
|
impl SmpCpuManager {
|
||||||
pub fn arch_init(boot_cpu: ProcessorId) {
|
pub fn arch_init(_boot_cpu: ProcessorId) {
|
||||||
// todo: 读取所有可用的CPU
|
// todo: 读取所有可用的CPU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
use alloc::{
|
use alloc::sync::{Arc, Weak};
|
||||||
string::String,
|
|
||||||
sync::{Arc, Weak},
|
|
||||||
vec::Vec,
|
|
||||||
};
|
|
||||||
use core::{
|
use core::{
|
||||||
arch::asm,
|
arch::asm,
|
||||||
intrinsics::unlikely,
|
intrinsics::unlikely,
|
||||||
@ -28,7 +24,6 @@ use crate::{
|
|||||||
PROCESS_SWITCH_RESULT,
|
PROCESS_SWITCH_RESULT,
|
||||||
},
|
},
|
||||||
smp::cpu::ProcessorId,
|
smp::cpu::ProcessorId,
|
||||||
syscall::Syscall,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -61,12 +56,12 @@ pub unsafe fn arch_switch_to_user(trap_frame: TrapFrame) -> ! {
|
|||||||
let trap_frame_vaddr = VirtAddr::new(
|
let trap_frame_vaddr = VirtAddr::new(
|
||||||
current_pcb.kernel_stack().stack_max_address().data() - core::mem::size_of::<TrapFrame>(),
|
current_pcb.kernel_stack().stack_max_address().data() - core::mem::size_of::<TrapFrame>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_pc = VirtAddr::new(ret_from_exception as usize);
|
let new_pc = VirtAddr::new(ret_from_exception as usize);
|
||||||
|
|
||||||
let mut arch_guard = current_pcb.arch_info_irqsave();
|
let mut arch_guard = current_pcb.arch_info_irqsave();
|
||||||
arch_guard.ksp = trap_frame_vaddr.data();
|
arch_guard.ksp = trap_frame_vaddr.data();
|
||||||
|
|
||||||
arch_guard.ra = new_pc.data();
|
|
||||||
drop(arch_guard);
|
drop(arch_guard);
|
||||||
|
|
||||||
drop(current_pcb);
|
drop(current_pcb);
|
||||||
@ -315,12 +310,6 @@ unsafe extern "C" fn switch_to_inner(prev: *mut ArchPCBInfo, next: *mut ArchPCBI
|
|||||||
|
|
||||||
/// 在切换上下文完成后的钩子函数(必须在这里加一个跳转函数,否则会出现relocation truncated to fit: R_RISCV_JAL错误)
|
/// 在切换上下文完成后的钩子函数(必须在这里加一个跳转函数,否则会出现relocation truncated to fit: R_RISCV_JAL错误)
|
||||||
unsafe extern "C" fn before_switch_finish_hook() {
|
unsafe extern "C" fn before_switch_finish_hook() {
|
||||||
let pcb = ProcessManager::current_pcb();
|
|
||||||
// kdebug!(
|
|
||||||
// "before_switch_finish_hook, pid: {:?}, name: {:?}",
|
|
||||||
// pcb.pid(),
|
|
||||||
// pcb.basic().name()
|
|
||||||
// );
|
|
||||||
switch_finish_hook();
|
switch_finish_hook();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,6 @@ impl Syscall {
|
|||||||
regs.epc = load_result.entry_point().data();
|
regs.epc = load_result.entry_point().data();
|
||||||
regs.status.update_spp(SPP::User);
|
regs.status.update_spp(SPP::User);
|
||||||
regs.status.update_fs(FS::Clean);
|
regs.status.update_fs(FS::Clean);
|
||||||
regs.status.update_sie(true);
|
|
||||||
regs.status.update_sum(true);
|
regs.status.update_sum(true);
|
||||||
|
|
||||||
drop(param);
|
drop(param);
|
||||||
@ -111,7 +110,8 @@ impl Syscall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// ## 用于控制和查询与体系结构相关的进程特定选项
|
/// ## 用于控制和查询与体系结构相关的进程特定选项
|
||||||
pub fn arch_prctl(option: usize, arg2: usize) -> Result<usize, SystemError> {
|
#[allow(dead_code)]
|
||||||
|
pub fn arch_prctl(_option: usize, _arg2: usize) -> Result<usize, SystemError> {
|
||||||
unimplemented!("Syscall::arch_prctl")
|
unimplemented!("Syscall::arch_prctl")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ impl SMPArch for RiscV64SMPArch {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_cpu(cpu_id: ProcessorId, hp_state: &CpuHpCpuState) -> Result<(), SystemError> {
|
fn start_cpu(_cpu_id: ProcessorId, _hp_state: &CpuHpCpuState) -> Result<(), SystemError> {
|
||||||
kwarn!("RiscV64SMPArch::start_cpu() is not implemented");
|
kwarn!("RiscV64SMPArch::start_cpu() is not implemented");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
use crate::driver::clocksource::acpi_pm::{acpi_pm_read_verified, PMTMR_IO_PORT};
|
#[allow(dead_code)]
|
||||||
use core::sync::atomic::Ordering;
|
|
||||||
|
|
||||||
pub const ACPI_PM_OVERRUN: u64 = 1 << 24;
|
pub const ACPI_PM_OVERRUN: u64 = 1 << 24;
|
||||||
|
|
||||||
/// Number of PMTMR ticks expected during calibration run
|
/// Number of PMTMR ticks expected during calibration run
|
||||||
@ -12,6 +10,8 @@ pub const ACPI_PM_MASK: u64 = 0xffffff;
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub fn acpi_pm_read_early() -> u32 {
|
pub fn acpi_pm_read_early() -> u32 {
|
||||||
|
use crate::driver::clocksource::acpi_pm::{acpi_pm_read_verified, PMTMR_IO_PORT};
|
||||||
|
use core::sync::atomic::Ordering;
|
||||||
let port = unsafe { PMTMR_IO_PORT.load(Ordering::SeqCst) };
|
let port = unsafe { PMTMR_IO_PORT.load(Ordering::SeqCst) };
|
||||||
|
|
||||||
// 如果端口为零直接返回
|
// 如果端口为零直接返回
|
||||||
@ -25,6 +25,7 @@ pub fn acpi_pm_read_early() -> u32 {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg(not(target_arch = "x86_64"))]
|
#[cfg(not(target_arch = "x86_64"))]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn acpi_pm_read_early() -> u32 {
|
pub fn acpi_pm_read_early() -> u32 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ fn read_pmtmr() -> u32 {
|
|||||||
///
|
///
|
||||||
/// ## 返回值
|
/// ## 返回值
|
||||||
/// - u32: 读取到的acpi_pmtmr值
|
/// - u32: 读取到的acpi_pmtmr值
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn acpi_pm_read_verified() -> u32 {
|
pub fn acpi_pm_read_verified() -> u32 {
|
||||||
let mut v2: u32;
|
let mut v2: u32;
|
||||||
|
|
||||||
@ -167,6 +168,7 @@ const PMTMR_EXPECTED_RATE: u64 =
|
|||||||
/// ## 返回值
|
/// ## 返回值
|
||||||
/// - i32:如果为0则表示在预期范围内,否则不在
|
/// - i32:如果为0则表示在预期范围内,否则不在
|
||||||
#[cfg(not(target_arch = "x86_64"))]
|
#[cfg(not(target_arch = "x86_64"))]
|
||||||
|
#[allow(dead_code)]
|
||||||
fn verify_pmtmr_rate() -> bool {
|
fn verify_pmtmr_rate() -> bool {
|
||||||
let mut count: u32 = 0;
|
let mut count: u32 = 0;
|
||||||
|
|
||||||
@ -216,6 +218,8 @@ fn find_acpi_pm_clock() -> Result<(), SystemError> {
|
|||||||
|
|
||||||
/// # 初始化ACPI PM Timer作为系统时钟源
|
/// # 初始化ACPI PM Timer作为系统时钟源
|
||||||
// #[unified_init(INITCALL_FS)]
|
// #[unified_init(INITCALL_FS)]
|
||||||
|
#[inline(never)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn init_acpi_pm_clocksource() -> Result<(), SystemError> {
|
pub fn init_acpi_pm_clocksource() -> Result<(), SystemError> {
|
||||||
let acpi_pm = Acpipm::new();
|
let acpi_pm = Acpipm::new();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -19,7 +19,7 @@ use crate::{
|
|||||||
mm::percpu::PerCpu,
|
mm::percpu::PerCpu,
|
||||||
process::ProcessManager,
|
process::ProcessManager,
|
||||||
smp::core::smp_get_processor_id,
|
smp::core::smp_get_processor_id,
|
||||||
time::TimeArch,
|
time::{clocksource::HZ, TimeArch},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct RiscVSbiTimer;
|
pub struct RiscVSbiTimer;
|
||||||
@ -48,6 +48,7 @@ impl RiscVSbiTimer {
|
|||||||
unsafe { riscv::register::sie::set_stimer() };
|
unsafe { riscv::register::sie::set_stimer() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn disable() {
|
fn disable() {
|
||||||
unsafe { riscv::register::sie::clear_stimer() };
|
unsafe { riscv::register::sie::clear_stimer() };
|
||||||
}
|
}
|
||||||
@ -59,8 +60,7 @@ pub fn riscv_sbi_timer_init_local() {
|
|||||||
assert_eq!(CurrentIrqArch::is_irq_enabled(), false);
|
assert_eq!(CurrentIrqArch::is_irq_enabled(), false);
|
||||||
|
|
||||||
if unsafe { INTERVAL_CNT } == 0 {
|
if unsafe { INTERVAL_CNT } == 0 {
|
||||||
// todo: 将来正式实现时,需要除以HZ
|
let new = riscv_time_base_freq() / HZ as usize;
|
||||||
let new = riscv_time_base_freq() / 3;
|
|
||||||
if new == 0 {
|
if new == 0 {
|
||||||
panic!("riscv_sbi_timer_init: failed to get timebase-frequency");
|
panic!("riscv_sbi_timer_init: failed to get timebase-frequency");
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub mod ahci;
|
pub mod ahci;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use core::{hint::spin_loop, sync::atomic::Ordering};
|
use core::{hint::spin_loop, sync::atomic::Ordering};
|
||||||
|
|
||||||
use alloc::{string::ToString, sync::Arc};
|
use alloc::sync::Arc;
|
||||||
use system_error::SystemError;
|
use system_error::SystemError;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
driver::{base::block::disk_info::Partition, disk::ahci},
|
driver::base::block::disk_info::Partition,
|
||||||
filesystem::{
|
filesystem::{
|
||||||
devfs::devfs_init,
|
devfs::devfs_init,
|
||||||
fat::fs::FATFileSystem,
|
fat::fs::FATFileSystem,
|
||||||
@ -116,7 +116,8 @@ fn migrate_virtual_filesystem(new_fs: Arc<dyn FileSystem>) -> Result<(), SystemE
|
|||||||
fn root_partition() -> Arc<Partition> {
|
fn root_partition() -> Arc<Partition> {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
{
|
{
|
||||||
return ahci::get_disks_by_name("ahci_disk_0".to_string())
|
use alloc::string::ToString;
|
||||||
|
return crate::driver::disk::ahci::get_disks_by_name("ahci_disk_0".to_string())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.lock()
|
.lock()
|
||||||
|
@ -74,7 +74,6 @@ fn switch_to_user() -> ! {
|
|||||||
|
|
||||||
let mut trap_frame = TrapFrame::new();
|
let mut trap_frame = TrapFrame::new();
|
||||||
// 逐个尝试运行init进程
|
// 逐个尝试运行init进程
|
||||||
|
|
||||||
if try_to_run_init_process("/bin/dragonreach", &mut trap_frame).is_err()
|
if try_to_run_init_process("/bin/dragonreach", &mut trap_frame).is_err()
|
||||||
&& try_to_run_init_process("/bin/init", &mut trap_frame).is_err()
|
&& try_to_run_init_process("/bin/init", &mut trap_frame).is_err()
|
||||||
&& try_to_run_init_process("/bin/sh", &mut trap_frame).is_err()
|
&& try_to_run_init_process("/bin/sh", &mut trap_frame).is_err()
|
||||||
@ -83,6 +82,7 @@ fn switch_to_user() -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 需要确保执行到这里之后,上面所有的资源都已经释放(比如arc之类的)
|
// 需要确保执行到这里之后,上面所有的资源都已经释放(比如arc之类的)
|
||||||
|
compiler_fence(Ordering::SeqCst);
|
||||||
|
|
||||||
unsafe { arch_switch_to_user(trap_frame) };
|
unsafe { arch_switch_to_user(trap_frame) };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user