Skip to content
Closed
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
4 changes: 4 additions & 0 deletions Cargo.lock

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

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
8 changes: 4 additions & 4 deletions drivers/ax-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ rockchip-sdhci = [
"dep:rdif-clk",
"dep:sdhci-host",
"dep:sdmmc-protocol",
"sdmmc-protocol/sdio",
"sdmmc-protocol/rdif",
]
phytium-mci = [
"block",
"plat-dyn",
"dep:ax-kspin",
"dep:phytium-mci-host",
"dep:sdmmc-protocol",
"sdmmc-protocol/sdio",
"sdmmc-protocol/rdif",
]
k230-sdhci = [
"block",
"plat-dyn",
"dep:sdhci-host",
"dep:sdmmc-protocol",
"sdmmc-protocol/sdio",
"sdmmc-protocol/rdif",
]
rockchip-dwmmc = [
"block",
Expand All @@ -92,7 +92,7 @@ rockchip-dwmmc = [
"dep:dwmmc-host",
"dep:rdif-clk",
"dep:sdmmc-protocol",
"sdmmc-protocol/sdio",
"sdmmc-protocol/rdif",
]
rk3588-pcie = [
"pci",
Expand Down
25 changes: 12 additions & 13 deletions drivers/ax-driver/src/block/k230_sdhci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ use rdrive::{
probe::OnProbeError,
register::{FdtInfo, ProbeFdt},
};
use sdhci_host::Sdhci;
use sdhci_host::{Sdhci, rdif as sdhci_rdif};
use sdmmc_protocol::{
Error, OperationPoll,
error::Phase,
sdio::{CardInfo, CardInitPreference, SdioInitScratch, SdioSdmmc},
};

use crate::{
block::{
ProbeFdtBlock, SharedDriver,
sdmmc::{SdmmcBlockConfig, SdmmcBlockDevice},
},
mmio::iomap,
};
use crate::{block::ProbeFdtBlock, mmio::iomap};

const SDHCI_POWER_330: u8 = 0x0e;

Expand Down Expand Up @@ -78,7 +72,8 @@ fn probe(probe: ProbeFdt<'_>) -> Result<(), OnProbeError> {
.map_err(|e| init_error(base_reg.address, mmio_size, e))?;
host.set_power(SDHCI_POWER_330);
host.enable_interrupts();
host.set_dma(axklib::dma::device_with_mask(u32::MAX as u64));
let dma = axklib::dma::device_with_mask(u32::MAX as u64);
host.set_dma(dma.clone());

info!("k230-sdhci: initialize card");
let mut card = SdioSdmmc::new(host);
Expand All @@ -96,10 +91,14 @@ fn probe(probe: ProbeFdt<'_>) -> Result<(), OnProbeError> {
card_info.ext_csd.is_some()
);

let raw = SharedDriver::new(card);
let dev = SdmmcBlockDevice::new(
raw,
SdmmcBlockConfig::dma("k230-sdhci", card_info.capacity_blocks.unwrap_or(0), false),
let dev = sdhci_rdif::device(
card,
sdhci_rdif::dma_config(
"k230-sdhci",
card_info.capacity_blocks.unwrap_or(0),
false,
dma,
),
);
let irq = probe.register_block(dev)?;
info!("k230-sdhci block device registered irq={:?}", irq);
Expand Down
7 changes: 0 additions & 7 deletions drivers/ax-driver/src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
mod binding;

#[cfg(any(
feature = "k230-sdhci",
feature = "phytium-mci",
feature = "rockchip-dwmmc",
feature = "rockchip-sdhci"
))]
pub(crate) mod sdmmc;
#[allow(unused)]
mod shared;

Expand Down
22 changes: 10 additions & 12 deletions drivers/ax-driver/src/block/phytium_mci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::format;
use core::time::Duration;

use log::{info, warn};
use phytium_mci_host::PhytiumMci;
use phytium_mci_host::{PhytiumMci, rdif as phytium_rdif};
use rdrive::{
probe::OnProbeError,
register::{FdtInfo, ProbeFdt},
Expand All @@ -13,13 +13,7 @@ use sdmmc_protocol::{
sdio::{CardInfo, CardInitPreference, SdioInitScratch, SdioSdmmc},
};

use crate::{
block::{
ProbeFdtBlock, SharedDriver,
sdmmc::{SdmmcBlockConfig, SdmmcBlockDevice},
},
mmio::iomap,
};
use crate::{block::ProbeFdtBlock, mmio::iomap};

type PhytiumSdMmc = SdioSdmmc<PhytiumMci>;

Expand Down Expand Up @@ -81,10 +75,14 @@ fn probe(probe: ProbeFdt<'_>) -> Result<(), OnProbeError> {
card_info.ext_csd.is_some()
);

let raw = SharedDriver::new(card);
let dev = SdmmcBlockDevice::new(
raw,
SdmmcBlockConfig::fifo("phytium-mci", card_info.capacity_blocks.unwrap_or(0), false),
let dev = phytium_rdif::device(
card,
phytium_rdif::dma_config(
"phytium-mci",
card_info.capacity_blocks.unwrap_or(0),
false,
axklib::dma::device_with_mask(u32::MAX as u64),
),
);
let irq = probe.register_block(dev)?;
info!("phytium-mci block device registered irq={:?}", irq);
Expand Down
Loading
Loading