From be54a39592ff60fae6e729abaa3d4a26dd7f5624 Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Mon, 12 Aug 2024 13:04:53 +0000 Subject: [PATCH] Remove the preempt guard from the IRQ guard --- ostd/src/task/processor.rs | 10 ++++++++++ ostd/src/trap/irq.rs | 13 ++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ostd/src/task/processor.rs b/ostd/src/task/processor.rs index 4588b6732..48471908b 100644 --- a/ostd/src/task/processor.rs +++ b/ostd/src/task/processor.rs @@ -71,6 +71,11 @@ pub fn preempt(task: &Arc) { /// /// If the current task's status not [`TaskStatus::Runnable`], it will not be /// added to the scheduler. +/// +/// # Panics +/// +/// This function will panic if called while holding preemption locks or with +/// local IRQ disabled. fn switch_to_task(next_task: Arc) { let preemt_lock_count = PREEMPT_LOCK_COUNT.load(); if preemt_lock_count != 0 { @@ -80,6 +85,11 @@ fn switch_to_task(next_task: Arc) { ); } + assert!( + crate::arch::irq::is_local_enabled(), + "Switching task with local IRQ disabled" + ); + let irq_guard = crate::trap::disable_local(); let current_task_ptr = CURRENT_TASK_PTR.load(); diff --git a/ostd/src/trap/irq.rs b/ostd/src/trap/irq.rs index e6dbe7d1f..2d3935bf0 100644 --- a/ostd/src/trap/irq.rs +++ b/ostd/src/trap/irq.rs @@ -9,7 +9,6 @@ use trapframe::TrapFrame; use crate::{ arch::irq::{self, IrqCallbackHandle, IRQ_ALLOCATOR}, prelude::*, - task::{disable_preempt, DisablePreemptGuard}, Error, }; @@ -135,7 +134,6 @@ pub fn disable_local() -> DisabledLocalIrqGuard { #[must_use] pub struct DisabledLocalIrqGuard { was_enabled: bool, - preempt_guard: DisablePreemptGuard, } impl !Send for DisabledLocalIrqGuard {} @@ -146,11 +144,7 @@ impl DisabledLocalIrqGuard { if was_enabled { irq::disable_local(); } - let preempt_guard = disable_preempt(); - Self { - was_enabled, - preempt_guard, - } + Self { was_enabled } } /// Transfers the saved IRQ status of this guard to a new guard. @@ -158,10 +152,7 @@ impl DisabledLocalIrqGuard { pub fn transfer_to(&mut self) -> Self { let was_enabled = self.was_enabled; self.was_enabled = false; - Self { - was_enabled, - preempt_guard: disable_preempt(), - } + Self { was_enabled } } }