Skip to content

Commit

Permalink
Merge branch 'new-scheduler-test' into remove-unrunnable-task-from-ru…
Browse files Browse the repository at this point in the history
…n-queue
  • Loading branch information
tsoutsman committed Sep 16, 2023
2 parents fdd2add + 730278d commit b73000d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions applications/test_scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn test_pinned() {
let tasks = cpus()
.map(|cpu| {
(
#[allow(clippy::clone_on_copy)]
cpu.clone(),
(0..100)
.map(move |id| {
Expand Down Expand Up @@ -70,7 +71,9 @@ pub fn test_pinned() {

fn pinned_worker(pinned_cpu: CpuId) {
let mut rng = random::init_rng::<rand::rngs::SmallRng>().unwrap();
while !READY.load(Ordering::Acquire) {}
while !READY.load(Ordering::Acquire) {
core::hint::spin_loop();
}

let locked = TASKS.read();
let tasks = &locked.iter().find(|(cpu, _)| *cpu == pinned_cpu).unwrap().1;
Expand All @@ -89,9 +92,9 @@ pub fn test_pinned() {
continue;
}

let _ = random_task.block_no_log();
random_task.block_no_log();
task::schedule();
let _ = random_task.unblock_no_log();
random_task.unblock_no_log();
}
}
}
Expand Down Expand Up @@ -124,18 +127,20 @@ pub fn test_unpinned() {
let mut rng = random::init_rng::<rand::rngs::SmallRng>().unwrap();
while NUM_RUNNING.load(Ordering::Relaxed) != 0 {
let random_task = tasks.choose(&mut rng).unwrap();
let _ = random_task.block_no_log();
random_task.block_no_log();
// Let the worker tasks on this core run.
task::schedule();
let _ = random_task.unblock_no_log();
random_task.unblock_no_log();
}

for task in tasks {
task.join().unwrap();
}

fn unpinned_worker(_: ()) {
while !READY.load(Ordering::Acquire) {}
while !READY.load(Ordering::Acquire) {
core::hint::spin_loop();
}

for _ in 0..1000 {
task::schedule();
Expand Down

0 comments on commit b73000d

Please sign in to comment.