benches: Added several benchmarks

Based on some experience out-of-tree:

- bench_rbyd        - Simple rbyd attr/id litmus benchmark
- bench_btree (new) - Simple btree id/name litmus benchmark
- bench_file (new)  - Simple file read/write litmus benchmark
- bench_dir (new)   - Simple dir read/write/stat litmus benchmark
- bench_wt          - Heavy-duty write-throughput benchmark
- bench_rt (new)    - Heavy-duty read-throughput benchmark

Benches take a long time to run for useful results, so we probably don't
want to go crazy with them like with the tests.

Honestly, we may want to chop this down to just the
write/read-throughput benches.
This commit is contained in:
Christopher Haster
2026-02-06 16:47:49 -06:00
parent c722bc08f5
commit 440d303a6b
7 changed files with 855 additions and 26 deletions
+121 -11
View File
@@ -10,15 +10,127 @@ defines.BLOCK_COUNT = 1
# don't bother simulating erases, this gets expensive with big disks
defines.ERASE_VALUE = -1
[cases.bench_rbyd]
[cases.bench_rbyd_attrs]
# 0 = in-order
# 1 = reversed-order
# 2 = random-order
defines.ORDER = 2
defines.N = 256
defines.SIZE = 4
defines.STEP = 1
defines.SEED = 42
# set of probes to measure
# 0x01 => append
# 0x02 => remove
# 0x04 => fetch
# 0x08 => lookup
# 0x10 => usage
defines.MASK = 0x1f
in = 'lfs3.c'
code = '''
lfs3_t lfs3;
lfs3_init(&lfs3, LFS3_M_RDWR, CFG) => 0;
for (lfs3_size_t n = 1; n < N; n += STEP) {
lfs3_rbyd_t rbyd = {
.blocks[0] = 0,
.eoff = 0,
.cksum = 0,
.trunk = 0,
.weight = 0,
};
lfs3_bd_erase(&lfs3, rbyd.blocks[0]) => 0;
// create N attrs
//
// NOTE we only have 256 user attributes, so this benchmark is
// a bit limited
uint32_t prng = SEED;
for (lfs3_size_t i = 0; i < n; i++) {
// create an attr
lfs3_off_t i_
= (ORDER == 0) ? i
: (ORDER == 1) ? (n-1-i)
: BENCH_PRNG(&prng) % n;
uint8_t wbuf[SIZE];
memset(wbuf, 'a'+(BENCH_PRNG(&prng) % 26), SIZE);
lfs3_rbyd_commit(&lfs3, &rbyd, -1, LFS3_RATTRS(
LFS3_RATTR(3,
LFS3_TAG_ATTR(i_ & 0xff), 0, LFS3_FROM_DATA),
LFS3_RATTR_ARG(SIZE),
LFS3_RATTR_ARG(wbuf),
LFS3_RATTR_NULL)) => 0;
}
// create an attr
if (MASK & 0x01) {
BENCH_START("append");
lfs3_off_t i_
= (ORDER == 0) ? (n-1)
: (ORDER == 1) ? 0
: BENCH_PRNG(&prng) % n;
uint8_t wbuf[SIZE];
memset(wbuf, 'a'+(BENCH_PRNG(&prng) % 26), SIZE);
lfs3_rbyd_commit(&lfs3, &rbyd, -1, LFS3_RATTRS(
LFS3_RATTR(3,
LFS3_TAG_ATTR(i_ & 0xff), 0, LFS3_FROM_DATA),
LFS3_RATTR_ARG(SIZE),
LFS3_RATTR_ARG(wbuf),
LFS3_RATTR_NULL)) => 0;
BENCH_STOP("append", n+STEP);
}
// delete an attr
if (MASK & 0x02) {
BENCH_START("remove");
lfs3_off_t i_ = BENCH_PRNG(&prng) % n;
lfs3_rbyd_commit(&lfs3, &rbyd, -1, LFS3_RATTRS(
LFS3_RATTR(1,
LFS3_tag_RM | LFS3_TAG_ATTR(i_ & 0xff), 0),
LFS3_RATTR_NULL)) => 0;
BENCH_STOP("remove", n+STEP);
}
// fetch the rbyd
if (MASK & 0x04) {
BENCH_START("fetch");
lfs3_rbyd_t rbyd_;
lfs3_rbyd_fetch(&lfs3, &rbyd_, rbyd.blocks[0], 0) => 0;
BENCH_STOP("fetch", n+STEP);
}
// lookup an attr
if (MASK & 0x08) {
BENCH_START("lookup");
lfs3_off_t i_ = BENCH_PRNG(&prng) % n;
lfs3_data_t data_;
lfs3_stag_t tag_ = lfs3_rbyd_lookup(&lfs3, &rbyd,
-1, LFS3_TAG_ATTR(i_ & 0xff),
&data_);
// note that random order may have some collisions
assert(tag_ == LFS3_TAG_ATTR(i_ & 0xff)
|| tag_ == LFS3_ERR_NOENT);
BENCH_STOP("lookup", n+STEP);
}
// measure the disk usage
if (MASK & 0x10) {
BENCH_RESULT("usage", n+STEP, lfs3_rbyd_eoff(&rbyd));
}
}
'''
[cases.bench_rbyd_ids]
# 0 = in-order
# 1 = reversed-order
# 2 = random-order
defines.ORDER = 2
defines.N = 1024
defines.SIZE = 4
defines.STEP = 1
defines.SEED = 42
defines.SIZE = 4
# set of probes to measure
# 0x01 => create
# 0x02 => delete
@@ -31,7 +143,7 @@ code = '''
lfs3_t lfs3;
lfs3_init(&lfs3, LFS3_M_RDWR, CFG) => 0;
for (lfs3_size_t n = 0; n < N; n += STEP) {
for (lfs3_size_t n = 1; n < N; n += STEP) {
lfs3_rbyd_t rbyd = {
.blocks[0] = 0,
.eoff = 0,
@@ -83,14 +195,12 @@ code = '''
// delete an attr
if (MASK & 0x02) {
BENCH_START("delete");
if (n > 0) {
lfs3_off_t i_ = BENCH_PRNG(&prng) % rbyd.weight;
lfs3_off_t n_ = rbyd.weight;
lfs3_rbyd_commit(&lfs3, &rbyd, i_, LFS3_RATTRS(
LFS3_RATTR(1, LFS3_tag_RM, -1),
LFS3_RATTR_NULL)) => 0;
assert(rbyd.weight == n_-1);
}
lfs3_off_t i_ = BENCH_PRNG(&prng) % rbyd.weight;
lfs3_off_t n_ = rbyd.weight;
lfs3_rbyd_commit(&lfs3, &rbyd, i_, LFS3_RATTRS(
LFS3_RATTR(1, LFS3_tag_RM, -1),
LFS3_RATTR_NULL)) => 0;
assert(rbyd.weight == n_-1);
BENCH_STOP("delete", n+STEP);
}