runners: emubd/kiwibd: Adopted emulated simtime API
This is based on some work in external benchmarks. What's worked well
there is emulating a global simtime based on per-byte estimates.
This moves the emulated simtime into emubd/kiwibd, and extends the idea
with both per-byte and per-op timing estimates for hopefully more
realistic results.
---
The problem is how NAND flash reads work.
Per-byte timing estimates are surprisingly accurate for NOR flash. There
is some overhead for sending the address, but it's mostly dominated by
bus cost (~20ns/B [1]).
NAND flash, on the otherhand, technically does support byte-level reads,
but first needs to read into 2KiB buffer. Surprisingly, these are pretty
close in cost (~19ns/B bus [2] vs ~12ns/B buffer [2]).
This close-ness makes modeling NAND flash difficult. If we set
read_size=1, we risk hiding the cost of small reads, which littlefs3 is
full of (rbyd lookups). If we set read_size=2048, we unfairly penalize
littlefs3 for the same reason.
---
The solution here is to expose both per-byte and per-op timing
estimates. This lets you model NAND reads using two data points:
^
| realtime --> ...............o
| : .....'''' :
| ...............:'''' ^ :
| :....''''' | :
| ..........:::::: simtime :
| .....:'''' :
|o....:::::.....: :
|: :
|: :
+:-----------------------------------------------------------:>
min read max read
Where:
bus_timing = 19ns
buffer_timing = 25us
buffer_size = 2KiB
erase_size = 128KiB
min_read = buffer_timing
max_read = (erase_size/buffer_size)*buffer_timing - buffer_timing
read_timing = min_read
readed_timing = ((max_read - min_read)/erase_size) + bus_timing
simtime = reads*read_timing + readed*readed_timing
(per-op) (per-byte)
This should correctly penalize small reads without complicating
emubd/kiwibd too much.
That's the idea anyways! It will take some use to understand if this is
a reasonable approach.
As a plus, this is a superset of the per-byte model, so both can be used
for realistic vs idealistic simulations (and to test the bus+buffer
model itself).
1: https://www.winbond.com/resource-files/W25Q256JV%20SPI%20RevQ%2002072025%20Plus.pdf
2: https://www.winbond.com/resource-files/W25N01GV%20Rev%20R%20070323.pdf
This commit is contained in:
+24
-24
@@ -1493,7 +1493,7 @@ code = '''
|
||||
(lfs3_size_t)BADBLOCK, badbit/8, badbit, badbit/8, badbit%8);
|
||||
|
||||
// mark our badbit as bad
|
||||
lfs3_emubd_markbadbit(CFG, BADBLOCK, badbit) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, BADBLOCK, badbit) => 0;
|
||||
|
||||
// formatting the filesystem may already find the bit error
|
||||
lfs3_t lfs3;
|
||||
@@ -1552,7 +1552,7 @@ code = '''
|
||||
|
||||
corrupt:;
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, BADBLOCK) => 0;
|
||||
lfs3_emubd_mkgood(CFG, BADBLOCK) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -1610,7 +1610,7 @@ code = '''
|
||||
badblock, badbit/8, badbit, badbit/8, badbit%8);
|
||||
|
||||
// mark our badbit as bad
|
||||
lfs3_emubd_markbadbit(CFG, badblock, badbit) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, badblock, badbit) => 0;
|
||||
|
||||
// format
|
||||
lfs3_t lfs3;
|
||||
@@ -1660,7 +1660,7 @@ code = '''
|
||||
lfs3_unmount(&lfs3) => 0;
|
||||
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkgood(CFG, badblock) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -1721,7 +1721,7 @@ code = '''
|
||||
badblock, badbit/8, badbit, badbit/8, badbit%8);
|
||||
|
||||
// mark our badbit as bad
|
||||
lfs3_emubd_markbadbit(CFG, badblock, badbit) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, badblock, badbit) => 0;
|
||||
|
||||
// format
|
||||
lfs3_t lfs3;
|
||||
@@ -1771,7 +1771,7 @@ code = '''
|
||||
lfs3_unmount(&lfs3) => 0;
|
||||
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkgood(CFG, badblock) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -1816,8 +1816,8 @@ code = '''
|
||||
badbit_/8, badbit_%8);
|
||||
|
||||
// mark our badbits as bad
|
||||
lfs3_emubd_markbadbit(CFG, BADBLOCK, badbit) => 0;
|
||||
lfs3_emubd_markbadbit(CFG, BADBLOCK_, badbit_) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, BADBLOCK, badbit) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, BADBLOCK_, badbit_) => 0;
|
||||
|
||||
// keep track of open files so we clean up correctly
|
||||
lfs3_file_t files[N];
|
||||
@@ -1980,8 +1980,8 @@ code = '''
|
||||
|
||||
corrupt:;
|
||||
// reset badbits
|
||||
lfs3_emubd_markgood(CFG, BADBLOCK) => 0;
|
||||
lfs3_emubd_markgood(CFG, BADBLOCK_) => 0;
|
||||
lfs3_emubd_mkgood(CFG, BADBLOCK) => 0;
|
||||
lfs3_emubd_mkgood(CFG, BADBLOCK_) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -2063,7 +2063,7 @@ code = '''
|
||||
|
||||
corrupt:;
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, BADBLOCK) => 0;
|
||||
lfs3_emubd_mkgood(CFG, BADBLOCK) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -2171,7 +2171,7 @@ code = '''
|
||||
lfs3_unmount(&lfs3) => 0;
|
||||
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkgood(CFG, badblock) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -2282,7 +2282,7 @@ code = '''
|
||||
lfs3_unmount(&lfs3) => 0;
|
||||
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkgood(CFG, badblock) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -2346,7 +2346,7 @@ code = '''
|
||||
(lfs3_size_t)BADBLOCK, badbit/8, badbit, badbit/8, badbit%8);
|
||||
|
||||
// mark our badbit as bad
|
||||
lfs3_emubd_markbadbit(CFG, BADBLOCK, badbit) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, BADBLOCK, badbit) => 0;
|
||||
|
||||
// With metastability, basically any filesystem operation can
|
||||
// return LFS3_ERR_CORRUPT. This is ok, what we're really testing
|
||||
@@ -2430,7 +2430,7 @@ code = '''
|
||||
|
||||
corrupt:;
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, BADBLOCK) => 0;
|
||||
lfs3_emubd_mkgood(CFG, BADBLOCK) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -2504,7 +2504,7 @@ code = '''
|
||||
badblock, badbit/8, badbit, badbit/8, badbit%8);
|
||||
|
||||
// mark our badbit as bad
|
||||
lfs3_emubd_markbadbit(CFG, badblock, badbit) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, badblock, badbit) => 0;
|
||||
|
||||
// With metastability, basically any filesystem operation can
|
||||
// return LFS3_ERR_CORRUPT. This is ok, what we're really testing
|
||||
@@ -2573,7 +2573,7 @@ code = '''
|
||||
lfs3_unmount(&lfs3) => 0;
|
||||
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkgood(CFG, badblock) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -2641,7 +2641,7 @@ code = '''
|
||||
badblock, badbit/8, badbit, badbit/8, badbit%8);
|
||||
|
||||
// mark our badbit as bad
|
||||
lfs3_emubd_markbadbit(CFG, badblock, badbit) => 0;
|
||||
lfs3_emubd_mkbadbit(CFG, badblock, badbit) => 0;
|
||||
|
||||
// With metastability, basically any filesystem operation can
|
||||
// return LFS3_ERR_CORRUPT. This is ok, what we're really testing
|
||||
@@ -2710,7 +2710,7 @@ code = '''
|
||||
lfs3_unmount(&lfs3) => 0;
|
||||
|
||||
// reset badbit
|
||||
lfs3_emubd_markgood(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkgood(CFG, badblock) => 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -2818,7 +2818,7 @@ code = '''
|
||||
// bit differently
|
||||
|
||||
// mark our badblock as bad
|
||||
lfs3_emubd_markbad(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkbad(CFG, badblock) => 0;
|
||||
|
||||
// manually flipping? flip all badbits in badblocks
|
||||
if (BADBLOCK_BEHAVIOR == LFS3_EMUBD_BADBLOCK_MANUAL) {
|
||||
@@ -3136,7 +3136,7 @@ code = '''
|
||||
// bit differently
|
||||
|
||||
// mark our badblock as bad
|
||||
lfs3_emubd_markbad(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkbad(CFG, badblock) => 0;
|
||||
|
||||
// manually flipping? flip all badbits in badblocks
|
||||
if (BADBLOCK_BEHAVIOR == LFS3_EMUBD_BADBLOCK_MANUAL) {
|
||||
@@ -3552,7 +3552,7 @@ code = '''
|
||||
// bit differently
|
||||
|
||||
// mark our badblock as bad
|
||||
lfs3_emubd_markbad(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkbad(CFG, badblock) => 0;
|
||||
|
||||
// manually flipping? flip all badbits in badblocks
|
||||
if (BADBLOCK_BEHAVIOR == LFS3_EMUBD_BADBLOCK_MANUAL) {
|
||||
@@ -3837,7 +3837,7 @@ code = '''
|
||||
// bit differently
|
||||
|
||||
// mark our badblock as bad
|
||||
lfs3_emubd_markbad(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkbad(CFG, badblock) => 0;
|
||||
|
||||
// manually flipping? flip all badbits in badblocks
|
||||
if (BADBLOCK_BEHAVIOR == LFS3_EMUBD_BADBLOCK_MANUAL) {
|
||||
@@ -4441,7 +4441,7 @@ code = '''
|
||||
// bit differently
|
||||
|
||||
// mark our badblock as bad
|
||||
lfs3_emubd_markbad(CFG, badblock) => 0;
|
||||
lfs3_emubd_mkbad(CFG, badblock) => 0;
|
||||
|
||||
// manually flipping? flip all badbits in badblocks
|
||||
if (BADBLOCK_BEHAVIOR == LFS3_EMUBD_BADBLOCK_MANUAL) {
|
||||
|
||||
Reference in New Issue
Block a user