mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Scheduling class support
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
a260411a2a
commit
878f3f3760
55
kernel/src/sched/sched_class/stop.rs
Normal file
55
kernel/src/sched/sched_class/stop.rs
Normal file
@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The per-cpu run queue for the STOP scheduling class.
|
||||
///
|
||||
/// This is a singleton class, meaning that only one thread can be in this class at a time.
|
||||
/// This is used for the most critical tasks, such as powering off and rebooting.
|
||||
pub(super) struct StopClassRq {
|
||||
thread: SpinLock<Option<Arc<Thread>>>,
|
||||
}
|
||||
|
||||
impl StopClassRq {
|
||||
pub fn new() -> Arc<Self> {
|
||||
Arc::new(StopClassRq {
|
||||
thread: SpinLock::new(None),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for StopClassRq {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
if self.thread.lock().is_some() {
|
||||
write!(f, "Stop: occupied")?;
|
||||
} else {
|
||||
write!(f, "Stop: empty")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl SchedClassRq for Arc<StopClassRq> {
|
||||
fn enqueue(&mut self, thread: Arc<Thread>, _: Option<EnqueueFlags>) {
|
||||
if self.thread.lock().replace(thread).is_some() {
|
||||
panic!("Multiple `stop` threads spawned")
|
||||
}
|
||||
}
|
||||
|
||||
fn len(&mut self) -> usize {
|
||||
usize::from(!self.is_empty())
|
||||
}
|
||||
|
||||
fn is_empty(&mut self) -> bool {
|
||||
self.thread.lock().is_none()
|
||||
}
|
||||
|
||||
fn pick_next(&mut self) -> Option<Arc<Thread>> {
|
||||
self.thread.lock().take()
|
||||
}
|
||||
|
||||
fn update_current(&mut self, _: &CurrentRuntime, _: &SchedAttr, _flags: UpdateFlags) -> bool {
|
||||
// Stop threads has the lowest priority value. They should never be preempted.
|
||||
false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user