Remove priority field from OSTD Task struct

This commit is contained in:
jellllly420
2024-09-14 15:32:21 +08:00
committed by Tate, Hongliang Tian
parent 0a36760f7a
commit 8927031426
18 changed files with 258 additions and 252 deletions

View File

@ -16,7 +16,7 @@ use processor::current_task;
pub use self::{
preempt::{disable_preempt, DisabledPreemptGuard},
scheduler::info::{AtomicCpuId, Priority, TaskScheduleInfo},
scheduler::info::{AtomicCpuId, TaskScheduleInfo},
};
pub(crate) use crate::arch::task::{context_switch, TaskContext};
use crate::{cpu::CpuSet, prelude::*, user::UserSpace};
@ -124,7 +124,6 @@ pub struct TaskOptions {
func: Option<Box<dyn Fn() + Send + Sync>>,
data: Option<Box<dyn Any + Send + Sync>>,
user_space: Option<Arc<UserSpace>>,
priority: Priority,
cpu_affinity: CpuSet,
}
@ -138,7 +137,6 @@ impl TaskOptions {
func: Some(Box::new(func)),
data: None,
user_space: None,
priority: Priority::normal(),
cpu_affinity: CpuSet::new_full(),
}
}
@ -167,12 +165,6 @@ impl TaskOptions {
self
}
/// Sets the priority of the task.
pub fn priority(mut self, priority: Priority) -> Self {
self.priority = priority;
self
}
/// Sets the CPU affinity mask for the task.
///
/// The `cpu_affinity` parameter represents
@ -220,7 +212,6 @@ impl TaskOptions {
kstack,
schedule_info: TaskScheduleInfo {
cpu: AtomicCpuId::default(),
priority: self.priority,
cpu_affinity: self.cpu_affinity,
},
};

View File

@ -15,83 +15,12 @@ use crate::cpu::CpuSet;
/// [existential types](https://github.com/rust-lang/rfcs/pull/2492) do not
/// exist yet. So we decide to define them in OSTD.
pub struct TaskScheduleInfo {
/// Priority of the task.
pub priority: Priority,
/// The CPU that the task would like to be running on.
pub cpu: AtomicCpuId,
/// The CPUs that this task can run on.
pub cpu_affinity: CpuSet,
}
/// The priority of a real-time task.
pub const REAL_TIME_TASK_PRIORITY: u16 = 100;
/// The priority of a task.
///
/// Similar to Linux, a larger value represents a lower priority,
/// with a range of 0 to 139. Priorities ranging from 0 to 99 are considered real-time,
/// while those ranging from 100 to 139 are considered normal.
#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct Priority(u16);
impl Priority {
const LOWEST: u16 = 139;
const LOW: u16 = 110;
const NORMAL: u16 = 100;
const HIGH: u16 = 10;
const HIGHEST: u16 = 0;
/// Creates a new `Priority` with the specified value.
///
/// # Panics
///
/// Panics if the `val` is greater than 139.
pub const fn new(val: u16) -> Self {
assert!(val <= Self::LOWEST);
Self(val)
}
/// Returns a `Priority` representing the lowest priority (139).
pub const fn lowest() -> Self {
Self::new(Self::LOWEST)
}
/// Returns a `Priority` representing a low priority.
pub const fn low() -> Self {
Self::new(Self::LOW)
}
/// Returns a `Priority` representing a normal priority.
pub const fn normal() -> Self {
Self::new(Self::NORMAL)
}
/// Returns a `Priority` representing a high priority.
pub const fn high() -> Self {
Self::new(Self::HIGH)
}
/// Returns a `Priority` representing the highest priority (0).
pub const fn highest() -> Self {
Self::new(Self::HIGHEST)
}
/// Sets the value of the `Priority`.
pub const fn set(&mut self, val: u16) {
self.0 = val;
}
/// Returns the value of the `Priority`.
pub const fn get(self) -> u16 {
self.0
}
/// Checks if the `Priority` is considered a real-time priority.
pub const fn is_real_time(&self) -> bool {
self.0 < REAL_TIME_TASK_PRIORITY
}
}
/// An atomic CPUID container.
pub struct AtomicCpuId(AtomicU32);