10e77d9177
- 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.
68 lines
1.7 KiB
C
68 lines
1.7 KiB
C
/*
|
|
* Some extra bench helpers
|
|
*
|
|
*/
|
|
#include "benches/bench_helpers.h"
|
|
|
|
|
|
// warm up the filesystem
|
|
//
|
|
// 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) {
|
|
uint8_t *wbuf = malloc(BLOCK_SIZE);
|
|
memset(wbuf, '1', BLOCK_SIZE);
|
|
|
|
lfs3_file_t file;
|
|
lfs3_file_open(lfs3, &file, "warmup",
|
|
LFS3_O_WRONLY | LFS3_O_CREAT | LFS3_O_EXCL) => 0;
|
|
for (lfs3_block_t i = 0; i < 2*BLOCK_COUNT; i++) {
|
|
lfs3_file_rewind(lfs3, &file) => 0;
|
|
lfs3_file_write(lfs3, &file, wbuf, BLOCK_SIZE) => BLOCK_SIZE;
|
|
lfs3_file_sync(lfs3, &file) => 0;
|
|
}
|
|
lfs3_file_close(lfs3, &file) => 0;
|
|
|
|
lfs3_remove(lfs3, "warmup") => 0;
|
|
|
|
free(wbuf);
|
|
return 0;
|
|
}
|
|
|
|
|
|
// find tight disk usage
|
|
uintmax_t bench_helpers_usage(lfs3_t *lfs3) {
|
|
// measure disk usage
|
|
//
|
|
// littlefs can be a dag, so build a bitmap to find the exact
|
|
// disk usage
|
|
uint8_t *usage_bmap = malloc((BLOCK_COUNT+8-1)/8);
|
|
memset(usage_bmap, 0, (BLOCK_COUNT+8-1)/8);
|
|
|
|
lfs3_trv_t trv;
|
|
lfs3_trv_open(lfs3, &trv, 0) => 0;
|
|
while (true) {
|
|
struct lfs3_tinfo tinfo;
|
|
int err = lfs3_trv_read(lfs3, &trv, &tinfo);
|
|
assert(!err || err == LFS3_ERR_NOENT);
|
|
if (err == LFS3_ERR_NOENT) {
|
|
break;
|
|
}
|
|
|
|
usage_bmap[tinfo.block/8] |= 1 << (tinfo.block % 8);
|
|
}
|
|
lfs3_trv_close(lfs3, &trv) => 0;
|
|
|
|
lfs3_size_t usage = 0;
|
|
for (lfs3_size_t j = 0; j < BLOCK_COUNT; j++) {
|
|
if (usage_bmap[j / 8] & (1 << (j % 8))) {
|
|
usage += 1;
|
|
}
|
|
}
|
|
|
|
free(usage_bmap);
|
|
return (uintmax_t)usage * (uintmax_t)BLOCK_SIZE;
|
|
}
|
|
|
|
|