d3dd927de3
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
116 lines
6.4 KiB
C
116 lines
6.4 KiB
C
// littlefs bench runner defines
|
|
|
|
|
|
// preconfigured defines that control how benches run
|
|
#ifdef BENCH_DEFINE
|
|
// name value (overridable)
|
|
BENCH_DEFINE(READ_SIZE, 1 )
|
|
BENCH_DEFINE(PROG_SIZE, 1 )
|
|
BENCH_DEFINE(BLOCK_SIZE, 4096 )
|
|
BENCH_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE )
|
|
BENCH_DEFINE(DISK_SIZE, 1024*1024 )
|
|
BENCH_DEFINE(BLOCK_RECYCLES, -1 )
|
|
BENCH_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) )
|
|
BENCH_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) )
|
|
BENCH_DEFINE(FCACHE_SIZE, 16 )
|
|
BENCH_DEFINE(LOOKAHEAD_SIZE, 16 )
|
|
BENCH_DEFINE(GC_FLAGS, LFS3_GC_GC )
|
|
BENCH_DEFINE(GC_STEPS, 0 )
|
|
BENCH_DEFINE(GC_LOOKAHEAD_THRESH, -1 )
|
|
BENCH_DEFINE(GC_LOOKGBMAP_THRESH, -1 )
|
|
BENCH_DEFINE(GC_PREERASE_COUNT, -1 )
|
|
BENCH_DEFINE(GC_COMPACT_THRESH, 0 )
|
|
BENCH_DEFINE(SHRUB_SIZE, BLOCK_SIZE/4 )
|
|
BENCH_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) )
|
|
BENCH_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 )
|
|
BENCH_DEFINE(LOOKGBMAP_THRESH, BLOCK_COUNT/4 )
|
|
BENCH_DEFINE(ERASE_VALUE, 0xff )
|
|
// the default timings here are based on NOR flash, specifically
|
|
// w25q64jv:
|
|
//
|
|
// https://www.winbond.com/resource-files/W25Q256JV%20SPI%20RevQ%2002072025%20Plus.pdf
|
|
//
|
|
// note one thing unique to NOR flash is the extreme erase cost
|
|
//
|
|
// FR=104 MHz, quad prog (9.6 ns * 8/4)
|
|
// => +~19 ns for bus (not read!)
|
|
//
|
|
// readed=40ns/B fR=50 MHz, quad read (20 ns * 8/4)
|
|
// progged=1582ns/B tPP=0.4 ms, page=256 (0.4 ms / 256 + bus)
|
|
// erased=10986ns/B tSE=45 ms, sector=4096 (45 ms / 4096)
|
|
//
|
|
// reads=0ns (no transaction cost)
|
|
// progs=400000ns tPP=0.4 ms, page=256
|
|
// erases=45000000ns tSE=45 ms, sector=4096
|
|
// readed=40ns/B fR=50 MHz, quad read (20 ns * 8/4)
|
|
// progged=1484ns/B tPP=0.4 ms (((4096/256)*0.4 ms - 0.4 ms)/4096 + bus)
|
|
// erased=0ns/B (no per-byte cost)
|
|
//
|
|
#ifdef BENCH_SIMPLE
|
|
BENCH_DEFINE(READS_TIMING, 0 )
|
|
BENCH_DEFINE(PROGS_TIMING, 0 )
|
|
BENCH_DEFINE(ERASES_TIMING, 0 )
|
|
BENCH_DEFINE(READED_TIMING, 40 )
|
|
BENCH_DEFINE(PROGGED_TIMING, 1582 )
|
|
BENCH_DEFINE(ERASED_TIMING, 10986 )
|
|
#else
|
|
BENCH_DEFINE(READS_TIMING, 0 )
|
|
BENCH_DEFINE(PROGS_TIMING, 400000 )
|
|
BENCH_DEFINE(ERASES_TIMING, 45000000 )
|
|
BENCH_DEFINE(READED_TIMING, 40 )
|
|
BENCH_DEFINE(PROGGED_TIMING, 1484 )
|
|
BENCH_DEFINE(ERASED_TIMING, 0 )
|
|
#endif
|
|
BENCH_DEFINE(ERASE_CYCLES, 0 )
|
|
BENCH_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR )
|
|
BENCH_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC )
|
|
BENCH_DEFINE(EMUBD_SEED, 0 )
|
|
#endif
|
|
|
|
|
|
// struct lfs3_cfg fields
|
|
#ifdef BENCH_CFG
|
|
BENCH_CFG(read_size, READ_SIZE )
|
|
BENCH_CFG(prog_size, PROG_SIZE )
|
|
BENCH_CFG(block_size, BLOCK_SIZE )
|
|
BENCH_CFG(block_count, BLOCK_COUNT )
|
|
BENCH_CFG(block_recycles, BLOCK_RECYCLES )
|
|
BENCH_CFG(rcache_size, RCACHE_SIZE )
|
|
BENCH_CFG(pcache_size, PCACHE_SIZE )
|
|
BENCH_CFG(fcache_size, FCACHE_SIZE )
|
|
BENCH_CFG(lookahead_size, LOOKAHEAD_SIZE )
|
|
#ifdef LFS3_GBMAP
|
|
BENCH_CFG(gc_lookgbmap_thresh, GC_LOOKGBMAP_THRESH )
|
|
BENCH_CFG(lookgbmap_thresh, LOOKGBMAP_THRESH )
|
|
#endif
|
|
#ifdef LFS3_PREERASE
|
|
BENCH_CFG(gc_preerase_count, GC_PREERASE_COUNT )
|
|
#endif
|
|
#ifdef LFS3_GC
|
|
BENCH_CFG(gc_flags, GC_FLAGS )
|
|
BENCH_CFG(gc_steps, GC_STEPS )
|
|
#endif
|
|
BENCH_CFG(gc_lookahead_thresh, GC_LOOKAHEAD_THRESH )
|
|
BENCH_CFG(gc_compact_thresh, GC_COMPACT_THRESH )
|
|
BENCH_CFG(shrub_size, SHRUB_SIZE )
|
|
BENCH_CFG(fragment_size, FRAGMENT_SIZE )
|
|
BENCH_CFG(crystal_thresh, CRYSTAL_THRESH )
|
|
#endif
|
|
|
|
|
|
// struct lfs3_*bd_cfg fields
|
|
#ifdef BENCH_BDCFG
|
|
BENCH_BDCFG(erase_value, ERASE_VALUE )
|
|
BENCH_BDCFG(reads_timing, READS_TIMING )
|
|
BENCH_BDCFG(progs_timing, PROGS_TIMING )
|
|
BENCH_BDCFG(erases_timing, ERASES_TIMING )
|
|
BENCH_BDCFG(readed_timing, READED_TIMING )
|
|
BENCH_BDCFG(progged_timing, PROGGED_TIMING )
|
|
BENCH_BDCFG(erased_timing, ERASED_TIMING )
|
|
BENCH_BDCFG(erase_cycles, ERASE_CYCLES )
|
|
BENCH_BDCFG(badblock_behavior, BADBLOCK_BEHAVIOR )
|
|
BENCH_BDCFG(powerloss_behavior, POWERLOSS_BEHAVIOR )
|
|
BENCH_BDCFG(seed, EMUBD_SEED )
|
|
#endif
|
|
|