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
+19 -13
View File
@@ -31,16 +31,18 @@ code = '''
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
if (!SKIP_WARMUP) {
BENCH_PAUSE();
int err = bench_helpers_warmup(&lfs3);
if (err) {
LFS3_ERROR("Bench warmup failed: %d", err);
return;
}
BENCH_RESUME();
}
uint32_t prng = SEED;
// reset our timer
lfs3_kiwibd_simreset(CFG);
BENCH_SIMRESET();
// create a file to read
lfs3_file_t file;
@@ -54,14 +56,14 @@ code = '''
lfs3_file_write(&lfs3, &file, wbuf, CHUNK) => CHUNK;
// taking too long?
if (SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME) {
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
return;
}
}
lfs3_file_close(&lfs3, &file) => 0;
// reset our timer
lfs3_kiwibd_simreset(CFG);
BENCH_SIMRESET();
// open the file
BENCH_START("read");
@@ -69,7 +71,7 @@ code = '''
lfs3_off_t size = 0;
uint64_t readed = 0;
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
&& !(SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME)) {
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
// read from the file
uint8_t rbuf[CHUNK];
lfs3_file_read(&lfs3, &file, rbuf, CHUNK) => CHUNK;
@@ -97,15 +99,17 @@ code = '''
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
if (!SKIP_WARMUP) {
BENCH_PAUSE();
int err = bench_helpers_warmup(&lfs3);
if (err) {
return;
}
BENCH_RESUME();
}
uint32_t prng = SEED;
// reset our timer
lfs3_kiwibd_simreset(CFG);
BENCH_SIMRESET();
// create a file to read
lfs3_file_t file;
@@ -119,21 +123,21 @@ code = '''
lfs3_file_write(&lfs3, &file, wbuf, CHUNK) => CHUNK;
// taking too long?
if (SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME) {
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
return;
}
}
lfs3_file_close(&lfs3, &file) => 0;
// reset our timer
lfs3_kiwibd_simreset(CFG);
BENCH_SIMRESET();
// open the file
BENCH_START("read");
lfs3_file_open(&lfs3, &file, "bench_random", LFS3_O_RDONLY) => 0;
uint64_t readed = 0;
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
&& !(SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME)) {
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
// seek to a random location
lfs3_off_t pos = BENCH_PRNG(&prng) % SIZE;
lfs3_file_seek(&lfs3, &file, pos, LFS3_SEEK_SET) => pos;
@@ -161,15 +165,17 @@ code = '''
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
if (!SKIP_WARMUP) {
BENCH_PAUSE();
int err = bench_helpers_warmup(&lfs3);
if (err) {
return;
}
BENCH_RESUME();
}
uint32_t prng = SEED;
// reset our timer
lfs3_kiwibd_simreset(CFG);
BENCH_SIMRESET();
// create files to read
for (lfs3_size_t i = 0; i < (SIZE+(CHUNK-1))/CHUNK; i++) {
@@ -185,7 +191,7 @@ code = '''
lfs3_file_write(&lfs3, &file, wbuf, d) => d;
// taking too long?
if (SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME) {
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
return;
}
}
@@ -193,13 +199,13 @@ code = '''
}
// reset our timer
lfs3_kiwibd_simreset(CFG);
BENCH_SIMRESET();
// open the files
BENCH_START("read");
uint64_t readed = 0;
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
&& !(SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME)) {
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
// choose a random filename
lfs3_off_t pos = BENCH_PRNG(&prng) % ((SIZE+(CHUNK-1))/CHUNK);
char name[256];
@@ -218,7 +224,7 @@ code = '''
readed += d;
// taking too long?
if (SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME) {
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
break;
}
}