Skip to content

Commit

Permalink
Add features for device driver selection
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Aug 2, 2023
1 parent e9517d4 commit b9f2f64
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 68 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ jobs:
- name: Build c/redis
run: make ARCH=${{ matrix.arch }} A=apps/c/redis SMP=4

build-apps-for-other-platforms:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.rust-toolchain }}
components: rust-src
- uses: actions-rs/[email protected]
with:
crate: cargo-binutils
version: latest
use-tool-cache: true
- uses: ./.github/workflows/actions/setup-musl
with:
arch: x86_64

- 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
- 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
- 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

- 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

build-apps-for-std:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

48 changes: 30 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

# General options
ARCH ?= x86_64
PLATFORM ?=
SMP ?= 1
MODE ?= release
LOG ?= warn
Expand Down Expand Up @@ -63,40 +64,51 @@ else
APP_TYPE := c
endif

# Platform and target
# Architecture, platform and target
ifneq ($(filter $(MAKECMDGOALS),unittest unittest_no_fail_fast),)
PLATFORM_NAME :=
else ifneq ($(PLATFORM),)
# `PLATFORM` is specified, override the `ARCH` variables
builtin_platforms := $(patsubst platforms/%.toml,%,$(wildcard platforms/*))
ifneq ($(filter $(PLATFORM),$(builtin_platforms)),)
# builtin platform
PLATFORM_NAME := $(PLATFORM)
_arch := $(word 1,$(subst -, ,$(PLATFORM)))
else ifneq ($(wildcard $(PLATFORM)),)
# custom platform, read the "platform" field from the toml file
PLATFORM_NAME := $(shell cat $(PLATFORM) | sed -n 's/^platform = "\([a-z0-9A-Z_\-]*\)"/\1/p')
_arch := $(shell cat $(PLATFORM) | sed -n 's/^arch = "\([a-z0-9A-Z_\-]*\)"/\1/p')
else
$(error "PLATFORM" must be one of "$(builtin_platforms)" or a valid path to a toml file)
endif
ifeq ($(origin ARCH),command line)
ifneq ($(ARCH),$(_arch))
$(error "ARCH=$(ARCH)" is not compatible with "PLATFORM=$(PLATFORM)")
endif
endif
ARCH := $(_arch)
endif

ifeq ($(ARCH), x86_64)
# Don't enable kvm for WSL/WSL2.
ACCEL ?= $(if $(findstring -microsoft, $(shell uname -r | tr '[:upper:]' '[:lower:]')),n,y)
PLATFORM ?= x86_64-qemu-q35
PLATFORM_NAME ?= x86_64-qemu-q35
TARGET := x86_64-unknown-none
BUS := pci
else ifeq ($(ARCH), riscv64)
ACCEL ?= n
PLATFORM ?= riscv64-qemu-virt
PLATFORM_NAME ?= riscv64-qemu-virt
TARGET := riscv64gc-unknown-none-elf
else ifeq ($(ARCH), aarch64)
ACCEL ?= n
PLATFORM ?= aarch64-qemu-virt
PLATFORM_NAME ?= aarch64-qemu-virt
TARGET := aarch64-unknown-none-softfloat
else
$(error "ARCH" must be one of "x86_64", "riscv64", or "aarch64")
endif

ifneq ($(filter $(MAKECMDGOALS),unittest unittest_no_fail_fast),)
PLATFORM :=
endif

builtin_platforms := $(patsubst platforms/%.toml,%,$(wildcard platforms/*))
ifneq ($(filter $(PLATFORM),$(builtin_platforms)),)
# builtin platform
PLATFORM_NAME := $(PLATFORM)
else ifneq ($(wildcard $(PLATFORM)),)
# custom platform, read the "platform" field from the toml file
PLATFORM_NAME := $(shell cat $(PLATFORM) | sed -n 's/^platform = "\([a-z0-9A-Z_\-]*\)"/\1/p')
endif

export AX_ARCH=$(ARCH)
export AX_PLATFORM=$(PLATFORM)
export AX_PLATFORM=$(PLATFORM_NAME)
export AX_SMP=$(SMP)
export AX_MODE=$(MODE)
export AX_LOG=$(LOG)
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ ArceOS was inspired a lot by [Unikraft](https://github.com/unikraft/unikraft).

🚧 Working In Progress.

## Contributing to arceos
1. fork this repo's branch `dev` to your own repo
2. add&update codes in your own repo's `dev` branch, pass CI test
3. create PR to this repo's branch `dev`
4. discuss with other contributors, merge PR to this repo's branch `dev`
5. owners merge this repo's branch `dev` to `main`

## Features & TODOs

* [x] Architecture: x86_64, riscv64, aarch64
Expand Down Expand Up @@ -168,6 +161,24 @@ Note that the `NET=y` argument is required to enable the network device in QEMU.
# more args: LOG=<log> SMP=<smp> NET=[y|n] ...
```

### How to build ArceOS for specified platforms and devices

Set the `PLATFORM` variable when run `make`:

```bash
# Build helloworld for raspi4
make PLATFORM=aarch64-raspi4 A=apps/helloworld
```

You may also need to select the corrsponding device drivers by setting the `APP_FEATURES` variable:

```bash
# Build the shell app for raspi4, and use the SD card driver
make PLATFORM=aarch64-raspi4 A=apps/fs/shell APP_FEATURES=axstd/driver-bcm2835-sdhci
# Build Redis for the bare-metal x86_64 platform, and use the ixgbe and ramdisk driver
make PLATFORM=x86_64-pc-oslab A=apps/c/redis APP_FEATURES=axstd/driver-ixgbe,axstd/driver-ramdisk SMP=4
```

## Design

![](doc/figures/ArceOS.svg)
2 changes: 1 addition & 1 deletion apps/c/pthread/parallel/test_cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
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 APP_FEATURES=axstd/sched_rr" "expect_info_smp4_rr.out"
rm -f $APP/*.o
3 changes: 1 addition & 2 deletions apps/c/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@ MSET (10 keys): 183150.19 requests per second

- Comment out `spt_init()`(Already patched).
- It will be nicer to comment out `pthread_cond_wait` as well.
- change `axruntime/Cargo.toml`, use `net = ["alloc", "paging", "axdriver/ixgbe", "dep:axnet"]`

## Compile and Run

- `make A=apps/c/redis LOG=error PLATFORM=x86_64-pc-oslab IP=10.2.2.2 GW=10.2.2.1 SMP=4 ARCH=x86_64`
- `make A=apps/c/redis LOG=error PLATFORM=x86_64-pc-oslab SMP=4 APP_FEATURES=axstd/driver-ixgbe,axstd/driver-ramdisk IP=10.2.2.2 GW=10.2.2.1`
- Copy `redis_x86_64-pc-oslab.elf` to `/boot`, then reboot.
- Enter `grub` then boot the PC by ArceOS Redis.
- Connect to ArceOS-Redis server by:
Expand Down
1 change: 0 additions & 1 deletion apps/c/redis/features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ irq
multitask
fs
net
use-ramdisk
pipe
epoll
2 changes: 1 addition & 1 deletion apps/c/sqlite3/test_cmd
Original file line number Diff line number Diff line change
@@ -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=use-ramdisk" "expect_info_ramdisk.out"
test_one "LOG=info BLK=y APP_FEATURES=axstd/driver-ramdisk" "expect_info_ramdisk.out"
rm -f $APP/*.o
2 changes: 2 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
| [helloworld](../apps/c/helloworld/) | | | A minimal C app that just prints a string |
| [memtest](../apps/c/memtest/) | axalloc | alloc, paging | Dynamic memory allocation test in C |
| [sqlite3](../apps/c/sqlite3/) | axalloc, axdriver, axfs | alloc, paging, fp_simd, fs | Porting of [SQLite3](https://sqlite.org/index.html) |
| [iperf](../apps/c/iperf/) | axalloc, axdriver, axfs, axnet | alloc, paging, fp_simd, fs, net, select | Porting of [iPerf3](https://iperf.fr/) |
| [redis](../apps/c/redis/) | axalloc, axdriver, axtask, axfs, axnet | alloc, paging, fp_simd, irq, multitask, fs, net, pipe, epoll | Porting of [Redis](https://redis.io/) |

## Dependencies

Expand Down
15 changes: 4 additions & 11 deletions doc/ixgbe.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# How to run arceos with ixgbe NIC?

First, you need to enable a new network feature and comment out the existing feature in `modules/axruntime/Cargo.toml`:

```toml
# net = ["alloc", "paging", "axdriver/virtio-net", "dep:axnet"]
net = ["alloc", "paging", "axdriver/ixgbe", "dep:axnet"] # Ixgbe
```

Additionally, you also need to specify the platform that owns this network card. For example, we defined a toml file named x86_64-pc-oslab under the platforms directory to describe the platform characteristics.
You need to specify the platform that owns this network card. For example, we defined a toml file named `x86_64-pc-oslab`` under the platforms directory to describe the platform characteristics.

You can use the following command to compile an 'httpserver' app application:

```shell
make A=apps/net/httpserver ARCH=x86_64 PLATFORM=x86_64-pc-oslab NET=y
make A=apps/net/httpserver PLATFORM=x86_64-pc-oslab APP_FEATURES=axstd/driver-ixgbe
```

You can also use the following command to start the iperf application:

```shell
make A=apps/c/iperf ARCH=x86_64 PLATFORM=x86_64-pc-oslab NET=y BLK=y
```
make A=apps/c/iperf PLATFORM=x86_64-pc-oslab APP_FEATURES=axstd/driver-ixgbe,axstd/driver-ramdisk
```
13 changes: 6 additions & 7 deletions modules/axruntime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ documentation = "https://rcore-os.github.io/arceos/axruntime/index.html"
[features]
default = []

smp = ["axhal/smp", "spinlock/smp"]
smp = ["axhal/smp"]
irq = ["axhal/irq", "axtask?/irq", "percpu", "kernel_guard"]
alloc = ["axalloc"]
paging = ["alloc", "axhal/paging", "lazy_init"]
paging = ["axhal/paging", "lazy_init"]

multitask = ["alloc", "axtask/multitask"]
fs = ["alloc", "paging", "axdriver/virtio-blk", "dep:axfs"] # TODO: remove "paging"
net = ["alloc", "paging", "axdriver/virtio-net", "dep:axnet"]
display = ["alloc", "paging", "axdriver/virtio-gpu", "dep:axdisplay"]
multitask = ["axtask/multitask"]
fs = ["axdriver", "axfs"]
net = ["axdriver", "axnet"]
display = ["axdriver", "axdisplay"]

[dependencies]
axhal = { path = "../axhal" }
Expand All @@ -37,4 +37,3 @@ crate_interface = { path = "../../crates/crate_interface" }
percpu = { path = "../../crates/percpu", optional = true }
kernel_guard = { path = "../../crates/kernel_guard", optional = true }
lazy_init = { path = "../../crates/lazy_init", optional = true }
spinlock = { path = "../../crates/spinlock", optional = true }
2 changes: 1 addition & 1 deletion platforms/x86_64-pc-oslab.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ family = "x86-pc"
# Base address of the whole physical memory.
phys-memory-base = "0"
# Size of the whole physical memory.
phys-memory-size = "0x800_0000" # 128M
phys-memory-size = "0x8000_0000" # 2G
# Base physical address of the kernel image.
kernel-base-paddr = "0x20_0000"
# Base virtual address of the kernel image.
Expand Down
10 changes: 5 additions & 5 deletions scripts/make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ else
rust_elf := $(rust_target_dir)/$(rust_package)
endif

ifeq ($(filter $(MAKECMDGOALS),build run debug chainboot),$(MAKECMDGOALS))
ifneq ($(filter $(MAKECMDGOALS),doc doc_check_missing),) # run `cargo doc`
$(if $(V), $(info RUSTDOCFLAGS: "$(RUSTDOCFLAGS)"))
export RUSTDOCFLAGS
else ifeq ($(filter $(MAKECMDGOALS),clippy unittest unittest_no_fail_fast),) # not run `cargo test` or `cargo clippy`
ifneq ($(V),)
$(info APP: "$(APP)")
$(info APP_TYPE: "$(APP_TYPE)")
Expand All @@ -21,9 +24,6 @@ ifeq ($(filter $(MAKECMDGOALS),build run debug chainboot),$(MAKECMDGOALS))
$(if $(V), $(info RUSTFLAGS: "$(RUSTFLAGS)"))
export RUSTFLAGS
endif
else ifneq ($(filter $(MAKECMDGOALS),doc doc_check_missing),)
$(if $(V), $(info RUSTDOCFLAGS: "$(RUSTDOCFLAGS)"))
export RUSTDOCFLAGS
endif

_cargo_build:
Expand All @@ -32,7 +32,7 @@ ifeq ($(APP_TYPE), rust)
$(call cargo_rustc,--manifest-path $(APP)/Cargo.toml)
@cp $(rust_elf) $(OUT_ELF)
else ifeq ($(APP_TYPE), c)
$(call cargo_rustc,-p axlibc --crate-type staticlib)
$(call cargo_rustc,-p axlibc)
endif

$(OUT_DIR):
Expand Down
10 changes: 3 additions & 7 deletions ulib/axlibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ homepage = "https://github.com/rcore-os/arceos"
repository = "https://github.com/rcore-os/arceos/tree/main/ulib/axlibc"
documentation = "https://rcore-os.github.io/arceos/axlibc/index.html"

[lib]
crate-type = ["staticlib"]

[features]
default = []

Expand All @@ -27,23 +30,16 @@ fp_simd = ["axstd/fp_simd"]

# Memory
alloc = ["axstd/alloc", "dep:axalloc"]
alloc_tlsf = ["axalloc/tlsf"]
alloc_slab = ["axalloc/slab"]
alloc_buddy = ["axalloc/buddy"]
paging = ["axstd/paging"]

# Interrupts
irq = ["axstd/irq"]

# Multi-task
multitask = ["axstd/multitask", "axtask/multitask"]
sched_fifo = ["axstd/sched_fifo"]
sched_rr = ["axstd/sched_rr"]
sched_cfs = ["axstd/sched_cfs"]

# File system
fs = ["axstd/fs", "fd"]
use-ramdisk = ["axstd/use-ramdisk"]

# Networking
net = ["axstd/net", "dep:axnet", "fd"]
Expand Down
10 changes: 6 additions & 4 deletions ulib/axstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ sched_rr = ["axtask/sched_rr", "irq"]
sched_cfs = ["axtask/sched_cfs", "irq"]

# File system
fs = ["alloc", "axruntime/fs", "dep:axdriver", "dep:axfs"]
fs = ["alloc", "paging", "axruntime/fs", "axdriver/virtio-blk", "dep:axfs"] # TODO: remove "paging"
myfs = ["axfs?/myfs"]
use-ramdisk = ["axdriver?/ramdisk", "axfs?/use-ramdisk"]

# Networking
net = ["alloc", "axruntime/net", "dep:axdriver", "dep:axnet"]
net = ["alloc", "paging", "axruntime/net", "axdriver/virtio-net", "dep:axnet"]
dns = []

# Display
display = ["axruntime/display", "dep:axdriver", "dep:axdisplay"]
display = ["paging", "axruntime/display", "axdriver/virtio-gpu", "dep:axdisplay"]

# 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"]
Expand Down
7 changes: 5 additions & 2 deletions ulib/axstd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
//! - `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.
//! - Device and upperlayer stack
//! - Upperlayer stacks
//! - `fs`: Enable file system support.
//! - `myfs`: Allow users to define their custom filesystems to override the default.
//! - `use-ramdisk`: Use the RAM disk to emulate the block device.
//! - `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`,
Expand Down

0 comments on commit b9f2f64

Please sign in to comment.