diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7e8b5678cf..5df991adf9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -119,16 +119,16 @@ jobs: - name: Build helloworld for x86_64-pc-oslab run: make PLATFORM=x86_64-pc-oslab A=apps/helloworld - name: Build net/httpserver for x86_64-pc-oslab - run: make PLATFORM=x86_64-pc-oslab A=apps/net/httpserver APP_FEATURES=axstd/driver-ixgbe + run: make PLATFORM=x86_64-pc-oslab A=apps/net/httpserver FEATURES=ax/driver-ixgbe - name: Build c/iperf for x86_64-pc-oslab - run: make PLATFORM=x86_64-pc-oslab A=apps/c/iperf APP_FEATURES=axstd/driver-ixgbe,axstd/driver-ramdisk + run: make PLATFORM=x86_64-pc-oslab A=apps/c/iperf FEATURES=ax/driver-ixgbe,ax/driver-ramdisk - name: Build c/redis for x86_64-pc-oslab - run: make PLATFORM=x86_64-pc-oslab A=apps/c/redis APP_FEATURES=axstd/driver-ixgbe,axstd/driver-ramdisk SMP=4 + run: make PLATFORM=x86_64-pc-oslab A=apps/c/redis FEATURES=ax/driver-ixgbe,ax/driver-ramdisk SMP=4 - name: Build helloworld for aarch64-raspi4 run: make PLATFORM=aarch64-raspi4 A=apps/helloworld - name: Build fs/shell for aarch64-raspi4 - run: make PLATFORM=aarch64-raspi4 A=apps/fs/shell APP_FEATURES=axstd/driver-bcm2835-sdhci + run: make PLATFORM=aarch64-raspi4 A=apps/fs/shell FEATURES=ax/driver-bcm2835-sdhci build-apps-for-std: runs-on: ${{ matrix.os }} diff --git a/Cargo.lock b/Cargo.lock index b4425ed8cf..e6acce105d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,6 +123,7 @@ dependencies = [ name = "arceos-parallel" version = "0.1.0" dependencies = [ + "axfeat", "axstd", "rand", ] @@ -131,6 +132,7 @@ dependencies = [ name = "arceos-priority" version = "0.1.0" dependencies = [ + "axfeat", "axstd", ] @@ -138,6 +140,7 @@ dependencies = [ name = "arceos-shell" version = "0.1.0" dependencies = [ + "axfeat", "axfs_ramfs", "axfs_vfs", "axstd", @@ -148,6 +151,7 @@ dependencies = [ name = "arceos-sleep" version = "0.1.0" dependencies = [ + "axfeat", "axstd", ] @@ -162,6 +166,7 @@ dependencies = [ name = "arceos-yield" version = "0.1.0" dependencies = [ + "axfeat", "axstd", ] @@ -260,6 +265,23 @@ dependencies = [ "log", ] +[[package]] +name = "axfeat" +version = "0.1.0" +dependencies = [ + "axalloc", + "axdisplay", + "axdriver", + "axfs", + "axhal", + "axlog", + "axnet", + "axruntime", + "axsync", + "axtask", + "spinlock", +] + [[package]] name = "axfs" version = "0.1.0" @@ -425,8 +447,8 @@ dependencies = [ "axalloc", "axconfig", "axdisplay", - "axdriver", "axerrno", + "axfeat", "axfs", "axhal", "axio", @@ -605,9 +627,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" +dependencies = [ + "libc", +] [[package]] name = "cexpr" @@ -1236,9 +1261,9 @@ version = "0.1.0" [[package]] name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" @@ -1644,9 +1669,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "1ee020b1716f0a80e2ace9b03441a749e402e86712f15f16fe8a8f75afac732f" dependencies = [ "bitflags 2.3.3", "errno", @@ -1715,18 +1740,18 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.179" +version = "1.0.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5bf42b8d227d4abf38a1ddb08602e229108a517cd4e5bb28f9c7eaafdce5c0" +checksum = "0ea67f183f058fe88a4e3ec6e2788e003840893b91bac4559cabedd00863b3ed" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.179" +version = "1.0.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "741e124f5485c7e60c03b043f79f320bff3527f4bbf12cf3831750dc46a0ec2c" +checksum = "24e744d7782b686ab3b73267ef05697159cc0e5abbed3f47f9933165e5219036" dependencies = [ "proc-macro2", "quote", @@ -2218,9 +2243,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd122eb777186e60c3fdf765a58ac76e41c582f1f535fbf3314434c6b58f3f7" +checksum = "f46aab759304e4d7b2075a9aecba26228bb073ee8c50db796b2c72c676b5d807" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 9c3d3d5a6d..1b6f267b6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,21 +2,6 @@ resolver = "2" members = [ - "apps/display", - "apps/exception", - "apps/helloworld", - "apps/memtest", - "apps/fs/shell", - "apps/net/echoserver", - "apps/net/httpclient", - "apps/net/httpserver", - "apps/net/udpserver", - "apps/net/bwbench", - "apps/task/parallel", - "apps/task/sleep", - "apps/task/yield", - "apps/task/priority", - "crates/allocator", "crates/arm_gic", "crates/arm_pl011", @@ -62,8 +47,25 @@ members = [ "modules/axsync", "modules/axtask", + "api/axfeat", + "ulib/axstd", "ulib/axlibc", + + "apps/display", + "apps/exception", + "apps/helloworld", + "apps/memtest", + "apps/fs/shell", + "apps/net/echoserver", + "apps/net/httpclient", + "apps/net/httpserver", + "apps/net/udpserver", + "apps/net/bwbench", + "apps/task/parallel", + "apps/task/sleep", + "apps/task/yield", + "apps/task/priority", ] [profile.release] diff --git a/Makefile b/Makefile index 9c07d43551..4094e129d3 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ V ?= # App options A ?= apps/helloworld APP ?= $(A) -APP_FEATURES ?= +FEATURES ?= # QEMU options BLK ?= n diff --git a/README.md b/README.md index 6df1b47f9f..131c56d49f 100644 --- a/README.md +++ b/README.md @@ -148,9 +148,9 @@ Note that the `NET=y` argument is required to enable the network device in QEMU. ```bash # in features.txt - alloc - paging - net + ax/paging # enable `paing` feature for ArceOS modules + lib/alloc # enable `alloc` feature for the libc + lib/net # enable `net` feature for the libc ``` 3. Build your application with ArceOS, by running the `make` command in the application directory: diff --git a/api/axfeat/Cargo.toml b/api/axfeat/Cargo.toml new file mode 100644 index 0000000000..a6b91fb7d9 --- /dev/null +++ b/api/axfeat/Cargo.toml @@ -0,0 +1,73 @@ +[package] +name = "axfeat" +version = "0.1.0" +edition = "2021" +authors = ["Yuekai Jia "] +description = "Top-level feature selection for ArceOS" +license = "GPL-3.0-or-later OR Apache-2.0" +homepage = "https://github.com/rcore-os/arceos" +repository = "https://github.com/rcore-os/arceos/tree/main/api/axfeat" +documentation = "https://rcore-os.github.io/arceos/axfeat/index.html" + +[features] +default = [] + +# Multicore +smp = ["axhal/smp", "axruntime/smp", "spinlock/smp"] + +# Floating point/SIMD +fp_simd = ["axhal/fp_simd"] + +# Interrupts +irq = ["axhal/irq", "axruntime/irq", "axtask?/irq"] + +# Memory +alloc = ["dep:axalloc", "axruntime/alloc"] +alloc-tlsf = ["axalloc/tlsf"] +alloc-slab = ["axalloc/slab"] +alloc-buddy = ["axalloc/buddy"] +paging = ["alloc", "axhal/paging", "axruntime/paging"] + +# Multi-threading and scheduler +multitask = ["alloc", "axtask/multitask", "axsync/multitask", "axruntime/multitask"] +sched_fifo = ["axtask/sched_fifo"] +sched_rr = ["axtask/sched_rr", "irq"] +sched_cfs = ["axtask/sched_cfs", "irq"] + +# File system +fs = ["alloc", "paging", "axdriver/virtio-blk", "dep:axfs", "axruntime/fs"] # TODO: try to remove "paging" +myfs = ["axfs?/myfs"] + +# Networking +net = ["alloc", "paging", "axdriver/virtio-net", "dep:axnet", "axruntime/net"] + +# Display +display = ["alloc", "paging", "axdriver/virtio-gpu", "dep:axdisplay", "axruntime/display"] + +# Device drivers +bus-mmio = ["axdriver?/bus-mmio"] +bus-pci = ["axdriver?/bus-pci"] +driver-ramdisk = ["axdriver?/ramdisk", "axfs?/use-ramdisk"] +driver-ixgbe = ["axdriver?/ixgbe"] +driver-bcm2835-sdhci = ["axdriver?/bcm2835-sdhci"] + +# Logging +log-level-off = ["axlog/log-level-off"] +log-level-error = ["axlog/log-level-error"] +log-level-warn = ["axlog/log-level-warn"] +log-level-info = ["axlog/log-level-info"] +log-level-debug = ["axlog/log-level-debug"] +log-level-trace = ["axlog/log-level-trace"] + +[dependencies] +axruntime = { path = "../../modules/axruntime" } +axhal = { path = "../../modules/axhal" } +axlog = { path = "../../modules/axlog" } +axalloc = { path = "../../modules/axalloc", optional = true } +axdriver = { path = "../../modules/axdriver", optional = true } +axfs = { path = "../../modules/axfs", optional = true } +axnet = { path = "../../modules/axnet", optional = true } +axdisplay = { path = "../../modules/axdisplay", optional = true } +axsync = { path = "../../modules/axsync", optional = true } +axtask = { path = "../../modules/axtask", optional = true } +spinlock = { path = "../../crates/spinlock", optional = true } diff --git a/api/axfeat/src/lib.rs b/api/axfeat/src/lib.rs new file mode 100644 index 0000000000..aa5d987d92 --- /dev/null +++ b/api/axfeat/src/lib.rs @@ -0,0 +1,40 @@ +//! Top-level feature selection for [ArceOS]. +//! +//! # Cargo Features +//! +//! - CPU +//! - `smp`: Enable SMP (symmetric multiprocessing) support. +//! - `fp_simd`: Enable floating point and SIMD support. +//! - Interrupts: +//! - `irq`: Enable interrupt handling support. +//! - Memory +//! - `alloc`: Enable dynamic memory allocation. +//! - `alloc-tlsf`: Use the TLSF allocator. +//! - `alloc-slab`: Use the slab allocator. +//! - `alloc-buddy`: Use the buddy system allocator. +//! - `paging`: Enable page table manipulation. +//! - Task management +//! - `multitask`: Enable multi-threading support. +//! - `sched_fifo`: Use the FIFO cooperative scheduler. +//! - `sched_rr`: Use the Round-robin preemptive scheduler. +//! - `sched_cfs`: Use the Completely Fair Scheduler (CFS) preemptive scheduler. +//! - Upperlayer stacks (fs, net, display) +//! - `fs`: Enable file system support. +//! - `myfs`: Allow users to define their custom filesystems to override the default. +//! - `net`: Enable networking support. +//! - `dns`: Enable DNS lookup support. +//! - `display`: Enable graphics support. +//! - Device drivers +//! - `bus-mmio`: Use device tree to probe all MMIO devices. +//! - `bus-pci`: Use PCI bus to probe all PCI devices. +//! - `driver-ramdisk`: Use the RAM disk to emulate the block device. +//! - `driver-ixgbe`: Enable the Intel 82599 10Gbit NIC driver. +//! - `driver-bcm2835-sdhci`: Enable the BCM2835 SDHCI driver (Raspberry Pi SD card). +//! - Logging +//! - `log-level-off`: Disable all logging. +//! - `log-level-error`, `log-level-warn`, `log-level-info`, `log-level-debug`, +//! `log-level-trace`: Keep logging only at the specified level or higher. +//! +//! [ArceOS]: https://github.com/rcore-os/arceos + +#![no_std] diff --git a/apps/c/httpclient/features.txt b/apps/c/httpclient/features.txt index 25ca64f38b..10edbe8fba 100644 --- a/apps/c/httpclient/features.txt +++ b/apps/c/httpclient/features.txt @@ -1,3 +1,3 @@ -alloc -paging -net +ax/paging +lib/alloc +lib/net diff --git a/apps/c/httpserver/features.txt b/apps/c/httpserver/features.txt index 25ca64f38b..10edbe8fba 100644 --- a/apps/c/httpserver/features.txt +++ b/apps/c/httpserver/features.txt @@ -1,3 +1,3 @@ -alloc -paging -net +ax/paging +lib/alloc +lib/net diff --git a/apps/c/iperf/features.txt b/apps/c/iperf/features.txt index bf42f8cfee..614608fc31 100644 --- a/apps/c/iperf/features.txt +++ b/apps/c/iperf/features.txt @@ -1,6 +1,6 @@ -alloc -paging -net -fs -select -fp_simd +ax/paging +lib/fp_simd +lib/alloc +lib/fs +lib/net +lib/select diff --git a/apps/c/memtest/features.txt b/apps/c/memtest/features.txt index 1b71ca850f..f09d8079bd 100644 --- a/apps/c/memtest/features.txt +++ b/apps/c/memtest/features.txt @@ -1,2 +1,2 @@ -alloc -paging +ax/paging +lib/alloc diff --git a/apps/c/pthread/basic/features.txt b/apps/c/pthread/basic/features.txt index 6ca9b0c5f7..ef2eeaa243 100644 --- a/apps/c/pthread/basic/features.txt +++ b/apps/c/pthread/basic/features.txt @@ -1,3 +1,3 @@ -alloc -paging -multitask +ax/paging +lib/alloc +lib/multitask diff --git a/apps/c/pthread/parallel/features.txt b/apps/c/pthread/parallel/features.txt index 6ca9b0c5f7..ef2eeaa243 100644 --- a/apps/c/pthread/parallel/features.txt +++ b/apps/c/pthread/parallel/features.txt @@ -1,3 +1,3 @@ -alloc -paging -multitask +ax/paging +lib/alloc +lib/multitask diff --git a/apps/c/pthread/parallel/test_cmd b/apps/c/pthread/parallel/test_cmd index 333e19fd5d..e1f8471a08 100644 --- a/apps/c/pthread/parallel/test_cmd +++ b/apps/c/pthread/parallel/test_cmd @@ -1,3 +1,3 @@ test_one "SMP=4 LOG=info" "expect_info_smp4_fifo.out" -test_one "SMP=4 LOG=info APP_FEATURES=axstd/sched_rr" "expect_info_smp4_rr.out" +test_one "SMP=4 LOG=info FEATURES=ax/sched_rr" "expect_info_smp4_rr.out" rm -f $APP/*.o diff --git a/apps/c/pthread/pipe/features.txt b/apps/c/pthread/pipe/features.txt index be558434d3..46525446fb 100644 --- a/apps/c/pthread/pipe/features.txt +++ b/apps/c/pthread/pipe/features.txt @@ -1,4 +1,4 @@ -paging -alloc -multitask -pipe +ax/paging +lib/alloc +lib/multitask +lib/pipe diff --git a/apps/c/pthread/sleep/features.txt b/apps/c/pthread/sleep/features.txt index efe7876d34..1d86a206df 100644 --- a/apps/c/pthread/sleep/features.txt +++ b/apps/c/pthread/sleep/features.txt @@ -1,4 +1,4 @@ -paging -alloc -multitask -irq +ax/paging +ax/irq +lib/alloc +lib/multitask diff --git a/apps/c/redis/features.txt b/apps/c/redis/features.txt index 8422cb83c0..dfe90731c7 100644 --- a/apps/c/redis/features.txt +++ b/apps/c/redis/features.txt @@ -1,9 +1,8 @@ -alloc -paging -fp_simd -irq -multitask -fs -net -pipe -epoll +ax/paging +ax/fp_simd +lib/alloc +lib/multitask +lib/fs +lib/net +lib/pipe +lib/epoll diff --git a/apps/c/sqlite3/features.txt b/apps/c/sqlite3/features.txt index e1814d00a3..ec0e9b61d2 100644 --- a/apps/c/sqlite3/features.txt +++ b/apps/c/sqlite3/features.txt @@ -1,4 +1,4 @@ -fp_simd -alloc -paging -fs +ax/paging +ax/fp_simd +lib/alloc +lib/fs diff --git a/apps/c/sqlite3/test_cmd b/apps/c/sqlite3/test_cmd index 70170cc52c..c977beb895 100644 --- a/apps/c/sqlite3/test_cmd +++ b/apps/c/sqlite3/test_cmd @@ -1,4 +1,4 @@ test_one "LOG=info BLK=y" "expect_info.out" test_one "LOG=info BLK=y" "expect_info_again.out" -test_one "LOG=info BLK=y APP_FEATURES=axstd/driver-ramdisk" "expect_info_ramdisk.out" +test_one "LOG=info BLK=y FEATURES=ax/driver-ramdisk" "expect_info_ramdisk.out" rm -f $APP/*.o diff --git a/apps/c/udpserver/features.txt b/apps/c/udpserver/features.txt index 25ca64f38b..10edbe8fba 100644 --- a/apps/c/udpserver/features.txt +++ b/apps/c/udpserver/features.txt @@ -1,3 +1,3 @@ -alloc -paging -net +ax/paging +lib/alloc +lib/net diff --git a/apps/fs/shell/Cargo.toml b/apps/fs/shell/Cargo.toml index bd99c1d11b..de85e19879 100644 --- a/apps/fs/shell/Cargo.toml +++ b/apps/fs/shell/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -use-ramfs = ["axstd/myfs", "dep:axfs_vfs", "dep:axfs_ramfs", "dep:crate_interface"] +use-ramfs = ["axfeat/myfs", "dep:axfs_vfs", "dep:axfs_ramfs", "dep:crate_interface"] default = [] [dependencies] @@ -15,3 +15,4 @@ axfs_vfs = { path = "../../../crates/axfs_vfs", optional = true } axfs_ramfs = { path = "../../../crates/axfs_ramfs", optional = true } crate_interface = { path = "../../../crates/crate_interface", optional = true } axstd = { path = "../../../ulib/axstd", features = ["alloc", "fs"], optional = true } +axfeat = { path = "../../../api/axfeat", optional = true } diff --git a/apps/memtest/test_cmd b/apps/memtest/test_cmd index dfa19caf9f..bd587f61e4 100644 --- a/apps/memtest/test_cmd +++ b/apps/memtest/test_cmd @@ -1 +1 @@ -test_one "LOG=trace APP_FEATURES=axstd/paging" "expect_trace.out" +test_one "LOG=trace FEATURES=ax/paging" "expect_trace.out" diff --git a/apps/net/httpclient/test_cmd b/apps/net/httpclient/test_cmd index f56d6d43d4..0689236fd7 100644 --- a/apps/net/httpclient/test_cmd +++ b/apps/net/httpclient/test_cmd @@ -1,2 +1,2 @@ test_one "LOG=info NET=y" "expect_info.out" -test_one "LOG=info NET=y APP_FEATURES=dns" "expect_info_dns.out" +test_one "LOG=info NET=y FEATURES=app/dns" "expect_info_dns.out" diff --git a/apps/task/parallel/Cargo.toml b/apps/task/parallel/Cargo.toml index defca45026..e562fbeab7 100644 --- a/apps/task/parallel/Cargo.toml +++ b/apps/task/parallel/Cargo.toml @@ -7,9 +7,10 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -sched_rr = ["axstd/sched_rr"] -sched_cfs = ["axstd/sched_cfs"] +sched_rr = ["axfeat/sched_rr"] +sched_cfs = ["axfeat/sched_cfs"] [dependencies] rand = { version = "0.8", default-features = false, features = ["small_rng"] } axstd = { path = "../../../ulib/axstd", features = ["alloc", "multitask", "irq"], optional = true } +axfeat = { path = "../../../api/axfeat", optional = true } diff --git a/apps/task/parallel/test_cmd b/apps/task/parallel/test_cmd index a4d38e89e5..41a22799df 100644 --- a/apps/task/parallel/test_cmd +++ b/apps/task/parallel/test_cmd @@ -1,3 +1,3 @@ test_one "LOG=info" "expect_info_smp1_fifo.out" -test_one "SMP=4 LOG=info APP_FEATURES=sched_rr" "expect_info_smp4_rr.out" -test_one "SMP=4 LOG=info APP_FEATURES=sched_cfs" "expect_info_smp4_cfs.out" +test_one "SMP=4 LOG=info FEATURES=app/sched_rr" "expect_info_smp4_rr.out" +test_one "SMP=4 LOG=info FEATURES=app/sched_cfs" "expect_info_smp4_cfs.out" diff --git a/apps/task/priority/Cargo.toml b/apps/task/priority/Cargo.toml index 19c32545fb..2c14e7ba2a 100644 --- a/apps/task/priority/Cargo.toml +++ b/apps/task/priority/Cargo.toml @@ -7,8 +7,9 @@ authors = ["Haoxing Ye "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -sched_rr = ["axstd/sched_rr"] -sched_cfs = ["axstd/sched_cfs"] +sched_rr = ["axfeat/sched_rr"] +sched_cfs = ["axfeat/sched_cfs"] [dependencies] axstd = { path = "../../../ulib/axstd", features = ["alloc", "multitask"], optional = true } +axfeat = { path = "../../../api/axfeat", optional = true } diff --git a/apps/task/priority/test_cmd b/apps/task/priority/test_cmd index 6c0bd6b3a2..a529eb1325 100644 --- a/apps/task/priority/test_cmd +++ b/apps/task/priority/test_cmd @@ -1,4 +1,4 @@ test_one "SMP=1 LOG=info" "expect_info_smp1_fifo.out" -test_one "SMP=1 LOG=info APP_FEATURES=sched_cfs" "expect_info_smp1_cfs.out" -test_one "SMP=1 LOG=info APP_FEATURES=sched_rr" "expect_info_smp1_rr.out" -test_one "SMP=4 LOG=info APP_FEATURES=sched_cfs" "expect_info_smp4_cfs.out" +test_one "SMP=1 LOG=info FEATURES=app/sched_cfs" "expect_info_smp1_cfs.out" +test_one "SMP=1 LOG=info FEATURES=app/sched_rr" "expect_info_smp1_rr.out" +test_one "SMP=4 LOG=info FEATURES=app/sched_cfs" "expect_info_smp4_cfs.out" diff --git a/apps/task/sleep/Cargo.toml b/apps/task/sleep/Cargo.toml index c286ff2d7d..29150925b7 100644 --- a/apps/task/sleep/Cargo.toml +++ b/apps/task/sleep/Cargo.toml @@ -7,7 +7,8 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -sched_rr = ["axstd/sched_rr"] +sched_rr = ["axfeat/sched_rr"] [dependencies] axstd = { path = "../../../ulib/axstd", features = ["multitask", "irq"], optional = true } +axfeat = { path = "../../../api/axfeat", optional = true } diff --git a/apps/task/sleep/test_cmd b/apps/task/sleep/test_cmd index 632d343f0d..0e32e3a43c 100644 --- a/apps/task/sleep/test_cmd +++ b/apps/task/sleep/test_cmd @@ -1,2 +1,2 @@ test_one "SMP=4 LOG=info" "expect_info_smp4_fifo.out" -test_one "SMP=4 LOG=info APP_FEATURES=sched_rr" "expect_info_smp4_rr.out" +test_one "SMP=4 LOG=info FEATURES=app/sched_rr" "expect_info_smp4_rr.out" diff --git a/apps/task/yield/Cargo.toml b/apps/task/yield/Cargo.toml index 228bd7bb57..d9bdc97b8a 100644 --- a/apps/task/yield/Cargo.toml +++ b/apps/task/yield/Cargo.toml @@ -7,8 +7,9 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -sched_rr = ["axstd/sched_rr"] -sched_cfs = ["axstd/sched_cfs"] +sched_rr = ["axfeat/sched_rr"] +sched_cfs = ["axfeat/sched_cfs"] [dependencies] axstd = { path = "../../../ulib/axstd", features = ["multitask"], optional = true } +axfeat = { path = "../../../api/axfeat", optional = true } diff --git a/apps/task/yield/test_cmd b/apps/task/yield/test_cmd index bf30e3ba40..2d594d1283 100644 --- a/apps/task/yield/test_cmd +++ b/apps/task/yield/test_cmd @@ -1,3 +1,3 @@ test_one "LOG=debug" "expect_debug_smp1_fifo.out" test_one "SMP=4 LOG=info" "expect_info_smp4_fifo.out" -test_one "SMP=4 LOG=info APP_FEATURES=sched_rr" "expect_info_smp4_rr.out" +test_one "SMP=4 LOG=info FEATURES=app/sched_rr" "expect_info_smp4_rr.out" diff --git a/modules/axhal/src/platform/x86_pc/misc.rs b/modules/axhal/src/platform/x86_pc/misc.rs index 6d88863f4b..f4534ef3dd 100644 --- a/modules/axhal/src/platform/x86_pc/misc.rs +++ b/modules/axhal/src/platform/x86_pc/misc.rs @@ -7,9 +7,12 @@ pub fn terminate() -> ! { info!("Shutting down..."); #[cfg(platform = "x86_64-pc-oslab")] - unsafe { - PortWriteOnly::new(0x64).write(0xfeu8) - }; + { + axlog::ax_println!("Run completed, press any key to reboot ..."); + while super::console::getchar().is_none() {} + axlog::ax_println!("Rebooting ..."); + unsafe { PortWriteOnly::new(0x64).write(0xfeu8) }; + } #[cfg(platform = "x86_64-qemu-q35")] unsafe { diff --git a/modules/axruntime/Cargo.toml b/modules/axruntime/Cargo.toml index e4880cc32a..d8fbaf9d6d 100644 --- a/modules/axruntime/Cargo.toml +++ b/modules/axruntime/Cargo.toml @@ -12,12 +12,12 @@ documentation = "https://rcore-os.github.io/arceos/axruntime/index.html" [features] default = [] -smp = ["axhal/smp"] -irq = ["axhal/irq", "axtask?/irq", "percpu", "kernel_guard"] +smp = [] +irq = ["axhal/irq", "percpu", "kernel_guard"] alloc = ["axalloc"] paging = ["axhal/paging", "lazy_init"] -multitask = ["axtask/multitask"] +multitask = ["axtask"] fs = ["axdriver", "axfs"] net = ["axdriver", "axnet"] display = ["axdriver", "axdisplay"] diff --git a/scripts/make/build.mk b/scripts/make/build.mk index 28ba4cac5f..0a58739ffb 100644 --- a/scripts/make/build.mk +++ b/scripts/make/build.mk @@ -1,6 +1,7 @@ # Main building script include scripts/make/cargo.mk +include scripts/make/features.mk ifeq ($(APP_TYPE), c) include scripts/make/build_c.mk @@ -17,6 +18,10 @@ else ifeq ($(filter $(MAKECMDGOALS),clippy unittest unittest_no_fail_fast),) # n ifneq ($(V),) $(info APP: "$(APP)") $(info APP_TYPE: "$(APP_TYPE)") + $(info FEATURES: "$(FEATURES)") + $(info AX_FEAT: "$(AX_FEAT)") + $(info LIB_FEAT: "$(LIB_FEAT)") + $(info APP_FEAT: "$(APP_FEAT)") endif ifeq ($(APP_TYPE), c) $(if $(V), $(info CFLAGS: "$(CFLAGS)") $(info LDFLAGS: "$(LDFLAGS)")) @@ -29,10 +34,10 @@ endif _cargo_build: @printf " $(GREEN_C)Building$(END_C) App: $(APP_NAME), Arch: $(ARCH), Platform: $(PLATFORM_NAME), App type: $(APP_TYPE)\n" ifeq ($(APP_TYPE), rust) - $(call cargo_rustc,--manifest-path $(APP)/Cargo.toml) + $(call cargo_build,--manifest-path $(APP)/Cargo.toml,$(AX_FEAT) $(LIB_FEAT) $(APP_FEAT)) @cp $(rust_elf) $(OUT_ELF) else ifeq ($(APP_TYPE), c) - $(call cargo_rustc,-p axlibc) + $(call cargo_build,-p axfeat -p axlibc,$(AX_FEAT) $(LIB_FEAT)) endif $(OUT_DIR): diff --git a/scripts/make/build_c.mk b/scripts/make/build_c.mk index d59cd1d832..8ac0ec3ac7 100644 --- a/scripts/make/build_c.mk +++ b/scripts/make/build_c.mk @@ -15,6 +15,11 @@ ulib_src := $(wildcard $(src_dir)/*.c) ulib_hdr := $(wildcard $(inc_dir)/*.h) ulib_obj := $(patsubst $(src_dir)/%.c,$(obj_dir)/%.o,$(ulib_src)) +lib_feat_no_prefix := $(patsubst axlibc/%,%,$(LIB_FEAT)) + +CFLAGS += $(addprefix -DAX_CONFIG_,$(shell echo $(lib_feat_no_prefix) | tr 'a-z' 'A-Z' | tr '-' '_')) +CFLAGS += -DAX_LOG_$(shell echo $(LOG) | tr 'a-z' 'A-Z') + CFLAGS += -nostdinc -static -no-pie -fno-builtin -ffreestanding -Wall CFLAGS += -I$(CURDIR)/$(inc_dir) LDFLAGS += -nostdlib -static -no-pie --gc-sections -T$(LD_SCRIPT) @@ -23,15 +28,11 @@ ifeq ($(MODE), release) CFLAGS += -O3 endif -ifneq ($(wildcard $(APP)/features.txt),) # check if features.txt contains "fp_simd" - fp_simd := $(shell grep "fp_simd" < $(APP)/features.txt) -endif - ifeq ($(ARCH), riscv64) CFLAGS += -march=rv64gc -mabi=lp64d -mcmodel=medany endif -ifeq ($(fp_simd),) +ifeq ($(call feature_has_fp_simd),) ifeq ($(ARCH), x86_64) CFLAGS += -mno-sse else ifeq ($(ARCH), aarch64) @@ -46,7 +47,8 @@ endif _check_need_rebuild: $(obj_dir) @if [ "$(CFLAGS)" != "`cat $(last_cflags) 2>&1`" ]; then \ - echo $(CFLAGS) > $(last_cflags); \ + echo "CFLAGS changed, rebuild"; \ + echo "$(CFLAGS)" > $(last_cflags); \ fi $(obj_dir): diff --git a/scripts/make/cargo.mk b/scripts/make/cargo.mk index 3edeeff558..566198c555 100644 --- a/scripts/make/cargo.mk +++ b/scripts/make/cargo.mk @@ -8,47 +8,12 @@ else verbose := endif -features-y := - -ifeq ($(shell test $(SMP) -gt 1; echo $$?),0) - features-y += axstd/smp - ifeq ($(APP_TYPE), c) - features-y += axlibc/smp - endif -endif - -ifneq ($(filter $(LOG),off error warn info debug trace),) - features-y += axstd/log-level-$(LOG) -else - $(error "LOG" must be one of "off", "error", "warn", "info", "debug", "trace") -endif - -ifeq ($(BUS),pci) - features-y += axstd/bus-pci -endif - -ifeq ($(APP_TYPE),c) - ifneq ($(wildcard $(APP)/features.txt),) # check features.txt exists - features_c := $(shell cat $(APP)/features.txt) - ifneq ($(strip $(foreach feat,fs net pipe select epoll,$(filter $(feat),$(features_c)))),) - features_c += fd - endif - CFLAGS += $(addprefix -DAX_CONFIG_,$(shell echo $(features_c) | tr 'a-z' 'A-Z' | tr '-' '_')) - endif - CFLAGS += -DAX_LOG_$(shell echo $(LOG) | tr 'a-z' 'A-Z') - features-y += $(addprefix axlibc/,$(features_c)) - features-y += $(APP_FEATURES) -else ifeq ($(APP_TYPE),rust) - features-y += $(APP_FEATURES) -endif - build_args-release := --release build_args := \ --target $(TARGET) \ --target-dir $(CURDIR)/target \ $(build_args-$(MODE)) \ - --features "$(features-y)" \ $(verbose) RUSTFLAGS := -C link-arg=-T$(LD_SCRIPT) -C link-arg=-no-pie @@ -58,8 +23,8 @@ ifeq ($(MAKECMDGOALS), doc_check_missing) RUSTDOCFLAGS += -D missing-docs endif -define cargo_rustc - $(call run_cmd,cargo rustc,$(build_args) $(1)) +define cargo_build + $(call run_cmd,cargo build,$(build_args) $(1) --features "$(strip $(2))") endef define cargo_clippy @@ -70,7 +35,7 @@ endef all_packages := \ $(shell ls $(CURDIR)/crates) \ $(shell ls $(CURDIR)/modules) \ - axstd axlibc + axfeat axstd axlibc define cargo_doc $(call run_cmd,cargo doc,--no-deps --all-features --workspace --exclude "arceos-*" $(verbose)) diff --git a/scripts/make/features.mk b/scripts/make/features.mk new file mode 100644 index 0000000000..a8a8cdc6d2 --- /dev/null +++ b/scripts/make/features.mk @@ -0,0 +1,69 @@ +# Features resolving. +# +# Inputs: +# - `FEATURES`: a list of features to be enabled split by space. Each feature +# should starts with a prefix, which can be one of `ax/`, `lib/` or `app/` +# and be used to set the features of ArceOS modules, the use library, and +# the app itself, respectively. (e.g, `ax/feature1 lib/feature2 app/feature3`). +# +# Outputs: +# - `AX_FEAT`: features to be enabled for ArceOS modules (crate `axfeat`). +# - `LIB_FEAT`: features to be enabled for the user library (crate `axstd`, `axlibc`). +# - `APP_FEAT`: features to be enabled for the app. + +ax_prefix := ax/ +lib_prefix := lib/ +app_prefix := app/ + +ifeq ($(APP_TYPE),c) + ax_prefix_after := axfeat/ + lib_prefix_after := axlibc/ + app_prefix_after := +else + # TODO: it's better to use `axfeat`, but all apps need to have `axfeat` as a dependency + ax_prefix_after := axstd/ + lib_prefix_after := axstd/ + app_prefix_after := +endif + +feature_has_fd = $(strip $(foreach feat,fs net pipe select epoll,$(filter lib/$(feat),$(FEATURES)))) +feature_has_fp_simd = $(findstring fp_simd,$(FEATURES)) + +override FEATURES := $(shell echo $(FEATURES) | tr ',' ' ') + +ifeq ($(APP_TYPE), c) + ifneq ($(wildcard $(APP)/features.txt),) # check features.txt exists + override FEATURES += $(shell cat $(APP)/features.txt) + endif + ifneq ($(call feature_has_fd),) + override FEATURES += lib/fd + endif +endif + +ax_feat := +lib_feat := + +ifneq ($(filter $(LOG),off error warn info debug trace),) + ax_feat += log-level-$(LOG) +else + $(error "LOG" must be one of "off", "error", "warn", "info", "debug", "trace") +endif + +ifeq ($(BUS),pci) + ax_feat += bus-pci +endif + +ifeq ($(shell test $(SMP) -gt 1; echo $$?),0) + lib_feat += smp +endif + +AX_FEAT := $(patsubst $(ax_prefix)%,$(ax_prefix_after)%,$(filter $(ax_prefix)%,$(FEATURES))) +AX_FEAT += $(addprefix $(ax_prefix_after),$(ax_feat)) +AX_FEAT := $(strip $(AX_FEAT)) + +LIB_FEAT := $(patsubst $(lib_prefix)%,$(lib_prefix_after)%,$(filter $(lib_prefix)%,$(FEATURES))) +LIB_FEAT += $(addprefix $(lib_prefix_after),$(lib_feat)) +LIB_FEAT := $(strip $(LIB_FEAT)) + +APP_FEAT := $(patsubst $(app_prefix)%,$(app_prefix_after)%,$(filter $(app_prefix)%,$(FEATURES))) +APP_FEAT := $(strip $(APP_FEAT)) diff --git a/ulib/axstd/Cargo.toml b/ulib/axstd/Cargo.toml index 67efcccb38..12ccab8a1b 100644 --- a/ulib/axstd/Cargo.toml +++ b/ulib/axstd/Cargo.toml @@ -20,61 +20,61 @@ documentation = "https://rcore-os.github.io/arceos/axstd/index.html" default = [] # Multicore -smp = ["axruntime/smp", "spinlock/smp"] +smp = ["axfeat/smp"] # Floating point/SIMD -fp_simd = ["axhal/fp_simd"] - -# Memory -alloc = ["dep:axalloc", "axruntime/alloc", "axio/alloc"] -alloc_tlsf = ["axalloc/tlsf"] -alloc_slab = ["axalloc/slab"] -alloc_buddy = ["axalloc/buddy"] -paging = ["axruntime/paging"] +fp_simd = ["axfeat/fp_simd"] # Interrupts -irq = ["axruntime/irq"] +irq = ["axfeat/irq"] + +# Memory +alloc = ["dep:axalloc", "axfeat/alloc", "axio/alloc"] +alloc-tlsf = ["axfeat/alloc-tlsf"] +alloc-slab = ["axfeat/alloc-slab"] +alloc-buddy = ["axfeat/alloc-buddy"] +paging = ["axfeat/paging"] -# Multi-task -multitask = ["alloc", "axtask", "axruntime/multitask", "axsync/multitask"] -sched_fifo = ["axtask/sched_fifo"] -sched_rr = ["axtask/sched_rr", "irq"] -sched_cfs = ["axtask/sched_cfs", "irq"] +# Multi-threading and scheduler +multitask = ["axtask/multitask", "axsync/multitask", "axfeat/multitask"] +sched_fifo = ["axfeat/sched_fifo"] +sched_rr = ["axfeat/sched_rr"] +sched_cfs = ["axfeat/sched_cfs"] # File system -fs = ["alloc", "paging", "axruntime/fs", "axdriver/virtio-blk", "dep:axfs"] # TODO: remove "paging" -myfs = ["axfs?/myfs"] +fs = ["dep:axfs", "axfeat/fs"] +myfs = ["axfeat/myfs"] # Networking -net = ["alloc", "paging", "axruntime/net", "axdriver/virtio-net", "dep:axnet"] +net = ["dep:axnet", "axfeat/net"] dns = [] # Display -display = ["paging", "axruntime/display", "axdriver/virtio-gpu", "dep:axdisplay"] +display = ["dep:axdisplay", "axfeat/display"] # Device drivers -bus-mmio = ["axdriver?/bus-mmio"] -bus-pci = ["axdriver?/bus-pci"] -driver-ramdisk = ["axdriver?/ramdisk", "axfs?/use-ramdisk"] -driver-ixgbe = ["axdriver?/ixgbe"] -driver-bcm2835-sdhci = ["axdriver?/bcm2835-sdhci"] +bus-mmio = ["axfeat/bus-mmio"] +bus-pci = ["axfeat/bus-pci"] +driver-ramdisk = ["axfeat/driver-ramdisk"] +driver-ixgbe = ["axfeat/driver-ixgbe"] +driver-bcm2835-sdhci = ["axfeat/driver-bcm2835-sdhci"] # Logging -log-level-off = ["axlog/log-level-off"] -log-level-error = ["axlog/log-level-error"] -log-level-warn = ["axlog/log-level-warn"] -log-level-info = ["axlog/log-level-info"] -log-level-debug = ["axlog/log-level-debug"] -log-level-trace = ["axlog/log-level-trace"] +log-level-off = ["axfeat/log-level-off"] +log-level-error = ["axfeat/log-level-error"] +log-level-warn = ["axfeat/log-level-warn"] +log-level-info = ["axfeat/log-level-info"] +log-level-debug = ["axfeat/log-level-debug"] +log-level-trace = ["axfeat/log-level-trace"] [dependencies] # ArceOS modules +axfeat = { path = "../../api/axfeat" } axruntime = { path = "../../modules/axruntime" } axhal = { path = "../../modules/axhal" } axlog = { path = "../../modules/axlog" } axconfig = { path = "../../modules/axconfig" } axalloc = { path = "../../modules/axalloc", optional = true } -axdriver = { path = "../../modules/axdriver", optional = true } axfs = { path = "../../modules/axfs", optional = true } axnet = { path = "../../modules/axnet", optional = true } axdisplay = { path = "../../modules/axdisplay", optional = true } diff --git a/ulib/axstd/src/lib.rs b/ulib/axstd/src/lib.rs index a65c423dcd..eed2cd72b8 100644 --- a/ulib/axstd/src/lib.rs +++ b/ulib/axstd/src/lib.rs @@ -13,6 +13,9 @@ //! - `irq`: Enable interrupt handling support. //! - Memory //! - `alloc`: Enable dynamic memory allocation. +//! - `alloc-tlsf`: Use the TLSF allocator. +//! - `alloc-slab`: Use the slab allocator. +//! - `alloc-buddy`: Use the buddy system allocator. //! - `paging`: Enable page table manipulation. //! - Task management //! - `multitask`: Enable multi-threading support.