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
-12
View File
@@ -10,9 +10,6 @@
// this writes a 1 block file 2*block_count times to get it into a good
// state for benchmarking
int bench_helpers_warmup(lfs3_t *lfs3) {
BENCH_STACK_PAUSE();
BENCH_HEAP_PAUSE();
uint8_t *wbuf = malloc(BLOCK_SIZE);
memset(wbuf, '1', BLOCK_SIZE);
@@ -29,18 +26,12 @@ int bench_helpers_warmup(lfs3_t *lfs3) {
lfs3_remove(lfs3, "warmup") => 0;
free(wbuf);
BENCH_HEAP_RESUME();
BENCH_STACK_RESUME();
return 0;
}
// find tight disk usage
uintmax_t bench_helpers_usage(lfs3_t *lfs3) {
BENCH_STACK_PAUSE();
BENCH_HEAP_PAUSE();
// measure disk usage
//
// littlefs can be a dag, so build a bitmap to find the exact
@@ -70,9 +61,6 @@ uintmax_t bench_helpers_usage(lfs3_t *lfs3) {
}
free(usage_bmap);
BENCH_HEAP_RESUME();
BENCH_STACK_RESUME();
return (uintmax_t)usage * (uintmax_t)BLOCK_SIZE;
}
+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;
}
}
+17 -9
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();
// open a file
BENCH_START("write");
@@ -52,7 +54,7 @@ code = '''
// ok, one of these needs to be non-zero
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
&& !(SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME)) {
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
// arguably we should just rewind and continue writing to the
// front of the file when we hit the end, but this overly
// penalizes littlefs2, so instead we truncate
@@ -100,15 +102,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();
// open a file
BENCH_START("write");
@@ -118,7 +122,7 @@ code = '''
lfs3_off_t size = 0;
uint64_t written = 0;
while (!(SIM_SIZE && written >= (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;
@@ -164,15 +168,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();
// open a file
BENCH_START("write");
@@ -183,7 +189,7 @@ code = '''
// ok, one of these needs to be non-zero
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
&& !(SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME)) {
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
// append to log
uint8_t wbuf[CHUNK];
for (lfs3_size_t j = 0; j < CHUNK; j++) {
@@ -241,15 +247,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();
// open a file
BENCH_START("write");
@@ -257,7 +265,7 @@ code = '''
// ok, one of these needs to be non-zero
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
while (!(SIM_SIZE && written >= (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) % FILE_COUNT;
char name[256];
@@ -279,7 +287,7 @@ code = '''
written += d;
// taking too long?
if (SIM_TIME && lfs3_kiwibd_simtime(CFG) >= SIM_TIME) {
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
break;
}
}