mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 13:13:55 +00:00
Halt the idle CPUs
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
265bc25dd7
commit
30ec0be210
@ -4,3 +4,17 @@
|
||||
|
||||
pub mod context;
|
||||
pub mod local;
|
||||
|
||||
/// Halts the CPU.
|
||||
///
|
||||
/// This function halts the CPU until the next interrupt is received. By
|
||||
/// halting, the CPU might consume less power. Internally it is implemented
|
||||
/// using the `wfi` instruction.
|
||||
///
|
||||
/// Since the function sleeps the CPU, it should not be used within an atomic
|
||||
/// mode ([`crate::task::atomic_mode`]).
|
||||
#[track_caller]
|
||||
pub fn sleep_for_interrupt() {
|
||||
crate::task::atomic_mode::might_sleep();
|
||||
riscv::asm::wfi();
|
||||
}
|
||||
|
@ -4,3 +4,16 @@
|
||||
|
||||
pub mod context;
|
||||
pub mod local;
|
||||
|
||||
/// Halts the CPU.
|
||||
///
|
||||
/// This function halts the CPU until the next interrupt is received. By
|
||||
/// halting, the CPU will enter the C-0 state and consume less power.
|
||||
///
|
||||
/// Since the function sleeps the CPU, it should not be used within an atomic
|
||||
/// mode ([`crate::task::atomic_mode`]).
|
||||
#[track_caller]
|
||||
pub fn sleep_for_interrupt() {
|
||||
crate::task::atomic_mode::might_sleep();
|
||||
x86_64::instructions::hlt();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
//! Tasks are the unit of code execution.
|
||||
|
||||
pub(crate) mod atomic_mode;
|
||||
pub mod atomic_mode;
|
||||
mod kernel_stack;
|
||||
mod preempt;
|
||||
mod processor;
|
||||
|
@ -12,7 +12,7 @@ use spin::Once;
|
||||
|
||||
use super::{preempt::cpu_local, processor, Task};
|
||||
use crate::{
|
||||
cpu::{CpuId, PinCurrentCpu},
|
||||
cpu::{CpuId, CpuSet, PinCurrentCpu},
|
||||
prelude::*,
|
||||
task::disable_preempt,
|
||||
timer,
|
||||
@ -195,7 +195,9 @@ fn set_need_preempt(cpu_id: CpuId) {
|
||||
if preempt_guard.current_cpu() == cpu_id {
|
||||
cpu_local::set_need_preempt();
|
||||
} else {
|
||||
// TODO: Send IPIs to set remote CPU's `need_preempt`
|
||||
crate::smp::inter_processor_call(&CpuSet::from(cpu_id), || {
|
||||
cpu_local::set_need_preempt();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user