runners: bench: Added BENCH_SIMTIME/SIMRESET/PAUSE/RESUME/etc

- BENCH_SIMTIME()   => lfs3_kiwibd_simtime()
- BENCH_SIMRESET()  => lfs3_kiwibd_simreset()
- BENCH_SIMPAUSE()  => lfs3_kiwibd_simpause()
- BENCH_SIMRESUME() => lfs3_kiwibd_simresume()
- BENCH_RESET()     => lfs3_kiwibd_simreset() + BENCH_STACK/HEAP_RESET()
- BENCH_PAUSE()     => lfs3_kiwibd_simpause() + BENCH_STACK/HEAP_PAUSE()
- BENCH_RESUME()    => lfs3_kiwibd_simresume() + BENCH_STACK/HEAP_RESUME()

This does two things:

1. Adds pause/resume counters to bd counters to make it easier to
   exclude operations from the current bench (potentially useful for
   seq+disk usage).

2. Exposes bd simtime operations as BENCH_* macros, to make it a bit
   easier to interact with simtime without tying all the benches to
   kiwibd. (Not that we'll ever probably not use kiwibd, but still).

Also adopted 32-bit counters for stack/heap pause state instead of a
32-bit stack. Not that either are at a risk of overflowing, but better
safe than sorry.
This commit is contained in:
Christopher Haster
2026-02-07 20:02:26 -06:00
parent f62d91c9b5
commit 10e77d9177
12 changed files with 325 additions and 119 deletions
+41 -12
View File
@@ -217,6 +217,7 @@ int lfs3_emubd_createcfg(const struct lfs3_cfg *cfg, const char *path,
// setup testing things
bd->blocks = NULL;
bd->paused = false;
bd->reads = 0;
bd->progs = 0;
bd->erases = 0;
@@ -437,10 +438,14 @@ int lfs3_emubd_read(const struct lfs3_cfg *cfg, lfs3_block_t block,
}
// track reads
bd->reads += (lfs3_alignup(off + size, lfs3_max(bd->cfg->read_width, 1))
- lfs3_aligndown(off, lfs3_max(bd->cfg->read_width, 1)))
/ lfs3_max(bd->cfg->read_width, 1);
bd->readed += size;
if (!bd->paused) {
bd->reads += (lfs3_alignup(off + size,
lfs3_max(bd->cfg->read_width, 1))
- lfs3_aligndown(off,
lfs3_max(bd->cfg->read_width, 1)))
/ lfs3_max(bd->cfg->read_width, 1);
bd->readed += size;
}
if (bd->cfg->read_sleep) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->read_sleep/1000000000,
@@ -751,10 +756,14 @@ progged:;
}
// track progs
bd->progs += (lfs3_alignup(off + size, lfs3_max(bd->cfg->prog_width, 1))
- lfs3_aligndown(off, lfs3_max(bd->cfg->prog_width, 1)))
/ lfs3_max(bd->cfg->prog_width, 1);
bd->progged += size;
if (!bd->paused) {
bd->progs += (lfs3_alignup(off + size,
lfs3_max(bd->cfg->prog_width, 1))
- lfs3_aligndown(off,
lfs3_max(bd->cfg->prog_width, 1)))
/ lfs3_max(bd->cfg->prog_width, 1);
bd->progged += size;
}
if (bd->cfg->prog_sleep) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->prog_sleep/1000000000,
@@ -1049,10 +1058,12 @@ int lfs3_emubd_erase(const struct lfs3_cfg *cfg, lfs3_block_t block) {
erased:;
// track erases
bd->erases += lfs3_alignup(cfg->block_size,
lfs3_max(bd->cfg->erase_width, 1))
/ lfs3_max(bd->cfg->erase_width, 1);
bd->erased += cfg->block_size;
if (!bd->paused) {
bd->erases += lfs3_alignup(cfg->block_size,
lfs3_max(bd->cfg->erase_width, 1))
/ lfs3_max(bd->cfg->erase_width, 1);
bd->erased += cfg->block_size;
}
if (bd->cfg->erase_sleep) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->erase_sleep/1000000000,
@@ -1128,6 +1139,23 @@ int lfs3_emubd_simreset(const struct lfs3_cfg *cfg) {
return 0;
}
int lfs3_emubd_simpause(const struct lfs3_cfg *cfg) {
LFS3_EMUBD_TRACE("lfs3_emubd_simpause(%p)", (void*)cfg);
lfs3_emubd_t *bd = cfg->context;
bd->paused += 1;
LFS3_EMUBD_TRACE("lfs3_emubd_simpause -> %d", 0);
return 0;
}
int lfs3_emubd_simresume(const struct lfs3_cfg *cfg) {
LFS3_EMUBD_TRACE("lfs3_emubd_simresume(%p)", (void*)cfg);
lfs3_emubd_t *bd = cfg->context;
LFS3_ASSERT(bd->paused);
bd->paused -= 1;
LFS3_EMUBD_TRACE("lfs3_emubd_simresume -> %d", 0);
return 0;
}
lfs3_emubd_sio_t lfs3_emubd_reads(const struct lfs3_cfg *cfg) {
LFS3_EMUBD_TRACE("lfs3_emubd_reads(%p)", (void*)cfg);
lfs3_emubd_t *bd = cfg->context;
@@ -1519,6 +1547,7 @@ int lfs3_emubd_cpy(const struct lfs3_cfg *cfg, lfs3_emubd_t *copy) {
}
// other state
copy->paused = bd->paused;
copy->reads = bd->reads;
copy->progs = bd->progs;
copy->erases = bd->erases;
+11 -1
View File
@@ -179,13 +179,17 @@ typedef struct lfs3_emubd {
// array of copy-on-write blocks
lfs3_emubd_block_t **blocks;
// some other test state
// sim state
uint32_t paused;
// amount read/progged/erased
lfs3_emubd_io_t reads;
lfs3_emubd_io_t progs;
lfs3_emubd_io_t erases;
lfs3_emubd_io_t readed;
lfs3_emubd_io_t progged;
lfs3_emubd_io_t erased;
// some other test state
uint32_t prng;
lfs3_emubd_powercycles_t power_cycles;
lfs3_emubd_block_t **ooo_before;
@@ -239,6 +243,12 @@ lfs3_emubd_sns_t lfs3_emubd_simtime(const struct lfs3_cfg *cfg);
// Reset simulation counters
int lfs3_emubd_simreset(const struct lfs3_cfg *cfg);
// Pause simulation counters
int lfs3_emubd_simpause(const struct lfs3_cfg *cfg);
// Resume simulation counters
int lfs3_emubd_simresume(const struct lfs3_cfg *cfg);
// Get total number of read transactions
lfs3_emubd_sio_t lfs3_emubd_reads(const struct lfs3_cfg *cfg);
+40 -12
View File
@@ -117,6 +117,7 @@ int lfs3_kiwibd_createcfg(const struct lfs3_cfg *cfg, const char *path,
bd->cfg = bdcfg;
// setup some initial state
bd->paused = false;
bd->reads = 0;
bd->progs = 0;
bd->erases = 0;
@@ -279,10 +280,14 @@ int lfs3_kiwibd_read(const struct lfs3_cfg *cfg, lfs3_block_t block,
}
// track reads
bd->reads += (lfs3_alignup(off + size, lfs3_max(bd->cfg->read_width, 1))
- lfs3_aligndown(off, lfs3_max(bd->cfg->read_width, 1)))
/ lfs3_max(bd->cfg->read_width, 1);
bd->readed += size;
if (!bd->paused) {
bd->reads += (lfs3_alignup(off + size,
lfs3_max(bd->cfg->read_width, 1))
- lfs3_aligndown(off,
lfs3_max(bd->cfg->read_width, 1)))
/ lfs3_max(bd->cfg->read_width, 1);
bd->readed += size;
}
if (bd->cfg->read_sleep) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->read_sleep/1000000000,
@@ -410,10 +415,14 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
}
// track progs
bd->progs += (lfs3_alignup(off + size, lfs3_max(bd->cfg->prog_width, 1))
- lfs3_aligndown(off, lfs3_max(bd->cfg->prog_width, 1)))
/ lfs3_max(bd->cfg->prog_width, 1);
bd->progged += size;
if (!bd->paused) {
bd->progs += (lfs3_alignup(off + size,
lfs3_max(bd->cfg->prog_width, 1))
- lfs3_aligndown(off,
lfs3_max(bd->cfg->prog_width, 1)))
/ lfs3_max(bd->cfg->prog_width, 1);
bd->progged += size;
}
if (bd->cfg->prog_sleep) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->prog_sleep/1000000000,
@@ -474,10 +483,12 @@ int lfs3_kiwibd_erase(const struct lfs3_cfg *cfg, lfs3_block_t block) {
erased:;
// track erases
bd->erases += lfs3_alignup(cfg->block_size,
lfs3_max(bd->cfg->erase_width, 1))
/ lfs3_max(bd->cfg->erase_width, 1);
bd->erased += cfg->block_size;
if (!bd->paused) {
bd->erases += lfs3_alignup(cfg->block_size,
lfs3_max(bd->cfg->erase_width, 1))
/ lfs3_max(bd->cfg->erase_width, 1);
bd->erased += cfg->block_size;
}
if (bd->cfg->erase_sleep) {
int err = nanosleep(&(struct timespec){
.tv_sec=bd->cfg->erase_sleep/1000000000,
@@ -553,6 +564,23 @@ int lfs3_kiwibd_simreset(const struct lfs3_cfg *cfg) {
return 0;
}
int lfs3_kiwibd_simpause(const struct lfs3_cfg *cfg) {
LFS3_KIWIBD_TRACE("lfs3_kiwibd_simpause(%p)", (void*)cfg);
lfs3_kiwibd_t *bd = cfg->context;
bd->paused += 1;
LFS3_KIWIBD_TRACE("lfs3_kiwibd_simpause -> %d", 0);
return 0;
}
int lfs3_kiwibd_simresume(const struct lfs3_cfg *cfg) {
LFS3_KIWIBD_TRACE("lfs3_kiwibd_simresume(%p)", (void*)cfg);
lfs3_kiwibd_t *bd = cfg->context;
LFS3_ASSERT(bd->paused);
bd->paused -= 1;
LFS3_KIWIBD_TRACE("lfs3_kiwibd_simresume -> %d", 0);
return 0;
}
lfs3_kiwibd_sio_t lfs3_kiwibd_reads(const struct lfs3_cfg *cfg) {
LFS3_KIWIBD_TRACE("lfs3_kiwibd_reads(%p)", (void*)cfg);
lfs3_kiwibd_t *bd = cfg->context;
+8
View File
@@ -107,6 +107,8 @@ typedef struct lfs3_kiwibd {
uint8_t *mem;
} u;
// sim state
uint32_t paused;
// amount read/progged/erased
lfs3_kiwibd_io_t reads;
lfs3_kiwibd_io_t progs;
@@ -161,6 +163,12 @@ lfs3_kiwibd_sns_t lfs3_kiwibd_simtime(const struct lfs3_cfg *cfg);
// Reset simulation counters
int lfs3_kiwibd_simreset(const struct lfs3_cfg *cfg);
// Pause simulation counters
int lfs3_kiwibd_simpause(const struct lfs3_cfg *cfg);
// Resume simulation counters
int lfs3_kiwibd_simresume(const struct lfs3_cfg *cfg);
// Get total number of read transactions
lfs3_kiwibd_sio_t lfs3_kiwibd_reads(const struct lfs3_cfg *cfg);