Skip to content

Commit 8a3c67e

Browse files
feat(awkernel_userland): userland is both library and binary, so users can extend base userland (#767)
1 parent c19c1ba commit 8a3c67e

6 files changed

Lines changed: 100 additions & 81 deletions

File tree

‎.cargo/config.toml‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
[alias]
2-
x86 = "build --package userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
3-
aarch64 = "build --package userland --no-default-features --features aarch64 --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
4-
rv32 = "build --package userland --no-default-features --features rv32 --target riscv32imac-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
5-
rv64 = "build --package userland --no-default-features --features rv64 --target riscv64gc-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
6-
std = "build --package userland --no-default-features --features std"
2+
x86 = "build --package awkernel_userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
3+
aarch64 = "build --package awkernel_userland --no-default-features --features aarch64 --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
4+
rv32 = "build --package awkernel_userland --no-default-features --features rv32 --target riscv32imac-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
5+
rv64 = "build --package awkernel_userland --no-default-features --features rv64 --target riscv64gc-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
6+
std = "build --package awkernel_userland --no-default-features --features std"
77

88
test_awkernel_lib = "test --package awkernel_lib --no-default-features --features std"
99
test_awkernel_async_lib = "test --package awkernel_async_lib --no-default-features --features std"
1010
test_awkernel_drivers = "test --package awkernel_drivers --no-default-features --features std"
1111
test_smoltcp = "test --package smoltcp --no-default-features --features std --features awkernel"
1212
test_rd_gen_to_dags = "test --package rd_gen_to_dags --no-default-features --features std --features milliseconds"
1313

14-
clippy_x86 = "clippy --package userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
15-
clippy_raspi = "clippy --package userland --no-default-features --features raspi --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
16-
clippy_raspi5 = "clippy --package userland --no-default-features --features raspi5 --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
17-
clippy_aarch64_virt = "clippy --package userland --no-default-features --features aarch64_virt --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
18-
clippy_std = "clippy --package userland --no-default-features --features std"
19-
clippy_rv32 = "clippy --package userland --no-default-features --features rv32 --target riscv32imac-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
20-
clippy_rv64 = "clippy --package userland --no-default-features --features rv64 --target riscv64gc-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
14+
clippy_x86 = "clippy --package awkernel_userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
15+
clippy_raspi = "clippy --package awkernel_userland --no-default-features --features raspi --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
16+
clippy_raspi5 = "clippy --package awkernel_userland --no-default-features --features raspi5 --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
17+
clippy_aarch64_virt = "clippy --package awkernel_userland --no-default-features --features aarch64_virt --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
18+
clippy_std = "clippy --package awkernel_userland --no-default-features --features std"
19+
clippy_rv32 = "clippy --package awkernel_userland --no-default-features --features rv32 --target riscv32imac-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
20+
clippy_rv64 = "clippy --package awkernel_userland --no-default-features --features rv64 --target riscv64gc-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
2121
clippy_rd_gen_to_dags = "clippy --package rd_gen_to_dags --no-default-features --features std --features milliseconds"
2222

23-
check_aarch64 = "check --package userland --no-default-features --features aarch64 --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
24-
check_x86 = "check --package userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
25-
check_rv32 = "check --package userland --no-default-features --features rv32 --target riscv32imac-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
26-
check_rv64 = "check --package userland --no-default-features --features rv64 --target riscv64gc-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
27-
check_no_std = "check --package userland -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem --quiet --message-format=json -Zjson-target-spec"
28-
check_std = "check --package userland --no-default-features --features std"
23+
check_aarch64 = "check --package awkernel_userland --no-default-features --features aarch64 --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
24+
check_x86 = "check --package awkernel_userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
25+
check_rv32 = "check --package awkernel_userland --no-default-features --features rv32 --target riscv32imac-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
26+
check_rv64 = "check --package awkernel_userland --no-default-features --features rv64 --target riscv64gc-unknown-none-elf -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
27+
check_no_std = "check --package awkernel_userland -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem --quiet --message-format=json -Zjson-target-spec"
28+
check_std = "check --package awkernel_userland --no-default-features --features std"
2929

30-
doc_raspi = "doc --package userland --no-default-features --features raspi --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
31-
doc_aarch64_virt = "doc --package userland --no-default-features --features aarch64_virt --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
32-
doc_x86 = "doc --package userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
30+
doc_raspi = "doc --package awkernel_userland --no-default-features --features raspi --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
31+
doc_aarch64_virt = "doc --package awkernel_userland --no-default-features --features aarch64_virt --target targets/aarch64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
32+
doc_x86 = "doc --package awkernel_userland --no-default-features --features x86 --target targets/x86_64-kernel.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -Zjson-target-spec"
3333

3434
udeps_x86 = "udeps --package awkernel --no-default-features --features x86 --target x86_64-unknown-linux-gnu"
3535
udeps_raspi = "udeps --package awkernel --no-default-features --features x86 --target x86_64-unknown-linux-gnu"

‎userland/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "userland"
2+
name = "awkernel_userland"
33
version = "0.1.0"
44
edition = "2021"
55

‎userland/src/lib.rs‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
2+
3+
extern crate alloc;
4+
extern crate awkernel;
5+
6+
use alloc::borrow::Cow;
7+
8+
pub async fn run() -> Result<(), Cow<'static, str>> {
9+
awkernel_services::run().await;
10+
11+
#[cfg(feature = "autoware")]
12+
autoware::run().await; // run the autoware application
13+
14+
#[cfg(feature = "rd_gen_to_dags")]
15+
rd_gen_to_dags::run().await; // run the rd_gen_to_dags application
16+
17+
#[cfg(feature = "test_network")]
18+
test_network::run().await; // test for network
19+
20+
#[cfg(feature = "test_pubsub")]
21+
test_pubsub::run().await; // test for pubsub
22+
23+
#[cfg(feature = "test_rpi_hal")]
24+
test_rpi_hal::run().await; // test for RPi HAL
25+
26+
#[cfg(feature = "test_graphics")]
27+
test_graphics::run().await; // test for graphics
28+
29+
#[cfg(feature = "test_prioritized_fifo")]
30+
test_prioritized_fifo::run().await; // test for prioritized_fifo
31+
32+
#[cfg(feature = "test_multi_prioritized_scheduler")]
33+
test_multi_prioritized_scheduler::run().await; // test for multi prioritized scheduler
34+
35+
#[cfg(feature = "test_prioritized_rr")]
36+
test_prioritized_rr::run().await; // test for prioritized_rr
37+
38+
#[cfg(feature = "test_async_mutex")]
39+
test_async_mutex::run().await; // test for async_mutex
40+
41+
#[cfg(feature = "test_gedf")]
42+
test_gedf::run().await; // test for Global Earliest Deadline First scheduler
43+
44+
#[cfg(feature = "test_measure_channel")]
45+
test_measure_channel::run().await; // measure channel
46+
47+
#[cfg(feature = "test_measure_channel_heavy")]
48+
test_measure_channel_heavy::run().await; // measure channel heavy
49+
50+
#[cfg(feature = "test_dag")]
51+
test_dag::run().await; // test for DAG
52+
53+
#[cfg(feature = "test_dvfs")]
54+
test_dvfs::run().await; // test for DVFS
55+
56+
#[cfg(feature = "test_raspi_dvfs")]
57+
test_raspi_dvfs::run().await; // test for Raspberry Pi firmware mailbox DVFS
58+
59+
#[cfg(feature = "test_voluntary_preemption")]
60+
test_voluntary_preemption::run().await; // test for voluntary preemption
61+
62+
#[cfg(feature = "test_clustered_edf")]
63+
test_clustered_edf::run().await; // test for Clustered EDF scheduler
64+
65+
Ok(())
66+
}

‎userland/src/main.rs‎

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,10 @@
22
#![no_main]
33

44
extern crate alloc;
5-
// Links the kernel's entry points and panic handler.
6-
extern crate awkernel;
75

86
use alloc::borrow::Cow;
97

108
#[awkernel::main]
119
async fn main() -> Result<(), Cow<'static, str>> {
12-
awkernel_services::run().await;
13-
14-
#[cfg(feature = "autoware")]
15-
autoware::run().await; // run the autoware application
16-
17-
#[cfg(feature = "rd_gen_to_dags")]
18-
rd_gen_to_dags::run().await; // run the rd_gen_to_dags application
19-
20-
#[cfg(feature = "test_network")]
21-
test_network::run().await; // test for network
22-
23-
#[cfg(feature = "test_pubsub")]
24-
test_pubsub::run().await; // test for pubsub
25-
26-
#[cfg(feature = "test_rpi_hal")]
27-
test_rpi_hal::run().await; // test for RPi HAL
28-
29-
#[cfg(feature = "test_graphics")]
30-
test_graphics::run().await; // test for graphics
31-
32-
#[cfg(feature = "test_prioritized_fifo")]
33-
test_prioritized_fifo::run().await; // test for prioritized_fifo
34-
35-
#[cfg(feature = "test_multi_prioritized_scheduler")]
36-
test_multi_prioritized_scheduler::run().await; // test for multi prioritized scheduler
37-
38-
#[cfg(feature = "test_prioritized_rr")]
39-
test_prioritized_rr::run().await; // test for prioritized_rr
40-
41-
#[cfg(feature = "test_async_mutex")]
42-
test_async_mutex::run().await; // test for async_mutex
43-
44-
#[cfg(feature = "test_gedf")]
45-
test_gedf::run().await; // test for Global Earliest Deadline First scheduler
46-
47-
#[cfg(feature = "test_measure_channel")]
48-
test_measure_channel::run().await; // measure channel
49-
50-
#[cfg(feature = "test_measure_channel_heavy")]
51-
test_measure_channel_heavy::run().await; // measure channel heavy
52-
53-
#[cfg(feature = "test_dag")]
54-
test_dag::run().await; // test for DAG
55-
56-
#[cfg(feature = "test_dvfs")]
57-
test_dvfs::run().await; // test for DVFS
58-
59-
#[cfg(feature = "test_raspi_dvfs")]
60-
test_raspi_dvfs::run().await; // test for Raspberry Pi firmware mailbox DVFS
61-
62-
#[cfg(feature = "test_voluntary_preemption")]
63-
test_voluntary_preemption::run().await; // test for voluntary preemption
64-
65-
#[cfg(feature = "test_clustered_edf")]
66-
test_clustered_edf::run().await; // test for Clustered EDF scheduler
67-
68-
Ok(())
10+
awkernel_userland::run().await
6911
}

‎userland_extern_template/Cargo.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ edition = "2021"
77
[workspace]
88

99
[[bin]]
10+
# To make sure the binary's name is always awkernel
1011
name = "awkernel"
1112
path = "src/main.rs"
1213

1314
[features]
15+
perf = ["awkernel/perf"]
1416
debug = ["awkernel/debug"]
1517
# Select exactly one architecture (the Makefile does it).
1618
x86 = ["awkernel/x86"]
@@ -19,6 +21,7 @@ raspi = ["awkernel/raspi"]
1921
raspi5 = ["awkernel/raspi5"]
2022
rv32 = ["awkernel/rv32"]
2123
rv64 = ["awkernel/rv64"]
24+
std = ["awkernel/std"]
2225

2326
[dependencies]
2427
log = "0.4"
@@ -27,6 +30,13 @@ log = "0.4"
2730
path = "../kernel"
2831
default-features = false
2932

33+
[dependencies.awkernel_userland]
34+
# As an example, you can extend the base userland crate with your own code in this crate!
35+
# Here, I will only use the basic awkernel services and the test_dvfs application
36+
path = "../userland"
37+
default-features = false
38+
features = ["test_dvfs"]
39+
3040
[dependencies.awkernel_async_lib]
3141
path = "../awkernel_async_lib"
3242
default-features = false

‎userland_extern_template/src/main.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use core::time::Duration;
1111

1212
#[awkernel::main]
1313
async fn main() -> Result<(), Cow<'static, str>> {
14+
awkernel_userland::run().await?;
1415
loop {
1516
log::info!("Hello from an out-of-tree userland!");
1617
sleep(Duration::from_secs(1)).await;

0 commit comments

Comments
 (0)