Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ members = [
"components/scope-local",
"components/sdhci-cv1800",
"components/sdio-host",
"components/sdio-host2",
"components/someboot",
"components/somehal-macros",
"components/starry-process",
Expand Down Expand Up @@ -242,6 +243,7 @@ rdrive-macros = { version = "0.4.2", path = "drivers/rdrive-macros" }
rsext4 = { version = "0.7.2", path = "components/rsext4" }
scope-local = { version = "0.4.0", path = "components/scope-local" }
sdio-host = { version = "0.1.0", package = "sdio-host-cv1800", path = "components/sdio-host" }
sdio-host2 = { version = "0.1.0", path = "components/sdio-host2" }
sdhci-cv1800 = { version = "0.1.1", path = "components/sdhci-cv1800" }
aic8800 = { version = "0.2.0", path = "components/aic8800" }
crab-usb = { version = "0.9.8", path = "drivers/usb/usb-host" }
Expand Down
11 changes: 11 additions & 0 deletions apps/starry/block-rw-bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# block-rw-bench

Starry board file-I/O benchmark for SD/MMC RDIF validation.

Build and install the helper into the board rootfs as `/usr/bin/block-rw-bench`
before running `cargo xtask starry app board -t block-rw-bench -b <board>`.
The board app `init.sh` executes that helper directly.

The helper writes files under `/root/block-rw-bench/`, calls `sync_all`, reads
the data back, verifies a deterministic pattern, and prints one result line for
each block size plus a final success line.
1 change: 1 addition & 0 deletions apps/starry/block-rw-bench/block-rw-bench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions apps/starry/block-rw-bench/block-rw-bench/Cargo.lock

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

9 changes: 9 additions & 0 deletions apps/starry/block-rw-bench/block-rw-bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "block-rw-bench"
version = "0.1.0"
edition = "2024"
license = "Apache-2.0"

[dependencies]

[workspace]
136 changes: 136 additions & 0 deletions apps/starry/block-rw-bench/block-rw-bench/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
use std::{
env,
fs::{self, File, OpenOptions},
io::{self, BufReader, Read, Write},
path::{Path, PathBuf},
time::{Duration, Instant},
};

const BENCH_DIR: &str = "/root/block-rw-bench";
const TOTAL_BYTES: usize = 64 * 1024 * 1024;
const BLOCK_SIZES: [usize; 3] = [4 * 1024, 64 * 1024, 1024 * 1024];
const DROP_CACHES_ENV: &str = "BLOCK_RW_BENCH_DROP_CACHES";

fn main() {
if let Err(err) = run() {
eprintln!("block-rw-bench: error: {err}");
std::process::exit(1);
}
}

fn run() -> io::Result<()> {
let dir = Path::new(BENCH_DIR);
fs::create_dir_all(dir)?;

for &block_size in &BLOCK_SIZES {
run_case(dir, block_size, TOTAL_BYTES)?;
}

println!(
"block-rw-bench: done cases={} status=ok",
BLOCK_SIZES.len()
);
Ok(())
}

fn run_case(dir: &Path, block_size: usize, bytes: usize) -> io::Result<()> {
maybe_drop_caches()?;

let path = case_path(dir, block_size);
let mut pattern = vec![0; block_size];
let write_start = Instant::now();
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&path)?;

let mut offset = 0usize;
while offset < bytes {
let chunk_len = (bytes - offset).min(block_size);
fill_pattern(&mut pattern[..chunk_len], block_size, offset);
file.write_all(&pattern[..chunk_len])?;
offset += chunk_len;
}
let write_elapsed = write_start.elapsed();

let fsync_start = Instant::now();
file.sync_all()?;
let fsync_elapsed = fsync_start.elapsed();
drop(file);

maybe_drop_caches()?;

let read_start = Instant::now();
verify_file(&path, block_size, bytes)?;
let read_elapsed = read_start.elapsed();

println!(
"block-rw-bench: case block_size={} bytes={} write_mib_s={:.2} read_mib_s={:.2} fsync_ms={} verify=ok",
block_size,
bytes,
throughput_mib_s(bytes, write_elapsed),
throughput_mib_s(bytes, read_elapsed),
duration_ms(fsync_elapsed)
);

fs::remove_file(path)?;
Ok(())
}

fn verify_file(path: &Path, block_size: usize, bytes: usize) -> io::Result<()> {
let mut reader = BufReader::new(File::open(path)?);
let mut actual = vec![0; block_size];
let mut expected = vec![0; block_size];
let mut offset = 0usize;

while offset < bytes {
let chunk_len = (bytes - offset).min(block_size);
reader.read_exact(&mut actual[..chunk_len])?;
fill_pattern(&mut expected[..chunk_len], block_size, offset);
if actual[..chunk_len] != expected[..chunk_len] {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
format!(
"verify mismatch block_size={} offset={} expected={:02x} actual={:02x}",
block_size, offset, expected[0], actual[0]
),
));
}
offset += chunk_len;
}

Ok(())
}

fn fill_pattern(buf: &mut [u8], block_size: usize, base_offset: usize) {
let seed = block_size as u64 ^ 0x5d51_d1f5_a5a5_1234;
for (index, byte) in buf.iter_mut().enumerate() {
let pos = (base_offset + index) as u64;
*byte = pos
.wrapping_mul(1103515245)
.wrapping_add(seed)
.rotate_left((pos & 7) as u32) as u8;
}
}

fn throughput_mib_s(bytes: usize, elapsed: Duration) -> f64 {
let seconds = elapsed.as_secs_f64().max(0.000_001);
bytes as f64 / (1024.0 * 1024.0) / seconds
}

fn duration_ms(elapsed: Duration) -> u128 {
elapsed.as_millis()
}

fn case_path(dir: &Path, block_size: usize) -> PathBuf {
dir.join(format!("case-{}.bin", block_size))
}

fn maybe_drop_caches() -> io::Result<()> {
if env::var_os(DROP_CACHES_ENV).is_none() {
return Ok(());
}

fs::write("/proc/sys/vm/drop_caches", b"3\n")
}
13 changes: 13 additions & 0 deletions apps/starry/block-rw-bench/board-orangepi-5-plus.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
board_type = "OrangePi-5-Plus"
shell_prefix = "root@starry:/root #"
success_regex = [
'(?m)^block-rw-bench: done cases=3 status=ok$',
]
fail_regex = [
'(?i)\bpanic(?:ked)?\b',
'(?m)^block-rw-bench: error: .*$',
'(?m)^block-rw-bench: .*verify=(?:fail|mismatch).*$',
'(?i)(block-rw-bench|sh): .*not found',
'(?i)\bI/O error\b',
]
timeout = 600
13 changes: 13 additions & 0 deletions apps/starry/block-rw-bench/board-phytiumpi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
board_type = "PhytiumPi"
shell_prefix = "root@starry:/root #"
success_regex = [
'(?m)^block-rw-bench: done cases=3 status=ok$',
]
fail_regex = [
'(?i)\bpanic(?:ked)?\b',
'(?m)^block-rw-bench: error: .*$',
'(?m)^block-rw-bench: .*verify=(?:fail|mismatch).*$',
'(?i)(block-rw-bench|sh): .*not found',
'(?i)\bI/O error\b',
]
timeout = 600
13 changes: 13 additions & 0 deletions apps/starry/block-rw-bench/board-roc-rk3568-pc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
board_type = "ROC-RK3568-PC"
shell_prefix = "root@starry:/root #"
success_regex = [
'(?m)^block-rw-bench: done cases=3 status=ok$',
]
fail_regex = [
'(?i)\bpanic(?:ked)?\b',
'(?m)^block-rw-bench: error: .*$',
'(?m)^block-rw-bench: .*verify=(?:fail|mismatch).*$',
'(?i)(block-rw-bench|sh): .*not found',
'(?i)\bI/O error\b',
]
timeout = 1200
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
target = "aarch64-unknown-none-softfloat"
features = [
"ax-driver/rockchip-soc",
"ax-driver/rockchip-sdhci",
"ax-driver/rockchip-dwmmc",
"ax-driver/phytium-mci",
]
log = "Info"
max_cpu_num = 1
1 change: 1 addition & 0 deletions apps/starry/block-rw-bench/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -rf /root/block-rw-bench && mkdir -p /root/block-rw-bench && /usr/bin/block-rw-bench && sync
9 changes: 7 additions & 2 deletions components/axklib/src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use core::{alloc::Layout, num::NonZeroUsize, ptr::NonNull};

use ax_memory_addr::{MemoryAddr, PAGE_SIZE_4K, VirtAddr};
use dma_api::{
DeviceDma, DmaAllocHandle, DmaConstraints, DmaDirection, DmaError, DmaMapHandle, DmaOp,
DeviceDma, DmaAllocHandle, DmaConstraints, DmaDirection, DmaDomainId, DmaError, DmaMapHandle,
DmaOp,
};

pub struct KlibDma;
Expand All @@ -13,8 +14,12 @@ pub fn op() -> &'static KlibDma {
&DMA
}

pub const fn domain_id() -> DmaDomainId {
DmaDomainId::legacy_global()
}

pub fn device_with_mask(dma_mask: u64) -> DeviceDma {
DeviceDma::new(dma_mask, op())
DeviceDma::new(domain_id(), dma_mask, op())
}

struct DmaPages {
Expand Down
13 changes: 13 additions & 0 deletions components/sdio-host2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "sdio-host2"
version = "0.1.0"
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
description = "no_std SD/SDIO/MMC host bus transaction traits and types"
keywords.workspace = true
categories.workspace = true

[dependencies]
dma-api.workspace = true
Loading