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

[task] support percpu run-queue and cpu affinity for axtask #176

Merged
merged 51 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
e2680d7
[task] support percpu run-queue and cpu affinity for axtask
hky1999 Sep 20, 2024
b706e87
refactor: add preempt guard for AxRunQueue through AxRunQueueRef
hky1999 Sep 21, 2024
65cc732
refactor: use kernel_guard hold by RQ in wait_queue.rs
hky1999 Sep 23, 2024
e5551cb
feat: introduce cpumask
hky1999 Sep 23, 2024
6cab4cc
[feat] add on_cpu and prev_task_on_cpu_ptr field in AxTaskInner
hky1999 Sep 25, 2024
aafcf9b
fix: delete redundant kernel guard in WaitQueue wait()
hky1999 Sep 26, 2024
8e645fd
Add percpu scheduler doc
hky1999 Sep 26, 2024
091a054
[fix] unit test error related to doc comment
hky1999 Sep 26, 2024
a86d819
[feat] delete cancel_alarm from timers
hky1999 Sep 26, 2024
c49bd2d
Update percpu_rq
hky1999 Sep 27, 2024
e2b1ce1
[fix] use timer ticket id to prevent potential bug introduced by time…
hky1999 Sep 28, 2024
602fadd
[feat] use type CpuSet to wrap cpumask::CpuMask
hky1999 Sep 28, 2024
95c9344
[fix] use allow(clippy::modulo_one) to bypass modulo 1 error in selec…
hky1999 Sep 28, 2024
bad3355
[fix] miss doc for type alias CpuSet
hky1999 Sep 28, 2024
73eb533
[fix] little modification in axtask api.rs
hky1999 Sep 30, 2024
71909cf
[fix] some review opinions
hky1999 Sep 30, 2024
75b7756
[fix] delete if self.on_cpu() block in unblock_locked
hky1999 Sep 30, 2024
347f3fa
[refactor] remove in_timer_list flag in axtask
hky1999 Sep 30, 2024
1fd84b1
[fix] doc error in unblock_task
hky1999 Sep 30, 2024
2782e4e
[refactor] timer ticket id
hky1999 Sep 30, 2024
1f7ac39
[fix] use put_prev_task in unblock_task
hky1999 Sep 30, 2024
de504e1
[fix] pontential bug in unblock_locked, set on_cpu as true for init t…
hky1999 Oct 4, 2024
c9b9ecc
[feat] enrich code comments and scheduling-related docs
hky1999 Oct 4, 2024
901575f
[refactor] move percpu related docs to discussions
hky1999 Oct 6, 2024
0f69a5b
[fix] first round fix of review suggestions
hky1999 Oct 6, 2024
6c7f533
[refactor] add block_current in run_queue.rs
hky1999 Oct 7, 2024
868ac3e
[refactor] pass SpinNoIrqGuard to blocked_resched
hky1999 Oct 7, 2024
d21f780
[feat] add WaitQueueGuard
hky1999 Oct 7, 2024
8b1fe9b
[refactor] merge unblock_task, add TaskUnblockGuard
hky1999 Oct 7, 2024
d04dfd6
[fix] second round fix of review suggestions
hky1999 Oct 8, 2024
80a2c94
[fix] third round fix of review suggestions
hky1999 Oct 8, 2024
0d629a4
[refactor] use weak reference for prev task to manipulate on_cpu flag
hky1999 Oct 8, 2024
c3e665c
[feat] enable on_cpu flag only with smp feature enabled
hky1999 Oct 8, 2024
02a8f9a
[fix] enable on_cpu flag only with smp feature enabled
hky1999 Oct 8, 2024
ee2fc14
[fix] change the pos of NoPreemptIrqSave guard hold by rq in wait_que…
hky1999 Oct 9, 2024
e64a60a
[refactor] delete unblock_locked, use atomic compare_exchange in unbl…
hky1999 Oct 9, 2024
038e3e4
[fix] bug in wait_timeout, modify assert in blocked_resched and switc…
hky1999 Oct 9, 2024
0b3786b
[fix] modify assert about irqs_enabled in switch_to
hky1999 Oct 10, 2024
713f4ea
[refactor] keep the guard in the loop in wait_timeout_until
hky1999 Oct 10, 2024
d5db096
[fix] some compile warnings
hky1999 Oct 10, 2024
5dfd043
Update the commit hash for arceos-apps
hky1999 Oct 10, 2024
b4c09aa
Update the commit hash for arceos-apps again
hky1999 Oct 10, 2024
4690c10
Update the commit hash for arceos-apps again and again
hky1999 Oct 10, 2024
6cef2ae
[fix] bug in wait_timeout and wait_timeout_until
hky1999 Oct 11, 2024
a8fa3da
[CI] update dependencies for qemu build
hky1999 Oct 11, 2024
c09cb39
[fix] fourth round fix of review suggestions
hky1999 Oct 11, 2024
e41100a
[fix] problems related to WAIT_FOR_EXIT in gc_entry
hky1999 Oct 11, 2024
7a34fc5
[refactor] use current_ref_mut_raw to get TIMER_LIST in check_events()
hky1999 Oct 11, 2024
ec64c8e
[refactor] improve notify_all in wait_queue.rs
hky1999 Oct 11, 2024
836a79d
[refactor] delete redundant assertion in block_resched()
hky1999 Oct 11, 2024
63e978b
[fix] some compile warnings
hky1999 Oct 11, 2024
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
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
9 changes: 9 additions & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ run: build justrun
justrun:
$(call run_qemu)

debug: build
$(call run_qemu_debug) &
sleep 1
debug:
$(call run_qemu_debug)

gdb:
$(GDB) $(OUT_ELF) \
-ex 'target remote localhost:1234' \
-ex 'b rust_entry' \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ArceOS was inspired a lot by [Unikraft](https://github.com/unikraft/unikraft).
* [x] VirtIO net/blk/gpu drivers
* [x] TCP/UDP net stack using [smoltcp](https://github.com/smoltcp-rs/smoltcp)
* [x] Synchronization/Mutex
* [x] SMP scheduling with single run queue
* [x] SMP scheduling with [per-cpu run queue](https://github.com/arceos-org/arceos/discussions/181)
* [x] File system
* [ ] Compatible with Linux apps
* [ ] Interrupt driven device I/O
Expand Down
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"]
equation314 marked this conversation as resolved.
Show resolved Hide resolved
smp = ["axhal/smp", "axruntime/smp", "axtask?/smp", "kspin/smp"]

# Floating point/SIMD
fp_simd = ["axhal/fp_simd"]
Expand Down
7 changes: 7 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ See [arceos-apps](https://github.com/arceos-org/arceos-apps) for example applica
Documentation of ArceOS [modules](../modules), [api](../api), and [ulib](../ulib) are generated by [`rustdoc`](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) and hosted on GitHub Pages:

* https://arceos-org.github.io/arceos/

## Discussions

* [Rust std support](https://github.com/arceos-org/arceos/discussions/92)
* [ArceOS for ARM64](https://github.com/arceos-org/arceos/discussions/101)
* [ArceOS for RISCV Hardware](https://github.com/arceos-org/arceos/discussions/120)
* [Per-CPU scheduling](https://github.com/arceos-org/arceos/discussions/181)
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
14 changes: 12 additions & 2 deletions modules/axtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ 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",
"dep:cpumask",
]
irq = []
tls = ["axhal/tls"]
preempt = ["irq", "percpu?/preempt", "kernel_guard/preempt"]
smp = ["kspin/smp"]

sched_fifo = ["multitask"]
sched_rr = ["multitask", "preempt"]
Expand All @@ -39,6 +48,7 @@ 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 }
cpumask = { git = "https://github.com/arceos-org/cpumask.git", optional = true }

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

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

pub(crate) use crate::run_queue::{AxRunQueue, RUN_QUEUE};
use kernel_guard::{NoOp, NoPreemptIrqSave};

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

#[doc(cfg(feature = "multitask"))]
pub use crate::task::{CurrentTask, TaskId, TaskInner};
Expand All @@ -14,6 +16,9 @@ pub use crate::wait_queue::WaitQueue;
/// The reference type of a task.
pub type AxTaskRef = Arc<AxTask>;

/// The wrapper type for cpumask::CpuMask with SMP configuration.
pub type CpuMask = cpumask::CpuMask<{ axconfig::SMP }>;

cfg_if::cfg_if! {
if #[cfg(feature = "sched_rr")] {
const MAX_TIME_SLICE: usize = 5;
Expand Down Expand Up @@ -77,6 +82,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 +93,15 @@ pub fn init_scheduler_secondary() {
#[doc(cfg(feature = "irq"))]
pub fn on_timer_tick() {
crate::timers::check_events();
RUN_QUEUE.lock().scheduler_timer_tick();
// Since irq and preemption are both disabled here,
// we can get current run queue with the default `kernel_guard::NoOp`.
current_run_queue::<NoOp>().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());
select_run_queue::<NoPreemptIrqSave>(&task_ref).add_task(task_ref.clone());
task_ref
}

Expand Down Expand Up @@ -129,13 +138,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::<NoPreemptIrqSave>().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::<NoPreemptIrqSave>().yield_current()
}

/// Current task is going to sleep for the given duration.
Expand All @@ -150,14 +159,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::<NoPreemptIrqSave>().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::<NoPreemptIrqSave>().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
Loading