mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 18:03:25 +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
|
/// scheduling classes in its corresponding CPU core. The current task of this CPU
|
||||||
/// core is also stored in this structure.
|
/// core is also stored in this structure.
|
||||||
struct PerCpuClassRqSet {
|
struct PerCpuClassRqSet {
|
||||||
stop: Arc<stop::StopClassRq>,
|
stop: stop::StopClassRq,
|
||||||
real_time: real_time::RealTimeClassRq,
|
real_time: real_time::RealTimeClassRq,
|
||||||
fair: fair::FairClassRq,
|
fair: fair::FairClassRq,
|
||||||
idle: idle::IdleClassRq,
|
idle: idle::IdleClassRq,
|
||||||
@ -249,10 +249,9 @@ impl Scheduler for ClassScheduler {
|
|||||||
|
|
||||||
impl ClassScheduler {
|
impl ClassScheduler {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let stop = stop::StopClassRq::new();
|
|
||||||
let class_rq = |cpu| {
|
let class_rq = |cpu| {
|
||||||
SpinLock::new(PerCpuClassRqSet {
|
SpinLock::new(PerCpuClassRqSet {
|
||||||
stop: stop.clone(),
|
stop: stop::StopClassRq::new(),
|
||||||
real_time: real_time::RealTimeClassRq::new(cpu),
|
real_time: real_time::RealTimeClassRq::new(cpu),
|
||||||
fair: fair::FairClassRq::new(cpu),
|
fair: fair::FairClassRq::new(cpu),
|
||||||
idle: idle::IdleClassRq::new(),
|
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 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.
|
/// This is used for the most critical tasks, such as powering off and rebooting.
|
||||||
pub(super) struct StopClassRq {
|
pub(super) struct StopClassRq {
|
||||||
thread: SpinLock<Option<Arc<Thread>>>,
|
thread: Option<Arc<Thread>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StopClassRq {
|
impl StopClassRq {
|
||||||
pub fn new() -> Arc<Self> {
|
pub fn new() -> Self {
|
||||||
Arc::new(StopClassRq {
|
Self { thread: None }
|
||||||
thread: SpinLock::new(None),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Debug for StopClassRq {
|
impl core::fmt::Debug for StopClassRq {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
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")?;
|
write!(f, "Stop: occupied")?;
|
||||||
} else {
|
} else {
|
||||||
write!(f, "Stop: empty")?;
|
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>) {
|
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")
|
panic!("Multiple `stop` threads spawned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,11 +39,11 @@ impl SchedClassRq for Arc<StopClassRq> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&mut self) -> bool {
|
fn is_empty(&mut self) -> bool {
|
||||||
self.thread.lock().is_none()
|
self.thread.is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pick_next(&mut self) -> Option<Arc<Thread>> {
|
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 {
|
fn update_current(&mut self, _: &CurrentRuntime, _: &SchedAttr, _flags: UpdateFlags) -> bool {
|
||||||
|
Reference in New Issue
Block a user