Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions applications/tests/test_clustered_edf/Cargo.toml

This file was deleted.

12 changes: 6 additions & 6 deletions applications/tests/test_dag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +30,7 @@ pub async fn run() {
(number,)
},
vec![Cow::from("topic0")],
SchedulerType::GEDF(5),
SchedulerType::EDF(5, CpuSet::all()),
period,
)
.await;
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions applications/tests/test_dvfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ 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;

#[cfg(all(target_arch = "x86_64", target_os = "none", feature = "energy"))]
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "test_gedf"
name = "test_edf"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ 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);

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;
}

test_global_edf().await;
test_core_pinning().await;
test_cluster_affinity().await;
test_edf_preemption().await;
Expand All @@ -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.
Expand All @@ -50,7 +100,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;
}
Expand Down Expand Up @@ -82,7 +132,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;
}
Expand Down Expand Up @@ -133,7 +183,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;
}
Expand Down Expand Up @@ -166,7 +216,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;
}
58 changes: 0 additions & 58 deletions applications/tests/test_gedf/src/lib.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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(
Expand Down
50 changes: 42 additions & 8 deletions awkernel_async_lib/src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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<JobInfo> {
fn get_or_release_job(&self, node_idx: NodeIndex, release: bool) -> Option<JobInfo> {
let mut node = MCSNode::new();
let mut jobs = self.jobs.lock(&mut node);

Expand Down Expand Up @@ -757,6 +757,42 @@ pub fn get_dag(id: u32) -> Option<Arc<Dag>> {
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<Dag>]) -> Result<(), Vec<DagError>> {
match validate_all_rules(dags) {
Ok(()) => {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
Loading
Loading