mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 01:43:22 +00:00
Make stop runqueue per-CPU
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
87da1a0787
commit
6cea8d2a8c
@ -49,7 +49,7 @@ pub struct ClassScheduler {
|
||||
/// scheduling classes in its corresponding CPU core. The current task of this CPU
|
||||
/// core is also stored in this structure.
|
||||
struct PerCpuClassRqSet {
|
||||
stop: Arc<stop::StopClassRq>,
|
||||
stop: stop::StopClassRq,
|
||||
real_time: real_time::RealTimeClassRq,
|
||||
fair: fair::FairClassRq,
|
||||
idle: idle::IdleClassRq,
|
||||
@ -249,10 +249,9 @@ impl Scheduler for ClassScheduler {
|
||||
|
||||
impl ClassScheduler {
|
||||
pub fn new() -> Self {
|
||||
let stop = stop::StopClassRq::new();
|
||||
let class_rq = |cpu| {
|
||||
SpinLock::new(PerCpuClassRqSet {
|
||||
stop: stop.clone(),
|
||||
stop: stop::StopClassRq::new(),
|
||||
real_time: real_time::RealTimeClassRq::new(cpu),
|
||||
fair: fair::FairClassRq::new(cpu),
|
||||
idle: idle::IdleClassRq::new(),
|
||||
|
@ -7,20 +7,18 @@ use super::*;
|
||||
/// 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>>>,
|
||||
thread: Option<Arc<Thread>>,
|
||||
}
|
||||
|
||||
impl StopClassRq {
|
||||
pub fn new() -> Arc<Self> {
|
||||
Arc::new(StopClassRq {
|
||||
thread: SpinLock::new(None),
|
||||
})
|
||||
pub fn new() -> Self {
|
||||
Self { thread: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for StopClassRq {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
if self.thread.lock().is_some() {
|
||||
if self.thread.is_some() {
|
||||
write!(f, "Stop: occupied")?;
|
||||
} else {
|
||||
write!(f, "Stop: empty")?;
|
||||
@ -29,9 +27,9 @@ impl core::fmt::Debug for StopClassRq {
|
||||
}
|
||||
}
|
||||
|
||||
impl SchedClassRq for Arc<StopClassRq> {
|
||||
impl SchedClassRq for StopClassRq {
|
||||
fn enqueue(&mut self, thread: Arc<Thread>, _: Option<EnqueueFlags>) {
|
||||
if self.thread.lock().replace(thread).is_some() {
|
||||
if self.thread.replace(thread).is_some() {
|
||||
panic!("Multiple `stop` threads spawned")
|
||||
}
|
||||
}
|
||||
@ -41,11 +39,11 @@ impl SchedClassRq for Arc<StopClassRq> {
|
||||
}
|
||||
|
||||
fn is_empty(&mut self) -> bool {
|
||||
self.thread.lock().is_none()
|
||||
self.thread.is_none()
|
||||
}
|
||||
|
||||
fn pick_next(&mut self) -> Option<Arc<Thread>> {
|
||||
self.thread.lock().take()
|
||||
self.thread.take()
|
||||
}
|
||||
|
||||
fn update_current(&mut self, _: &CurrentRuntime, _: &SchedAttr, _flags: UpdateFlags) -> bool {
|
||||
|
Reference in New Issue
Block a user