c1b86ac9db
- Renamed BENCH_STACK/HEAP -> BENCH_STACK/HEAP_WATERMARK
- Renamed BENCH_YES_STACK/HEAP -> BENCH_STACK/HEAP
- Tweaked stack/heap watermarks to hopefully be easier to access when
debugging. Now also exposed as global variables
(bench_stack/heap_watermark).
I considered changing BENCH_STACK/HEAP_WATERMARK to be the variable
itself, to be consistent with TEST_PLS, but decided against it:
1. BENCH_STACK_CURRENT() is a bit magic in that it relies on
__attribute__((noinline)) to force a new stack frame. This wouldn't
really be possible with a variable.
2. TEST_PLS is at least constant from the _current run_'s perspective.
This isn't true for the stack/heap watermarks.
- Reworked internals a bit to hopefully be simpler
80 lines
1.9 KiB
C
80 lines
1.9 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) {
|
|
BENCH_STACK_PAUSE();
|
|
BENCH_HEAP_PAUSE();
|
|
|
|
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);
|
|
|
|
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
|
|
// 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);
|
|
|
|
BENCH_HEAP_RESUME();
|
|
BENCH_STACK_RESUME();
|
|
return (uintmax_t)usage * (uintmax_t)BLOCK_SIZE;
|
|
}
|
|
|
|
|