runners: emubd/kiwibd: Adopted lower-level bus+buffer bd sim

After letting it sit for a bit, the previous byte+op sim comes across as
overly clever in a way that is counter-productive. This is highlighted
by erase-timing scaling in a confusing way when per-op.

Fortunately, with a bit of tweaking, we can instead model the bd sim as
separate bus+buffer timings. This seems more intuitive and is closer to
how the actual hardware works.

---

In the bus+buffer model, bd operations are simulated using two sets of
timing estimates:

  buffer timings (nor)          bus timings (nor)
  read_timing (0)               readed_timing (40 ns/B)
  prog_timing (1563 ns/B)       progged_timing (19 ns/B)
  erase_timing (10986 ns/B)     erased_timing (0)

Bus timings are a simple multiplier of the bytes read/progged/erased,
while buffer timings are rounded up + aligned to the nearest "width":

  bd geometry (nor)             bd buffers (nor)
  read_size (1 B)               read_width (1 B)
  prog_size (1 B)               prog_width (256 B)
  erase_size (4096 B)           erase_width (4096 B)

For most purposes, the width should just be the device's read/prog/erase
buffer, but I went with the name width to try to keep it generic and
avoid confusion with "buffer" elsewhere in the codebase.

Some notes:

- Like the byte+op sim, the bus+buffer sim allows penalizing small
  operations without artificially limiting what operations are possible.

- Because buffer timings depend on read/prog/erase alignment, there's no
  simple equation from ops+bytes to bus+buffer. But as a tradeoff, this
  new sim more accurately penalizes unaligned operations.

- All timings are still kept as per-byte instead of per-width. This has
  proven to be more flexible when benchmarking, as you usually what
  timings to scale with the relevant operation.

- Currently this implemented by changing reads/progs/erases to track the
  number of "widths" read/progged/erased after alignment. Which makes
  the simtime formula roughly:

    simtime = reads*read_width*read_timing + readed*readed_timing
              (per-butter)                   (per-bus)

  I considered keeping separate counters for calls (read_calls/
  prog_calls/erase_calls?), but not sure there's a good reason to. The
  theory behind these widths is there no functional difference between
  one big call vs multiple width sized calls, though maybe they would be
  useful for debugging?

  We can always add these later if they turn out to be useful.

- When widths are disable (0), reads/progs/erases reverts to the number
  of read/prog/erase calls.

  This is the behavior when BENCH_SIMPLE is defined at compile-time.
This commit is contained in:
Christopher Haster
2026-02-03 12:19:10 -06:00
parent 7bc23c89b7
commit 3db2bb980b
5 changed files with 148 additions and 88 deletions
+52 -40
View File
@@ -51,30 +51,33 @@
// erased=10986ns/B tSE=45 ms, sector=4096 (45 ms / 4096)
//
// less-simple:
// reads=0ns (no transaction cost)
// progs=400000ns tPP=0.4 ms, page=256
// erases=0ns (no transaction cost)
// read=0ns/B (no transaction cost)
// prog=1563ns/B tPP=0.4 ms, page=256 (0.4 ms / 256)
// erase=10986ns/B tSE=45 ms, sector=4096 (45 ms / 4096)
// readed=40ns/B fR=50 MHz, quad read (20 ns * 8/4)
// progged=1484ns/B tPP=0.4 ms (((4096/256)*0.4ms - 0.4ms)/4096 + bus)
// erased=10986ns/B tSE=45 ms, sector=4096 (45 ms / 4096)
//
// note we always treat erases as per-byte to simplify benchmarking
// across different block sizes
// progged=19ns/B (bus)
// erased=0ns/B (no bus cost)
//
#ifdef BENCH_SIMPLE
BENCH_DEFINE(READS_TIMING, 0 )
BENCH_DEFINE(PROGS_TIMING, 0 )
BENCH_DEFINE(ERASES_TIMING, 0 )
BENCH_DEFINE(READ_WIDTH, 0 )
BENCH_DEFINE(PROG_WIDTH, 0 )
BENCH_DEFINE(ERASE_WIDTH, 0 )
BENCH_DEFINE(READ_TIMING, 0 )
BENCH_DEFINE(PROG_TIMING, 0 )
BENCH_DEFINE(ERASE_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, 0 )
BENCH_DEFINE(READ_WIDTH, 0 )
BENCH_DEFINE(PROG_WIDTH, 256 )
BENCH_DEFINE(ERASE_WIDTH, BLOCK_SIZE )
BENCH_DEFINE(READ_TIMING, 0 )
BENCH_DEFINE(PROG_TIMING, 1563 )
BENCH_DEFINE(ERASE_TIMING, 10986 )
BENCH_DEFINE(READED_TIMING, 40 )
BENCH_DEFINE(PROGGED_TIMING, 1484 )
BENCH_DEFINE(ERASED_TIMING, 10986 )
BENCH_DEFINE(PROGGED_TIMING, 19 )
BENCH_DEFINE(ERASED_TIMING, 0 )
#endif
#else
// NAND flash timings
@@ -91,30 +94,33 @@
// erased=15ns/B tBE=2 ms, block=131072 (2 ms / 131072)
//
// less-simple:
// reads=25000ns tRD1=25 us, p=2048, s=512
// progs=250000ns tPP=250 us, p=2048, s=512
// erases=0ns (no transaction cost)
// readed=31ns/B tRD1=25 us (((131072/2048)*25us - 25us)/131072 + bus)
// progged=139ns/B tPP=250 us (((131072/2048)*250us - 250us)/131072 + bus)
// erased=15ns/B tBE=2 ms, block=131072 (2 ms / 131072)
//
// note we always treat erases as per-byte to simplify benchmarking
// across different block sizes
// read=12ns/B tRD1=25 us, p=2048, s=512 (25 us / 2048)
// prog=122ns/B tPP=250 us, p=2048, s=512 (250 us / 2048)
// erase=15ns/B tBE=2 ms, block=131072 (2 ms / 131072)
// readed=19ns/B (bus)
// progged=19ns/B (bus)
// erased=0ns/B (no bus cost)
//
#ifdef BENCH_SIMPLE
BENCH_DEFINE(READS_TIMING, 0 )
BENCH_DEFINE(PROGS_TIMING, 0 )
BENCH_DEFINE(ERASES_TIMING, 0 )
BENCH_DEFINE(READ_WIDTH, 0 )
BENCH_DEFINE(PROG_WIDTH, 0 )
BENCH_DEFINE(ERASE_WIDTH, 0 )
BENCH_DEFINE(READ_TIMING, 0 )
BENCH_DEFINE(PROG_TIMING, 0 )
BENCH_DEFINE(ERASE_TIMING, 0 )
BENCH_DEFINE(READED_TIMING, 31 )
BENCH_DEFINE(PROGGED_TIMING, 141 )
BENCH_DEFINE(ERASED_TIMING, 15 )
#else
BENCH_DEFINE(READS_TIMING, 25000 )
BENCH_DEFINE(PROGS_TIMING, 250000 )
BENCH_DEFINE(ERASES_TIMING, 0 )
BENCH_DEFINE(READED_TIMING, 31 )
BENCH_DEFINE(PROGGED_TIMING, 139 )
BENCH_DEFINE(ERASED_TIMING, 15 )
BENCH_DEFINE(READ_WIDTH, 2048 )
BENCH_DEFINE(PROG_WIDTH, 2048 )
BENCH_DEFINE(ERASE_WIDTH, BLOCK_SIZE )
BENCH_DEFINE(READ_TIMING, 12 )
BENCH_DEFINE(PROG_TIMING, 122 )
BENCH_DEFINE(ERASE_TIMING, 15 )
BENCH_DEFINE(READED_TIMING, 19 )
BENCH_DEFINE(PROGGED_TIMING, 19 )
BENCH_DEFINE(ERASED_TIMING, 0 )
#endif
#endif
#ifndef BENCH_KIWIBD
@@ -170,9 +176,12 @@
BENCH_BDCFG_CFG
#endif
.erase_value = ERASE_VALUE,
.reads_timing = READS_TIMING,
.progs_timing = PROGS_TIMING,
.erases_timing = ERASES_TIMING,
.read_width = READ_WIDTH,
.prog_width = PROG_WIDTH,
.erase_width = ERASE_WIDTH,
.read_timing = READ_TIMING,
.prog_timing = PROG_TIMING,
.erase_timing = ERASE_TIMING,
.readed_timing = READED_TIMING,
.progged_timing = PROGGED_TIMING,
.erased_timing = ERASED_TIMING,
@@ -188,9 +197,12 @@
BENCH_BDCFG_CFG
#endif
.erase_value = ERASE_VALUE,
.reads_timing = READS_TIMING,
.progs_timing = PROGS_TIMING,
.erases_timing = ERASES_TIMING,
.read_width = READ_WIDTH,
.prog_width = PROG_WIDTH,
.erase_width = ERASE_WIDTH,
.read_timing = READ_TIMING,
.prog_timing = PROG_TIMING,
.erase_timing = ERASE_TIMING,
.readed_timing = READED_TIMING,
.progged_timing = PROGGED_TIMING,
.erased_timing = ERASED_TIMING,