diff --git a/Cargo.lock b/Cargo.lock index 4ff56a5ea3..a05e9f9f51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -536,7 +536,7 @@ dependencies = [ "axconfig", "axcpu", "axlog", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "axplat-aarch64-qemu-virt", "axplat-loongarch64-qemu-virt", "axplat-riscv64-qemu-virt", @@ -579,7 +579,7 @@ version = "0.1.0" source = "git+https://github.com/arceos-hypervisor/axklib.git#22d120d3cecc905340f31cb6895f8b47f28103a9" dependencies = [ "axerrno", - "axplat", + "axplat 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memory_addr", "trait-ffi", ] @@ -658,12 +658,27 @@ dependencies = [ "lazyinit", ] +[[package]] +name = "axplat" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4de04c54b63bf2ca1ff202733d2516da49d7779649cdb2f9c4ecf22909e6810" +dependencies = [ + "axplat-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 2.10.0", + "const-str", + "crate_interface", + "handler_table", + "kspin", + "memory_addr", +] + [[package]] name = "axplat" version = "0.2.0" source = "git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0#3345f58f3da5ef2eafcfa1fcf1ac32e5e80e1a7d" dependencies = [ - "axplat-macros", + "axplat-macros 0.1.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "bitflags 2.10.0", "const-str", "crate_interface", @@ -679,7 +694,7 @@ source = "git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0# dependencies = [ "axconfig-macros", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "axplat-aarch64-peripherals", "dw_apb_uart", "kspin", @@ -697,7 +712,7 @@ dependencies = [ "arm_pl011", "arm_pl031", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "int_ratio", "kspin", "lazyinit", @@ -713,7 +728,7 @@ source = "git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0# dependencies = [ "axconfig-macros", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "axplat-aarch64-peripherals", "log", "page_table_entry", @@ -726,7 +741,7 @@ source = "git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0# dependencies = [ "axconfig-macros", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "axplat-aarch64-peripherals", "log", "page_table_entry", @@ -740,7 +755,7 @@ dependencies = [ "aarch64-cpu 10.0.0", "axconfig-macros", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "axplat-aarch64-peripherals", "log", "page_table_entry", @@ -753,7 +768,7 @@ source = "git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0# dependencies = [ "axconfig-macros", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "chrono", "kspin", "lazyinit", @@ -763,6 +778,17 @@ dependencies = [ "page_table_entry", ] +[[package]] +name = "axplat-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90dfaee06a112fe4f810c60af1a86bc080af2172185b491cacc307b84dff748" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.108", +] + [[package]] name = "axplat-macros" version = "0.1.0" @@ -780,7 +806,7 @@ source = "git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0# dependencies = [ "axconfig-macros", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "log", "riscv", "riscv_goldfish", @@ -794,7 +820,7 @@ source = "git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0# dependencies = [ "axconfig-macros", "axcpu", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "bitflags 2.10.0", "heapless 0.9.1", "int_ratio", @@ -826,7 +852,7 @@ dependencies = [ "axlog", "axmm", "axnet", - "axplat", + "axplat 0.2.0 (git+https://github.com/arceos-hypervisor/axplat_crates?tag=vmm-v0.3.0)", "axtask", "chrono", "crate_interface", diff --git a/modules/axtask/src/api.rs b/modules/axtask/src/api.rs index 1e3fdca726..e005822cdc 100644 --- a/modules/axtask/src/api.rs +++ b/modules/axtask/src/api.rs @@ -1,5 +1,7 @@ //! Task APIs for multi-task configuration. +use core::sync::atomic::AtomicUsize; + use alloc::{string::String, sync::Arc}; use kernel_guard::NoPreemptIrqSave; @@ -19,6 +21,8 @@ pub type AxTaskRef = Arc; /// The wrapper type for [`cpumask::CpuMask`] with SMP configuration. pub type AxCpuMask = cpumask::CpuMask<{ axconfig::plat::CPU_NUM }>; +static CPU_NUM: AtomicUsize = AtomicUsize::new(1); + cfg_if::cfg_if! { if #[cfg(feature = "sched-rr")] { const MAX_TIME_SLICE: usize = 5; @@ -70,8 +74,13 @@ pub fn current() -> CurrentTask { /// Initializes the task scheduler (for the primary CPU). pub fn init_scheduler() { - info!("Initialize scheduling..."); + init_scheduler_with_cpu_num(axconfig::plat::CPU_NUM); +} +/// Initializes the task scheduler with cpu_num (for the primary CPU). +pub fn init_scheduler_with_cpu_num(cpu_num: usize) { + info!("Initialize scheduling..."); + CPU_NUM.store(cpu_num, core::sync::atomic::Ordering::Relaxed); crate::run_queue::init(); #[cfg(feature = "irq")] crate::timers::init(); @@ -79,6 +88,10 @@ pub fn init_scheduler() { info!(" use {} scheduler.", Scheduler::scheduler_name()); } +pub(crate) fn active_cpu_num() -> usize { + CPU_NUM.load(core::sync::atomic::Ordering::Relaxed) +} + /// Initializes the task scheduler for secondary CPUs. pub fn init_scheduler_secondary() { crate::run_queue::init_secondary(); diff --git a/modules/axtask/src/task.rs b/modules/axtask/src/task.rs index 603717bfd9..8ba25dc024 100644 --- a/modules/axtask/src/task.rs +++ b/modules/axtask/src/task.rs @@ -224,6 +224,11 @@ impl TaskInner { // private methods impl TaskInner { fn new_common(id: TaskId, name: String) -> Self { + let mut cpumask = AxCpuMask::new(); + for cpu_id in 0..crate::api::active_cpu_num() { + cpumask.set(cpu_id, true); + } + Self { id, name, @@ -232,7 +237,7 @@ impl TaskInner { entry: None, state: AtomicU8::new(TaskState::Ready as u8), // By default, the task is allowed to run on all CPUs. - cpumask: SpinNoIrq::new(AxCpuMask::full()), + cpumask: SpinNoIrq::new(cpumask), in_wait_queue: AtomicBool::new(false), #[cfg(feature = "irq")] timer_ticket_id: AtomicU64::new(0),