From 2db453556d68c24604d003218fe2c92b9f6cbc1c Mon Sep 17 00:00:00 2001 From: WangRunji Date: Mon, 26 Nov 2018 16:58:45 +0800 Subject: [PATCH] try to fix interrupt & deadlock on RV32 --- crate/process/src/interrupt.rs | 4 ++-- crate/process/src/processor.rs | 3 +++ kernel/src/logging.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crate/process/src/interrupt.rs b/crate/process/src/interrupt.rs index e0f2283a..17d62ceb 100644 --- a/crate/process/src/interrupt.rs +++ b/crate/process/src/interrupt.rs @@ -10,8 +10,8 @@ pub unsafe fn disable_and_store() -> usize { #[cfg(target_arch = "riscv32")] pub unsafe fn disable_and_store() -> usize { let sstatus: usize; - asm!("csrrci $0, 0x100, 1" : "=r"(sstatus)); - sstatus & 1 + asm!("csrrci $0, 0x100, 2" : "=r"(sstatus)); + sstatus & 2 } #[inline(always)] diff --git a/crate/process/src/processor.rs b/crate/process/src/processor.rs index ef617fe0..d29d5602 100644 --- a/crate/process/src/processor.rs +++ b/crate/process/src/processor.rs @@ -92,7 +92,10 @@ impl Processor { } pub fn tick(&self) { + let flags = unsafe { interrupt::disable_and_store() }; let need_reschedule = self.manager().tick(self.pid()); + unsafe { interrupt::restore(flags); } + if need_reschedule { self.yield_now(); } diff --git a/kernel/src/logging.rs b/kernel/src/logging.rs index 513e0c08..86bd1c25 100644 --- a/kernel/src/logging.rs +++ b/kernel/src/logging.rs @@ -1,6 +1,6 @@ use core::fmt; use log::{self, Level, LevelFilter, Log, Metadata, Record}; -use spin::Mutex; +use crate::sync::SpinNoIrqLock as Mutex; use lazy_static::lazy_static; lazy_static! {