Skip to content

Commit 30cb3f9

Browse files
authored
Merge pull request #2468 from zyuiop/feat/smp-race-cond
smp: always wake up core when ready
2 parents 9160d28 + f4942c9 commit 30cb3f9

4 files changed

Lines changed: 1 addition & 26 deletions

File tree

src/arch/x86_64/kernel/apic.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,10 +886,7 @@ pub fn ipi_tlb_flush() {
886886
#[allow(unused_variables)]
887887
pub fn wakeup_core(core_id_to_wakeup: CoreId) {
888888
#[cfg(all(feature = "smp", not(feature = "idle-poll")))]
889-
if core_id_to_wakeup != core_id()
890-
&& !processor::supports_mwait()
891-
&& scheduler::take_core_hlt_state(core_id_to_wakeup)
892-
{
889+
if core_id_to_wakeup != core_id() && !processor::supports_mwait() {
893890
without_interrupts(|| {
894891
let apic_ids = CPU_LOCAL_APIC_IDS.lock();
895892
let local_apic_id = apic_ids[core_id_to_wakeup as usize];

src/arch/x86_64/kernel/core_local.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use alloc::boxed::Box;
22
use core::arch::asm;
33
use core::cell::Cell;
4-
#[cfg(feature = "smp")]
5-
use core::sync::atomic::AtomicBool;
64
use core::sync::atomic::Ordering;
75
use core::{mem, ptr};
86

@@ -34,8 +32,6 @@ pub(crate) struct CoreLocal {
3432
irq_statistics: &'static IrqStatistics,
3533
/// The core-local async executor.
3634
ex: StaticLocalExecutor<RawSpinMutex, RawRwSpinLock>,
37-
#[cfg(feature = "smp")]
38-
pub hlt: AtomicBool,
3935
/// Queues to handle incoming requests from the other cores
4036
#[cfg(feature = "smp")]
4137
pub scheduler_input: InterruptTicketMutex<SchedulerInput>,
@@ -63,8 +59,6 @@ impl CoreLocal {
6359
irq_statistics,
6460
ex: StaticLocalExecutor::new(),
6561
#[cfg(feature = "smp")]
66-
hlt: AtomicBool::new(false),
67-
#[cfg(feature = "smp")]
6862
scheduler_input: InterruptTicketMutex::new(SchedulerInput::new()),
6963
};
7064
let this = if core_id == 0 {

src/arch/x86_64/kernel/interrupts.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ pub(crate) fn enable_and_wait() {
8282
);
8383
}
8484
} else {
85-
#[cfg(feature = "smp")]
86-
crate::CoreLocal::get().hlt.store(true, Ordering::Relaxed);
8785
enable_and_hlt();
8886
}
8987
}

src/scheduler/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use alloc::sync::Arc;
88
use alloc::vec::Vec;
99
use core::cell::RefCell;
1010
use core::ptr;
11-
#[cfg(all(target_arch = "x86_64", feature = "smp"))]
12-
use core::sync::atomic::AtomicBool;
1311
use core::sync::atomic::{AtomicI32, AtomicU32, Ordering};
1412

1513
use ahash::RandomState;
@@ -40,8 +38,6 @@ static NO_TASKS: AtomicU32 = AtomicU32::new(0);
4038
#[cfg(feature = "smp")]
4139
static SCHEDULER_INPUTS: SpinMutex<Vec<&InterruptTicketMutex<SchedulerInput>>> =
4240
SpinMutex::new(Vec::new());
43-
#[cfg(all(target_arch = "x86_64", feature = "smp"))]
44-
static CORE_HLT_STATE: SpinMutex<Vec<&AtomicBool>> = SpinMutex::new(Vec::new());
4541
/// Map between Task ID and Queue of waiting tasks
4642
static WAITING_TASKS: InterruptTicketMutex<BTreeMap<TaskId, VecDeque<TaskHandle>>> =
4743
InterruptTicketMutex::new(BTreeMap::new());
@@ -891,19 +887,9 @@ pub(crate) fn add_current_core() {
891887
core_id.try_into().unwrap(),
892888
&CoreLocal::get().scheduler_input,
893889
);
894-
#[cfg(target_arch = "x86_64")]
895-
CORE_HLT_STATE
896-
.lock()
897-
.insert(core_id.try_into().unwrap(), &CoreLocal::get().hlt);
898890
}
899891
}
900892

901-
#[inline]
902-
#[cfg(all(target_arch = "x86_64", feature = "smp", not(feature = "idle-poll")))]
903-
pub(crate) fn take_core_hlt_state(core_id: CoreId) -> bool {
904-
CORE_HLT_STATE.lock()[usize::try_from(core_id).unwrap()].swap(false, Ordering::Acquire)
905-
}
906-
907893
#[inline]
908894
#[cfg(feature = "smp")]
909895
fn get_scheduler_input(core_id: CoreId) -> &'static InterruptTicketMutex<SchedulerInput> {

0 commit comments

Comments
 (0)