Skip to content

Commit bcc354a

Browse files
authored
Introduce max-cpu-num config item, remove all direct usages of axconfig::plat::CPU_NUM, use axplat to get cpu num. (arceos-org#317)
* squash from 28dc592 to 4f805fb * update axplat_crates for arceos-helloworld-myplat * fix errors after cherry-picking * add `smp = {}` output for test purpose * fix an out-dated comment * move `init_cpu_num` into `init_later` * cache `cpu_num` in select_run_queue_index
1 parent 9b740db commit bcc354a

File tree

22 files changed

+182
-65
lines changed

22 files changed

+182
-65
lines changed

Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# - `ARCH`: Target architecture: x86_64, riscv64, aarch64, loongarch64
44
# - `MYPLAT`: Package name of the target platform crate.
55
# - `PLAT_CONFIG`: Path to the platform configuration file.
6-
# - `SMP`: Number of CPUs. If not set, use the default value from platform config.
6+
# - `SMP`: Override maximum CPU number specified in the platform config. For
7+
# statically configured platforms, this is also the number of CPUs to boot
8+
# and for platforms with runtime CPU detection, this is the upper limit of
9+
# CPUs.
710
# - `MODE`: Build mode: release, debug
811
# - `LOG:` Logging level: warn, error, info, debug, trace
912
# - `V`: Verbose level: (empty), 1, 2

api/arceos_api/src/imp/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ mod stdio {
3939
}
4040
}
4141

42+
mod sys {
43+
pub use axhal::cpu_num as ax_get_cpu_num;
44+
pub use axhal::power::system_off as ax_terminate;
45+
}
46+
4247
mod time {
4348
pub use axhal::time::{
4449
TimeValue as AxTimeValue, monotonic_time as ax_monotonic_time, wall_time as ax_wall_time,
@@ -47,8 +52,8 @@ mod time {
4752

4853
pub use self::mem::*;
4954
pub use self::stdio::*;
55+
pub use self::sys::*;
5056
pub use self::task::*;
5157
pub use self::time::*;
5258

53-
pub use axhal::power::system_off as ax_terminate;
5459
pub use axio::PollState as AxPollState;

api/arceos_api/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub mod sys {
3232
define_api! {
3333
/// Shutdown the whole system and all CPUs.
3434
pub fn ax_terminate() -> !;
35+
36+
/// Returns the number of CPUs in the system.
37+
pub fn ax_get_cpu_num() -> usize;
3538
}
3639
}
3740

api/arceos_posix_api/src/imp/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn sys_sysconf(name: c_int) -> c_long {
1515
// Page size
1616
ctypes::_SC_PAGE_SIZE => Ok(PAGE_SIZE_4K),
1717
// Number of processors in use
18-
ctypes::_SC_NPROCESSORS_ONLN => Ok(axconfig::plat::CPU_NUM),
18+
ctypes::_SC_NPROCESSORS_ONLN => Ok(axhal::cpu_num()),
1919
// Total physical pages
2020
ctypes::_SC_PHYS_PAGES => Ok(axhal::mem::total_ram_size() / PAGE_SIZE_4K),
2121
// Avaliable physical pages

configs/custom/x86_64-pc-oslab.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ package = "axplat-x86-pc" # str
99
# Platform configs
1010
#
1111
[plat]
12-
# Number of CPUs.
13-
cpu-num = 8 # uint
12+
# Maximum number of CPUs. For platforms that do not support runtime CPU number
13+
# detection, it's also the number of CPUs to boot (like this platform).
14+
max-cpu-num = 8 # uint
1415
# Base address of the whole physical memory.
1516
phys-memory-base = 0 # uint
1617
# Size of the whole physical memory. (2G)

configs/dummy.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ ticks-per-sec = 100 # uint
1515
#
1616
[plat]
1717
# Platform family.
18-
# Number of CPUs
19-
cpu-num = 1 # uint
18+
# Maximum number of CPUs. For platforms that do not support runtime CPU number
19+
# detection, it's also the number of CPUs to boot.
20+
max-cpu-num = 1 # uint
2021
# Base address of the whole physical memory.
2122
phys-memory-base = 0 # uint
2223
# Size of the whole physical memory.

examples/helloworld-myplat/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ cfg-if = "1.0"
1818
axstd = { workspace = true, features = ["myplat"], optional = true }
1919

2020
[target.'cfg(target_arch = "x86_64")'.dependencies]
21-
axplat-x86-pc = { version = "0.2", features = ["smp", "irq"], optional = true }
21+
axplat-x86-pc = { version = "0.3", features = ["smp", "irq"], optional = true }
2222

2323
[target.'cfg(target_arch = "aarch64")'.dependencies]
24-
axplat-aarch64-qemu-virt = { version = "0.2", features = ["smp", "irq"], optional = true }
25-
axplat-aarch64-raspi = { version = "0.2", features = ["smp", "irq"], optional = true }
26-
axplat-aarch64-bsta1000b = { version = "0.2", features = ["smp", "irq"], optional = true }
27-
axplat-aarch64-phytium-pi = { version = "0.2", features = ["smp", "irq"], optional = true }
24+
axplat-aarch64-qemu-virt = { version = "0.3", features = ["smp", "irq"], optional = true }
25+
axplat-aarch64-raspi = { version = "0.3", features = ["smp", "irq"], optional = true }
26+
axplat-aarch64-bsta1000b = { version = "0.3", features = ["smp", "irq"], optional = true }
27+
axplat-aarch64-phytium-pi = { version = "0.3", features = ["smp", "irq"], optional = true }
2828

2929
[target.'cfg(target_arch = "riscv64")'.dependencies]
30-
axplat-riscv64-qemu-virt = { version = "0.2", features = ["smp", "irq"], optional = true }
30+
axplat-riscv64-qemu-virt = { version = "0.3", features = ["smp", "irq"], optional = true }
3131

3232
[target.'cfg(target_arch = "loongarch64")'.dependencies]
33-
axplat-loongarch64-qemu-virt = { version = "0.2", features = ["smp", "irq"], optional = true }
33+
axplat-loongarch64-qemu-virt = { version = "0.3", features = ["smp", "irq"], optional = true }

modules/axhal/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ memory_addr = "0.4"
3636
linkme = { version = "0.3.33", optional = true }
3737
page_table_multiarch = { version = "0.5", features = ["copy-from"], optional = true }
3838
axcpu = "0.2"
39-
axplat = "0.2"
39+
axplat = "0.3"
4040
axlog = { workspace = true }
4141
axconfig = { workspace = true }
4242
axalloc = { workspace = true, optional = true }
4343

4444
[target.'cfg(target_arch = "x86_64")'.dependencies]
45-
axplat-x86-pc = { version = "0.2", optional = true }
45+
axplat-x86-pc = { version = "0.3", optional = true }
4646

4747
[target.'cfg(target_arch = "aarch64")'.dependencies]
4848
aarch64-cpu = "10.0"
49-
axplat-aarch64-qemu-virt = { version = "0.2", optional = true }
49+
axplat-aarch64-qemu-virt = { version = "0.3", optional = true }
5050

5151
[target.'cfg(target_arch = "riscv64")'.dependencies]
52-
axplat-riscv64-qemu-virt = { version = "0.2", optional = true }
52+
axplat-riscv64-qemu-virt = { version = "0.3", optional = true }
5353

5454
[target.'cfg(target_arch = "loongarch64")'.dependencies]
55-
axplat-loongarch64-qemu-virt = { version = "0.2", optional = true }
55+
axplat-loongarch64-qemu-virt = { version = "0.3", optional = true }
5656

5757
[build-dependencies]
5858
axconfig = { workspace = true }

modules/axhal/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn gen_linker_script(arch: &str, platform: &str) -> Result<()> {
2424
"%KERNEL_BASE%",
2525
&format!("{:#x}", axconfig::plat::KERNEL_BASE_VADDR),
2626
);
27-
let ld_content = ld_content.replace("%CPU_NUM%", &format!("{}", axconfig::plat::CPU_NUM));
27+
let ld_content = ld_content.replace("%CPU_NUM%", &format!("{}", axconfig::plat::MAX_CPU_NUM));
2828

2929
// target/<target_triple>/<mode>/build/axhal-xxxx/out
3030
let out_dir = std::env::var("OUT_DIR").unwrap();

0 commit comments

Comments
 (0)