Skip to content

Commit

Permalink
[task] support percpu run-queue and cpu affinity for axtask
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Sep 20, 2024
1 parent 76d8cfc commit db02f00
Show file tree
Hide file tree
Showing 12 changed files with 524 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push, pull_request]
env:
qemu-version: 8.2.0
rust-toolchain: nightly-2024-05-02
arceos-apps: '68054e8'
arceos-apps: 'b25b7e2'

jobs:
unit-test:
Expand Down
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/axfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation = "https://arceos-org.github.io/arceos/axfeat/index.html"
default = []

# Multicore
smp = ["axhal/smp", "axruntime/smp", "kspin/smp"]
smp = ["axhal/smp", "axruntime/smp", "axtask/smp", "kspin/smp"]

# Floating point/SIMD
fp_simd = ["axhal/fp_simd"]
Expand Down
2 changes: 1 addition & 1 deletion modules/axruntime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ documentation = "https://arceos-org.github.io/arceos/axruntime/index.html"
[features]
default = []

smp = ["axhal/smp"]
smp = ["axhal/smp", "axtask?/smp"]
irq = ["axhal/irq", "axtask?/irq", "percpu", "kernel_guard"]
tls = ["axhal/tls", "axtask?/tls"]
alloc = ["axalloc"]
Expand Down
16 changes: 13 additions & 3 deletions modules/axtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ documentation = "https://arceos-org.github.io/arceos/axtask/index.html"
default = []

multitask = [
"dep:axconfig", "dep:percpu", "dep:kspin", "dep:lazyinit", "dep:memory_addr",
"dep:scheduler", "dep:timer_list", "kernel_guard", "dep:crate_interface",
"dep:axconfig",
"dep:percpu",
"dep:kspin",
"dep:lazyinit",
"dep:memory_addr",
"dep:scheduler",
"dep:timer_list",
"kernel_guard",
"dep:crate_interface",
]
irq = []
tls = ["axhal/tls"]
preempt = ["irq", "percpu?/preempt", "kernel_guard/preempt"]
smp = ["kspin/smp"]

sched_fifo = ["multitask"]
sched_rr = ["multitask", "preempt"]
Expand All @@ -29,6 +37,7 @@ test = ["percpu?/sp-naive"]
[dependencies]
cfg-if = "1.0"
log = "0.4.21"
bitmaps = { version = "3.2.1", default-features = false }
axhal = { workspace = true }
axconfig = { workspace = true, optional = true }
percpu = { version = "0.1", optional = true }
Expand All @@ -38,7 +47,8 @@ memory_addr = { version = "0.3", optional = true }
timer_list = { version = "0.1", optional = true }
kernel_guard = { version = "0.1", optional = true }
crate_interface = { version = "0.1", optional = true }
scheduler = { git = "https://github.com/arceos-org/scheduler.git", tag = "v0.1.0", optional = true }
# scheduler = { git = "https://github.com/arceos-org/scheduler.git", tag = "v0.1.0", optional = true }
scheduler = { git = "https://github.com/arceos-org/scheduler.git", branch = "num_tasks", optional = true }

[dev-dependencies]
rand = "0.8"
Expand Down
23 changes: 15 additions & 8 deletions modules/axtask/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloc::{string::String, sync::Arc};

pub(crate) use crate::run_queue::{AxRunQueue, RUN_QUEUE};
pub(crate) use crate::run_queue::{current_run_queue, select_run_queue};

#[doc(cfg(feature = "multitask"))]
pub use crate::task::{CurrentTask, TaskId, TaskInner};
Expand Down Expand Up @@ -77,6 +77,8 @@ pub fn init_scheduler() {
/// Initializes the task scheduler for secondary CPUs.
pub fn init_scheduler_secondary() {
crate::run_queue::init_secondary();
#[cfg(feature = "irq")]
crate::timers::init();
}

/// Handles periodic timer ticks for the task manager.
Expand All @@ -86,13 +88,18 @@ pub fn init_scheduler_secondary() {
#[doc(cfg(feature = "irq"))]
pub fn on_timer_tick() {
crate::timers::check_events();
RUN_QUEUE.lock().scheduler_timer_tick();
current_run_queue().scheduler_timer_tick();
}

/// Adds the given task to the run queue, returns the task reference.
pub fn spawn_task(task: TaskInner) -> AxTaskRef {
let task_ref = task.into_arc();
RUN_QUEUE.lock().add_task(task_ref.clone());
let _kernel_guard = kernel_guard::NoPreemptIrqSave::new();
crate::select_run_queue(
#[cfg(feature = "smp")]
task_ref.clone(),
)
.add_task(task_ref.clone());
task_ref
}

Expand All @@ -103,7 +110,7 @@ pub fn spawn_raw<F>(f: F, name: String, stack_size: usize) -> AxTaskRef
where
F: FnOnce() + Send + 'static,
{
spawn_task(TaskInner::new(f, name, stack_size))
spawn_task(TaskInner::new(f, name, stack_size, None))
}

/// Spawns a new task with the default parameters.
Expand All @@ -129,13 +136,13 @@ where
///
/// [CFS]: https://en.wikipedia.org/wiki/Completely_Fair_Scheduler
pub fn set_priority(prio: isize) -> bool {
RUN_QUEUE.lock().set_current_priority(prio)
current_run_queue().set_current_priority(prio)
}

/// Current task gives up the CPU time voluntarily, and switches to another
/// ready task.
pub fn yield_now() {
RUN_QUEUE.lock().yield_current();
current_run_queue().yield_current()
}

/// Current task is going to sleep for the given duration.
Expand All @@ -150,14 +157,14 @@ pub fn sleep(dur: core::time::Duration) {
/// If the feature `irq` is not enabled, it uses busy-wait instead.
pub fn sleep_until(deadline: axhal::time::TimeValue) {
#[cfg(feature = "irq")]
RUN_QUEUE.lock().sleep_until(deadline);
current_run_queue().sleep_until(deadline);
#[cfg(not(feature = "irq"))]
axhal::time::busy_wait_until(deadline);
}

/// Exits the current task.
pub fn exit(exit_code: i32) -> ! {
RUN_QUEUE.lock().exit_current(exit_code)
current_run_queue().exit_current(exit_code)
}

/// The idle task routine.
Expand Down
1 change: 1 addition & 0 deletions modules/axtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ cfg_if::cfg_if! {
extern crate log;
extern crate alloc;

#[macro_use]
mod run_queue;
mod task;
mod task_ext;
Expand Down
Loading

0 comments on commit db02f00

Please sign in to comment.