* [PATCH] cmd: mtd: Enable speed benchmarking
@ 2025-07-03 16:58 Miquel Raynal
2025-07-03 17:19 ` Michael Nazzareno Trimarchi
0 siblings, 1 reply; 4+ messages in thread
From: Miquel Raynal @ 2025-07-03 16:58 UTC (permalink / raw)
To: Tom Rini
Cc: Christian Marangi, Michael Trimarchi, Heinrich Schuchardt, u-boot,
Steam Lin, Thomas Petazzoni, Miquel Raynal
Linux features a flash_speed speed test from the mtd-utils suite, U-Boot
does not. Benchmarks are useful for speed improvement developments as
well as troubleshooting or regression testing sometimes.
Enable a benchmark option to enable this feature.
Example of output on a Nuvoton platform:
MA35D1> mtd read nor0 0x81000000 0 0x10000
Reading 65536 byte(s) at offset 0x00000000
MA35D1> mtd read.benchmark nor0 0x81000000 0 0x10000
Reading 65536 byte(s) at offset 0x00000000
Read speed: 3752kiB/s
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
cmd/mtd.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/cmd/mtd.c b/cmd/mtd.c
index c25997cfb246..d5843db663d7 100644
--- a/cmd/mtd.c
+++ b/cmd/mtd.c
@@ -17,6 +17,7 @@
#include <malloc.h>
#include <mapmem.h>
#include <mtd.h>
+#include <time.h>
#include <dm/devres.h>
#include <linux/err.h>
@@ -466,10 +467,11 @@ static int mtd_special_write_oob(struct mtd_info *mtd, u64 off,
static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
- bool dump, read, raw, woob, write_empty_pages, has_pages = false;
+ bool dump, read, raw, woob, benchmark, write_empty_pages, has_pages = false;
u64 start_off, off, len, remaining, default_len;
struct mtd_oob_ops io_op = {};
uint user_addr = 0, npages;
+ u32 bench_start, bench_end;
const char *cmd = argv[0];
struct mtd_info *mtd;
u32 oob_len;
@@ -490,6 +492,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
read = dump || !strncmp(cmd, "read", 4);
raw = strstr(cmd, ".raw");
woob = strstr(cmd, ".oob");
+ benchmark = strstr(cmd, ".benchmark");
write_empty_pages = !has_pages || strstr(cmd, ".dontskipff");
argc -= 2;
@@ -559,6 +562,9 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
led_activity_blink();
+ if (benchmark)
+ bench_start = timer_get_us();
+
/* Loop over the pages to do the actual read/write */
while (remaining) {
/* Skip the block if it is bad */
@@ -586,6 +592,13 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
io_op.oobbuf += io_op.oobretlen;
}
+ if (benchmark && bench_start) {
+ bench_end = timer_get_us();
+ printf("%s speed: %lukiB/s\n",
+ read ? "Read" : "Write",
+ ((io_op.len * 1000000) / (bench_end - bench_start)) / 1024);
+ }
+
led_activity_off();
if (!ret && dump)
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cmd: mtd: Enable speed benchmarking
2025-07-03 16:58 [PATCH] cmd: mtd: Enable speed benchmarking Miquel Raynal
@ 2025-07-03 17:19 ` Michael Nazzareno Trimarchi
2025-08-04 9:15 ` Miquel Raynal
0 siblings, 1 reply; 4+ messages in thread
From: Michael Nazzareno Trimarchi @ 2025-07-03 17:19 UTC (permalink / raw)
To: Miquel Raynal
Cc: Tom Rini, Christian Marangi, Heinrich Schuchardt, u-boot,
Steam Lin, Thomas Petazzoni
Hi Miquel
On Thu, Jul 3, 2025 at 6:58 PM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Linux features a flash_speed speed test from the mtd-utils suite, U-Boot
> does not. Benchmarks are useful for speed improvement developments as
> well as troubleshooting or regression testing sometimes.
>
> Enable a benchmark option to enable this feature.
>
> Example of output on a Nuvoton platform:
>
> MA35D1> mtd read nor0 0x81000000 0 0x10000
> Reading 65536 byte(s) at offset 0x00000000
> MA35D1> mtd read.benchmark nor0 0x81000000 0 0x10000
> Reading 65536 byte(s) at offset 0x00000000
> Read speed: 3752kiB/s
>
I was using time and reading but this looked much nicer. I will give it a try
and review.
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
> cmd/mtd.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/cmd/mtd.c b/cmd/mtd.c
> index c25997cfb246..d5843db663d7 100644
> --- a/cmd/mtd.c
> +++ b/cmd/mtd.c
> @@ -17,6 +17,7 @@
> #include <malloc.h>
> #include <mapmem.h>
> #include <mtd.h>
> +#include <time.h>
> #include <dm/devres.h>
> #include <linux/err.h>
>
> @@ -466,10 +467,11 @@ static int mtd_special_write_oob(struct mtd_info *mtd, u64 off,
> static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
> char *const argv[])
> {
> - bool dump, read, raw, woob, write_empty_pages, has_pages = false;
> + bool dump, read, raw, woob, benchmark, write_empty_pages, has_pages = false;
> u64 start_off, off, len, remaining, default_len;
> struct mtd_oob_ops io_op = {};
> uint user_addr = 0, npages;
> + u32 bench_start, bench_end;
unsigned long
> const char *cmd = argv[0];
> struct mtd_info *mtd;
> u32 oob_len;
> @@ -490,6 +492,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
> read = dump || !strncmp(cmd, "read", 4);
> raw = strstr(cmd, ".raw");
> woob = strstr(cmd, ".oob");
> + benchmark = strstr(cmd, ".benchmark");
> write_empty_pages = !has_pages || strstr(cmd, ".dontskipff");
>
> argc -= 2;
> @@ -559,6 +562,9 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
>
> led_activity_blink();
>
> + if (benchmark)
> + bench_start = timer_get_us();
> +
> /* Loop over the pages to do the actual read/write */
> while (remaining) {
> /* Skip the block if it is bad */
> @@ -586,6 +592,13 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
> io_op.oobbuf += io_op.oobretlen;
> }
>
> + if (benchmark && bench_start) {
> + bench_end = timer_get_us();
> + printf("%s speed: %lukiB/s\n",
> + read ? "Read" : "Write",
> + ((io_op.len * 1000000) / (bench_end - bench_start)) / 1024);
Did you check if it can not wrap?
Michael
> + }
> +
> led_activity_off();
>
> if (!ret && dump)
> --
> 2.49.0
>
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael@amarulasolutions.com
__________________________________
Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
info@amarulasolutions.com
www.amarulasolutions.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cmd: mtd: Enable speed benchmarking
2025-07-03 17:19 ` Michael Nazzareno Trimarchi
@ 2025-08-04 9:15 ` Miquel Raynal
2025-08-29 8:27 ` Michael Nazzareno Trimarchi
0 siblings, 1 reply; 4+ messages in thread
From: Miquel Raynal @ 2025-08-04 9:15 UTC (permalink / raw)
To: Michael Nazzareno Trimarchi
Cc: Tom Rini, Christian Marangi, Heinrich Schuchardt, u-boot,
Steam Lin, Thomas Petazzoni
Hello Michael,
>> MA35D1> mtd read nor0 0x81000000 0 0x10000
>> Reading 65536 byte(s) at offset 0x00000000
>> MA35D1> mtd read.benchmark nor0 0x81000000 0 0x10000
>> Reading 65536 byte(s) at offset 0x00000000
>> Read speed: 3752kiB/s
>>
>
> I was using time and reading but this looked much nicer. I will give it a try
> and review.
Thanks! It turned out very useful for development purposes :-)
>> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
>> ---
[...]
>> - bool dump, read, raw, woob, write_empty_pages, has_pages = false;
>> + bool dump, read, raw, woob, benchmark, write_empty_pages, has_pages = false;
>> u64 start_off, off, len, remaining, default_len;
>> struct mtd_oob_ops io_op = {};
>> uint user_addr = 0, npages;
>> + u32 bench_start, bench_end;
>
> unsigned long
Okay.
>> const char *cmd = argv[0];
>> struct mtd_info *mtd;
>> u32 oob_len;
>> @@ -490,6 +492,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
>> read = dump || !strncmp(cmd, "read", 4);
>> raw = strstr(cmd, ".raw");
>> woob = strstr(cmd, ".oob");
>> + benchmark = strstr(cmd, ".benchmark");
>> write_empty_pages = !has_pages || strstr(cmd, ".dontskipff");
>>
>> argc -= 2;
>> @@ -559,6 +562,9 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
>>
>> led_activity_blink();
>>
>> + if (benchmark)
>> + bench_start = timer_get_us();
>> +
>> /* Loop over the pages to do the actual read/write */
>> while (remaining) {
>> /* Skip the block if it is bad */
>> @@ -586,6 +592,13 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
>> io_op.oobbuf += io_op.oobretlen;
>> }
>>
>> + if (benchmark && bench_start) {
>> + bench_end = timer_get_us();
>> + printf("%s speed: %lukiB/s\n",
>> + read ? "Read" : "Write",
>> + ((io_op.len * 1000000) / (bench_end - bench_start)) / 1024);
>
> Did you check if it can not wrap?
That is a good question, if my calculations are correct, time capture
may wrap if one spends more than 1h12 in the Bootloader. So yes it is
'doable' to make the time overlap.
But is this relevant? It really is a development feature at the moment
(developers comparing speeds would notice the overlap) and Bootloaders
in general are not supposed to run for that long anyway. So I would
argue that it is acceptable like that.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cmd: mtd: Enable speed benchmarking
2025-08-04 9:15 ` Miquel Raynal
@ 2025-08-29 8:27 ` Michael Nazzareno Trimarchi
0 siblings, 0 replies; 4+ messages in thread
From: Michael Nazzareno Trimarchi @ 2025-08-29 8:27 UTC (permalink / raw)
To: Miquel Raynal
Cc: Tom Rini, Christian Marangi, Heinrich Schuchardt, U-Boot-Denx,
Steam Lin, Thomas Petazzoni
Hi
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael@amarulasolutions.com
__________________________________
Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
info@amarulasolutions.com
www.amarulasolutions.com
Il lun 4 ago 2025, 11:15 Miquel Raynal <miquel.raynal@bootlin.com> ha
scritto:
> Hello Michael,
>
> >> MA35D1> mtd read nor0 0x81000000 0 0x10000
> >> Reading 65536 byte(s) at offset 0x00000000
> >> MA35D1> mtd read.benchmark nor0 0x81000000 0 0x10000
> >> Reading 65536 byte(s) at offset 0x00000000
> >> Read speed: 3752kiB/s
> >>
> >
> > I was using time and reading but this looked much nicer. I will give it
> a try
> > and review.
>
> Thanks! It turned out very useful for development purposes :-)
>
> >> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> >> ---
>
> [...]
>
> >> - bool dump, read, raw, woob, write_empty_pages, has_pages =
> false;
> >> + bool dump, read, raw, woob, benchmark, write_empty_pages,
> has_pages = false;
> >> u64 start_off, off, len, remaining, default_len;
> >> struct mtd_oob_ops io_op = {};
> >> uint user_addr = 0, npages;
> >> + u32 bench_start, bench_end;
> >
> > unsigned long
>
> Okay.
>
> >> const char *cmd = argv[0];
> >> struct mtd_info *mtd;
> >> u32 oob_len;
> >> @@ -490,6 +492,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int
> flag, int argc,
> >> read = dump || !strncmp(cmd, "read", 4);
> >> raw = strstr(cmd, ".raw");
> >> woob = strstr(cmd, ".oob");
> >> + benchmark = strstr(cmd, ".benchmark");
> >> write_empty_pages = !has_pages || strstr(cmd, ".dontskipff");
> >>
> >> argc -= 2;
> >> @@ -559,6 +562,9 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int
> flag, int argc,
> >>
> >> led_activity_blink();
> >>
> >> + if (benchmark)
> >> + bench_start = timer_get_us();
> >> +
> >> /* Loop over the pages to do the actual read/write */
> >> while (remaining) {
> >> /* Skip the block if it is bad */
> >> @@ -586,6 +592,13 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int
> flag, int argc,
> >> io_op.oobbuf += io_op.oobretlen;
> >> }
> >>
> >> + if (benchmark && bench_start) {
> >> + bench_end = timer_get_us();
> >> + printf("%s speed: %lukiB/s\n",
> >> + read ? "Read" : "Write",
> >> + ((io_op.len * 1000000) / (bench_end -
> bench_start)) / 1024);
> >
> > Did you check if it can not wrap?
>
> That is a good question, if my calculations are correct, time capture
> may wrap if one spends more than 1h12 in the Bootloader. So yes it is
> 'doable' to make the time overlap.
>
> But is this relevant? It really is a development feature at the moment
> (developers comparing speeds would notice the overlap) and Bootloaders
> in general are not supposed to run for that long anyway. So I would
> argue that it is acceptable like that.
>
No was not. Because we run 10 seconds test
Michael
>
> Thanks,
> Miquèl
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-29 8:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03 16:58 [PATCH] cmd: mtd: Enable speed benchmarking Miquel Raynal
2025-07-03 17:19 ` Michael Nazzareno Trimarchi
2025-08-04 9:15 ` Miquel Raynal
2025-08-29 8:27 ` Michael Nazzareno Trimarchi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.