mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Clean up the implementation of scheduling class
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
3f951e0c0c
commit
c2f48a41db
@ -57,7 +57,7 @@ impl TryFrom<i8> for Nice {
|
||||
///
|
||||
/// It is an integer in the range of [0, 139]. Here we follow the Linux
|
||||
/// priority mappings: the relation between [`Priority`] and [`Nice`] is
|
||||
/// as such - prio = nice + 120 while the priority of [0, 100] are
|
||||
/// as such - prio = nice + 120 while the priority of [0, 99] are
|
||||
/// reserved for real-time tasks.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
|
||||
pub struct Priority(PriorityRange);
|
||||
@ -70,18 +70,12 @@ define_atomic_version_of_integer_like_type!(Priority, try_from = true, {
|
||||
});
|
||||
|
||||
impl Priority {
|
||||
pub const MIN_NORMAL: Self = Self::new(PriorityRange::new(100));
|
||||
|
||||
pub const fn new(range: PriorityRange) -> Self {
|
||||
Self(range)
|
||||
}
|
||||
|
||||
pub const fn default_real_time() -> Self {
|
||||
Self::new(PriorityRange::new(50))
|
||||
}
|
||||
|
||||
pub const fn idle() -> Self {
|
||||
Self::new(PriorityRange::new(PriorityRange::MAX))
|
||||
}
|
||||
|
||||
pub const fn range(&self) -> &PriorityRange {
|
||||
&self.0
|
||||
}
|
||||
@ -92,14 +86,14 @@ impl Priority {
|
||||
}
|
||||
|
||||
impl From<Nice> for Priority {
|
||||
fn from(value: Nice) -> Self {
|
||||
Self::new(PriorityRange::new(value.range().get() as u8 + 120))
|
||||
fn from(nice: Nice) -> Self {
|
||||
Self::new(PriorityRange::new((nice.range().get() as i16 + 120) as u8))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Priority> for Nice {
|
||||
fn from(priority: Priority) -> Self {
|
||||
Self::new(NiceRange::new((priority.range().get() - 100) as i8 - 20))
|
||||
Self::new(NiceRange::new(((priority.range().get() as i16 - 100) - 20) as i8))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::{collections::binary_heap::BinaryHeap, sync::Arc};
|
||||
use alloc::{collections::BinaryHeap, sync::Arc};
|
||||
use core::{
|
||||
cmp::{self, Reverse},
|
||||
sync::atomic::{AtomicU64, Ordering::*},
|
||||
sync::atomic::{AtomicU64, Ordering::Relaxed},
|
||||
};
|
||||
|
||||
use ostd::{
|
||||
|
@ -1,6 +1,13 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::*;
|
||||
use alloc::sync::Arc;
|
||||
|
||||
use ostd::task::{
|
||||
scheduler::{EnqueueFlags, UpdateFlags},
|
||||
Task,
|
||||
};
|
||||
|
||||
use super::{CurrentRuntime, SchedAttr, SchedClassRq};
|
||||
|
||||
/// The per-cpu run queue for the IDLE scheduling class.
|
||||
///
|
||||
|
@ -3,9 +3,10 @@
|
||||
#![warn(unused)]
|
||||
|
||||
use alloc::{boxed::Box, sync::Arc};
|
||||
use core::{fmt, sync::atomic::AtomicU64};
|
||||
use core::fmt;
|
||||
|
||||
use ostd::{
|
||||
arch::read_tsc as sched_clock,
|
||||
cpu::{all_cpus, AtomicCpuSet, CpuId, PinCurrentCpu},
|
||||
sync::SpinLock,
|
||||
task::{
|
||||
@ -18,6 +19,9 @@ use ostd::{
|
||||
trap::disable_local,
|
||||
};
|
||||
|
||||
use super::{priority::Nice, stats::SchedulerStats};
|
||||
use crate::thread::{AsThread, Thread};
|
||||
|
||||
mod policy;
|
||||
mod time;
|
||||
|
||||
@ -26,15 +30,7 @@ mod idle;
|
||||
mod real_time;
|
||||
mod stop;
|
||||
|
||||
use ostd::arch::read_tsc as sched_clock;
|
||||
|
||||
pub use self::policy::*;
|
||||
use self::policy::{SchedPolicyKind, SchedPolicyState};
|
||||
use super::{
|
||||
priority::{Nice, RangedU8},
|
||||
stats::SchedulerStats,
|
||||
};
|
||||
use crate::thread::{AsThread, Thread};
|
||||
use self::policy::{SchedPolicy, SchedPolicyKind, SchedPolicyState};
|
||||
|
||||
type SchedEntity = (Arc<Task>, Arc<Thread>);
|
||||
|
||||
|
@ -6,8 +6,8 @@ use atomic_integer_wrapper::define_atomic_version_of_integer_like_type;
|
||||
use int_to_c_enum::TryFromInt;
|
||||
use ostd::sync::SpinLock;
|
||||
|
||||
pub use super::real_time::RealTimePolicy;
|
||||
use crate::sched::priority::{Nice, Priority, RangedU8};
|
||||
pub use super::real_time::{RealTimePolicy, RtPrio};
|
||||
use crate::sched::priority::{Nice, Priority};
|
||||
|
||||
/// The User-chosen scheduling policy.
|
||||
///
|
||||
@ -35,13 +35,12 @@ pub(super) enum SchedPolicyKind {
|
||||
impl From<Priority> for SchedPolicy {
|
||||
fn from(priority: Priority) -> Self {
|
||||
match priority.range().get() {
|
||||
0 => SchedPolicy::Stop,
|
||||
rt @ 1..=99 => SchedPolicy::RealTime {
|
||||
rt_prio: RangedU8::new(rt),
|
||||
rt @ 0..=99 => SchedPolicy::RealTime {
|
||||
rt_prio: RtPrio::new(rt as u8),
|
||||
rt_policy: Default::default(),
|
||||
},
|
||||
100..=139 => SchedPolicy::Fair(priority.into()),
|
||||
_ => SchedPolicy::Idle,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,25 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::collections::vec_deque::VecDeque;
|
||||
use alloc::{collections::VecDeque, sync::Arc};
|
||||
use core::{
|
||||
array,
|
||||
num::NonZero,
|
||||
sync::atomic::{AtomicU8, Ordering::*},
|
||||
sync::atomic::{AtomicU64, AtomicU8, Ordering::Relaxed},
|
||||
};
|
||||
|
||||
use bitvec::{bitarr, BitArr};
|
||||
use ostd::{
|
||||
cpu::CpuId,
|
||||
task::{
|
||||
scheduler::{EnqueueFlags, UpdateFlags},
|
||||
Task,
|
||||
},
|
||||
};
|
||||
|
||||
use super::{time::base_slice_clocks, *};
|
||||
use super::{time::base_slice_clocks, CurrentRuntime, SchedAttr, SchedClassRq};
|
||||
use crate::{sched::priority::RangedU8, thread::AsThread};
|
||||
|
||||
pub type RtPrio = RangedU8<1, 99>;
|
||||
pub type RtPrio = RangedU8<0, 99>;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum RealTimePolicy {
|
||||
|
@ -1,6 +1,13 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::*;
|
||||
use alloc::sync::Arc;
|
||||
|
||||
use ostd::task::{
|
||||
scheduler::{EnqueueFlags, UpdateFlags},
|
||||
Task,
|
||||
};
|
||||
|
||||
use super::{CurrentRuntime, SchedAttr, SchedClassRq};
|
||||
|
||||
/// The per-cpu run queue for the STOP scheduling class.
|
||||
///
|
||||
|
Reference in New Issue
Block a user