[PATCH v2] cmd: mtd: fix speed measurement in the speed benchmark
Mikhail Kshevetskiy
mikhail.kshevetskiy at iopsys.eu
Tue Aug 26 21:21:31 CEST 2025
The shown speed inversely proportional to the data size.
See the output:
spi-nand: spi_nand nand at 0: Micron SPI NAND was found.
spi-nand: spi_nand nand at 0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128
...
=> mtd read.benchmark spi-nand0 $loadaddr 0 0x40000
Reading 262144 byte(s) (128 page(s)) at offset 0x00000000
Read speed: 63kiB/s
=> mtd read.benchmark spi-nand0 $loadaddr 0 0x20000
Reading 131072 byte(s) (64 page(s)) at offset 0x00000000
Read speed: 127kiB/s
=> mtd read.benchmark spi-nand0 $loadaddr 0 0x10000
Reading 65536 byte(s) (32 page(s)) at offset 0x00000000
Read speed: 254kiB/s
In the spi-nand case 'io_op.len' is not always the same as 'len', thus
we are using the wrong amount of data to derive the speed.
The patch also updates the help for 'mtd read' command to show the presence
of the benchmark option. The help for the 'mtd write' command help has not
been changed to fit 80 character width restriction.
Fixes: d246e70cf81d0 ("cmd: mtd: Enable speed benchmarking")
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy at iopsys.eu>
---
cmd/mtd.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Changes v2:
* update commit message
* 'Fixes:' tag was added
* calculate speed a bit more precisely using a 64-bit math
diff --git a/cmd/mtd.c b/cmd/mtd.c
index cee3a7e43ef..7e022fdc0f7 100644
--- a/cmd/mtd.c
+++ b/cmd/mtd.c
@@ -469,7 +469,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
bool dump, read, raw, woob, benchmark, write_empty_pages, has_pages = false;
- u64 start_off, off, len, remaining, default_len;
+ u64 start_off, off, len, remaining, default_len, speed;
unsigned long bench_start, bench_end;
struct mtd_oob_ops io_op = {};
uint user_addr = 0, npages;
@@ -595,9 +595,10 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
if (benchmark && bench_start) {
bench_end = timer_get_us();
+ speed = (len * 1000000) / (bench_end - bench_start);
printf("%s speed: %lukiB/s\n",
read ? "Read" : "Write",
- ((io_op.len * 1000000) / (bench_end - bench_start)) / 1024);
+ (unsigned long)(speed / 1024));
}
led_activity_off();
@@ -1210,7 +1211,7 @@ static int mtd_name_complete(int argc, char *const argv[], char last_char,
U_BOOT_LONGHELP(mtd,
"- generic operations on memory technology devices\n\n"
"mtd list\n"
- "mtd read[.raw][.oob] <name> <addr> [<off> [<size>]]\n"
+ "mtd read[.raw][.oob][.benchmark] <name> <addr> [<off> [<size>]]\n"
"mtd dump[.raw][.oob] <name> [<off> [<size>]]\n"
"mtd write[.raw][.oob][.dontskipff] <name> <addr> [<off> [<size>]]\n"
"mtd erase[.dontskipbad] <name> [<off> [<size>]]\n"
--
2.50.1
More information about the U-Boot
mailing list