* [PATCH mtd-utils 00/10] New options for hardening continuous read support
@ 2024-08-26 9:46 Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 01/10] nand-utils: nanddump: Use a specific variable for the buffer size Miquel Raynal
` (10 more replies)
0 siblings, 11 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
Continuous reads can significantly improve the read speed when several
sequential pages are read. Support has been (is being) contributed to
the Linux kernel and in order to test the features I had to hack in to
the mtd-utils in order to add several options.
The options are named -c, except when -c was already in-use, where I
switched to -C:
* nanddump: When asking for more than one page, we can ask to enable the
feature and compare two outputs.
* nandbiterrs: The biflips will only happen in the first page, but two
pages will be read. The returned values concern the
entire read.
* flash_test: It is interesting to see the read speed increasing with
the number of pages. The new measurements are made
optionals.
Cheers,
Miquèl
Miquel Raynal (10):
nand-utils: nanddump: Use a specific variable for the buffer size
nand-utils: nanddump: Explicitely use the page size when relevant
nand-utils: nanddump: Add support for testing continuous reads
mtd-tests: nandbiterrs: Store the chunks size in an intermediate
variable
mtd-tests: nandbiterrs: Add support for testing continuous reads
mtd-tests: flash_speed: Drop an apparently useless block
mtd-tests: flash_speed: Clarify the number of pages in each set while
measuring
mtd-tests: flash_speed: Generalize read_eraseblock_by_2pages()
mtd-tests: flash_speed: Drop read_eraseblock_by_page()
mtd-tests: flash_speed: Benchmark continuous reads
nand-utils/nanddump.c | 34 ++++++++---
tests/mtd-tests/flash_speed.c | 111 +++++++++++++++++-----------------
tests/mtd-tests/nandbiterrs.c | 35 +++++++----
3 files changed, 106 insertions(+), 74 deletions(-)
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 01/10] nand-utils: nanddump: Use a specific variable for the buffer size
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 02/10] nand-utils: nanddump: Explicitely use the page size when relevant Miquel Raynal
` (9 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
The read buffer size happen to be as big as the bs variable, but this is
going to change. When accessing the buffer size, use a specific variable
instead.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
nand-utils/nanddump.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/nand-utils/nanddump.c b/nand-utils/nanddump.c
index 47539f5..346af1e 100644
--- a/nand-utils/nanddump.c
+++ b/nand-utils/nanddump.c
@@ -332,7 +332,7 @@ static int ofd_write(int ofd, const void *buf, size_t nbyte)
*/
int main(int argc, char * const argv[])
{
- long long ofs, end_addr = 0;
+ long long ofs, end_addr = 0, readbuf_sz;
long long blockstart = 1;
int i, fd, ofd = 0, bs, badblock = 0;
struct mtd_dev_info mtd;
@@ -362,8 +362,9 @@ int main(int argc, char * const argv[])
return errmsg("mtd_get_dev_info failed");
/* Allocate buffers */
+ readbuf_sz = mtd.min_io_size;
oobbuf = xmalloc(mtd.oob_size);
- readbuf = xmalloc(mtd.min_io_size);
+ readbuf = xmalloc(readbuf_sz);
if (noecc) {
if (ioctl(fd, MTDFILEMODE, MTD_FILE_MODE_RAW) != 0) {
@@ -462,7 +463,7 @@ int main(int argc, char * const argv[])
end_addr = mtd.size;
continue;
}
- memset(readbuf, 0xff, bs);
+ memset(readbuf, 0xff, readbuf_sz);
} else {
/* Read page data and exit on failure */
if (mtd_read(&mtd, fd, ofs / mtd.eb_size, ofs % mtd.eb_size, readbuf, bs)) {
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 02/10] nand-utils: nanddump: Explicitely use the page size when relevant
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 01/10] nand-utils: nanddump: Use a specific variable for the buffer size Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 03/10] nand-utils: nanddump: Add support for testing continuous reads Miquel Raynal
` (8 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
Using bs when skipping the bad sector is abusive as what we want is
using the size of a block and the size of a page. The fact that bs
currently is the size of a page is misleading here, has I intend to make
this amount grow.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
nand-utils/nanddump.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nand-utils/nanddump.c b/nand-utils/nanddump.c
index 346af1e..a3e6e92 100644
--- a/nand-utils/nanddump.c
+++ b/nand-utils/nanddump.c
@@ -458,7 +458,7 @@ int main(int argc, char * const argv[])
/* skip bad block, increase end_addr */
if (bb_method == skipbad) {
end_addr += mtd.eb_size;
- ofs += mtd.eb_size - bs;
+ ofs += mtd.eb_size - mtd.min_io_size;
if (end_addr > mtd.size)
end_addr = mtd.size;
continue;
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 03/10] nand-utils: nanddump: Add support for testing continuous reads
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 01/10] nand-utils: nanddump: Use a specific variable for the buffer size Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 02/10] nand-utils: nanddump: Explicitely use the page size when relevant Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 04/10] mtd-tests: nandbiterrs: Store the chunks size in an intermediate variable Miquel Raynal
` (7 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
In order to trigger a continuous read, the user needs to request more
than one data page. So far the tool would split the length into page
chunks. This is no longer the case when the -C option is passed (-c is
already used for the canonical output style).
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
nand-utils/nanddump.c | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/nand-utils/nanddump.c b/nand-utils/nanddump.c
index a3e6e92..bc22858 100644
--- a/nand-utils/nanddump.c
+++ b/nand-utils/nanddump.c
@@ -54,6 +54,7 @@ static void display_help(int status)
"-s addr --startaddress=addr Start address\n"
" --skip-bad-blocks-to-start\n"
" Skip bad blocks when seeking to the start address\n"
+"-C --continuous Continuous read up to a block of data at a time\n"
"\n"
"--bb=METHOD, where METHOD can be `padbad', `dumpbad', or `skipbad':\n"
" padbad: dump flash data, substituting 0xFF for any bad blocks\n"
@@ -89,6 +90,7 @@ static bool quiet = false; // suppress diagnostic output
static bool canonical = false; // print nice + ascii
static bool forcebinary = false; // force printing binary to tty
static bool skip_bad_blocks_to_start = false;
+static bool continuous = false; // leverage continuous reads
static enum {
padbad, // dump flash data, substituting 0xFF for any bad blocks
@@ -103,7 +105,7 @@ static void process_options(int argc, char * const argv[])
for (;;) {
int option_index = 0;
- static const char short_options[] = "hs:f:l:opqncaV";
+ static const char short_options[] = "hs:f:l:opqncaVC";
static const struct option long_options[] = {
{"version", no_argument, 0, 'V'},
{"bb", required_argument, 0, 0},
@@ -119,6 +121,7 @@ static void process_options(int argc, char * const argv[])
{"length", required_argument, 0, 'l'},
{"noecc", no_argument, 0, 'n'},
{"quiet", no_argument, 0, 'q'},
+ {"continuous", no_argument, 0, 'C'},
{0, 0, 0, 0},
};
@@ -191,6 +194,9 @@ static void process_options(int argc, char * const argv[])
case 'n':
noecc = true;
break;
+ case 'C':
+ continuous = true;
+ break;
case 'h':
display_help(EXIT_SUCCESS);
break;
@@ -220,6 +226,13 @@ static void process_options(int argc, char * const argv[])
exit(EXIT_FAILURE);
}
+ if (continuous && !omitoob) {
+ fprintf(stderr, "Sequential/continuous reads (when available) will\n"
+ "always skip OOB data, so it is not possible to \n"
+ "request both at the same time.\n");
+ exit(EXIT_FAILURE);
+ }
+
if ((argc - optind) != 1 || error)
display_help(EXIT_FAILURE);
@@ -362,7 +375,7 @@ int main(int argc, char * const argv[])
return errmsg("mtd_get_dev_info failed");
/* Allocate buffers */
- readbuf_sz = mtd.min_io_size;
+ readbuf_sz = mtd.eb_size;
oobbuf = xmalloc(mtd.oob_size);
readbuf = xmalloc(readbuf_sz);
@@ -428,8 +441,6 @@ int main(int argc, char * const argv[])
if (!length || end_addr > mtd.size)
end_addr = mtd.size;
- bs = mtd.min_io_size;
-
/* Print informative message */
if (!quiet) {
fprintf(stderr, "Block size %d, page size %d, OOB size %d\n",
@@ -441,6 +452,8 @@ int main(int argc, char * const argv[])
/* Dump the flash contents */
for (ofs = start_addr; ofs < end_addr; ofs += bs) {
+ long long size_left = end_addr - ofs;
+
/* Check for bad block */
if (bb_method == dumpbad) {
badblock = 0;
@@ -454,6 +467,11 @@ int main(int argc, char * const argv[])
}
}
+ if (continuous)
+ bs = MIN(size_left, mtd.eb_size);
+ else
+ bs = mtd.min_io_size;
+
if (badblock) {
/* skip bad block, increase end_addr */
if (bb_method == skipbad) {
@@ -500,7 +518,6 @@ int main(int argc, char * const argv[])
}
} else {
/* Write requested length if oob is omitted */
- long long size_left = end_addr - ofs;
if (omitoob && (size_left < bs))
err = ofd_write(ofd, readbuf, size_left);
else
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 04/10] mtd-tests: nandbiterrs: Store the chunks size in an intermediate variable
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (2 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 03/10] nand-utils: nanddump: Add support for testing continuous reads Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 05/10] mtd-tests: nandbiterrs: Add support for testing continuous reads Miquel Raynal
` (6 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
'pagesize' is used for two purposes:
- accessing the size of a page
- getting the size of the test buffer, which happen to be the size of a
page for now.
Use an intermediate variable when getting the size of the test buffer,
as we will later increase its size.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
tests/mtd-tests/nandbiterrs.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/tests/mtd-tests/nandbiterrs.c b/tests/mtd-tests/nandbiterrs.c
index f583c14..30954f5 100644
--- a/tests/mtd-tests/nandbiterrs.c
+++ b/tests/mtd-tests/nandbiterrs.c
@@ -68,7 +68,7 @@ static int peb = -1, page = -1, max_overwrite = -1, seed = -1;
static const char *mtddev;
static unsigned char *wbuffer, *rbuffer, *old_data;
-static int fd, pagesize, pagecount, flags;
+static int fd, pagesize, bs, pagecount, flags;
static struct mtd_dev_info mtd;
static libmtd_t mtd_desc;
@@ -235,9 +235,9 @@ static void init_buffer(void)
unsigned int i;
if (flags & PAGE_ERASED) {
- memset(wbuffer, 0xff, pagesize);
+ memset(wbuffer, 0xff, bs);
} else {
- for (i = 0; i < pagesize; ++i)
+ for (i = 0; i < bs; ++i)
wbuffer[i] = hash(i+seed);
}
}
@@ -251,7 +251,7 @@ static int write_page(void)
goto fail_mode;
err = mtd_write(mtd_desc, &mtd, fd, peb, page*pagesize,
- wbuffer, pagesize, NULL, 0, 0);
+ wbuffer, bs, NULL, 0, 0);
if (err)
fprintf(stderr, "Failed to write page %d in block %d\n", peb, page);
@@ -290,7 +290,7 @@ static int read_page(void)
if (ioctl(fd, ECCGETSTATS, &old) != 0)
goto failstats;
- err = mtd_read(&mtd, fd, peb, page*pagesize, rbuffer, pagesize);
+ err = mtd_read(&mtd, fd, peb, page*pagesize, rbuffer, bs);
if (err) {
fputs("Read failed!\n", stderr);
return -1;
@@ -316,7 +316,7 @@ static int verify_page(void)
int erased = flags & PAGE_ERASED;
unsigned int i, errs = 0;
- for (i = 0; i < pagesize; ++i) {
+ for (i = 0; i < bs; ++i) {
if (rbuffer[i] != (erased ? 0xff : hash(i+seed)))
++errs;
}
@@ -332,7 +332,7 @@ static int insert_biterror(void)
{
int bit, mask, byte;
- for (byte = 0; byte < pagesize; ++byte) {
+ for (byte = 0; byte < bs; ++byte) {
for (bit = 7, mask = 0x80; bit >= 0; bit--, mask >>= 1) {
if (wbuffer[byte] & mask) {
wbuffer[byte] &= ~mask;
@@ -461,6 +461,7 @@ int main(int argc, char **argv)
pagesize = mtd.subpage_size;
pagecount = mtd.eb_size / pagesize;
+ bs = pagesize;
if (peb >= mtd.eb_cnt)
return errmsg("Physical erase block %d is out of range!", peb);
@@ -483,13 +484,13 @@ int main(int argc, char **argv)
}
}
- wbuffer = malloc(pagesize);
+ wbuffer = malloc(bs);
if (!wbuffer) {
perror(NULL);
goto fail_dev;
}
- rbuffer = malloc(pagesize);
+ rbuffer = malloc(bs);
if (!rbuffer) {
perror(NULL);
goto fail_rbuffer;
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 05/10] mtd-tests: nandbiterrs: Add support for testing continuous reads
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (3 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 04/10] mtd-tests: nandbiterrs: Store the chunks size in an intermediate variable Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 06/10] mtd-tests: flash_speed: Drop an apparently useless block Miquel Raynal
` (5 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
In order to trigger a continuous read, the user needs to request at
least two pages at the same time. So far the tool would only read single
pages, so let's extend its capabilities to test continuous read output
when the -c option is passed.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
tests/mtd-tests/nandbiterrs.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/tests/mtd-tests/nandbiterrs.c b/tests/mtd-tests/nandbiterrs.c
index 30954f5..424a95f 100644
--- a/tests/mtd-tests/nandbiterrs.c
+++ b/tests/mtd-tests/nandbiterrs.c
@@ -63,6 +63,7 @@
#define MODE_INCREMENTAL 0x02
#define MODE_OVERWRITE 0x04
#define PAGE_ERASED 0x08
+#define CONTINUOUS_READ 0x10
static int peb = -1, page = -1, max_overwrite = -1, seed = -1;
static const char *mtddev;
@@ -81,6 +82,7 @@ static const struct option options[] = {
{ "erased", no_argument, NULL, 'e' },
{ "writes", required_argument, NULL, 'w' },
{ "incremental", no_argument, NULL, 'i' },
+ { "continuous", no_argument, NULL, 'c' },
{ "overwrite", no_argument, NULL, 'o' },
{ NULL, 0, NULL, 0 },
};
@@ -95,7 +97,8 @@ static NORETURN void usage(int status)
" -b, --peb <num> Use this physical erase block\n"
" -p, --page <num> Use this page within the erase block\n"
" -s, --seed <num> Specify seed for PRNG\n"
- " -e, --erased Test erased pages instead of written pages\n\n"
+ " -e, --erased Test erased pages instead of written pages\n"
+ " -c, --continuous Use two consecutive pages (incremental test only)\n\n"
"Options controling test mode:\n"
" -i, --incremental Manually insert bit errors until ECC fails\n"
" -o, --overwrite Rewrite page until bits flip and ECC fails\n\n"
@@ -124,7 +127,7 @@ static void process_options(int argc, char **argv)
int c;
while (1) {
- c = getopt_long(argc, argv, "hkb:p:s:eiow:", options, NULL);
+ c = getopt_long(argc, argv, "hkb:p:s:eiow:c", options, NULL);
if (c == -1)
break;
@@ -175,6 +178,9 @@ static void process_options(int argc, char **argv)
case 'e':
flags |= PAGE_ERASED;
break;
+ case 'c':
+ flags |= CONTINUOUS_READ;
+ break;
case 'h':
usage(EXIT_SUCCESS);
default:
@@ -193,6 +199,9 @@ static void process_options(int argc, char **argv)
if (!(flags & (MODE_OVERWRITE|MODE_INCREMENTAL)))
errmsg_die("No test mode specified!");
+ if (flags & CONTINUOUS_READ && !(flags & MODE_INCREMENTAL))
+ errmsg_die("Use --continuous with --incremental only!");
+
if ((max_overwrite > 0) && !(flags & MODE_OVERWRITE))
errmsg_die("Write count specified but mode is not --overwrite!");
@@ -461,7 +470,10 @@ int main(int argc, char **argv)
pagesize = mtd.subpage_size;
pagecount = mtd.eb_size / pagesize;
- bs = pagesize;
+ if (!(flags & CONTINUOUS_READ))
+ bs = pagesize;
+ else
+ bs = 2 * pagesize;
if (peb >= mtd.eb_cnt)
return errmsg("Physical erase block %d is out of range!", peb);
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 06/10] mtd-tests: flash_speed: Drop an apparently useless block
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (4 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 05/10] mtd-tests: nandbiterrs: Add support for testing continuous reads Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 07/10] mtd-tests: flash_speed: Clarify the number of pages in each set while measuring Miquel Raynal
` (4 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
I know no device without a multiple of 2 number of pages in each
block. Even though it might be the case, it is clearly not a big deal
and we don't really care about reading the last page, we are doing a
speed benchmark; so as long as the throughput calculation knows how much
data has been read it's fine. Eitherway, I don't think we ever have
fallen in this block because we would read the content of two pages (so
one past the block) and put it in a page-wide buffer, which would
probably lead to an out-of-bound abort.
Just drop the block.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
tests/mtd-tests/flash_speed.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/tests/mtd-tests/flash_speed.c b/tests/mtd-tests/flash_speed.c
index 3489233..f542a8d 100644
--- a/tests/mtd-tests/flash_speed.c
+++ b/tests/mtd-tests/flash_speed.c
@@ -265,13 +265,6 @@ static int read_eraseblock_by_2pages(int ebnum)
}
buf += sz;
}
- if (pgcnt % 2) {
- err = mtd_read(&mtd, fd, ebnum, i * sz, iobuf, pgsize);
- if (err) {
- fprintf(stderr, "Error reading block %d, page %d!\n",
- ebnum, i*2);
- }
- }
return err;
}
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 07/10] mtd-tests: flash_speed: Clarify the number of pages in each set while measuring
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (5 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 06/10] mtd-tests: flash_speed: Drop an apparently useless block Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 08/10] mtd-tests: flash_speed: Generalize read_eraseblock_by_2pages() Miquel Raynal
` (3 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
So far speed calculations have only be done 1 page at a time or 2 pages
at a time in a block; so basically all the block was always read because
all blocks are multiple of 2. But in the future, if we want to extend
the number of pages in a single read, the final number of pages actually
read might be less than an erase block size, hence failing the throuput
calculations.
Make the number of pages in a set explicit.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
tests/mtd-tests/flash_speed.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/tests/mtd-tests/flash_speed.c b/tests/mtd-tests/flash_speed.c
index f542a8d..f161d6e 100644
--- a/tests/mtd-tests/flash_speed.c
+++ b/tests/mtd-tests/flash_speed.c
@@ -289,14 +289,17 @@ static long calc_duration(struct timespec *start, struct timespec *finish)
return ms;
}
-static long calc_speed(struct timespec *start, struct timespec *finish)
+static long calc_speed(struct timespec *start, struct timespec *finish,
+ int pages_per_set)
{
long ms = calc_duration(start, finish);
+ int sets_in_eb = pgcnt / pages_per_set;
+ size_t sz = pgsize * pages_per_set * sets_in_eb;
if (ms <= 0)
return 0;
- return ((long)goodebcnt * (mtd.eb_size / 1024L) * 1000L) / ms;
+ return ((long)goodebcnt * (sz / 1024L) * 1000L) / ms;
}
static void scan_for_bad_eraseblocks(unsigned int eb, int ebcnt, int ebskip)
@@ -357,7 +360,7 @@ static void *op_thread(void *ptr)
return (void *)err;
}
-#define TIME_OP_PER_PEB( op )\
+#define TIME_OP_PER_PEB( op, npages ) \
start_timing(&start);\
for (i = 0; i < count; ++i) {\
if (bbt[i])\
@@ -367,7 +370,7 @@ static void *op_thread(void *ptr)
goto out;\
}\
stop_timing(&finish);\
- speed = calc_speed(&start, &finish)
+ speed = calc_speed(&start, &finish, npages)
int main(int argc, char **argv)
{
@@ -428,13 +431,13 @@ int main(int argc, char **argv)
goto out;
puts("testing eraseblock write speed");
- TIME_OP_PER_PEB(write_eraseblock);
+ TIME_OP_PER_PEB(write_eraseblock, 1);
printf("eraseblock write speed is %ld KiB/s\n", speed);
}
/* Read all eraseblocks, 1 eraseblock at a time */
puts("testing eraseblock read speed");
- TIME_OP_PER_PEB(read_eraseblock);
+ TIME_OP_PER_PEB(read_eraseblock, 1);
printf("eraseblock read speed is %ld KiB/s\n", speed);
/* Write all eraseblocks, 1 page at a time */
@@ -444,13 +447,13 @@ int main(int argc, char **argv)
goto out;
puts("testing page write speed");
- TIME_OP_PER_PEB(write_eraseblock_by_page);
+ TIME_OP_PER_PEB(write_eraseblock_by_page, 1);
printf("page write speed is %ld KiB/s\n", speed);
}
/* Read all eraseblocks, 1 page at a time */
puts("testing page read speed");
- TIME_OP_PER_PEB(read_eraseblock_by_page);
+ TIME_OP_PER_PEB(read_eraseblock_by_page, 1);
printf("page read speed is %ld KiB/s\n", speed);
/* Write all eraseblocks, 2 pages at a time */
@@ -460,13 +463,13 @@ int main(int argc, char **argv)
goto out;
puts("testing 2 page write speed");
- TIME_OP_PER_PEB(write_eraseblock_by_2pages);
+ TIME_OP_PER_PEB(write_eraseblock_by_2pages, 2);
printf("2 page write speed is %ld KiB/s\n", speed);
}
/* Read all eraseblocks, 2 pages at a time */
puts("testing 2 page read speed");
- TIME_OP_PER_PEB(read_eraseblock_by_2pages);
+ TIME_OP_PER_PEB(read_eraseblock_by_2pages, 2);
printf("2 page read speed is %ld KiB/s\n", speed);
/* Erase all eraseblocks */
@@ -477,7 +480,7 @@ int main(int argc, char **argv)
if (err)
goto out;
stop_timing(&finish);
- speed = calc_speed(&start, &finish);
+ speed = calc_speed(&start, &finish, 1);
printf("erase speed is %ld KiB/s\n", speed);
}
@@ -501,7 +504,7 @@ int main(int argc, char **argv)
i += j;
}
stop_timing(&finish);
- speed = calc_speed(&start, &finish);
+ speed = calc_speed(&start, &finish, 1);
printf("%dx multi-block erase speed is %ld KiB/s\n",
blocks, speed);
}
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 08/10] mtd-tests: flash_speed: Generalize read_eraseblock_by_2pages()
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (6 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 07/10] mtd-tests: flash_speed: Clarify the number of pages in each set while measuring Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 09/10] mtd-tests: flash_speed: Drop read_eraseblock_by_page() Miquel Raynal
` (2 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
Right now there are only 2 pages that may be read continuously, but why
not trying more? At least when the continuous feature is out, this type
of benchmarking will be interesting. In order to facilitate later
additions, lets make this helper more generic and accept a global
'npages' variable as parameter (because this function is called in a
macro, it is simpler like that).
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
tests/mtd-tests/flash_speed.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/tests/mtd-tests/flash_speed.c b/tests/mtd-tests/flash_speed.c
index f161d6e..6df0568 100644
--- a/tests/mtd-tests/flash_speed.c
+++ b/tests/mtd-tests/flash_speed.c
@@ -47,6 +47,7 @@ static const char *mtddev;
static libmtd_t mtd_desc;
static int fd;
+static int npages = 1;
static int peb=-1, count=-1, skip=-1, flags=0, speb=-1;
static struct timespec start, finish;
static int pgsize, pgcnt;
@@ -250,17 +251,17 @@ static int read_eraseblock_by_page(int ebnum)
return err;
}
-static int read_eraseblock_by_2pages(int ebnum)
+static int read_eraseblock_by_npages(int ebnum)
{
- int i, n = pgcnt / 2, err = 0;
- size_t sz = pgsize * 2;
+ int i, n = pgcnt / npages, err = 0;
+ size_t sz = pgsize * npages;
void *buf = iobuf;
for (i = 0; i < n; ++i) {
err = mtd_read(&mtd, fd, ebnum, i * sz, iobuf, sz);
if (err) {
- fprintf(stderr, "Error reading block %d, page %d + %d!\n",
- ebnum, i*2, i*2+1);
+ fprintf(stderr, "Error reading block %d, page [%d-%d]!\n",
+ ebnum, i*npages, (i*npages) + npages- 1);
return err;
}
buf += sz;
@@ -469,7 +470,8 @@ int main(int argc, char **argv)
/* Read all eraseblocks, 2 pages at a time */
puts("testing 2 page read speed");
- TIME_OP_PER_PEB(read_eraseblock_by_2pages, 2);
+ npages = 2;
+ TIME_OP_PER_PEB(read_eraseblock_by_npages, npages);
printf("2 page read speed is %ld KiB/s\n", speed);
/* Erase all eraseblocks */
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 09/10] mtd-tests: flash_speed: Drop read_eraseblock_by_page()
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (7 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 08/10] mtd-tests: flash_speed: Generalize read_eraseblock_by_2pages() Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 10/10] mtd-tests: flash_speed: Benchmark continuous reads Miquel Raynal
2024-10-08 7:00 ` [PATCH mtd-utils 00/10] New options for hardening continuous read support David Oberhollenzer
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
The read_eraseblock_by_2pages() has been generalized so it became
read_eraseblock_by_npages(), but there is no limitation (besides 0)
regarding the number of pages. Hence, drop the _by_page() helper and
replace it with the _by_npages(), using 'npages = 1'.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
tests/mtd-tests/flash_speed.c | 21 ++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/tests/mtd-tests/flash_speed.c b/tests/mtd-tests/flash_speed.c
index 6df0568..1064491 100644
--- a/tests/mtd-tests/flash_speed.c
+++ b/tests/mtd-tests/flash_speed.c
@@ -233,24 +233,6 @@ static int write_eraseblock_by_2pages(int ebnum)
return err;
}
-static int read_eraseblock_by_page(int ebnum)
-{
- void *buf = iobuf;
- int i, err = 0;
-
- for (i = 0; i < pgcnt; ++i) {
- err = mtd_read(&mtd, fd, ebnum, i * pgsize, iobuf, pgsize);
- if (err) {
- fprintf(stderr, "Error reading block %d, page %d!\n",
- ebnum, i);
- break;
- }
- buf += pgsize;
- }
-
- return err;
-}
-
static int read_eraseblock_by_npages(int ebnum)
{
int i, n = pgcnt / npages, err = 0;
@@ -454,7 +436,8 @@ int main(int argc, char **argv)
/* Read all eraseblocks, 1 page at a time */
puts("testing page read speed");
- TIME_OP_PER_PEB(read_eraseblock_by_page, 1);
+ npages = 1;
+ TIME_OP_PER_PEB(read_eraseblock_by_npages, npages);
printf("page read speed is %ld KiB/s\n", speed);
/* Write all eraseblocks, 2 pages at a time */
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH mtd-utils 10/10] mtd-tests: flash_speed: Benchmark continuous reads
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (8 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 09/10] mtd-tests: flash_speed: Drop read_eraseblock_by_page() Miquel Raynal
@ 2024-08-26 9:46 ` Miquel Raynal
2024-10-08 7:00 ` [PATCH mtd-utils 00/10] New options for hardening continuous read support David Oberhollenzer
10 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-08-26 9:46 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni, Miquel Raynal
Currently the read throuput test tries:
- 1 page
- 2 pages
- 1 block (64 or more pages, usually)
But it might be interesting to see how the speed gradually increases,
eg. testing all number of pages from 1 to maybe 16, and then
arbitrarilly 32 and 64.
Let's add a -C parameter to enable this additional test.
The 2-page read/write tests are also moved under this new option.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
tests/mtd-tests/flash_speed.c | 52 ++++++++++++++++++++++++-----------
1 file changed, 36 insertions(+), 16 deletions(-)
diff --git a/tests/mtd-tests/flash_speed.c b/tests/mtd-tests/flash_speed.c
index 1064491..11f396c 100644
--- a/tests/mtd-tests/flash_speed.c
+++ b/tests/mtd-tests/flash_speed.c
@@ -23,6 +23,7 @@
* Author: Adrian Hunter <adrian.hunter@nokia.com>
*/
#define DESTRUCTIVE 0x01
+#define CONTINOUS 0x02
#define PROGRAM_NAME "flash_speed"
@@ -49,6 +50,7 @@ static int fd;
static int npages = 1;
static int peb=-1, count=-1, skip=-1, flags=0, speb=-1;
+static bool continuous = false;
static struct timespec start, finish;
static int pgsize, pgcnt;
static int goodebcnt;
@@ -60,6 +62,7 @@ static const struct option options[] = {
{ "count", required_argument, NULL, 'c' },
{ "skip", required_argument, NULL, 's' },
{ "sec-peb", required_argument, NULL, 'k' },
+ { "continuous", no_argument, NULL, 'C' },
{ NULL, 0, NULL, 0 },
};
@@ -73,7 +76,8 @@ static NORETURN void usage(int status)
" -c, --count <num> Number of erase blocks to use (default: all)\n"
" -s, --skip <num> Number of blocks to skip\n"
" -d, --destructive Run destructive (erase and write speed) tests\n"
- " -k, --sec-peb <num> Start of secondary block to measure RWW latency (requires -d)\n",
+ " -k, --sec-peb <num> Start of secondary block to measure RWW latency (requires -d)\n"
+ " -C, --continuous Increase the number of consecutive pages gradually\n",
status==EXIT_SUCCESS ? stdout : stderr);
exit(status);
}
@@ -97,7 +101,7 @@ static void process_options(int argc, char **argv)
int c;
while (1) {
- c = getopt_long(argc, argv, "hb:c:s:dk:", options, NULL);
+ c = getopt_long(argc, argv, "hb:c:s:dk:C", options, NULL);
if (c == -1)
break;
@@ -137,6 +141,9 @@ static void process_options(int argc, char **argv)
if (speb < 0)
goto failarg;
break;
+ case 'C':
+ continuous = true;
+ break;
default:
exit(EXIT_FAILURE);
}
@@ -440,23 +447,36 @@ int main(int argc, char **argv)
TIME_OP_PER_PEB(read_eraseblock_by_npages, npages);
printf("page read speed is %ld KiB/s\n", speed);
- /* Write all eraseblocks, 2 pages at a time */
- if (flags & DESTRUCTIVE) {
- err = erase_good_eraseblocks(peb, count, skip);
- if (err)
- goto out;
+ if (continuous) {
+ /* Write all eraseblocks, 2 pages at a time */
+ if (flags & DESTRUCTIVE) {
+ err = erase_good_eraseblocks(peb, count, skip);
+ if (err)
+ goto out;
- puts("testing 2 page write speed");
- TIME_OP_PER_PEB(write_eraseblock_by_2pages, 2);
- printf("2 page write speed is %ld KiB/s\n", speed);
+ puts("testing 2 page write speed");
+ TIME_OP_PER_PEB(write_eraseblock_by_2pages, 2);
+ printf("2 page write speed is %ld KiB/s\n", speed);
+ }
+
+ /* Read all eraseblocks, N pages at a time */
+ puts("testing multiple pages read speed");
+ for (npages = 2; npages <= 16 && npages <= pgcnt; npages++) {
+ TIME_OP_PER_PEB(read_eraseblock_by_npages, npages);
+ printf("%d page read speed is %ld KiB/s\n", npages, speed);
+ }
+ if (pgcnt >= 32) {
+ npages = 32;
+ TIME_OP_PER_PEB(read_eraseblock_by_npages, npages);
+ printf("%d page read speed is %ld KiB/s\n", npages, speed);
+ }
+ if (pgcnt >= 64) {
+ npages = 64;
+ TIME_OP_PER_PEB(read_eraseblock_by_npages, npages);
+ printf("%d page read speed is %ld KiB/s\n", npages, speed);
+ }
}
- /* Read all eraseblocks, 2 pages at a time */
- puts("testing 2 page read speed");
- npages = 2;
- TIME_OP_PER_PEB(read_eraseblock_by_npages, npages);
- printf("2 page read speed is %ld KiB/s\n", speed);
-
/* Erase all eraseblocks */
if (flags & DESTRUCTIVE) {
puts("Testing erase speed");
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH mtd-utils 00/10] New options for hardening continuous read support
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
` (9 preceding siblings ...)
2024-08-26 9:46 ` [PATCH mtd-utils 10/10] mtd-tests: flash_speed: Benchmark continuous reads Miquel Raynal
@ 2024-10-08 7:00 ` David Oberhollenzer
2024-10-08 8:35 ` Miquel Raynal
10 siblings, 1 reply; 13+ messages in thread
From: David Oberhollenzer @ 2024-10-08 7:00 UTC (permalink / raw)
To: Miquel Raynal
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni
Applied to mtd-utils.git master.
Thanks,
David
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH mtd-utils 00/10] New options for hardening continuous read support
2024-10-08 7:00 ` [PATCH mtd-utils 00/10] New options for hardening continuous read support David Oberhollenzer
@ 2024-10-08 8:35 ` Miquel Raynal
0 siblings, 0 replies; 13+ messages in thread
From: Miquel Raynal @ 2024-10-08 8:35 UTC (permalink / raw)
To: David Oberhollenzer
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd, Julien Su, Alvin Zhou,
Thomas Petazzoni
Hi David,
david.oberhollenzer@sigma-star.at wrote on Tue, 8 Oct 2024 09:00:35
+0200:
> Applied to mtd-utils.git master.
Thanks!
I'll try to remember bumping the Buildroot packet later when you tag a
new version (it's not a request, I have my own setup for now anyway).
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2024-10-08 8:45 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-26 9:46 [PATCH mtd-utils 00/10] New options for hardening continuous read support Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 01/10] nand-utils: nanddump: Use a specific variable for the buffer size Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 02/10] nand-utils: nanddump: Explicitely use the page size when relevant Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 03/10] nand-utils: nanddump: Add support for testing continuous reads Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 04/10] mtd-tests: nandbiterrs: Store the chunks size in an intermediate variable Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 05/10] mtd-tests: nandbiterrs: Add support for testing continuous reads Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 06/10] mtd-tests: flash_speed: Drop an apparently useless block Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 07/10] mtd-tests: flash_speed: Clarify the number of pages in each set while measuring Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 08/10] mtd-tests: flash_speed: Generalize read_eraseblock_by_2pages() Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 09/10] mtd-tests: flash_speed: Drop read_eraseblock_by_page() Miquel Raynal
2024-08-26 9:46 ` [PATCH mtd-utils 10/10] mtd-tests: flash_speed: Benchmark continuous reads Miquel Raynal
2024-10-08 7:00 ` [PATCH mtd-utils 00/10] New options for hardening continuous read support David Oberhollenzer
2024-10-08 8:35 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox