Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testcases for cpu affinity and wait queue #2

Merged
merged 8 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- name: Check code format
run: cargo fmt --all -- --check
- name: Clippy
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: cargo clippy --all-features

build-rust-apps:
Expand Down Expand Up @@ -63,6 +64,10 @@ jobs:
run: make ARCH=${{ matrix.arch }} A=rust/task/tls
- name: Build rust/task/irq
run: make ARCH=${{ matrix.arch }} A=rust/task/irq
- name: Build rust/task/affinity
run: make ARCH=${{ matrix.arch }} A=rust/task/affinity
- name: Build rust/task/wait_queue
run: make ARCH=${{ matrix.arch }} A=rust/task/wait_queue
- name: Build rust/fs/shell
run: make ARCH=${{ matrix.arch }} A=rust/fs/shell
- name: Build rust/net/echoserver
Expand Down Expand Up @@ -163,6 +168,7 @@ jobs:
with:
toolchain: ${{ matrix.rust-toolchain }}
- name: Build apps for std
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: |
./scripts/get_deps.sh
cargo build --all --exclude arceos-display
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ members = [
"rust/task/priority",
"rust/task/tls",
"rust/task/irq",
"rust/task/affinity",
"rust/task/wait_queue",
]
exclude = [".arceos"]

Expand Down
14 changes: 14 additions & 0 deletions rust/task/affinity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "affinity"
version = "0.1.0"
edition = "2021"
authors = ["Keyang Hu <[email protected]>"]
description = "A simple demo to test the cpu affinity of tasks under ArceOS"

[features]
sched_rr = ["axstd?/sched_rr"]
sched_cfs = ["axstd?/sched_cfs"]

[dependencies]
axstd = { workspace = true, features = ["multitask"], optional = true }
cpumask = { git = "https://github.com/arceos-org/cpumask.git" }
hky1999 marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 37 additions & 0 deletions rust/task/affinity/expect_info_smp4_cfs.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
smp = 4
build_mode = release
log_level = info

CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize platform devices...
Initialize scheduling...
use Completely Fair scheduler.
Initialize interrupt handlers...
CPU 0 init OK
CPU 1 started
CPU 2 started
CPU 3 started
CPU 1 init OK
CPU 2 init OK
CPU 3 init OK
Hello, main task!
Hello, task (0)! id = TaskId([0-9]\+)
Hello, task (1)! id = TaskId([0-9]\+)
Hello, task (2)! id = TaskId([0-9]\+)
Hello, task (3)! id = TaskId([0-9]\+)
Hello, task (4)! id = TaskId([0-9]\+)
Hello, task (5)! id = TaskId([0-9]\+)
Hello, task (6)! id = TaskId([0-9]\+)
Hello, task (7)! id = TaskId([0-9]\+)
Hello, task (8)! id = TaskId([0-9]\+)
Hello, task (9)! id = TaskId([0-9]\+)
Task affinity tests run OK!
36 changes: 36 additions & 0 deletions rust/task/affinity/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
smp = 4
build_mode = release
log_level = info

CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize platform devices...
Initialize scheduling...
use FIFO scheduler.
CPU 0 init OK
CPU 1 started
CPU 2 started
CPU 3 started
CPU 1 init OK
CPU 2 init OK
CPU 3 init OK
Hello, main task!
Hello, task (0)! id = TaskId([0-9]\+)
Hello, task (1)! id = TaskId([0-9]\+)
Hello, task (2)! id = TaskId([0-9]\+)
Hello, task (3)! id = TaskId([0-9]\+)
Hello, task (4)! id = TaskId([0-9]\+)
Hello, task (5)! id = TaskId([0-9]\+)
Hello, task (6)! id = TaskId([0-9]\+)
Hello, task (7)! id = TaskId([0-9]\+)
Hello, task (8)! id = TaskId([0-9]\+)
Hello, task (9)! id = TaskId([0-9]\+)
Task affinity tests run OK!
37 changes: 37 additions & 0 deletions rust/task/affinity/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
smp = 4
build_mode = release
log_level = info

CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize platform devices...
Initialize scheduling...
use Round-robin scheduler.
Initialize interrupt handlers...
CPU 0 init OK
CPU 1 started
CPU 2 started
CPU 3 started
CPU 1 init OK
CPU 2 init OK
CPU 3 init OK
Hello, main task!
Hello, task (0)! id = TaskId([0-9]\+)
Hello, task (1)! id = TaskId([0-9]\+)
Hello, task (2)! id = TaskId([0-9]\+)
Hello, task (3)! id = TaskId([0-9]\+)
Hello, task (4)! id = TaskId([0-9]\+)
Hello, task (5)! id = TaskId([0-9]\+)
Hello, task (6)! id = TaskId([0-9]\+)
Hello, task (7)! id = TaskId([0-9]\+)
Hello, task (8)! id = TaskId([0-9]\+)
Hello, task (9)! id = TaskId([0-9]\+)
Task affinity tests run OK!
70 changes: 70 additions & 0 deletions rust/task/affinity/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#![cfg_attr(feature = "axstd", no_std)]
#![cfg_attr(feature = "axstd", no_main)]

#[macro_use]
#[cfg(feature = "axstd")]
extern crate axstd as std;

use cpumask::CpuMask;
use std::sync::atomic::{AtomicUsize, Ordering};

#[cfg(feature = "axstd")]
use axtask::TaskInner;
#[cfg(feature = "axstd")]
use std::os::arceos::modules::axconfig;
hky1999 marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "axstd")]
use std::os::arceos::modules::axhal;
#[cfg(feature = "axstd")]
use std::os::arceos::modules::axtask;

const KERNEL_STACK_SIZE: usize = 0x40000; // 256 KiB

const NUM_TASKS: usize = 10;
const NUM_TIMES: usize = 100;
static FINISHED_TASKS: AtomicUsize = AtomicUsize::new(0);

#[allow(clippy::modulo_one)]
#[cfg_attr(feature = "axstd", no_mangle)]
fn main() {
println!("Hello, main task!");
for i in 0..NUM_TASKS {
let cpu_id = i % axconfig::SMP;
let task = TaskInner::new(
move || {
println!("Hello, task ({})! id = {:?}", i, axtask::current().id());
for _t in 0..NUM_TIMES {
// Test CPU affinity here.
assert_eq!(axhal::cpu::this_cpu_id(), cpu_id, "CPU affinity failed!");
axtask::yield_now();
}

// Change cpu affinity here.
let mut cpumask = CpuMask::full();
cpumask.set(cpu_id, false);
assert!(
axtask::set_current_affinity(cpumask),
"Change CPU affinity failed!"
);

for _t in 0..NUM_TIMES {
// Test CPU affinity here.
assert_ne!(axhal::cpu::this_cpu_id(), cpu_id, "CPU affinity failed!");
axtask::yield_now();
}
let _ = FINISHED_TASKS.fetch_add(1, Ordering::Relaxed);
},
"".into(),
crate::KERNEL_STACK_SIZE,
);

// Initialized cpu affinity here.
task.set_cpumask(CpuMask::one_shot(cpu_id));
axtask::spawn_task(task);
}

while FINISHED_TASKS.load(Ordering::Relaxed) < NUM_TASKS {
axtask::yield_now();
}

println!("Task affinity tests run OK!");
}
3 changes: 3 additions & 0 deletions rust/task/affinity/test_cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_one "SMP=4 LOG=info" "expect_info_smp4_fifo.out"
test_one "SMP=4 LOG=info FEATURES=sched_rr" "expect_info_smp4_rr.out"
test_one "SMP=4 LOG=info FEATURES=sched_cfs" "expect_info_smp4_cfs.out"
4 changes: 2 additions & 2 deletions rust/task/parallel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn barrier() {
static BARRIER_COUNT: AtomicUsize = AtomicUsize::new(0);

BARRIER_COUNT.fetch_add(1, Ordering::Relaxed);
api::ax_wait_queue_wait(
api::ax_wait_queue_wait_until(
&BARRIER_WQ,
|| BARRIER_COUNT.load(Ordering::Relaxed) == NUM_TASKS,
None,
Expand Down Expand Up @@ -60,7 +60,7 @@ fn main() {
#[cfg(feature = "axstd")]
{
// equals to sleep(500ms)
let timeout = api::ax_wait_queue_wait(
let timeout = api::ax_wait_queue_wait_until(
&AxWaitQueueHandle::new(),
|| false,
Some(std::time::Duration::from_millis(500)),
Expand Down
9 changes: 9 additions & 0 deletions rust/task/wait_queue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "wait_queue"
version = "0.1.0"
edition = "2021"
authors = ["Keyang Hu <[email protected]>"]
description = "A simple demo to test the wait queue for tasks under ArceOS"

[dependencies]
axstd = { workspace = true, features = ["multitask", "irq"], optional = true }
36 changes: 36 additions & 0 deletions rust/task/wait_queue/expect_info_smp1_fifo.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
smp = 1
build_mode = release
log_level = info

Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize platform devices...
Initialize scheduling...
use FIFO scheduler.
Initialize interrupt handlers...
Primary CPU 0 init OK.
Hello, main task
wait_queue: test_wait()
task TaskId(2) is waiting for tasks to start...
task TaskId(2) is waiting for tasks to finish...
wait_queue: test_wait() OK!
wait_timeout_until: tests begin
wait_timeout_until: test tasks woken up by notification, spawn 16 tasks...
wait_timeout_until: sleep for 100ms to let all tasks start
wait_timeout_until: wake up all tasks who are waiting for timeout through notification
wait_timeout_until: tasks woken up by notification test OK!
wait_timeout_until: test tasks woken up by timeout, spawn 16 tasks...
wait_timeout_until: wait for all tasks to finish
wait_timeout_until: tasks woken up by timeout test OK!
wait_timeout_until: test tasks woken up by notification or timeout, spawn 16 tasks...
wait_timeout_until: test tasks woken up by notification or timeout, test OK!
wait_timeout_until: all tests OK!
Shutting down...
42 changes: 42 additions & 0 deletions rust/task/wait_queue/expect_info_smp4_cfs.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
smp = 4
build_mode = release
log_level = info

CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize platform devices...
Initialize scheduling...
use Completely Fair scheduler.
Initialize interrupt handlers...
CPU 0 init OK
CPU 1 started
CPU 2 started
CPU 3 started
CPU 1 init OK
CPU 2 init OK
CPU 3 init OK
Hello, main task
wait_queue: test_wait()
task TaskId(2) is waiting for tasks to start...
task TaskId(2) is waiting for tasks to finish...
wait_queue: test_wait() OK!
wait_timeout_until: tests begin
wait_timeout_until: test tasks woken up by notification, spawn 16 tasks...
wait_timeout_until: sleep for 100ms to let all tasks start
wait_timeout_until: wake up all tasks who are waiting for timeout through notification
wait_timeout_until: tasks woken up by notification test OK!
wait_timeout_until: test tasks woken up by timeout, spawn 16 tasks...
wait_timeout_until: wait for all tasks to finish
wait_timeout_until: tasks woken up by timeout test OK!
wait_timeout_until: test tasks woken up by notification or timeout, spawn 16 tasks...
wait_timeout_until: test tasks woken up by notification or timeout, test OK!
wait_timeout_until: all tests OK!
Shutting down...
42 changes: 42 additions & 0 deletions rust/task/wait_queue/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
smp = 4
build_mode = release
log_level = info

CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize platform devices...
Initialize scheduling...
use FIFO scheduler.
Initialize interrupt handlers...
CPU 0 init OK
CPU 1 started
CPU 2 started
CPU 3 started
CPU 1 init OK
CPU 2 init OK
CPU 3 init OK
Hello, main task
wait_queue: test_wait()
task TaskId(2) is waiting for tasks to start...
task TaskId(2) is waiting for tasks to finish...
wait_queue: test_wait() OK!
wait_timeout_until: tests begin
wait_timeout_until: test tasks woken up by notification, spawn 16 tasks...
wait_timeout_until: sleep for 100ms to let all tasks start
wait_timeout_until: wake up all tasks who are waiting for timeout through notification
wait_timeout_until: tasks woken up by notification test OK!
wait_timeout_until: test tasks woken up by timeout, spawn 16 tasks...
wait_timeout_until: wait for all tasks to finish
wait_timeout_until: tasks woken up by timeout test OK!
wait_timeout_until: test tasks woken up by notification or timeout, spawn 16 tasks...
wait_timeout_until: test tasks woken up by notification or timeout, test OK!
wait_timeout_until: all tests OK!
Shutting down...
Loading
Loading