7e307f2160
These were copied from external benchmarks, and tweaked/simplified a bit based on gained experience. I mostly just wanted something to test the bench runner/scripts, with bench_rbyd showcasing a low-level litmus benchmark, and bench_wt showcasing a high-level throughput benchmark. Though bench_wt has proven to be a _very_ versatile benchmark, and will likely be the first stop for getting an understanding of high-level performance implications. --- Also added bench_helpers.h/c, which includes a couple helper functions: - bench_helpers_warmup - Warm up the filesystem by writing a 1 block file 2*block_count times. This is meant to exhaust any preerased state, post-format lookahead buffers, etc. - bench_helpers_usage - Find a tight bound on disk usage. This allocates a bitmap to find the tight bound, unlike lfs3_fs_usage, which is best-effort. However the bitmap is hidden behind BENCH_HEAP_PAUSE to prevent messing with parallel heap measurements.
96 lines
2.2 KiB
C
96 lines
2.2 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) {
|
|
#ifdef BENCH_YES_STACK
|
|
BENCH_STACK_PAUSE();
|
|
#endif
|
|
#ifdef BENCH_YES_HEAP
|
|
BENCH_HEAP_PAUSE();
|
|
#endif
|
|
|
|
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);
|
|
|
|
#ifdef BENCH_YES_HEAP
|
|
BENCH_HEAP_RESUME();
|
|
#endif
|
|
#ifdef BENCH_YES_STACK
|
|
BENCH_STACK_RESUME();
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
|
|
// find tight disk usage
|
|
uintmax_t bench_helpers_usage(lfs3_t *lfs3) {
|
|
#ifdef BENCH_YES_STACK
|
|
BENCH_STACK_PAUSE();
|
|
#endif
|
|
#ifdef BENCH_YES_HEAP
|
|
BENCH_HEAP_PAUSE();
|
|
#endif
|
|
|
|
// 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);
|
|
|
|
#ifdef BENCH_YES_HEAP
|
|
BENCH_HEAP_RESUME();
|
|
#endif
|
|
#ifdef BENCH_YES_STACK
|
|
BENCH_STACK_RESUME();
|
|
#endif
|
|
return (uintmax_t)usage * (uintmax_t)BLOCK_SIZE;
|
|
}
|
|
|
|
|