From e41c78810fc09a083371c8070bf7a800d7196ab6 Mon Sep 17 00:00:00 2001 From: atsushi421 Date: Thu, 12 Nov 2026 16:30:23 +0900 Subject: [PATCH 1/2] feat(sched): merge GEDF into ClusteredEDF and rename it to EDF GEDF is ClusteredEDF with every worker core in the CPU set, so one EDF scheduler covers both. Remove GEDFScheduler and SchedulerType::GEDF, and rename ClusteredEDF to EDF. SchedulerType::EDF(d, CpuSet::all()) gives global EDF, and a one-core CPU set gives partitioned EDF. - Move calculate_and_update_dag_deadline from gedf.rs to dag.rs as pub(crate), because the EDF scheduler and the DAG tests use it. - Remove the NOTE in invoke_preemption that described the GEDF policy. The EDF scheduler does not preempt when a core in the set is idle. - Rename test_clustered_edf to test_edf and remove test_gedf. Move test_dag, test_dvfs, and test_multi_prioritized_scheduler to SchedulerType::EDF. Signed-off-by: atsushi421 --- .../tests/test_clustered_edf/Cargo.toml | 15 -- applications/tests/test_dag/src/lib.rs | 12 +- applications/tests/test_dvfs/src/lib.rs | 6 +- .../tests/{test_gedf => test_edf}/Cargo.toml | 2 +- .../src/lib.rs | 10 +- applications/tests/test_gedf/src/lib.rs | 58 ----- .../src/lib.rs | 9 +- awkernel_async_lib/src/dag.rs | 48 +++- awkernel_async_lib/src/scheduler.rs | 37 ++- .../scheduler/{clustered_edf.rs => edf.rs} | 32 ++- awkernel_async_lib/src/scheduler/gedf.rs | 234 ------------------ awkernel_async_lib/src/task.rs | 13 +- awkernel_lib/src/cpu.rs | 2 +- mdbook/src/internal/scheduler.md | 19 +- userland/Cargo.toml | 11 +- userland/src/lib.rs | 7 +- 16 files changed, 110 insertions(+), 405 deletions(-) delete mode 100644 applications/tests/test_clustered_edf/Cargo.toml rename applications/tests/{test_gedf => test_edf}/Cargo.toml (93%) rename applications/tests/{test_clustered_edf => test_edf}/src/lib.rs (94%) delete mode 100644 applications/tests/test_gedf/src/lib.rs rename awkernel_async_lib/src/scheduler/{clustered_edf.rs => edf.rs} (87%) delete mode 100644 awkernel_async_lib/src/scheduler/gedf.rs diff --git a/applications/tests/test_clustered_edf/Cargo.toml b/applications/tests/test_clustered_edf/Cargo.toml deleted file mode 100644 index 561137e65..000000000 --- a/applications/tests/test_clustered_edf/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "test_clustered_edf" -version = "0.1.0" -edition = "2021" - -[dependencies] -log = "0.4" - -[dependencies.awkernel_async_lib] -path = "../../../awkernel_async_lib" -default-features = false - -[dependencies.awkernel_lib] -path = "../../../awkernel_lib" -default-features = false diff --git a/applications/tests/test_dag/src/lib.rs b/applications/tests/test_dag/src/lib.rs index a7330457f..0d2f5efbf 100644 --- a/applications/tests/test_dag/src/lib.rs +++ b/applications/tests/test_dag/src/lib.rs @@ -4,7 +4,7 @@ extern crate alloc; use alloc::{borrow::Cow, vec}; use awkernel_async_lib::dag::{create_dag, finish_create_dags}; use awkernel_async_lib::scheduler::SchedulerType; -use awkernel_lib::delay::wait_microsec; +use awkernel_lib::{cpu::CpuSet, delay::wait_microsec}; use core::time::Duration; const LOG_ENABLE: bool = true; @@ -30,7 +30,7 @@ pub async fn run() { (number,) }, vec![Cow::from("topic0")], - SchedulerType::GEDF(5), + SchedulerType::EDF(5, CpuSet::all()), period, ) .await; @@ -47,7 +47,7 @@ pub async fn run() { }, vec![Cow::from("topic0")], vec![Cow::from("topic1"), Cow::from("topic2")], - SchedulerType::GEDF(10), + SchedulerType::EDF(10, CpuSet::all()), ) .await; @@ -62,7 +62,7 @@ pub async fn run() { }, vec![Cow::from("topic1")], vec![Cow::from("topic3")], - SchedulerType::GEDF(10), + SchedulerType::EDF(10, CpuSet::all()), ) .await; @@ -77,7 +77,7 @@ pub async fn run() { }, vec![Cow::from("topic2")], vec![Cow::from("topic4")], - SchedulerType::GEDF(10), + SchedulerType::EDF(10, CpuSet::all()), ) .await; @@ -90,7 +90,7 @@ pub async fn run() { } }, vec![Cow::from("topic3"), Cow::from("topic4")], - SchedulerType::GEDF(10), + SchedulerType::EDF(10, CpuSet::all()), Duration::from_secs(1), ) .await; diff --git a/applications/tests/test_dvfs/src/lib.rs b/applications/tests/test_dvfs/src/lib.rs index 411941d7e..1932f8cbb 100644 --- a/applications/tests/test_dvfs/src/lib.rs +++ b/applications/tests/test_dvfs/src/lib.rs @@ -33,7 +33,7 @@ pub async fn run() { awkernel_async_lib::spawn( APP_NAME.into(), test_dvfs(), - awkernel_async_lib::scheduler::SchedulerType::ClusteredEDF(DEADLINE, cpu_set), + awkernel_async_lib::scheduler::SchedulerType::EDF(DEADLINE, cpu_set), ) .await; @@ -41,14 +41,14 @@ pub async fn run() { awkernel_async_lib::spawn( energy::APP_NAME.into(), energy::measure_energy(), - awkernel_async_lib::scheduler::SchedulerType::ClusteredEDF(DEADLINE, cpu_set), + awkernel_async_lib::scheduler::SchedulerType::EDF(DEADLINE, cpu_set), ) .await; awkernel_async_lib::spawn( "test DVFS measurements".into(), measure_dvfs(), - awkernel_async_lib::scheduler::SchedulerType::ClusteredEDF(DEADLINE, cpu_set), + awkernel_async_lib::scheduler::SchedulerType::EDF(DEADLINE, cpu_set), ) .await; } diff --git a/applications/tests/test_gedf/Cargo.toml b/applications/tests/test_edf/Cargo.toml similarity index 93% rename from applications/tests/test_gedf/Cargo.toml rename to applications/tests/test_edf/Cargo.toml index cd3d63fef..32f3432c9 100644 --- a/applications/tests/test_gedf/Cargo.toml +++ b/applications/tests/test_edf/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "test_gedf" +name = "test_edf" version = "0.1.0" edition = "2021" diff --git a/applications/tests/test_clustered_edf/src/lib.rs b/applications/tests/test_edf/src/lib.rs similarity index 94% rename from applications/tests/test_clustered_edf/src/lib.rs rename to applications/tests/test_edf/src/lib.rs index 600408393..9bf59fb07 100644 --- a/applications/tests/test_clustered_edf/src/lib.rs +++ b/applications/tests/test_edf/src/lib.rs @@ -16,7 +16,7 @@ pub async fn run() { wait_microsec(2_000_000); if num_cpu() < 2 { - log::warn!("test_clustered_edf: requires at least 2 CPUs, skipping"); + log::warn!("test_edf: requires at least 2 CPUs, skipping"); return; } @@ -50,7 +50,7 @@ async fn test_core_pinning() { awkernel_async_lib::r#yield().await; } }, - SchedulerType::ClusteredEDF(1_000_000, CpuSet::empty().with(core)), + SchedulerType::EDF(1_000_000, CpuSet::empty().with(core)), ) .await; } @@ -82,7 +82,7 @@ async fn test_cluster_affinity() { awkernel_async_lib::r#yield().await; } }, - SchedulerType::ClusteredEDF(1_000_000, cluster), + SchedulerType::EDF(1_000_000, cluster), ) .await; } @@ -133,7 +133,7 @@ async fn test_empty_set_fallback() { awkernel_async_lib::r#yield().await; } }, - SchedulerType::ClusteredEDF(1_000_000, set), + SchedulerType::EDF(1_000_000, set), ) .await; } @@ -166,7 +166,7 @@ async fn spawn_periodic_task( awkernel_async_lib::r#yield().await; } }, - SchedulerType::ClusteredEDF(relative_deadline, CpuSet::empty().with(core)), + SchedulerType::EDF(relative_deadline, CpuSet::empty().with(core)), ) .await; } diff --git a/applications/tests/test_gedf/src/lib.rs b/applications/tests/test_gedf/src/lib.rs deleted file mode 100644 index 034382a39..000000000 --- a/applications/tests/test_gedf/src/lib.rs +++ /dev/null @@ -1,58 +0,0 @@ -#![no_std] - -extern crate alloc; -use alloc::string::String; -use alloc::string::ToString; - -use awkernel_async_lib::sleep; -use awkernel_async_lib::{scheduler::SchedulerType, spawn}; -use awkernel_lib::delay::uptime; -use awkernel_lib::{cpu::cpu_id, delay::wait_microsec}; -use core::time::Duration; - -pub async fn run() { - wait_microsec(2000000); - - // Generate tasks with pseudo-periods. - // Assumption that periodic reactors are running. - // heavy_1 is preempted by light_1. - log::info!("spawn heavy_1: {:?}", uptime()); - spawn_periodic_loop("heavy_1".to_string(), 9600000, 10000000, 9900000).await; // Task id = 8 - log::info!("spawn task_1: {:?}", uptime()); - spawn_periodic_loop("task_1".to_string(), 9800000, 10000000, 9800000).await; // Task id = 9 - log::info!("spawn light_1: {:?}", uptime()); - spawn_periodic_loop("light_1".to_string(), 900000, 1000000, 990000).await; // Task id = 10 - - wait_microsec(100000000); -} - -/// Spawn a pseudo-periodic task. -async fn spawn_periodic_loop( - task_name: String, - exe_time: u64, - period: u64, - relative_deadline: u64, -) { - let task_name_clone = task_name.clone(); - spawn( - task_name.into(), - async move { - loop { - let start_time = awkernel_lib::delay::uptime(); - wait_microsec(exe_time); - let end_time = awkernel_lib::delay::uptime(); - log::debug!( - "task_name: {}, cpu_id: {}, start_time: {}, end_time: {}", - task_name_clone, - cpu_id(), - start_time, - end_time - ); - sleep(Duration::from_micros(period - exe_time)).await; - awkernel_async_lib::r#yield().await; - } - }, - SchedulerType::GEDF(relative_deadline), - ) - .await; -} diff --git a/applications/tests/test_multi_prioritized_scheduler/src/lib.rs b/applications/tests/test_multi_prioritized_scheduler/src/lib.rs index 349788884..833263e3c 100644 --- a/applications/tests/test_multi_prioritized_scheduler/src/lib.rs +++ b/applications/tests/test_multi_prioritized_scheduler/src/lib.rs @@ -3,7 +3,10 @@ extern crate alloc; use awkernel_async_lib::{scheduler::SchedulerType, spawn}; -use awkernel_lib::{cpu::num_cpu, delay::wait_millisec}; +use awkernel_lib::{ + cpu::{num_cpu, CpuSet}, + delay::wait_millisec, +}; pub async fn run() { wait_millisec(1000); @@ -13,7 +16,7 @@ pub async fn run() { } else if i % 3 == 1 { SchedulerType::PrioritizedRR(0) } else { - SchedulerType::GEDF(1000) + SchedulerType::EDF(1000, CpuSet::all()) }; spawn( @@ -34,7 +37,7 @@ pub async fn run() { } else if i % 3 == 1 { SchedulerType::PrioritizedRR(1) } else { - SchedulerType::GEDF(500) + SchedulerType::EDF(500, CpuSet::all()) }; spawn( diff --git a/awkernel_async_lib/src/dag.rs b/awkernel_async_lib/src/dag.rs index 809f980ad..6f2b01346 100644 --- a/awkernel_async_lib/src/dag.rs +++ b/awkernel_async_lib/src/dag.rs @@ -64,7 +64,7 @@ use crate::{ visit::{EdgeRef, IntoNodeReferences, NodeRef}, }, scheduler::SchedulerType, - task::DagInfo, + task::{DagInfo, State}, time_interval::interval, Attribute, MultipleReceiver, MultipleSender, VectorToPublishers, VectorToSubscribers, }; @@ -757,6 +757,42 @@ pub fn get_dag(id: u32) -> Option> { dags.id_to_dag.get(&id).cloned() } +/// Returns the absolute deadline of the DAG job that the node of `dag_info` processes next. +/// A source wake in any `state` except `State::Preempted` releases an unreleased job. Its +/// absolute deadline is fixed at release to the interval tick target plus the sink relative +/// deadline. A wake before release gets `wake_time` plus the current sink relative deadline. +/// +/// # Panics +/// +/// Panics if the DAG does not exist, has no node `dag_info.node_id`, or has no sink relative +/// deadline, or the source releases a job without an interval tick target. +pub(crate) fn calculate_and_update_dag_deadline( + dag_info: &DagInfo, + wake_time: u64, + state: State, +) -> u64 { + let dag_id = dag_info.dag_id; + let dag = get_dag(dag_id).unwrap_or_else(|| panic!("DAG {dag_id} not found")); + + // The wake of a preempted task resumes it and does not release a job. Any other wake + // of the source node at an unreleased job must come from its `Interval` tick. After the + // source node finishes a job, it waits only for that tick, because it has no subscriber. + let release = state != State::Preempted; + + dag.get_or_release_job(to_node_index(dag_info.node_id), release) + .map_or_else( + || { + // Microseconds, the unit of `awkernel_lib::delay::uptime()`. + let relative_deadline_us = dag + .get_sink_relative_deadline() + .map(|deadline| deadline.as_micros() as u64) + .unwrap_or_else(|_| panic!("DAG {dag_id} has no sink relative deadline set")); + wake_time + relative_deadline_us + }, + |job| job.absolute_deadline, + ) +} + pub async fn finish_create_dags(dags: &[Arc]) -> Result<(), Vec> { match validate_all_rules(dags) { Ok(()) => { @@ -1465,13 +1501,12 @@ mod tests { } #[test] - fn gedf_deadline_uses_job_release_time() { - use crate::scheduler::gedf::calculate_and_update_dag_deadline; + fn dag_deadline_uses_job_release_time() { use crate::task::{DagInfo, State}; let dag = create_dag(); - let source = dag.add_node_with_topic_edges(&[], &["gedf_test_topic".into()]); - let sink = dag.add_node_with_topic_edges(&["gedf_test_topic".into()], &[]); + let source = dag.add_node_with_topic_edges(&[], &["dag_deadline_test_topic".into()]); + let sink = dag.add_node_with_topic_edges(&["dag_deadline_test_topic".into()], &[]); dag.set_relative_deadline(sink, Duration::from_micros(50)) .unwrap(); let source_info = DagInfo { @@ -1533,8 +1568,7 @@ mod tests { } #[test] - fn gedf_deadline_is_fixed_when_job_is_released() { - use crate::scheduler::gedf::calculate_and_update_dag_deadline; + fn dag_deadline_is_fixed_when_job_is_released() { use crate::task::{DagInfo, State}; let dag = create_dag(); diff --git a/awkernel_async_lib/src/scheduler.rs b/awkernel_async_lib/src/scheduler.rs index 1637ee06f..bcd4ebb5b 100644 --- a/awkernel_async_lib/src/scheduler.rs +++ b/awkernel_async_lib/src/scheduler.rs @@ -19,8 +19,7 @@ use awkernel_lib::{ #[cfg(not(feature = "std"))] use alloc::boxed::Box; -mod clustered_edf; -pub mod gedf; +mod edf; pub(super) mod panicked; mod prioritized_fifo; mod prioritized_rr; @@ -75,7 +74,7 @@ pub fn move_preemption_pending(cpu_id: usize) -> Option>> { /// 0 is the lowest priority and 31 is the highest priority. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum SchedulerType { - /// Clustered EDF: `(relative_deadline, cpu_set)`. + /// EDF: `(relative_deadline, cpu_set)`. /// /// `cpu_set` is the set of cores the task may run on. It is normalized at /// spawn time: CPU 0 (the primary core) and any out-of-range bits are @@ -83,8 +82,10 @@ pub enum SchedulerType { /// one naming only CPU 0 or out-of-range cores — the task is **not** /// rejected; it falls back to all worker cores (`1..num_cpu()`) with a /// warning. - ClusteredEDF(u64, CpuSet), - GEDF(u64), // relative deadline + /// + /// `CpuSet::all()` gives global EDF, and a one-core set gives + /// partitioned EDF. + EDF(u64, CpuSet), PrioritizedFIFO(u8), PrioritizedRR(u8), Panicked, @@ -94,11 +95,7 @@ impl SchedulerType { pub const fn equals(&self, other: &Self) -> bool { matches!( (self, other), - (SchedulerType::GEDF(_), SchedulerType::GEDF(_)) - | ( - SchedulerType::ClusteredEDF(_, _), - SchedulerType::ClusteredEDF(_, _) - ) + (SchedulerType::EDF(_, _), SchedulerType::EDF(_, _)) | ( SchedulerType::PrioritizedFIFO(_), SchedulerType::PrioritizedFIFO(_) @@ -111,13 +108,13 @@ impl SchedulerType { ) } - /// Return the CPU affinity set if this is a [`SchedulerType::ClusteredEDF`] scheduler. + /// Return the CPU affinity set if this is a [`SchedulerType::EDF`] scheduler. /// /// Returns `Some(set)` where `set` is the set of CPU cores (`1..num_cpu()`) the task /// may run on. Returns `None` for all other scheduler variants. pub const fn cpu_set(&self) -> Option { match self { - SchedulerType::ClusteredEDF(_, set) => Some(*set), + SchedulerType::EDF(_, set) => Some(*set), _ => None, } } @@ -127,7 +124,7 @@ impl SchedulerType { /// scheduler; it is the single source of truth for the clustered prefix /// of `PRIORITY_LIST`. pub const fn is_clustered(&self) -> bool { - matches!(self, SchedulerType::ClusteredEDF(_, _)) + matches!(self, SchedulerType::EDF(_, _)) } } @@ -136,18 +133,15 @@ impl SchedulerType { /// `priority()` returns the priority of the scheduler for preemption. /// /// - The highest priority. -/// - Clustered EDF scheduler. +/// - EDF scheduler. /// - The second highest priority. -/// - GEDF scheduler. -/// - The third highest priority. /// - Prioritized FIFO scheduler. -/// - The fourth highest priority. +/// - The third highest priority. /// - Prioritized Round-Robin scheduler. /// - The lowest priority. /// - Panicked scheduler. -static PRIORITY_LIST: [SchedulerType; 5] = [ - SchedulerType::ClusteredEDF(0, CpuSet::empty()), - SchedulerType::GEDF(0), +static PRIORITY_LIST: [SchedulerType; 4] = [ + SchedulerType::EDF(0, CpuSet::empty()), SchedulerType::PrioritizedFIFO(0), SchedulerType::PrioritizedRR(0), SchedulerType::Panicked, @@ -282,8 +276,7 @@ pub(crate) fn get_scheduler(sched_type: &SchedulerType) -> &'static dyn Schedule match sched_type { SchedulerType::PrioritizedFIFO(_) => &prioritized_fifo::SCHEDULER, SchedulerType::PrioritizedRR(_) => &prioritized_rr::SCHEDULER, - SchedulerType::GEDF(_) => &gedf::SCHEDULER, - SchedulerType::ClusteredEDF(_, _) => &clustered_edf::SCHEDULER, + SchedulerType::EDF(_, _) => &edf::SCHEDULER, SchedulerType::Panicked => &panicked::SCHEDULER, } } diff --git a/awkernel_async_lib/src/scheduler/clustered_edf.rs b/awkernel_async_lib/src/scheduler/edf.rs similarity index 87% rename from awkernel_async_lib/src/scheduler/clustered_edf.rs rename to awkernel_async_lib/src/scheduler/edf.rs index 15ba4deb5..c8b0d800a 100644 --- a/awkernel_async_lib/src/scheduler/clustered_edf.rs +++ b/awkernel_async_lib/src/scheduler/edf.rs @@ -1,15 +1,17 @@ -//! A Clustered EDF scheduler. +//! An EDF scheduler. //! //! Each task carries a [`CpuSet`] describing the CPU cores it may run on. +//! A one-core set gives partitioned EDF, and `CpuSet::all()` gives global EDF. //! Runnable tasks are kept in a single affinity-aware priority queue //! ([`AffinityBTreeQueue`]); `get_next` on CPU `c` pops the earliest-deadline //! task whose `cpu_set` contains `c`. use super::{Scheduler, SchedulerType, Task}; use crate::{ + dag::calculate_and_update_dag_deadline, scheduler::{ - gedf::calculate_and_update_dag_deadline, get_priority, peek_preemption_pending, - push_preemption_pending, ClusteredTask, GLOBAL_WAKE_GET_MUTEX, PREEMPTION_ENABLED, + get_priority, peek_preemption_pending, push_preemption_pending, ClusteredTask, + GLOBAL_WAKE_GET_MUTEX, PREEMPTION_ENABLED, }, task::{ get_task, get_task_running, set_current_task, set_need_preemption, State, MAX_TASK_PRIORITY, @@ -28,21 +30,21 @@ use awkernel_lib::{ type EDFQueue = AffinityBTreeQueue<(u64, u64), ClusteredTask>, DEFAULT_MIN_DEGREE, CPU_SET_WORDS>; -pub struct ClusteredEDFScheduler { +pub struct EDFScheduler { // `AffinityBTreeQueue::new` is not a const fn, so the queue is lazily // initialized with `num_cpu()` on first use. data: Mutex>, priority: u8, } -impl Scheduler for ClusteredEDFScheduler { +impl Scheduler for EDFScheduler { fn wake_task(&self, task: Arc) { let (wake_time, absolute_deadline) = { let mut node_inner = MCSNode::new(); let mut info = task.info.lock(&mut node_inner); let dag_info = info.get_dag_info(); match info.scheduler_type { - SchedulerType::ClusteredEDF(relative_deadline, _) => { + SchedulerType::EDF(relative_deadline, _) => { let wake_time = awkernel_lib::delay::uptime(); let absolute_deadline = if let Some(ref dag_info) = dag_info { calculate_and_update_dag_deadline(dag_info, wake_time, info.state) @@ -66,9 +68,9 @@ impl Scheduler for ClusteredEDFScheduler { // set (masking to worker cores, falling back to all workers when empty). // Reaching here with an invalid set means that invariant was violated // internally, so fail loud rather than enqueue an unrunnable task. - let cpu_set = task.cpu_set.expect("ClusteredEDF task has no CPU set"); + let cpu_set = task.cpu_set.expect("EDF task has no CPU set"); if cpu_set.is_empty() || masked_workers(cpu_set, num_cpu()) != cpu_set { - unreachable!("ClusteredEDF: cpu_set {cpu_set:?} was not normalized by spawn"); + unreachable!("EDF: cpu_set {cpu_set:?} was not normalized by spawn"); } let mut node = MCSNode::new(); @@ -83,7 +85,7 @@ impl Scheduler for ClusteredEDFScheduler { cpu_set, ClusteredTask::new(task.clone()), ) - .expect("ClusteredEDF: failed to push a task"); + .expect("EDF: failed to push a task"); } } @@ -127,7 +129,7 @@ impl Scheduler for ClusteredEDFScheduler { } fn scheduler_name(&self) -> SchedulerType { - SchedulerType::ClusteredEDF(0, CpuSet::empty()) + SchedulerType::EDF(0, CpuSet::empty()) } fn priority(&self) -> u8 { @@ -147,12 +149,12 @@ impl Scheduler for ClusteredEDFScheduler { } } -pub static SCHEDULER: ClusteredEDFScheduler = ClusteredEDFScheduler { +pub static SCHEDULER: EDFScheduler = EDFScheduler { data: Mutex::new(None), - priority: get_priority(&SchedulerType::ClusteredEDF(0, CpuSet::empty())), + priority: get_priority(&SchedulerType::EDF(0, CpuSet::empty())), }; -impl ClusteredEDFScheduler { +impl EDFScheduler { fn invoke_preemption(&self, task: Arc) -> bool { if !PREEMPTION_ENABLED { return false; @@ -203,10 +205,6 @@ impl ClusteredEDFScheduler { set_need_preemption(target_task.id, victim_cpu); awkernel_lib::interrupt::send_ipi(preempt_irq, victim_cpu as u32); - // NOTE(atsushi421): Currently, preemption is requested regardless of the number of idle CPUs. - // While this implementation easily prevents priority inversion, it may also cause unnecessary preemption. - // Therefore, a more sophisticated implementation will be considered in the future. - // NOTE: The task is now pinned to `victim_cpu`'s preemption-pending // heap and is not in the affinity queue, so it is invisible to the // other CPUs in its `cpu_set` (neither `pop_for_cpu`, the clustered diff --git a/awkernel_async_lib/src/scheduler/gedf.rs b/awkernel_async_lib/src/scheduler/gedf.rs deleted file mode 100644 index f7cdb5259..000000000 --- a/awkernel_async_lib/src/scheduler/gedf.rs +++ /dev/null @@ -1,234 +0,0 @@ -//! A GEDF scheduler. - -use core::cmp::max; - -use super::{Scheduler, SchedulerType, Task}; -use crate::{ - dag::{get_dag, to_node_index}, - scheduler::GLOBAL_WAKE_GET_MUTEX, - scheduler::{ - get_priority, peek_preemption_pending, push_preemption_pending, PREEMPTION_ENABLED, - }, - task::{ - get_task, get_tasks_running, set_current_task, set_need_preemption, DagInfo, State, - MAX_TASK_PRIORITY, - }, -}; -use alloc::{collections::BinaryHeap, sync::Arc, vec::Vec}; -use awkernel_lib::sync::mutex::{MCSNode, Mutex}; - -pub struct GEDFScheduler { - data: Mutex>, // Run queue. - priority: u8, -} - -struct GEDFTask { - task: Arc, - absolute_deadline: u64, - wake_time: u64, -} - -impl PartialOrd for GEDFTask { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialEq for GEDFTask { - fn eq(&self, other: &Self) -> bool { - self.absolute_deadline == other.absolute_deadline && self.wake_time == other.wake_time - } -} - -impl Ord for GEDFTask { - fn cmp(&self, other: &Self) -> core::cmp::Ordering { - match other.absolute_deadline.cmp(&self.absolute_deadline) { - core::cmp::Ordering::Equal => other.wake_time.cmp(&self.wake_time), - other => other, - } - } -} - -impl Eq for GEDFTask {} - -struct GEDFData { - queue: BinaryHeap, -} - -impl GEDFData { - fn new() -> Self { - Self { - queue: BinaryHeap::new(), - } - } -} - -impl Scheduler for GEDFScheduler { - fn wake_task(&self, task: Arc) { - let (wake_time, absolute_deadline) = { - let mut node_inner = MCSNode::new(); - let mut info = task.info.lock(&mut node_inner); - let dag_info = info.get_dag_info(); - match info.scheduler_type { - SchedulerType::GEDF(relative_deadline) => { - let wake_time = awkernel_lib::delay::uptime(); - let absolute_deadline = if let Some(ref dag_info) = dag_info { - calculate_and_update_dag_deadline(dag_info, wake_time, info.state) - } else { - // If dag_info is not present, the task is treated as a regular task, and - // the absolute_deadline is calculated using the scheduler's relative_deadline. - wake_time + relative_deadline - }; - - task.priority - .update_priority_info(self.priority, MAX_TASK_PRIORITY - absolute_deadline); - info.update_absolute_deadline(absolute_deadline); - - (wake_time, absolute_deadline) - } - _ => unreachable!(), - } - }; - - let mut node = MCSNode::new(); - let _guard = GLOBAL_WAKE_GET_MUTEX.lock(&mut node); - if !self.invoke_preemption(task.clone()) { - let mut node_inner = MCSNode::new(); - let mut data = self.data.lock(&mut node_inner); - let internal_data = data.get_or_insert_with(GEDFData::new); - internal_data.queue.push(GEDFTask { - task: task.clone(), - absolute_deadline, - wake_time, - }); - } - } - - fn get_next(&self, execution_ensured: bool) -> Option> { - let mut node = MCSNode::new(); - let mut data = self.data.lock(&mut node); - - #[allow(clippy::question_mark)] - let data = match data.as_mut() { - Some(data) => data, - None => return None, - }; - - loop { - // Pop a task from the run queue. - let task = data.queue.pop()?; - - // Make the state of the task Running. - { - let mut node = MCSNode::new(); - let mut task_info = task.task.info.lock(&mut node); - - if matches!(task_info.state, State::Terminated | State::Panicked) { - continue; - } - - if task_info.state == State::Preempted { - task_info.need_preemption = false; - } - if execution_ensured { - task_info.state = State::Running; - set_current_task(awkernel_lib::cpu::cpu_id(), task.task.id); - } - } - - return Some(task.task); - } - } - - fn scheduler_name(&self) -> SchedulerType { - SchedulerType::GEDF(0) - } - - fn priority(&self) -> u8 { - self.priority - } -} - -pub static SCHEDULER: GEDFScheduler = GEDFScheduler { - data: Mutex::new(None), - priority: get_priority(&SchedulerType::GEDF(0)), -}; - -impl GEDFScheduler { - fn invoke_preemption(&self, task: Arc) -> bool { - if !PREEMPTION_ENABLED { - return false; - } - - let tasks_running = get_tasks_running() - .into_iter() - .filter(|rt| rt.task_id != 0) // Filter out idle CPUs - .collect::>(); - - // If the task has already been running, preempt is not required. - if tasks_running.is_empty() || tasks_running.iter().any(|rt| rt.task_id == task.id) { - return false; - } - - let preemption_target = tasks_running - .iter() - .filter_map(|rt| { - get_task(rt.task_id).map(|t| { - let highest_pending = peek_preemption_pending(rt.cpu_id).unwrap_or(t.clone()); - (max(t, highest_pending), rt.cpu_id) - }) - }) - .min() - .unwrap(); - - let (target_task, target_cpu) = preemption_target; - if task.preempts(&target_task) { - push_preemption_pending(target_cpu, task); - let preempt_irq = awkernel_lib::interrupt::get_preempt_irq(); - set_need_preemption(target_task.id, target_cpu); - awkernel_lib::interrupt::send_ipi(preempt_irq, target_cpu as u32); - - // NOTE(atsushi421): Currently, preemption is requested regardless of the number of idle CPUs. - // While this implementation easily prevents priority inversion, it may also cause unnecessary preemption. - // Therefore, a more sophisticated implementation will be considered in the future. - - return true; - } - - false - } -} - -/// Returns the absolute deadline of the DAG job that the node of `dag_info` processes next. -/// A source wake in any `state` except `State::Preempted` releases an unreleased job. Its -/// absolute deadline is fixed at release to the interval tick target plus the sink relative -/// deadline. A wake before release gets `wake_time` plus the current sink relative deadline. -/// -/// # Panics -/// -/// Panics if the DAG does not exist, has no node `dag_info.node_id`, or has no sink relative -/// deadline, or the source releases a job without an interval tick target. -pub fn calculate_and_update_dag_deadline(dag_info: &DagInfo, wake_time: u64, state: State) -> u64 { - let dag_id = dag_info.dag_id; - let dag = get_dag(dag_id).unwrap_or_else(|| panic!("GEDF scheduler: DAG {dag_id} not found")); - - // The wake of a preempted task resumes it and does not release a job. Any other wake - // of the source node at an unreleased job must come from its `Interval` tick. After the - // source node finishes a job, it waits only for that tick, because it has no subscriber. - let release = state != State::Preempted; - - dag.get_or_release_job(to_node_index(dag_info.node_id), release) - .map_or_else( - || { - // Microseconds, the unit of `awkernel_lib::delay::uptime()`. - let relative_deadline_us = dag - .get_sink_relative_deadline() - .map(|deadline| deadline.as_micros() as u64) - .unwrap_or_else(|_| { - panic!("GEDF scheduler: DAG {dag_id} has no sink relative deadline set") - }); - wake_time + relative_deadline_us - }, - |job| job.absolute_deadline, - ) -} diff --git a/awkernel_async_lib/src/task.rs b/awkernel_async_lib/src/task.rs index aed588098..346c0c890 100644 --- a/awkernel_async_lib/src/task.rs +++ b/awkernel_async_lib/src/task.rs @@ -85,7 +85,7 @@ impl Task { /// priority (scheduler priority, then task priority; see `PriorityInfo`). /// /// Equal priorities never preempt. Within a priority level the schedulers - /// are FIFO (PrioritizedFIFO, ClusteredEDF/GEDF on equal deadlines) or + /// are FIFO (PrioritizedFIFO, EDF on equal deadlines) or /// rotate by their own time quantum (PrioritizedRR), so a task woken while /// an equal-priority task is running waits in the run queue instead of /// displacing it. @@ -166,7 +166,7 @@ impl ArcWake for Task { } // Panicked tasks go to the global panicked scheduler, so always use the global counter. - // Non-panicked clustered tasks: counters are managed inside clustered_edf::wake_task. + // Non-panicked clustered tasks: counters are managed inside edf::wake_task. // Non-panicked non-clustered tasks: increment the global counter here. if panicked || self.cpu_set.is_none() { NUM_TASK_IN_QUEUE.fetch_add(1, Ordering::Release); @@ -314,7 +314,7 @@ impl Tasks { if let btree_map::Entry::Vacant(e) = self.id_to_task.entry(id) { // Validate and normalise the CPU set before creating TaskInfo so that // info.scheduler_type and task.cpu_set stay in sync. - let cpu_set = if let SchedulerType::ClusteredEDF(deadline, set) = scheduler_type { + let cpu_set = if let SchedulerType::EDF(deadline, set) = scheduler_type { // CPU 0 is the primary core and cannot run clustered tasks. let masked = masked_workers(set, num_cpu()); let normalized = if masked.is_empty() { @@ -329,7 +329,7 @@ impl Tasks { } else { masked }; - scheduler_type = SchedulerType::ClusteredEDF(deadline, normalized); + scheduler_type = SchedulerType::EDF(deadline, normalized); Some(normalized) } else { None @@ -417,12 +417,13 @@ pub fn spawn( /// Spawn a detached task with DAG information. /// This function is similar to `spawn` but automatically sets DAG information -/// for the task, which is useful for DAG-based schedulers like GEDF. +/// for the task, which is useful for DAG-based schedulers like EDF. /// /// # Example /// /// ```ignore /// use awkernel_async_lib::{scheduler::SchedulerType, task, dag::{create_dag, add_node_with_topic_edges_public, set_relative_deadline_public}}; +/// use awkernel_lib::cpu::CpuSet; /// use core::time::Duration; /// let dag = create_dag(); /// let sink_node_idx = add_node_with_topic_edges_public(&dag, &[], &[]); @@ -431,7 +432,7 @@ pub fn spawn( /// let task_id = task::spawn_with_dag_info( /// "dag task".into(), /// async { Ok(()) }, -/// SchedulerType::GEDF(0), +/// SchedulerType::EDF(0, CpuSet::all()), /// DagInfo { dag_id: 1, node_id: 0 } /// ); /// ``` diff --git a/awkernel_lib/src/cpu.rs b/awkernel_lib/src/cpu.rs index 2ff5b13ce..c35e6cb80 100644 --- a/awkernel_lib/src/cpu.rs +++ b/awkernel_lib/src/cpu.rs @@ -208,7 +208,7 @@ mod tests { #[test] fn masked_workers_is_idempotent_on_valid_sets() { // An already-normalized set is a fixed point. This is the invariant - // `clustered_edf::wake_task` relies on (`masked_workers(s, n) != s` + // `edf::wake_task` relies on (`masked_workers(s, n) != s` // is false for a valid set). let s = all_workers(64); assert_eq!(masked_workers(s, 64), s); diff --git a/mdbook/src/internal/scheduler.md b/mdbook/src/internal/scheduler.md index 3107f683a..c15853e4e 100644 --- a/mdbook/src/internal/scheduler.md +++ b/mdbook/src/internal/scheduler.md @@ -30,8 +30,7 @@ There are several functions regarding the scheduler in [awkernel_async_lib/src/s ```rust pub enum SchedulerType { - ClusteredEDF(u64, CpuSet), // relative deadline and CPU affinity set - GEDF(u64), // relative deadline + EDF(u64, CpuSet), // relative deadline and CPU affinity set PrioritizedFIFO(u8), PrioritizedRR(u8), Panicked, @@ -63,20 +62,20 @@ Some schedulers are implemented under the folder [awkernel_async_lib/src/schedul ```shell $ ls awkernel_async_lib/src/scheduler -> clustered_edf.rs gedf.rs panicked.rs prioritized_fifo.rs prioritized_rr.rs +> edf.rs panicked.rs prioritized_fifo.rs prioritized_rr.rs ``` A scheduler can be implemented by implementing `Scheduler` Trait. Each scheduler must be registered in the following three locations. `fn get_next_task()`, `fn get_scheduler(sched_type: &SchedulerType)` and `pub enum SchedulerType`. -### ClusteredEDF Scheduler +### EDF Scheduler -The Clustered Earliest Deadline First (ClusteredEDF) scheduler is implemented in [clustered_edf.rs](https://github.com/tier4/awkernel/blob/main/awkernel_async_lib/src/scheduler/clustered_edf.rs). This scheduler is an EDF variant that restricts each task to a set of CPU cores (a cluster), specified as a `CpuSet` bitmask. Pinning a task to a single core (partitioned scheduling) is the special case of a one-bit `CpuSet`. +The Earliest Deadline First (EDF) scheduler is implemented in [edf.rs](https://github.com/tier4/awkernel/blob/main/awkernel_async_lib/src/scheduler/edf.rs). This scheduler restricts each task to a set of CPU cores (a cluster), specified as a `CpuSet` bitmask. A one-bit `CpuSet` pins a task to a single core (partitioned EDF), and `CpuSet::all()` lets it run on every worker core (global EDF). The scheduler holds a single affinity-aware priority queue, [`AffinityBTreeQueue`](https://crates.io/crates/affinity_btree_queue), backed by an augmented B-tree. Each entry carries `(priority, affinity, task)`, where the priority is the pair `(absolute_deadline, wake_time)`; smaller values dequeue first, so tasks are ordered by earliest deadline with wake time as a tie-breaker. Every B-tree node stores the OR of the affinities in its subtree, which lets `pop_for_cpu(cpu)` find the earliest-deadline task runnable on `cpu` in logarithmic time while skipping subtrees with no eligible entry. -When a task is enqueued via `wake_task()`, the scheduler reads the `SchedulerType::ClusteredEDF(relative_deadline, cpu_set)` attached to the task and calculates the absolute deadline as `uptime + relative_deadline`. If the task is part of a DAG, `calculate_and_update_dag_deadline()` (shared with the GEDF scheduler) is used instead to propagate deadlines through the DAG. The task is then pushed into the queue with its `cpu_set` as the affinity mask. Preemption is handled via `invoke_preemption()`: if no core in the set is idle and the task is not already running, the core running the lowest-priority task among the set is chosen, and an IPI is sent to it when the newly enqueued task has an earlier deadline than the task currently running (or pending preemption) on that core. +When a task is enqueued via `wake_task()`, the scheduler reads the `SchedulerType::EDF(relative_deadline, cpu_set)` attached to the task and calculates the absolute deadline as `uptime + relative_deadline`. If the task is part of a DAG, `calculate_and_update_dag_deadline()` is used instead to propagate deadlines through the DAG. The task priority (`PriorityInfo`) becomes `MAX_TASK_PRIORITY - absolute_deadline`, so an earlier deadline gives a higher priority. The task is then pushed into the queue with its `cpu_set` as the affinity mask. Preemption is handled via `invoke_preemption()`: if no core in the set is idle and the task is not already running, the core running the lowest-priority task among the set is chosen, and an IPI is sent to it when the newly enqueued task has an earlier deadline than the task currently running (or pending preemption) on that core. `get_next()` pops the earliest-deadline task whose `cpu_set` contains the calling CPU (`pop_for_cpu`), so a task is only ever dequeued by a core within its set. This guarantees CPU affinity. CPU 0 (the primary core) is always excluded from `cpu_set` when a task is spawned. The `cpu_set` is normalized at spawn time by removing CPU 0 and out-of-range bits; if this leaves the set empty (for example an empty set, or one naming only CPU 0 or out-of-range cores), the task is not rejected but falls back to all worker cores (`1..num_cpu()`) with a warning. @@ -84,14 +83,6 @@ Bookkeeping for sleeping workers uses two pieces of state. A single global count A new clustered scheduler must (1) wrap its queue entries in `ClusteredTask`, (2) implement `Scheduler::queued_cpu_mask()`, and (3) be placed in the clustered prefix of `PRIORITY_LIST` and matched by `SchedulerType::is_clustered()`; the prefix requirement is enforced at compile time. -### GEDF Scheduler - -The Global Earliest Deadline First (GEDF) scheduler is implemented in [gedf.rs](https://github.com/tier4/awkernel/blob/main/awkernel_async_lib/src/scheduler/gedf.rs). This scheduler implements a real-time scheduling algorithm that prioritizes tasks based on their absolute deadlines. - -The scheduler maintains a `BinaryHeap` as its run queue, where tasks are ordered by their absolute deadlines. When a task is enqueued via `wake_task()`, the scheduler calculates the absolute deadline by adding the relative deadline (specified in `SchedulerType::GEDF(relative_deadline)`) to the current uptime. The task's priority is updated using `MAX_TASK_PRIORITY - absolute_deadline` to ensure proper inter-scheduler priority comparison. - -The `GEDFTask` struct implements custom ordering where tasks are compared first by absolute deadline (earlier deadlines have higher priority), and then by wake time for tie-breaking. The scheduler supports preemption through the `invoke_preemption()` method, which sends IPIs to target CPUs when a task with an earlier deadline arrives and can preempt currently running tasks. - ### PrioritizedFIFO Scheduler The PrioritizedFIFO scheduler is implemented in [prioritized_fifo.rs](https://github.com/tier4/awkernel/blob/main/awkernel_async_lib/src/scheduler/prioritized_fifo.rs). This scheduler provides fixed-priority scheduling where tasks are executed in First-In-First-Out order within each priority level. diff --git a/userland/Cargo.toml b/userland/Cargo.toml index 7d6bd9bcf..98eb2af89 100644 --- a/userland/Cargo.toml +++ b/userland/Cargo.toml @@ -62,10 +62,6 @@ optional = true path = "../applications/tests/test_async_mutex" optional = true -[dependencies.test_gedf] -path = "../applications/tests/test_gedf" -optional = true - [dependencies.test_measure_channel] path = "../applications/tests/test_measure_channel" optional = true @@ -90,8 +86,8 @@ optional = true path = "../applications/tests/test_voluntary_preemption" optional = true -[dependencies.test_clustered_edf] -path = "../applications/tests/test_clustered_edf" +[dependencies.test_edf] +path = "../applications/tests/test_edf" optional = true [features] @@ -126,11 +122,10 @@ test_graphics = ["dep:test_graphics"] test_prioritized_fifo = ["dep:test_prioritized_fifo"] test_prioritized_rr = ["dep:test_prioritized_rr"] test_async_mutex = ["dep:test_async_mutex"] -test_gedf = ["dep:test_gedf"] test_measure_channel = ["dep:test_measure_channel"] test_measure_channel_heavy = ["dep:test_measure_channel_heavy"] test_dag = ["dep:test_dag"] test_dvfs = ["dep:test_dvfs", "awkernel/dvfs"] test_raspi_dvfs = ["dep:test_raspi_dvfs"] test_voluntary_preemption = ["dep:test_voluntary_preemption"] -test_clustered_edf = ["dep:test_clustered_edf"] +test_edf = ["dep:test_edf"] diff --git a/userland/src/lib.rs b/userland/src/lib.rs index 6674128be..a21a1450c 100644 --- a/userland/src/lib.rs +++ b/userland/src/lib.rs @@ -38,9 +38,6 @@ pub async fn run() -> Result<(), Cow<'static, str>> { #[cfg(feature = "test_async_mutex")] test_async_mutex::run().await; // test for async_mutex - #[cfg(feature = "test_gedf")] - test_gedf::run().await; // test for Global Earliest Deadline First scheduler - #[cfg(feature = "test_measure_channel")] test_measure_channel::run().await; // measure channel @@ -59,8 +56,8 @@ pub async fn run() -> Result<(), Cow<'static, str>> { #[cfg(feature = "test_voluntary_preemption")] test_voluntary_preemption::run().await; // test for voluntary preemption - #[cfg(feature = "test_clustered_edf")] - test_clustered_edf::run().await; // test for Clustered EDF scheduler + #[cfg(feature = "test_edf")] + test_edf::run().await; // test for EDF scheduler Ok(()) } From 204cee29442ad3da0cb4f6b11ad3a39236f07d1c Mon Sep 17 00:00:00 2001 From: atsushi421 Date: Fri, 13 Nov 2026 13:47:17 +0900 Subject: [PATCH 2/2] fix: address review findings - Add test_global_edf, which checks that a CpuSet::all() EDF task preempts when every worker is busy and never runs on CPU 0. - Wake the primary CPU after the EDF scheduler enqueues a task, so re-wakes from do_preemption and run_main also wake an idle worker. - Make Dag::get_or_release_job private, because all callers are now in dag.rs. - Pass the task to ClusteredTask::new by value at its last use. Signed-off-by: atsushi421 --- applications/tests/test_edf/src/lib.rs | 52 ++++++++++++++++++++++++- awkernel_async_lib/src/dag.rs | 2 +- awkernel_async_lib/src/scheduler/edf.rs | 8 +++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/applications/tests/test_edf/src/lib.rs b/applications/tests/test_edf/src/lib.rs index 9bf59fb07..d78d2df50 100644 --- a/applications/tests/test_edf/src/lib.rs +++ b/applications/tests/test_edf/src/lib.rs @@ -10,7 +10,10 @@ use awkernel_lib::{ cpu::{all_workers, cpu_id, num_cpu, CpuSet}, delay::{uptime, wait_microsec}, }; -use core::time::Duration; +use core::{ + sync::atomic::{AtomicUsize, Ordering}, + time::Duration, +}; pub async fn run() { wait_microsec(2_000_000); @@ -20,6 +23,7 @@ pub async fn run() { return; } + test_global_edf().await; test_core_pinning().await; test_cluster_affinity().await; test_edf_preemption().await; @@ -29,6 +33,52 @@ pub async fn run() { wait_microsec(100_000_000); } +/// Number of `test_global_edf` filler tasks that finished their job. +static GLOBAL_FILLERS_DONE: AtomicUsize = AtomicUsize::new(0); + +/// Test 0: Verify global EDF (`CpuSet::all()`). +/// One filler per worker core keeps every worker busy, and the userland task +/// (PrioritizedFIFO) is preempted, so no worker is idle. `urgent` wakes from +/// its sleep while the fillers run and must preempt one of them, which means +/// that it runs before any filler finishes. No task may run on CPU 0. +async fn test_global_edf() { + log::info!("=== test_global_edf start ==="); + + spawn( + "global_urgent".into(), + async move { + sleep(Duration::from_millis(200)).await; + let actual = cpu_id(); + let done = GLOBAL_FILLERS_DONE.load(Ordering::Relaxed); + if actual != 0 && done == 0 { + log::info!("global_edf: urgent preempted a filler on cpu {actual} [OK]"); + } else { + log::error!( + "global_edf: urgent ran on cpu {actual} after {done} fillers finished [FAIL]" + ); + } + }, + SchedulerType::EDF(300_000, CpuSet::all()), + ) + .await; + + for i in 1..num_cpu() { + spawn( + alloc::format!("global_filler{i}").into(), + async move { + let actual = cpu_id(); + if actual == 0 { + log::error!("global_edf: filler {i} ran on cpu 0 [FAIL]"); + } + wait_microsec(1_000_000); + GLOBAL_FILLERS_DONE.fetch_add(1, Ordering::Relaxed); + }, + SchedulerType::EDF(10_000_000, CpuSet::all()), + ) + .await; + } +} + /// Test 1: Verify tasks are pinned to their assigned cores. /// Spawns one periodic task per worker core (1..num_cpu()) with a /// single-core CPU set. Each task checks cpu_id() matches the assigned core. diff --git a/awkernel_async_lib/src/dag.rs b/awkernel_async_lib/src/dag.rs index 6f2b01346..9b19750c2 100644 --- a/awkernel_async_lib/src/dag.rs +++ b/awkernel_async_lib/src/dag.rs @@ -571,7 +571,7 @@ impl Dag { /// # Panics /// /// Panics if the source releases a job before its next release time is set. - pub(crate) fn get_or_release_job(&self, node_idx: NodeIndex, release: bool) -> Option { + fn get_or_release_job(&self, node_idx: NodeIndex, release: bool) -> Option { let mut node = MCSNode::new(); let mut jobs = self.jobs.lock(&mut node); diff --git a/awkernel_async_lib/src/scheduler/edf.rs b/awkernel_async_lib/src/scheduler/edf.rs index c8b0d800a..065a880e8 100644 --- a/awkernel_async_lib/src/scheduler/edf.rs +++ b/awkernel_async_lib/src/scheduler/edf.rs @@ -83,9 +83,15 @@ impl Scheduler for EDFScheduler { .push( (absolute_deadline, wake_time), cpu_set, - ClusteredTask::new(task.clone()), + ClusteredTask::new(task), ) .expect("EDF: failed to push a task"); + drop(data); + + // `do_preemption` and `run_main` re-wake tasks through this function + // without `ArcWake::wake`, so notify the primary CPU here to wake an + // idle worker in the set. + awkernel_lib::cpu::wake_cpu(0); } }