Skip to content

Commit cb034ed

Browse files
committed
nits and doc
1 parent f531a8d commit cb034ed

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/arch/x86_64/kernel/apic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +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() && !processor::supports_mwait() && scheduler::sleep_state::core_wake_up(core_id_to_wakeup) {
889+
if core_id_to_wakeup != core_id() && !processor::supports_mwait() && scheduler::sleep_state::try_wake_up(core_id_to_wakeup) {
890890
without_interrupts(|| {
891891
let apic_ids = CPU_LOCAL_APIC_IDS.lock();
892892
let local_apic_id = apic_ids[core_id_to_wakeup as usize];

src/arch/x86_64/kernel/interrupts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) fn enable_and_wait() {
8383
}
8484
} else {
8585
#[cfg(feature = "smp")]
86-
if !scheduler::sleep_state::core_sleep() {
86+
if !scheduler::sleep_state::try_sleep() {
8787
return;
8888
}
8989

src/scheduler/sleep_state.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct SleepState(AtomicU8);
1212

1313
/// # Race condition prevention
1414
///
15-
/// Two methods matter here: [crate::arch::interrupts::enable_and_wait] and [crate::arch::wakeup_core].
15+
/// Two methods matter here: `crate::arch::interrupts::enable_and_wait` and `crate::arch::wakeup_core`.
1616
/// `enable_and_wait` checks the status, ensuring it is set to 0+setting it to 1, then sleeps.
1717
/// `wakeup_core` checks the status, ensuring it is set to 1+setting it to 0, then issues interrupt.
1818
///
@@ -34,12 +34,12 @@ impl SleepState {
3434
const STATUS_DONT_SLEEP: u8 = 2;
3535

3636
fn new() -> Self {
37-
Self(AtomicU8::new(SleepState::STATUS_ACTIVE))
37+
Self(AtomicU8::new(Self::STATUS_ACTIVE))
3838
}
3939

4040
#[inline]
4141
fn set_active(&self) {
42-
self.0.store(SleepState::STATUS_ACTIVE, Ordering::SeqCst);
42+
self.0.store(Self::STATUS_ACTIVE, Ordering::SeqCst);
4343
}
4444

4545
/// Indicates that this core will go to HLT.
@@ -49,8 +49,8 @@ impl SleepState {
4949
if self
5050
.0
5151
.compare_exchange(
52-
SleepState::STATUS_ACTIVE,
53-
SleepState::STATUS_IDLE,
52+
Self::STATUS_ACTIVE,
53+
Self::STATUS_IDLE,
5454
Ordering::SeqCst,
5555
Ordering::Relaxed,
5656
)
@@ -84,10 +84,10 @@ impl SleepState {
8484
// Ask the core not to sleep.
8585
// This makes sure that if the two atomic operations become interleaved, the core will
8686
// not go to sleep with us assuming it was running.
87-
let previous_state = self.0.swap(SleepState::STATUS_DONT_SLEEP, Ordering::SeqCst);
87+
let previous_state = self.0.swap(Self::STATUS_DONT_SLEEP, Ordering::SeqCst);
8888

8989
// If the core was idle, we can actually wake it up
90-
if previous_state == SleepState::STATUS_IDLE {
90+
if previous_state == Self::STATUS_IDLE {
9191
// Again, this operation is not necessarily ordered.
9292
// - Another `go_to_sleep` could be processing, either BEFORE or AFTER the atomic op.
9393
// * BEFORE:
@@ -119,12 +119,17 @@ pub(super) fn install_for_core(core_id: CoreId) {
119119
.insert(core_id.try_into().unwrap(), SleepState::new());
120120
}
121121

122+
/// Tries to put the core to sleep.
123+
/// Returns `true` if the core can safely sleep, `false` if it should continue running.
122124
#[inline]
123-
pub fn core_sleep() -> bool {
125+
pub fn try_sleep() -> bool {
124126
CORE_HLT_STATE.read()[usize::try_from(core_id()).unwrap()].go_to_sleep()
125127
}
126128

129+
/// Tries to wake up the core.
130+
/// Returns `true` if the core should be woken up via an interrupt, `false` if the core is already
131+
/// running.
127132
#[inline]
128-
pub fn core_wake_up(core_id: CoreId) -> bool {
133+
pub fn try_wake_up(core_id: CoreId) -> bool {
129134
CORE_HLT_STATE.read()[usize::try_from(core_id).unwrap()].wake_up()
130135
}

0 commit comments

Comments
 (0)