Scheduling class support

This commit is contained in:
徐启航
2024-08-17 08:06:35 +00:00
committed by Tate, Hongliang Tian
parent a260411a2a
commit 878f3f3760
17 changed files with 1062 additions and 32 deletions

View File

@ -5,7 +5,7 @@ use ostd::{
task::{Task, TaskOptions},
};
use super::{oops, status::ThreadStatus, AsThread, Thread};
use super::{oops, AsThread, Thread};
use crate::{prelude::*, sched::priority::Priority};
/// The inner data of a kernel thread.
@ -58,13 +58,11 @@ impl ThreadOptions {
Arc::new_cyclic(|weak_task| {
let thread = {
let kernel_thread = KernelThread;
let status = ThreadStatus::Init;
let priority = self.priority;
let cpu_affinity = self.cpu_affinity;
Arc::new(Thread::new(
weak_task.clone(),
kernel_thread,
status,
priority,
cpu_affinity,
))

View File

@ -12,7 +12,10 @@ use ostd::{
use self::status::{AtomicThreadStatus, ThreadStatus};
use crate::{
prelude::*,
sched::priority::{AtomicPriority, Priority},
sched::{
priority::{AtomicPriority, Priority},
SchedAttr,
},
};
pub mod exception;
@ -40,6 +43,7 @@ pub struct Thread {
priority: AtomicPriority,
/// Thread CPU affinity
cpu_affinity: AtomicCpuSet,
sched_attr: SchedAttr,
}
impl Thread {
@ -47,16 +51,16 @@ impl Thread {
pub fn new(
task: Weak<Task>,
data: impl Send + Sync + Any,
status: ThreadStatus,
priority: Priority,
cpu_affinity: CpuSet,
) -> Self {
Thread {
task,
data: Box::new(data),
status: AtomicThreadStatus::new(status),
status: AtomicThreadStatus::new(ThreadStatus::Init),
priority: AtomicPriority::new(priority),
cpu_affinity: AtomicCpuSet::new(cpu_affinity),
sched_attr: SchedAttr::new(priority.into()),
}
}
@ -140,6 +144,10 @@ impl Thread {
&self.cpu_affinity
}
pub fn sched_attr(&self) -> &SchedAttr {
&self.sched_attr
}
/// Yields the execution to another thread.
///
/// This method will return once the current thread is scheduled again.

View File

@ -10,7 +10,7 @@ use ostd::{
use super::worker_pool::WorkerPool;
use crate::{
prelude::*,
sched::priority::{Priority, PriorityRange},
sched::priority::Priority,
thread::{kernel_thread::ThreadOptions, AsThread},
};
@ -52,8 +52,7 @@ impl Worker {
cpu_affinity.add(bound_cpu);
let mut priority = Priority::default();
if worker_pool.upgrade().unwrap().is_high_priority() {
// FIXME: remove the use of real-time priority.
priority = Priority::new(PriorityRange::new(0));
priority = Priority::default_real_time();
}
let bound_task = ThreadOptions::new(task_fn)
.cpu_affinity(cpu_affinity)

View File

@ -16,7 +16,7 @@ use ostd::{
use super::{simple_scheduler::SimpleScheduler, worker::Worker, WorkItem, WorkPriority, WorkQueue};
use crate::{
prelude::*,
sched::priority::{Priority, PriorityRange},
sched::priority::Priority,
thread::{kernel_thread::ThreadOptions, AsThread},
};
@ -242,7 +242,7 @@ impl Monitor {
// This workaround is to make the monitor of high-priority worker pool
// starvation-free under the current scheduling policy.
let priority = match priority {
WorkPriority::High => Priority::new(PriorityRange::new(0)),
WorkPriority::High => Priority::default_real_time(),
WorkPriority::Normal => Priority::default(),
};
let bound_task = ThreadOptions::new(task_fn)